Use Allman style, please!

Code cleanup.
Switched to StringUtils.join, we are re-inventing the wheel :D
Added whitelist support to TFM_PlayerListener auth code.
@Deprecated some utility methods, will remove shortly.
This commit is contained in:
Steven Lawson 2012-09-17 19:46:59 -04:00
parent c9c1b7519d
commit 3feec18131
8 changed files with 311 additions and 329 deletions

View File

@ -2,11 +2,8 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -15,22 +12,18 @@ import org.bukkit.entity.Player;
public class Command_doom extends TFM_Command public class Command_doom extends TFM_Command
{ {
public String[] p = public final static List<String> ALLOWED_USERS = Arrays.asList(
{
"madgeek", "madgeek",
"darth", "darth",
"madgeek1450", "madgeek1450",
"mark", "mark",
"markbyron", "markbyron",
"darthsalamon" "darthsalamon");
};
public List<String> players = Arrays.asList(p);
@Override @Override
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if(!(senderIsConsole && players.contains(sender.getName().toLowerCase()))) if (!(senderIsConsole && ALLOWED_USERS.contains(sender.getName().toLowerCase())))
{ {
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;
@ -52,7 +45,6 @@ public class Command_doom extends TFM_Command
return true; return true;
} }
TFM_Util.adminAction(sender.getName(), "Casting oblivion over " + p.getName(), true); TFM_Util.adminAction(sender.getName(), "Casting oblivion over " + p.getName(), true);
TFM_Util.bcastMsg(p.getName() + " will be completely obliviated!", ChatColor.RED); TFM_Util.bcastMsg(p.getName() + " will be completely obliviated!", ChatColor.RED);
@ -71,10 +63,10 @@ public class Command_doom extends TFM_Command
p.setOp(false); p.setOp(false);
// ban IP // ban IP
Bukkit.banIP(IP); TFM_Util.banIP(IP, null, null, null);
// ban name // ban name
p.setBanned(true); TFM_Util.banUsername(p.getName(), null, null, null);
// set gamemode to survival // set gamemode to survival
p.setGameMode(GameMode.SURVIVAL); p.setGameMode(GameMode.SURVIVAL);
@ -92,20 +84,21 @@ public class Command_doom extends TFM_Command
server.getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() server.getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable()
{ {
@Override @Override
public void run() { public void run()
{
// strike lightning // strike lightning
p.getWorld().strikeLightning(p.getLocation()); p.getWorld().strikeLightning(p.getLocation());
// kill (if not done already) // kill (if not done already)
p.setHealth(0); p.setHealth(0);
} }
}, 40L); // 2 seconds }, 40L); // 2 seconds
server.getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() server.getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable()
{ {
@Override @Override
public void run() { public void run()
{
// message // message
TFM_Util.adminAction(sender.getName(), "Banning " + p.getName() + ", IP: " + IP, true); TFM_Util.adminAction(sender.getName(), "Banning " + p.getName() + ", IP: " + IP, true);
@ -115,7 +108,6 @@ public class Command_doom extends TFM_Command
// kick player // kick player
p.kickPlayer(ChatColor.RED + "FUCKOFF, and get your shit together!"); p.kickPlayer(ChatColor.RED + "FUCKOFF, and get your shit together!");
} }
}, 60L); // 3 seconds }, 60L); // 3 seconds
return true; return true;

View File

@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -26,10 +27,7 @@ public class Command_ops extends TFM_Command
if (args[0].equalsIgnoreCase("list")) if (args[0].equalsIgnoreCase("list"))
{ {
String ops = TFM_Util.arrayToString(server.getOperators()); TFM_Util.playerMsg(sender, "Operators: " + StringUtils.join(server.getOperators(), ", "));
TFM_Util.playerMsg(sender, "Operators:");
TFM_Util.playerMsg(sender, ops);
return true; return true;
} }

View File

@ -17,7 +17,9 @@ public class Command_rd extends TFM_Command
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;
} }
TFM_Util.adminAction(sender.getName(), "Removing all server entities", false);
//This terminology is wrong, this doesn't remove *all* entities, by far. - Madgeek
TFM_Util.adminAction(sender.getName(), "Removing all server entities.", false);
sender.sendMessage(ChatColor.GRAY + String.valueOf(TFM_Util.wipeEntities(true, true)) + " enties removed."); sender.sendMessage(ChatColor.GRAY + String.valueOf(TFM_Util.wipeEntities(true, true)) + " enties removed.");
return true; return true;

View File

