2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
|
|
|
|
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
|
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
2022-11-17 08:34:45 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
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.block.BlockBreakEvent;
|
|
|
|
import org.bukkit.event.block.BlockPlaceEvent;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class AntiNuke extends FreedomService
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStart()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStop()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
|
|
|
public void onBlockBreak(BlockBreakEvent event)
|
|
|
|
{
|
|
|
|
if (!ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Player player = event.getPlayer();
|
|
|
|
final FPlayer fPlayer = plugin.pl.getPlayer(player);
|
|
|
|
|
|
|
|
if (fPlayer.incrementAndGetBlockDestroyCount() > ConfigEntry.NUKE_MONITOR_COUNT_BREAK.getInteger())
|
|
|
|
{
|
2022-11-17 08:34:45 +00:00
|
|
|
server.broadcast(Component.text(player.getName()).append(Component.text(" is breaking blocks too fast!"))
|
|
|
|
.color(NamedTextColor.RED));
|
|
|
|
player.kick(Component.text("You are breaking blocks too fast. Nukers are not permitted on this server.",
|
|
|
|
NamedTextColor.RED));
|
2015-11-15 23:32:04 +00:00
|
|
|
fPlayer.resetBlockDestroyCount();
|
|
|
|
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
|
|
|
public void onBlockPlace(BlockPlaceEvent event)
|
|
|
|
{
|
|
|
|
if (!ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
FPlayer fPlayer = plugin.pl.getPlayer(player);
|
|
|
|
|
|
|
|
if (fPlayer.incrementAndGetBlockPlaceCount() > ConfigEntry.NUKE_MONITOR_COUNT_PLACE.getInteger())
|
|
|
|
{
|
2022-11-17 08:34:45 +00:00
|
|
|
server.broadcast(Component.text(player.getName()).append(Component.text(" is placing blocks too fast!"))
|
|
|
|
.color(NamedTextColor.RED));
|
|
|
|
player.kick(Component.text("You are placing blocks too fast.", NamedTextColor.RED));
|
2015-11-15 23:32:04 +00:00
|
|
|
fPlayer.resetBlockPlaceCount();
|
|
|
|
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|