From ccd13369e502c632f25f7832d5d073866d64813c Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Fri, 9 Mar 2012 14:01:04 -0500 Subject: [PATCH] Added userlist Build # tracking Exploding arrows --- build.xml | 9 + manifest.mf | 3 - nbproject/build-impl.xml | 2095 +++++++++-------- nbproject/genfiles.properties | 16 +- .../Commands/Command_gadmin.java | 4 +- .../Commands/Command_glist.java | 89 + .../Commands/Command_gtfo.java | 2 +- .../Commands/Command_saconfig.java | 2 +- .../TotalFreedomMod/Commands/Command_say.java | 20 +- .../Commands/Command_status.java | 12 +- .../Listener/TFM_EntityListener.java | 15 +- .../Listener/TFM_PlayerListener.java | 77 +- .../TotalFreedomMod/TFM_UserInfo.java | 5 +- .../TotalFreedomMod/TFM_UserList.java | 150 ++ .../TotalFreedomMod/TFM_Util.java | 29 +- .../TotalFreedomMod/TotalFreedomMod.java | 43 +- src/plugin.yml | 5 +- 17 files changed, 1445 insertions(+), 1131 deletions(-) delete mode 100644 manifest.mf create mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java create mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_UserList.java diff --git a/build.xml b/build.xml index 14ce5c6f..eeb8ca04 100644 --- a/build.xml +++ b/build.xml @@ -71,4 +71,13 @@ nbproject/build-impl.xml file. --> + + + + + + + + + diff --git a/manifest.mf b/manifest.mf deleted file mode 100644 index 328e8e5b..00000000 --- a/manifest.mf +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -X-COMMENT: Main-Class will be added automatically by build - diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index adb00ea5..4f26f1da 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -1,1042 +1,1053 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set test.src.dir - Must set build.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set JVM to use for profiling in profiler.info.jvm - Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - - - - - - java -cp "${run.classpath.with.dist.jar}" ${main.class} - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - java -jar "${dist.jar.resolved}" - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - - - - - - - - Must select one file in the IDE or set profile.class - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + Must select one file in the IDE or set profile.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 95790e22..3a0508f6 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=7bf70ec5 -build.xml.script.CRC32=b1031e10 -build.xml.stylesheet.CRC32=28e38971@1.44.1.45 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=7bf70ec5 -nbproject/build-impl.xml.script.CRC32=c53303a0 -nbproject/build-impl.xml.stylesheet.CRC32=0ae3a408@1.44.1.45 +build.xml.data.CRC32=7bf70ec5 +build.xml.script.CRC32=b1031e10 +build.xml.stylesheet.CRC32=28e38971@1.44.1.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=7bf70ec5 +nbproject/build-impl.xml.script.CRC32=ea1ae258 +nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.2.46 diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java index 00cf738a..0196dad9 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java @@ -51,7 +51,7 @@ public class Command_gadmin extends TFM_Command } else if (mode.equals("ipban")) { - String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim(); + String user_ip = p.getAddress().getAddress().getHostAddress(); String[] ip_parts = user_ip.split("\\."); if (ip_parts.length == 4) { @@ -63,7 +63,7 @@ public class Command_gadmin extends TFM_Command } else if (mode.equals("ban")) { - String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim(); + String user_ip = p.getAddress().getAddress().getHostAddress(); String[] ip_parts = user_ip.split("\\."); if (ip_parts.length == 4) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java new file mode 100644 index 00000000..aece7187 --- /dev/null +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java @@ -0,0 +1,89 @@ +package me.StevenLawson.TotalFreedomMod.Commands; + +import java.util.ArrayList; +import java.util.List; +import me.StevenLawson.TotalFreedomMod.TFM_UserList; +import me.StevenLawson.TotalFreedomMod.TFM_UserList.TFM_UserListEntry; +import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Command_glist extends TFM_Command +{ + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if (args.length != 2) + { + return false; + } + + if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin)) + { + String username; + List ip_addresses = new ArrayList(); + + try + { + Player p = getPlayer(args[1]); + + username = p.getName(); + ip_addresses.add(p.getAddress().getAddress().getHostName()); + } + catch (CantFindPlayerException ex) + { + TFM_UserListEntry entry = TFM_UserList.getInstance(plugin).getEntry(args[1]); + + if (entry == null) + { + sender.sendMessage("Can't find that user. If target is not logged in, make sure that you spelled the name exactly."); + return true; + } + + username = entry.getUsername(); + ip_addresses = entry.getIpAddresses(); + } + + String mode = args[0].toLowerCase(); + if (mode.equals("ban")) + { + Player p = server.getPlayerExact(username); + if (p != null) + { + p.setBanned(true); + p.kickPlayer("IP and username banned by Administrator."); + } + else + { + server.getOfflinePlayer(username).setBanned(true); + } + + for (String ip_address : ip_addresses) + { + server.banIP(ip_address); + String[] ip_address_parts = ip_address.split("\\."); + server.banIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*"); + } + } + else if (mode.equals("unban")) + { + server.getOfflinePlayer(username).setBanned(false); + + for (String ip_address : ip_addresses) + { + server.unbanIP(ip_address); + String[] ip_address_parts = ip_address.split("\\."); + server.unbanIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*"); + } + } + } + else + { + sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); + } + + return true; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java index 71641590..dea6fff1 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java @@ -64,7 +64,7 @@ public class Command_gtfo extends TFM_Command } //Ban IP Address: - String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim(); + String user_ip = p.getAddress().getAddress().getHostAddress(); String[] ip_parts = user_ip.split("\\."); if (ip_parts.length == 4) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java index f8462440..139bcccc 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java @@ -53,7 +53,7 @@ public class Command_saconfig extends TFM_Command } String user_name = p.getName().toLowerCase().trim(); - String new_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim(); + String new_ip = p.getAddress().getAddress().getHostAddress(); boolean something_changed = false; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_say.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_say.java index bab64aec..392d2a7c 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_say.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_say.java @@ -17,10 +17,28 @@ public class Command_say extends TFM_Command { return false; } + + String message = TFM_Util.implodeStringList(" ", Arrays.asList(args)); + + if (senderIsConsole && sender.getName().equals("Rcon")) + { + if (message.equals("WARNING: Server is restarting, you will be kicked")) + { + TFM_Util.bcastMsg("Server is going offline.", ChatColor.GRAY); + + for (Player p : server.getOnlinePlayers()) + { + p.kickPlayer("Server is going offline, come back in a few minutes."); + } + + server.shutdown(); + + return true; + } + } if (senderIsConsole || sender.isOp()) { - String message = TFM_Util.implodeStringList(" ", Arrays.asList(args)); TFM_Util.bcastMsg(String.format("[Server:%s] %s", sender.getName(), message), ChatColor.LIGHT_PURPLE); } else diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_status.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_status.java index e7546ee0..43415083 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_status.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_status.java @@ -1,6 +1,8 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.ChatColor; +import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -10,7 +12,15 @@ public class Command_status extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - sender.sendMessage(ChatColor.GRAY + "Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'."); + sender.sendMessage(ChatColor.GOLD + "Madgeek1450's Total Freedom Mod v" + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber + ", built " + TotalFreedomMod.buildDate); + sender.sendMessage(ChatColor.YELLOW + "Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'."); + sender.sendMessage(ChatColor.GOLD + "Loaded worlds:"); + + int i = 0; + for (World world : server.getWorlds()) + { + sender.sendMessage(ChatColor.GOLD + "World " + Integer.toString(i++) + ": " + world.getName() + " - " + Integer.toString(world.getPlayers().size()) + " players."); + } return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_EntityListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_EntityListener.java index dfabcfef..a957fa5c 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_EntityListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_EntityListener.java @@ -28,7 +28,7 @@ public class TFM_EntityListener implements Listener return; } - event.setYield(0.0f); + event.setYield(0.0F); } @EventHandler(priority = EventPriority.HIGH) @@ -138,4 +138,17 @@ public class TFM_EntityListener implements Listener event.setDroppedExp(0); } } + + @EventHandler(priority = EventPriority.NORMAL) + public void onProjectileHit(ProjectileHitEvent event) + { + if (TotalFreedomMod.allowExplosions) + { + Projectile entity = event.getEntity(); + if (event.getEntityType() == EntityType.ARROW && entity.getShooter() instanceof Player) + { + entity.getWorld().createExplosion(entity.getLocation(), 2F); + } + } + } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index 0a19a09c..a779e672 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -1,19 +1,12 @@ package me.StevenLawson.TotalFreedomMod.Listener; import java.util.Iterator; -import java.util.List; import java.util.Map.Entry; +import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; -import me.StevenLawson.TotalFreedomMod.TFM_LandmineData; -import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; -import me.StevenLawson.TotalFreedomMod.TFM_Util; -import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Server; +import me.StevenLawson.TotalFreedomMod.*; +import org.bukkit.*; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; @@ -252,38 +245,44 @@ public class TFM_PlayerListener implements Listener @EventHandler(priority = EventPriority.NORMAL) public void onPlayerChat(PlayerChatEvent event) { - Player p = event.getPlayer(); - - TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p); - playerdata.incrementMsgCount(); - - if (playerdata.getMsgCount() > 10) + try { - TFM_Util.bcastMsg(p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED); - TFM_Util.autoEject(p, "Kicked for spamming chat."); + Player p = event.getPlayer(); - playerdata.resetMsgCount(); + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p); + playerdata.incrementMsgCount(); - event.setCancelled(true); - return; - } - - if (Pattern.compile("^mad(?:geek)?(?:1450)?[\\?\\.\\!]?$").matcher(event.getMessage().toLowerCase()).find()) - { - List matches = server.matchPlayer("Madgeek1450"); - if (!matches.isEmpty()) + if (playerdata.getMsgCount() > 10) { - //TFM_Util.bcastMsg("<" + matches.get(0).getDisplayName() + "> Bitch says Madgeek..."); - - p.setGameMode(GameMode.SURVIVAL); - p.setFoodLevel(0); - p.setHealth(1); - - TNTPrimed tnt1 = p.getWorld().spawn(p.getLocation(), TNTPrimed.class); - tnt1.setFuseTicks(40); - tnt1.setPassenger(p); - tnt1.setVelocity(new Vector(0.0, 2.0, 0.0)); + TFM_Util.bcastMsg(p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED); + TFM_Util.autoEject(p, "Kicked for spamming chat."); + + playerdata.resetMsgCount(); + + event.setCancelled(true); + return; } + +// if (Pattern.compile("^mad(?:geek)?(?:1450)?[\\?\\.\\!]?$").matcher(event.getMessage().toLowerCase()).find()) +// { +// if (server.getPlayerExact("Madgeek1450") != null) +// { +// p.setGameMode(GameMode.SURVIVAL); +// p.setFoodLevel(0); +// p.setHealth(1); +// +// TNTPrimed tnt1 = p.getWorld().spawn(p.getLocation(), TNTPrimed.class); +// tnt1.setFuseTicks(40); +// tnt1.setPassenger(p); +// tnt1.setVelocity(new Vector(0.0, 2.0, 0.0)); +// } +// } + + event.setMessage(ChatColor.stripColor(event.getMessage())); + } + catch (Exception ex) + { + log.log(Level.SEVERE, null, ex); } } @@ -419,12 +418,14 @@ public class TFM_PlayerListener implements Listener { try { + TFM_UserList.getInstance(plugin).addUser(event.getPlayer()); + if (!server.getOnlineMode()) { Player p = event.getPlayer(); if (TotalFreedomMod.superadmins.contains(p.getName().toLowerCase())) { - String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim(); + String user_ip = p.getAddress().getAddress().getHostAddress(); if (user_ip != null && !user_ip.isEmpty()) { TFM_Util.checkPartialSuperadminIP(user_ip, plugin); diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java b/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java index b56494c0..4d5df07f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java @@ -7,7 +7,10 @@ import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.entity.*; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; public class TFM_UserInfo { diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_UserList.java b/src/me/StevenLawson/TotalFreedomMod/TFM_UserList.java new file mode 100644 index 00000000..77b9e8e9 --- /dev/null +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_UserList.java @@ -0,0 +1,150 @@ +package me.StevenLawson.TotalFreedomMod; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; + +public class TFM_UserList +{ + private static final String USERLIST_FILENAME = "userlist.yml"; + + private static final Logger log = Logger.getLogger("Minecraft"); + + private static TFM_UserList instance = null; + + private Map _userlist = new HashMap(); + private final TotalFreedomMod _plugin; + + protected TFM_UserList(TotalFreedomMod plugin) + { + _plugin = plugin; + + primeList(); + } + + private void primeList() + { + _userlist.clear(); + + FileConfiguration saved_userlist = YamlConfiguration.loadConfiguration(new File(_plugin.getDataFolder(), USERLIST_FILENAME)); + + for (String username : saved_userlist.getKeys(false)) + { + TFM_UserListEntry entry = new TFM_UserListEntry(username, saved_userlist.getStringList(username)); + _userlist.put(username, entry); + } + + for (Player p : _plugin.getServer().getOnlinePlayers()) + { + addUser(p); + } + + exportList(); + } + + private void exportList() + { + FileConfiguration new_userlist = new YamlConfiguration(); + + for (TFM_UserListEntry entry : _userlist.values()) + { + new_userlist.set(entry.getUsername(), entry.getIpAddresses()); + } + + try + { + new_userlist.save(new File(_plugin.getDataFolder(), USERLIST_FILENAME)); + } + catch (IOException ex) + { + log.log(Level.SEVERE, null, ex); + } + } + + public static TFM_UserList getInstance(TotalFreedomMod plugin) + { + if (instance == null) + { + instance = new TFM_UserList(plugin); + } + return instance; + } + + public void addUser(Player p) + { + addUser(p.getName(), p.getAddress().getAddress().getHostAddress()); + } + + public void addUser(String username, String ip_address) + { + username = username.toLowerCase(); + + TFM_UserListEntry entry = _userlist.get(username); + if (entry == null) + { + entry = new TFM_UserListEntry(username); + } + + _userlist.put(username, entry); + + if (entry.addIpAddress(ip_address)) + { + exportList(); + } + } + + public TFM_UserListEntry getEntry(Player p) + { + return getEntry(p.getName()); + } + + public TFM_UserListEntry getEntry(String username) + { + return _userlist.get(username.toLowerCase()); + } + + public class TFM_UserListEntry + { + private String _username; + private List _ip_addresses = new ArrayList(); + + public TFM_UserListEntry(String username, Listip_addresses) + { + _username = username; + _ip_addresses = ip_addresses; + } + + public TFM_UserListEntry(String username) + { + _username = username; + } + + public List getIpAddresses() + { + return _ip_addresses; + } + + public String getUsername() + { + return _username; + } + + public boolean addIpAddress(String ip_address) + { + if (!_ip_addresses.contains(ip_address)) + { + _ip_addresses.add(ip_address); + return true; + } + return false; + } + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java index bde60280..f21d7141 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java @@ -1,35 +1,16 @@ package me.StevenLawson.TotalFreedomMod; -import java.io.Closeable; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import java.net.InetSocketAddress; import java.net.URI; -import java.util.ArrayList; -import java.util.Deque; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.jar.JarFile; import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.WorldType; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; @@ -225,7 +206,7 @@ public class TFM_Util tfm.getDataFolder().mkdirs(); output = new FileOutputStream(actual); byte[] buf = new byte[8192]; - int length = 0; + int length; while ((length = input.read(buf)) > 0) { output.write(buf, 0, length); @@ -554,7 +535,7 @@ public class TFM_Util try { - player_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim(); + player_ip = p.getAddress().getAddress().getHostAddress(); Integer num_kicks = TFM_Util.eject_tracker.get(player_ip); if (num_kicks == null) diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java index 775bef26..7467a294 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java @@ -1,15 +1,15 @@ package me.StevenLawson.TotalFreedomMod; import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.io.InputStream; +import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command; -import me.StevenLawson.TotalFreedomMod.Listener.*; +import me.StevenLawson.TotalFreedomMod.Listener.TFM_BlockListener; +import me.StevenLawson.TotalFreedomMod.Listener.TFM_EntityListener; +import me.StevenLawson.TotalFreedomMod.Listener.TFM_PlayerListener; +import me.StevenLawson.TotalFreedomMod.Listener.TFM_WeatherListener; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Server; @@ -43,14 +43,18 @@ public class TotalFreedomMod extends JavaPlugin @Override public void onEnable() { + setAppProperties(); + loadMainConfig(); loadSuperadminConfig(); + TFM_UserList.getInstance(this); + registerEventHandlers(); server.getScheduler().scheduleAsyncRepeatingTask(this, new TFM_Heartbeat(this), HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L); - log.log(Level.INFO, "[" + getDescription().getName() + "] - Enabled! - Version: " + getDescription().getVersion() + " by Madgeek1450"); + log.log(Level.INFO, "[" + getDescription().getName() + "] - Enabled! - Version: " + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber + " by Madgeek1450"); TFM_Util.deleteFolder(new File("./_deleteme")); @@ -231,4 +235,29 @@ public class TotalFreedomMod extends JavaPlugin pm.registerEvents(playerListener, this); pm.registerEvents(weatherListener, this); } + + public static String pluginVersion = ""; + public static String buildNumber = ""; + public static String buildDate = ""; + + private void setAppProperties() + { + try + { + InputStream in; + Properties props = new Properties(); + + in = getClass().getResourceAsStream("/appinfo.properties"); + props.load(in); + in.close(); + + pluginVersion = props.getProperty("program.VERSION"); + buildNumber = props.getProperty("program.BUILDNUM"); + buildDate = props.getProperty("program.BUILDDATE"); + } + catch (Exception ex) + { + log.log(Level.SEVERE, null, ex); + } + } } diff --git a/src/plugin.yml b/src/plugin.yml index 2c7b79fd..fa96f3d9 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: TotalFreedomMod main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod -version: 2.4 +version: 2.5 description: Plugin for the Total Freedom server. author: StevenLawson / Madgeek1450 commands: @@ -58,6 +58,9 @@ commands: gcmd: description: Superadmin command - Send a command as someone else. usage: / + glist: + description: Superadmin command - Ban/Unban any player, even those who are not logged in anymore. + usage: / gtfo: description: Superadmin command - Makes someone GTFO (deop and ip ban by username). usage: /