Fixed nonstandard formatting in recent commits.

Cleaned up the halt and permban commands.
Nobody cares about the "count" when you first load the plugin. Lets not include that.
This commit is contained in:
Steven Lawson 2012-09-18 17:25:37 -04:00
parent 322f233ce0
commit 30c65d49ed
10 changed files with 233 additions and 245 deletions

View File

@ -26,7 +26,7 @@ public class Command_glist extends TFM_Command
{ {
if (args[0].equalsIgnoreCase("purge")) if (args[0].equalsIgnoreCase("purge"))
{ {
TFM_Util.adminAction(sender.getName(), "Purging the banlist", true); //Purge does not clear the banlist! This is not for clearing bans! This is for clearing the yaml file that stores the player/IP database!
TFM_UserList.getInstance(plugin).purge(); TFM_UserList.getInstance(plugin).purge();
return true; return true;
} }

View File

@ -3,7 +3,6 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
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.GameMode; import org.bukkit.GameMode;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -11,55 +10,54 @@ import org.bukkit.entity.Player;
public class Command_halt extends TFM_Command public class Command_halt extends TFM_Command
{ {
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if(!(TFM_Util.isUserSuperadmin(sender) || senderIsConsole)) if (!(TFM_Util.isUserSuperadmin(sender) || senderIsConsole))
{ {
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;
} }
if(args.length != 1) if (args.length != 1)
{ {
return false; return false;
} }
if(args[0].equalsIgnoreCase("all")) if (args[0].equalsIgnoreCase("all"))
{ {
TFM_Util.adminAction(sender.getName(), "Halting all non-Superadmins", true); TFM_Util.adminAction(sender.getName(), "Halting all non-superadmins.", true);
int counter = 0; int counter = 0;
for(Player p : server.getOnlinePlayers()) for (Player p : server.getOnlinePlayers())
{ {
if(!TFM_Util.isUserSuperadmin(p)) if (!TFM_Util.isUserSuperadmin(p))
{ {
halt(p, sender); setHalted(p, true);
counter++; counter++;
} }
} }
TFM_Util.playerMsg(sender, "Halted " + counter + " players."); TFM_Util.playerMsg(sender, "Halted " + counter + " players.");
return true; return true;
} }
if(args[0].equalsIgnoreCase("purge")) if (args[0].equalsIgnoreCase("purge"))
{ {
TFM_Util.adminAction(sender.getName(), "Unhalting all players", true); TFM_Util.adminAction(sender.getName(), "Unhalting all players.", true);
int counter = 0; int counter = 0;
for(Player p : server.getOnlinePlayers()) for (Player p : server.getOnlinePlayers())
{ {
if(TFM_UserInfo.getPlayerData(p).isHalted()) if (TFM_UserInfo.getPlayerData(p).isHalted())
{ {
unhalt(p, sender); setHalted(p, false);
counter++; counter++;
} }
} }
TFM_Util.playerMsg(sender, "Unhalted " + counter + " players."); TFM_Util.playerMsg(sender, "Unhalted " + counter + " players.");
return true; return true;
} }
if(args[0].equalsIgnoreCase("list")) if (args[0].equalsIgnoreCase("list"))
{ {
TFM_Util.playerMsg(sender, "Halted players:");
TFM_UserInfo info; TFM_UserInfo info;
int count = 0; int count = 0;
for (Player hp : server.getOnlinePlayers()) for (Player hp : server.getOnlinePlayers())
@ -67,72 +65,75 @@ public class Command_halt extends TFM_Command
info = TFM_UserInfo.getPlayerData(hp); info = TFM_UserInfo.getPlayerData(hp);
if (info.isHalted()) if (info.isHalted())
{ {
if (count == 0)
{
TFM_Util.playerMsg(sender, "Halted players:");
}
TFM_Util.playerMsg(sender, "- " + hp.getName()); TFM_Util.playerMsg(sender, "- " + hp.getName());
count++; count++;
} }
} }
if (count == 0) if (count == 0)
{ {
TFM_Util.playerMsg(sender, "- none"); TFM_Util.playerMsg(sender, "There are currently no halted players.");
} }
return true; return true;
} }
Player p; Player p;
try try
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch(CantFindPlayerException ex) catch (CantFindPlayerException ex)
{ {
sender.sendMessage(ex.getMessage()); sender.sendMessage(ex.getMessage());
return true; return true;
} }
if(!TFM_UserInfo.getPlayerData(p).isHalted()) if (!TFM_UserInfo.getPlayerData(p).isHalted())
{ {
TFM_Util.adminAction(sender.getName(), "Halting " + p.getName(), true); TFM_Util.adminAction(sender.getName(), "Halting " + p.getName(), true);
halt(p, sender); setHalted(p, true);
return true; return true;
} }
else else
{ {
TFM_Util.adminAction(sender.getName(), "Unhalting " + p.getName(), true); TFM_Util.adminAction(sender.getName(), "Unhalting " + p.getName(), true);
setHalted(p, false);
return true;
}
}
unhalt(p, sender); private void setHalted(Player p, boolean is_halted)
return true; {
} TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p);
}
public void halt(Player p, CommandSender sender) if (is_halted)
{ {
TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p); p.setOp(false);
p.setGameMode(GameMode.SURVIVAL);
p.setFlying(false);
p.setDisplayName(p.getName());
p.closeInventory();
p.setTotalExperience(0);
p.setOp(false); playerdata.stopOrbiting();
p.setGameMode(GameMode.SURVIVAL); playerdata.setFrozen(true);
p.setFlying(false); playerdata.setMuted(true);
p.setDisplayName(p.getName()); playerdata.setHalted(true);
p.closeInventory();
p.setTotalExperience(0);
playerdata.stopOrbiting(); TFM_Util.playerMsg(p, "You have been halted, don't move!");
playerdata.setFrozen(true); }
playerdata.setMuted(true); else
playerdata.setHalted(true); {
p.setOp(true);
TFM_Util.playerMsg(p, "You have been halted, don't move!"); p.setGameMode(GameMode.CREATIVE);
} playerdata.setFrozen(false);
playerdata.setMuted(false);
public void unhalt(Player p, CommandSender sender) playerdata.setHalted(false);
{ TFM_Util.playerMsg(p, "You are no longer halted.");
TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p); }
}
p.setOp(true);
p.setGameMode(GameMode.CREATIVE);
playerdata.setFrozen(false);
playerdata.setMuted(false);
playerdata.setHalted(false);
TFM_Util.playerMsg(p, "You are no longer halted.");
}
} }

