Added saconfig

Moved superadmin lists
Added CantFindPlayerException
Code cleanup
This commit is contained in:
Steven Lawson 2011-10-18 22:52:32 -04:00
parent 0a2f7fb4c5
commit f84f10a7ad
20 changed files with 320 additions and 220 deletions

View File

@ -33,8 +33,4 @@ disable_weather: true
# Superadmins: Users that can always log in and use the most powerful commands:
# When online-mode = false, only superadmin_ips will be used.
superadmins:
- Madgeek1450
- markbyron
superadmin_ips:
- 127.0.0.1
# The superadmin lists have been moved to superadmin.yml

View File

@ -0,0 +1,13 @@
package me.StevenLawson.TotalFreedomMod.Commands;
public class CantFindPlayerException extends Exception
{
public CantFindPlayerException()
{
}
public CantFindPlayerException(String msg)
{
super("Can't find player: " + msg);
}
}

View File

@ -1,10 +1,8 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -26,15 +24,14 @@ public class Command_cage extends TFM_Command
}
Player p;
List<Player> matches = Bukkit.matchPlayer(args[0]);
if (matches.isEmpty())
try
{
sender.sendMessage(ChatColor.GRAY + "Can't find user " + args[0]);
return true;
p = getPlayer(args[0]);
}
else
catch (CantFindPlayerException ex)
{
p = matches.get(0);
sender.sendMessage(ex.getMessage());
return true;
}
TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p, plugin);

View File

@ -3,6 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -21,32 +22,29 @@ public class Command_creative extends TFM_Command
return true;
}
}
else
{
if (!sender.isOp())
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
}
Player p;
if (args.length == 0)
{
p = Bukkit.getPlayerExact(sender.getName());
p = sender_p;
}
else
{
List<Player> matches = Bukkit.matchPlayer(args[0]);
if (matches.isEmpty())
try
{
sender.sendMessage("Can't find user " + args[0]);
p = getPlayer(args[0]);
}
catch (CantFindPlayerException ex)
{
sender.sendMessage(ex.getMessage());
return true;
}
else
{
p = matches.get(0);
}
}
sender.sendMessage("Setting " + p.getName() + " to game mode 'Creative'.");

View File

@ -29,7 +29,7 @@ public class Command_expel extends TFM_Command
{
try
{
radius = Double.parseDouble(args[0]);
radius = Math.max(1.0, Math.min(200.0, Double.parseDouble(args[0])));
}
catch (NumberFormatException nfex)
{
@ -40,7 +40,7 @@ public class Command_expel extends TFM_Command
{
try
{
strength = Double.parseDouble(args[1]);
strength = Math.max(0.0, Math.min(200.0, Double.parseDouble(args[1])));
}
catch (NumberFormatException nfex)
{

View File

@ -22,7 +22,7 @@ public class Command_explosives extends TFM_Command
{
try
{
plugin.explosiveRadius = Double.parseDouble(args[1]);
plugin.explosiveRadius = Math.max(1.0, Math.min(30.0, Double.parseDouble(args[1])));
}
catch (NumberFormatException nfex)
{

View File

@ -37,15 +37,14 @@ public class Command_fr extends TFM_Command
else
{
Player p;
List<Player> matches = Bukkit.matchPlayer(args[0]);
if (matches.isEmpty())
try
{
sender.sendMessage("Can't find user " + args[0]);
return true;
p = getPlayer(args[0]);
}
else
catch (CantFindPlayerException ex)
{
p = matches.get(0);
sender.sendMessage(ex.getMessage());
return true;
}
TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p, plugin);

View File

@ -22,15 +22,14 @@ public class Command_gcmd extends TFM_Command
}
Player p;
List<Player> matches = Bukkit.matchPlayer(args[0]);
if (matches.isEmpty())
try
{
sender.sendMessage(ChatColor.GRAY + "Can't find user " + args[0]);
return true;
p = getPlayer(args[0]);
}
else
catch (CantFindPlayerException ex)
{
p = matches.get(0);
sender.sendMessage(ex.getMessage());
return true;
}
String outcommand = "";
@ -43,9 +42,9 @@ public class Command_gcmd extends TFM_Command
}
outcommand = outcommand_bldr.toString().trim();
}
catch (Exception cmdex)
catch (Throwable ex)
{
sender.sendMessage(ChatColor.GRAY + "Error building command: " + cmdex.getMessage());
sender.sendMessage(ChatColor.GRAY + "Error building command: " + ex.getMessage());
}
try
@ -60,9 +59,9 @@ public class Command_gcmd extends TFM_Command
sender.sendMessage(ChatColor.GRAY + "Unknown error sending command.");
}
}
catch (Exception cmdex)
catch (Throwable ex)
{
sender.sendMessage(ChatColor.GRAY + "Error sending command: " + cmdex.getMessage());
sender.sendMessage(ChatColor.GRAY + "Error sending command: " + ex.getMessage());
}
}
else

