Mineplex2018-withcommit/Plugins/Mineplex.Hub/src/mineplex/hub/modules/ParkourManager.java

269 lines
7.0 KiB
Java
Raw Normal View History

2013-09-18 11:46:45 +02:00
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;
2013-11-21 21:38:16 +01:00
import org.bukkit.entity.Entity;
2013-09-18 11:46:45 +02:00
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;
2013-09-18 11:46:45 +02:00
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.",
},
2013-10-12 09:21:19 +02:00
4000, new Location(Manager.GetSpawn().getWorld(), 115,70,-10), 60));
2013-09-18 11:46:45 +02:00
_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!"
2013-10-12 09:21:19 +02:00
}, 1000, new Location(Manager.GetSpawn().getWorld(), -100,60,0), 60));
2013-09-18 11:46:45 +02:00
_lavaParkourReturn = new Location(Manager.GetSpawn().getWorld(), -89.5,68,36.5);
_lavaParkourReturn.setYaw(90);
}
2013-11-21 21:38:16 +01:00
public boolean InParkour(Entity ent)
2013-09-18 11:46:45 +02:00
{
for (ParkourData data : _parkour)
{
2013-10-25 12:25:23 +02:00
if (UtilMath.offset(ent.getLocation(), data.Location) < data.Distance)
2013-09-18 11:46:45 +02:00
{
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);
}
}
2013-09-18 11:46:45 +02:00
@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!"));
}
}
}
}
2013-09-18 11:46:45 +02:00
@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))
2013-09-18 11:46:45 +02:00
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)
2013-09-18 11:46:45 +02:00
{
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();
2013-09-27 21:45:24 +02:00
if (!Recharge.Instance.use(player, "Finish Parkour", 30000, false))
2013-09-18 11:46:45 +02:00
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>()
{
2013-09-18 11:46:45 +02:00
public void run(Boolean completed)
{
UtilPlayer.message(player, F.main("Parkour", "You received " + F.elem(C.cGreen + fData.Gems + " Gems") + "."));
2013-09-18 11:46:45 +02:00
_taskManager.completedTask(player, fData.Name);
2013-09-18 11:46:45 +02:00
//Sound
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
}
}, "Parkour " + data.Name, player.getName(), data.Gems);
2013-09-18 11:46:45 +02:00
}
}
}
}
}