Added entity listener.

This commit is contained in:
Steven Lawson 2011-09-22 23:22:10 -04:00
parent 10c2354821
commit d72211c289
3 changed files with 60 additions and 2 deletions

View File

@ -11,6 +11,8 @@ import org.bukkit.GameMode;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.config.Configuration; import org.bukkit.util.config.Configuration;
@ -19,6 +21,8 @@ public class TotalFreedomMod extends JavaPlugin
private static final Logger log = Logger.getLogger("Minecraft"); private static final Logger log = Logger.getLogger("Minecraft");
protected static Configuration CONFIG; protected static Configuration CONFIG;
private List<String> superadmins = new ArrayList<String>(); private List<String> superadmins = new ArrayList<String>();
private final TotalFreedomModEntityListener entityListener = new TotalFreedomModEntityListener(this);
public Boolean allowExplosions = false;
public void onEnable() 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)..."); log.log(Level.INFO, "[Total Freedom Mod] - Generating default config file (plugins/TotalFreedomMod/config.yml)...");
CONFIG.setProperty("superadmins", new String[] {"Madgeek1450", "markbyron"}); CONFIG.setProperty("superadmins", new String[] {"Madgeek1450", "markbyron"});
CONFIG.setProperty("allow_explosions", false);
CONFIG.save(); CONFIG.save();
CONFIG.load(); CONFIG.load();
} }
superadmins = CONFIG.getStringList("superadmins", null); 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] - Enabled! - Version: " + this.getDescription().getVersion() + " by Madgeek1450");
log.log(Level.INFO, "[Total Freedom Mod] - Loaded superadmins: " + implodeStringList(", ", superadmins)); log.log(Level.INFO, "[Total Freedom Mod] - Loaded superadmins: " + implodeStringList(", ", superadmins));
@ -48,7 +57,7 @@ public class TotalFreedomMod extends JavaPlugin
if (sender instanceof Player) if (sender instanceof Player)
{ {
player = (Player)sender; 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 else
{ {
@ -67,7 +76,6 @@ public class TotalFreedomMod extends JavaPlugin
{ {
sender.setOp(true); sender.setOp(true);
sender.sendMessage(ChatColor.YELLOW + "You are now op!"); sender.sendMessage(ChatColor.YELLOW + "You are now op!");
log.log(Level.INFO, "[Total Freedom Mod]: " + sender.getName() + " gave themselves op.");
} }
else else
{ {
@ -416,6 +424,33 @@ public class TotalFreedomMod extends JavaPlugin
return true; 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; return false;
} }

View File

@ -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);
}
}

View File

@ -10,6 +10,9 @@ commands:
deopall: deopall:
description: Superadmin command - Deop everyone on the server. description: Superadmin command - Deop everyone on the server.
usage: /<command> usage: /<command>
explosives:
description: Superadmin command - Enable/disable explosives.
usage: /<command> [on|off]
gtfo: gtfo:
description: Superadmin command - Makes someone GTFO (deop and ip ban by username). description: Superadmin command - Makes someone GTFO (deop and ip ban by username).
usage: /<command> [partialname] usage: /<command> [partialname]