mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-12 13:53:54 +00:00
Mavenized project
This commit is contained in:
@ -0,0 +1,114 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class BlockBlocker extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public BlockBlocker(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
switch (event.getBlockPlaced().getType())
|
||||
{
|
||||
case LAVA:
|
||||
case STATIONARY_LAVA:
|
||||
{
|
||||
if (ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
|
||||
{
|
||||
FLog.info(String.format("%s placed lava @ %s", player.getName(), FUtil.formatLocation(event.getBlock().getLocation())));
|
||||
|
||||
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
||||
}
|
||||
else
|
||||
{
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||
player.sendMessage(ChatColor.GRAY + "Lava placement is currently disabled.");
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WATER:
|
||||
case STATIONARY_WATER:
|
||||
{
|
||||
if (ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
|
||||
{
|
||||
FLog.info(String.format("%s placed water @ %s", player.getName(), FUtil.formatLocation(event.getBlock().getLocation())));
|
||||
|
||||
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
||||
}
|
||||
else
|
||||
{
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||
player.sendMessage(ChatColor.GRAY + "Water placement is currently disabled.");
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FIRE:
|
||||
{
|
||||
if (ConfigEntry.ALLOW_FIRE_PLACE.getBoolean())
|
||||
{
|
||||
FLog.info(String.format("%s placed fire @ %s", player.getName(), FUtil.formatLocation(event.getBlock().getLocation())));
|
||||
|
||||
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
||||
}
|
||||
else
|
||||
{
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||
player.sendMessage(ChatColor.GRAY + "Fire placement is currently disabled.");
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TNT:
|
||||
{
|
||||
if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||
{
|
||||
FLog.info(String.format("%s placed TNT @ %s", player.getName(), FUtil.formatLocation(event.getBlock().getLocation())));
|
||||
|
||||
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
||||
}
|
||||
else
|
||||
{
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||
|
||||
player.sendMessage(ChatColor.GRAY + "TNT is currently disabled.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,172 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
|
||||
public class EventBlocker extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public EventBlocker(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockBurn(BlockBurnEvent event)
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockIgnite(BlockIgniteEvent event)
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_FIRE_PLACE.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockFromTo(BlockFromToEvent event)
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_FLUID_SPREAD.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityExplode(EntityExplodeEvent event)
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
event.setYield(0.0F);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onExplosionPrime(ExplosionPrimeEvent event)
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
event.setRadius(ConfigEntry.EXPLOSIVE_RADIUS.getDouble().floatValue());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityCombust(EntityCombustEvent event)
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityDeath(EntityDeathEvent event)
|
||||
{
|
||||
if (ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
||||
{
|
||||
event.setDroppedExp(0);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onProjectileHit(ProjectileHitEvent event)
|
||||
{
|
||||
if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||
{
|
||||
Projectile entity = event.getEntity();
|
||||
if (event.getEntityType() == EntityType.ARROW)
|
||||
{
|
||||
entity.getWorld().createExplosion(entity.getLocation(), 2F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityDamage(EntityDamageEvent event)
|
||||
{
|
||||
switch (event.getCause())
|
||||
{
|
||||
case LAVA:
|
||||
{
|
||||
if (!ConfigEntry.ALLOW_LAVA_DAMAGE.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigEntry.ENABLE_PET_PROTECT.getBoolean())
|
||||
{
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Tameable)
|
||||
{
|
||||
if (((Tameable) entity).isTamed())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event)
|
||||
{
|
||||
if (!ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getPlayer().getWorld().getEntities().size() > 750)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onLeavesDecay(LeavesDecayEvent event)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class InteractBlocker extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public InteractBlocker(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
final FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
|
||||
switch (event.getAction())
|
||||
{
|
||||
case RIGHT_CLICK_AIR:
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
{
|
||||
handleRightClick(event);
|
||||
break;
|
||||
}
|
||||
|
||||
case LEFT_CLICK_AIR:
|
||||
case LEFT_CLICK_BLOCK:
|
||||
{
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleRightClick(PlayerInteractEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
switch (event.getMaterial())
|
||||
{
|
||||
case WATER_BUCKET:
|
||||
{
|
||||
if (plugin.al.isAdmin(player) || ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||
player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
|
||||
case LAVA_BUCKET:
|
||||
{
|
||||
if (plugin.al.isAdmin(player) || ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||
player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
|
||||
case EXPLOSIVE_MINECART:
|
||||
{
|
||||
if (ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
||||
player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.entity.Bat;
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Ghast;
|
||||
import org.bukkit.entity.Giant;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
public class MobBlocker extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public MobBlocker(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event)
|
||||
{
|
||||
if (!ConfigEntry.MOB_LIMITER_ENABLED.getBoolean())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Entity spawned = event.getEntity();
|
||||
if (spawned instanceof EnderDragon)
|
||||
{
|
||||
if (ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (spawned instanceof Ghast)
|
||||
{
|
||||
if (ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (spawned instanceof Slime)
|
||||
{
|
||||
if (ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (spawned instanceof Giant)
|
||||
{
|
||||
if (ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (spawned instanceof Bat)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int mobLimiterMax = ConfigEntry.MOB_LIMITER_MAX.getInteger();
|
||||
|
||||
if (mobLimiterMax <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int mobcount = 0;
|
||||
for (Entity entity : event.getLocation().getWorld().getLivingEntities())
|
||||
{
|
||||
if (!(entity instanceof HumanEntity))
|
||||
{
|
||||
mobcount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (mobcount > mobLimiterMax)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,206 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking.command;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import net.pravian.aero.command.CommandReflection;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class CommandBlocker extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
public static Pattern NUMBER_FLAG_PATTERN = Pattern.compile("(:([0-9]){5,})");
|
||||
//
|
||||
private final Map<String, CommandBlockerEntry> entryList = Maps.newHashMap();
|
||||
|
||||
public CommandBlocker(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
entryList.clear();
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
entryList.clear();
|
||||
|
||||
final CommandMap commandMap = CommandReflection.getCommandMap();
|
||||
if (commandMap == null)
|
||||
{
|
||||
FLog.severe("Error loading commandMap.");
|
||||
return;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> blockedCommands = (List<String>) ConfigEntry.BLOCKED_COMMANDS.getList();
|
||||
for (String rawEntry : blockedCommands)
|
||||
{
|
||||
final String[] parts = rawEntry.split(":");
|
||||
if (parts.length < 3 || parts.length > 4)
|
||||
{
|
||||
FLog.warning("Invalid command blocker entry: " + rawEntry);
|
||||
continue;
|
||||
}
|
||||
|
||||
final CommandBlockerRank rank = CommandBlockerRank.fromToken(parts[0]);
|
||||
final CommandBlockerAction action = CommandBlockerAction.fromToken(parts[1]);
|
||||
String commandName = parts[2].toLowerCase().substring(1);
|
||||
final String message = (parts.length > 3 ? parts[3] : null);
|
||||
|
||||
if (rank == null || action == null || commandName == null || commandName.isEmpty())
|
||||
{
|
||||
FLog.warning("Invalid command blocker entry: " + rawEntry);
|
||||
continue;
|
||||
}
|
||||
|
||||
final String[] commandParts = commandName.split(" ");
|
||||
String subCommand = null;
|
||||
if (commandParts.length > 1)
|
||||
{
|
||||
commandName = commandParts[0];
|
||||
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).trim().toLowerCase();
|
||||
}
|
||||
|
||||
final Command command = commandMap.getCommand(commandName);
|
||||
|
||||
// Obtain command from alias
|
||||
if (command == null)
|
||||
{
|
||||
FLog.info("Blocking unknown command: /" + commandName);
|
||||
}
|
||||
else
|
||||
{
|
||||
commandName = command.getName().toLowerCase();
|
||||
}
|
||||
|
||||
if (entryList.containsKey(commandName))
|
||||
{
|
||||
FLog.warning("Not blocking: /" + commandName + " - Duplicate entry exists!");
|
||||
continue;
|
||||
}
|
||||
|
||||
final CommandBlockerEntry blockedCommandEntry = new CommandBlockerEntry(rank, action, commandName, subCommand, message);
|
||||
entryList.put(blockedCommandEntry.getCommand(), blockedCommandEntry);
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
for (String alias : command.getAliases())
|
||||
{
|
||||
entryList.put(alias.toLowerCase(), blockedCommandEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FLog.info("Loaded " + blockedCommands.size() + " blocked commands");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
// Blocked commands
|
||||
if (isCommandBlocked(event.getMessage(), event.getPlayer(), true))
|
||||
{
|
||||
// CommandBlocker handles messages and broadcasts
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCommandBlocked(String command, CommandSender sender)
|
||||
{
|
||||
return isCommandBlocked(command, sender, false);
|
||||
}
|
||||
|
||||
public boolean isCommandBlocked(String command, CommandSender sender, boolean doAction)
|
||||
{
|
||||
if (command == null || command.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Format
|
||||
command = command.toLowerCase().trim();
|
||||
command = command.startsWith("/") ? command.substring(1) : command;
|
||||
|
||||
// Check for plugin specific commands
|
||||
final String[] commandParts = command.split(" ");
|
||||
if (commandParts[0].contains(":"))
|
||||
{
|
||||
if (doAction)
|
||||
{
|
||||
FUtil.playerMsg(sender, "Plugin specific commands are disabled.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
for (String part : commandParts)
|
||||
{
|
||||
Matcher matcher = NUMBER_FLAG_PATTERN.matcher(part);
|
||||
if (!matcher.matches())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (doAction)
|
||||
{
|
||||
FUtil.playerMsg(sender, "That command contains an illegal number: " + matcher.group(1));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Obtain sub command, if it exists
|
||||
String subCommand = null;
|
||||
if (commandParts.length > 1)
|
||||
{
|
||||
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).toLowerCase();
|
||||
}
|
||||
|
||||
// Obtain entry
|
||||
final CommandBlockerEntry entry = entryList.get(commandParts[0]);
|
||||
if (entry == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate sub command
|
||||
if (entry.getSubCommand() != null)
|
||||
{
|
||||
if (subCommand == null || !subCommand.startsWith(entry.getSubCommand()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.getRank().hasPermission(sender))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (doAction)
|
||||
{
|
||||
entry.doActions(sender);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking.command;
|
||||
|
||||
public enum CommandBlockerAction
|
||||
{
|
||||
BLOCK("b"),
|
||||
BLOCK_AND_EJECT("a"),
|
||||
BLOCK_UNKNOWN("u");
|
||||
private final String token;
|
||||
|
||||
private CommandBlockerAction(String token)
|
||||
{
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getToken()
|
||||
{
|
||||
return this.token;
|
||||
}
|
||||
|
||||
public static CommandBlockerAction fromToken(String token)
|
||||
{
|
||||
for (CommandBlockerAction action : CommandBlockerAction.values())
|
||||
{
|
||||
if (action.getToken().equalsIgnoreCase(token))
|
||||
{
|
||||
return action;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking.command;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandBlockerEntry
|
||||
{
|
||||
@Getter
|
||||
private final CommandBlockerRank rank;
|
||||
@Getter
|
||||
private final CommandBlockerAction action;
|
||||
@Getter
|
||||
private final String command;
|
||||
@Getter
|
||||
private final String subCommand;
|
||||
@Getter
|
||||
private final String message;
|
||||
|
||||
public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String message)
|
||||
{
|
||||
this(rank, action, command, null, message);
|
||||
}
|
||||
|
||||
public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String subCommand, String message)
|
||||
{
|
||||
this.rank = rank;
|
||||
this.action = action;
|
||||
this.command = command;
|
||||
this.subCommand = (subCommand == null ? null : subCommand.toLowerCase().trim());
|
||||
this.message = (message == null || message.equals("_") ? "That command is blocked." : message);
|
||||
}
|
||||
|
||||
public void doActions(CommandSender sender)
|
||||
{
|
||||
if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player)
|
||||
{
|
||||
FUtil.autoEject((Player) sender, "You used a prohibited command: " + command);
|
||||
FUtil.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED);
|
||||
return;
|
||||
}
|
||||
|
||||
if (action == CommandBlockerAction.BLOCK_UNKNOWN)
|
||||
{
|
||||
FUtil.playerMsg(sender, "Unknown command. Type \"help\" for help.", ChatColor.RESET);
|
||||
return;
|
||||
}
|
||||
|
||||
FUtil.playerMsg(sender, FUtil.colorize(message));
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package me.totalfreedom.totalfreedommod.blocking.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public enum CommandBlockerRank
|
||||
{
|
||||
ANYONE("a"),
|
||||
OP("o"),
|
||||
SUPER("s"),
|
||||
TELNET("t"),
|
||||
SENIOR("c"),
|
||||
NOBODY("n");
|
||||
//
|
||||
private final String token;
|
||||
|
||||
private CommandBlockerRank(String token)
|
||||
{
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getToken()
|
||||
{
|
||||
return this.token;
|
||||
}
|
||||
|
||||
public boolean hasPermission(CommandSender sender)
|
||||
{
|
||||
return fromSender(sender).ordinal() >= ordinal();
|
||||
}
|
||||
|
||||
public static CommandBlockerRank fromSender(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player))
|
||||
{
|
||||
return TELNET;
|
||||
}
|
||||
|
||||
Admin admin = TotalFreedomMod.plugin.al.getAdmin(sender);
|
||||
if (admin != null)
|
||||
{
|
||||
if (admin.getRank() == PlayerRank.SENIOR_ADMIN)
|
||||
{
|
||||
return SENIOR;
|
||||
}
|
||||
return SUPER;
|
||||
}
|
||||
|
||||
if (sender.isOp())
|
||||
{
|
||||
return OP;
|
||||
}
|
||||
|
||||
return ANYONE;
|
||||
|
||||
}
|
||||
|
||||
public static CommandBlockerRank fromToken(String token)
|
||||
{
|
||||
for (CommandBlockerRank rank : CommandBlockerRank.values())
|
||||
{
|
||||
if (rank.getToken().equalsIgnoreCase(token))
|
||||
{
|
||||
return rank;
|
||||
}
|
||||
}
|
||||
return ANYONE;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user