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;
}
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("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("list"))
{
TFM_Util.playerMsg(sender, "Halted players:");
@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[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())
{
setHalted(p, false);
counter++;
}
}
TFM_Util.playerMsg(sender, "Unhalted " + counter + " players.");
return true;
}
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;
}
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);
unhalt(p, sender);
return true;
}
}
public void halt(Player p, CommandSender sender)
{
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);
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.");
}
}
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);
setHalted(p, true);
return true;
}
else
{
TFM_Util.adminAction(sender.getName(), "Unhalting " + p.getName(), true);
setHalted(p, false);
return true;
}
}
private void setHalted(Player p, boolean is_halted)
{
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);
playerdata.stopOrbiting();
playerdata.setFrozen(true);
playerdata.setMuted(true);
playerdata.setHalted(true);
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(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)
{
TFM_Util.playerMsg(sender, "- " + pbp);
count++;
}
if (count == 0)
{
TFM_Util.playerMsg(sender, "- none");
}
else
{
TFM_Util.playerMsg(sender, "Total: " + count);
}
count = 0;
TFM_Util.playerMsg(sender, "Permanently banned IPs:");
for (String pbp : TotalFreedomMod.permbanned_ips)
{
TFM_Util.playerMsg(sender, "- " + pbp);
count++;
}
if (count == 0)
{
TFM_Util.playerMsg(sender, "- none");
}
else
{
TFM_Util.playerMsg(sender, "Total: " + count);
}
if (!sender.isOp())
{
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;
}
// no command executed
return false;
}
if (args.length != 1)
{
return false;
}
if (args[0].equalsIgnoreCase("list"))
{
if (TotalFreedomMod.permbanned_players.size() > 0)
{
TFM_Util.playerMsg(sender, "No permanently banned player names.");
}
else
{
TFM_Util.playerMsg(sender, TotalFreedomMod.permbanned_players.size() + " permanently banned players:");
for (String player_name : TotalFreedomMod.permbanned_players)
{
TFM_Util.playerMsg(sender, "- " + player_name);
}
}
if (TotalFreedomMod.permbanned_ips.size() > 0)
{
TFM_Util.playerMsg(sender, "No permanently banned IPs.");
}
else
{
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 (args[0].equalsIgnoreCase("reload"))
{
plugin.loadPermbanConfig();
return true;
}
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,14 +37,13 @@ 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)
{
this.player = player;
}
public static TFM_UserInfo getPlayerData(Player p)
{
TFM_UserInfo playerdata = TFM_UserInfo.userinfo.get(p);
@ -55,7 +54,7 @@ public class TFM_UserInfo
}
return playerdata;
}
public boolean isOrbiting()
{
return this.is_orbiting;
@ -66,7 +65,7 @@ public class TFM_UserInfo
this.is_orbiting = true;
this.orbit_strength = orbit_strength;
}
public void stopOrbiting()
{
this.is_orbiting = false;
@ -94,7 +93,7 @@ public class TFM_UserInfo
{
return this.user_caged;
}
public enum CageLayer
{
INNER, OUTER
@ -187,7 +186,7 @@ public class TFM_UserInfo
{
this.block_destroy_total = 0;
}
public void incrementBlockPlaceCount()
{
this.block_place_total++;
@ -239,7 +238,7 @@ public class TFM_UserInfo
this.mob_thrower_creature = mob_thrower_creature;
this.mob_thrower_speed = mob_thrower_speed;
}
public void disableMobThrower()
{
this.mob_thrower_enabled = false;
@ -254,12 +253,12 @@ public class TFM_UserInfo
{
return this.mob_thrower_speed;
}
public boolean mobThrowerEnabled()
{
return this.mob_thrower_enabled;
}
public void enqueueMob(LivingEntity mob)
{
mob_thrower_queue.add(mob);
@ -272,14 +271,14 @@ public class TFM_UserInfo
}
}
}
public void startArrowShooter(TotalFreedomMod plugin)
{
this.stopArrowShooter();
this.mp44_schedule_id = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new ArrowShooter(this.player), 1L, 1L);
mp44_firing = true;
}
public void stopArrowShooter()
{
if (this.mp44_schedule_id != -1)
@ -289,11 +288,11 @@ public class TFM_UserInfo
}
mp44_firing = false;
}
class ArrowShooter implements Runnable
{
private Player _player;
public ArrowShooter(Player player)
{
this._player = player;
@ -306,24 +305,24 @@ public class TFM_UserInfo
shot_arrow.setVelocity(shot_arrow.getVelocity().multiply(2.0));
}
}
public void armMP44()
{
mp44_armed = true;
this.stopArrowShooter();
}
public void disarmMP44()
{
mp44_armed = false;
this.stopArrowShooter();
}
public boolean isMP44Armed()
{
return this.mp44_armed;
}
public boolean toggleMP44Firing()
{
this.mp44_firing = !this.mp44_firing;
@ -339,14 +338,14 @@ public class TFM_UserInfo
{
this.is_muted = is_muted;
}
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

@ -23,20 +23,22 @@ import org.bukkit.plugin.java.JavaPlugin;
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_";
public static final String MSG_NO_PERMS = ChatColor.YELLOW + "You do not have permission to use this command.";
public static final String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!";
public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!";
public static final String CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake.";
public static final String NOT_FROM_CONSOLE = "This command may not be used from the console.";
public static boolean allPlayersFrozen = false;
public static Map<Player, Double> fuckoffEnabledFor = new HashMap<Player, Double>();
@ -55,7 +57,7 @@ public class TotalFreedomMod extends JavaPlugin
TotalFreedomMod.pluginName = this.getDescription().getName();
setAppProperties();
loadMainConfig();
loadSuperadminConfig();
loadPermbanConfig();
@ -141,7 +143,7 @@ public class TotalFreedomMod extends JavaPlugin
return true;
}
public static boolean allowFirePlace = false;
public static Boolean allowFireSpread = false;
public static Boolean allowLavaDamage = false;
@ -207,10 +209,10 @@ public class TotalFreedomMod extends JavaPlugin
allowFliudSpread = config.getBoolean("allow_fluid_spread", allowFliudSpread);
adminOnlyMode = config.getBoolean("admin_only_mode", adminOnlyMode);
}
public static List<String> superadmins = new ArrayList<String>();
public static List<String> superadmin_ips = new ArrayList<String>();
public void loadSuperadminConfig()
{
TFM_Util.createDefaultConfiguration(SUPERADMIN_FILE, getFile());
@ -233,23 +235,19 @@ 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_ips = new ArrayList<String>();
public void loadPermbanConfig()
{
TFM_Util.createDefaultConfiguration(PERMBAN_FILE, getFile());
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), PERMBAN_FILE));
TFM_Util.createDefaultConfiguration(PERMBAN_FILE, getFile());
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))
{
permbanned_players.add(user.toLowerCase().trim());
@ -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,10 +1,9 @@
#
# Permanent bans
# Only to be modified by markbyron
# Permanent Bans
#
badplayer1:
- 123.123.123.123
- 321.321.321.321
badplayer2:
- 111.111.111.111
- 111.111.111.111

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>