From d72211c289f8bc47bada96d0e0d206a205ded8ba Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Thu, 22 Sep 2011 23:22:10 -0400 Subject: [PATCH] Added entity listener. --- .../TotalFreedomMod/TotalFreedomMod.java | 39 ++++++++++++++++++- .../TotalFreedomModEntityListener.java | 20 ++++++++++ src/plugin.yml | 3 ++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/me/StevenLawson/TotalFreedomMod/TotalFreedomModEntityListener.java diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java index e8a16559..12f77a6a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java @@ -11,6 +11,8 @@ import org.bukkit.GameMode; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.config.Configuration; @@ -19,6 +21,8 @@ public class TotalFreedomMod extends JavaPlugin private static final Logger log = Logger.getLogger("Minecraft"); protected static Configuration CONFIG; private List superadmins = new ArrayList(); + private final TotalFreedomModEntityListener entityListener = new TotalFreedomModEntityListener(this); + public Boolean allowExplosions = false; public void onEnable() { @@ -28,10 +32,15 @@ public class TotalFreedomMod extends JavaPlugin { log.log(Level.INFO, "[Total Freedom Mod] - Generating default config file (plugins/TotalFreedomMod/config.yml)..."); CONFIG.setProperty("superadmins", new String[] {"Madgeek1450", "markbyron"}); + CONFIG.setProperty("allow_explosions", false); CONFIG.save(); CONFIG.load(); } superadmins = CONFIG.getStringList("superadmins", null); + allowExplosions = CONFIG.getBoolean("allow_explosions", false); + + PluginManager pm = this.getServer().getPluginManager(); + pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Event.Priority.High, this); log.log(Level.INFO, "[Total Freedom Mod] - Enabled! - Version: " + this.getDescription().getVersion() + " by Madgeek1450"); log.log(Level.INFO, "[Total Freedom Mod] - Loaded superadmins: " + implodeStringList(", ", superadmins)); @@ -48,7 +57,7 @@ public class TotalFreedomMod extends JavaPlugin if (sender instanceof Player) { player = (Player)sender; - log.log(Level.INFO, String.format("[PLAYER_COMMAND] %s(%s): /%s %s", player.getName(), player.getDisplayName(), commandLabel, implodeStringList(" ", Arrays.asList(args)))); + log.log(Level.INFO, String.format("[PLAYER_COMMAND] %s(%s): /%s %s", player.getName(), player.getDisplayName().replaceAll("\\xA7.", ""), commandLabel, implodeStringList(" ", Arrays.asList(args)))); } else { @@ -67,7 +76,6 @@ public class TotalFreedomMod extends JavaPlugin { sender.setOp(true); sender.sendMessage(ChatColor.YELLOW + "You are now op!"); - log.log(Level.INFO, "[Total Freedom Mod]: " + sender.getName() + " gave themselves op."); } else { @@ -416,6 +424,33 @@ public class TotalFreedomMod extends JavaPlugin return true; } + else if(cmd.getName().equalsIgnoreCase("explosives")) + { + if (player == null || isUserSuperadmin(sender.getName())) + { + if (args.length != 1) + { + return false; + } + + if (args[0].equalsIgnoreCase("on")) + { + this.allowExplosions = true; + sender.sendMessage("Explosives are now enabled. Don't blow your fingers off!"); + } + else + { + this.allowExplosions = false; + sender.sendMessage("Explosives are now disabled. Funtime is over..."); + } + } + else + { + sender.sendMessage(ChatColor.YELLOW + "You do not have permission to use this command."); + } + + return true; + } return false; } diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomModEntityListener.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomModEntityListener.java new file mode 100644 index 00000000..ea50a16d --- /dev/null +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomModEntityListener.java @@ -0,0 +1,20 @@ +package me.StevenLawson.TotalFreedomMod; + +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityListener; + +public class TotalFreedomModEntityListener extends EntityListener +{ + public static TotalFreedomMod plugin; + + TotalFreedomModEntityListener(TotalFreedomMod instance) + { + plugin = instance; + } + + @Override + public void onEntityExplode(EntityExplodeEvent event) + { + event.setCancelled(!plugin.allowExplosions); + } +} diff --git a/src/plugin.yml b/src/plugin.yml index 04cd698c..7feee05b 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -10,6 +10,9 @@ commands: deopall: description: Superadmin command - Deop everyone on the server. usage: / + explosives: + description: Superadmin command - Enable/disable explosives. + usage: / [on|off] gtfo: description: Superadmin command - Makes someone GTFO (deop and ip ban by username). usage: / [partialname]