0585116e78
Hub Dragon (Hero Only) XMAS block efficiency
269 lines
7.0 KiB
Java
269 lines
7.0 KiB
Java
package mineplex.hub.modules;
|
|
|
|
import java.util.HashSet;
|
|
import java.util.WeakHashMap;
|
|
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.Sound;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.block.BlockFace;
|
|
import org.bukkit.entity.EnderDragon;
|
|
import org.bukkit.entity.Entity;
|
|
import org.bukkit.entity.LivingEntity;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.block.BlockBreakEvent;
|
|
import org.bukkit.event.entity.EntityCombustEvent;
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
|
|
|
import mineplex.core.MiniPlugin;
|
|
import mineplex.core.common.util.C;
|
|
import mineplex.core.common.util.Callback;
|
|
import mineplex.core.common.util.F;
|
|
import mineplex.core.common.util.UtilBlock;
|
|
import mineplex.core.common.util.UtilEnt;
|
|
import mineplex.core.common.util.UtilMath;
|
|
import mineplex.core.common.util.UtilPlayer;
|
|
import mineplex.core.common.util.UtilServer;
|
|
import mineplex.core.common.util.UtilTime;
|
|
import mineplex.core.donation.DonationManager;
|
|
import mineplex.core.recharge.Recharge;
|
|
import mineplex.core.task.TaskManager;
|
|
import mineplex.core.updater.UpdateType;
|
|
import mineplex.core.updater.event.UpdateEvent;
|
|
import mineplex.hub.HubManager;
|
|
|
|
public class ParkourManager extends MiniPlugin
|
|
{
|
|
public HubManager Manager;
|
|
|
|
private HashSet<ParkourData> _parkour = new HashSet<ParkourData>();
|
|
|
|
private Location _lavaParkourReturn;
|
|
private WeakHashMap<Player, Location> _lavaLocation = new WeakHashMap<Player, Location>();
|
|
private WeakHashMap<Player, Long> _lavaTimer = new WeakHashMap<Player, Long>();
|
|
|
|
//Modules
|
|
protected DonationManager _donationManager;
|
|
protected TaskManager _taskManager;
|
|
|
|
public ParkourManager(HubManager manager, DonationManager donation, TaskManager task)
|
|
{
|
|
super("Parkour", manager.GetPlugin());
|
|
|
|
Manager = manager;
|
|
|
|
_taskManager = task;
|
|
_donationManager = donation;
|
|
|
|
_parkour.add(new ParkourData("Ruins Parkour", new String[]
|
|
{
|
|
"This is an extremely difficult parkour.",
|
|
"You will need to find the correct way through",
|
|
"the ruins, overcoming many challenging jumps.",
|
|
},
|
|
4000, new Location(Manager.GetSpawn().getWorld(), 115,70,-10), 60));
|
|
|
|
|
|
_parkour.add(new ParkourData("Lava Parkour", new String[]
|
|
{
|
|
"This parkour is HOT! It's so hot that you",
|
|
"must keep sprinting for the entire course,",
|
|
"or you will die in flames!"
|
|
}, 1000, new Location(Manager.GetSpawn().getWorld(), -100,60,0), 60));
|
|
|
|
_lavaParkourReturn = new Location(Manager.GetSpawn().getWorld(), -89.5,68,36.5);
|
|
_lavaParkourReturn.setYaw(90);
|
|
}
|
|
|
|
public boolean InParkour(Entity ent)
|
|
{
|
|
for (ParkourData data : _parkour)
|
|
{
|
|
if (UtilMath.offset(ent.getLocation(), data.Location) < data.Distance)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
@EventHandler
|
|
public void BlockBreak(BlockBreakEvent event)
|
|
{
|
|
if (InParkour(event.getPlayer()))
|
|
{
|
|
event.getPlayer().teleport(Manager.GetSpawn());
|
|
UtilPlayer.message(event.getPlayer(), F.main("Parkour", "You cannot break blocks near parkour!"));
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void combustPrevent(EntityCombustEvent event)
|
|
{
|
|
if (event.getEntity() instanceof Player)
|
|
{
|
|
event.setCancelled(true);
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void LavaReturn(EntityDamageEvent event)
|
|
{
|
|
if (event.getCause() == DamageCause.LAVA)
|
|
if (event.getEntity() instanceof Player)
|
|
{
|
|
event.getEntity().eject();
|
|
event.getEntity().leaveVehicle();
|
|
event.getEntity().teleport(_lavaParkourReturn);
|
|
}
|
|
|
|
else
|
|
event.getEntity().remove();
|
|
|
|
event.setCancelled(true);
|
|
}
|
|
|
|
@EventHandler
|
|
public void preventCarriers(UpdateEvent event)
|
|
{
|
|
if (event.getType() != UpdateType.SEC)
|
|
return;
|
|
|
|
for (Player player : UtilServer.getPlayers())
|
|
{
|
|
if (InParkour(player))
|
|
{
|
|
if ((player.getVehicle() != null && !(player.getVehicle() instanceof EnderDragon)) || player.getPassenger() != null)
|
|
{
|
|
player.eject();
|
|
player.leaveVehicle();
|
|
|
|
UtilPlayer.message(player, F.main("Parkour", "You can't be a passenger near Parkours!"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void LavaBlockReturn(UpdateEvent event)
|
|
{
|
|
if (event.getType() != UpdateType.TICK)
|
|
return;
|
|
|
|
for (Player player : UtilServer.getPlayers())
|
|
{
|
|
if (!UtilEnt.isGrounded(player))
|
|
continue;
|
|
|
|
int id = player.getLocation().getBlock().getRelative(BlockFace.DOWN).getTypeId();
|
|
int data = player.getLocation().getBlock().getRelative(BlockFace.DOWN).getData();
|
|
if (id != 0 && id != 112 && id != 114 && !(id == 43 && data == 6) && !(id == 44 && data == 6))
|
|
continue;
|
|
|
|
if (!_lavaLocation.containsKey(player) || UtilMath.offset(player.getLocation(), _lavaLocation.get(player)) > 1.5)
|
|
{
|
|
_lavaLocation.put(player, player.getLocation());
|
|
_lavaTimer.put(player, System.currentTimeMillis());
|
|
continue;
|
|
}
|
|
|
|
if (UtilTime.elapsed(_lavaTimer.get(player), 500))
|
|
{
|
|
boolean inCourse = false;
|
|
for (Block block : UtilBlock.getInRadius(player.getLocation(), 1.5).keySet())
|
|
{
|
|
if (block.getType() == Material.NETHER_BRICK || block.getType() == Material.NETHER_BRICK_STAIRS)
|
|
{
|
|
inCourse = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!inCourse)
|
|
continue;
|
|
|
|
_lavaLocation.remove(player);
|
|
_lavaTimer.remove(player);
|
|
|
|
player.eject();
|
|
player.leaveVehicle();
|
|
player.teleport(_lavaParkourReturn);
|
|
player.setFireTicks(0);
|
|
|
|
UtilPlayer.message(player, F.main("Parkour", "You cannot stop running during Lava Parkour!"));
|
|
}
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void Finish(PlayerInteractEntityEvent event)
|
|
{
|
|
if (event.getRightClicked() == null)
|
|
return;
|
|
|
|
if (!(event.getRightClicked() instanceof LivingEntity))
|
|
return;
|
|
|
|
LivingEntity ent = (LivingEntity)event.getRightClicked();
|
|
|
|
if (ent.getCustomName() == null)
|
|
return;
|
|
|
|
//Start Message
|
|
if (ent.getCustomName().contains("Start"))
|
|
{
|
|
Player player = event.getPlayer();
|
|
|
|
for (ParkourData data : _parkour)
|
|
{
|
|
if (!ent.getCustomName().contains(data.Name))
|
|
continue;
|
|
|
|
data.Inform(player);
|
|
}
|
|
}
|
|
|
|
//Finish Message
|
|
if (ent.getCustomName().contains("Finish"))
|
|
{
|
|
final Player player = event.getPlayer();
|
|
|
|
if (!Recharge.Instance.use(player, "Finish Parkour", 30000, false))
|
|
return;
|
|
|
|
for (ParkourData data : _parkour)
|
|
{
|
|
if (!ent.getCustomName().contains(data.Name))
|
|
continue;
|
|
|
|
//Inform
|
|
UtilPlayer.message(player, F.main("Parkour", "You completed " + F.elem(data.Name) + "."));
|
|
|
|
//Gems
|
|
if (!_taskManager.hasCompletedTask(player, data.Name))
|
|
{
|
|
final ParkourData fData = data;
|
|
|
|
_donationManager.RewardGems(new Callback<Boolean>()
|
|
{
|
|
public void run(Boolean completed)
|
|
{
|
|
UtilPlayer.message(player, F.main("Parkour", "You received " + F.elem(C.cGreen + fData.Gems + " Gems") + "."));
|
|
|
|
_taskManager.completedTask(player, fData.Name);
|
|
|
|
//Sound
|
|
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
|
|
}
|
|
}, "Parkour " + data.Name, player.getName(), data.Gems);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|