diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_BlockListener.java b/src/me/StevenLawson/TotalFreedomMod/TFM_BlockListener.java index 046d18d7..cb94dc5d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_BlockListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_BlockListener.java @@ -45,13 +45,7 @@ public class TFM_BlockListener extends BlockListener if (plugin.nukeMonitor) { Player p = event.getPlayer(); - - TFM_UserInfo playerdata = plugin.userinfo.get(p); - if (playerdata == null) - { - playerdata = new TFM_UserInfo(); - plugin.userinfo.put(p, playerdata); - } + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p, plugin); Location player_pos = p.getLocation(); Location block_pos = event.getBlock().getLocation(); @@ -59,7 +53,7 @@ public class TFM_BlockListener extends BlockListener if (player_pos.distance(block_pos) > plugin.nukeMonitorRange) { playerdata.incrementFreecamDestroyCount(); - if (playerdata.getFreecamPlaceCount() > plugin.freecamTriggerCount) + if (playerdata.getFreecamDestroyCount() > plugin.freecamTriggerCount) { p.setOp(false); p.setGameMode(GameMode.SURVIVAL); @@ -82,6 +76,7 @@ public class TFM_BlockListener extends BlockListener p.setOp(false); p.setGameMode(GameMode.SURVIVAL); p.getInventory().clear(); + p.kickPlayer("You are breaking blocks too fast. Nukers are not permitted on this server."); event.setCancelled(true); return; @@ -101,12 +96,7 @@ public class TFM_BlockListener extends BlockListener if (player_pos.distance(block_pos) > plugin.nukeMonitorRange) { - TFM_UserInfo playerdata = plugin.userinfo.get(p); - if (playerdata == null) - { - playerdata = new TFM_UserInfo(); - plugin.userinfo.put(p, playerdata); - } + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p, plugin); playerdata.incrementFreecamPlaceCount(); if (playerdata.getFreecamPlaceCount() > plugin.freecamTriggerCount) diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Cmds_Admin.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Cmds_Admin.java index baad8dd6..20986061 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Cmds_Admin.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Cmds_Admin.java @@ -14,6 +14,7 @@ import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; @@ -81,17 +82,8 @@ public class TFM_Cmds_Admin implements CommandExecutor p = matches.get(0); } - TFM_UserInfo playerdata = plugin.userinfo.get(p); - if (playerdata != null) - { - playerdata.setFrozen(!playerdata.isFrozen()); - } - else - { - playerdata = new TFM_UserInfo(); - playerdata.setFrozen(true); - plugin.userinfo.put(p, playerdata); - } + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p, plugin); + playerdata.setFrozen(!playerdata.isFrozen()); sender.sendMessage(ChatColor.AQUA + p.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + "."); p.sendMessage(ChatColor.AQUA + "You have been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + "."); @@ -128,7 +120,7 @@ public class TFM_Cmds_Admin implements CommandExecutor TFM_Util.tfm_broadcastMessage(p.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED); //Undo WorldEdits: - Bukkit.getServer().dispatchCommand(sender, String.format("/undo %d %s", 15, p.getName())); + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("/undo %d %s", 15, p.getName())); //Deop p.setOp(false); @@ -211,11 +203,8 @@ public class TFM_Cmds_Admin implements CommandExecutor p.getInventory().clear(); //Flag for insta-kill: - TFM_UserInfo playerdata = plugin.userinfo.get(p); - if (playerdata != null) - { - playerdata.setForcedDeath(true); - } + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p, plugin); + playerdata.setForcedDeath(true); //Strike with lightning effect: final Location target_pos = p.getLocation(); @@ -307,17 +296,9 @@ public class TFM_Cmds_Admin implements CommandExecutor } else if (mode.equals("fr")) { - TFM_UserInfo playerdata = plugin.userinfo.get(p); - if (playerdata != null) - { - playerdata.setFrozen(!playerdata.isFrozen()); - } - else - { - playerdata = new TFM_UserInfo(); - playerdata.setFrozen(true); - plugin.userinfo.put(p, playerdata); - } + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p, plugin); + playerdata.setFrozen(!playerdata.isFrozen()); + sender.sendMessage(ChatColor.AQUA + p.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + "."); p.sendMessage(ChatColor.AQUA + "You have been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + "."); } @@ -354,7 +335,7 @@ public class TFM_Cmds_Admin implements CommandExecutor { String out_command = base_command.replaceAll("\\x3f", p.getName()); sender.sendMessage("Running Command: " + out_command); - Bukkit.getServer().dispatchCommand(sender, out_command); + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), out_command); } } else @@ -375,12 +356,24 @@ public class TFM_Cmds_Admin implements CommandExecutor if (args.length >= 2) { - plugin.nukeMonitorRange = Double.parseDouble(args[1]); + try + { + plugin.nukeMonitorRange = Double.parseDouble(args[1]); + } + catch (NumberFormatException nfex) + { + } } if (args.length >= 3) { - plugin.nukeMonitorCountBreak = Integer.parseInt(args[2]); + try + { + plugin.nukeMonitorCountBreak = Integer.parseInt(args[2]); + } + catch (NumberFormatException nfex) + { + } } if (args[0].equalsIgnoreCase("on")) @@ -570,7 +563,7 @@ public class TFM_Cmds_Admin implements CommandExecutor } //Send to jail "mgjail": - Bukkit.getServer().dispatchCommand(sender, String.format("tjail %s mgjail", p.getName())); + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("tjail %s mgjail 1y", p.getName().replace(" ", "").trim())); TFM_Util.tfm_broadcastMessage(p.getName() + " has been JAILED!", ChatColor.RED); } @@ -654,12 +647,7 @@ public class TFM_Cmds_Admin implements CommandExecutor p = matches.get(0); } - TFM_UserInfo playerdata = plugin.userinfo.get(p); - if (playerdata == null) - { - playerdata = new TFM_UserInfo(); - plugin.userinfo.put(p, playerdata); - } + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p, plugin); Material cage_material_outer = Material.GLASS; Material cage_material_inner = Material.AIR; @@ -699,8 +687,8 @@ public class TFM_Cmds_Admin implements CommandExecutor playerdata.regenerateHistory(); playerdata.clearHistory(); TFM_Util.buildHistory(target_pos, 2, playerdata); - TFM_Util.generateCube(target_pos, 2, playerdata.getCageMaterial(TFM_UserInfo.CageLayer.INNER)); - TFM_Util.generateCube(target_pos, 1, playerdata.getCageMaterial(TFM_UserInfo.CageLayer.OUTER)); + TFM_Util.generateCube(target_pos, 2, playerdata.getCageMaterial(TFM_UserInfo.CageLayer.OUTER)); + TFM_Util.generateCube(target_pos, 1, playerdata.getCageMaterial(TFM_UserInfo.CageLayer.INNER)); p.setGameMode(GameMode.SURVIVAL); @@ -734,13 +722,127 @@ public class TFM_Cmds_Admin implements CommandExecutor p = matches.get(0); } - double strength = 100.0; + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p, plugin); + + double strength = 10.0; + if (args.length >= 2) { - strength = Double.parseDouble(args[1]); + if (args[1].equalsIgnoreCase("stop") || args[1].equalsIgnoreCase("end")) + { + sender.sendMessage(ChatColor.GRAY + "Stopped orbiting " + p.getName()); + playerdata.stopOrbiting(); + return true; + } + + try + { + strength = Double.parseDouble(args[1]); + } + catch (NumberFormatException nfex) + { + strength = 10.0; + } } + p.setGameMode(GameMode.SURVIVAL); + playerdata.startOrbiting(strength); + p.setVelocity(new Vector(0, strength, 0)); + + sender.sendMessage(ChatColor.GRAY + "Orbiting " + p.getName()); + } + else + { + sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); + } + + return true; + } + else if (cmd.getName().equalsIgnoreCase("expel")) + { + if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin)) + { + if (senderIsConsole) + { + sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE); + return true; + } + + double radius = 50.0; + double strength = 100.0; + + if (args.length >= 1) + { + try + { + radius = Double.parseDouble(args[0]); + } + catch (NumberFormatException nfex) + { + } + } + + if (args.length >= 2) + { + try + { + strength = Double.parseDouble(args[1]); + } + catch (NumberFormatException nfex) + { + } + } + + Location sender_pos = sender_p.getLocation(); + for (Player p : Bukkit.getOnlinePlayers()) + { + if (!p.equals(sender_p)) + { + Location target_pos = p.getLocation(); + if (target_pos.distance(sender_pos) < radius) + { + sender.sendMessage("Pushing " + p.getName()); + Vector expel_direction = target_pos.subtract(sender_pos).toVector().normalize(); + p.setVelocity(expel_direction.multiply(strength)); + } + } + } + } + else + { + sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); + } + + return true; + } + else if (cmd.getName().equalsIgnoreCase("mp44")) + { + if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin)) + { + if (senderIsConsole) + { + sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE); + return true; + } + + if (args.length == 0) + { + return false; + } + + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(sender_p, plugin); + + if (args[0].equalsIgnoreCase("draw")) + { + playerdata.stopArrowShooter(); + int schedule_id = Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new ArrowShooter(sender_p), 1L, 1L); + playerdata.startArrowShooter(schedule_id); + } + else + { + playerdata.stopArrowShooter(); + } } else { @@ -757,4 +859,21 @@ public class TFM_Cmds_Admin implements CommandExecutor return false; } + + class ArrowShooter implements Runnable + { + private Player _player; + + public ArrowShooter(Player player) + { + _player = player; + } + + @Override + public void run() + { + Arrow shot_arrow = _player.shootArrow(); + shot_arrow.setVelocity(shot_arrow.getVelocity().multiply(2.0)); + } + } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Cmds_AntiBlock.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Cmds_AntiBlock.java index 1b3da1b5..2d6fb229 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Cmds_AntiBlock.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Cmds_AntiBlock.java @@ -48,7 +48,13 @@ public class TFM_Cmds_AntiBlock implements CommandExecutor if (args.length == 2) { - plugin.explosiveRadius = Double.parseDouble(args[1]); + try + { + plugin.explosiveRadius = Double.parseDouble(args[1]); + } + catch (NumberFormatException nfex) + { + } } if (args[0].equalsIgnoreCase("on")) diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Cmds_General.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Cmds_General.java index 4e6a8ba6..8ddf1bb9 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Cmds_General.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Cmds_General.java @@ -3,7 +3,9 @@ package me.StevenLawson.TotalFreedomMod; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Logger; import me.desmin88.mobdisguise.api.MobDisguiseAPI; import org.bukkit.Bukkit; @@ -20,9 +22,8 @@ import org.bukkit.entity.*; public class TFM_Cmds_General implements CommandExecutor { private TotalFreedomMod plugin; - private static final Logger log = Logger.getLogger("Minecraft"); - + public TFM_Cmds_General(TotalFreedomMod plugin) { this.plugin = plugin; @@ -45,7 +46,7 @@ public class TFM_Cmds_General implements CommandExecutor senderIsConsole = true; log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s", sender.getName(), commandLabel, TFM_Util.implodeStringList(" ", Arrays.asList(args)))); } - + if (cmd.getName().equalsIgnoreCase("creative")) { if (senderIsConsole) @@ -144,7 +145,7 @@ public class TFM_Cmds_General implements CommandExecutor { if (senderIsConsole) { - sender.sendMessage("This command can only be used in-game."); + sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE); return true; } @@ -169,7 +170,13 @@ public class TFM_Cmds_General implements CommandExecutor int countmax = 5; if (args.length == 1) { - countmax = Integer.parseInt(args[0]); + try + { + countmax = Integer.parseInt(args[0]); + } + catch (NumberFormatException nfex) + { + } } int count = 0; @@ -183,8 +190,7 @@ public class TFM_Cmds_General implements CommandExecutor sender.sendMessage(ChatColor.YELLOW + String.format("%s - %d, Disguised: %s", i.player.getName(), Math.round(i.distance), - MobDisguiseAPI.isDisguised(i.player) ? "Yes" : "No" - )); + MobDisguiseAPI.isDisguised(i.player) ? "Yes" : "No")); } return true; @@ -194,7 +200,7 @@ public class TFM_Cmds_General implements CommandExecutor if (senderIsConsole || sender.isOp()) { sender.sendMessage(ChatColor.GRAY + "Removing all dropped items, arrows, exp. orbs and TNT..."); - sender.sendMessage(ChatColor.GRAY + String.valueOf(TFM_Util.wipeDropEntities(plugin)) + " dropped enties removed."); + sender.sendMessage(ChatColor.GRAY + String.valueOf(TFM_Util.wipeDropEntities(true)) + " dropped enties removed."); } else { @@ -231,21 +237,21 @@ public class TFM_Cmds_General implements CommandExecutor return true; } - else if (cmd.getName().equalsIgnoreCase("flatlands")) - { + else if (cmd.getName().equalsIgnoreCase("flatlands")) + { TFM_Util.gotoWorld(sender, "flatlands"); - return true; - } - else if (cmd.getName().equalsIgnoreCase("skylands")) - { + return true; + } + else if (cmd.getName().equalsIgnoreCase("skylands")) + { TFM_Util.gotoWorld(sender, "skylands"); - return true; - } - else if (cmd.getName().equalsIgnoreCase("nether")) - { + return true; + } + else if (cmd.getName().equalsIgnoreCase("nether")) + { TFM_Util.gotoWorld(sender, "nether"); - return true; - } + return true; + } else if (cmd.getName().equalsIgnoreCase("tfbanlist")) { if (args.length > 0) @@ -269,7 +275,7 @@ public class TFM_Cmds_General implements CommandExecutor } } } - + StringBuilder banned_players = new StringBuilder(); banned_players.append("Banned Players: "); boolean first = true; @@ -282,9 +288,9 @@ public class TFM_Cmds_General implements CommandExecutor first = false; banned_players.append(p.getName().trim()); } - + sender.sendMessage(ChatColor.GRAY + banned_players.toString()); - + return true; } else if (cmd.getName().equalsIgnoreCase("tfipbanlist")) @@ -310,10 +316,10 @@ public class TFM_Cmds_General implements CommandExecutor } } } - + List ip_bans = Arrays.asList(Bukkit.getIPBans().toArray(new String[0])); Collections.sort(ip_bans); - + StringBuilder banned_ips = new StringBuilder(); banned_ips.append("Banned IPs: "); boolean first = true; @@ -329,9 +335,86 @@ public class TFM_Cmds_General implements CommandExecutor banned_ips.append(ip.trim()); } } - + sender.sendMessage(ChatColor.GRAY + banned_ips.toString()); - + + return true; + } + else if (cmd.getName().equalsIgnoreCase("tossmob")) + { + if (senderIsConsole || sender.isOp()) + { + if (senderIsConsole) + { + sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE); + return true; + } + + TFM_UserInfo playerData = TFM_UserInfo.getPlayerData(sender_p, plugin); + + CreatureType creature = CreatureType.PIG; + if (args.length >= 1) + { + if (args[0].equalsIgnoreCase("off") || args[0].equalsIgnoreCase("end")) + { + playerData.disableMobThrower(); + sender.sendMessage(ChatColor.GREEN + "MobThrower is disabled."); + return true; + } + + Map mobtypes = new HashMap(); + mobtypes.put("chicken", CreatureType.CHICKEN); + mobtypes.put("cow", CreatureType.COW); + mobtypes.put("creeper", CreatureType.CREEPER); + mobtypes.put("pig", CreatureType.PIG); + mobtypes.put("sheep", CreatureType.SHEEP); + mobtypes.put("skeleton", CreatureType.SKELETON); + mobtypes.put("spider", CreatureType.SPIDER); + mobtypes.put("zombie", CreatureType.ZOMBIE); + mobtypes.put("wolf", CreatureType.WOLF); + + CreatureType creature_query = mobtypes.get(args[0].toLowerCase().trim()); + if (creature_query != null) + { + creature = creature_query; + } + else + { + sender.sendMessage(args[1] + " is not a supported mob type. Using a pig instead."); + } + } + + double speed = 1.0; + if (args.length >= 2) + { + try + { + speed = Double.parseDouble(args[1]); + } + catch (NumberFormatException nfex) + { + } + } + + if (speed < 1.0) + { + speed = 1.0; + } + else if (speed > 5.0) + { + speed = 5.0; + } + + playerData.enableMobThrower(creature, speed); + sender.sendMessage(ChatColor.GREEN + "MobThrower is enabled. Creature: " + creature + " - Speed: " + speed + "."); + sender.sendMessage(ChatColor.GREEN + "Left click while holding a stick to throw mobs!"); + sender.sendMessage(ChatColor.GREEN + "Type '/tossmob off' to disable. -By Madgeek1450"); + } + else + { + sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); + } + return true; } } @@ -339,7 +422,7 @@ public class TFM_Cmds_General implements CommandExecutor { log.severe("Exception in TFM_Cmds_General.onCommand(): " + ex.getMessage()); } - + return false; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_EntityListener.java b/src/me/StevenLawson/TotalFreedomMod/TFM_EntityListener.java index 86dc18b3..fa53ae4d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_EntityListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_EntityListener.java @@ -53,18 +53,15 @@ public class TFM_EntityListener extends EntityListener Player p = (Player) event.getEntity(); if (p != null) { - TFM_UserInfo playerdata = plugin.userinfo.get(p); - if (playerdata != null) + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p, plugin); + if (playerdata.getForcedDeath()) { - if (playerdata.getForcedDeath()) - { - event.setCancelled(false); - p.setFoodLevel(0); - p.setHealth(0); - event.setDamage(100); - playerdata.setForcedDeath(false); - return; - } + event.setCancelled(false); + p.setFoodLevel(0); + p.setHealth(0); + event.setDamage(100); + playerdata.setForcedDeath(false); + return; } } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java index 22cb56be..92db0778 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java @@ -1,6 +1,5 @@ package me.StevenLawson.TotalFreedomMod; -import java.util.logging.Logger; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -19,17 +18,14 @@ public class TFM_Heartbeat implements Runnable { for (Player p : Bukkit.getOnlinePlayers()) { - TFM_UserInfo playerdata = plugin.userinfo.get(p); - if (playerdata != null) - { - playerdata.resetMsgCount(); - playerdata.resetBlockDestroyCount(); - } + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p, plugin); + playerdata.resetMsgCount(); + playerdata.resetBlockDestroyCount(); } if (plugin.autoEntityWipe) { - TFM_Util.wipeDropEntities(plugin); + TFM_Util.wipeDropEntities(!plugin.allowExplosions); } if (plugin.disableNight) diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerListener.java index c3b28ee4..2a02b60a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerListener.java @@ -5,10 +5,13 @@ import java.util.regex.Pattern; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.entity.CreatureType; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.block.Action; import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; class TFM_PlayerListener extends PlayerListener { @@ -23,12 +26,12 @@ class TFM_PlayerListener extends PlayerListener @Override public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.getMaterial() == Material.WATER_BUCKET) { - Player player = event.getPlayer(); - int slot = player.getInventory().getHeldItemSlot(); ItemStack heldItem = new ItemStack(Material.COOKIE, 1); player.getInventory().setItem(slot, heldItem); @@ -40,8 +43,6 @@ class TFM_PlayerListener extends PlayerListener } else if (event.getMaterial() == Material.LAVA_BUCKET) { - Player player = event.getPlayer(); - int slot = player.getInventory().getHeldItemSlot(); ItemStack heldItem = new ItemStack(Material.COOKIE, 1); player.getInventory().setItem(slot, heldItem); @@ -52,13 +53,32 @@ class TFM_PlayerListener extends PlayerListener return; } } + else if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) + { + if (event.getMaterial() == Material.STICK) + { + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(player, plugin); + if (playerdata.mobThrowerEnabled()) + { + Location player_pos = player.getLocation(); + Vector direction = player_pos.getDirection().normalize(); + Location rez_pos = player_pos.add(direction.multiply(2.0)); + + LivingEntity rezzed_mob = player.getWorld().spawnCreature(rez_pos, playerdata.mobThrowerCreature()); + rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed())); + playerdata.enqueueMob(rezzed_mob); + + event.setCancelled(true); + } + } + } } @Override public void onPlayerMove(PlayerMoveEvent event) { Player p = event.getPlayer(); - TFM_UserInfo playerdata = plugin.userinfo.get(p); + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p, plugin); boolean do_freeze = false; if (plugin.allPlayersFrozen) @@ -70,12 +90,9 @@ class TFM_PlayerListener extends PlayerListener } else { - if (playerdata != null) + if (playerdata.isFrozen()) { - if (playerdata.isFrozen()) - { - do_freeze = true; - } + do_freeze = true; } } @@ -91,21 +108,26 @@ class TFM_PlayerListener extends PlayerListener event.setTo(to); } - if (playerdata != null) + if (playerdata.isCaged()) { - if (playerdata.isCaged()) - { - Location target_pos = p.getLocation().add(0, 1, 0); + Location target_pos = p.getLocation().add(0, 1, 0); - if (target_pos.distance(playerdata.getCagePos()) > 2.5) - { - playerdata.setCaged(true, target_pos, playerdata.getCageMaterial(TFM_UserInfo.CageLayer.INNER), playerdata.getCageMaterial(TFM_UserInfo.CageLayer.OUTER)); - playerdata.regenerateHistory(); - playerdata.clearHistory(); - TFM_Util.buildHistory(target_pos, 2, playerdata); - TFM_Util.generateCube(target_pos, 2, playerdata.getCageMaterial(TFM_UserInfo.CageLayer.INNER)); - TFM_Util.generateCube(target_pos, 1, playerdata.getCageMaterial(TFM_UserInfo.CageLayer.OUTER)); - } + if (target_pos.distance(playerdata.getCagePos()) > 2.5) + { + playerdata.setCaged(true, target_pos, playerdata.getCageMaterial(TFM_UserInfo.CageLayer.INNER), playerdata.getCageMaterial(TFM_UserInfo.CageLayer.OUTER)); + playerdata.regenerateHistory(); + playerdata.clearHistory(); + TFM_Util.buildHistory(target_pos, 2, playerdata); + TFM_Util.generateCube(target_pos, 2, playerdata.getCageMaterial(TFM_UserInfo.CageLayer.OUTER)); + TFM_Util.generateCube(target_pos, 1, playerdata.getCageMaterial(TFM_UserInfo.CageLayer.INNER)); + } + } + + if (playerdata.isOrbiting()) + { + if (p.getVelocity().length() < playerdata.orbitStrength() * (2.0 / 3.0)) + { + p.setVelocity(new Vector(0, playerdata.orbitStrength(), 0)); } } } @@ -115,26 +137,18 @@ class TFM_PlayerListener extends PlayerListener { Player p = event.getPlayer(); - TFM_UserInfo playerdata = plugin.userinfo.get(p); - if (playerdata != null) - { - playerdata.incrementMsgCount(); + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p, plugin); + playerdata.incrementMsgCount(); - if (playerdata.getMsgCount() > 10) - { - p.setOp(false); - p.kickPlayer("No Spamming"); - TFM_Util.tfm_broadcastMessage(p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED); - - event.setCancelled(true); - return; - } - } - else + if (playerdata.getMsgCount() > 10) { - playerdata = new TFM_UserInfo(); - playerdata.incrementMsgCount(); - plugin.userinfo.put(p, playerdata); + p.setOp(false); + p.kickPlayer("No Spamming"); + TFM_Util.tfm_broadcastMessage(p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED); + playerdata.resetMsgCount(); + + event.setCancelled(true); + return; } String message = event.getMessage().toLowerCase(); @@ -177,6 +191,11 @@ class TFM_PlayerListener extends PlayerListener block_command = true; } } + else if (Pattern.compile("^/time").matcher(command).find()) + { + player.sendMessage(ChatColor.GRAY + "Server-side time changing is disabled. Please use /ptime to set your own personal time."); + block_command = true; + } if (block_command) { @@ -185,4 +204,34 @@ class TFM_PlayerListener extends PlayerListener return; } } + + @Override + public void onPlayerDropItem(PlayerDropItemEvent event) + { + if (plugin.autoEntityWipe) + { + if (event.getPlayer().getWorld().getEntities().size() > 750) + { + event.setCancelled(true); + } + else + { + event.getItemDrop().remove(); + } + } + } + + @Override + public void onPlayerKick(PlayerKickEvent event) + { + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(event.getPlayer(), plugin); + playerdata.stopArrowShooter(); + } + + @Override + public void onPlayerQuit(PlayerQuitEvent event) + { + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(event.getPlayer(), plugin); + playerdata.stopArrowShooter(); + } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java b/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java index 4d834b08..247d8bff 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java @@ -2,8 +2,12 @@ package me.StevenLawson.TotalFreedomMod; import java.util.ArrayList; import java.util.List; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.entity.CreatureType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; public class TFM_UserInfo { @@ -16,12 +20,51 @@ public class TFM_UserInfo private boolean user_caged = false; private Location user_cage_pos; private List user_cage_history = new ArrayList(); - private Material cage_material_outer; - private Material cage_material_inner; + private Material cage_material_outer = Material.GLASS; + private Material cage_material_inner = Material.AIR; + private boolean is_orbiting = false; + private double orbit_strength = 10.0; + private boolean mob_thrower_enabled = false; + private CreatureType mob_thrower_creature = CreatureType.PIG; + private double mob_thrower_speed = 4.0; + private List mobqueue = new ArrayList(); + private int schedule_id = -1; public TFM_UserInfo() { } + + public static TFM_UserInfo getPlayerData(Player p, TotalFreedomMod tfm) + { + TFM_UserInfo playerdata = tfm.userinfo.get(p); + if (playerdata == null) + { + playerdata = new TFM_UserInfo(); + tfm.userinfo.put(p, playerdata); + } + return playerdata; + } + + public boolean isOrbiting() + { + return this.is_orbiting; + } + + public void startOrbiting(double orbit_strength) + { + this.is_orbiting = true; + this.orbit_strength = orbit_strength; + } + + public void stopOrbiting() + { + this.is_orbiting = false; + } + + public double orbitStrength() + { + return this.orbit_strength; + } public void setCaged(boolean state) { @@ -173,4 +216,58 @@ public class TFM_UserInfo { this.freecam_place_count = 0; } + + public void enableMobThrower(CreatureType mob_thrower_creature, double mob_thrower_speed) + { + this.mob_thrower_enabled = true; + this.mob_thrower_creature = mob_thrower_creature; + this.mob_thrower_speed = mob_thrower_speed; + } + + public void disableMobThrower() + { + this.mob_thrower_enabled = false; + } + + public CreatureType mobThrowerCreature() + { + return this.mob_thrower_creature; + } + + public double mobThrowerSpeed() + { + return this.mob_thrower_speed; + } + + public boolean mobThrowerEnabled() + { + return this.mob_thrower_enabled; + } + + public void enqueueMob(LivingEntity mob) + { + mobqueue.add(mob); + if (mobqueue.size() > 4) + { + LivingEntity oldmob = mobqueue.remove(0); + if (oldmob != null) + { + oldmob.damage(20); + } + } + } + + void startArrowShooter(int schedule_id) + { + this.schedule_id = schedule_id; + } + + void stopArrowShooter() + { + if (this.schedule_id != -1) + { + Bukkit.getScheduler().cancelTask(this.schedule_id); + this.schedule_id = -1; + } + } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java index 80334c2b..a7f69286 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java @@ -95,7 +95,7 @@ public class TFM_Util } else { - sender.sendMessage("This command may not be used from the console."); + sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE); } } @@ -219,7 +219,7 @@ public class TFM_Util if (Bukkit.getOnlineMode()) { - if (tfm.superadmins.contains(user.getName())) + if (tfm.superadmins.contains(user.getName().toLowerCase())) { return true; } @@ -250,14 +250,14 @@ public class TFM_Util return false; } - public static int wipeDropEntities(TotalFreedomMod tfm) + public static int wipeDropEntities(boolean wipe_tnt) { int removed = 0; for (World world : Bukkit.getWorlds()) { for (Entity ent : world.getEntities()) { - if (ent instanceof Arrow || (ent instanceof TNTPrimed && !tfm.allowExplosions) || ent instanceof Item || ent instanceof ExperienceOrb) + if (ent instanceof Arrow || (ent instanceof TNTPrimed && wipe_tnt) || ent instanceof Item || ent instanceof ExperienceOrb) { ent.remove(); removed++; diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java index c97c720c..444dc754 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java @@ -27,6 +27,7 @@ public class TotalFreedomMod extends JavaPlugin public static final String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!"; public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!"; 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."; + public static final String NOT_FROM_CONSOLE = "This command may not be used from the console."; public Map userinfo = new HashMap(); public boolean allPlayersFrozen = false; @@ -92,20 +93,34 @@ public class TotalFreedomMod extends JavaPlugin disableNight = config.getBoolean("disable_night", disableNight); disableWeather = config.getBoolean("disable_weather", disableWeather); - superadmins = (List) config.getList("superadmins", null); - if (superadmins == null) + superadmins = new ArrayList(); + List superadmins_temp = (List) config.getList("superadmins", null); + if (superadmins_temp == null || superadmins_temp.isEmpty()) { - superadmins = new ArrayList(); superadmins.add("Madgeek1450"); superadmins.add("markbyron"); } - - superadmin_ips = (List) config.getList("superadmin_ips", null); - if (superadmin_ips == null) + else + { + for (String admin_name : superadmins_temp) + { + superadmins.add(admin_name.toLowerCase().trim()); + } + } + + superadmin_ips = new ArrayList(); + List superadmin_ips_temp = (List) config.getList("superadmin_ips", null); + if (superadmin_ips_temp == null || superadmin_ips_temp.isEmpty()) { - superadmin_ips = new ArrayList(); superadmin_ips.add("127.0.0.1"); } + else + { + for (String admin_ip : superadmin_ips_temp) + { + superadmin_ips.add(admin_ip.toLowerCase().trim()); + } + } } private final TFM_EntityListener entityListener = new TFM_EntityListener(this); @@ -131,6 +146,9 @@ public class TotalFreedomMod extends JavaPlugin pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Event.Priority.High, this); pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Event.Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Event.Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_KICK, playerListener, Event.Priority.Monitor, this); + pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Event.Priority.Monitor, this); pm.registerEvent(Event.Type.WEATHER_CHANGE, weatherListener, Event.Priority.High, this); pm.registerEvent(Event.Type.THUNDER_CHANGE, weatherListener, Event.Priority.High, this); @@ -161,10 +179,12 @@ public class TotalFreedomMod extends JavaPlugin this.getCommand("skylands").setExecutor(GeneralCommands); this.getCommand("status").setExecutor(GeneralCommands); this.getCommand("survival").setExecutor(GeneralCommands); + this.getCommand("tossmob").setExecutor(GeneralCommands); this.getCommand("cage").setExecutor(AdminCommands); this.getCommand("cake").setExecutor(AdminCommands); this.getCommand("csay").setExecutor(AdminCommands); + this.getCommand("expel").setExecutor(AdminCommands); this.getCommand("fr").setExecutor(AdminCommands); this.getCommand("gadmin").setExecutor(AdminCommands); this.getCommand("gcmd").setExecutor(AdminCommands); @@ -176,6 +196,7 @@ public class TotalFreedomMod extends JavaPlugin this.getCommand("tfsmite").setExecutor(AdminCommands); this.getCommand("umd").setExecutor(AdminCommands); this.getCommand("wildcard").setExecutor(AdminCommands); + this.getCommand("mp44").setExecutor(AdminCommands); this.getCommand("explosives").setExecutor(AntiblockCommands); this.getCommand("fireplace").setExecutor(AntiblockCommands); diff --git a/src/plugin.yml b/src/plugin.yml index 031b4492..813c807a 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -22,6 +22,9 @@ commands: explosives: description: Superadmin command - Enable/disable explosives and set effect radius. usage: / [radius] + expel: + description: Superadmin command - Push people away from you. + usage: / [radius] [strength] fireplace: description: Superadmin command - Enable/disable fire placement. usage: / @@ -58,6 +61,9 @@ commands: mp: description: Use moblimiter to purge all mobs. usage: / + mp44: + description: Superadmin Command - Modern weaponry, FTW. Use 'draw' to start firing, 'sling' to stop firing. + usage: / [draw|sling] nether: description: Goto the nether. usage: / @@ -106,6 +112,9 @@ commands: survival: description: Quickly change your own gamemode to survival, or define someone's username to change theirs. usage: / [partialname] + tossmob: + description: Throw a mob in the direction you are facing when you left click with a stick. + usage: / [mobtype | off] [speed] tfbanlist: description: Shows all banned player names. Superadmins may optionally use 'purge' to clear the list. usage: / [purge]