Created utility class.

Code cleanup.
This commit is contained in:
Steven Lawson 2011-10-13 19:07:52 -04:00
parent 47279beb4d
commit 85f32fcc76
10 changed files with 358 additions and 354 deletions

View File

@ -6,11 +6,7 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.*;
import org.bukkit.inventory.ItemStack;
public class TFM_BlockListener extends BlockListener
@ -69,7 +65,7 @@ public class TFM_BlockListener extends BlockListener
p.setGameMode(GameMode.SURVIVAL);
p.getInventory().clear();
TotalFreedomMod.tfm_broadcastMessage(p.getName() + " has been flagged for possible freecam nuking.", ChatColor.RED);
TFM_Util.tfm_broadcastMessage(p.getName() + " has been flagged for possible freecam nuking.", ChatColor.RED);
playerdata.resetFreecamDestroyCount();
@ -81,7 +77,7 @@ public class TFM_BlockListener extends BlockListener
playerdata.incrementBlockDestroyCount();
if (playerdata.getBlockDestroyCount() > plugin.nukeMonitorCountBreak)
{
TotalFreedomMod.tfm_broadcastMessage(p.getName() + " is breaking blocks too fast!", ChatColor.RED);
TFM_Util.tfm_broadcastMessage(p.getName() + " is breaking blocks too fast!", ChatColor.RED);
p.setOp(false);
p.setGameMode(GameMode.SURVIVAL);
@ -119,7 +115,7 @@ public class TFM_BlockListener extends BlockListener
p.setGameMode(GameMode.SURVIVAL);
p.getInventory().clear();
TotalFreedomMod.tfm_broadcastMessage(p.getName() + " has been flagged for possible freecam building.", ChatColor.RED);
TFM_Util.tfm_broadcastMessage(p.getName() + " has been flagged for possible freecam building.", ChatColor.RED);
playerdata.resetFreecamPlaceCount();
@ -136,7 +132,7 @@ public class TFM_BlockListener extends BlockListener
{
log.info(String.format("%s placed lava @ %s",
p.getName(),
TotalFreedomMod.formatLocation(event.getBlock().getLocation())));
TFM_Util.formatLocation(event.getBlock().getLocation())));
p.getInventory().clear(p.getInventory().getHeldItemSlot());
}
@ -158,7 +154,7 @@ public class TFM_BlockListener extends BlockListener
{
log.info(String.format("%s placed water @ %s",
p.getName(),
TotalFreedomMod.formatLocation(event.getBlock().getLocation())));
TFM_Util.formatLocation(event.getBlock().getLocation())));
p.getInventory().clear(p.getInventory().getHeldItemSlot());
}
@ -180,7 +176,7 @@ public class TFM_BlockListener extends BlockListener
{
log.info(String.format("%s placed fire @ %s",
p.getName(),
TotalFreedomMod.formatLocation(event.getBlock().getLocation())));
TFM_Util.formatLocation(event.getBlock().getLocation())));
p.getInventory().clear(p.getInventory().getHeldItemSlot());
}
@ -202,7 +198,7 @@ public class TFM_BlockListener extends BlockListener
{
log.info(String.format("%s placed TNT @ %s",
p.getName(),
TotalFreedomMod.formatLocation(event.getBlock().getLocation())));
TFM_Util.formatLocation(event.getBlock().getLocation())));
p.getInventory().clear(p.getInventory().getHeldItemSlot());
}

View File