View File

@ -24,15 +24,14 @@ public class Command_gtfo extends TFM_Command
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
Player p;
List<Player> matches = Bukkit.matchPlayer(args[0]);
if (matches.isEmpty())
try
{
sender.sendMessage("Can't find user " + args[0]);
return true;
p = getPlayer(args[0]);
}
else
catch (CantFindPlayerException ex)
{
p = matches.get(0);
sender.sendMessage(ex.getMessage());
return true;
}
TFM_Util.tfm_broadcastMessage(p.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);

View File

@ -23,7 +23,7 @@ public class Command_nonuke extends TFM_Command
{
try
{
plugin.nukeMonitorRange = Double.parseDouble(args[1]);
plugin.nukeMonitorRange = Math.max(1.0, Math.min(500.0, Double.parseDouble(args[1])));
}
catch (NumberFormatException nfex)
{
@ -34,7 +34,7 @@ public class Command_nonuke extends TFM_Command
{
try
{
plugin.nukeMonitorCountBreak = Integer.parseInt(args[2]);
plugin.nukeMonitorCountBreak = Math.max(1, Math.min(500, Integer.parseInt(args[2])));
}
catch (NumberFormatException nfex)
{

View File

@ -1,10 +1,8 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
@ -25,15 +23,14 @@ public class Command_orbit extends TFM_Command
}
Player p;
List<Player> matches = Bukkit.matchPlayer(args[0]);
if (matches.isEmpty())
try
{
sender.sendMessage(ChatColor.GRAY + "Can't find user " + args[0]);
return true;
p = getPlayer(args[0]);
}
else
catch (CantFindPlayerException ex)
{
p = matches.get(0);
sender.sendMessage(ex.getMessage());
return true;
}
TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p, plugin);
@ -51,11 +48,10 @@ public class Command_orbit extends TFM_Command
try
{
strength = Double.parseDouble(args[1]);
strength = Math.max(1.0, Math.min(150.0, Double.parseDouble(args[1])));
}
catch (NumberFormatException nfex)
{
strength = 10.0;
}
}

View File

@ -24,15 +24,14 @@ public class Command_qjail extends TFM_Command
}
Player p;
List<Player> matches = Bukkit.matchPlayer(args[0]);
if (matches.isEmpty())
try
{
sender.sendMessage(ChatColor.GRAY + "Can't find user " + args[0]);
return true;
p = getPlayer(args[0]);
}
else
catch (CantFindPlayerException ex)
{
p = matches.get(0);
sender.sendMessage(ex.getMessage());
return true;
}
//Deop

View File

@ -47,7 +47,7 @@ public class Command_radar extends TFM_Command
{
try
{
countmax = Integer.parseInt(args[0]);
countmax = Math.max(1, Math.min(64, Integer.parseInt(args[0])));
}
catch (NumberFormatException nfex)
{

View File

@ -0,0 +1,74 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
public class Command_saconfig 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"))
{
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the Telnet or BukkitHttpd console.");
return true;
}
if (args.length < 2)
{
return false;
}
if (args[0].equalsIgnoreCase("add"))
{
Player p;
try
{
p = getPlayer(args[1]);
}
catch (CantFindPlayerException ex)
{
sender.sendMessage(ex.getMessage());
return true;
}
String user_name = p.getName().toLowerCase().trim();
String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
sender.sendMessage(ChatColor.GRAY + "Adding " + user_name + " as a superadmin, with current IP = " + user_ip);
if (!plugin.superadmins.contains(user_name))
{
plugin.superadmins.add(user_name);
}
if (!plugin.superadmin_ips.contains(user_ip))
{
plugin.superadmin_ips.add(user_ip);
}
try
{
FileConfiguration sa_config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
sa_config.set("superadmins", plugin.superadmins);
sa_config.set("superadmin_ips", plugin.superadmin_ips);
sa_config.save(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
}
catch (IOException ex)
{
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
}
}
return true;
}
}

View File

@ -3,6 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -21,32 +22,29 @@ public class Command_survival extends TFM_Command
return true;
}
}
else
{
if (!sender.isOp())
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
}
Player p;
if (args.length == 0)
{
p = Bukkit.getPlayerExact(sender.getName());
p = sender_p;
}
else
{
List<Player> matches = Bukkit.matchPlayer(args[0]);
if (matches.isEmpty())
try
{
sender.sendMessage("Can't find user " + args[0]);
p = getPlayer(args[0]);
}
catch (CantFindPlayerException ex)
{
sender.sendMessage(ex.getMessage());
return true;
}
else
{
p = matches.get(0);
}
}
sender.sendMessage("Setting " + p.getName() + " to game mode 'Survival'.");

View File

