2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.freeze;
|
|
|
|
|
|
|
|
import lombok.Getter;
|
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
|
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
|
|
|
import static me.totalfreedom.totalfreedommod.player.FPlayer.AUTO_PURGE_TICKS;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
|
|
import org.bukkit.GameMode;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
import org.bukkit.scheduler.BukkitTask;
|
|
|
|
|
|
|
|
public class FreezeData
|
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
private final FPlayer fPlayer;
|
|
|
|
//
|
|
|
|
@Getter
|
|
|
|
private Location location = null;
|
|
|
|
private BukkitTask unfreeze = null;
|
|
|
|
|
|
|
|
public FreezeData(FPlayer fPlayer)
|
|
|
|
{
|
|
|
|
this.fPlayer = fPlayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isFrozen()
|
|
|
|
{
|
|
|
|
return unfreeze != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFrozen(boolean freeze)
|
|
|
|
{
|
|
|
|
final Player player = fPlayer.getPlayer();
|
|
|
|
if (player == null)
|
|
|
|
{
|
|
|
|
FLog.info("Could not freeze " + fPlayer.getName() + ". Player not online!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FUtil.cancel(unfreeze);
|
|
|
|
unfreeze = null;
|
|
|
|
location = null;
|
|
|
|
|
|
|
|
if (!freeze)
|
|
|
|
{
|
|
|
|
if (fPlayer.getPlayer().getGameMode() != GameMode.CREATIVE)
|
|
|
|
{
|
|
|
|
FUtil.setFlying(player, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
location = player.getLocation(); // Blockify location
|
|
|
|
FUtil.setFlying(player, true); // Avoid infinite falling
|
2016-05-12 19:40:39 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
unfreeze = new BukkitRunnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
2018-03-27 07:08:57 +00:00
|
|
|
if (!fPlayer.getPlugin().al.isAdminImpostor(player) && !fPlayer.getPlugin().pv.isPlayerImpostor(player))
|
2018-03-13 04:43:51 +00:00
|
|
|
{
|
|
|
|
FUtil.adminAction("TotalFreedom", "Unfreezing " + player.getName(), false);
|
|
|
|
setFrozen(false);
|
|
|
|
}
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
}.runTaskLater(fPlayer.getPlugin(), AUTO_PURGE_TICKS);
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|