View File

@ -2,77 +2,71 @@ 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.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;
public class Command_permban extends TFM_Command public class Command_permban extends TFM_Command
{ {
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if(!sender.isOp()) if (!sender.isOp())
{ {
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;
} }
if(args.length != 1) if (args.length != 1)
{ {
return false; return false;
} }
if(args[0].equalsIgnoreCase("list")) if (args[0].equalsIgnoreCase("list"))
{ {
TFM_Util.playerMsg(sender, "Permanently banned players:"); if (TotalFreedomMod.permbanned_players.size() > 0)
int count = 0;
for (String pbp : TotalFreedomMod.permbanned_players)
{ {
TFM_Util.playerMsg(sender, "- " + pbp); TFM_Util.playerMsg(sender, "No permanently banned player names.");
count++;
}
if (count == 0)
{
TFM_Util.playerMsg(sender, "- none");
} }
else else
{ {
TFM_Util.playerMsg(sender, "Total: " + count); TFM_Util.playerMsg(sender, TotalFreedomMod.permbanned_players.size() + " permanently banned players:");
for (String player_name : TotalFreedomMod.permbanned_players)
{
TFM_Util.playerMsg(sender, "- " + player_name);
}
} }
count = 0; if (TotalFreedomMod.permbanned_ips.size() > 0)
TFM_Util.playerMsg(sender, "Permanently banned IPs:");
for (String pbp : TotalFreedomMod.permbanned_ips)
{ {
TFM_Util.playerMsg(sender, "- " + pbp); TFM_Util.playerMsg(sender, "No permanently banned IPs.");
count++;
}
if (count == 0)
{
TFM_Util.playerMsg(sender, "- none");
} }
else else
{ {
TFM_Util.playerMsg(sender, "Total: " + count); TFM_Util.playerMsg(sender, TotalFreedomMod.permbanned_ips.size() + " permanently banned IPs:");
for (String ip_address : TotalFreedomMod.permbanned_ips)
{
TFM_Util.playerMsg(sender, "- " + ip_address);
}
} }
return true; return true;
} }
if(!senderIsConsole) if (!senderIsConsole)
{ {
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;
} }
if(args[0].equalsIgnoreCase("reload")) if (args[0].equalsIgnoreCase("reload"))
{ {
plugin.loadPermbanConfig(); plugin.loadPermbanConfig();
return true; return true;
} }
// no command executed return false;
return false;
} }
} }

