2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.caging;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
|
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Location;
|
2016-03-07 20:32:05 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
2016-03-07 20:32:05 +00:00
|
|
|
import org.bukkit.event.block.BlockBreakEvent;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
2018-07-31 07:01:29 +00:00
|
|
|
import org.bukkit.event.player.PlayerKickEvent;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.event.player.PlayerMoveEvent;
|
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class Cager extends FreedomService
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public Cager(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-03-07 20:32:05 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
|
|
|
public void onBreakBlock(BlockBreakEvent event)
|
|
|
|
{
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
if (player == null
|
|
|
|
|| plugin.al.isAdmin(player))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FPlayer fPlayer = plugin.pl.getPlayer(event.getPlayer());
|
|
|
|
CageData cage = fPlayer.getCageData();
|
|
|
|
|
|
|
|
if (cage.isCaged())
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
@EventHandler
|
|
|
|
public void onPlayerMove(PlayerMoveEvent event)
|
|
|
|
{
|
|
|
|
FPlayer player = plugin.pl.getPlayer(event.getPlayer());
|
|
|
|
CageData cage = player.getCageData();
|
|
|
|
|
|
|
|
if (!cage.isCaged())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Location playerLoc = player.getPlayer().getLocation().add(0, 1, 0);
|
|
|
|
Location cageLoc = cage.getLocation();
|
|
|
|
|
|
|
|
final boolean outOfCage;
|
|
|
|
if (!playerLoc.getWorld().equals(cageLoc.getWorld()))
|
|
|
|
{
|
|
|
|
outOfCage = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
outOfCage = playerLoc.distanceSquared(cageLoc) > (2.5D * 2.5D);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outOfCage)
|
|
|
|
{
|
2016-03-07 20:32:05 +00:00
|
|
|
player.getPlayer().teleport(cageLoc.subtract(0, 0.1, 0));
|
2015-11-15 23:32:04 +00:00
|
|
|
FUtil.playerMsg(player.getPlayer(), "You may not leave your cage.", ChatColor.RED);
|
2016-03-07 20:32:05 +00:00
|
|
|
cage.regenerate();
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
|
|
|
public void onPlayerQuit(PlayerQuitEvent event)
|
|
|
|
{
|
|
|
|
FPlayer player = plugin.pl.getPlayer(event.getPlayer());
|
|
|
|
CageData cage = player.getCageData();
|
|
|
|
|
|
|
|
if (cage.isCaged())
|
|
|
|
{
|
|
|
|
cage.playerQuit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-30 07:47:31 +00:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
|
|
|
public void onPlayerKick(PlayerKickEvent event)
|
|
|
|
{
|
|
|
|
FPlayer player = plugin.pl.getPlayer(event.getPlayer());
|
|
|
|
CageData cage = player.getCageData();
|
|
|
|
|
|
|
|
if (cage.isCaged())
|
|
|
|
{
|
|
|
|
cage.playerQuit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
|
|
|
public void onPlayerJoin(PlayerJoinEvent event)
|
|
|
|
{
|
|
|
|
FPlayer player = plugin.pl.getPlayer(event.getPlayer());
|
|
|
|
CageData cage = player.getCageData();
|
|
|
|
|
|
|
|
if (cage.isCaged())
|
|
|
|
{
|
|
|
|
cage.playerJoin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|