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"))
{
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();
return true;
}

View File

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

View File

@ -171,7 +171,7 @@ public class Command_whitelist extends TFM_Command
if (args[0].equalsIgnoreCase("purge"))
{
@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.playerMsg(sender, "Removed " + whitelisted.size() + " players from the whitelist.");
whitelisted.clear();

View File

@ -691,6 +691,26 @@ public class TFM_PlayerListener implements Listener
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())
{
event.disallow(PlayerLoginEvent.Result.KICK_FULL, "Sorry, but this server is full.");
@ -720,25 +740,6 @@ public class TFM_PlayerListener implements Listener
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
{

View File

@ -37,7 +37,6 @@ public class TFM_UserInfo
private int mp44_schedule_id = -1;
private boolean mp44_armed = false;
private boolean mp44_firing = false;
public static Map<Player, TFM_UserInfo> userinfo = new HashMap<Player, TFM_UserInfo>();
private TFM_UserInfo(Player player)
@ -342,11 +341,11 @@ public class TFM_UserInfo
public boolean isHalted()
{
return is_halted;
return 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();
public static final long HEARTBEAT_RATE = 5L; //Seconds
public static final String CONFIG_FILE = "config.yml";
public static final String SUPERADMIN_FILE = "superadmin.yml";
public static final String PERMBAN_FILE = "permban.yml";
public static final String COMMAND_PATH = "me.StevenLawson.TotalFreedomMod.Commands";
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>();
@ -243,12 +242,11 @@ public class TotalFreedomMod extends JavaPlugin
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))
{
@ -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()

View File

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

View File

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