View File

@ -6,7 +6,6 @@ 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;
public class Command_rank extends TFM_Command public class Command_rank extends TFM_Command
{ {
@Override @Override
@ -14,10 +13,10 @@ public class Command_rank extends TFM_Command
{ {
if (senderIsConsole && args.length < 1) if (senderIsConsole && args.length < 1)
{ {
for(Player p : server.getOnlinePlayers()) for (Player p : server.getOnlinePlayers())
{ {
sender.sendMessage(p.getName() + " is " + TFM_Util.getRank(p)); sender.sendMessage(p.getName() + " is " + TFM_Util.getRank(p));
} }
return true; return true;
} }

View File

@ -171,7 +171,7 @@ public class Command_whitelist extends TFM_Command
if (args[0].equalsIgnoreCase("purge")) if (args[0].equalsIgnoreCase("purge"))
{ {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Set whitelisted = MinecraftServer.getServer().getServerConfigurationManager().getWhitelisted(); Set whitelisted = MinecraftServer.getServer().getServerConfigurationManager().getWhitelisted();
TFM_Util.adminAction(sender.getName(), "Removing all players from the whitelist.", false); TFM_Util.adminAction(sender.getName(), "Removing all players from the whitelist.", false);
TFM_Util.playerMsg(sender, "Removed " + whitelisted.size() + " players from the whitelist."); TFM_Util.playerMsg(sender, "Removed " + whitelisted.size() + " players from the whitelist.");
whitelisted.clear(); whitelisted.clear();

View File

@ -691,6 +691,26 @@ public class TFM_PlayerListener implements Listener
return; return;
} }
for (String test_player : TotalFreedomMod.permbanned_players)
{
if (test_player.equalsIgnoreCase(player_name))
{
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your username is permanently banned from this server.");
return;
}
}
for (String test_ip : TotalFreedomMod.permbanned_ips)
{
//TODO: Add support for wildcards in permbanned_ips list.
//TODO: Create generic wildcard IP matching method since we do this several times already in this project.
if (test_ip.equalsIgnoreCase(player_ip))
{
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your IP address is permanently banned from this server.");
return;
}
}
if (server.getOnlinePlayers().length >= server.getMaxPlayers()) if (server.getOnlinePlayers().length >= server.getMaxPlayers())
{ {
event.disallow(PlayerLoginEvent.Result.KICK_FULL, "Sorry, but this server is full."); event.disallow(PlayerLoginEvent.Result.KICK_FULL, "Sorry, but this server is full.");
@ -720,25 +740,6 @@ public class TFM_PlayerListener implements Listener
return; return;
} }
} }
for(String test_player : TotalFreedomMod.permbanned_players)
{
if(test_player.equalsIgnoreCase(player_name))
{
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your username is permanently banned from this server.");
return;
}
}
for(String test_ip : TotalFreedomMod.permbanned_ips)
{
if(test_ip.equalsIgnoreCase(player_ip))
{
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your IP-address is permanently banned from this server.");
return;
}
}
} }
else else
{ {

View File

@ -37,7 +37,6 @@ public class TFM_UserInfo
private int mp44_schedule_id = -1; private int mp44_schedule_id = -1;
private boolean mp44_armed = false; private boolean mp44_armed = false;
private boolean mp44_firing = false; private boolean mp44_firing = false;
public static Map<Player, TFM_UserInfo> userinfo = new HashMap<Player, TFM_UserInfo>(); public static Map<Player, TFM_UserInfo> userinfo = new HashMap<Player, TFM_UserInfo>();
private TFM_UserInfo(Player player) private TFM_UserInfo(Player player)
@ -342,11 +341,11 @@ public class TFM_UserInfo
public boolean isHalted() public boolean isHalted()
{ {
return is_halted; return is_halted;
} }
public void setHalted(boolean is_halted) public void setHalted(boolean is_halted)
{ {
this.is_halted = is_halted; this.is_halted = is_halted;
} }
} }