@ -81,7 +81,7 @@ public class Command_stfu extends TFM_Command
} }
TFM_Util.playerMsg(sender, "Muted " + counter + " players."); TFM_Util.playerMsg(sender, "Muted " + counter + " players.");
return true;
} }
Player p; Player p;
@ -101,7 +101,6 @@ public class Command_stfu extends TFM_Command
TFM_Util.adminAction(sender.getName(), "Unmuting " + p.getName(), true); TFM_Util.adminAction(sender.getName(), "Unmuting " + p.getName(), true);
playerdata.setMuted(false); playerdata.setMuted(false);
TFM_Util.playerMsg(sender, "Unmuted " + p.getName()); TFM_Util.playerMsg(sender, "Unmuted " + p.getName());
return true;
} }
else else
{ {

View File

@ -1,8 +1,10 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.Set;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.server.MinecraftServer;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -28,10 +30,7 @@ public class Command_whitelist extends TFM_Command
// list // list
if (args[0].equalsIgnoreCase("list")) if (args[0].equalsIgnoreCase("list"))
{ {
String players = TFM_Util.arrayToString(server.getWhitelistedPlayers()); TFM_Util.playerMsg(sender, "Whitelisted players: " + StringUtils.join(server.getWhitelistedPlayers(), ", "));
TFM_Util.playerMsg(sender, "Whitelisted players:");
TFM_Util.playerMsg(sender, players);
return true; return true;
} }
@ -111,6 +110,7 @@ public class Command_whitelist extends TFM_Command
p = server.getOfflinePlayer(args[0]); p = server.getOfflinePlayer(args[0]);
} }
} }
TFM_Util.adminAction(sender.getName(), "Adding " + p.getName() + " to the whitelist", false); TFM_Util.adminAction(sender.getName(), "Adding " + p.getName() + " to the whitelist", false);
p.setWhitelisted(true); p.setWhitelisted(true);
return true; return true;
@ -176,14 +176,10 @@ public class Command_whitelist extends TFM_Command
//purge //purge
if (args[0].equalsIgnoreCase("purge")) if (args[0].equalsIgnoreCase("purge"))
{ {
Set whitelisted = MinecraftServer.getServer().getServerConfigurationManager().getWhitelisted();
TFM_Util.adminAction(sender.getName(), "Removing all players from the whitelist", true); TFM_Util.adminAction(sender.getName(), "Removing all players from the whitelist", true);
int counter = 0; TFM_Util.playerMsg(sender, "Removed " + whitelisted.size() + " players from the whitelist.");
for(OfflinePlayer p : server.getWhitelistedPlayers()) whitelisted.clear();
{
p.setWhitelisted(false);
counter++;
}
TFM_Util.playerMsg(sender, "Removed " + counter + " players from the whitelist");
return true; return true;
} }

View File

@ -231,24 +231,6 @@ public class TFM_PlayerListener implements Listener
p.setVelocity(new Vector(0, playerdata.orbitStrength(), 0)); p.setVelocity(new Vector(0, playerdata.orbitStrength(), 0));
} }
} }
/*
if (p.getItemInHand().getType() == Material.SPECKLED_MELON)
{
if (TFM_Util.isUserSuperadmin(p))
{
Location from_pos = event.getFrom().clone();
Location to_pos = event.getTo().clone();
Block block_pos = user_pos.clone().add(user_pos.getDirection().multiply(-2.0)).getBlock();
if ((block_pos.isEmpty() || block_pos.isLiquid()))
{
block_pos.setTypeIdAndData(Material.WOOL.getId(), DyeColor.values()[randomGenerator.nextInt(DyeColor.values().length)].getData(), false);
}
}
}
*/
if (TotalFreedomMod.landminesEnabled && TotalFreedomMod.allowExplosions) if (TotalFreedomMod.landminesEnabled && TotalFreedomMod.allowExplosions)
{ {
Iterator<TFM_LandmineData> landmines = TFM_LandmineData.landmines.iterator(); Iterator<TFM_LandmineData> landmines = TFM_LandmineData.landmines.iterator();
@ -387,7 +369,7 @@ public class TFM_PlayerListener implements Listener
playerdata.resetMsgCount(); playerdata.resetMsgCount();
TFM_Util.wipeEntities(true); TFM_Util.wipeEntities(true, true);
event.setCancelled(true); event.setCancelled(true);
return; return;
@ -721,6 +703,15 @@ public class TFM_PlayerListener implements Listener
return; return;
} }
if (scm.hasWhitelist)
{
if (!scm.getWhitelisted().contains(player_name))
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server.");
return;
}
}
for (Player test_player : server.getOnlinePlayers()) for (Player test_player : server.getOnlinePlayers())
{ {
if (test_player.getName().equalsIgnoreCase(player_name)) if (test_player.getName().equalsIgnoreCase(player_name))

View File

@ -28,7 +28,7 @@ public class TFM_Heartbeat implements Runnable
if (TotalFreedomMod.autoEntityWipe) if (TotalFreedomMod.autoEntityWipe)
{ {
TFM_Util.wipeEntities(!TotalFreedomMod.allowExplosions); TFM_Util.wipeEntities(!TotalFreedomMod.allowExplosions, false);
} }
if (TotalFreedomMod.disableNight) if (TotalFreedomMod.disableNight)

View File

@ -13,6 +13,7 @@ import java.util.zip.ZipOutputStream;
import net.minecraft.server.BanEntry; import net.minecraft.server.BanEntry;
import net.minecraft.server.BanList; import net.minecraft.server.BanList;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -106,16 +107,17 @@ public class TFM_Util
public static String implodeStringList(String glue, List<String> pieces) public static String implodeStringList(String glue, List<String> pieces)
{ {
StringBuilder output = new StringBuilder(); // StringBuilder output = new StringBuilder();
for (int i = 0; i < pieces.size(); i++) // for (int i = 0; i < pieces.size(); i++)
{ // {
if (i != 0) // if (i != 0)
{ // {
output.append(glue); // output.append(glue);
} // }
output.append(pieces.get(i)); // output.append(pieces.get(i));
} // }
return output.toString(); // return output.toString();
return StringUtils.join(pieces, glue);
} }
public static String formatLocation(Location in_loc) public static String formatLocation(Location in_loc)
@ -396,6 +398,7 @@ public class TFM_Util
} }
} }
@Deprecated
public static int wipeEntities(boolean wipe_explosives) public static int wipeEntities(boolean wipe_explosives)
{ {
return wipeEntities(wipe_explosives, false); return wipeEntities(wipe_explosives, false);
@ -926,6 +929,7 @@ public class TFM_Util
return c.getTime(); return c.getTime();
} }
@Deprecated
public static String arrayToString(Set<OfflinePlayer> set) public static String arrayToString(Set<OfflinePlayer> set)
{ {
String players = ""; String players = "";