diff --git a/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java b/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java index 7b903796..9bc6bc48 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java @@ -114,4 +114,4 @@ public class AntiSpam extends FreedomService } } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ChestMonitor.java b/src/main/java/me/totalfreedom/totalfreedommod/ChestMonitor.java new file mode 100644 index 00000000..b533e6a9 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/ChestMonitor.java @@ -0,0 +1,142 @@ +package me.totalfreedom.totalfreedommod; + +import org.bukkit.event.EventPriority; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import java.text.DecimalFormat; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; + +public class ChestMonitor extends FreedomService +{ + + DecimalFormat df; + + public ChestMonitor(TotalFreedomMod plugin) + { + super(plugin); + this.df = new DecimalFormat("#"); + } + + @Override + protected void onStart() + { + } + + @Override + protected void onStop() + { + } + + public String GetMaterial(final int id) + { + return String.valueOf(Material.getMaterial(id)); + } + + @EventHandler(priority = EventPriority.LOW) + public final void onChestMove(final InventoryClickEvent event) + { + if (plugin.al.isAdmin(event.getWhoClicked())) + { + return; + } + final Inventory top = event.getView().getTopInventory(); + final Inventory bottom = event.getView().getBottomInventory(); + if (top.getType() == InventoryType.CHEST && bottom.getType() == InventoryType.PLAYER && event.getCurrentItem() != null && event.getCurrentItem().getTypeId() != 0) + { + final Player p = (Player) event.getWhoClicked(); + final Location loc = p.getLocation(); + final int item = event.getCurrentItem().getTypeId(); + final int amount = event.getCurrentItem().getAmount(); + for (Player player : server.getOnlinePlayers()) + { + if (plugin.al.isAdmin(player) && plugin.pl.getPlayer(player).ChestMonitorEnabled()) + { + FUtil.playerMsg(player, p.getName() + " Moved in a chest with " + amount + " " + this.GetMaterial(item) + " [" + this.df.format(loc.getX()) + ", " + this.df.format(loc.getY()) + ", " + this.df.format(loc.getZ()) + "] at the world '" + loc.getWorld().getName() + "'."); + } + } + } + if (top.getType() == InventoryType.DISPENSER && bottom.getType() == InventoryType.PLAYER && event.getCurrentItem() != null && event.getCurrentItem().getTypeId() != 0) + { + final Player p2 = (Player) event.getWhoClicked(); + final Location loc = p2.getLocation(); + final int item = event.getCurrentItem().getTypeId(); + final int amount = event.getCurrentItem().getAmount(); + for (Player player : server.getOnlinePlayers()) + { + if (plugin.al.isAdmin(player) && plugin.pl.getPlayer(player).ChestMonitorEnabled()) + { + FUtil.playerMsg(player, p2.getName() + " Moved in a dispenser with " + amount + " " + this.GetMaterial(item) + " [" + this.df.format(loc.getX()) + ", " + this.df.format(loc.getY()) + ", " + this.df.format(loc.getZ()) + "] at the world '" + loc.getWorld().getName() + "'."); + } + + } + } + if (top.getType() == InventoryType.HOPPER && bottom.getType() == InventoryType.PLAYER && event.getCurrentItem() != null && event.getCurrentItem().getTypeId() != 0) + { + final Player p2 = (Player) event.getWhoClicked(); + final Location loc = p2.getLocation(); + final int item = event.getCurrentItem().getTypeId(); + final int amount = event.getCurrentItem().getAmount(); + for (Player player : server.getOnlinePlayers()) + { + if (plugin.al.isAdmin(player) && plugin.pl.getPlayer(player).ChestMonitorEnabled()) + { + FUtil.playerMsg(player, p2.getName() + " Moved in a hopper with " + amount + " " + this.GetMaterial(item) + " [" + this.df.format(loc.getX()) + ", " + this.df.format(loc.getY()) + ", " + this.df.format(loc.getZ()) + "] at the world '" + loc.getWorld().getName() + "'."); + } + + } + } + if (top.getType() == InventoryType.DROPPER && bottom.getType() == InventoryType.PLAYER && event.getCurrentItem() != null && event.getCurrentItem().getTypeId() != 0) + { + final Player p2 = (Player) event.getWhoClicked(); + final Location loc = p2.getLocation(); + final int item = event.getCurrentItem().getTypeId(); + final int amount = event.getCurrentItem().getAmount(); + for (Player player : server.getOnlinePlayers()) + { + if (plugin.al.isAdmin(player) && plugin.pl.getPlayer(player).ChestMonitorEnabled()) + { + FUtil.playerMsg(player, p2.getName() + " Moved in a dropper with " + amount + " " + this.GetMaterial(item) + " [" + this.df.format(loc.getX()) + ", " + this.df.format(loc.getY()) + ", " + this.df.format(loc.getZ()) + "] at the world '" + loc.getWorld().getName() + "'."); + } + + } + + } + if (top.getType() == InventoryType.SHULKER_BOX && bottom.getType() == InventoryType.PLAYER && event.getCurrentItem() != null && event.getCurrentItem().getTypeId() != 0) + { + final Player p2 = (Player) event.getWhoClicked(); + final Location loc = p2.getLocation(); + final int item = event.getCurrentItem().getTypeId(); + final int amount = event.getCurrentItem().getAmount(); + for (Player player : server.getOnlinePlayers()) + { + if (plugin.al.isAdmin(player) && plugin.pl.getPlayer(player).ChestMonitorEnabled()) + { + FUtil.playerMsg(player, p2.getName() + " Moved in a shulker box with " + amount + " " + this.GetMaterial(item) + " [" + this.df.format(loc.getX()) + ", " + this.df.format(loc.getY()) + ", " + this.df.format(loc.getZ()) + "] at the world '" + loc.getWorld().getName() + "'."); + } + + } + + } + if (top.getType() == InventoryType.ENDER_CHEST && bottom.getType() == InventoryType.PLAYER && event.getCurrentItem() != null && event.getCurrentItem().getTypeId() != 0) + { + final Player p2 = (Player) event.getWhoClicked(); + final Location loc = p2.getLocation(); + final int item = event.getCurrentItem().getTypeId(); + final int amount = event.getCurrentItem().getAmount(); + for (Player player : server.getOnlinePlayers()) + { + if (plugin.al.isAdmin(player) && plugin.pl.getPlayer(player).ChestMonitorEnabled()) + { + FUtil.playerMsg(player, p2.getName() + " Moved in a ender chest with " + amount + " " + this.GetMaterial(item) + " [" + this.df.format(loc.getX()) + ", " + this.df.format(loc.getY()) + ", " + this.df.format(loc.getZ()) + "] at the world '" + loc.getWorld().getName() + "'."); + } + + } + + } + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java index 35b61d63..e5ae049c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java @@ -12,6 +12,7 @@ import me.totalfreedom.totalfreedommod.util.FUtil; import net.pravian.aero.base.ConfigLoadable; import net.pravian.aero.base.ConfigSavable; import net.pravian.aero.base.Validatable; +import net.pravian.aero.config.YamlConfig; import net.pravian.aero.util.Ips; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; @@ -40,6 +41,8 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable @Setter private String loginMessage = null; + public static final String CONFIG_FILENAME = "admins.yml"; + public Admin(Player player) { this.configKey = player.getName().toLowerCase(); @@ -126,6 +129,11 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable } } + public String getLoginMessage() + { + return this.loginMessage; + } + public void removeIp(String ip) { if (ips.contains(ip)) @@ -168,4 +176,54 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable && !ips.isEmpty() && lastLogin != null; } + + public boolean isActive() + { + return this.active; + } + + public String getConfigKey() + { + return this.configKey; + } + + public String getName() + { + return this.name; + } + + public void setName(final String name) + { + this.name = name; + } + + public Rank getRank() + { + return this.rank; + } + + public void setRank(final Rank rank) + { + this.rank = rank; + } + + public List getIps() + { + return this.ips; + } + + public Date getLastLogin() + { + return this.lastLogin; + } + + public void setLastLogin(final Date lastLogin) + { + this.lastLogin = lastLogin; + } + + public void setLoginMessage(final String loginMessage) + { + this.loginMessage = loginMessage; + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java index 95872050..9a1d2e71 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java @@ -130,6 +130,16 @@ public class AdminList extends FreedomService return admin != null && admin.isActive(); } + public Map getAllAdmins() + { + return this.allAdmins; + } + + public Set getActiveAdmins() + { + return this.activeAdmins; + } + public boolean isSeniorAdmin(CommandSender sender) { Admin admin = getAdmin(sender); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java b/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java index 3d22a3ae..b25fbc4d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java @@ -156,6 +156,51 @@ public class Ban implements ConfigLoadable, ConfigSavable, Validatable return expiryUnix > 0; } + public String getUsername() + { + return this.username; + } + + public void setUsername(final String username) + { + this.username = username; + } + + public List getIps() + { + return this.ips; + } + + public String getBy() + { + return this.by; + } + + public void setBy(final String by) + { + this.by = by; + } + + public String getReason() + { + return this.reason; + } + + public void setReason(final String reason) + { + this.reason = reason; + } + + public long getExpiryUnix() + { + return this.expiryUnix; + } + + public void setExpiryUnix(final long expiryUnix) + { + this.expiryUnix = expiryUnix; + } + public Date getExpiryDate() { return FUtil.getUnixDate(expiryUnix); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java b/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java index bae05298..5d282ac0 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java @@ -30,6 +30,8 @@ public class BanManager extends FreedomService private final Map ipBans = Maps.newHashMap(); private final Map nameBans = Maps.newHashMap(); private final List unbannableUsernames = Lists.newArrayList(); + public static final String CONFIG_FILENAME = "bans.yml"; + // private final YamlConfig config; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/banning/PermbanList.java b/src/main/java/me/totalfreedom/totalfreedommod/banning/PermbanList.java index 8803d6d2..a360e55c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/banning/PermbanList.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/banning/PermbanList.java @@ -87,4 +87,13 @@ public class PermbanList extends FreedomService } + public Set getPermbannedNames() + { + return this.permbannedNames; + } + + public Set getPermbannedIps() + { + return this.permbannedIps; + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java index bd469ed1..a8623ada 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java @@ -44,14 +44,11 @@ public class BlockBlocker extends FreedomService 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; @@ -62,8 +59,6 @@ public class BlockBlocker extends FreedomService 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 { @@ -79,14 +74,11 @@ public class BlockBlocker extends FreedomService 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; @@ -96,23 +88,13 @@ public class BlockBlocker extends FreedomService 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; } case STRUCTURE_BLOCK: - case STRUCTURE_VOID: { player.sendMessage(ChatColor.GRAY + "Structure blocks are disabled."); - + player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); event.setCancelled(true); break; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java index 90ead70d..9a30217d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java @@ -12,12 +12,16 @@ 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.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.block.BlockRedstoneEvent; 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.FireworkExplodeEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.player.PlayerDropItemEvent; @@ -71,7 +75,7 @@ public class EventBlocker extends FreedomService { if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) { - event.setCancelled(true); + event.blockList().clear(); return; } @@ -107,22 +111,28 @@ public class EventBlocker extends FreedomService event.setDroppedExp(0); } } + + //deprecated (buggy) - @EventHandler(priority = EventPriority.HIGH) + /* @EventHandler(priority = EventPriority.HIGH) public void onProjectileHit(ProjectileHitEvent event) { - if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) + if (ConfigEntry.MAKE_ARROW_EXPLOSIVE.getBoolean()) { Projectile entity = event.getEntity(); - if (event.getEntityType() == EntityType.ARROW) + if (entity instanceof Projectile) { - entity.getWorld().createExplosion(entity.getLocation(), 2F); + if (event.getEntityType() == EntityType.ARROW) + { + entity.getWorld().createExplosion(entity.getLocation(), 2F); + } } } - } + }*/ @EventHandler(priority = EventPriority.HIGH) - public void onEntityDamage(EntityDamageEvent event) + public void onEntityDamage(EntityDamageEvent event + ) { switch (event.getCause()) { @@ -150,7 +160,8 @@ public class EventBlocker extends FreedomService } @EventHandler(priority = EventPriority.NORMAL) - public void onPlayerDropItem(PlayerDropItemEvent event) + public void onPlayerDropItem(PlayerDropItemEvent event + ) { if (!ConfigEntry.AUTO_ENTITY_WIPE.getBoolean()) { @@ -164,9 +175,47 @@ public class EventBlocker extends FreedomService } @EventHandler(priority = EventPriority.NORMAL) - public void onLeavesDecay(LeavesDecayEvent event) + public void onLeavesDecay(LeavesDecayEvent event + ) { event.setCancelled(true); } + @EventHandler(priority = EventPriority.HIGH) + public void FireworkExplodeEvent(final FireworkExplodeEvent event + ) + { + if (!ConfigEntry.ALLOW_FIREWORK_EXPLOSION.getBoolean()) + { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void BlockPistonRetractEvent(final BlockPistonRetractEvent event) + { + if (!ConfigEntry.ALLOW_REDSTONE.getBoolean()) + { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void BlockPistonExtendEvent(final BlockPistonExtendEvent event) + { + if (!ConfigEntry.ALLOW_REDSTONE.getBoolean()) + { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void BlockRedstoneEvent(final BlockRedstoneEvent event) + { + if (!ConfigEntry.ALLOW_REDSTONE.getBoolean()) + { + event.setNewCurrent(0); + } + } + } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/MobBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/MobBlocker.java index e9efce7b..0c0a2a0c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/MobBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/MobBlocker.java @@ -10,6 +10,7 @@ import org.bukkit.entity.Ghast; import org.bukkit.entity.Giant; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Slime; +import org.bukkit.entity.Wither; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.CreatureSpawnEvent; @@ -65,40 +66,47 @@ public class MobBlocker extends FreedomService return; } } - else if (spawned instanceof Giant) + else if (spawned instanceof Wither) { - if (ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean()) + if (ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.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)) + else if (spawned instanceof Giant) { - mobcount++; + 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); } } - - if (mobcount > mobLimiterMax) - { - event.setCancelled(true); - } } - } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlockerEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlockerEntry.java index ff40ce12..b57fbfb6 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlockerEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlockerEntry.java @@ -20,36 +20,49 @@ public class CommandBlockerEntry private final String subCommand; @Getter private final String message; - - public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String message) - { + + public CommandBlockerEntry(final CommandBlockerRank rank, final CommandBlockerAction action, final String command, final String message) { this(rank, action, command, null, message); } - - public CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String subCommand, String message) - { + + public CommandBlockerEntry(final CommandBlockerRank rank, final CommandBlockerAction action, final String command, final String subCommand, final 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); + 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) - { - TotalFreedomMod.plugin().ae.autoEject((Player) sender, "You used a prohibited command: " + command); + + public void doActions(final CommandSender sender) { + if (this.action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player) { + TotalFreedomMod.plugin().ae.autoEject((Player)sender, "You used a prohibited command: " + this.command); FUtil.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED); return; } - - if (action == CommandBlockerAction.BLOCK_UNKNOWN) - { + if (this.action == CommandBlockerAction.BLOCK_UNKNOWN) { FUtil.playerMsg(sender, "Unknown command. Type \"help\" for help.", ChatColor.RESET); return; } - - FUtil.playerMsg(sender, FUtil.colorize(message)); + FUtil.playerMsg(sender, FUtil.colorize(this.message)); + } + + public CommandBlockerRank getRank() { + return this.rank; + } + + public CommandBlockerAction getAction() { + return this.action; + } + + public String getCommand() { + return this.command; + } + + public String getSubCommand() { + return this.subCommand; + } + + public String getMessage() { + return this.message; } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java new file mode 100644 index 00000000..83719f5a --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java @@ -0,0 +1,259 @@ +package me.totalfreedom.totalfreedommod.bridge; + +import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import net.coreprotect.CoreProtect; +import net.coreprotect.CoreProtectAPI; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.plugin.Plugin; +import org.bukkit.World; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.plugin.PluginManager; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.ResultSet; +import java.io.File; +import java.util.List; +import java.util.Arrays; +import me.totalfreedom.totalfreedommod.util.FUtil; + +public class CoreProtectBridge extends FreedomService +{ + private CoreProtectAPI coreProtectAPI = null; + + private final List tables = Arrays.asList("co_sign", "co_session", "co_container", "co_block"); + + private BukkitTask wiper; + + public CoreProtectBridge(TotalFreedomMod plugin) + { + super(plugin); + } + + @Override + protected void onStart() + { + if (ConfigEntry.COREPROTECT_AUTO_WIPING_ENABLED.getBoolean() && getCoreProtect() != null) + { + createAutomaticWiper(); + } + } + + @Override + protected void onStop() + { + } + + public CoreProtect getCoreProtect() + { + CoreProtect coreProtect = null; + try + { + final Plugin coreProtectPlugin = Bukkit.getServer().getPluginManager().getPlugin("CoreProtect"); + + if (coreProtectPlugin != null && coreProtectPlugin instanceof CoreProtect) + { + coreProtect = (CoreProtect)coreProtectPlugin; + } + } + catch (Exception ex) + { + FLog.severe(ex); + } + return coreProtect; + } + + public CoreProtectAPI getCoreProtectAPI() + { + if (coreProtectAPI == null) + { + try + { + final CoreProtect coreProtect = getCoreProtect(); + + coreProtectAPI = coreProtect.getAPI(); + + // Check if the plugin or api is not enabled, if so, return null + if (!coreProtect.isEnabled() || !coreProtectAPI.isEnabled()) + { + return null; + } + } + catch (Exception ex) + { + FLog.severe(ex); + } + } + + return coreProtectAPI; + } + + public boolean isEnabled() + { + final CoreProtect coreProtect = getCoreProtect(); + + return coreProtect != null && coreProtect.isEnabled(); + } + + // Rollback the specifed player's edits that were in the last 24 hours. + public void rollback(final String name) + { + final CoreProtectAPI coreProtect = getCoreProtectAPI(); + + if (!isEnabled()) + { + return; + } + + new BukkitRunnable() + { + @Override + public void run() + { + coreProtect.performRollback(86400, Arrays.asList(name), null, null, null, null, 0, null); + } + }.runTaskAsynchronously(plugin); + } + + // Reverts a rollback for the specifed player's edits that were in the last 24 hours. + public void undoRollback(final String name) + { + final CoreProtectAPI coreProtect = getCoreProtectAPI(); + + if (!isEnabled()) + { + return; + } + + new BukkitRunnable() + { + @Override + public void run() + { + coreProtect.performRestore(86400, Arrays.asList(name), null, null, null, null, 0, null); + } + }.runTaskAsynchronously(plugin); + } + + public File getDatabase() + { + if (!isEnabled()) + { + return null; + } + + return(new File(getCoreProtect().getDataFolder(), "database.db")); + } + + private void createAutomaticWiper() + { + final long interval = 10 * 20L; + final File databaseFile = getDatabase(); + + wiper = new BukkitRunnable() + { + @Override + public void run() + { + final CoreProtect coreProtect = getCoreProtect(); + if (getDBSize() > ConfigEntry.COREPROTECT_FILE_LIMIT.getInteger()) + { + FLog.info("The CoreProtect log file has grown too big for the server to cope, the data is being wiped!"); + FUtil.bcastMsg("The CoreProtect log file has grown too big for the server to cope, the data is being wiped!", ChatColor.RED); + PluginManager pluginManager = server.getPluginManager(); + pluginManager.disablePlugin(coreProtect); + for(World world : Bukkit.getWorlds()) + { + if(!world.equals(plugin.wm.adminworld.getWorld())) + { + clearDatabase(world); + } + } + //check if still too big, if so delete all data + if(getDBSize() > ConfigEntry.COREPROTECT_FILE_LIMIT.getInteger()) + { + FUtil.deleteFolder(databaseFile); + } + pluginManager.enablePlugin(coreProtect); + } + } + }.runTaskTimer(plugin, interval, interval); + } + public double getDBSize() + { + double bytes = getDatabase().length(); + double kilobytes = (bytes / 1024); + double megabytes = (kilobytes / 1024); + return (megabytes / 1024); + } + // Wipes DB for the specified world + public void clearDatabase(World world) + { + clearDatabase(world, false); + } + + // Wipes DB for the specified world + public void clearDatabase(World world, Boolean shutdown) + { + final CoreProtect coreProtect = getCoreProtect(); + + if (coreProtect == null) + { + return; + } + + /* As CoreProtect doesn't have an api method for deleting all of the data for a specific world + we have to do this manually via sql */ + File databaseFile = getDatabase(); + Connection connection = null; + try + { + connection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile); + final Statement statement = connection.createStatement(); + statement.setQueryTimeout(30); + + // Obtain world ID from CoreProtect database + ResultSet resultSet = statement.executeQuery("SELECT id FROM co_world WHERE world = '" + world.getName() + "'"); + String worldID = null; + while (resultSet.next()) + { + worldID = String.valueOf(resultSet.getInt("id")); + } + + // Ensure the world ID is not null + if (worldID == null) + { + FLog.warning("Failed to obtain the world ID for the " + world.getName()); + return; + } + + // Iterate through each table and delete their data if the world ID matches + for (String table : tables) + { + statement.executeUpdate("DELETE FROM " + table + " WHERE wid = " + worldID); + } + + // This shrinks down the file size + statement.executeUpdate("VACUUM"); + + connection.close(); + + } + catch (SQLException e) + { + FLog.warning("Failed to delete the CoreProtect data for the " + world.getName()); + } + + // This exits for flatlands wipes + if (shutdown) + { + server.shutdown(); + } + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java index a3859c05..2fe4b2a3 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java @@ -1,137 +1,191 @@ + + package me.totalfreedom.totalfreedommod.bridge; -import com.earth2me.essentials.Essentials; -import com.earth2me.essentials.User; -import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; -import me.totalfreedom.totalfreedommod.util.FLog; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.EventPriority; +import org.bukkit.event.EventHandler; +import me.totalfreedom.totalfreedommod.rank.Rank; +import org.bukkit.inventory.InventoryHolder; +import me.totalfreedom.totalfreedommod.player.FPlayer; +import org.bukkit.inventory.Inventory; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.entity.HumanEntity; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryClickEvent; import me.totalfreedom.totalfreedommod.util.FUtil; -import org.bukkit.Bukkit; +import com.earth2me.essentials.User; import org.bukkit.plugin.Plugin; +import me.totalfreedom.totalfreedommod.util.FLog; +import org.bukkit.Bukkit; +import me.totalfreedom.totalfreedommod.command.Command_vanish; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import com.earth2me.essentials.Essentials; +import me.totalfreedom.totalfreedommod.FreedomService; public class EssentialsBridge extends FreedomService { - - private Essentials essentialsPlugin = null; - - public EssentialsBridge(TotalFreedomMod plugin) - { + private Essentials essentialsPlugin; + + public EssentialsBridge(final TotalFreedomMod plugin) { super(plugin); + this.essentialsPlugin = null; } - - @Override - protected void onStart() - { + + protected void onStart() { } - - @Override - protected void onStop() - { + + protected void onStop() { + Command_vanish.vanished.clear(); } - - public Essentials getEssentialsPlugin() - { - if (essentialsPlugin == null) - { - try - { + + public Essentials getEssentialsPlugin() { + if (this.essentialsPlugin == null) { + try { final Plugin essentials = Bukkit.getServer().getPluginManager().getPlugin("Essentials"); - if (essentials != null) - { - if (essentials instanceof Essentials) - { - essentialsPlugin = (Essentials) essentials; - } + if (essentials != null && essentials instanceof Essentials) { + this.essentialsPlugin = (Essentials)essentials; } } - catch (Exception ex) - { + catch (Exception ex) { FLog.severe(ex); } } - return essentialsPlugin; + return this.essentialsPlugin; } - - public User getEssentialsUser(String username) - { - try - { - final Essentials essentials = getEssentialsPlugin(); - if (essentials != null) - { + + public User getEssentialsUser(final String username) { + try { + final Essentials essentials = this.getEssentialsPlugin(); + if (essentials != null) { return essentials.getUserMap().getUser(username); } } - catch (Exception ex) - { + catch (Exception ex) { FLog.severe(ex); } return null; } - - public void setNickname(String username, String nickname) - { - try - { - final User user = getEssentialsUser(username); - if (user != null) - { + + public void setNickname(final String username, final String nickname) { + try { + final User user = this.getEssentialsUser(username); + if (user != null) { user.setNickname(nickname); user.setDisplayNick(); } } - catch (Exception ex) - { + catch (Exception ex) { FLog.severe(ex); } } - - public String getNickname(String username) - { - try - { - final User user = getEssentialsUser(username); - if (user != null) - { + + public String getNickname(final String username) { + try { + final User user = this.getEssentialsUser(username); + if (user != null) { return user.getNickname(); } } - catch (Exception ex) - { + catch (Exception ex) { FLog.severe(ex); } return null; } - - public long getLastActivity(String username) - { - try - { - final User user = getEssentialsUser(username); - if (user != null) - { - return FUtil.getField(user, "lastActivity"); // This is weird + + public long getLastActivity(final String username) { + try { + final User user = this.getEssentialsUser(username); + if (user != null) { + return FUtil.getField(user, "lastActivity"); } } - catch (Exception ex) - { + catch (Exception ex) { FLog.severe(ex); } return 0L; } - - public boolean isEssentialsEnabled() - { - try - { - final Essentials essentials = getEssentialsPlugin(); - if (essentials != null) - { + + public void setVanished(final String username, final boolean vanished) { + try { + final User user = this.getEssentialsUser(username); + if (user != null) { + user.setVanished(vanished); + } + } + catch (Exception ex) { + FLog.severe(ex); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onInventoryClickEvent(final InventoryClickEvent event) { + Player refreshPlayer = null; + final Inventory top = event.getView().getTopInventory(); + final InventoryType type = top.getType(); + final Player playerdata = (Player)event.getWhoClicked(); + final FPlayer fPlayer = ((TotalFreedomMod)this.plugin).pl.getPlayer(playerdata); + if (type == InventoryType.PLAYER && fPlayer.isInvsee()) { + final InventoryHolder invHolder = top.getHolder(); + if (invHolder != null && invHolder instanceof HumanEntity) { + final Player invOwner = (Player)invHolder; + final Rank recieverRank = ((TotalFreedomMod)this.plugin).rm.getRank(playerdata); + final Rank playerRank = ((TotalFreedomMod)this.plugin).rm.getRank(invOwner); + if (playerRank.ordinal() >= recieverRank.ordinal() || !invOwner.isOnline()) { + event.setCancelled(true); + refreshPlayer = playerdata; + } + } + } + if (refreshPlayer != null) { + final Player player = refreshPlayer; + new BukkitRunnable() { + public void run() { + player.updateInventory(); + } + }.runTaskLater((Plugin)this.plugin, 20L); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onInventoryCloseEvent(final InventoryCloseEvent event) { + Player refreshPlayer = null; + final Inventory top = event.getView().getTopInventory(); + final InventoryType type = top.getType(); + final Player playerdata = (Player)event.getPlayer(); + final FPlayer fPlayer = ((TotalFreedomMod)this.plugin).pl.getPlayer(playerdata); + if (type == InventoryType.PLAYER && fPlayer.isInvsee()) { + fPlayer.setInvsee(false); + refreshPlayer = playerdata; + } + if (refreshPlayer != null) { + final Player player = refreshPlayer; + new BukkitRunnable() { + public void run() { + player.updateInventory(); + } + }.runTaskLater((Plugin)this.plugin, 20L); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerQuitEvent(final PlayerQuitEvent event) { + final Player player = event.getPlayer(); + if (Command_vanish.vanished.contains(player)) { + Command_vanish.vanished.remove(player); + } + } + + public boolean isEssentialsEnabled() { + try { + final Essentials essentials = this.getEssentialsPlugin(); + if (essentials != null) { return essentials.isEnabled(); } } - catch (Exception ex) - { + catch (Exception ex) { FLog.severe(ex); } return false; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/LibsDisguisesBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/LibsDisguisesBridge.java index 256fca0e..307bdc05 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/LibsDisguisesBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/LibsDisguisesBridge.java @@ -1,8 +1,8 @@ package me.totalfreedom.totalfreedommod.bridge; -//import me.libraryaddict.disguise.DisallowedDisguises; -//import me.libraryaddict.disguise.LibsDisguises; -//import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.DisallowedDisguises; +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.LibsDisguises; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.util.FLog; @@ -13,7 +13,7 @@ import org.bukkit.plugin.Plugin; public class LibsDisguisesBridge extends FreedomService { - // private LibsDisguises libsDisguisesPlugin = null; + private LibsDisguises libsDisguisesPlugin = null; public LibsDisguisesBridge(TotalFreedomMod plugin) { @@ -29,7 +29,7 @@ public class LibsDisguisesBridge extends FreedomService protected void onStop() { } -/* + public LibsDisguises getLibsDisguisesPlugin() { if (libsDisguisesPlugin == null) @@ -134,5 +134,5 @@ public class LibsDisguisesBridge extends FreedomService } return ld.isEnabled(); - }*/ + } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/caging/CageData.java b/src/main/java/me/totalfreedom/totalfreedommod/caging/CageData.java index 53e4c903..29a9c74f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/caging/CageData.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/caging/CageData.java @@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.caging; import java.util.ArrayList; import java.util.List; import lombok.Getter; +import me.totalfreedom.totalfreedommod.command.Command_cage; import me.totalfreedom.totalfreedommod.player.FPlayer; import org.bukkit.Location; import org.bukkit.Material; @@ -187,7 +188,7 @@ public class CageData block.setType(Material.SKULL); final Skull skull = (Skull) block.getState(); skull.setSkullType(SkullType.PLAYER); - skull.setOwner("Prozza"); + skull.setOwner(Command_cage.playerSkullName); skull.update(); } } @@ -195,6 +196,26 @@ public class CageData } } + public boolean isCaged() + { + return this.caged; + } + + public Location getLocation() + { + return this.location; + } + + public Material getOuterMaterial() + { + return this.outerMaterial; + } + + public Material getInnerMaterial() + { + return this.innerMaterial; + } + private static class BlockData { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/CommandFailException.java b/src/main/java/me/totalfreedom/totalfreedommod/command/CommandFailException.java index 64025aea..9792fd48 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/CommandFailException.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/CommandFailException.java @@ -10,4 +10,4 @@ public class CommandFailException extends RuntimeException super(message); } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java b/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java index 78a48045..0a6e60d4 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java @@ -42,4 +42,4 @@ public class CommandLoader extends FreedomService handler.clearCommands(); } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/CommandParameters.java b/src/main/java/me/totalfreedom/totalfreedommod/command/CommandParameters.java index db7a5ae3..bae0e188 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/CommandParameters.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/CommandParameters.java @@ -12,4 +12,4 @@ public @interface CommandParameters String usage(); String aliases() default ""; // "alias1,alias2,alias3" - no spaces -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/CommandPermissions.java b/src/main/java/me/totalfreedom/totalfreedommod/command/CommandPermissions.java index c587593e..0fe15b70 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/CommandPermissions.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/CommandPermissions.java @@ -13,4 +13,4 @@ public @interface CommandPermissions SourceType source(); boolean blockHostConsole() default false; -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java index f25b402f..dfbda626 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java @@ -11,7 +11,8 @@ import org.bukkit.entity.Player; @CommandPermissions(level = Rank.OP, source = SourceType.BOTH) @CommandParameters(description = "Go to the AdminWorld.", - usage = "/ [guest < list | purge | add | remove > | time | weather ]") + usage = "/ [guest < list | purge | add | remove > | time | weather ]", + aliases = "aw") public class Command_adminworld extends FreedomCommand { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockcmd.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockcmd.java index 0699f00b..45aeb662 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockcmd.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockcmd.java @@ -68,7 +68,7 @@ public class Command_blockcmd extends FreedomCommand if (isAdmin(player)) { - msg(player.getName() + " is a Superadmin, and cannot have their commands blocked."); + msg(player.getName() + " is an admin, and cannot have their commands blocked."); return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockedit.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockedit.java new file mode 100644 index 00000000..01434ae9 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockedit.java @@ -0,0 +1,109 @@ + + +package me.totalfreedom.totalfreedommod.command; + +import me.totalfreedom.totalfreedommod.player.FPlayer; +import java.util.Iterator; +import org.bukkit.ChatColor; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.ArrayUtils; +import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import org.bukkit.command.Command; +import org.bukkit.entity.Player; +import org.bukkit.command.CommandSender; +import me.totalfreedom.totalfreedommod.rank.Rank; + +@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) +@CommandParameters(description = "Blocks all block placing for player with brute force.", usage = "/ [[-s] [reason] | list | purge | all]", aliases = "editmute") +public class Command_blockedit extends FreedomCommand +{ + public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, String[] args, final boolean senderIsConsole) { + if (args.length == 0) { + return false; + } + if (args[0].equals("list")) { + this.msg("Block edits blocked for players:"); + int count = 0; + for (final Player mp : this.server.getOnlinePlayers()) { + final FPlayer info = ((TotalFreedomMod)this.plugin).pl.getPlayer(mp); + if (info.isEditBlock()) { + this.msg("- " + mp.getName()); + ++count; + } + } + if (count == 0) { + this.msg("- none"); + } + return true; + } + if (args[0].equals("purge")) { + FUtil.adminAction(sender.getName(), "Unblocking block edits for all players.", true); + int count = 0; + for (final Player mp : this.server.getOnlinePlayers()) { + final FPlayer info = ((TotalFreedomMod)this.plugin).pl.getPlayer(mp); + if (info.isEditBlock()) { + info.setEditBlocked(false); + ++count; + } + } + this.msg("Unblocked all block edit for " + count + " players."); + return true; + } + if (args[0].equals("all")) { + FUtil.adminAction(sender.getName(), "Blocking block edits for all non-admins.", true); + int counter = 0; + for (final Player player : this.server.getOnlinePlayers()) { + if (!((TotalFreedomMod)this.plugin).al.isAdmin((CommandSender)player)) { + final FPlayer playerdata = ((TotalFreedomMod)this.plugin).pl.getPlayer(player); + playerdata.setEditBlocked(true); + ++counter; + } + } + this.msg("Blocked block edits for " + counter + " players."); + return true; + } + final boolean smite = args[0].equals("-s"); + if (smite) { + args = (String[])ArrayUtils.subarray((Object[])args, 1, args.length); + if (args.length < 1) { + return false; + } + } + final Player player2 = this.getPlayer(args[0]); + if (player2 == null) { + sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND); + return true; + } + String reason = null; + if (args.length > 1) { + reason = StringUtils.join((Object[])args, " ", 1, args.length); + } + final FPlayer playerdata2 = ((TotalFreedomMod)this.plugin).pl.getPlayer(player2); + if (playerdata2.isEditBlock()) { + FUtil.adminAction(sender.getName(), "Unblocking block edits for " + player2.getName(), true); + playerdata2.setEditBlocked(false); + this.msg("Unblocking block edits for " + player2.getName()); + this.msg((CommandSender)player2, "Your block edits have been unblocked.", ChatColor.RED); + } + else { + if (((TotalFreedomMod)this.plugin).al.isAdmin((CommandSender)player2)) { + this.msg(player2.getName() + " is an admin, and cannot have their block edits blocked."); + return true; + } + FUtil.adminAction(sender.getName(), "Blocking block edits for " + player2.getName(), true); + playerdata2.setEditBlocked(true); + if (smite) { + Command_smite.smite(player2, sender); + } + if (reason != null) { + this.msg((CommandSender)player2, "Your block edits have been blocked. Reason: " + reason, ChatColor.RED); + } + else { + this.msg((CommandSender)player2, "Your block edits have been blocked.", ChatColor.RED); + } + this.msg("Blocked all block edits for " + player2.getName()); + } + return true; + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockpvp.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockpvp.java new file mode 100644 index 00000000..911f9c4f --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockpvp.java @@ -0,0 +1,109 @@ + + +package me.totalfreedom.totalfreedommod.command; + +import me.totalfreedom.totalfreedommod.player.FPlayer; +import java.util.Iterator; +import org.bukkit.ChatColor; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.ArrayUtils; +import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import org.bukkit.command.Command; +import org.bukkit.entity.Player; +import org.bukkit.command.CommandSender; +import me.totalfreedom.totalfreedommod.rank.Rank; + +@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) +@CommandParameters(description = "Toggle PVP mode for players.", usage = "/ [[-s] [reason] | list | purge | all]", aliases = "pvpblock,pvpmode,pvpman,pvman") +public class Command_blockpvp extends FreedomCommand +{ + public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, String[] args, final boolean senderIsConsole) { + if (args.length == 0) { + return false; + } + if (args[0].equals("list")) { + this.msg("PVP is blocked for players:"); + int count = 0; + for (final Player mp : this.server.getOnlinePlayers()) { + final FPlayer info = ((TotalFreedomMod)this.plugin).pl.getPlayer(mp); + if (info.isPVPBlock()) { + this.msg("- " + mp.getName()); + ++count; + } + } + if (count == 0) { + this.msg("- none"); + } + return true; + } + if (args[0].equals("purge")) { + FUtil.adminAction(sender.getName(), "Enabling PVP for all players.", true); + int count = 0; + for (final Player mp : this.server.getOnlinePlayers()) { + final FPlayer info = ((TotalFreedomMod)this.plugin).pl.getPlayer(mp); + if (info.isPVPBlock()) { + info.setPVPBlock(false); + ++count; + } + } + this.msg("Enabled PVP for " + count + " players."); + return true; + } + if (args[0].equals("all")) { + FUtil.adminAction(sender.getName(), "Disabling PVP for all non-admins", true); + int counter = 0; + for (final Player player : this.server.getOnlinePlayers()) { + if (!((TotalFreedomMod)this.plugin).al.isAdmin((CommandSender)player)) { + final FPlayer playerdata = ((TotalFreedomMod)this.plugin).pl.getPlayer(player); + playerdata.setPVPBlock(true); + ++counter; + } + } + this.msg("Disabling PVP for " + counter + " players."); + return true; + } + final boolean smite = args[0].equals("-s"); + if (smite) { + args = (String[])ArrayUtils.subarray((Object[])args, 1, args.length); + if (args.length < 1) { + return false; + } + } + final Player player2 = this.getPlayer(args[0]); + if (player2 == null) { + sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND); + return true; + } + String reason = null; + if (args.length > 1) { + reason = StringUtils.join((Object[])args, " ", 1, args.length); + } + final FPlayer playerdata2 = ((TotalFreedomMod)this.plugin).pl.getPlayer(player2); + if (playerdata2.isPVPBlock()) { + FUtil.adminAction(sender.getName(), "Enabling PVP for " + player2.getName(), true); + playerdata2.setPVPBlock(false); + this.msg("Enabling PVP for " + player2.getName()); + this.msg((CommandSender)player2, "Your PVP have been enabled.", ChatColor.GREEN); + } + else { + if (((TotalFreedomMod)this.plugin).al.isAdmin((CommandSender)player2)) { + this.msg(player2.getName() + " is an admin, and his PVP cannot be disabled."); + return true; + } + FUtil.adminAction(sender.getName(), "Disabling PVP for " + player2.getName(), true); + playerdata2.setPVPBlock(true); + if (smite) { + Command_smite.smite(player2, sender); + } + if (reason != null) { + this.msg((CommandSender)player2, "Your PVP has been disabled. Reason: " + reason, ChatColor.RED); + } + else { + this.msg((CommandSender)player2, "Your PVP has been disabled.", ChatColor.RED); + } + this.msg("Disabled PVP for " + player2.getName()); + } + return true; + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockredstone.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockredstone.java new file mode 100644 index 00000000..c1661327 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockredstone.java @@ -0,0 +1,42 @@ +package me.totalfreedom.totalfreedommod.command; + +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; +import me.totalfreedom.totalfreedommod.util.FUtil; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import org.bukkit.command.Command; +import org.bukkit.entity.Player; +import org.bukkit.command.CommandSender; +import me.totalfreedom.totalfreedommod.rank.Rank; + +@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) +@CommandParameters(description = "Blocks redstone on the server.", usage = "/", aliases = "bre") +public class Command_blockredstone extends FreedomCommand +{ + + public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole) + { + if (ConfigEntry.ALLOW_REDSTONE.getBoolean()) + { + ConfigEntry.ALLOW_REDSTONE.setBoolean(false); + FUtil.adminAction(sender.getName(), "Blocking all redstone", true); + new BukkitRunnable() + { + public void run() + { + if (!ConfigEntry.ALLOW_REDSTONE.getBoolean()) + { + FUtil.adminAction("TotalFreedom", "Unblocking all redstone", false); + ConfigEntry.ALLOW_REDSTONE.setBoolean(true); + } + } + }.runTaskLater((Plugin) this.plugin, 6000L); + } + else + { + ConfigEntry.ALLOW_REDSTONE.setBoolean(true); + FUtil.adminAction(sender.getName(), "Unblocking all redstone", true); + } + return true; + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java index 3c2d466d..baa58b46 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java @@ -1,8 +1,10 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -11,100 +13,77 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) -@CommandParameters(description = "Place a cage around someone.", usage = "/ [outermaterial] [innermaterial]>") +@CommandParameters(description = "Place a cage around someone.", usage = "/ [skull | block] [blockname | skullname]") public class Command_cage extends FreedomCommand { - - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length == 0) - { + public static String playerSkullName; + + public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole) { + if (args.length == 0) { return false; } - - if ("off".equals(args[0]) && sender instanceof Player) - { + if ("off".equals(args[0]) && sender instanceof Player) { FUtil.adminAction(sender.getName(), "Uncaging " + sender.getName(), true); - FPlayer playerdata = plugin.pl.getPlayer(playerSender); - + final FPlayer playerdata = ((TotalFreedomMod)this.plugin).pl.getPlayer(playerSender); playerdata.getCageData().setCaged(false); return true; } - else if ("purge".equals(args[0])) - { + if ("purge".equals(args[0])) { FUtil.adminAction(sender.getName(), "Uncaging all players", true); - - for (Player player : server.getOnlinePlayers()) - { - FPlayer playerdata = plugin.pl.getPlayer(player); - playerdata.getCageData().setCaged(false); + for (final Player player : this.server.getOnlinePlayers()) { + final FPlayer playerdata2 = ((TotalFreedomMod)this.plugin).pl.getPlayer(player); + playerdata2.getCageData().setCaged(false); } - return true; } - - final Player player = getPlayer(args[0]); - - if (player == null) - { + final Player player2 = this.getPlayer(args[0]); + if (player2 == null) { sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND); return true; } - - FPlayer playerdata = plugin.pl.getPlayer(player); - + final FPlayer playerdata3 = ((TotalFreedomMod)this.plugin).pl.getPlayer(player2); Material outerMaterial = Material.GLASS; Material innerMaterial = Material.AIR; - - if (args.length >= 2) - { - if ("off".equals(args[1])) - { - FUtil.adminAction(sender.getName(), "Uncaging " + player.getName(), true); - playerdata.getCageData().setCaged(false); - - return true; - } - else - { - if ("darth".equalsIgnoreCase(args[1])) - { - outerMaterial = Material.SKULL; + if (args.length >= 2 && null != args[1]) { + final String s = args[1]; + switch (s) { + case "off": { + FUtil.adminAction(sender.getName(), "Uncaging " + player2.getName(), true); + playerdata3.getCageData().setCaged(false); + return true; } - else if (Material.matchMaterial(args[1]) != null) - { - outerMaterial = Material.matchMaterial(args[1]); + case "skull": { + outerMaterial = Material.SKULL; + Command_cage.playerSkullName = args[2]; + break; + } + case "block": { + if (Material.matchMaterial(args[2]) != null) { + outerMaterial = Material.matchMaterial(args[2]); + break; + } + sender.sendMessage(ChatColor.RED + "Invalid block!"); + break; } } } - - if (args.length >= 3) - { - if (args[2].equalsIgnoreCase("water")) - { + if (args.length >= 3) { + if (args[2].equalsIgnoreCase("water")) { innerMaterial = Material.STATIONARY_WATER; } - else if (args[2].equalsIgnoreCase("lava")) - { + else if (args[2].equalsIgnoreCase("lava")) { innerMaterial = Material.STATIONARY_LAVA; } } - - Location targetPos = player.getLocation().clone().add(0, 1, 0); - playerdata.getCageData().cage(targetPos, outerMaterial, innerMaterial); - - player.setGameMode(GameMode.SURVIVAL); - - if (outerMaterial != Material.SKULL) - { - FUtil.adminAction(sender.getName(), "Caging " + player.getName(), true); + final Location targetPos = player2.getLocation().clone().add(0.0, 1.0, 0.0); + playerdata3.getCageData().cage(targetPos, outerMaterial, innerMaterial); + player2.setGameMode(GameMode.SURVIVAL); + if (outerMaterial != Material.SKULL) { + FUtil.adminAction(sender.getName(), "Caging " + player2.getName(), true); } - else - { - FUtil.adminAction(sender.getName(), "Caging " + player.getName() + " in PURE_DARTH", true); + else { + FUtil.adminAction(sender.getName(), "Caging " + player2.getName() + " in " + Command_cage.playerSkullName, true); } - return true; } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cake.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cake.java index 0178ce10..5e46d3ab 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cake.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cake.java @@ -1,54 +1,49 @@ + + package me.totalfreedom.totalfreedommod.command; -import java.util.Random; -import me.totalfreedom.totalfreedommod.rank.Rank; -import me.totalfreedom.totalfreedommod.util.FUtil; +import java.util.Iterator; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.Achievement; import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.Material; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.command.Command; +import org.bukkit.entity.Player; +import org.bukkit.command.CommandSender; +import java.util.Random; +import me.totalfreedom.totalfreedommod.rank.Rank; @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "For the people that are still alive.", usage = "/") public class Command_cake extends FreedomCommand { - public static final String CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake."; - private final Random random = new Random(); - - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { + private final Random random; + + public Command_cake() { + this.random = new Random(); + } + + public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole) { final StringBuilder output = new StringBuilder(); - - final String[] words = CAKE_LYRICS.split(" "); - for (final String word : words) - { - output.append(ChatColor.COLOR_CHAR).append(Integer.toHexString(1 + random.nextInt(14))).append(word).append(" "); + final String[] split; + final String[] words = split = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake.".split(" "); + for (final String word : split) { + output.append(FUtil.rainbowChatColor()).append(word).append(" "); } - final ItemStack heldItem = new ItemStack(Material.CAKE); final ItemMeta heldItemMeta = heldItem.getItemMeta(); - heldItemMeta.setDisplayName((new StringBuilder()).append(ChatColor.WHITE).append("The ").append(ChatColor.DARK_GRAY).append("Lie").toString()); + heldItemMeta.setDisplayName(ChatColor.WHITE + "The " + ChatColor.DARK_GRAY + "Lie"); heldItem.setItemMeta(heldItemMeta); - - for (final Player player : server.getOnlinePlayers()) - { + for (final Player player : this.server.getOnlinePlayers()) { final int firstEmpty = player.getInventory().firstEmpty(); - if (firstEmpty >= 0) - { + if (firstEmpty >= 0) { player.getInventory().setItem(firstEmpty, heldItem); } - - player.awardAchievement(Achievement.BAKE_CAKE); } - FUtil.bcastMsg(output.toString()); - return true; } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_chestspy.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_chestspy.java new file mode 100644 index 00000000..2878c25e --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_chestspy.java @@ -0,0 +1,24 @@ +package me.totalfreedom.totalfreedommod.command; + +import me.totalfreedom.totalfreedommod.player.FPlayer; +import me.totalfreedom.totalfreedommod.rank.Rank; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME) +@CommandParameters(description = "Spy on Chest Movements", usage = "/", aliases = "chspy") +public class Command_chestspy extends FreedomCommand +{ + + @Override + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + + FPlayer playerdata = plugin.pl.getPlayer(playerSender); + playerdata.setChestMonitor(!playerdata.ChestMonitorEnabled()); + msg("ChestSpy " + (playerdata.ChestMonitorEnabled()? "enabled." : "disabled.")); + + return true; + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_disguisetoggle.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_disguisetoggle.java index ac31a704..ba14f785 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_disguisetoggle.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_disguisetoggle.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; //import me.libraryaddict.disguise.DisallowedDisguises; +import me.libraryaddict.disguise.DisallowedDisguises; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.command.Command; @@ -15,7 +16,7 @@ public class Command_disguisetoggle extends FreedomCommand @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - {/* + { if (!plugin.ldb.isPluginEnabled()) { msg(ChatColor.RED + "LibsDisguises is not enabled."); @@ -23,7 +24,7 @@ public class Command_disguisetoggle extends FreedomCommand } FUtil.adminAction(sender.getName(), (DisallowedDisguises.disabled ? "Enabling" : "Disabling") + " " + - "Disguises", false); + "disguises.", false); if (plugin.ldb.isDisguisesEnabled()) { @@ -38,10 +39,5 @@ public class Command_disguisetoggle extends FreedomCommand msg("Disguises are now " + (!DisallowedDisguises.disabled ? "enabled." : "disabled.")); return true; - -*/ - - msg("This command has been disabled for technical reasons. Contact a developer for additional information."); - return true; } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java index 61e6306d..55de2a64 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java @@ -83,7 +83,7 @@ public class Command_doom extends FreedomCommand public void run() { // strike lightning - player.getWorld().strikeLightning(player.getLocation()); + player.getWorld().strikeLightningEffect(player.getLocation()); // kill (if not done already) player.setHealth(0.0); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_dropspy.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_dropspy.java new file mode 100644 index 00000000..1f5b6d1d --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_dropspy.java @@ -0,0 +1,24 @@ +package me.totalfreedom.totalfreedommod.command; + +import me.totalfreedom.totalfreedommod.player.FPlayer; +import me.totalfreedom.totalfreedommod.rank.Rank; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME) +@CommandParameters(description = "Spy on Dropped Items", usage = "/", aliases = "dropspy") +public class Command_dropspy extends FreedomCommand +{ + + @Override + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + + FPlayer playerdata = plugin.pl.getPlayer(playerSender); + playerdata.setDropMonitor(!playerdata.DropMonitorEnabled()); + msg("DropSpy " + (playerdata.DropMonitorEnabled() ? "enabled." : "disabled.")); + + return true; + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gadmin.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gadmin.java index dad4ee07..adb3e44e 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gadmin.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gadmin.java @@ -198,7 +198,7 @@ public class Command_gadmin extends FreedomCommand } case SMITE: { - Command_smite.smite(target); + Command_smite.smite(target, sender); break; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_glist.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_glist.java index 016abe73..5c38c644 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_glist.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_glist.java @@ -11,8 +11,10 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; + + @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true) -@CommandParameters(description = "Bans or unbans any player, even those who are not logged in anymore.", usage = "/ [reason] | unban >") +@CommandParameters(description = "Bans or unbans any player, even those who are not logged in anymore.", usage = "/ [reason] | unban | banip | unbanip | nameban | unbanname >") public class Command_glist extends FreedomCommand { @@ -38,78 +40,158 @@ public class Command_glist extends FreedomCommand return false; } - if (args.length < 2) - { - return false; - } - - String username; - final List ips = new ArrayList<>(); - - final Player player = getPlayer(args[1]); - if (player == null) - { - final PlayerData entry = plugin.pl.getData(args[1]); - - if (entry == null) - { - msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly."); - return true; - } - - username = entry.getUsername(); - ips.addAll(entry.getIps()); - } - else - { - final PlayerData entry = plugin.pl.getData(player); - username = player.getName(); - ips.addAll(entry.getIps()); - } - - if ("ban".equals(args[0])) - { - FUtil.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ", "), true); - - final String reason = args.length > 2 ? StringUtils.join(args, " ", 2, args.length) : null; - - Ban ban = Ban.forPlayerName(username, sender, null, reason); - for (String ip : ips) - { - ban.addIp(ip); - ban.addIp(FUtil.getFuzzyIp(ip)); - } - plugin.bm.addBan(ban); - - if (player != null) - { - player.kickPlayer(ban.bakeKickMessage()); - } - return true; - } - - if ("unban".equals(args[0])) - { - FUtil.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ", "), true); - plugin.bm.removeBan(plugin.bm.getByUsername(username)); - - for (String ip : ips) - { - Ban ban = plugin.bm.getByIp(ip); - if (ban != null) + if (args.length < 2) { - plugin.bm.removeBan(ban); + return false; } - ban = plugin.bm.getByIp(FUtil.getFuzzyIp(ip)); - if (ban != null) + + String username = null; + final List ips = new ArrayList<>(); + boolean usingIp = false; + String banIp = null; + if (args[1].matches("^([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))$") || args[1].matches("^([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\\.([*])\\.([*])$")) { - plugin.bm.removeBan(ban); + usingIp = true; + banIp = args[1]; + } + final Player player = getPlayer(args[1]); + if (!usingIp) + { + if (player == null) + { + final PlayerData entry = plugin.pl.getData(args[1]); + + if (entry == null) + { + msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly."); + return true; + } + + username = entry.getUsername(); + ips.addAll(entry.getIps()); + } + else + { + final PlayerData entry = plugin.pl.getData(player); + username = entry.getUsername(); + ips.addAll(entry.getIps()); + } + } + switch (args[0]) + { + case "ban": + case "gtfo": + if (usingIp) + { + msg("Please specify a player, not an ip."); + return true; + } + final String playerBanReason = args.length > 2 ? StringUtils.join(args, " ", 2, args.length) : null; + Ban playerBan = Ban.forPlayerName(username, sender, null, playerBanReason); + for (String ip : ips) + { + playerBan.addIp(ip); + playerBan.addIp(FUtil.getFuzzyIp(ip)); + } + FUtil.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ", "), true); + + plugin.bm.addBan(playerBan); + + if (player != null) + { + player.kickPlayer(playerBan.bakeKickMessage()); + } + return true; + case "unban": + case "pardon": + if (usingIp) + { + msg("Please specify a player, not an ip."); + return true; + } + FUtil.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ", "), true); + plugin.bm.removeBan(plugin.bm.getByUsername(username)); + + for (String ip : ips) + { + Ban playerUnban = plugin.bm.getByIp(ip); + if (playerUnban != null) + { + plugin.bm.removeBan(playerUnban); + } + playerUnban = plugin.bm.getByIp(FUtil.getFuzzyIp(ip)); + if (playerUnban != null) + { + plugin.bm.removeBan(playerUnban); + } + } + + return true; + case "nameban": + case "banname": + if (usingIp) + { + msg("Please specify a name, not an ip."); + return true; + } + final String nameBanReason = args.length > 2 ? StringUtils.join(args, " ", 2, args.length) : null; + Ban nameBan = Ban.forPlayerName(username, sender, null, nameBanReason); + FUtil.adminAction(sender.getName(), "Banning IGN: " + username, true); + plugin.bm.addBan(nameBan); + + if (player != null) + { + player.kickPlayer(nameBan.bakeKickMessage()); + } + return true; + case "unbanname": + case "nameunban": + if (usingIp) + { + msg("Please specify a name, not an ip."); + return true; + } + FUtil.adminAction(sender.getName(), "Unbanning IGN: " + username, true); + plugin.bm.removeBan(plugin.bm.getByUsername(username)); + return true; + case "banip": + case "ipban": + if (!usingIp) + { + msg("Please specify an IP."); + return true; + } + + final String ipBanReason = args.length > 2 ? StringUtils.join(args, " ", 2, args.length) : null; + Ban ipBan = Ban.forPlayerIp(banIp, sender, null, ipBanReason); + plugin.bm.addBan(ipBan); + FUtil.adminAction(sender.getName(), "Banning IP: " + banIp, true); + return true; + case "unbanip": + case "pardonip": + if (!usingIp) + { + msg("Please specify an IP."); + return true; + } + + FUtil.adminAction(sender.getName(), "Unbanning IP: " + banIp, true); + Ban ipUnban = plugin.bm.getByIp(banIp); + if (ipUnban != null) + { + plugin.bm.removeBan(ipUnban); + plugin.bm.unbanIp(banIp); + } + ipUnban = plugin.bm.getByIp(FUtil.getFuzzyIp(banIp)); + if (ipUnban != null) + { + plugin.bm.removeBan(ipUnban); + plugin.bm.unbanIp(banIp); + } + return true; + default: + return false; } } - - return true; } - return false; - } -} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java index b8360c36..11cc4eec 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java @@ -6,6 +6,7 @@ import me.totalfreedom.totalfreedommod.util.FUtil; import net.pravian.aero.util.Ips; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; +import static org.bukkit.Bukkit.getServer; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; @@ -21,7 +22,6 @@ public class Command_gtfo extends FreedomCommand @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (args.length == 0) { return false; @@ -43,17 +43,26 @@ public class Command_gtfo extends FreedomCommand FUtil.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED); - // Undo WorldEdits - try + //checks if there is CoreProtect loaded and installed , if not it skips the rollback and uses coreprotect directly + if (!getServer().getPluginManager().isPluginEnabled("CoreProtect")) { - plugin.web.undo(player, 15); - } - catch (NoClassDefFoundError ex) - { - } + // Undo WorldEdits + try + { + plugin.web.undo(player, 15); + } + catch (NoClassDefFoundError ex) + { + } - // Rollback - plugin.rb.rollback(player.getName()); + // Rollback + plugin.rb.rollback(player.getName()); + + } + else + { + plugin.cpb.rollback(player.getName()); + } // Deop player.setOp(false); @@ -71,7 +80,7 @@ public class Command_gtfo extends FreedomCommand for (int z = -1; z <= 1; z++) { final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z); - targetPos.getWorld().strikeLightning(strike_pos); + targetPos.getWorld().strikeLightningEffect(strike_pos); } } @@ -86,16 +95,19 @@ public class Command_gtfo extends FreedomCommand .append(ip); if (reason != null) { - bcast.append(" - Reason: ").append(ChatColor.YELLOW).append(reason); + bcast.append(" - Reason: ").append(ChatColor.YELLOW).append(FUtil.colorize(reason)); } FUtil.bcastMsg(bcast.toString()); // Ban player plugin.bm.addBan(Ban.forPlayerFuzzy(player, sender, null, reason)); + // Kill player + player.setHealth(0.0); + // Kick player player.kickPlayer(ChatColor.RED + "GTFO"); return true; } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invis.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invis.java index f0267dca..34e8d827 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invis.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invis.java @@ -11,7 +11,7 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffectType; @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) -@CommandParameters(description = "Shows (and optionally clears) invisisible players", usage = "/ [clear]") +@CommandParameters(description = "Shows (optionally clears) invisisible players", usage = "/ (clear)") public class Command_invis extends FreedomCommand { @@ -19,11 +19,12 @@ public class Command_invis extends FreedomCommand public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { boolean clear = false; + if (args.length >= 1) { if (args[0].equalsIgnoreCase("clear")) { - FUtil.adminAction(sender.getName(), "Clearing invisibility for all players", false); + FUtil.adminAction(sender.getName(), "Clearing all invis potion effect from all players", true); clear = true; } else @@ -32,7 +33,7 @@ public class Command_invis extends FreedomCommand } } - List players = new ArrayList<>(); + List players = new ArrayList(); int clears = 0; for (Player player : server.getOnlinePlayers()) @@ -42,7 +43,7 @@ public class Command_invis extends FreedomCommand players.add(player.getName()); if (clear && !plugin.al.isAdmin(player)) { - player.removePotionEffect(PotionEffectType.INVISIBILITY); + player.removePotionEffect((PotionEffectType.INVISIBILITY)); clears++; } } @@ -50,17 +51,16 @@ public class Command_invis extends FreedomCommand if (players.isEmpty()) { - msg("There are no invisible players"); + sender.sendMessage("There are no invisible players"); return true; } - if (clear) { - msg("Cleared invisibility effect from " + clears + " players"); + sender.sendMessage("Cleared " + clears + " players"); } else { - msg("Invisible players (" + players.size() + "): " + StringUtils.join(players, ", ")); + sender.sendMessage("Invisible players (" + players.size() + "): " + StringUtils.join(players, ", ")); } return true; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invsee.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invsee.java new file mode 100644 index 00000000..1e95c274 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invsee.java @@ -0,0 +1,54 @@ +package me.totalfreedom.totalfreedommod.command; + +import me.totalfreedom.totalfreedommod.player.FPlayer; +import me.totalfreedom.totalfreedommod.rank.Rank; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME) +@CommandParameters(description = " Look into another player's inventory, optionally take items out.", usage = "/ ", aliases = "inv,insee") +public class Command_invsee extends FreedomCommand +{ + + @Override + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + + if (args.length != 1) + { + msg("You need to specify a player."); + return false; + } + + Player player = getPlayer(args[0]); + + if (player == null) + { + msg("This player is not online."); + return false; + } + + if (playerSender == player) + { + msg("You cannot invsee yourself."); + return true; + } + + if (plugin.al.isAdmin(player) && !plugin.al.isAdmin(playerSender)) + { + msg("You can't spy on admins!"); + return true; + + } + + playerSender.closeInventory(); + FPlayer fPlayer = plugin.pl.getPlayer(playerSender); + fPlayer.setInvsee(true); + Inventory playerInv = player.getInventory(); + playerSender.openInventory(playerInv); + return true; + } + +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java index 8240b2c0..fe651c4f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java @@ -1,120 +1,119 @@ + + package me.totalfreedom.totalfreedommod.command; -import java.util.ArrayList; +import me.totalfreedom.totalfreedommod.rank.Displayable; +import java.util.Iterator; import java.util.List; import me.totalfreedom.totalfreedommod.config.ConfigEntry; -import me.totalfreedom.totalfreedommod.rank.Displayable; -import me.totalfreedom.totalfreedommod.rank.Rank; -import me.totalfreedom.totalfreedommod.util.FUtil; -import org.apache.commons.lang3.StringUtils; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import org.bukkit.ChatColor; +import org.apache.commons.lang3.StringUtils; +import java.util.ArrayList; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.command.CommandSender; +import me.totalfreedom.totalfreedommod.rank.Rank; @CommandPermissions(level = Rank.IMPOSTOR, source = SourceType.BOTH) @CommandParameters(description = "Lists the real names of all online players.", usage = "/ [-a | -i | -f]", aliases = "who") public class Command_list extends FreedomCommand { - - private static enum ListFilter - { - - PLAYERS, - ADMINS, - FAMOUS_PLAYERS, - IMPOSTORS; - } - - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length > 1) - { + public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole) { + if (args.length > 1) { return false; } - - if (FUtil.isFromHostConsole(sender.getName())) - { - final List names = new ArrayList<>(); - for (Player player : server.getOnlinePlayers()) - { + if (FUtil.isFromHostConsole(sender.getName())) { + final List names = new ArrayList(); + for (final Player player : this.server.getOnlinePlayers()) { names.add(player.getName()); } - msg("There are " + names.size() + "/" + server.getMaxPlayers() + " players online:\n" + StringUtils.join(names, ", "), ChatColor.WHITE); + this.msg("There are " + names.size() + "/" + this.server.getMaxPlayers() + " players online:\n" + StringUtils.join((Iterable)names, ", "), ChatColor.WHITE); return true; } - - final ListFilter listFilter; - if (args.length == 1) - { - switch (args[0]) - { - case "-a": + ListFilter listFilter = null; + if (args.length == 1) { + final String s = args[0]; + switch (s) { + case "-a": { listFilter = ListFilter.ADMINS; break; - case "-i": + } + case "-v": { + listFilter = ListFilter.VANISHED_ADMINS; + break; + } + case "-i": { listFilter = ListFilter.IMPOSTORS; break; - case "-f": + } + case "-f": { listFilter = ListFilter.FAMOUS_PLAYERS; break; - default: + } + default: { return false; + } } } - else - { + else { listFilter = ListFilter.PLAYERS; } - + if (listFilter == ListFilter.VANISHED_ADMINS && !((TotalFreedomMod)this.plugin).al.isAdmin((CommandSender)playerSender)) { + this.msg("/list [-a | -i | -f ]", ChatColor.WHITE); + return true; + } final StringBuilder onlineStats = new StringBuilder(); final StringBuilder onlineUsers = new StringBuilder(); - - onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(server.getOnlinePlayers().size()); - onlineStats.append(ChatColor.BLUE).append(" out of a maximum ").append(ChatColor.RED).append(server.getMaxPlayers()); + onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(this.server.getOnlinePlayers().size() - Command_vanish.vanished.size()); + onlineStats.append(ChatColor.BLUE).append(" out of a maximum ").append(ChatColor.RED).append(this.server.getMaxPlayers()); onlineStats.append(ChatColor.BLUE).append(" players online."); - - final List names = new ArrayList<>(); - for (Player player : server.getOnlinePlayers()) - { - if (listFilter == ListFilter.ADMINS && !plugin.al.isAdmin(player)) - { + final List names2 = new ArrayList(); + for (final Player player2 : this.server.getOnlinePlayers()) { + if (listFilter == ListFilter.ADMINS && !((TotalFreedomMod)this.plugin).al.isAdmin((CommandSender)player2)) { continue; } - - if (listFilter == ListFilter.IMPOSTORS && !plugin.al.isAdminImpostor(player)) - { + if (listFilter == ListFilter.ADMINS && Command_vanish.vanished.contains(player2)) { continue; } - - if (listFilter == ListFilter.FAMOUS_PLAYERS && !ConfigEntry.FAMOUS_PLAYERS.getList().contains(player.getName().toLowerCase())) - { + if (listFilter == ListFilter.VANISHED_ADMINS && !Command_vanish.vanished.contains(player2)) { continue; } - - Displayable display = plugin.rm.getDisplay(player); - - names.add(display.getColoredTag() + player.getName()); + if (listFilter == ListFilter.IMPOSTORS && !((TotalFreedomMod)this.plugin).al.isAdminImpostor(player2)) { + continue; + } + if (listFilter == ListFilter.FAMOUS_PLAYERS && !ConfigEntry.FAMOUS_PLAYERS.getList().contains(player2.getName().toLowerCase())) { + continue; + } + if (listFilter == ListFilter.PLAYERS && Command_vanish.vanished.contains(player2)) { + continue; + } + final Displayable display = ((TotalFreedomMod)this.plugin).rm.getDisplay((CommandSender)player2); + names2.add(display.getColoredTag() + player2.getName()); } - - String playerType = listFilter == null ? "players" : listFilter.toString().toLowerCase().replace('_', ' '); - + final String playerType = (listFilter == null) ? "players" : listFilter.toString().toLowerCase().replace('_', ' '); onlineUsers.append("Connected "); onlineUsers.append(playerType + ": "); - onlineUsers.append(StringUtils.join(names, ChatColor.WHITE + ", ")); - - if (senderIsConsole) - { + onlineUsers.append(StringUtils.join((Iterable)names2, ChatColor.WHITE + ", ")); + if (senderIsConsole) { sender.sendMessage(ChatColor.stripColor(onlineStats.toString())); sender.sendMessage(ChatColor.stripColor(onlineUsers.toString())); } - else - { + else { sender.sendMessage(onlineStats.toString()); sender.sendMessage(onlineUsers.toString()); } - + names2.clear(); return true; } + + private enum ListFilter + { + PLAYERS, + ADMINS, + VANISHED_ADMINS, + FAMOUS_PLAYERS, + IMPOSTORS; + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_namehistory.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_namehistory.java new file mode 100644 index 00000000..47ca81ac --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_namehistory.java @@ -0,0 +1,24 @@ +package me.totalfreedom.totalfreedommod.command; + + import me.totalfreedom.totalfreedommod.rank.Rank; + import org.bukkit.command.Command; + import org.bukkit.command.CommandSender; + import org.bukkit.entity.Player; + import me.totalfreedom.totalfreedommod.util.History; + +@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) +@CommandParameters(description = "Check name history of username.", usage = "/ ") +public class Command_namehistory extends FreedomCommand +{ + + @Override + public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if (args.length != 1) + { + return false; + } + History.reportHistory(sender, args[0]); + return true; + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_onlinemode.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_onlinemode.java index 199f8e8f..ba20edee 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_onlinemode.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_onlinemode.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; +import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -43,29 +44,27 @@ public class Command_onlinemode extends FreedomCommand return false; } -// try -// { -// plugin.si.setOnlineMode(onlineMode); -// -// if (onlineMode) -// { -// for (Player player : server.getOnlinePlayers()) -// { -// player.kickPlayer("Server is activating \"online-mode=true\". Please reconnect."); -// } -// } -// -// FUtil.adminAction(sender.getName(), "Turning player validation " + (onlineMode ? "on" : "off") + ".", true); -// -// server.reload(); -// } -// catch (Exception ex) -// { -// FLog.severe(ex); -// } - FUtil.adminAction(sender.getName(), "Online-Mode toggling is temporarily disabled.", true); - } + try + { + plugin.si.setOnlineMode(onlineMode); + if (onlineMode) + { + for (Player player : server.getOnlinePlayers()) + { + player.kickPlayer("Server is activating \"online-mode=true\". Please reconnect."); + } + } + + FUtil.adminAction(sender.getName(), "Turning player validation " + (onlineMode ? "on" : "off") + ".", true); + + server.reload(); + } + catch (Exception ex) + { + FLog.severe(ex); + } + } return true; } }