@ -1,7 +1,9 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.List;
import java.util.logging.Logger;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -27,4 +29,17 @@ public class TFM_Command
{
this.plugin = plugin;
}
public Player getPlayer(String partialname) throws CantFindPlayerException
{
List<Player> matches = Bukkit.matchPlayer(partialname);
if (matches.isEmpty())
{
throw new CantFindPlayerException(partialname);
}
else
{
return matches.get(0);
}
}
}

View File

@ -8,7 +8,7 @@ public class TFM_Heartbeat implements Runnable
{
private TotalFreedomMod plugin;
TFM_Heartbeat(TotalFreedomMod instance)
public TFM_Heartbeat(TotalFreedomMod instance)
{
this.plugin = instance;
}

View File

@ -27,6 +27,7 @@ public class TotalFreedomMod extends JavaPlugin
public static final long HEARTBEAT_RATE = 5L; //Seconds
public static final String CONFIG_FILE = "config.yml";
public static final String SUPERADMIN_FILE = "superadmin.yml";
private static final String COMMAND_PATH = "me.StevenLawson.TotalFreedomMod.Commands";
private static final String COMMAND_PREFIX = "Command_";
@ -42,7 +43,9 @@ public class TotalFreedomMod extends JavaPlugin
@Override
public void onEnable()
{
loadTFMConfig();
loadMainConfig();
loadSuperadminConfig();
registerEventHandlers();
Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new TFM_Heartbeat(this), HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
@ -93,7 +96,7 @@ public class TotalFreedomMod extends JavaPlugin
}
catch (Throwable ex)
{
log.log(Level.SEVERE, "Command not loaded: " + cmd.getName(), ex);
log.log(Level.SEVERE, "[" + getDescription().getName() + "] Command not loaded: " + cmd.getName(), ex);
sender.sendMessage(ChatColor.RED + "Command Error: Command not loaded: " + cmd.getName());
return true;
}
@ -109,7 +112,7 @@ public class TotalFreedomMod extends JavaPlugin
}
catch (Throwable ex)
{
log.log(Level.SEVERE, "Command Error: " + commandLabel, ex);
log.log(Level.SEVERE, "[" + getDescription().getName() + "] Command Error: " + commandLabel, ex);
sender.sendMessage(ChatColor.RED + "Unknown Command Error.");
}
@ -132,13 +135,10 @@ public class TotalFreedomMod extends JavaPlugin
public Boolean preprocessLogEnabled = true;
public Boolean disableNight = true;
public Boolean disableWeather = true;
public List<String> superadmins = new ArrayList<String>();
public List<String> superadmin_ips = new ArrayList<String>();
private void loadTFMConfig()
public void loadMainConfig()
{
TFM_Util.createDefaultConfiguration(CONFIG_FILE, this, getFile());
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), CONFIG_FILE));
allowFirePlace = config.getBoolean("allow_fire_place", allowFirePlace);
@ -157,9 +157,18 @@ public class TotalFreedomMod extends JavaPlugin
preprocessLogEnabled = config.getBoolean("preprocess_log", preprocessLogEnabled);
disableNight = config.getBoolean("disable_night", disableNight);
disableWeather = config.getBoolean("disable_weather", disableWeather);
}
public List<String> superadmins = new ArrayList<String>();
public List<String> superadmin_ips = new ArrayList<String>();
public void loadSuperadminConfig()
{
TFM_Util.createDefaultConfiguration(SUPERADMIN_FILE, this, getFile());
FileConfiguration sa_config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), SUPERADMIN_FILE));
superadmins = new ArrayList<String>();
List<String> superadmins_temp = (List<String>) config.getList("superadmins", null);
List<String> superadmins_temp = (List<String>) sa_config.getList("superadmins", null);
if (superadmins_temp == null || superadmins_temp.isEmpty())
{
superadmins.add("Madgeek1450");
@ -174,7 +183,7 @@ public class TotalFreedomMod extends JavaPlugin
}
superadmin_ips = new ArrayList<String>();
List<String> superadmin_ips_temp = (List<String>) config.getList("superadmin_ips", null);
List<String> superadmin_ips_temp = (List<String>) sa_config.getList("superadmin_ips", null);
if (superadmin_ips_temp == null || superadmin_ips_temp.isEmpty())
{
superadmin_ips.add("127.0.0.1");

View File

@ -95,6 +95,9 @@ commands:
rd:
description: Remove drops, arrows, primed TNT, and expierence orbs in all worlds.
usage: /<command>
saconfig:
description: Owner command - Manage superadmins.
usage: /<command> <add> <username>
say:
description: Broadcasts the given message as the console, includes sender name.
usage: /<command> <message>

5
src/superadmin.yml Normal file
View File

@ -0,0 +1,5 @@
superadmins:
- Madgeek1450
- markbyron
superadmin_ips:
- 127.0.0.1