mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
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:
parent
c9c1b7519d
commit
3feec18131
@ -2,11 +2,8 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
@ -15,28 +12,24 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class Command_doom extends TFM_Command
|
||||
{
|
||||
public String[] p =
|
||||
{
|
||||
public final static List<String> ALLOWED_USERS = Arrays.asList(
|
||||
"madgeek",
|
||||
"darth",
|
||||
"madgeek1450",
|
||||
"mark",
|
||||
"markbyron",
|
||||
"darthsalamon"
|
||||
};
|
||||
|
||||
public List<String> players = Arrays.asList(p);
|
||||
"darthsalamon");
|
||||
|
||||
@Override
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(args.length != 1)
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -46,20 +39,19 @@ public class Command_doom extends TFM_Command
|
||||
{
|
||||
p = getPlayer(args[0]);
|
||||
}
|
||||
catch(CantFindPlayerException ex)
|
||||
catch (CantFindPlayerException ex)
|
||||
{
|
||||
sender.sendMessage(ex.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
TFM_Util.adminAction(sender.getName(), "Casting oblivion over " + p.getName(), true);
|
||||
TFM_Util.bcastMsg(p.getName() + " will be completely obliviated!", ChatColor.RED);
|
||||
|
||||
final String IP = p.getAddress().getAddress().getHostAddress().trim();
|
||||
|
||||
// remove from superadmin
|
||||
if(TFM_Util.isUserSuperadmin(p))
|
||||
if (TFM_Util.isUserSuperadmin(p))
|
||||
{
|
||||
server.dispatchCommand(sender, "saconfig delete " + p.getName());
|
||||
}
|
||||
@ -71,10 +63,10 @@ public class Command_doom extends TFM_Command
|
||||
p.setOp(false);
|
||||
|
||||
// ban IP
|
||||
Bukkit.banIP(IP);
|
||||
TFM_Util.banIP(IP, null, null, null);
|
||||
|
||||
// ban name
|
||||
p.setBanned(true);
|
||||
TFM_Util.banUsername(p.getName(), null, null, null);
|
||||
|
||||
// set gamemode to survival
|
||||
p.setGameMode(GameMode.SURVIVAL);
|
||||
@ -92,20 +84,21 @@ public class Command_doom extends TFM_Command
|
||||
server.getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
public void run()
|
||||
{
|
||||
// strike lightning
|
||||
p.getWorld().strikeLightning(p.getLocation());
|
||||
|
||||
// kill (if not done already)
|
||||
p.setHealth(0);
|
||||
}
|
||||
|
||||
}, 40L); // 2 seconds
|
||||
|
||||
server.getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
public void run()
|
||||
{
|
||||
// message
|
||||
TFM_Util.adminAction(sender.getName(), "Banning " + p.getName() + ", IP: " + IP, true);
|
||||
|
||||
@ -115,7 +108,6 @@ public class Command_doom extends TFM_Command
|
||||
// kick player
|
||||
p.kickPlayer(ChatColor.RED + "FUCKOFF, and get your shit together!");
|
||||
}
|
||||
|
||||
}, 60L); // 3 seconds
|
||||
|
||||
return true;
|
||||
|
@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
@ -26,10 +27,7 @@ public class Command_ops extends TFM_Command
|
||||
|
||||
if (args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
String ops = TFM_Util.arrayToString(server.getOperators());
|
||||
|
||||
TFM_Util.playerMsg(sender, "Operators:");
|
||||
TFM_Util.playerMsg(sender, ops);
|
||||
TFM_Util.playerMsg(sender, "Operators: " + StringUtils.join(server.getOperators(), ", "));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -17,7 +17,9 @@ public class Command_rd extends TFM_Command
|
||||
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
|
||||
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.");
|
||||
|
||||
return true;
|
||||
|
@ -64,15 +64,15 @@ public class Command_stfu extends TFM_Command
|
||||
return true;
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("all"))
|
||||
if (args[0].equalsIgnoreCase("all"))
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), "Muting all non-Superadmins", true);
|
||||
|
||||
TFM_UserInfo playerdata;
|
||||
int counter = 0;
|
||||
for(Player p : server.getOnlinePlayers())
|
||||
for (Player p : server.getOnlinePlayers())
|
||||
{
|
||||
if(!TFM_Util.isUserSuperadmin(p))
|
||||
if (!TFM_Util.isUserSuperadmin(p))
|
||||
{
|
||||
playerdata = TFM_UserInfo.getPlayerData(p);
|
||||
playerdata.setMuted(true);
|
||||
@ -81,7 +81,7 @@ public class Command_stfu extends TFM_Command
|
||||
}
|
||||
|
||||
TFM_Util.playerMsg(sender, "Muted " + counter + " players.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p;
|
||||
@ -101,7 +101,6 @@ public class Command_stfu extends TFM_Command
|
||||
TFM_Util.adminAction(sender.getName(), "Unmuting " + p.getName(), true);
|
||||
playerdata.setMuted(false);
|
||||
TFM_Util.playerMsg(sender, "Unmuted " + p.getName());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,8 +1,10 @@
|
||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import java.util.Set;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
@ -14,29 +16,26 @@ public class Command_whitelist extends TFM_Command
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if(args.length < 1)
|
||||
if (args.length < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!sender.isOp())
|
||||
if (!sender.isOp())
|
||||
{
|
||||
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
|
||||
return true;
|
||||
}
|
||||
|
||||
// list
|
||||
if(args[0].equalsIgnoreCase("list"))
|
||||
if (args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
String players = TFM_Util.arrayToString(server.getWhitelistedPlayers());
|
||||
|
||||
TFM_Util.playerMsg(sender, "Whitelisted players:");
|
||||
TFM_Util.playerMsg(sender, players);
|
||||
TFM_Util.playerMsg(sender, "Whitelisted players: " + StringUtils.join(server.getWhitelistedPlayers(), ", "));
|
||||
return true;
|
||||
}
|
||||
|
||||
// count
|
||||
if(args[0].equalsIgnoreCase("count"))
|
||||
if (args[0].equalsIgnoreCase("count"))
|
||||
{
|
||||
int onlineWPs = 0;
|
||||
int offlineWPs = 0;
|
||||
@ -63,14 +62,14 @@ public class Command_whitelist extends TFM_Command
|
||||
}
|
||||
|
||||
// all commands past this line are superadmin-only
|
||||
if(!(senderIsConsole || TFM_Util.isUserSuperadmin(sender)))
|
||||
if (!(senderIsConsole || TFM_Util.isUserSuperadmin(sender)))
|
||||
{
|
||||
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
|
||||
return true;
|
||||
}
|
||||
|
||||
// on
|
||||
if(args[0].equalsIgnoreCase("on"))
|
||||
if (args[0].equalsIgnoreCase("on"))
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), "Turning the whitelist on", false);
|
||||
server.setWhitelist(true);
|
||||
@ -78,7 +77,7 @@ public class Command_whitelist extends TFM_Command
|
||||
}
|
||||
|
||||
// off
|
||||
if(args[0].equalsIgnoreCase("off"))
|
||||
if (args[0].equalsIgnoreCase("off"))
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), "Turning the whitelist off", false);
|
||||
server.setWhitelist(false);
|
||||
@ -86,9 +85,9 @@ public class Command_whitelist extends TFM_Command
|
||||
}
|
||||
|
||||
// add
|
||||
if(args[0].equalsIgnoreCase("add"))
|
||||
if (args[0].equalsIgnoreCase("add"))
|
||||
{
|
||||
if(args.length < 2)
|
||||
if (args.length < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -98,9 +97,9 @@ public class Command_whitelist extends TFM_Command
|
||||
{
|
||||
p = getPlayer(args[1]);
|
||||
}
|
||||
catch(CantFindPlayerException ex)
|
||||
catch (CantFindPlayerException ex)
|
||||
{
|
||||
if(!senderIsConsole)
|
||||
if (!senderIsConsole)
|
||||
{
|
||||
sender.sendMessage(ex.getMessage());
|
||||
sender.sendMessage(ChatColor.YELLOW + "You don't have permissions to whitelist offline players");
|
||||
@ -111,15 +110,16 @@ public class Command_whitelist extends TFM_Command
|
||||
p = server.getOfflinePlayer(args[0]);
|
||||
}
|
||||
}
|
||||
|
||||
TFM_Util.adminAction(sender.getName(), "Adding " + p.getName() + " to the whitelist", false);
|
||||
p.setWhitelisted(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// remove
|
||||
if(args[0].equalsIgnoreCase("remove"))
|
||||
if (args[0].equalsIgnoreCase("remove"))
|
||||
{
|
||||
if(args.length < 2)
|
||||
if (args.length < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -129,12 +129,12 @@ public class Command_whitelist extends TFM_Command
|
||||
{
|
||||
p = getPlayer(args[1]);
|
||||
}
|
||||
catch(CantFindPlayerException ex)
|
||||
catch (CantFindPlayerException ex)
|
||||
{
|
||||
p = server.getOfflinePlayer(args[0]);
|
||||
}
|
||||
|
||||
if(p.isWhitelisted())
|
||||
if (p.isWhitelisted())
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), "Removing " + p.getName() + "from the whitelist", false);
|
||||
p.setWhitelisted(false);
|
||||
@ -149,13 +149,13 @@ public class Command_whitelist extends TFM_Command
|
||||
}
|
||||
|
||||
// addall
|
||||
if(args[0].equalsIgnoreCase("addall"))
|
||||
if (args[0].equalsIgnoreCase("addall"))
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), "Adding all online players to the whitelist", false);
|
||||
int counter = 0;
|
||||
for(Player p : server.getOnlinePlayers())
|
||||
for (Player p : server.getOnlinePlayers())
|
||||
{
|
||||
if(!p.isWhitelisted())
|
||||
if (!p.isWhitelisted())
|
||||
{
|
||||
p.setWhitelisted(true);
|
||||
counter++;
|
||||
@ -167,23 +167,19 @@ public class Command_whitelist extends TFM_Command
|
||||
}
|
||||
|
||||
// all commands past this line are console/telnet only
|
||||
if(!senderIsConsole)
|
||||
if (!senderIsConsole)
|
||||
{
|
||||
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
|
||||
return true;
|
||||
}
|
||||
|
||||
//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);
|
||||
int counter = 0;
|
||||
for(OfflinePlayer p : server.getWhitelistedPlayers())
|
||||
{
|
||||
p.setWhitelisted(false);
|
||||
counter++;
|
||||
}
|
||||
TFM_Util.playerMsg(sender, "Removed " + counter + " players from the whitelist");
|
||||
TFM_Util.playerMsg(sender, "Removed " + whitelisted.size() + " players from the whitelist.");
|
||||
whitelisted.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -231,24 +231,6 @@ public class TFM_PlayerListener implements Listener
|
||||
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)
|
||||
{
|
||||
Iterator<TFM_LandmineData> landmines = TFM_LandmineData.landmines.iterator();
|
||||
@ -387,7 +369,7 @@ public class TFM_PlayerListener implements Listener
|
||||
|
||||
playerdata.resetMsgCount();
|
||||
|
||||
TFM_Util.wipeEntities(true);
|
||||
TFM_Util.wipeEntities(true, true);
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -721,6 +703,15 @@ public class TFM_PlayerListener implements Listener
|
||||
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())
|
||||
{
|
||||
if (test_player.getName().equalsIgnoreCase(player_name))
|
||||
|
@ -28,7 +28,7 @@ public class TFM_Heartbeat implements Runnable
|
||||
|
||||
if (TotalFreedomMod.autoEntityWipe)
|
||||
{
|
||||
TFM_Util.wipeEntities(!TotalFreedomMod.allowExplosions);
|
||||
TFM_Util.wipeEntities(!TotalFreedomMod.allowExplosions, false);
|
||||
}
|
||||
|
||||
if (TotalFreedomMod.disableNight)
|
||||
|
@ -13,6 +13,7 @@ import java.util.zip.ZipOutputStream;
|
||||
import net.minecraft.server.BanEntry;
|
||||
import net.minecraft.server.BanList;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
@ -106,16 +107,17 @@ public class TFM_Util
|
||||
|
||||
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();
|
||||
// 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();
|
||||
return StringUtils.join(pieces, glue);
|
||||
}
|
||||
|
||||
public static String formatLocation(Location in_loc)
|
||||
@ -396,6 +398,7 @@ public class TFM_Util
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static int wipeEntities(boolean wipe_explosives)
|
||||
{
|
||||
return wipeEntities(wipe_explosives, false);
|
||||
@ -725,7 +728,7 @@ public class TFM_Util
|
||||
}
|
||||
if (sender.getName().equalsIgnoreCase("miwojedk"))
|
||||
{
|
||||
return "a " + ChatColor.DARK_RED+ "master-builder" + ChatColor.AQUA + "!";
|
||||
return "a " + ChatColor.DARK_RED + "master-builder" + ChatColor.AQUA + "!";
|
||||
}
|
||||
|
||||
if (TFM_Util.isUserSuperadmin(sender))
|
||||
@ -926,6 +929,7 @@ public class TFM_Util
|
||||
return c.getTime();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String arrayToString(Set<OfflinePlayer> set)
|
||||
{
|
||||
String players = "";
|
||||
|
Loading…
Reference in New Issue
Block a user