2013-09-18 11:46:45 +02:00
|
|
|
package mineplex.hub.modules;
|
2013-08-27 17:14:08 +02:00
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
2013-10-26 19:02:18 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
2013-08-27 17:14:08 +02:00
|
|
|
import org.bukkit.GameMode;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.Sound;
|
|
|
|
import org.bukkit.block.Block;
|
2013-12-21 10:05:42 +01:00
|
|
|
import org.bukkit.entity.EnderDragon;
|
2013-08-27 17:14:08 +02:00
|
|
|
import org.bukkit.entity.Entity;
|
2013-09-07 08:01:10 +02:00
|
|
|
import org.bukkit.entity.Horse;
|
2013-08-27 17:14:08 +02:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
2013-11-08 23:48:40 +01:00
|
|
|
import org.bukkit.event.block.Action;
|
2013-10-26 19:02:18 +02:00
|
|
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
2013-08-27 17:14:08 +02:00
|
|
|
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;
|
2013-11-07 00:33:39 +01:00
|
|
|
import mineplex.core.common.Rank;
|
2013-08-27 17:14:08 +02:00
|
|
|
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;
|
2013-12-16 04:32:51 +01:00
|
|
|
import mineplex.core.common.util.UtilGear;
|
2013-08-27 17:14:08 +02:00
|
|
|
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;
|
2013-09-23 05:53:24 +02:00
|
|
|
import mineplex.core.recharge.Recharge;
|
2013-09-18 11:46:45 +02:00
|
|
|
import mineplex.hub.HubManager;
|
2013-08-27 17:14:08 +02:00
|
|
|
|
2013-09-18 11:46:45 +02:00
|
|
|
public class StackerManager extends MiniPlugin implements IThrown
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
2013-09-18 11:46:45 +02:00
|
|
|
public HubManager Manager;
|
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
private ProjectileManager _projectileManager;
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-12-16 04:32:51 +01:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
private HashSet<Entity> _tempStackShift = new HashSet<Entity>();
|
2013-10-25 10:20:14 +02:00
|
|
|
|
2013-12-16 04:32:51 +01:00
|
|
|
|
2013-09-27 09:08:32 +02:00
|
|
|
|
2013-09-18 11:46:45 +02:00
|
|
|
public StackerManager(HubManager manager)
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
2013-09-18 11:46:45 +02:00
|
|
|
super("Stacker", manager.GetPlugin());
|
|
|
|
|
|
|
|
Manager = manager;
|
|
|
|
|
|
|
|
_projectileManager = new ProjectileManager(manager.GetPlugin());
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
2013-10-25 10:20:14 +02:00
|
|
|
|
2013-12-16 04:32:51 +01:00
|
|
|
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-12-16 04:32:51 +01:00
|
|
|
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-10-26 19:02:18 +02:00
|
|
|
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-10-25 10:20:14 +02:00
|
|
|
public boolean CanStack(LivingEntity ent)
|
|
|
|
{
|
|
|
|
if (!(ent instanceof Player))
|
|
|
|
return true;
|
|
|
|
|
2013-12-16 04:32:51 +01:00
|
|
|
if (Manager.BumpDisabled(ent))
|
2013-10-25 10:20:14 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (Manager.GetVisibility().IsHiding(ent))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
@EventHandler
|
|
|
|
public void GrabEntity(PlayerInteractEntityEvent event)
|
|
|
|
{
|
|
|
|
if (event.isCancelled())
|
|
|
|
return;
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
Player stacker = event.getPlayer();
|
|
|
|
|
|
|
|
if (stacker.getGameMode() != GameMode.SURVIVAL)
|
|
|
|
return;
|
2013-12-16 04:32:51 +01:00
|
|
|
|
|
|
|
if (UtilGear.isMat(stacker.getItemInHand(), Material.SNOW_BALL))
|
|
|
|
return;
|
2013-09-18 11:46:45 +02:00
|
|
|
|
|
|
|
//Parkour Disable
|
|
|
|
if (Manager.GetParkour().InParkour(stacker))
|
|
|
|
{
|
|
|
|
UtilPlayer.message(stacker, F.main("Parkour", "You cannot Stack/Throw near Parkour Challenges."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-25 10:20:14 +02:00
|
|
|
if (!CanStack(stacker))
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
|
|
|
UtilPlayer.message(stacker, F.main("Stacker", "You are not playing stacker."));
|
|
|
|
return;
|
|
|
|
}
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
if (stacker.getVehicle() != null || _tempStackShift.contains(stacker))
|
|
|
|
{
|
|
|
|
UtilPlayer.message(stacker, F.main("Stacker", "You cannot stack while stacked..."));
|
|
|
|
return;
|
|
|
|
}
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
Entity stackee = event.getRightClicked();
|
|
|
|
if (stackee == null)
|
|
|
|
return;
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-09-08 02:16:39 +02:00
|
|
|
if (!(stackee instanceof LivingEntity))
|
|
|
|
return;
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-09-07 08:01:10 +02:00
|
|
|
if (stackee instanceof Horse)
|
|
|
|
return;
|
2013-12-21 10:05:42 +01:00
|
|
|
|
|
|
|
if (stackee instanceof EnderDragon)
|
|
|
|
return;
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
if (stackee instanceof Player && ((Player)stackee).getGameMode() != GameMode.SURVIVAL)
|
|
|
|
return;
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-10-25 10:20:14 +02:00
|
|
|
if (stackee instanceof Player && !CanStack(((Player)stackee)))
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
|
|
|
UtilPlayer.message(stacker, F.main("Stacker", F.name(UtilEnt.getName(stackee)) + " is not playing stacker."));
|
|
|
|
return;
|
|
|
|
}
|
2013-11-07 00:33:39 +01:00
|
|
|
|
|
|
|
//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;
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
if (stackee instanceof LivingEntity)
|
|
|
|
{
|
|
|
|
if (((LivingEntity)stackee).isCustomNameVisible())
|
|
|
|
{
|
|
|
|
UtilPlayer.message(stacker, F.main("Stacker", "You cannot stack this entity."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
while (stackee.getVehicle() != null)
|
|
|
|
stackee = stackee.getVehicle();
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
if (stackee.equals(stacker))
|
|
|
|
return;
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
Entity top = stacker;
|
|
|
|
while (top.getPassenger() != null)
|
|
|
|
top = top.getPassenger();
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-09-23 05:53:24 +02:00
|
|
|
if (!Recharge.Instance.use(stacker, "Stacker", 500, true))
|
|
|
|
return;
|
2013-09-27 09:08:32 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
top.setPassenger(stackee);
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
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!"));
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-09-27 09:08:32 +02:00
|
|
|
//Portal Delay
|
2013-10-26 10:01:26 +02:00
|
|
|
Manager.SetPortalDelay(stacker);
|
|
|
|
Manager.SetPortalDelay(stackee);
|
2013-09-27 09:08:32 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
@EventHandler
|
|
|
|
public void ThrowEntity(PlayerInteractEvent event)
|
|
|
|
{
|
|
|
|
if (!UtilEvent.isAction(event, ActionType.L))
|
|
|
|
return;
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
Player thrower = event.getPlayer();
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
if (thrower.getVehicle() != null)
|
|
|
|
return;
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
Entity throwee = thrower.getPassenger();
|
|
|
|
if (throwee == null)
|
|
|
|
return;
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
thrower.eject();
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
Entity throweeStack = throwee.getPassenger();
|
|
|
|
if (throweeStack != null)
|
|
|
|
{
|
|
|
|
throwee.eject();
|
|
|
|
throweeStack.leaveVehicle();
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
final Entity fThrower = thrower;
|
|
|
|
final Entity fThroweeStack = throweeStack;
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
_tempStackShift.add(throweeStack);
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
GetPlugin().getServer().getScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable()
|
|
|
|
{
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
fThrower.setPassenger(fThroweeStack);
|
|
|
|
_tempStackShift.remove(fThroweeStack);
|
|
|
|
}
|
|
|
|
}, 2);
|
|
|
|
}
|
2013-09-18 11:46:45 +02:00
|
|
|
|
|
|
|
//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;
|
|
|
|
}
|
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
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())));
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
UtilAction.velocity(throwee, thrower.getLocation().getDirection(), 1.8, false, 0, 0.3, 2, false);
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
_projectileManager.AddThrow(throwee, thrower, this, -1, true, false, true, false, 2.4d);
|
2013-09-27 09:08:32 +02:00
|
|
|
|
|
|
|
//Portal Delay
|
2013-10-26 10:01:26 +02:00
|
|
|
Manager.SetPortalDelay(thrower);
|
|
|
|
Manager.SetPortalDelay(throwee);
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
@Override
|
|
|
|
public void Collide(LivingEntity target, Block block, ProjectileUser data)
|
|
|
|
{
|
|
|
|
if (target == null)
|
|
|
|
return;
|
2013-09-27 21:40:09 +02:00
|
|
|
|
|
|
|
if (target.getCustomName() != null || (target.getPassenger() != null && target.getPassenger() instanceof LivingEntity && ((LivingEntity)target.getPassenger()).getCustomName() != null))
|
|
|
|
return;
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
//Velocity
|
|
|
|
UtilAction.velocity(target, UtilAlg.getTrajectory2d(data.GetThrown(), target), 1, true, 0.8, 0, 10, true);
|
|
|
|
|
|
|
|
Entity rider = target.getPassenger();
|
|
|
|
while (rider != null)
|
|
|
|
{
|
2013-09-27 09:08:32 +02:00
|
|
|
//Portal Delay
|
2013-10-26 10:01:26 +02:00
|
|
|
Manager.SetPortalDelay(rider);
|
2013-09-27 09:08:32 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
rider.leaveVehicle();
|
|
|
|
rider.setVelocity(new Vector(0.25 - Math.random()/2, Math.random()/2, 0.25 - Math.random()/2));
|
|
|
|
rider = rider.getPassenger();
|
|
|
|
}
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
UtilPlayer.message(target, F.main("Stacker", F.name(UtilEnt.getName(data.GetThrower())) + " hit you with " + F.name(UtilEnt.getName(data.GetThrown()))));
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
//Effect
|
|
|
|
data.GetThrown().getWorld().playSound(data.GetThrown().getLocation(), Sound.HURT, 1f, 1f);
|
2013-09-27 09:08:32 +02:00
|
|
|
|
|
|
|
//Portal Delay
|
2013-10-26 10:01:26 +02:00
|
|
|
Manager.SetPortalDelay(target);
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void Idle(ProjectileUser data)
|
|
|
|
{
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void Expire(ProjectileUser data)
|
|
|
|
{
|
2013-09-18 11:46:45 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
|
|
|
}
|