2022-05-31 20:09:36 +02:00
|
|
|
package wtf.beatrice.hubthat.listeners;
|
2020-04-09 16:31:14 +02:00
|
|
|
|
2022-05-31 20:09:36 +02:00
|
|
|
import wtf.beatrice.hubthat.utils.PluginCache;
|
2023-02-11 20:57:29 +01:00
|
|
|
import wtf.beatrice.hubthat.utils.ConfigEntry;
|
2023-02-11 20:57:11 +01:00
|
|
|
import wtf.beatrice.hubthat.utils.LocalizedMessage;
|
2022-05-31 20:09:36 +02:00
|
|
|
import wtf.beatrice.hubthat.utils.MessageUtils;
|
|
|
|
import wtf.beatrice.hubthat.utils.files.FileUtils;
|
2020-04-09 16:31:14 +02:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.event.player.PlayerMoveEvent;
|
|
|
|
|
|
|
|
public class PlayerMoveListener implements Listener
|
|
|
|
{
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onPlayerMove(PlayerMoveEvent event)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Check if the movement detection is enabled.
|
2023-02-11 20:57:29 +01:00
|
|
|
if(FileUtils.FileType.CONFIG_YAML.yaml.getBoolean(ConfigEntry.MOVEMENT_DETECTION_ENABLED.path))
|
2020-04-09 16:31:14 +02:00
|
|
|
{
|
|
|
|
// We are only going to allocate the playerName string and not the whole Player because we want efficiency.
|
|
|
|
String playerName = event.getPlayer().getName();
|
|
|
|
|
|
|
|
// Check if the player is waiting the teleport delay.
|
2020-06-25 20:45:26 +02:00
|
|
|
if (PluginCache.teleporting.contains(playerName))
|
2020-04-09 16:31:14 +02:00
|
|
|
{
|
|
|
|
// Check if the player moved a whole block.
|
|
|
|
if(event.getFrom().getBlockX() != event.getTo().getBlockX() ||
|
|
|
|
event.getFrom().getBlockY() != event.getTo().getBlockY() ||
|
|
|
|
event.getFrom().getBlockZ() != event.getTo().getBlockZ())
|
|
|
|
{
|
|
|
|
// Remove the player from the list and warn him.
|
2020-06-25 20:45:26 +02:00
|
|
|
PluginCache.teleporting.remove(playerName);
|
|
|
|
PluginCache.cancelRunnable.add(playerName);
|
2023-02-11 20:57:11 +01:00
|
|
|
MessageUtils.sendLocalizedMessage(event.getPlayer(), LocalizedMessage.WARNING_TELEPORTATION_CANCELLED);
|
2020-04-09 16:31:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|