package mineplex.hub.modules; import java.util.HashSet; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.Horse; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.util.Vector; import mineplex.core.MiniPlugin; import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.projectile.IThrown; import mineplex.core.projectile.ProjectileManager; import mineplex.core.projectile.ProjectileUser; import mineplex.core.recharge.Recharge; import mineplex.hub.HubManager; public class StackerManager extends MiniPlugin implements IThrown { public HubManager Manager; private ProjectileManager _projectileManager; private HashSet _disabled = new HashSet(); private HashSet _tempStackShift = new HashSet(); private int _slot = 7; public StackerManager(HubManager manager) { super("Stacker", manager.GetPlugin()); Manager = manager; _projectileManager = new ProjectileManager(manager.GetPlugin()); } @EventHandler public void ToggleVisibility(PlayerInteractEvent event) { Player player = event.getPlayer(); if (player.getInventory().getHeldItemSlot() != _slot) return; event.setCancelled(true); if (_disabled.remove(player)) { UtilPlayer.message(player, F.main("Stacker", "You are back in the stacking games! Squeeeee!")); player.getInventory().setItem(_slot, ItemStackFactory.Instance.CreateStack(Material.SLIME_BALL, (byte)0, 1, C.cYellow + "Stacker" + C.cWhite + " - " + C.cGreen + "Enabled")); } else { _disabled.add(player); UtilPlayer.message(player, F.main("Stacker", "You are no longer stackable... boring!")); player.getInventory().setItem(_slot, ItemStackFactory.Instance.CreateStack(Material.MAGMA_CREAM, (byte)0, 1, C.cYellow + "Stacker" + C.cWhite + " - " + C.cRed + "Disabled")); } } @EventHandler public void PlayerJoin(PlayerJoinEvent event) { event.getPlayer().getInventory().setItem(_slot, ItemStackFactory.Instance.CreateStack(Material.SLIME_BALL, (byte)0, 1, C.cYellow + "Stacker" + C.cWhite + " - " + C.cGreen + "Enabled")); } @EventHandler public void orderThatItem(final PlayerDropItemEvent event) { if (event.getItemDrop().getItemStack().getType() == Material.REDSTONE_TORCH_OFF || event.getItemDrop().getItemStack().getType() == Material.REDSTONE_TORCH_ON) { Bukkit.getScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable() { public void run() { if (event.getPlayer().isOnline()) { event.getPlayer().getInventory().remove(event.getItemDrop().getItemStack().getType()); event.getPlayer().getInventory().setItem(_slot, ItemStackFactory.Instance.CreateStack(event.getItemDrop().getItemStack().getType(), (byte)0, 1, ChatColor.RESET + C.cYellow + "Stacker" + C.cWhite + (_disabled.contains(event.getPlayer()) ? C.cWhite + " - " + C.cRed + "Disabled" : " - " + C.cGreen + "Enabled"))); event.getPlayer().updateInventory(); } } }); } } @EventHandler public void PlayerQuit(PlayerQuitEvent event) { _disabled.remove(event.getPlayer()); _tempStackShift.remove(event.getPlayer()); } public boolean CanStack(LivingEntity ent) { if (!(ent instanceof Player)) return true; if (_disabled.contains(ent)) return false; if (Manager.GetVisibility().IsHiding(ent)) return false; return true; } @EventHandler public void GrabEntity(PlayerInteractEntityEvent event) { if (event.isCancelled()) return; Player stacker = event.getPlayer(); if (stacker.getGameMode() != GameMode.SURVIVAL) return; //Parkour Disable if (Manager.GetParkour().InParkour(stacker)) { UtilPlayer.message(stacker, F.main("Parkour", "You cannot Stack/Throw near Parkour Challenges.")); return; } if (!CanStack(stacker)) { UtilPlayer.message(stacker, F.main("Stacker", "You are not playing stacker.")); return; } if (stacker.getVehicle() != null || _tempStackShift.contains(stacker)) { UtilPlayer.message(stacker, F.main("Stacker", "You cannot stack while stacked...")); return; } Entity stackee = event.getRightClicked(); if (stackee == null) return; if (!(stackee instanceof LivingEntity)) return; if (stackee instanceof Horse) return; if (stackee instanceof Player && ((Player)stackee).getGameMode() != GameMode.SURVIVAL) return; if (stackee instanceof Player && !CanStack(((Player)stackee))) { UtilPlayer.message(stacker, F.main("Stacker", F.name(UtilEnt.getName(stackee)) + " is not playing stacker.")); return; } //YouTuber if (stackee instanceof Player && Manager.GetClients().Get((Player)stackee).GetRank() == Rank.YOUTUBE) { if (!Manager.GetClients().Get(stacker).GetRank().Has(Rank.YOUTUBE)) { UtilPlayer.message(stacker, F.main("Stacker", F.name(UtilEnt.getName(stackee)) + " cannot be stacked! Leave him/her alone!")); return; } } if (stackee instanceof LivingEntity) { if (((LivingEntity)stackee).isCustomNameVisible()) { UtilPlayer.message(stacker, F.main("Stacker", "You cannot stack this entity.")); return; } } while (stackee.getVehicle() != null) stackee = stackee.getVehicle(); if (stackee.equals(stacker)) return; Entity top = stacker; while (top.getPassenger() != null) top = top.getPassenger(); if (!Recharge.Instance.use(stacker, "Stacker", 500, true)) return; top.setPassenger(stackee); UtilPlayer.message(stacker, F.main("Stacker", "You stacked " + F.name(UtilEnt.getName(stackee) + "."))); UtilPlayer.message(stackee, F.main("Stacker", "You were stacked by " + F.name(stacker.getName() + "."))); UtilPlayer.message(stackee, F.main("Stacker", "Push " + F.skill("Crouch") + " to escape!")); //Portal Delay Manager.SetPortalDelay(stacker); Manager.SetPortalDelay(stackee); event.setCancelled(true); } @EventHandler public void ThrowEntity(PlayerInteractEvent event) { if (!UtilEvent.isAction(event, ActionType.L)) return; Player thrower = event.getPlayer(); if (thrower.getVehicle() != null) return; Entity throwee = thrower.getPassenger(); if (throwee == null) return; thrower.eject(); Entity throweeStack = throwee.getPassenger(); if (throweeStack != null) { throwee.eject(); throweeStack.leaveVehicle(); final Entity fThrower = thrower; final Entity fThroweeStack = throweeStack; _tempStackShift.add(throweeStack); GetPlugin().getServer().getScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable() { public void run() { fThrower.setPassenger(fThroweeStack); _tempStackShift.remove(fThroweeStack); } }, 2); } //Parkour Disable if (Manager.GetParkour().InParkour(thrower)) { UtilPlayer.message(thrower, F.main("Parkour", "You cannot Stack/Throw near Parkour Challenges.")); UtilPlayer.message(throwee, F.main("Parkour", "You cannot Stack/Throw near Parkour Challenges.")); return; } UtilPlayer.message(thrower, F.main("Stacker", "You threw " + F.name(UtilEnt.getName(throwee)))); UtilPlayer.message(throwee, F.main("Stacker", "You were thrown by " + F.name(thrower.getName()))); UtilAction.velocity(throwee, thrower.getLocation().getDirection(), 1.8, false, 0, 0.3, 2, false); _projectileManager.AddThrow(throwee, thrower, this, -1, true, false, true, false, 2.4d); //Portal Delay Manager.SetPortalDelay(thrower); Manager.SetPortalDelay(throwee); } @Override public void Collide(LivingEntity target, Block block, ProjectileUser data) { if (target == null) return; if (target.getCustomName() != null || (target.getPassenger() != null && target.getPassenger() instanceof LivingEntity && ((LivingEntity)target.getPassenger()).getCustomName() != null)) return; //Velocity UtilAction.velocity(target, UtilAlg.getTrajectory2d(data.GetThrown(), target), 1, true, 0.8, 0, 10, true); Entity rider = target.getPassenger(); while (rider != null) { //Portal Delay Manager.SetPortalDelay(rider); rider.leaveVehicle(); rider.setVelocity(new Vector(0.25 - Math.random()/2, Math.random()/2, 0.25 - Math.random()/2)); rider = rider.getPassenger(); } UtilPlayer.message(target, F.main("Stacker", F.name(UtilEnt.getName(data.GetThrower())) + " hit you with " + F.name(UtilEnt.getName(data.GetThrown())))); //Effect data.GetThrown().getWorld().playSound(data.GetThrown().getLocation(), Sound.HURT, 1f, 1f); //Portal Delay Manager.SetPortalDelay(target); } @Override public void Idle(ProjectileUser data) { } @Override public void Expire(ProjectileUser data) { } }