2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.freeze;
|
|
|
|
|
|
|
|
import lombok.Getter;
|
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.util.FUtil;
|
2016-03-07 20:32:05 +00:00
|
|
|
import org.bukkit.Location;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.player.PlayerMoveEvent;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class Freezer extends FreedomService
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
@Getter
|
|
|
|
private boolean globalFreeze = false;
|
|
|
|
|
|
|
|
public Freezer(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart()
|
|
|
|
{
|
|
|
|
globalFreeze = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setGlobalFreeze(boolean frozen)
|
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
this.globalFreeze = frozen;
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void purge()
|
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
this.globalFreeze = false;
|
2015-11-15 23:32:04 +00:00
|
|
|
|
|
|
|
for (Player player : server.getOnlinePlayers())
|
|
|
|
{
|
|
|
|
plugin.pl.getPlayer(player).getFreezeData().setFrozen(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
|
|
|
public void onPlayerMove(PlayerMoveEvent event)
|
|
|
|
{
|
|
|
|
final Player player = event.getPlayer();
|
|
|
|
|
2016-03-07 20:32:05 +00:00
|
|
|
if (plugin.al.isAdmin(player))
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final FreezeData fd = plugin.pl.getPlayer(player).getFreezeData();
|
2016-03-07 20:32:05 +00:00
|
|
|
if (!fd.isFrozen() && !globalFreeze)
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2016-03-07 20:32:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FUtil.setFlying(player, true);
|
|
|
|
|
2018-07-25 02:44:00 +00:00
|
|
|
Location loc = player.getLocation();
|
2016-03-07 20:32:05 +00:00
|
|
|
if (loc == null)
|
|
|
|
{
|
|
|
|
loc = event.getFrom();
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
2016-03-07 20:32:05 +00:00
|
|
|
|
|
|
|
event.setTo(loc);
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|