Various cleanup and bugfixes.

This commit is contained in:
Steven Lawson 2012-11-17 22:57:24 -05:00
parent 6083f94797
commit 59e6588779
16 changed files with 176 additions and 151 deletions

View file

@ -13,7 +13,7 @@ public class Command_adminmode extends TFM_Command
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!senderIsConsole || sender.getName().equalsIgnoreCase("remotebukkit"))
if (!senderIsConsole || TFM_Util.isFromClanforge(sender.getName()))
{
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the Telnet or BukkitHttpd console.");
return true;

View file

@ -15,11 +15,6 @@ public class Command_csay extends TFM_Command
{
String sender_name = sender.getName();
if (sender_name.equalsIgnoreCase("remotebukkit"))
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
}
sender_name = sender_name.split("-")[0];
StringBuilder outmessage_bldr = new StringBuilder();

View file

@ -12,7 +12,7 @@ public class Command_kicknoob extends TFM_Command
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!senderIsConsole || sender.getName().equalsIgnoreCase("remotebukkit"))
if (!senderIsConsole || TFM_Util.isFromClanforge(sender.getName()))
{
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the Telnet or BukkitHttpd console.");
return true;

View file

@ -3,6 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
@ -14,7 +15,7 @@ public class Command_list extends TFM_Command
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
final boolean is_clanforge = sender.getName().equalsIgnoreCase("remotebukkit");
final boolean is_clanforge = TFM_Util.isFromClanforge(sender.getName());
StringBuilder onlineStats = new StringBuilder();
StringBuilder onlineUsers = new StringBuilder();

View file

@ -67,7 +67,7 @@ public class Command_lockup extends TFM_Command
startLockup(p);
TFM_Util.playerMsg(sender, "Locked up " + p.getName() + ".");
}
else if (args[1].equalsIgnoreCase("off"))
else if (TFM_Util.isStopCommand(args[1]))
{
final Player p;
try

View file

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
@ -11,7 +12,7 @@ public class Command_moblimiter extends TFM_Command
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!senderIsConsole || sender.getName().equalsIgnoreCase("remotebukkit"))
if (!senderIsConsole || TFM_Util.isFromClanforge(sender.getName()))
{
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the Telnet or BukkitHttpd console.");
return true;

View file

@ -21,7 +21,7 @@ public class Command_mp extends TFM_Command
{
for (Entity ent : world.getLivingEntities())
{
if (ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime || ent instanceof EnderDragon)
if (ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime || ent instanceof EnderDragon || ent instanceof Ambient)
{
ent.remove();
removed++;

View file

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
@ -11,7 +12,7 @@ public class Command_nonuke extends TFM_Command
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!senderIsConsole || sender.getName().equalsIgnoreCase("remotebukkit"))
if (!senderIsConsole || TFM_Util.isFromClanforge(sender.getName()))
{
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the Telnet or BukkitHttpd console.");
return true;

View file

@ -12,7 +12,7 @@ public class Command_rawsay extends TFM_Command
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!senderIsConsole || sender.getName().equalsIgnoreCase("remotebukkit"))
if (!senderIsConsole || TFM_Util.isFromClanforge(sender.getName()))
{
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the Telnet or BukkitHttpd console.");
return true;

View file

@ -1,6 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_RunSystemCommand;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -11,7 +12,7 @@ public class Command_terminal extends TFM_Command
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!senderIsConsole || sender.getName().equalsIgnoreCase("remotebukkit"))
if (!senderIsConsole || TFM_Util.isFromClanforge(sender.getName()))
{
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the Telnet or BukkitHttpd console.");
return true;

View file

@ -1,9 +1,9 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.Map.Entry;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
@ -43,12 +43,7 @@ public class Command_tossmob extends TFM_Command
if (args[0].equalsIgnoreCase("list"))
{
StringBuilder output = new StringBuilder("Supported mobs: ");
for (Entry<String, EntityType> mob : TFM_Util.mobtypes.entrySet())
{
output.append(mob.getKey()).append(", ");
}
sender.sendMessage(ChatColor.GREEN + output.toString());
sender.sendMessage(ChatColor.GREEN + "Supported mobs: " + StringUtils.join(TFM_Util.mobtypes.keySet(), ", "));
return true;
}

View file

@ -14,7 +14,7 @@ public class Command_ziptool extends TFM_Command
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!senderIsConsole || sender.getName().equalsIgnoreCase("remotebukkit"))
if (!senderIsConsole || TFM_Util.isFromClanforge(sender.getName()))
{
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the Telnet or BukkitHttpd console.");
return true;

View file

@ -64,6 +64,12 @@ public class TFM_EntityListener implements Listener
{
if (TotalFreedomMod.mobLimiterEnabled)
{
if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.EGG))
{
event.setCancelled(true);
return;
}
Entity spawned = event.getEntity();
if (spawned instanceof EnderDragon)
@ -98,6 +104,11 @@ public class TFM_EntityListener implements Listener
return;
}
}
else if (spawned instanceof Bat)
{
event.setCancelled(true);
return;
}
if (TotalFreedomMod.mobLimiterMax > 0)
{

View file

@ -1,7 +1,6 @@
package me.StevenLawson.TotalFreedomMod;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@ -16,6 +15,7 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.util.FileUtil;
public class TFM_SuperadminList
{
@ -41,29 +41,43 @@ public class TFM_SuperadminList
public static void loadSuperadminList()
{
convertV1List();
superadminList.clear();
TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file);
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
if (config.isConfigurationSection("superadmins"))
try
{
ConfigurationSection section = config.getConfigurationSection("superadmins");
// convertV1List();
for (String admin_name : section.getKeys(false))
superadminList.clear();
TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file);
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
if (config.isConfigurationSection("superadmins"))
{
TFM_Superadmin superadmin = new TFM_Superadmin(admin_name, section.getConfigurationSection(admin_name));
superadminList.put(admin_name.toLowerCase(), superadmin);
}
}
else
{
TFM_Log.warning("Missing superadmins section in superadmin.yml.");
}
ConfigurationSection section = config.getConfigurationSection("superadmins");
updateIndexLists();
for (String admin_name : section.getKeys(false))
{
TFM_Superadmin superadmin = new TFM_Superadmin(admin_name, section.getConfigurationSection(admin_name));
superadminList.put(admin_name.toLowerCase(), superadmin);
}
}
else
{
TFM_Log.warning("Missing superadmins section in superadmin.yml.");
}
updateIndexLists();
}
catch (Exception ex)
{
TFM_Log.severe(ex);
}
}
public static void backupSavedList()
{
File a = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE);
File b = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE + ".bak");
FileUtil.copy(a, b);
}
public static void updateIndexLists()
@ -98,51 +112,57 @@ public class TFM_SuperadminList
}
}
public static void convertV1List()
{
superadminList.clear();
TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file);
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
if (!config.isConfigurationSection("superadmins"))
{
for (String admin_name : config.getKeys(false))
{
TFM_Superadmin superadmin = new TFM_Superadmin(admin_name, config.getStringList(admin_name), new Date(), "", false, new ArrayList<String>());
superadminList.put(admin_name.toLowerCase(), superadmin);
}
saveSuperadminList();
}
}
// public static void convertV1List()
// {
// try
// {
// superadminList.clear();
//
// TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file);
// FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
//
// if (!config.isConfigurationSection("superadmins"))
// {
// for (String admin_name : config.getKeys(false))
// {
// TFM_Superadmin superadmin = new TFM_Superadmin(admin_name, config.getStringList(admin_name), new Date(), "", false, new ArrayList<String>());
// superadminList.put(admin_name.toLowerCase(), superadmin);
// }
//
// saveSuperadminList();
// }
// }
// catch (Exception ex)
// {
// TFM_Log.severe(ex);
// }
// }
public static void saveSuperadminList()
{
updateIndexLists();
YamlConfiguration config = new YamlConfiguration();
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
while (it.hasNext())
{
Entry<String, TFM_Superadmin> pair = it.next();
String admin_name = pair.getKey().toLowerCase();
TFM_Superadmin superadmin = pair.getValue();
config.set("superadmins." + admin_name + ".ips", superadmin.getIps());
config.set("superadmins." + admin_name + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin()));
config.set("superadmins." + admin_name + ".custom_login_message", superadmin.getCustomLoginMessage());
config.set("superadmins." + admin_name + ".is_super_awesome_admin", superadmin.isSuperAwesomeAdmin());
config.set("superadmins." + admin_name + ".console_aliases", superadmin.getConsoleAliases());
}
try
{
updateIndexLists();
YamlConfiguration config = new YamlConfiguration();
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
while (it.hasNext())
{
Entry<String, TFM_Superadmin> pair = it.next();
String admin_name = pair.getKey().toLowerCase();
TFM_Superadmin superadmin = pair.getValue();
config.set("superadmins." + admin_name + ".ips", superadmin.getIps());
config.set("superadmins." + admin_name + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin()));
config.set("superadmins." + admin_name + ".custom_login_message", superadmin.getCustomLoginMessage());
config.set("superadmins." + admin_name + ".is_super_awesome_admin", superadmin.isSuperAwesomeAdmin());
config.set("superadmins." + admin_name + ".console_aliases", superadmin.getConsoleAliases());
}
config.save(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
}
catch (IOException ex)
catch (Exception ex)
{
TFM_Log.severe(ex);
}
@ -246,48 +266,55 @@ public class TFM_SuperadminList
public static boolean checkPartialSuperadminIP(String user_ip)
{
user_ip = user_ip.trim();
if (superadminIPs.contains(user_ip))
try
{
return true;
}
else
{
String[] user_octets = user_ip.split("\\.");
if (user_octets.length != 4)
user_ip = user_ip.trim();
if (superadminIPs.contains(user_ip))
{
return false;
}
String match_ip = null;
for (String test_ip : getSuperadminIPs())
{
String[] test_octets = test_ip.split("\\.");
if (test_octets.length == 4)
{
if (user_octets[0].equals(test_octets[0]) && user_octets[1].equals(test_octets[1]) && user_octets[2].equals(test_octets[2]))
{
match_ip = test_ip;
break;
}
}
}
if (match_ip != null)
{
TFM_Superadmin admin_entry = getAdminEntryByIP(match_ip);
if (admin_entry != null)
{
List<String> ips = admin_entry.getIps();
ips.add(user_ip);
admin_entry.setIps(ips);
saveSuperadminList();
}
return true;
}
else
{
String[] user_octets = user_ip.split("\\.");
if (user_octets.length != 4)
{
return false;
}
String match_ip = null;
for (String test_ip : getSuperadminIPs())
{
String[] test_octets = test_ip.split("\\.");
if (test_octets.length == 4)
{
if (user_octets[0].equals(test_octets[0]) && user_octets[1].equals(test_octets[1]) && user_octets[2].equals(test_octets[2]))
{
match_ip = test_ip;
break;
}
}
}
if (match_ip != null)
{
TFM_Superadmin admin_entry = getAdminEntryByIP(match_ip);
if (admin_entry != null)
{
List<String> ips = admin_entry.getIps();
ips.add(user_ip);
admin_entry.setIps(ips);
saveSuperadminList();
}
return true;
}
}
}
catch (Exception ex)
{
TFM_Log.severe(ex);
}
return false;

View file

@ -23,42 +23,29 @@ import org.bukkit.entity.*;
public class TFM_Util
{
private static Map<String, Integer> eject_tracker = new HashMap<String, Integer>();
private static final Map<String, Integer> eject_tracker = new HashMap<String, Integer>();
public static final Map<String, EntityType> mobtypes = new HashMap<String, EntityType>();
public static final List<String> stop_commands = new ArrayList<String>();
public static final List<String> stop_commands = Arrays.asList("stop", "off", "end", "halt", "die");
public static final List<String> restricted_senders = Arrays.asList("rcon, remotebukkit");
static
{
mobtypes.put("blaze", EntityType.BLAZE);
mobtypes.put("cavespider", EntityType.CAVE_SPIDER);
mobtypes.put("chicken", EntityType.CHICKEN);
mobtypes.put("cow", EntityType.COW);
mobtypes.put("creeper", EntityType.CREEPER);
mobtypes.put("enderdragon", EntityType.ENDER_DRAGON);
mobtypes.put("enderman", EntityType.ENDERMAN);
mobtypes.put("ghast", EntityType.GHAST);
mobtypes.put("giant", EntityType.GIANT);
mobtypes.put("irongolem", EntityType.IRON_GOLEM);
mobtypes.put("mushroomcow", EntityType.MUSHROOM_COW);
mobtypes.put("ocelot", EntityType.OCELOT);
mobtypes.put("pig", EntityType.PIG);
mobtypes.put("pigzombie", EntityType.PIG_ZOMBIE);
mobtypes.put("sheep", EntityType.SHEEP);
mobtypes.put("silverfish", EntityType.SILVERFISH);
mobtypes.put("skeleton", EntityType.SKELETON);
mobtypes.put("slime", EntityType.SLIME);
mobtypes.put("snowman", EntityType.SNOWMAN);
mobtypes.put("spider", EntityType.SPIDER);
mobtypes.put("squid", EntityType.SQUID);
mobtypes.put("villager", EntityType.VILLAGER);
mobtypes.put("wolf", EntityType.WOLF);
mobtypes.put("zombie", EntityType.ZOMBIE);
stop_commands.add("stop");
stop_commands.add("off");
stop_commands.add("end");
stop_commands.add("halt");
stop_commands.add("die");
for (EntityType entity_type : EntityType.values())
{
try
{
if (entity_type.getName() != null)
{
if (Creature.class.isAssignableFrom(entity_type.getEntityClass()))
{
mobtypes.put(entity_type.getName().toLowerCase(), entity_type);
}
}
}
catch (Exception ex)
{
}
}
}
private TFM_Util()
@ -910,6 +897,11 @@ public class TFM_Util
return new Date(0L);
}
}
public static boolean isFromClanforge(String sender_name)
{
return restricted_senders.contains(sender_name.toLowerCase());
}
// I wrote all this before i discovered getTargetBlock >.> - might come in handy some day...
// public static final double LOOKAT_VIEW_HEIGHT = 1.65;
// public static final double LOOKAT_STEP_DISTANCE = 0.2;

View file

@ -255,6 +255,7 @@ public class TotalFreedomMod extends JavaPlugin
{
try
{
TFM_SuperadminList.backupSavedList();
TFM_SuperadminList.loadSuperadminList();
superadmins = TFM_SuperadminList.getSuperadminNames();