@ -38,17 +38,17 @@ public class TFM_Cmds_Admin implements CommandExecutor
if (sender instanceof Player)
{
sender_p = (Player) sender;
log.info(String.format("[PLAYER_COMMAND] %s(%s): /%s %s", sender_p.getName(), ChatColor.stripColor(sender_p.getDisplayName()), commandLabel, TotalFreedomMod.implodeStringList(" ", Arrays.asList(args))));
log.info(String.format("[PLAYER_COMMAND] %s(%s): /%s %s", sender_p.getName(), ChatColor.stripColor(sender_p.getDisplayName()), commandLabel, TFM_Util.implodeStringList(" ", Arrays.asList(args))));
}
else
{
senderIsConsole = true;
log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s", sender.getName(), commandLabel, TotalFreedomMod.implodeStringList(" ", Arrays.asList(args))));
log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s", sender.getName(), commandLabel, TFM_Util.implodeStringList(" ", Arrays.asList(args))));
}
if (cmd.getName().equalsIgnoreCase("fr"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (args.length == 0)
{
@ -58,13 +58,13 @@ public class TFM_Cmds_Admin implements CommandExecutor
{
plugin.allPlayersFrozen = true;
sender.sendMessage("Players are now frozen.");
TotalFreedomMod.tfm_broadcastMessage(sender.getName() + " has temporarily frozen everyone on the server.", ChatColor.AQUA);
TFM_Util.tfm_broadcastMessage(sender.getName() + " has temporarily frozen everyone on the server.", ChatColor.AQUA);
}
else
{
plugin.allPlayersFrozen = false;
sender.sendMessage("Players are now free to move.");
TotalFreedomMod.tfm_broadcastMessage(sender.getName() + " has unfrozen everyone.", ChatColor.AQUA);
TFM_Util.tfm_broadcastMessage(sender.getName() + " has unfrozen everyone.", ChatColor.AQUA);
}
}
else
@ -111,7 +111,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
return false;
}
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
Player p;
List<Player> matches = Bukkit.matchPlayer(args[0]);
@ -125,7 +125,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
p = matches.get(0);
}
TotalFreedomMod.tfm_broadcastMessage(p.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);
TFM_Util.tfm_broadcastMessage(p.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);
//Undo WorldEdits:
Bukkit.getServer().dispatchCommand(sender, String.format("/undo %d %s", 15, p.getName()));
@ -152,7 +152,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
//Ban IP Address:
String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
TotalFreedomMod.tfm_broadcastMessage(String.format("Banning: %s, IP: %s.", p.getName(), user_ip), ChatColor.RED);
TFM_Util.tfm_broadcastMessage(String.format("Banning: %s, IP: %s.", p.getName(), user_ip), ChatColor.RED);
Bukkit.banIP(user_ip);
//Ban Username:
@ -177,7 +177,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
String mode = args[0].toLowerCase();
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (mode.equals("list"))
{
@ -203,33 +203,33 @@ public class TFM_Cmds_Admin implements CommandExecutor
else if (mode.equals("nameban"))
{
Bukkit.getOfflinePlayer(p.getName()).setBanned(true);
TotalFreedomMod.tfm_broadcastMessage(String.format("Banning Name: %s.", p.getName()), ChatColor.RED);
TFM_Util.tfm_broadcastMessage(String.format("Banning Name: %s.", p.getName()), ChatColor.RED);
p.kickPlayer("Username banned by Administrator.");
}
else if (mode.equals("ipban"))
{
String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
TotalFreedomMod.tfm_broadcastMessage(String.format("Banning IP: %s.", p.getName(), user_ip), ChatColor.RED);
TFM_Util.tfm_broadcastMessage(String.format("Banning IP: %s.", p.getName(), user_ip), ChatColor.RED);
Bukkit.banIP(user_ip);
p.kickPlayer("IP address banned by Administrator.");
}
else if (mode.equals("ban"))
{
String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
TotalFreedomMod.tfm_broadcastMessage(String.format("Banning Name: %s, IP: %s.", p.getName(), user_ip), ChatColor.RED);
TFM_Util.tfm_broadcastMessage(String.format("Banning Name: %s, IP: %s.", p.getName(), user_ip), ChatColor.RED);
Bukkit.banIP(user_ip);
Bukkit.getOfflinePlayer(p.getName()).setBanned(true);
p.kickPlayer("IP and username banned by Administrator.");
}
else if (mode.equals("op"))
{
TotalFreedomMod.tfm_broadcastMessage(String.format("(%s: Opping %s)", sender.getName(), p.getName()), ChatColor.GRAY);
TFM_Util.tfm_broadcastMessage(String.format("(%s: Opping %s)", sender.getName(), p.getName()), ChatColor.GRAY);
p.setOp(false);
p.sendMessage(TotalFreedomMod.YOU_ARE_OP);
}
else if (mode.equals("deop"))
{
TotalFreedomMod.tfm_broadcastMessage(String.format("(%s: De-opping %s)", sender.getName(), p.getName()), ChatColor.GRAY);
TFM_Util.tfm_broadcastMessage(String.format("(%s: De-opping %s)", sender.getName(), p.getName()), ChatColor.GRAY);
p.setOp(false);
p.sendMessage(TotalFreedomMod.YOU_ARE_NOT_OP);
}
@ -272,7 +272,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("wildcard"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (args[0].equals("wildcard"))
{
@ -280,7 +280,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
return true;
}
String base_command = TotalFreedomMod.implodeStringList(" ", Arrays.asList(args));
String base_command = TFM_Util.implodeStringList(" ", Arrays.asList(args));
for (Player p : Bukkit.getOnlinePlayers())
{
@ -298,7 +298,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("nonuke"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (args.length < 1)
{
@ -343,7 +343,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("prelog"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (args.length != 1)
{
@ -374,7 +374,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("cake"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
StringBuilder output = new StringBuilder();
Random randomGenerator = new Random();
@ -391,7 +391,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
p.getInventory().setItem(p.getInventory().firstEmpty(), heldItem);
}
TotalFreedomMod.tfm_broadcastMessage(output.toString());
TFM_Util.tfm_broadcastMessage(output.toString());
}
else
{
@ -402,7 +402,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("gcmd"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (args.length < 2)
{
@ -462,7 +462,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("qjail"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (args.length < 1)
{
@ -504,7 +504,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
//Send to jail "mgjail":
Bukkit.getServer().dispatchCommand(sender, String.format("tjail %s mgjail", p.getName()));
TotalFreedomMod.tfm_broadcastMessage(p.getName() + " has been JAILED!", ChatColor.RED);
TFM_Util.tfm_broadcastMessage(p.getName() + " has been JAILED!", ChatColor.RED);
}
else
{
@ -515,7 +515,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("umd"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
for (Player p : Bukkit.getOnlinePlayers())
{
@ -556,7 +556,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
outmessage_bldr.append(args[i]).append(" ");
}
TotalFreedomMod.tfm_broadcastMessage(String.format("§7[CONSOLE]§f<§c%s§f> %s", sender_name, outmessage_bldr.toString().trim()));
TFM_Util.tfm_broadcastMessage(String.format("§7[CONSOLE]§f<§c%s§f> %s", sender_name, outmessage_bldr.toString().trim()));
}
else
{
@ -567,7 +567,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("cage"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (args.length == 0)
{
@ -630,13 +630,13 @@ public class TFM_Cmds_Admin implements CommandExecutor
playerdata.setCaged(true, target_pos, cage_material_outer, cage_material_inner);
playerdata.regenerateHistory();
playerdata.clearHistory();
TotalFreedomMod.buildHistory(target_pos, 2, playerdata);
TotalFreedomMod.generateCube(target_pos, 2, playerdata.getCageMaterial(0));
TotalFreedomMod.generateCube(target_pos, 1, playerdata.getCageMaterial(1));
TFM_Util.buildHistory(target_pos, 2, playerdata);
TFM_Util.generateCube(target_pos, 2, playerdata.getCageMaterial(0));
TFM_Util.generateCube(target_pos, 1, playerdata.getCageMaterial(1));
p.setGameMode(GameMode.SURVIVAL);
TotalFreedomMod.tfm_broadcastMessage(sender.getName() + " caged " + p.getName() + "!", ChatColor.YELLOW);
TFM_Util.tfm_broadcastMessage(sender.getName() + " caged " + p.getName() + "!", ChatColor.YELLOW);
}
else
{
@ -647,7 +647,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("orbit"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (args.length == 0)
{

View File

@ -29,17 +29,17 @@ public class TFM_Cmds_AntiBlock implements CommandExecutor
if (sender instanceof Player)
{
sender_p = (Player) sender;
log.info(String.format("[PLAYER_COMMAND] %s(%s): /%s %s", sender_p.getName(), ChatColor.stripColor(sender_p.getDisplayName()), commandLabel, TotalFreedomMod.implodeStringList(" ", Arrays.asList(args))));
log.info(String.format("[PLAYER_COMMAND] %s(%s): /%s %s", sender_p.getName(), ChatColor.stripColor(sender_p.getDisplayName()), commandLabel, TFM_Util.implodeStringList(" ", Arrays.asList(args))));
}
else
{
senderIsConsole = true;
log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s", sender.getName(), commandLabel, TotalFreedomMod.implodeStringList(" ", Arrays.asList(args))));
log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s", sender.getName(), commandLabel, TFM_Util.implodeStringList(" ", Arrays.asList(args))));
}
if (cmd.getName().equalsIgnoreCase("explosives"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (args.length == 0)
{
@ -71,7 +71,7 @@ public class TFM_Cmds_AntiBlock implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("firespread"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (args.length != 1)
{
@ -98,7 +98,7 @@ public class TFM_Cmds_AntiBlock implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("fireplace"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (args.length != 1)
{
@ -125,7 +125,7 @@ public class TFM_Cmds_AntiBlock implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("lavadmg"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (args.length != 1)
{
@ -152,7 +152,7 @@ public class TFM_Cmds_AntiBlock implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("lavaplace"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (args.length != 1)
{
@ -179,7 +179,7 @@ public class TFM_Cmds_AntiBlock implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("waterplace"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
if (args.length != 1)
{

View File

@ -38,12 +38,12 @@ public class TFM_Cmds_General implements CommandExecutor
if (sender instanceof Player)
{
sender_p = (Player) sender;
log.info(String.format("[PLAYER_COMMAND] %s(%s): /%s %s", sender_p.getName(), ChatColor.stripColor(sender_p.getDisplayName()), commandLabel, TotalFreedomMod.implodeStringList(" ", Arrays.asList(args))));
log.info(String.format("[PLAYER_COMMAND] %s(%s): /%s %s", sender_p.getName(), ChatColor.stripColor(sender_p.getDisplayName()), commandLabel, TFM_Util.implodeStringList(" ", Arrays.asList(args))));
}
else
{
senderIsConsole = true;
log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s", sender.getName(), commandLabel, TotalFreedomMod.implodeStringList(" ", Arrays.asList(args))));
log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s", sender.getName(), commandLabel, TFM_Util.implodeStringList(" ", Arrays.asList(args))));
}
if (cmd.getName().equalsIgnoreCase("creative"))
@ -194,7 +194,7 @@ public class TFM_Cmds_General implements CommandExecutor
if (senderIsConsole || sender.isOp())
{
sender.sendMessage(ChatColor.GRAY + "Removing all dropped items, arrows, exp. orbs and TNT...");
sender.sendMessage(ChatColor.GRAY + String.valueOf(plugin.wipeDropEntities()) + " dropped enties removed.");
sender.sendMessage(ChatColor.GRAY + String.valueOf(TFM_Util.wipeDropEntities(plugin)) + " dropped enties removed.");
}
else
{
@ -233,17 +233,17 @@ public class TFM_Cmds_General implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("flatlands"))
{
TotalFreedomMod.gotoWorld(sender, "flatlands");
TFM_Util.gotoWorld(sender, "flatlands");
return true;
}
else if (cmd.getName().equalsIgnoreCase("skylands"))
{
TotalFreedomMod.gotoWorld(sender, "skylands");
TFM_Util.gotoWorld(sender, "skylands");
return true;
}
else if (cmd.getName().equalsIgnoreCase("nether"))
{
TotalFreedomMod.gotoWorld(sender, "nether");
TFM_Util.gotoWorld(sender, "nether");
return true;
}
else if (cmd.getName().equalsIgnoreCase("banlist"))
@ -252,7 +252,7 @@ public class TFM_Cmds_General implements CommandExecutor
{
if (args[0].equalsIgnoreCase("purge"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
for (OfflinePlayer p : Bukkit.getBannedPlayers())
{
@ -293,7 +293,7 @@ public class TFM_Cmds_General implements CommandExecutor
{
if (args[0].equalsIgnoreCase("purge"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
for (String ip : Bukkit.getIPBans())
{

View File

@ -31,12 +31,12 @@ public class TFM_Cmds_OP implements CommandExecutor
if (sender instanceof Player)
{
sender_p = (Player) sender;
log.info(String.format("[PLAYER_COMMAND] %s(%s): /%s %s", sender_p.getName(), ChatColor.stripColor(sender_p.getDisplayName()), commandLabel, TotalFreedomMod.implodeStringList(" ", Arrays.asList(args))));
log.info(String.format("[PLAYER_COMMAND] %s(%s): /%s %s", sender_p.getName(), ChatColor.stripColor(sender_p.getDisplayName()), commandLabel, TFM_Util.implodeStringList(" ", Arrays.asList(args))));
}
else
{
senderIsConsole = true;
log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s", sender.getName(), commandLabel, TotalFreedomMod.implodeStringList(" ", Arrays.asList(args))));
log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s", sender.getName(), commandLabel, TFM_Util.implodeStringList(" ", Arrays.asList(args))));
}
if (cmd.getName().equalsIgnoreCase("opme"))
@ -47,9 +47,9 @@ public class TFM_Cmds_OP implements CommandExecutor
}
else
{
if (plugin.isUserSuperadmin(sender))
if (TFM_Util.isUserSuperadmin(sender, plugin))
{
TotalFreedomMod.tfm_broadcastMessage(String.format("(%s: Opping %s)", sender.getName(), sender.getName()), ChatColor.GRAY);
TFM_Util.tfm_broadcastMessage(String.format("(%s: Opping %s)", sender.getName(), sender.getName()), ChatColor.GRAY);
sender.setOp(true);
sender.sendMessage(TotalFreedomMod.YOU_ARE_OP);
}
@ -63,9 +63,9 @@ public class TFM_Cmds_OP implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("opall"))
{
if (plugin.isUserSuperadmin(sender) || senderIsConsole)
if (TFM_Util.isUserSuperadmin(sender, plugin) || senderIsConsole)
{
TotalFreedomMod.tfm_broadcastMessage(String.format("(%s: Opping everyone)", sender.getName()), ChatColor.GRAY);
TFM_Util.tfm_broadcastMessage(String.format("(%s: Opping everyone)", sender.getName()), ChatColor.GRAY);
boolean doSetGamemode = false;
GameMode targetGamemode = GameMode.CREATIVE;
@ -103,17 +103,14 @@ public class TFM_Cmds_OP implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("deopall"))
{
if (plugin.isUserSuperadmin(sender) || senderIsConsole)
if (TFM_Util.isUserSuperadmin(sender, plugin) || senderIsConsole)
{
TotalFreedomMod.tfm_broadcastMessage(String.format("(%s: De-opping everyone)", sender.getName()), ChatColor.GRAY);
TFM_Util.tfm_broadcastMessage(String.format("(%s: De-opping everyone)", sender.getName()), ChatColor.GRAY);
for (Player p : Bukkit.getOnlinePlayers())
{
if (!plugin.isUserSuperadmin(p) && !p.getName().equals(sender.getName()))
{
p.setOp(false);
p.sendMessage(TotalFreedomMod.YOU_ARE_NOT_OP);
}
p.setOp(false);
p.sendMessage(TotalFreedomMod.YOU_ARE_NOT_OP);
}
}
else
@ -130,14 +127,14 @@ public class TFM_Cmds_OP implements CommandExecutor
return false;
}
if (sender.isOp() || senderIsConsole || plugin.isUserSuperadmin(sender))
if (sender.isOp() || senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
boolean matched_player = false;
for (Player p : Bukkit.matchPlayer(args[0]))
{
matched_player = true;
TotalFreedomMod.tfm_broadcastMessage(String.format("(%s: Opping %s)", sender.getName(), p.getName()), ChatColor.GRAY);
TFM_Util.tfm_broadcastMessage(String.format("(%s: Opping %s)", sender.getName(), p.getName()), ChatColor.GRAY);
p.setOp(true);
p.sendMessage(TotalFreedomMod.YOU_ARE_OP);
}
@ -160,14 +157,14 @@ public class TFM_Cmds_OP implements CommandExecutor
return false;
}
if (sender.isOp() || senderIsConsole || plugin.isUserSuperadmin(sender))
if (sender.isOp() || senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
boolean matched_player = false;
for (Player p : Bukkit.matchPlayer(args[0]))
{
matched_player = true;
TotalFreedomMod.tfm_broadcastMessage(String.format("(%s: De-opping %s)", sender.getName(), p.getName()), ChatColor.GRAY);
TFM_Util.tfm_broadcastMessage(String.format("(%s: De-opping %s)", sender.getName(), p.getName()), ChatColor.GRAY);
p.setOp(false);
p.sendMessage(TotalFreedomMod.YOU_ARE_NOT_OP);
}

View File

@ -30,12 +30,12 @@ public class TFM_Cmds_Override implements CommandExecutor
if (sender instanceof Player)
{
sender_p = (Player) sender;
log.info(String.format("[PLAYER_COMMAND] %s(%s): /%s %s", sender_p.getName(), ChatColor.stripColor(sender_p.getDisplayName()), commandLabel, TotalFreedomMod.implodeStringList(" ", Arrays.asList(args))));
log.info(String.format("[PLAYER_COMMAND] %s(%s): /%s %s", sender_p.getName(), ChatColor.stripColor(sender_p.getDisplayName()), commandLabel, TFM_Util.implodeStringList(" ", Arrays.asList(args))));
}
else
{
senderIsConsole = true;
log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s", sender.getName(), commandLabel, TotalFreedomMod.implodeStringList(" ", Arrays.asList(args))));
log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s", sender.getName(), commandLabel, TFM_Util.implodeStringList(" ", Arrays.asList(args))));
}
if (cmd.getName().equalsIgnoreCase("say"))
@ -47,8 +47,8 @@ public class TFM_Cmds_Override implements CommandExecutor
if (senderIsConsole || sender.isOp())
{
String message = TotalFreedomMod.implodeStringList(" ", Arrays.asList(args));
TotalFreedomMod.tfm_broadcastMessage(String.format("[Server:%s] %s", sender.getName(), message), ChatColor.LIGHT_PURPLE);
String message = TFM_Util.implodeStringList(" ", Arrays.asList(args));
TFM_Util.tfm_broadcastMessage(String.format("[Server:%s] %s", sender.getName(), message), ChatColor.LIGHT_PURPLE);
}
else
{
@ -59,9 +59,9 @@ public class TFM_Cmds_Override implements CommandExecutor
}
else if (cmd.getName().equalsIgnoreCase("stop"))
{
if (senderIsConsole || plugin.isUserSuperadmin(sender))
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
TotalFreedomMod.tfm_broadcastMessage("Server is going offline.", ChatColor.GRAY);
TFM_Util.tfm_broadcastMessage("Server is going offline.", ChatColor.GRAY);
for (Player p : Bukkit.getOnlinePlayers())
{

View File

@ -1,11 +1,7 @@
package me.StevenLawson.TotalFreedomMod;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.entity.ExplosionPrimeEvent;
public class TFM_EntityListener extends EntityListener
{

View File

@ -6,11 +6,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
class TFM_PlayerListener extends PlayerListener
@ -66,7 +62,7 @@ class TFM_PlayerListener extends PlayerListener
boolean do_freeze = false;
if (plugin.allPlayersFrozen)
{
if (!plugin.isUserSuperadmin(p))
if (!TFM_Util.isUserSuperadmin(p, plugin))
{
do_freeze = true;
}
@ -105,9 +101,9 @@ class TFM_PlayerListener extends PlayerListener
playerdata.setCaged(true, target_pos, playerdata.getCageMaterial(0), playerdata.getCageMaterial(1));
playerdata.regenerateHistory();
playerdata.clearHistory();
TotalFreedomMod.buildHistory(target_pos, 2, playerdata);
TotalFreedomMod.generateCube(target_pos, 2, playerdata.getCageMaterial(0));
TotalFreedomMod.generateCube(target_pos, 1, playerdata.getCageMaterial(1));
TFM_Util.buildHistory(target_pos, 2, playerdata);
TFM_Util.generateCube(target_pos, 2, playerdata.getCageMaterial(0));
TFM_Util.generateCube(target_pos, 1, playerdata.getCageMaterial(1));
}
}
}
@ -127,7 +123,7 @@ class TFM_PlayerListener extends PlayerListener
{
p.setOp(false);
p.kickPlayer("No Spamming");
TotalFreedomMod.tfm_broadcastMessage(p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
TFM_Util.tfm_broadcastMessage(p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
event.setCancelled(true);
return;
@ -158,14 +154,14 @@ class TFM_PlayerListener extends PlayerListener
if (command.matches("^/stop"))
{
if (!plugin.isUserSuperadmin(player))
if (!TFM_Util.isUserSuperadmin(player, plugin))
{
block_command = true;
}
}
else if (command.matches("^/reload"))
{
if (!plugin.isUserSuperadmin(player))
if (!TFM_Util.isUserSuperadmin(player, plugin))
{
block_command = true;
}

View File

@ -0,0 +1,269 @@
package me.StevenLawson.TotalFreedomMod;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.*;
public class TFM_Util
{
private static final Logger log = Logger.getLogger("Minecraft");
public TFM_Util()
{
}
public static void tfm_broadcastMessage(String message, ChatColor color)
{
log.info(message);
for (Player p : Bukkit.getOnlinePlayers())
{
p.sendMessage(color + message);
}
}
public static void tfm_broadcastMessage(String message)
{
log.info(ChatColor.stripColor(message));
for (Player p : Bukkit.getOnlinePlayers())
{
p.sendMessage(message);
}
}
public static String implodeStringList(String glue, List<String> pieces)
{
StringBuilder output = new StringBuilder();
for (int i = 0; i < pieces.size(); i++)
{
if (i != 0)
{
output.append(glue);
}
output.append(pieces.get(i));
}
return output.toString();
}
public static String formatLocation(Location in_loc)
{
return String.format("%s: (%d, %d, %d)",
in_loc.getWorld().getName(),
Math.round(in_loc.getX()),
Math.round(in_loc.getY()),
Math.round(in_loc.getZ()));
}
public static void gotoWorld(CommandSender sender, String targetworld)
{
if (sender instanceof Player)
{
Player sender_p = (Player) sender;
if (sender_p.getWorld().getName().equalsIgnoreCase(targetworld))
{
sender.sendMessage(ChatColor.GRAY + "Going to main world.");
Bukkit.getServer().dispatchCommand(sender, "world 0");
return;
}
for (World world : Bukkit.getWorlds())
{
if (world.getName().equalsIgnoreCase(targetworld))
{
sender.sendMessage(ChatColor.GRAY + "Going to world: " + targetworld);
Bukkit.getServer().dispatchCommand(sender, "mv tp " + targetworld);
return;
}
}
}
else
{
sender.sendMessage("This command may not be used from the console.");
}
}
public static void buildHistory(Location location, int length, TFM_UserInfo playerdata)
{
Block center_block = location.getBlock();
for (int x_offset = -length; x_offset <= length; x_offset++)
{
for (int y_offset = -length; y_offset <= length; y_offset++)
{
for (int z_offset = -length; z_offset <= length; z_offset++)
{
Block block = center_block.getRelative(x_offset, y_offset, z_offset);
playerdata.insertHistoryBlock(block.getLocation(), block.getType());
}
}
}
}
public static void generateCube(Location location, int length, Material material)
{
Block center_block = location.getBlock();
for (int x_offset = -length; x_offset <= length; x_offset++)
{
for (int y_offset = -length; y_offset <= length; y_offset++)
{
for (int z_offset = -length; z_offset <= length; z_offset++)
{
center_block.getRelative(x_offset, y_offset, z_offset).setType(material);
}
}
}
}
public static void setWorldTime(World world, long ticks)
{
long time = world.getTime();
time -= time % 24000;
world.setTime(time + 24000 + ticks);
}
public static void createDefaultConfiguration(String name, TotalFreedomMod tfm, File plugin_file)
{
File actual = new File(tfm.getDataFolder(), name);
if (!actual.exists())
{
log.info("[" + tfm.getDescription().getName() + "]: Installing default configuration file template: " + actual.getPath());
InputStream input = null;
try
{
JarFile file = new JarFile(plugin_file);
ZipEntry copy = file.getEntry(name);
if (copy == null)
{
log.severe("[" + tfm.getDescription().getName() + "]: Unable to read default configuration: " + actual.getPath());
return;
}
input = file.getInputStream(copy);
}
catch (IOException ioex)
{
log.severe("[" + tfm.getDescription().getName() + "]: Unable to read default configuration: " + actual.getPath());
}
if (input != null)
{
FileOutputStream output = null;
try
{
tfm.getDataFolder().mkdirs();
output = new FileOutputStream(actual);
byte[] buf = new byte[8192];
int length = 0;
while ((length = input.read(buf)) > 0)
{
output.write(buf, 0, length);
}
log.info("[" + tfm.getDescription().getName() + "]: Default configuration file written: " + actual.getPath());
}
catch (IOException ioex)
{
log.log(Level.SEVERE, "[" + tfm.getDescription().getName() + "]: Unable to write default configuration: " + actual.getPath(), ioex);
}
finally
{
try
{
if (input != null)
{
input.close();
}
}
catch (IOException ioex)
{
}
try
{
if (output != null)
{
output.close();
}
}
catch (IOException ioex)
{
}
}
}
}
}
public static boolean isUserSuperadmin(CommandSender user, TotalFreedomMod tfm)
{
try
{
if (!(user instanceof Player))
{
return true;
}
if (Bukkit.getOnlineMode())
{
if (tfm.superadmins.contains(user.getName()))
{
return true;
}
}
Player p = (Player) user;
if (p != null)
{
InetSocketAddress ip_address_obj = p.getAddress();
if (ip_address_obj != null)
{
String user_ip = ip_address_obj.getAddress().toString().replaceAll("/", "").trim();
if (user_ip != null && !user_ip.isEmpty())
{
if (tfm.superadmin_ips.contains(user_ip))
{
return true;
}
}
}
}
}
catch (Exception ex)
{
log.severe("Exception in TFM_Util.isUserSuperadmin: " + ex.getMessage());
}
return false;
}
public static int wipeDropEntities(TotalFreedomMod tfm)
{
int removed = 0;
for (World world : Bukkit.getWorlds())
{
for (Entity ent : world.getEntities())
{
if (ent instanceof Arrow || (ent instanceof TNTPrimed && !tfm.allowExplosions) || ent instanceof Item || ent instanceof ExperienceOrb)
{
ent.remove();
removed++;
}
}
}
return removed;
}
}

View File

@ -1,28 +1,18 @@
package me.StevenLawson.TotalFreedomMod;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.*;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@ -90,7 +80,7 @@ public class TotalFreedomMod extends JavaPlugin
if (plugin.autoEntityWipe)
{
plugin.wipeDropEntities();
TFM_Util.wipeDropEntities(plugin);
}
if (plugin.disableNight)
@ -99,181 +89,12 @@ public class TotalFreedomMod extends JavaPlugin
{
if (world.getTime() > 12000L)
{
TotalFreedomMod.setWorldTime(world, 1000L);
TFM_Util.setWorldTime(world, 1000L);
}
}
}
}
}
public boolean isUserSuperadmin(CommandSender user)
{
try
{
if (!(user instanceof Player))
{
return true;
}
if (Bukkit.getOnlineMode())
{
if (superadmins.contains(user.getName()))
{
return true;
}
}
Player p = (Player) user;
if (p != null)
{
InetSocketAddress ip_address_obj = p.getAddress();
if (ip_address_obj != null)
{
String user_ip = ip_address_obj.getAddress().toString().replaceAll("/", "").trim();
if (user_ip != null && !user_ip.isEmpty())
{
if (superadmin_ips.contains(user_ip))
{
return true;
}
}
}
}
}
catch (Exception ex)
{
log.severe("Exception in TotalFreedomMod.isUserSuperadmin: " + ex.getMessage());
}
return false;
}
public int wipeDropEntities()
{
int removed = 0;
for (World world : Bukkit.getWorlds())
{
for (Entity ent : world.getEntities())
{
if (ent instanceof Arrow || (ent instanceof TNTPrimed && !this.allowExplosions) || ent instanceof Item || ent instanceof ExperienceOrb)
{
ent.remove();
removed++;
}
}
}
return removed;
}
public static void tfm_broadcastMessage(String message, ChatColor color)
{
log.info(message);
for (Player p : Bukkit.getOnlinePlayers())
{
p.sendMessage(color + message);
}
}
public static void tfm_broadcastMessage(String message)
{
log.info(ChatColor.stripColor(message));
for (Player p : Bukkit.getOnlinePlayers())
{
p.sendMessage(message);
}
}
public static String implodeStringList(String glue, List<String> pieces)
{
StringBuilder output = new StringBuilder();
for (int i = 0; i < pieces.size(); i++)
{
if (i != 0)
{
output.append(glue);
}
output.append(pieces.get(i));
}
return output.toString();
}
public static String formatLocation(Location in_loc)
{
return String.format("%s: (%d, %d, %d)",
in_loc.getWorld().getName(),
Math.round(in_loc.getX()),
Math.round(in_loc.getY()),
Math.round(in_loc.getZ()));
}
public static void gotoWorld(CommandSender sender, String targetworld)
{
if (sender instanceof Player)
{
Player sender_p = (Player) sender;
if (sender_p.getWorld().getName().equalsIgnoreCase(targetworld))
{
sender.sendMessage(ChatColor.GRAY + "Going to main world.");
Bukkit.getServer().dispatchCommand(sender, "world 0");
return;
}
for (World world : Bukkit.getWorlds())
{
if (world.getName().equalsIgnoreCase(targetworld))
{
sender.sendMessage(ChatColor.GRAY + "Going to world: " + targetworld);
Bukkit.getServer().dispatchCommand(sender, "mv tp " + targetworld);
return;
}
}
}
else
{
sender.sendMessage("This command may not be used from the console.");
}
}
public static void buildHistory(Location location, int length, TFM_UserInfo playerdata)
{
Block center_block = location.getBlock();
for (int x_offset = -length; x_offset <= length; x_offset++)
{
for (int y_offset = -length; y_offset <= length; y_offset++)
{
for (int z_offset = -length; z_offset <= length; z_offset++)
{
Block block = center_block.getRelative(x_offset, y_offset, z_offset);
playerdata.insertHistoryBlock(block.getLocation(), block.getType());
}
}
}
}
public static void generateCube(Location location, int length, Material material)
{
Block center_block = location.getBlock();
for (int x_offset = -length; x_offset <= length; x_offset++)
{
for (int y_offset = -length; y_offset <= length; y_offset++)
{
for (int z_offset = -length; z_offset <= length; z_offset++)
{
center_block.getRelative(x_offset, y_offset, z_offset).setType(material);
}
}
}
}
public static void setWorldTime(World world, long ticks)
{
long time = world.getTime();
time -= time % 24000;
world.setTime(time + 24000 + ticks);
}
public boolean allowFirePlace = false;
public Boolean allowFireSpread = false;
@ -294,7 +115,7 @@ public class TotalFreedomMod extends JavaPlugin
private void loadTFMConfig()
{
createDefaultConfiguration(CONFIG_FILE);
TFM_Util.createDefaultConfiguration(CONFIG_FILE, this, getFile());
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), CONFIG_FILE));
@ -328,78 +149,7 @@ public class TotalFreedomMod extends JavaPlugin
superadmin_ips.add("127.0.0.1");
}
}
private void createDefaultConfiguration(String name)
{
File actual = new File(getDataFolder(), name);
if (!actual.exists())
{
log.info("[" + getDescription().getName() + "]: Installing default configuration file template: " + actual.getPath());
InputStream input = null;
try
{
JarFile file = new JarFile(getFile());
ZipEntry copy = file.getEntry(name);
if (copy == null)
{
log.severe("[" + getDescription().getName() + "]: Unable to read default configuration: " + actual.getPath());
return;
}
input = file.getInputStream(copy);
}
catch (IOException ioex)
{
log.severe("[" + getDescription().getName() + "]: Unable to read default configuration: " + actual.getPath());
}
if (input != null)
{
FileOutputStream output = null;
try
{
getDataFolder().mkdirs();
output = new FileOutputStream(actual);
byte[] buf = new byte[8192];
int length = 0;
while ((length = input.read(buf)) > 0)
{
output.write(buf, 0, length);
}
log.info("[" + getDescription().getName() + "]: Default configuration file written: " + actual.getPath());
}
catch (IOException ioex)
{
log.log(Level.SEVERE, "[" + getDescription().getName() + "]: Unable to write default configuration: " + actual.getPath(), ioex);
}
finally
{
try
{
if (input != null)
{
input.close();
}
}
catch (IOException ioex)
{
}
try
{
if (output != null)
{
output.close();
}
}
catch (IOException ioex)
{
}
}
}
}
}
private void registerEventHandlers()
{
PluginManager pm = this.getServer().getPluginManager();