From 17bdfe6814794efe30bf1ba42c01ed4a51dbca75 Mon Sep 17 00:00:00 2001 From: LCastr0 Date: Fri, 30 Dec 2016 12:44:49 -0200 Subject: [PATCH] Started on the flying mechanics stuff --- .../mineplex/core/gadget/GadgetManager.java | 31 +++++++++++++++++++ .../core/gadget/types/BalloonGadget.java | 5 +++ 2 files changed, 36 insertions(+) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java index e81faca04..3b1242667 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java @@ -2,8 +2,10 @@ package mineplex.core.gadget; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.function.Predicate; @@ -41,6 +43,7 @@ import mineplex.core.gadget.commands.LockCosmeticsCommand; import mineplex.core.gadget.commands.UnlockCosmeticsCommand; import mineplex.core.gadget.event.GadgetChangeEvent; import mineplex.core.gadget.event.GadgetCollideEntityEvent; +import mineplex.core.gadget.event.GadgetDisableEvent; import mineplex.core.gadget.event.GadgetEnableEvent; import mineplex.core.gadget.event.PlayerToggleSwimEvent; import mineplex.core.gadget.event.TauntCommandEvent; @@ -253,6 +256,9 @@ public class GadgetManager extends MiniPlugin private final HashSet _sets = new HashSet<>(); + private final Map _playerBalloons = new HashMap<>(); + private final Map _initialLocations = new HashMap<>(); + private UserGadgetPersistence _userGadgetPersistence; private boolean _hideParticles = false; @@ -1347,4 +1353,29 @@ public class GadgetManager extends MiniPlugin taunt.start(player); } + + @EventHandler + public void onActivateBalloon(GadgetEnableEvent event) + { + if (event.getGadget().getGadgetType() != GadgetType.BALLOON) + return; + + Player player = event.getPlayer(); + _initialLocations.put(player, player.getLocation()); + _playerBalloons.computeIfAbsent(player, d -> player.getLocation().getY()); + double height = _playerBalloons.get(player) + (UtilMath.random(1, 2) * BalloonGadget.getBalloons(player)); + Location newLocation = player.getLocation().clone(); + newLocation.setY(height); + player.teleport(newLocation); + } + + @EventHandler + public void onDeactivateBalloon(GadgetDisableEvent event) + { + if (event.getGadget().getGadgetType() != GadgetType.BALLOON) + return; + + Player player = event.getPlayer(); + if () + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/BalloonGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/BalloonGadget.java index ab126a238..980c43fd2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/BalloonGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/BalloonGadget.java @@ -130,4 +130,9 @@ public abstract class BalloonGadget extends Gadget { return _balloonType; } + + public static int getBalloons(Player player) + { + return ((PLAYER_BALLOONS.containsKey(player.getUniqueId())) ? PLAYER_BALLOONS.get(player.getUniqueId()).size() : 0); + } }