View File

@ -25,9 +25,11 @@ public class TotalFreedomMod extends JavaPlugin
private final Server server = Bukkit.getServer(); private final Server server = Bukkit.getServer();
public static final long HEARTBEAT_RATE = 5L; //Seconds public static final long HEARTBEAT_RATE = 5L; //Seconds
public static final String CONFIG_FILE = "config.yml"; public static final String CONFIG_FILE = "config.yml";
public static final String SUPERADMIN_FILE = "superadmin.yml"; public static final String SUPERADMIN_FILE = "superadmin.yml";
public static final String PERMBAN_FILE = "permban.yml"; public static final String PERMBAN_FILE = "permban.yml";
public static final String COMMAND_PATH = "me.StevenLawson.TotalFreedomMod.Commands"; public static final String COMMAND_PATH = "me.StevenLawson.TotalFreedomMod.Commands";
public static final String COMMAND_PREFIX = "Command_"; public static final String COMMAND_PREFIX = "Command_";
@ -233,9 +235,6 @@ public class TotalFreedomMod extends JavaPlugin
} }
} }
} }
TFM_Log.info("Loaded " + superadmins.size() + " superadmins");
TFM_Log.info("Loaded " + superadmin_ips.size() + " superadmin IPs");
} }
public static List<String> permbanned_players = new ArrayList<String>(); public static List<String> permbanned_players = new ArrayList<String>();
@ -243,12 +242,11 @@ public class TotalFreedomMod extends JavaPlugin
public void loadPermbanConfig() public void loadPermbanConfig()
{ {
TFM_Util.createDefaultConfiguration(PERMBAN_FILE, getFile()); TFM_Util.createDefaultConfiguration(PERMBAN_FILE, getFile());
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), PERMBAN_FILE));
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), PERMBAN_FILE)); permbanned_players = new ArrayList<String>();
permbanned_ips = new ArrayList<String>();
permbanned_players = new ArrayList<String>();
permbanned_ips = new ArrayList<String>();
for (String user : config.getKeys(false)) for (String user : config.getKeys(false))
{ {
@ -264,9 +262,6 @@ public class TotalFreedomMod extends JavaPlugin
} }
} }
} }
TFM_Log.info("Loaded " + permbanned_players.size() + " permanently banned players");
TFM_Log.info("Loaded " + permbanned_ips.size() + " permanently banned IPs");
} }
private void registerEventHandlers() private void registerEventHandlers()

View File

@ -1,6 +1,5 @@
# #
# Permanent bans # Permanent Bans
# Only to be modified by markbyron
# #
badplayer1: badplayer1:

View File

@ -75,7 +75,7 @@ commands:
usage: /<command> <partialname> usage: /<command> <partialname>
halt: halt:
description: Superadmin command - Halts a player description: Superadmin command - Halts a player
usage: /<command> <<partialname> | all | purge> usage: /<command> <<partialname> | all | purge | list>
kicknoob: kicknoob:
description: Superadmin command - Kick all non-superadmins on server. description: Superadmin command - Kick all non-superadmins on server.
usage: /<command> usage: /<command>