Merge vanish & coreprotect-switch into main

This commit is contained in:
Business Goose 2022-03-31 03:10:08 +01:00
parent 2a0244ddd4
commit 4782438bc8
No known key found for this signature in database
GPG key ID: 77DCA801362E9645
177 changed files with 12395 additions and 14092 deletions

View file

@ -3,105 +3,85 @@ package me.StevenLawson.TotalFreedomMod;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Log
{
public class Log {
private static final Logger FALLBACK_LOGGER = Logger.getLogger("Minecraft-Server");
private static Logger serverLogger = null;
private static Logger pluginLogger = null;
private Log()
{
private Log() {
throw new AssertionError();
}
// Level.INFO:
public static void info(String message)
{
public static void info(String message) {
info(message, false);
}
public static void info(String message, Boolean raw)
{
public static void info(String message, Boolean raw) {
log(Level.INFO, message, raw);
}
public static void info(Throwable ex)
{
public static void info(Throwable ex) {
log(Level.INFO, ex);
}
// Level.WARNING:
public static void warning(String message)
{
public static void warning(String message) {
warning(message, false);
}
public static void warning(String message, Boolean raw)
{
public static void warning(String message, Boolean raw) {
log(Level.WARNING, message, raw);
}
public static void warning(Throwable ex)
{
public static void warning(Throwable ex) {
log(Level.WARNING, ex);
}
// Level.SEVERE:
public static void severe(String message)
{
public static void severe(String message) {
severe(message, false);
}
public static void severe(String message, Boolean raw)
{
public static void severe(String message, Boolean raw) {
log(Level.SEVERE, message, raw);
}
public static void severe(Throwable ex)
{
public static void severe(Throwable ex) {
log(Level.SEVERE, ex);
}
// Utility
private static void log(Level level, String message, boolean raw)
{
private static void log(Level level, String message, boolean raw) {
getLogger(raw).log(level, message);
}
private static void log(Level level, Throwable throwable)
{
private static void log(Level level, Throwable throwable) {
getLogger(false).log(level, null, throwable);
}
public static void setServerLogger(Logger logger)
{
serverLogger = logger;
}
public static void setPluginLogger(Logger logger)
{
pluginLogger = logger;
}
private static Logger getLogger(boolean raw)
{
if (raw || pluginLogger == null)
{
private static Logger getLogger(boolean raw) {
if (raw || pluginLogger == null) {
return (serverLogger != null ? serverLogger : FALLBACK_LOGGER);
}
else
{
} else {
return pluginLogger;
}
}
public static Logger getPluginLogger()
{
public static Logger getPluginLogger() {
return (pluginLogger != null ? pluginLogger : FALLBACK_LOGGER);
}
public static Logger getServerLogger()
{
public static void setPluginLogger(Logger logger) {
pluginLogger = logger;
}
public static Logger getServerLogger() {
return (serverLogger != null ? serverLogger : FALLBACK_LOGGER);
}
public static void setServerLogger(Logger logger) {
serverLogger = logger;
}
}

View file

@ -1,6 +1,13 @@
package me.StevenLawson.TotalFreedomMod;
import static me.StevenLawson.TotalFreedomMod.listener.PlayerListener.DEFAULT_PORT;
import com.earth2me.essentials.utils.DateUtil;
import java.lang.management.ManagementFactory;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
import me.StevenLawson.TotalFreedomMod.ban.Ban;
import me.StevenLawson.TotalFreedomMod.ban.BanManager;
@ -19,87 +26,68 @@ import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import java.lang.management.ManagementFactory;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;
public class Server {
import static me.StevenLawson.TotalFreedomMod.listener.PlayerListener.DEFAULT_PORT;
public class Server
{
public static final String COMPILE_NMS_VERSION = "v1_8_R2";
public static final Pattern USERNAME_REGEX = Pattern.compile("^[\\w\\d_]{3,20}$");
public static void setOnlineMode(boolean mode)
{
public static void setOnlineMode(boolean mode) {
final PropertyManager manager = MinecraftServer.getServer().getPropertyManager();
manager.setProperty("online-mode", mode);
manager.savePropertiesFile();
}
public static int purgeWhitelist()
{
public static int purgeWhitelist() {
String[] whitelisted = MinecraftServer.getServer().getPlayerList().getWhitelisted();
int size = whitelisted.length;
for (EntityPlayer player : MinecraftServer.getServer().getPlayerList().players)
{
for (EntityPlayer player : MinecraftServer.getServer().getPlayerList().players) {
MinecraftServer.getServer().getPlayerList().getWhitelist().remove(player.getProfile());
}
try
{
try {
MinecraftServer.getServer().getPlayerList().getWhitelist().save();
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.warning("Could not purge the whitelist!");
Log.warning(ex);
}
return size;
}
public static boolean isWhitelisted()
{
public static boolean isWhitelisted() {
return MinecraftServer.getServer().getPlayerList().getHasWhitelist();
}
public static List<?> getWhitelisted()
{
public static List<?> getWhitelisted() {
return Arrays.asList(MinecraftServer.getServer().getPlayerList().getWhitelisted());
}
public static String getVersion()
{
public static String getVersion() {
return MinecraftServer.getServer().getVersion();
}
public static void handlePlayerPreLogin(AsyncPlayerPreLoginEvent event)
{
public static void handlePlayerPreLogin(AsyncPlayerPreLoginEvent event) {
final String ip = event.getAddress().getHostAddress().trim();
final boolean isAdmin = AdminList.isSuperAdminSafe(null, ip);
// Check if the player is already online
for (Player onlinePlayer : TotalFreedomMod.server.getOnlinePlayers())
{
if (!onlinePlayer.getName().equalsIgnoreCase(event.getName()))
{
for (Player onlinePlayer : TotalFreedomMod.server.getOnlinePlayers()) {
if (!onlinePlayer.getName().equalsIgnoreCase(event.getName())) {
continue;
}
if (!isAdmin) {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "Your username is already logged into this server.");
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,
"Your username is already logged into this server.");
} else {
event.allow();
SynchronousUtil.playerKick(onlinePlayer, "An admin just logged in with the username you are using.");
SynchronousUtil.playerKick(onlinePlayer,
"An admin just logged in with the username you are using.");
}
return;
}
}
public static void handlePlayerLogin(PlayerLoginEvent event)
{
public static void handlePlayerLogin(PlayerLoginEvent event) {
final org.bukkit.Server server = TotalFreedomMod.server;
final Player player = event.getPlayer();
final String username = player.getName();
@ -107,32 +95,32 @@ public class Server
final UUID uuid = UUIDManager.newPlayer(player, ip);
// Check username length
if (username.length() < 3 || username.length() > TotalFreedomMod.MAX_USERNAME_LENGTH)
{
event.disallow(Result.KICK_OTHER, "Your username is an invalid length (must be between 3 and 20 characters long).");
if (username.length() < 3 || username.length() > TotalFreedomMod.MAX_USERNAME_LENGTH) {
event.disallow(Result.KICK_OTHER,
"Your username is an invalid length (must be between 3 and 20 characters long).");
return;
}
// Check username characters
if (!USERNAME_REGEX.matcher(username).find())
{
if (!USERNAME_REGEX.matcher(username).find()) {
event.disallow(Result.KICK_OTHER, "Your username contains invalid characters.");
return;
}
// Check force-IP match
if (ConfigurationEntry.FORCE_IP_ENABLED.getBoolean())
{
final String hostname = event.getHostname().replace("FML", ""); // Forge fix - https://github.com/TotalFreedom/TotalFreedomMod/issues/493
if (ConfigurationEntry.FORCE_IP_ENABLED.getBoolean()) {
final String hostname = event.getHostname().replace("FML",
""); // Forge fix - https://github.com/TotalFreedom/TotalFreedomMod/issues/493
final String connectAddress = ConfigurationEntry.SERVER_ADDRESS.getString();
final int connectPort = TotalFreedomMod.server.getPort();
if (!hostname.equalsIgnoreCase(connectAddress + ":" + connectPort) && !hostname.equalsIgnoreCase(connectAddress + ".:" + connectPort))
{
if (!hostname.equalsIgnoreCase(connectAddress + ":" + connectPort)
&& !hostname.equalsIgnoreCase(connectAddress + ".:" + connectPort)) {
final int forceIpPort = ConfigurationEntry.FORCE_IP_PORT.getInteger();
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
ConfigurationEntry.FORCE_IP_KICKMSG.getString()
.replace("%address%", ConfigurationEntry.SERVER_ADDRESS.getString() + (forceIpPort == DEFAULT_PORT ? "" : ":" + forceIpPort)));
.replace("%address%", ConfigurationEntry.SERVER_ADDRESS.getString() + (
forceIpPort == DEFAULT_PORT ? "" : ":" + forceIpPort)));
return;
}
@ -149,26 +137,23 @@ public class Server
event.allow();
int count = server.getOnlinePlayers().size();
if (count >= server.getMaxPlayers())
{
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (!AdminList.isSuperAdmin(onlinePlayer))
{
onlinePlayer.kickPlayer("You have been kicked to free up room for an admin.");
if (count >= server.getMaxPlayers()) {
for (Player onlinePlayer : server.getOnlinePlayers()) {
if (!AdminList.isSuperAdmin(onlinePlayer)) {
onlinePlayer.kickPlayer(
"You have been kicked to free up room for an admin.");
count--;
}
if (count < server.getMaxPlayers())
{
if (count < server.getMaxPlayers()) {
break;
}
}
}
if (count >= server.getMaxPlayers())
{
event.disallow(Result.KICK_OTHER, "The server is full and a player could not be kicked, sorry!");
if (count >= server.getMaxPlayers()) {
event.disallow(Result.KICK_OTHER,
"The server is full and a player could not be kicked, sorry!");
return;
}
@ -177,57 +162,48 @@ public class Server
// Player is not an admin
// Server full check
if (server.getOnlinePlayers().size() >= server.getMaxPlayers())
{
if (server.getOnlinePlayers().size() >= server.getMaxPlayers()) {
event.disallow(Result.KICK_FULL, "Sorry, but this server is full.");
return;
}
// Admin-only mode
if (ConfigurationEntry.ADMIN_ONLY_MODE.getBoolean())
{
if (ConfigurationEntry.ADMIN_ONLY_MODE.getBoolean()) {
event.disallow(Result.KICK_OTHER, "Server is temporarily open to admins only.");
return;
}
// Lockdown mode
if (TotalFreedomMod.lockdownEnabled)
{
if (TotalFreedomMod.lockdownEnabled) {
event.disallow(Result.KICK_OTHER, "Server is currently in lockdown mode.");
return;
}
// Whitelist
if (isWhitelisted())
{
if (!getWhitelisted().contains(username.toLowerCase()))
{
if (isWhitelisted()) {
if (!getWhitelisted().contains(username.toLowerCase())) {
event.disallow(Result.KICK_OTHER, "You are not whitelisted on this server.");
return;
}
}
// UUID ban
if (BanManager.isUuidBanned(uuid))
{
if (BanManager.isUuidBanned(uuid)) {
final Ban ban = BanManager.getByUuid(uuid);
event.disallow(Result.KICK_OTHER, ban.getKickMessage());
return;
}
// IP ban
if (BanManager.isIpBanned(ip))
{
if (BanManager.isIpBanned(ip)) {
final Ban ban = BanManager.getByIp(ip);
event.disallow(Result.KICK_OTHER, ban.getKickMessage());
return;
}
// Permbanned IPs
for (String testIp : PermbanList.getPermbannedIps())
{
if (Utilities.fuzzyIpMatch(testIp, ip, 4))
{
for (String testIp : PermbanList.getPermbannedIps()) {
if (Utilities.fuzzyIpMatch(testIp, ip, 4)) {
event.disallow(Result.KICK_OTHER,
ChatColor.RED + "Your IP address is permanently banned from this server.\n"
+ "Release procedures are available at\n"
@ -237,10 +213,8 @@ public class Server
}
// Permbanned usernames
for (String testPlayer : PermbanList.getPermbannedPlayers())
{
if (testPlayer.equalsIgnoreCase(username))
{
for (String testPlayer : PermbanList.getPermbannedPlayers()) {
if (testPlayer.equalsIgnoreCase(username)) {
event.disallow(Result.KICK_OTHER,
ChatColor.RED + "Your username is permanently banned from this server.\n"
+ "Release procedures are available at\n"

View file

@ -1,22 +1,34 @@
package me.StevenLawson.TotalFreedomMod;
import com.google.common.base.Function;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Logger;
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
import me.StevenLawson.TotalFreedomMod.announcer.Announcer;
import me.StevenLawson.TotalFreedomMod.ban.BanManager;
import me.StevenLawson.TotalFreedomMod.ban.PermbanList;
import me.StevenLawson.TotalFreedomMod.commands.Commands;
import me.StevenLawson.TotalFreedomMod.discord.bridge.DiscordBridge;
import me.StevenLawson.TotalFreedomMod.command.CommandBlocker;
import me.StevenLawson.TotalFreedomMod.commands.Commands;
import me.StevenLawson.TotalFreedomMod.commands.FreedomCommand;
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
import me.StevenLawson.TotalFreedomMod.deprecated.bridge.BukkitTelnetBridge;
import me.StevenLawson.TotalFreedomMod.discord.bridge.DiscordBridge;
import me.StevenLawson.TotalFreedomMod.gamerule.GameRuleHandler;
import me.StevenLawson.TotalFreedomMod.httpd.HTTPDManager;
import me.StevenLawson.TotalFreedomMod.listener.*;
import me.StevenLawson.TotalFreedomMod.listener.BlockListener;
import me.StevenLawson.TotalFreedomMod.listener.EntityListener;
import me.StevenLawson.TotalFreedomMod.listener.PlayerListener;
import me.StevenLawson.TotalFreedomMod.listener.ServerListener;
import me.StevenLawson.TotalFreedomMod.listener.WeatherListener;
import me.StevenLawson.TotalFreedomMod.listener.WorldEditListener;
import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.player.HeartBeat;
import me.StevenLawson.TotalFreedomMod.player.PlayerList;
import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import me.StevenLawson.TotalFreedomMod.world.AdminWorld;
import me.StevenLawson.TotalFreedomMod.world.FlatlandsWorld;
@ -31,15 +43,8 @@ import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Logger;
public class TotalFreedomMod extends JavaPlugin {
public static final long HEARTBEAT_RATE = 5L; // Seconds
public static final long SERVICE_CHECKER_RATE = 120L;
public static final int MAX_USERNAME_LENGTH = 20;
@ -70,6 +75,26 @@ public class TotalFreedomMod extends JavaPlugin {
private FileConfiguration customConfig; // Custom configuration implementation by Eva
private static void setAppProperties() {
try {
//final InputStream in = plugin.getResource("appinfo.properties");
Properties props = new Properties();
// in = plugin.getClass().getResourceAsStream("/appinfo.properties");
//props.load(in);
//in.close();
//TotalFreedomMod.buildNumber = props.getProperty("program.buildnumber");
//TotalFreedomMod.buildDate = props.getProperty("program.builddate");
//TotalFreedomMod.buildCreator = props.getProperty("program.buildcreator");
TotalFreedomMod.buildNumber = "1337";
TotalFreedomMod.buildCreator = "You!";
} catch (Exception ex) {
Log.severe("Could not load App properties!");
Log.severe(ex);
}
}
@Override
public void onLoad() {
TotalFreedomMod.plugin = this;
@ -85,8 +110,7 @@ public class TotalFreedomMod extends JavaPlugin {
}
@Override
public void onEnable()
{
public void onEnable() {
getConfig().options().copyDefaults(true);
Log.info("Made by Madgeek1450 and Prozza");
@ -95,9 +119,9 @@ public class TotalFreedomMod extends JavaPlugin {
final Utilities.MethodTimer timer = new Utilities.MethodTimer();
timer.start();
if (!Server.COMPILE_NMS_VERSION.equals(Utilities.getNmsVersion()))
{
Log.warning(pluginName + " is compiled for " + Server.COMPILE_NMS_VERSION + " but the server is running "
if (!Server.COMPILE_NMS_VERSION.equals(Utilities.getNmsVersion())) {
Log.warning(pluginName + " is compiled for " + Server.COMPILE_NMS_VERSION
+ " but the server is running "
+ "version " + Utilities.getNmsVersion() + "!");
Log.warning("This might result in unexpected behaviour!");
}
@ -122,7 +146,8 @@ public class TotalFreedomMod extends JavaPlugin {
DiscordBridge.load();
// Start SuperAdmin service
server.getServicesManager().register(Function.class, AdminList.SUPERADMIN_SERVICE, plugin, ServicePriority.Normal);
server.getServicesManager()
.register(Function.class, AdminList.SUPERADMIN_SERVICE, plugin, ServicePriority.Normal);
final PluginManager pm = server.getPluginManager();
pm.registerEvents(new EntityListener(), plugin);
@ -143,27 +168,26 @@ public class TotalFreedomMod extends JavaPlugin {
try {
AdminWorld.getInstance().getWorld();
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.warning("Could not load world: AdminWorld");
}
// Initialize game rules
GameRuleHandler.setGameRule(GameRuleHandler.TFM_GameRule.DO_DAYLIGHT_CYCLE, !ConfigurationEntry.DISABLE_NIGHT.getBoolean(), false);
GameRuleHandler.setGameRule(GameRuleHandler.TFM_GameRule.DO_FIRE_TICK, ConfigurationEntry.ALLOW_FIRE_SPREAD.getBoolean(), false);
GameRuleHandler.setGameRule(GameRuleHandler.TFM_GameRule.DO_DAYLIGHT_CYCLE,
!ConfigurationEntry.DISABLE_NIGHT.getBoolean(), false);
GameRuleHandler.setGameRule(GameRuleHandler.TFM_GameRule.DO_FIRE_TICK,
ConfigurationEntry.ALLOW_FIRE_SPREAD.getBoolean(), false);
GameRuleHandler.setGameRule(GameRuleHandler.TFM_GameRule.DO_MOB_LOOT, false, false);
GameRuleHandler.setGameRule(GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING, !ConfigurationEntry.MOB_LIMITER_ENABLED.getBoolean(), false);
GameRuleHandler.setGameRule(GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING,
!ConfigurationEntry.MOB_LIMITER_ENABLED.getBoolean(), false);
GameRuleHandler.setGameRule(GameRuleHandler.TFM_GameRule.DO_TILE_DROPS, false, false);
GameRuleHandler.setGameRule(GameRuleHandler.TFM_GameRule.MOB_GRIEFING, false, false);
GameRuleHandler.setGameRule(GameRuleHandler.TFM_GameRule.NATURAL_REGENERATION, true, false);
GameRuleHandler.commitGameRules();
// Disable weather
if (ConfigurationEntry.DISABLE_WEATHER.getBoolean())
{
for (World world : server.getWorlds())
{
if (ConfigurationEntry.DISABLE_WEATHER.getBoolean()) {
for (World world : server.getWorlds()) {
world.setThundering(false);
world.setStorm(false);
world.setThunderDuration(0);
@ -181,7 +205,8 @@ public class TotalFreedomMod extends JavaPlugin {
timer.update();
Log.info("Version " + pluginVersion + " for " + Server.COMPILE_NMS_VERSION + " enabled in " + timer.getTotal() + "ms");
Log.info("Version " + pluginVersion + " for " + Server.COMPILE_NMS_VERSION + " enabled in "
+ timer.getTotal() + "ms");
// Metrics @ http://mcstats.org/plugin/TotalFreedomMod
// No longer exist!
@ -195,11 +220,9 @@ public class TotalFreedomMod extends JavaPlugin {
Log.warning("Failed to submit metrics data: " + ex.getMessage());
}*/
new BukkitRunnable()
{
new BukkitRunnable() {
@Override
public void run()
{
public void run() {
CommandBlocker.load();
// Add spawnpoints later - https://github.com/TotalFreedom/TotalFreedomMod/issues/438
@ -209,8 +232,7 @@ public class TotalFreedomMod extends JavaPlugin {
}
@Override
public void onDisable()
{
public void onDisable() {
HTTPDManager.stop();
BanManager.save();
UUIDManager.close();
@ -224,6 +246,7 @@ public class TotalFreedomMod extends JavaPlugin {
public FileConfiguration getCustomConfig() {
return this.customConfig;
}
//CustomConfig implementation by Eva
private void createCustomConfig() {
File customConfigFile = new File(getDataFolder(), "playerTags.yml");
@ -232,35 +255,11 @@ public class TotalFreedomMod extends JavaPlugin {
saveResource("playerTags.yml", false);
}
customConfig= new YamlConfiguration();
customConfig = new YamlConfiguration();
try {
customConfig.load(customConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
private static void setAppProperties()
{
try
{
//final InputStream in = plugin.getResource("appinfo.properties");
Properties props = new Properties();
// in = plugin.getClass().getResourceAsStream("/appinfo.properties");
//props.load(in);
//in.close();
//TotalFreedomMod.buildNumber = props.getProperty("program.buildnumber");
//TotalFreedomMod.buildDate = props.getProperty("program.builddate");
//TotalFreedomMod.buildCreator = props.getProperty("program.buildcreator");
TotalFreedomMod.buildNumber = "1337";
TotalFreedomMod.buildCreator = "You!";
}
catch (Exception ex)
{
Log.severe("Could not load App properties!");
Log.severe(ex);
}
}
}

View file

@ -1,27 +1,31 @@
package me.StevenLawson.TotalFreedomMod.admin;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
import me.StevenLawson.TotalFreedomMod.config.MainConfig;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.configuration.ConfigurationSection;
import java.util.*;
public class Admin {
public class Admin
{
private final UUID uuid;
private String lastLoginName;
private String loginMessage;
private final boolean isSeniorAdmin;
private final boolean isTelnetAdmin;
private final List<String> consoleAliases;
private final List<String> ips;
private String lastLoginName;
private String loginMessage;
private Date lastLogin;
private boolean isActivated;
public Admin(UUID uuid, String lastLoginName, Date lastLogin, String loginMessage, boolean isTelnetAdmin, boolean isSeniorAdmin, boolean isActivated)
{
public Admin(UUID uuid, String lastLoginName, Date lastLogin, String loginMessage,
boolean isTelnetAdmin, boolean isSeniorAdmin, boolean isActivated) {
this.uuid = uuid;
this.lastLoginName = lastLoginName;
this.ips = new ArrayList<String>();
@ -33,32 +37,30 @@ public class Admin
this.isActivated = isActivated;
}
public Admin(UUID uuid, ConfigurationSection section)
{
public Admin(UUID uuid, ConfigurationSection section) {
this.uuid = uuid;
this.lastLoginName = section.getString("last_login_name");
this.ips = section.getStringList("ips");
this.lastLogin = Utilities.stringToDate(section.getString("last_login", Utilities.dateToString(new Date(0L))));
this.lastLogin = Utilities.stringToDate(
section.getString("last_login", Utilities.dateToString(new Date(0L))));
this.loginMessage = section.getString("custom_login_message", "");
this.isSeniorAdmin = section.getBoolean("is_senior_admin", false);
this.isTelnetAdmin = section.getBoolean("is_telnet_admin", false);
this.consoleAliases = section.getStringList("console_aliases");
this.isActivated = section.getBoolean("is_activated", true);
for (Iterator<?> it = MainConfig.getList(ConfigurationEntry.NOADMIN_IPS).iterator(); it.hasNext();)
{
for (Iterator<?> it = MainConfig.getList(ConfigurationEntry.NOADMIN_IPS).iterator();
it.hasNext(); ) {
ips.remove((String) it.next());
}
}
@Override
public String toString()
{
public String toString() {
final StringBuilder output = new StringBuilder();
final ArrayList<String> fuzziedIps = new ArrayList<>();
for (String ip : ips)
{
for (String ip : ips) {
fuzziedIps.add(Utilities.getFuzzyIp(ip));
}
@ -69,100 +71,82 @@ public class Admin
output.append("- Custom Login Message: ").append(loginMessage).append("\n");
output.append("- Is Senior Admin: ").append(isSeniorAdmin).append("\n");
output.append("- Is Telnet Admin: ").append(isTelnetAdmin).append("\n");
output.append("- Console Aliases: ").append(StringUtils.join(consoleAliases, ", ")).append("\n");
output.append("- Console Aliases: ").append(StringUtils.join(consoleAliases, ", "))
.append("\n");
output.append("- Is Activated: ").append(isActivated);
return output.toString();
}
public UUID getUniqueId()
{
public UUID getUniqueId() {
return uuid;
}
public void setLastLoginName(String lastLoginName)
{
this.lastLoginName = lastLoginName;
}
public String getLastLoginName()
{
public String getLastLoginName() {
return lastLoginName;
}
public List<String> getIps()
{
public void setLastLoginName(String lastLoginName) {
this.lastLoginName = lastLoginName;
}
public List<String> getIps() {
return Collections.unmodifiableList(ips);
}
public void addIp(String ip)
{
if (!ips.contains(ip))
{
public void addIp(String ip) {
if (!ips.contains(ip)) {
ips.add(ip);
}
}
public void addIps(List<String> ips)
{
for (String ip : ips)
{
public void addIps(List<String> ips) {
for (String ip : ips) {
addIp(ip);
}
}
public void removeIp(String ip)
{
public void removeIp(String ip) {
ips.remove(ip);
}
public void clearIPs()
{
public void clearIPs() {
ips.clear();
}
public void setCustomLoginMessage(String newLoginMessage)
{
this.loginMessage = newLoginMessage;
}
public Date getLastLogin()
{
public Date getLastLogin() {
return lastLogin;
}
public String getCustomLoginMessage()
{
return loginMessage;
}
public boolean isSeniorAdmin()
{
return isSeniorAdmin;
}
public boolean isTelnetAdmin()
{
return isTelnetAdmin;
}
public List<String> getConsoleAliases()
{
return Collections.unmodifiableList(consoleAliases);
}
public void setLastLogin(Date lastLogin)
{
public void setLastLogin(Date lastLogin) {
this.lastLogin = lastLogin;
}
public boolean isActivated()
{
public String getCustomLoginMessage() {
return loginMessage;
}
public void setCustomLoginMessage(String newLoginMessage) {
this.loginMessage = newLoginMessage;
}
public boolean isSeniorAdmin() {
return isSeniorAdmin;
}
public boolean isTelnetAdmin() {
return isTelnetAdmin;
}
public List<String> getConsoleAliases() {
return Collections.unmodifiableList(consoleAliases);
}
public boolean isActivated() {
return isActivated;
}
public void setActivated(boolean isActivated)
{
public void setActivated(boolean isActivated) {
this.isActivated = isActivated;
}
}

View file

@ -1,55 +1,47 @@
package me.StevenLawson.TotalFreedomMod.announcer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Announcer {
public class Announcer
{
private static final List<String> ANNOUNCEMENTS = new ArrayList<String>();
private static boolean enabled;
private static long interval;
private static String prefix;
private static BukkitRunnable announcer;
private Announcer()
{
private Announcer() {
throw new AssertionError();
}
public static boolean isEnabled()
{
public static boolean isEnabled() {
return enabled;
}
public static List<String> getAnnouncements()
{
public static List<String> getAnnouncements() {
return Collections.unmodifiableList(ANNOUNCEMENTS);
}
public static long getTickInterval()
{
public static long getTickInterval() {
return interval;
}
public static String getPrefix()
{
public static String getPrefix() {
return prefix;
}
public static void load()
{
public static void load() {
stop();
ANNOUNCEMENTS.clear();
for (Object announcement : ConfigurationEntry.ANNOUNCER_ANNOUNCEMENTS.getList())
{
for (Object announcement : ConfigurationEntry.ANNOUNCER_ANNOUNCEMENTS.getList()) {
ANNOUNCEMENTS.add(Utilities.colorize((String) announcement));
}
@ -57,35 +49,28 @@ public class Announcer
interval = ConfigurationEntry.ANNOUNCER_INTERVAL.getInteger() * 20L;
prefix = Utilities.colorize(ConfigurationEntry.ANNOUNCER_PREFIX.getString());
if (enabled)
{
if (enabled) {
start();
}
}
public static boolean isStarted()
{
public static boolean isStarted() {
return announcer != null;
}
public static void start()
{
if (isStarted())
{
public static void start() {
if (isStarted()) {
return;
}
announcer = new BukkitRunnable()
{
announcer = new BukkitRunnable() {
private int current = 0;
@Override
public void run()
{
public void run() {
current++;
if (current >= ANNOUNCEMENTS.size())
{
if (current >= ANNOUNCEMENTS.size()) {
current = 0;
}
@ -96,19 +81,14 @@ public class Announcer
announcer.runTaskTimer(TotalFreedomMod.plugin, interval, interval);
}
public static void stop()
{
if (announcer == null)
{
public static void stop() {
if (announcer == null) {
return;
}
try
{
try {
announcer.cancel();
}
finally
{
} finally {
announcer = null;
}
}

View file

@ -1,23 +1,22 @@
package me.StevenLawson.TotalFreedomMod.ban;
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.bukkit.ChatColor;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.bukkit.ChatColor;
public class Ban
{
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
public class Ban {
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
"yyyy-MM-dd 'at' HH:mm:ss z");
public static final Pattern IP_BAN_REGEX;
public static final Pattern UUID_BAN_REGEX;
static
{
static {
// 192.168.1.254:LocalHost:Prozza:0:none
// 127.0.*.*:TestUserName:BannedByNotch:123567:Test reason
IP_BAN_REGEX = Pattern.compile(
@ -34,6 +33,7 @@ public class Ban
+ ":(\\d+)"
+ ":([\\s\\S]+)$");
}
private final BanType type;
private final boolean complete;
private String subject; // uuid or IP
@ -42,28 +42,24 @@ public class Ban
private long expireUnix;
private String reason;
public Ban(String ip, String lastLoginName)
{
public Ban(String ip, String lastLoginName) {
this(ip, lastLoginName, null, null, null);
}
public Ban(String ip, String lastLoginName, String sender, Date expire, String reason)
{
public Ban(String ip, String lastLoginName, String sender, Date expire, String reason) {
this(ip, lastLoginName, sender, expire, reason, BanType.IP);
}
public Ban(UUID uuid, String lastLoginName)
{
public Ban(UUID uuid, String lastLoginName) {
this(uuid, lastLoginName, null, null, null);
}
public Ban(UUID uuid, String lastLoginName, String sender, Date expire, String reason)
{
public Ban(UUID uuid, String lastLoginName, String sender, Date expire, String reason) {
this(uuid.toString(), lastLoginName, sender, expire, reason, BanType.UUID);
}
private Ban(String subject, String lastLoginName, String sender, Date expire, String reason, BanType type)
{
private Ban(String subject, String lastLoginName, String sender, Date expire, String reason,
BanType type) {
this.type = type;
this.subject = subject;
this.lastLoginName = (lastLoginName == null ? "none" : lastLoginName);
@ -73,14 +69,13 @@ public class Ban
complete = true;
}
public Ban(String banString, BanType type)
{
public Ban(String banString, BanType type) {
this.type = type;
final Matcher matcher = (type == BanType.IP ? IP_BAN_REGEX.matcher(banString) : UUID_BAN_REGEX.matcher(banString));
final Matcher matcher = (type == BanType.IP ? IP_BAN_REGEX.matcher(banString)
: UUID_BAN_REGEX.matcher(banString));
if (!matcher.find())
{
if (!matcher.find()) {
complete = false;
return;
}
@ -93,67 +88,53 @@ public class Ban
complete = true;
}
public enum BanType
{
IP,
UUID
}
public BanType getType()
{
public BanType getType() {
return type;
}
public String getSubject()
{
public String getSubject() {
return subject;
}
public String getLastLoginName()
{
public String getLastLoginName() {
return lastLoginName;
}
public String getBannedBy()
{
public String getBannedBy() {
return by;
}
public long getExpireUnix()
{
public long getExpireUnix() {
return expireUnix;
}
public String getReason()
{
public String getReason() {
return reason;
}
public boolean isExpired()
{
public boolean isExpired() {
return expireUnix != 0 && expireUnix < Utilities.getUnixTime();
}
public boolean isComplete()
{
public boolean isComplete() {
return complete;
}
public String getKickMessage()
{
public String getKickMessage() {
final StringBuilder message = new StringBuilder("You");
message.append(type == BanType.IP ? "r IP address is" : " are").append(" temporarily banned from this server.");
message.append("\nAppeal at ").append(ChatColor.GOLD).append(ConfigurationEntry.SERVER_BAN_URL.getString());
message.append(type == BanType.IP ? "r IP address is" : " are")
.append(" temporarily banned from this server.");
message.append("\nAppeal at ").append(ChatColor.GOLD)
.append(ConfigurationEntry.SERVER_BAN_URL.getString());
if (!reason.equals("none"))
{
if (!reason.equals("none")) {
message.append("\nReason: ").append(reason);
}
if (getExpireUnix() != 0)
{
message.append("\nYour ban will be removed on ").append(DATE_FORMAT.format(Utilities.getUnixDate(expireUnix)));
if (getExpireUnix() != 0) {
message.append("\nYour ban will be removed on ")
.append(DATE_FORMAT.format(Utilities.getUnixDate(expireUnix)));
}
return message.toString();
@ -161,33 +142,28 @@ public class Ban
// subject:lastLoginName:bannedBy:expireUnix:reason
@Override
public String toString()
{
return subject + ":" + lastLoginName + ":" + by + ":" + expireUnix + ":" + Utilities.decolorize(reason);
public String toString() {
return subject + ":" + lastLoginName + ":" + by + ":" + expireUnix + ":"
+ Utilities.decolorize(reason);
}
@Override
public boolean equals(Object object)
{
if (object == null)
{
public boolean equals(Object object) {
if (object == null) {
return false;
}
if (!(object instanceof Ban))
{
if (!(object instanceof Ban)) {
return false;
}
final Ban ban = (Ban) object;
if (toString().equals(ban.toString()))
{
if (toString().equals(ban.toString())) {
return true;
}
if (getType() != ban.getType())
{
if (getType() != ban.getType()) {
return false;
}
@ -195,12 +171,16 @@ public class Ban
}
@Override
public int hashCode()
{
public int hashCode() {
final int prime = 37;
int result = 1;
result = prime * result + getType().hashCode();
result = prime * result + getSubject().hashCode();
return result;
}
public enum BanType {
IP,
UUID
}
}

View file

@ -1,5 +1,10 @@
package me.StevenLawson.TotalFreedomMod.ban;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import me.StevenLawson.TotalFreedomMod.Log;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.ban.Ban.BanType;
@ -10,28 +15,23 @@ import me.StevenLawson.TotalFreedomMod.manager.UUIDManager.TFM_UuidResolver;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.bukkit.entity.Player;
import java.util.*;
public class BanManager {
public class BanManager
{
private static final List<Ban> ipBans;
private static final List<Ban> uuidBans;
private static final List<UUID> unbannableUUIDs;
static
{
static {
ipBans = new ArrayList<Ban>();
uuidBans = new ArrayList<Ban>();
unbannableUUIDs = new ArrayList<UUID>();
}
private BanManager()
{
private BanManager() {
throw new AssertionError();
}
public static void load()
{
public static void load() {
ipBans.clear();
uuidBans.clear();
unbannableUUIDs.clear();
@ -39,26 +39,18 @@ public class BanManager
final Configuration config = new Configuration(TotalFreedomMod.plugin, "bans.yml", true);
config.load();
for (String banString : config.getStringList("ips"))
{
try
{
for (String banString : config.getStringList("ips")) {
try {
addIpBan(new Ban(banString, BanType.IP));
}
catch (RuntimeException ex)
{
} catch (RuntimeException ex) {
Log.warning("Could not load IP ban: " + banString);
}
}
for (String banString : config.getStringList("uuids"))
{
try
{
for (String banString : config.getStringList("uuids")) {
try {
addUuidBan(new Ban(banString, BanType.UUID));
}
catch (RuntimeException ex)
{
} catch (RuntimeException ex) {
Log.warning("Could not load UUID ban: " + banString);
}
}
@ -67,37 +59,32 @@ public class BanManager
save();
Log.info("Loaded " + ipBans.size() + " IP bans and " + uuidBans.size() + " UUID bans");
@SuppressWarnings("unchecked")
final TFM_UuidResolver resolver = new TFM_UuidResolver((List<String>) ConfigurationEntry.UNBANNABLE_USERNAMES.getList());
@SuppressWarnings("unchecked") final TFM_UuidResolver resolver = new TFM_UuidResolver(
(List<String>) ConfigurationEntry.UNBANNABLE_USERNAMES.getList());
for (UUID uuid : resolver.call().values())
{
for (UUID uuid : resolver.call().values()) {
unbannableUUIDs.add(uuid);
}
Log.info("Loaded " + unbannableUUIDs.size() + " unbannable UUIDs");
}
public static void save()
{
public static void save() {
final Configuration config = new Configuration(TotalFreedomMod.plugin, "bans.yml", true);
config.load();
final List<String> newIpBans = new ArrayList<String>();
final List<String> newUuidBans = new ArrayList<String>();
for (Ban savedBan : ipBans)
{
if (!savedBan.isExpired())
{
for (Ban savedBan : ipBans) {
if (!savedBan.isExpired()) {
newIpBans.add(savedBan.toString());
}
}
for (Ban savedBan : uuidBans)
{
if (!savedBan.isExpired() && !unbannableUUIDs.contains(UUID.fromString(savedBan.getSubject())))
{
for (Ban savedBan : uuidBans) {
if (!savedBan.isExpired() && !unbannableUUIDs.contains(
UUID.fromString(savedBan.getSubject()))) {
newUuidBans.add(savedBan.toString());
}
}
@ -109,35 +96,27 @@ public class BanManager
config.save();
}
public static List<Ban> getIpBanList()
{
public static List<Ban> getIpBanList() {
return Collections.unmodifiableList(ipBans);
}
public static List<Ban> getUuidBanList()
{
public static List<Ban> getUuidBanList() {
return Collections.unmodifiableList(uuidBans);
}
public static Ban getByIp(String ip)
{
for (Ban ban : ipBans)
{
if (ban.isExpired())
{
public static Ban getByIp(String ip) {
for (Ban ban : ipBans) {
if (ban.isExpired()) {
continue;
}
wildcardCheck:
if (ban.getSubject().contains("*"))
{
if (ban.getSubject().contains("*")) {
final String[] subjectParts = ban.getSubject().split("\\.");
final String[] ipParts = ip.split("\\.");
for (int i = 0; i < 4; i++)
{
if (!(subjectParts[i].equals("*") || subjectParts[i].equals(ipParts[i])))
{
for (int i = 0; i < 4; i++) {
if (!(subjectParts[i].equals("*") || subjectParts[i].equals(ipParts[i]))) {
break wildcardCheck;
}
}
@ -145,22 +124,17 @@ public class BanManager
return ban;
}
if (ban.getSubject().equals(ip))
{
if (ban.getSubject().equals(ip)) {
return ban;
}
}
return null;
}
public static Ban getByUuid(UUID uuid)
{
for (Ban ban : uuidBans)
{
if (ban.getSubject().equalsIgnoreCase(uuid.toString()))
{
if (ban.isExpired())
{
public static Ban getByUuid(UUID uuid) {
for (Ban ban : uuidBans) {
if (ban.getSubject().equalsIgnoreCase(uuid.toString())) {
if (ban.isExpired()) {
continue;
}
@ -170,12 +144,10 @@ public class BanManager
return null;
}
public static void unbanIp(String ip)
{
public static void unbanIp(String ip) {
final Ban ban = getByIp(ip);
if (ban == null)
{
if (ban == null) {
return;
}
@ -183,52 +155,42 @@ public class BanManager
save();
}
public static void unbanUuid(UUID uuid)
{
public static void unbanUuid(UUID uuid) {
final Ban ban = getByUuid(uuid);
if (ban == null)
{
if (ban == null) {
return;
}
removeBan(ban);
}
public static boolean isIpBanned(String ip)
{
public static boolean isIpBanned(String ip) {
return getByIp(ip) != null;
}
public static boolean isUuidBanned(UUID uuid)
{
public static boolean isUuidBanned(UUID uuid) {
return getByUuid(uuid) != null;
}
public static void addUuidBan(Player player)
{
public static void addUuidBan(Player player) {
addUuidBan(new Ban(UUIDManager.getUniqueId(player), player.getName()));
}
public static void addUuidBan(Ban ban)
{
if (!ban.isComplete())
{
public static void addUuidBan(Ban ban) {
if (!ban.isComplete()) {
throw new RuntimeException("Could not add UUID ban, Invalid format!");
}
if (ban.isExpired())
{
if (ban.isExpired()) {
return;
}
if (uuidBans.contains(ban))
{
if (uuidBans.contains(ban)) {
return;
}
if (unbannableUUIDs.contains(UUID.fromString(ban.getSubject())))
{
if (unbannableUUIDs.contains(UUID.fromString(ban.getSubject()))) {
return;
}
@ -236,25 +198,20 @@ public class BanManager
save();
}
public static void addIpBan(Player player)
{
public static void addIpBan(Player player) {
addIpBan(new Ban(Utilities.getIp(player), player.getName()));
}
public static void addIpBan(Ban ban)
{
if (!ban.isComplete())
{
public static void addIpBan(Ban ban) {
if (!ban.isComplete()) {
throw new RuntimeException("Could not add IP ban, Invalid format!");
}
if (ban.isExpired())
{
if (ban.isExpired()) {
return;
}
if (ipBans.contains(ban))
{
if (ipBans.contains(ban)) {
return;
}
@ -262,22 +219,17 @@ public class BanManager
save();
}
public static void removeBan(Ban ban)
{
public static void removeBan(Ban ban) {
final Iterator<Ban> ips = ipBans.iterator();
while (ips.hasNext())
{
if (ips.next().getSubject().equalsIgnoreCase(ban.getSubject()))
{
while (ips.hasNext()) {
if (ips.next().getSubject().equalsIgnoreCase(ban.getSubject())) {
ips.remove();
}
}
final Iterator<Ban> uuids = uuidBans.iterator();
while (uuids.hasNext())
{
if (uuids.next().getSubject().equalsIgnoreCase(ban.getSubject()))
{
while (uuids.hasNext()) {
if (uuids.next().getSubject().equalsIgnoreCase(ban.getSubject())) {
uuids.remove();
}
}
@ -285,14 +237,12 @@ public class BanManager
save();
}
public static void purgeIpBans()
{
public static void purgeIpBans() {
ipBans.clear();
save();
}
public static void purgeUuidBans()
{
public static void purgeUuidBans() {
uuidBans.clear();
save();
}

View file

@ -1,63 +1,55 @@
package me.StevenLawson.TotalFreedomMod.ban;
import me.StevenLawson.TotalFreedomMod.Log;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.config.Configuration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.Log;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.config.Configuration;
public class PermbanList
{
public class PermbanList {
private static final List<String> PERMBANNED_PLAYERS;
private static final List<String> PERMBANNED_IPS;
static
{
static {
PERMBANNED_PLAYERS = new ArrayList<String>();
PERMBANNED_IPS = new ArrayList<String>();
}
private PermbanList()
{
private PermbanList() {
throw new AssertionError();
}
public static List<String> getPermbannedPlayers()
{
public static List<String> getPermbannedPlayers() {
return Collections.unmodifiableList(PERMBANNED_PLAYERS);
}
public static List<String> getPermbannedIps()
{
public static List<String> getPermbannedIps() {
return Collections.unmodifiableList(PERMBANNED_IPS);
}
public static void load()
{
public static void load() {
PERMBANNED_PLAYERS.clear();
PERMBANNED_IPS.clear();
final Configuration config = new Configuration(TotalFreedomMod.plugin, TotalFreedomMod.PERMBAN_FILENAME, true);
final Configuration config = new Configuration(TotalFreedomMod.plugin,
TotalFreedomMod.PERMBAN_FILENAME, true);
config.load();
for (String playername : config.getKeys(false))
{
for (String playername : config.getKeys(false)) {
PERMBANNED_PLAYERS.add(playername.toLowerCase().trim());
List<String> playerIps = config.getStringList(playername);
for (String ip : playerIps)
{
for (String ip : playerIps) {
ip = ip.trim();
if (!PERMBANNED_IPS.contains(ip))
{
if (!PERMBANNED_IPS.contains(ip)) {
PERMBANNED_IPS.add(ip);
}
}
}
Log.info("Loaded " + PERMBANNED_PLAYERS.size() + " permanently banned players and " + PERMBANNED_IPS.size() + " permanently banned IPs.");
Log.info("Loaded " + PERMBANNED_PLAYERS.size() + " permanently banned players and "
+ PERMBANNED_IPS.size() + " permanently banned IPs.");
}
}

View file

@ -8,6 +8,7 @@ import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
public class EssentialsBridge {
private static Essentials essentialsPlugin = null;
private EssentialsBridge() {
@ -15,107 +16,77 @@ public class EssentialsBridge {
}
public static Essentials getEssentialsPlugin() {
if (essentialsPlugin == null)
{
try
{
final Plugin essentials = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
if (essentials != null)
{
if (essentials instanceof Essentials)
{
if (essentialsPlugin == null) {
try {
final Plugin essentials = Bukkit.getServer().getPluginManager()
.getPlugin("Essentials");
if (essentials != null) {
if (essentials instanceof Essentials) {
essentialsPlugin = (Essentials) essentials;
}
}
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.severe(ex);
}
}
return essentialsPlugin;
}
public static User getEssentialsUser(String username)
{
try
{
public static User getEssentialsUser(String username) {
try {
final Essentials essentials = getEssentialsPlugin();
if (essentials != null)
{
if (essentials != null) {
return essentials.getUserMap().getUser(username);
}
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.severe(ex);
}
return null;
}
public static void setNickname(String username, String nickname)
{
try
{
public static void setNickname(String username, String nickname) {
try {
final User user = getEssentialsUser(username);
if (user != null)
{
if (user != null) {
user.setNickname(nickname);
user.setDisplayNick();
}
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.severe(ex);
}
}
public static String getNickname(String username)
{
try
{
public static String getNickname(String username) {
try {
final User user = getEssentialsUser(username);
if (user != null)
{
if (user != null) {
return user.getNickname();
}
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.severe(ex);
}
return null;
}
public static long getLastActivity(String username)
{
try
{
public static long getLastActivity(String username) {
try {
final User user = getEssentialsUser(username);
if (user != null)
{
if (user != null) {
return Utilities.<Long>getField(user, "lastActivity"); // This is weird
}
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.severe(ex);
}
return 0L;
}
public static boolean isEssentialsEnabled()
{
try
{
public static boolean isEssentialsEnabled() {
try {
final Essentials essentials = getEssentialsPlugin();
if (essentials != null)
{
if (essentials != null) {
return essentials.isEnabled();
}
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.severe(ex);
}
return false;

View file

@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class WorldEditBridge {
private static WorldEditPlugin worldEditPlugin = null;
private WorldEditBridge() {
@ -16,96 +17,68 @@ public class WorldEditBridge {
}
private static WorldEditPlugin getWorldEditPlugin() {
if (worldEditPlugin == null)
{
try
{
if (worldEditPlugin == null) {
try {
Plugin we = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
if (we != null)
{
if (we instanceof WorldEditPlugin)
{
if (we != null) {
if (we instanceof WorldEditPlugin) {
worldEditPlugin = (WorldEditPlugin) we;
}
}
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.severe(ex);
}
}
return worldEditPlugin;
}
private static LocalSession getPlayerSession(Player player)
{
try
{
private static LocalSession getPlayerSession(Player player) {
try {
final WorldEditPlugin wep = getWorldEditPlugin();
if (wep != null)
{
if (wep != null) {
return wep.getSession(player);
}
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.severe(ex);
}
return null;
}
private static BukkitPlayer getBukkitPlayer(Player player)
{
try
{
private static BukkitPlayer getBukkitPlayer(Player player) {
try {
final WorldEditPlugin wep = getWorldEditPlugin();
if (wep != null)
{
if (wep != null) {
return wep.wrapPlayer(player);
}
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.severe(ex);
}
return null;
}
public static void undo(Player player, int count)
{
try
{
public static void undo(Player player, int count) {
try {
LocalSession session = getPlayerSession(player);
if (session != null)
{
if (session != null) {
final BukkitPlayer bukkitPlayer = getBukkitPlayer(player);
if (bukkitPlayer != null)
{
for (int i = 0; i < count; i++)
{
if (bukkitPlayer != null) {
for (int i = 0; i < count; i++) {
session.undo(session.getBlockBag(bukkitPlayer), bukkitPlayer);
}
}
}
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.severe(ex);
}
}
public static void setLimit(Player player, int limit)
{
try
{
public static void setLimit(Player player, int limit) {
try {
final LocalSession session = getPlayerSession(player);
if (session != null)
{
if (session != null) {
session.setBlockChangeLimit(limit);
}
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.severe(ex);
}
}

View file

@ -1,5 +1,8 @@
package me.StevenLawson.TotalFreedomMod.command;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import me.StevenLawson.TotalFreedomMod.Log;
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
@ -12,42 +15,33 @@ import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CommandBlocker {
public class CommandBlocker
{
private static final Map<String, CommandBlockerEntry> BLOCKED_COMMANDS;
static
{
static {
BLOCKED_COMMANDS = new HashMap<String, CommandBlockerEntry>();
}
private CommandBlocker()
{
private CommandBlocker() {
throw new AssertionError();
}
public static void load()
{
public static void load() {
BLOCKED_COMMANDS.clear();
final CommandMap commandMap = Utilities.getField(Bukkit.getServer().getPluginManager(), "commandMap");
if (commandMap == null)
{
final CommandMap commandMap = Utilities.getField(Bukkit.getServer().getPluginManager(),
"commandMap");
if (commandMap == null) {
Log.severe("Error loading commandMap.");
return;
}
@SuppressWarnings("unchecked")
List<String> blockedCommands = (List<String>) ConfigurationEntry.BLOCKED_COMMANDS.getList();
for (String rawEntry : blockedCommands)
{
for (String rawEntry : blockedCommands) {
final String[] parts = rawEntry.split(":");
if (parts.length < 3 || parts.length > 4)
{
if (parts.length < 3 || parts.length > 4) {
Log.warning("Invalid command blocker entry: " + rawEntry);
continue;
}
@ -57,45 +51,39 @@ public class CommandBlocker
String commandName = parts[2].toLowerCase().substring(1);
final String message = (parts.length > 3 ? parts[3] : null);
if (rank == null || action == null || commandName == null || commandName.isEmpty())
{
if (rank == null || action == null || commandName == null || commandName.isEmpty()) {
Log.warning("Invalid command blocker entry: " + rawEntry);
continue;
}
final String[] commandParts = commandName.split(" ");
String subCommand = null;
if (commandParts.length > 1)
{
if (commandParts.length > 1) {
commandName = commandParts[0];
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).trim().toLowerCase();
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).trim()
.toLowerCase();
}
final Command command = commandMap.getCommand(commandName);
// Obtain command from alias
if (command == null)
{
if (command == null) {
Log.info("Blocking unknown command: /" + commandName);
}
else
{
} else {
commandName = command.getName().toLowerCase();
}
if (BLOCKED_COMMANDS.containsKey(commandName))
{
if (BLOCKED_COMMANDS.containsKey(commandName)) {
Log.warning("Not blocking: /" + commandName + " - Duplicate entry exists!");
continue;
}
final CommandBlockerEntry blockedCommandEntry = new CommandBlockerEntry(rank, action, commandName, subCommand, message);
final CommandBlockerEntry blockedCommandEntry = new CommandBlockerEntry(rank, action,
commandName, subCommand, message);
BLOCKED_COMMANDS.put(blockedCommandEntry.getCommand(), blockedCommandEntry);
if (command != null)
{
for (String alias : command.getAliases())
{
if (command != null) {
for (String alias : command.getAliases()) {
BLOCKED_COMMANDS.put(alias.toLowerCase(), blockedCommandEntry);
}
}
@ -104,68 +92,56 @@ public class CommandBlocker
Log.info("Loaded " + BLOCKED_COMMANDS.size() + " blocked commands");
}
public static boolean isCommandBlocked(String command, CommandSender sender)
{
public static boolean isCommandBlocked(String command, CommandSender sender) {
return isCommandBlocked(command, sender, false);
}
public static boolean isCommandBlocked(String command, CommandSender sender, boolean doAction)
{
if (command == null || command.isEmpty())
{
public static boolean isCommandBlocked(String command, CommandSender sender, boolean doAction) {
if (command == null || command.isEmpty()) {
return false;
}
command = command.toLowerCase().trim();
if (command.split(" ")[0].contains(":"))
{
if (command.split(" ")[0].contains(":")) {
Utilities.playerMsg(sender, "Plugin-specific commands are disabled.");
return true;
}
if (command.startsWith("/"))
{
if (command.startsWith("/")) {
command = command.substring(1);
}
final String[] commandParts = command.split(" ");
String subCommand = null;
if (commandParts.length > 1)
{
if (commandParts.length > 1) {
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).toLowerCase();
}
final CommandBlockerEntry entry = BLOCKED_COMMANDS.get(commandParts[0]);
if (entry == null)
{
if (entry == null) {
return false;
}
if (entry.getSubCommand() != null)
{
if (subCommand == null || !subCommand.startsWith(entry.getSubCommand()))
{
if (entry.getSubCommand() != null) {
if (subCommand == null || !subCommand.startsWith(entry.getSubCommand())) {
return false;
}
}
if (entry.getRank().hasPermission(sender))
{
if (entry.getRank().hasPermission(sender)) {
return false;
}
if (doAction)
{
if (doAction) {
entry.doActions(sender);
}
return true;
}
public enum CommandBlockerRank
{
public enum CommandBlockerRank {
ANYONE("a", 0),
OP("o", 1),
SUPER("s", 2),
@ -176,40 +152,24 @@ public class CommandBlocker
private final String token;
private final int level;
CommandBlockerRank(String token, int level)
{
CommandBlockerRank(String token, int level) {
this.token = token;
this.level = level;
}
public String getToken()
{
return this.token;
}
public boolean hasPermission(CommandSender sender)
{
return fromSender(sender).level >= this.level;
}
public static CommandBlockerRank fromSender(CommandSender sender)
{
if (!(sender instanceof Player))
{
public static CommandBlockerRank fromSender(CommandSender sender) {
if (!(sender instanceof Player)) {
return TELNET;
}
if (AdminList.isSuperAdmin(sender))
{
if (AdminList.isSeniorAdmin(sender))
{
if (AdminList.isSuperAdmin(sender)) {
if (AdminList.isSeniorAdmin(sender)) {
return SENIOR;
}
return SUPER;
}
if (sender.isOp())
{
if (sender.isOp()) {
return OP;
}
@ -217,102 +177,97 @@ public class CommandBlocker
}
public static CommandBlockerRank fromToken(String token)
{
for (CommandBlockerRank rank : CommandBlockerRank.values())
{
if (rank.getToken().equalsIgnoreCase(token))
{
public static CommandBlockerRank fromToken(String token) {
for (CommandBlockerRank rank : CommandBlockerRank.values()) {
if (rank.getToken().equalsIgnoreCase(token)) {
return rank;
}
}
return ANYONE;
}
public String getToken() {
return this.token;
}
public enum CommandBlockerAction
{
public boolean hasPermission(CommandSender sender) {
return fromSender(sender).level >= this.level;
}
}
public enum CommandBlockerAction {
BLOCK("b"),
BLOCK_AND_EJECT("a"),
BLOCK_UNKNOWN("u");
private final String token;
CommandBlockerAction(String token)
{
CommandBlockerAction(String token) {
this.token = token;
}
public String getToken()
{
return this.token;
}
public static CommandBlockerAction fromToken(String token)
{
for (CommandBlockerAction action : CommandBlockerAction.values())
{
if (action.getToken().equalsIgnoreCase(token))
{
public static CommandBlockerAction fromToken(String token) {
for (CommandBlockerAction action : CommandBlockerAction.values()) {
if (action.getToken().equalsIgnoreCase(token)) {
return action;
}
}
return null;
}
public String getToken() {
return this.token;
}
}
public static class CommandBlockerEntry
{
public static class CommandBlockerEntry {
private final CommandBlockerRank rank;
private final CommandBlockerAction action;
private final String command;
private final String subCommand;
private final String message;
private CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String message)
{
private CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action,
String command, String message) {
this(rank, action, command, null, message);
}
private CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action, String command, String subCommand, String message)
{
private CommandBlockerEntry(CommandBlockerRank rank, CommandBlockerAction action,
String command, String subCommand, String message) {
this.rank = rank;
this.action = action;
this.command = command;
this.subCommand = (subCommand == null ? null : subCommand.toLowerCase().trim());
this.message = (message == null || message.equals("_") ? "That command is blocked." : message);
this.message = (message == null || message.equals("_") ? "That command is blocked."
: message);
}
public CommandBlockerAction getAction()
{
public CommandBlockerAction getAction() {
return this.action;
}
public String getCommand()
{
public String getCommand() {
return this.command;
}
public String getSubCommand()
{
public String getSubCommand() {
return this.subCommand;
}
public String getMessage()
{
public String getMessage() {
return this.message;
}
public CommandBlockerRank getRank()
{
public CommandBlockerRank getRank() {
return this.rank;
}
private void doActions(CommandSender sender)
{
if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player)
{
private void doActions(CommandSender sender) {
if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player) {
Utilities.autoEject((Player) sender, "You used a prohibited command: " + command);
Utilities.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED);
Utilities.bcastMsg(
sender.getName() + " was automatically kicked for using harmful commands.",
ChatColor.RED);
return;
}

View file

@ -1,7 +1,8 @@
package me.StevenLawson.TotalFreedomMod.commands;
public enum AdminLevel {
ALL("All Player Commands"), OP("OP Commands"), SUPER("SuperAdmin Commands"), SENIOR("Senior Admin Commands");
ALL("All Player Commands"), OP("OP Commands"), SUPER("SuperAdmin Commands"), SENIOR(
"Senior Admin Commands");
//
private final String friendlyName;
@ -9,8 +10,7 @@ public enum AdminLevel {
this.friendlyName = friendlyName;
}
public String getFriendlyName()
{
public String getFriendlyName() {
return friendlyName;
}
}

View file

@ -2,8 +2,8 @@ package me.StevenLawson.TotalFreedomMod.commands;
// This is only here because of Command_tfm
public @interface CommandParameters
{
public @interface CommandParameters {
String description();
String usage();

View file

@ -4,8 +4,8 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface CommandPermissions
{
public @interface CommandPermissions {
AdminLevel level();
SourceType source();

View file

@ -9,8 +9,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true)
public class Command_adminmode extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
return false;
}
@ -19,15 +21,11 @@ public class Command_adminmode extends FreedomCommand {
ConfigurationEntry.ADMIN_ONLY_MODE.setBoolean(false);
Utilities.adminAction(sender.getName(), "Deactivating adminmode.", true);
return true;
}
else if (args[0].equalsIgnoreCase("on"))
{
} else if (args[0].equalsIgnoreCase("on")) {
ConfigurationEntry.ADMIN_ONLY_MODE.setBoolean(true);
Utilities.adminAction(sender.getName(), "Activating adminmode.", true);
for (Player player : server.getOnlinePlayers())
{
if (!AdminList.isSuperAdmin(player))
{
for (Player player : server.getOnlinePlayers()) {
if (!AdminList.isSuperAdmin(player)) {
player.kickPlayer("Server is now in adminmode.");
}
}

View file

@ -10,212 +10,164 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
public class Command_adminworld extends FreedomCommand {
private enum CommandMode {
TELEPORT, GUEST, TIME, WEATHER
}
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
CommandMode commandMode = null;
if (args.length == 0) {
commandMode = CommandMode.TELEPORT;
} else if (args.length >= 2) {
if ("guest".equalsIgnoreCase(args[0]))
{
if ("guest".equalsIgnoreCase(args[0])) {
commandMode = CommandMode.GUEST;
}
else if ("time".equalsIgnoreCase(args[0]))
{
} else if ("time".equalsIgnoreCase(args[0])) {
commandMode = CommandMode.TIME;
}
else if ("weather".equalsIgnoreCase(args[0]))
{
} else if ("weather".equalsIgnoreCase(args[0])) {
commandMode = CommandMode.WEATHER;
}
}
if (commandMode == null)
{
if (commandMode == null) {
return false;
}
try
{
switch (commandMode)
{
case TELEPORT:
{
if (!(sender instanceof Player) || sender_p == null)
{
try {
switch (commandMode) {
case TELEPORT: {
if (!(sender instanceof Player) || sender_p == null) {
return true;
}
World adminWorld = null;
try
{
try {
adminWorld = AdminWorld.getInstance().getWorld();
}
catch (Exception ex)
{
} catch (Exception ex) {
}
if (adminWorld == null || sender_p.getWorld() == adminWorld)
{
if (adminWorld == null || sender_p.getWorld() == adminWorld) {
playerMsg(sender, "Going to the main world.");
sender_p.teleport(server.getWorlds().get(0).getSpawnLocation());
}
else
{
if (AdminWorld.getInstance().canAccessWorld(sender_p))
{
} else {
if (AdminWorld.getInstance().canAccessWorld(sender_p)) {
playerMsg(sender, "Going to the AdminWorld.");
AdminWorld.getInstance().sendToWorld(sender_p);
}
else
{
playerMsg(sender, "You don't have permission to access the AdminWorld.");
} else {
playerMsg(sender,
"You don't have permission to access the AdminWorld.");
}
}
break;
}
case GUEST:
{
if (args.length == 2)
{
if ("list".equalsIgnoreCase(args[1]))
{
playerMsg(sender, "AdminWorld guest list: " + AdminWorld.getInstance().guestListToString());
}
else if ("purge".equalsIgnoreCase(args[1]))
{
case GUEST: {
if (args.length == 2) {
if ("list".equalsIgnoreCase(args[1])) {
playerMsg(sender, "AdminWorld guest list: " + AdminWorld.getInstance()
.guestListToString());
} else if ("purge".equalsIgnoreCase(args[1])) {
assertCommandPerms(sender, sender_p);
AdminWorld.getInstance().purgeGuestList();
Utilities.adminAction(sender.getName(), "AdminWorld guest list purged.", false);
}
else
{
Utilities.adminAction(sender.getName(), "AdminWorld guest list purged.",
false);
} else {
return false;
}
}
else if (args.length == 3)
{
} else if (args.length == 3) {
assertCommandPerms(sender, sender_p);
if ("add".equalsIgnoreCase(args[1]))
{
if ("add".equalsIgnoreCase(args[1])) {
final Player player = getPlayer(args[2]);
if (player == null)
{
if (player == null) {
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
if (AdminWorld.getInstance().addGuest(player, sender_p))
{
Utilities.adminAction(sender.getName(), "AdminWorld guest added: " + player.getName(), false);
}
else
{
if (AdminWorld.getInstance().addGuest(player, sender_p)) {
Utilities.adminAction(sender.getName(),
"AdminWorld guest added: " + player.getName(), false);
} else {
playerMsg(sender, "Could not add player to guest list.");
}
}
else if ("remove".equals(args[1]))
{
} else if ("remove".equals(args[1])) {
final Player player = AdminWorld.getInstance().removeGuest(args[2]);
if (player != null)
{
Utilities.adminAction(sender.getName(), "AdminWorld guest removed: " + player.getName(), false);
}
else
{
if (player != null) {
Utilities.adminAction(sender.getName(),
"AdminWorld guest removed: " + player.getName(), false);
} else {
playerMsg(sender, "Can't find guest entry for: " + args[2]);
}
}
else
{
} else {
return false;
}
}
break;
}
case TIME:
{
case TIME: {
assertCommandPerms(sender, sender_p);
if (args.length == 2)
{
if (args.length == 2) {
AdminWorld.TimeOfDay timeOfDay = AdminWorld.TimeOfDay.getByAlias(args[1]);
if (timeOfDay != null)
{
if (timeOfDay != null) {
AdminWorld.getInstance().setTimeOfDay(timeOfDay);
playerMsg(sender, "AdminWorld time set to: " + timeOfDay.name());
} else {
playerMsg(sender,
"Invalid time of day. Can be: sunrise, noon, sunset, midnight");
}
else
{
playerMsg(sender, "Invalid time of day. Can be: sunrise, noon, sunset, midnight");
}
}
else
{
} else {
return false;
}
break;
}
case WEATHER:
{
case WEATHER: {
assertCommandPerms(sender, sender_p);
if (args.length == 2)
{
AdminWorld.WeatherMode weatherMode = AdminWorld.WeatherMode.getByAlias(args[1]);
if (weatherMode != null)
{
if (args.length == 2) {
AdminWorld.WeatherMode weatherMode = AdminWorld.WeatherMode.getByAlias(
args[1]);
if (weatherMode != null) {
AdminWorld.getInstance().setWeatherMode(weatherMode);
playerMsg(sender, "AdminWorld weather set to: " + weatherMode.name());
}
else
{
} else {
playerMsg(sender, "Invalid weather mode. Can be: off, rain, storm");
}
}
else
{
} else {
return false;
}
break;
}
default:
{
default: {
return false;
}
}
}
catch (PermissionDeniedException ex)
{
} catch (PermissionDeniedException ex) {
sender.sendMessage(ex.getMessage());
}
return true;
}
private void assertCommandPerms(CommandSender sender, org.bukkit.entity.Player sender_p) throws PermissionDeniedException {
private void assertCommandPerms(CommandSender sender, org.bukkit.entity.Player sender_p)
throws PermissionDeniedException {
if (!(sender instanceof Player) || sender_p == null || !AdminList.isSuperAdmin(sender)) {
throw new PermissionDeniedException(FreedomCommand.MSG_NO_PERMS);
}
}
private class PermissionDeniedException extends Exception
{
private enum CommandMode {
TELEPORT, GUEST, TIME, WEATHER
}
private class PermissionDeniedException extends Exception {
private static final long serialVersionUID = 1L;
private PermissionDeniedException(String string)
{
private PermissionDeniedException(String string) {
super(string);
}
}

View file

@ -9,8 +9,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_blockcmd extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
return false;
}
@ -18,11 +20,9 @@ public class Command_blockcmd extends FreedomCommand {
if (args[0].equalsIgnoreCase("purge")) {
Utilities.adminAction(sender.getName(), "Unblocking commands for all players", true);
int counter = 0;
for (Player player : server.getOnlinePlayers())
{
for (Player player : server.getOnlinePlayers()) {
PlayerData playerdata = PlayerData.getPlayerData(player);
if (playerdata.allCommandsBlocked())
{
if (playerdata.allCommandsBlocked()) {
counter += 1;
playerdata.setCommandsBlocked(false);
}
@ -33,15 +33,14 @@ public class Command_blockcmd extends FreedomCommand {
final Player player = getPlayer(args[0]);
if (player == null)
{
if (player == null) {
playerMsg(sender, FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
if (AdminList.isSuperAdmin(player))
{
playerMsg(sender, player.getName() + " is a Superadmin, and cannot have their commands blocked.");
if (AdminList.isSuperAdmin(player)) {
playerMsg(sender,
player.getName() + " is a Superadmin, and cannot have their commands blocked.");
return true;
}
@ -49,7 +48,9 @@ public class Command_blockcmd extends FreedomCommand {
playerdata.setCommandsBlocked(!playerdata.allCommandsBlocked());
Utilities.adminAction(sender.getName(), (playerdata.allCommandsBlocked() ? "B" : "Unb") + "locking all commands for " + player.getName(), true);
Utilities.adminAction(sender.getName(),
(playerdata.allCommandsBlocked() ? "B" : "Unb") + "locking all commands for "
+ player.getName(), true);
playerMsg(sender, (playerdata.allCommandsBlocked() ? "B" : "Unb") + "locked all commands.");
return true;

View file

@ -11,8 +11,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_cage extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0) {
return false;
}
@ -26,13 +28,10 @@ public class Command_cage extends FreedomCommand {
playerdata.clearHistory();
return true;
}
else if ("purge".equals(args[0]))
{
} else if ("purge".equals(args[0])) {
Utilities.adminAction(sender.getName(), "Uncaging all players", true);
for (Player player : server.getOnlinePlayers())
{
for (Player player : server.getOnlinePlayers()) {
PlayerData playerdata = PlayerData.getPlayerData(player);
playerdata.setCaged(false);
playerdata.regenerateHistory();
@ -44,8 +43,7 @@ public class Command_cage extends FreedomCommand {
final Player player = getPlayer(args[0]);
if (player == null)
{
if (player == null) {
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
@ -55,10 +53,8 @@ public class Command_cage extends FreedomCommand {
Material outerMaterial = Material.GLASS;
Material innerMaterial = Material.AIR;
if (args.length >= 2)
{
if ("off".equals(args[1]))
{
if (args.length >= 2) {
if ("off".equals(args[1])) {
Utilities.adminAction(sender.getName(), "Uncaging " + player.getName(), true);
playerdata.setCaged(false);
@ -66,28 +62,19 @@ public class Command_cage extends FreedomCommand {
playerdata.clearHistory();
return true;
}
else
{
if ("darth".equalsIgnoreCase(args[1]))
{
} else {
if ("darth".equalsIgnoreCase(args[1])) {
outerMaterial = Material.SKULL;
}
else if (Material.matchMaterial(args[1]) != null)
{
} else if (Material.matchMaterial(args[1]) != null) {
outerMaterial = Material.matchMaterial(args[1]);
}
}
}
if (args.length >= 3)
{
if (args[2].equalsIgnoreCase("water"))
{
if (args.length >= 3) {
if (args[2].equalsIgnoreCase("water")) {
innerMaterial = Material.STATIONARY_WATER;
}
else if (args[2].equalsIgnoreCase("lava"))
{
} else if (args[2].equalsIgnoreCase("lava")) {
innerMaterial = Material.STATIONARY_LAVA;
}
}
@ -102,13 +89,11 @@ public class Command_cage extends FreedomCommand {
player.setGameMode(GameMode.SURVIVAL);
if (outerMaterial != Material.SKULL)
{
if (outerMaterial != Material.SKULL) {
Utilities.adminAction(sender.getName(), "Caging " + player.getName(), true);
}
else
{
Utilities.adminAction(sender.getName(), "Caging " + player.getName() + " in PURE_DARTH", true);
} else {
Utilities.adminAction(sender.getName(), "Caging " + player.getName() + " in PURE_DARTH",
true);
}
return true;

View file

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.Random;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.bukkit.Achievement;
import org.bukkit.ChatColor;
@ -10,32 +11,33 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Random;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_cake extends FreedomCommand {
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.";
private final Random random = new Random();
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
final StringBuilder output = new StringBuilder();
final String[] words = CAKE_LYRICS.split(" ");
for (final String word : words) {
output.append(ChatColor.COLOR_CHAR).append(Integer.toHexString(1 + random.nextInt(14))).append(word).append(" ");
output.append(ChatColor.COLOR_CHAR).append(Integer.toHexString(1 + random.nextInt(14)))
.append(word).append(" ");
}
final ItemStack heldItem = new ItemStack(Material.CAKE);
final ItemMeta heldItemMeta = heldItem.getItemMeta();
heldItemMeta.setDisplayName((new StringBuilder()).append(ChatColor.WHITE).append("The ").append(ChatColor.DARK_GRAY).append("Lie").toString());
heldItemMeta.setDisplayName(
(new StringBuilder()).append(ChatColor.WHITE).append("The ").append(ChatColor.DARK_GRAY)
.append("Lie").toString());
heldItem.setItemMeta(heldItemMeta);
for (final Player player : server.getOnlinePlayers())
{
for (final Player player : server.getOnlinePlayers()) {
final int firstEmpty = player.getInventory().firstEmpty();
if (firstEmpty >= 0)
{
if (firstEmpty >= 0) {
player.getInventory().setItem(firstEmpty, heldItem);
}

View file

@ -8,8 +8,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
public class Command_cartsit extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Player targetPlayer = sender_p;
if (args.length == 1) {
@ -22,51 +24,38 @@ public class Command_cartsit extends FreedomCommand {
}
}
if (senderIsConsole)
{
if (targetPlayer == null)
{
sender.sendMessage("When used from the console, you must define a target player: /cartsit <player>");
if (senderIsConsole) {
if (targetPlayer == null) {
sender.sendMessage(
"When used from the console, you must define a target player: /cartsit <player>");
return true;
}
}
else if (targetPlayer != sender_p && !AdminList.isSuperAdmin(sender))
{
} else if (targetPlayer != sender_p && !AdminList.isSuperAdmin(sender)) {
sender.sendMessage("Only superadmins can select another player as a /cartsit target.");
return true;
}
if (targetPlayer.isInsideVehicle())
{
if (targetPlayer.isInsideVehicle()) {
targetPlayer.getVehicle().eject();
}
else
{
} else {
Minecart nearest_cart = null;
for (Minecart cart : targetPlayer.getWorld().getEntitiesByClass(Minecart.class))
{
if (cart.isEmpty())
{
if (nearest_cart == null)
{
for (Minecart cart : targetPlayer.getWorld().getEntitiesByClass(Minecart.class)) {
if (cart.isEmpty()) {
if (nearest_cart == null) {
nearest_cart = cart;
}
else
{
if (cart.getLocation().distanceSquared(targetPlayer.getLocation()) < nearest_cart.getLocation().distanceSquared(targetPlayer.getLocation()))
{
} else {
if (cart.getLocation().distanceSquared(targetPlayer.getLocation())
< nearest_cart.getLocation()
.distanceSquared(targetPlayer.getLocation())) {
nearest_cart = cart;
}
}
}
}
if (nearest_cart != null)
{
if (nearest_cart != null) {
nearest_cart.setPassenger(targetPlayer);
}
else
{
} else {
sender.sendMessage("There are no empty minecarts in the target world.");
}
}

View file

@ -1,5 +1,8 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.Log;
import me.StevenLawson.TotalFreedomMod.command.CommandBlocker;
import me.StevenLawson.TotalFreedomMod.util.DeprecationUtil;
@ -13,14 +16,12 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
public class Command_cbtool extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 1) {
return false;
}
@ -31,107 +32,84 @@ public class Command_cbtool extends FreedomCommand {
return true;
}
try
{
try {
final StringBuffer generatedCommand = new StringBuffer();
final Matcher matcher = Pattern.compile("\\[(.+?)\\]").matcher(StringUtils.join(args, " ").trim());
while (matcher.find())
{
final Matcher matcher = Pattern.compile("\\[(.+?)\\]")
.matcher(StringUtils.join(args, " ").trim());
while (matcher.find()) {
matcher.appendReplacement(generatedCommand, processSubCommand(matcher.group(1)));
}
matcher.appendTail(generatedCommand);
if (CommandBlocker.isCommandBlocked(generatedCommand.toString(), sender, false))
{
if (CommandBlocker.isCommandBlocked(generatedCommand.toString(), sender, false)) {
return true;
}
server.dispatchCommand(sender, generatedCommand.toString());
}
catch (SubCommandFailureException ex)
{
}
catch (Exception ex)
{
} catch (SubCommandFailureException ex) {
} catch (Exception ex) {
Log.severe(ex);
}
return true;
}
private String processSubCommand(final String subcommand) throws SubCommandFailureException
{
private String processSubCommand(final String subcommand) throws SubCommandFailureException {
final String[] args = StringUtils.split(subcommand, " ");
if (args.length == 1)
{
if (args.length == 1) {
throw new SubCommandFailureException("Invalid subcommand name.");
}
return SubCommand.getByName(args[0]).getExecutable().execute(ArrayUtils.remove(args, 0));
}
private enum SubCommand
{
PLAYER_DETECT("playerdetect", new SubCommandExecutable()
{
private enum SubCommand {
PLAYER_DETECT("playerdetect", new SubCommandExecutable() {
@Override
public String execute(String[] args) throws SubCommandFailureException
{
if (args.length != 5)
{
public String execute(String[] args) throws SubCommandFailureException {
if (args.length != 5) {
throw new SubCommandFailureException("Invalid # of arguments.");
}
double x, y, z;
try
{
try {
x = Double.parseDouble(args[0].trim());
y = Double.parseDouble(args[1].trim());
z = Double.parseDouble(args[2].trim());
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
throw new SubCommandFailureException("Invalid coordinates.");
}
World world = null;
final String needleWorldName = args[3].trim();
final List<World> worlds = Bukkit.getWorlds();
for (final World testWorld : worlds)
{
if (testWorld.getName().trim().equalsIgnoreCase(needleWorldName))
{
for (final World testWorld : worlds) {
if (testWorld.getName().trim().equalsIgnoreCase(needleWorldName)) {
world = testWorld;
break;
}
}
if (world == null)
{
if (world == null) {
throw new SubCommandFailureException("Invalid world name.");
}
final Location testLocation = new Location(world, x, y, z);
double radius;
try
{
try {
radius = Double.parseDouble(args[4].trim());
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
throw new SubCommandFailureException("Invalid radius.");
}
final double radiusSq = radius * radius;
final List<Player> worldPlayers = testLocation.getWorld().getPlayers();
for (final Player testPlayer : worldPlayers)
{
if (testPlayer.getLocation().distanceSquared(testLocation) < radiusSq)
{
for (final Player testPlayer : worldPlayers) {
if (testPlayer.getLocation().distanceSquared(testLocation) < radiusSq) {
return testPlayer.getName();
}
}
@ -139,17 +117,12 @@ public class Command_cbtool extends FreedomCommand {
throw new SubCommandFailureException("No player found in range.");
}
}),
PLAYER_DETECT_BOOLEAN("playerdetectboolean", new SubCommandExecutable()
{
PLAYER_DETECT_BOOLEAN("playerdetectboolean", new SubCommandExecutable() {
@Override
public String execute(String[] args) throws SubCommandFailureException
{
try
{
public String execute(String[] args) throws SubCommandFailureException {
try {
PLAYER_DETECT.getExecutable().execute(args);
}
catch (SubCommandFailureException ex)
{
} catch (SubCommandFailureException ex) {
return "0";
}
@ -160,49 +133,41 @@ public class Command_cbtool extends FreedomCommand {
private final String name;
private final SubCommandExecutable executable;
SubCommand(String subCommandName, SubCommandExecutable subCommandImpl)
{
SubCommand(String subCommandName, SubCommandExecutable subCommandImpl) {
this.name = subCommandName;
this.executable = subCommandImpl;
}
public SubCommandExecutable getExecutable()
{
return executable;
}
public String getName()
{
return name;
}
public static SubCommand getByName(String needle) throws SubCommandFailureException
{
public static SubCommand getByName(String needle) throws SubCommandFailureException {
needle = needle.trim();
for (SubCommand subCommand : values())
{
if (subCommand.getName().equalsIgnoreCase(needle))
{
for (SubCommand subCommand : values()) {
if (subCommand.getName().equalsIgnoreCase(needle)) {
return subCommand;
}
}
throw new SubCommandFailureException("Invalid subcommand name.");
}
public SubCommandExecutable getExecutable() {
return executable;
}
private interface SubCommandExecutable
{
public String getName() {
return name;
}
}
private interface SubCommandExecutable {
String execute(String[] args) throws SubCommandFailureException;
}
private static class SubCommandFailureException extends Exception
{
public SubCommandFailureException()
{
private static class SubCommandFailureException extends Exception {
public SubCommandFailureException() {
}
public SubCommandFailureException(String message)
{
public SubCommandFailureException(String message) {
super(message);
}
}

View file

@ -1,21 +1,22 @@
package me.StevenLawson.TotalFreedomMod.commands;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
public class Command_cmdlist extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
List<String> commands = new ArrayList<String>();
for (Plugin targetPlugin : server.getPluginManager().getPlugins()) {
@ -23,17 +24,13 @@ public class Command_cmdlist extends FreedomCommand {
PluginDescriptionFile desc = targetPlugin.getDescription();
Map<String, Map<String, Object>> map = desc.getCommands();
if (map != null)
{
for (Entry<String, Map<String, Object>> entry : map.entrySet())
{
if (map != null) {
for (Entry<String, Map<String, Object>> entry : map.entrySet()) {
String command_name = entry.getKey();
commands.add(command_name);
}
}
}
catch (Throwable ex)
{
} catch (Throwable ex) {
}
}

View file

@ -6,8 +6,10 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
public class Command_cmdspy extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
PlayerData playerdata = PlayerData.getPlayerData(sender_p);
playerdata.setCommandSpy(!playerdata.cmdspyEnabled());

View file

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.Iterator;
import java.util.Map;
import me.StevenLawson.TotalFreedomMod.bridge.EssentialsBridge;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.apache.commons.lang3.StringUtils;
@ -7,42 +9,42 @@ import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.Iterator;
import java.util.Map;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
public class Command_colorme extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
return false;
}
if ("list".equalsIgnoreCase(args[0])) {
playerMsg(sender, "Colors: " + StringUtils.join(Utilities.CHAT_COLOR_NAMES.keySet(), ", "));
playerMsg(sender,
"Colors: " + StringUtils.join(Utilities.CHAT_COLOR_NAMES.keySet(), ", "));
return true;
}
final String needle = args[0].trim().toLowerCase();
ChatColor color = null;
final Iterator<Map.Entry<String, ChatColor>> it = Utilities.CHAT_COLOR_NAMES.entrySet().iterator();
while (it.hasNext())
{
final Iterator<Map.Entry<String, ChatColor>> it = Utilities.CHAT_COLOR_NAMES.entrySet()
.iterator();
while (it.hasNext()) {
final Map.Entry<String, ChatColor> entry = it.next();
if (entry.getKey().contains(needle))
{
if (entry.getKey().contains(needle)) {
color = entry.getValue();
break;
}
}
if (color == null)
{
playerMsg(sender, "Invalid color: " + needle + " - Use \"/colorme list\" to list colors.");
if (color == null) {
playerMsg(sender,
"Invalid color: " + needle + " - Use \"/colorme list\" to list colors.");
return true;
}
final String newNick = color + ChatColor.stripColor(sender_p.getDisplayName()).trim() + ChatColor.WHITE;
final String newNick =
color + ChatColor.stripColor(sender_p.getDisplayName()).trim() + ChatColor.WHITE;
EssentialsBridge.setNickname(sender.getName(), newNick);

View file

@ -9,49 +9,45 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
public class Command_creative extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (senderIsConsole) {
if (args.length == 0) {
sender.sendMessage("When used from the console, you must define a target user to change gamemode on.");
sender.sendMessage(
"When used from the console, you must define a target user to change gamemode on.");
return true;
}
}
Player player;
if (args.length == 0)
{
if (args.length == 0) {
player = sender_p;
}
else
{
if (args[0].equalsIgnoreCase("-a"))
{
if (!AdminList.isSuperAdmin(sender))
{
} else {
if (args[0].equalsIgnoreCase("-a")) {
if (!AdminList.isSuperAdmin(sender)) {
sender.sendMessage(FreedomCommand.MSG_NO_PERMS);
return true;
}
for (Player targetPlayer : server.getOnlinePlayers())
{
for (Player targetPlayer : server.getOnlinePlayers()) {
targetPlayer.setGameMode(GameMode.CREATIVE);
}
Utilities.adminAction(sender.getName(), "Changing everyone's gamemode to creative", false);
Utilities.adminAction(sender.getName(), "Changing everyone's gamemode to creative",
false);
return true;
}
if (!(senderIsConsole || AdminList.isSuperAdmin(sender)))
{
if (!(senderIsConsole || AdminList.isSuperAdmin(sender))) {
playerMsg(sender, "Only superadmins can change other user's gamemode.");
return true;
}
player = getPlayer(args[0]);
if (player == null)
{
if (player == null) {
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}

View file

@ -7,10 +7,13 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_CONSOLE)
public class Command_csay extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length > 0) {
Utilities.bcastMsg(String.format("§7[CONSOLE] §f<§c%s§f> %s", sender.getName(), StringUtils.join(args, " ")));
Utilities.bcastMsg(String.format("§7[CONSOLE] §f<§c%s§f> %s", sender.getName(),
StringUtils.join(args, " ")));
}
return true;
}

View file

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.Random;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.command.Command;
@ -7,24 +8,34 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Random;
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.BOTH, blockHostConsole = true)
public class Command_deafen extends FreedomCommand {
private static final Random random = new Random();
public static final double STEPS = 10.0;
private static final Random random = new Random();
private static Location randomOffset(Location a, double magnitude) {
return a.clone()
.add(randomDoubleRange(-1.0, 1.0) * magnitude, randomDoubleRange(-1.0, 1.0) * magnitude,
randomDoubleRange(-1.0, 1.0) * magnitude);
}
private static Double randomDoubleRange(double min, double max) {
return min + (random.nextDouble() * ((max - min) + 1.0));
}
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
for (final Player player : server.getOnlinePlayers()) {
for (double percent = 0.0; percent <= 1.0; percent += (1.0 / STEPS)) {
final float pitch = (float) (percent * 2.0);
new BukkitRunnable() {
@Override
public void run()
{
player.playSound(randomOffset(player.getLocation(), 5.0), Sound.values()[random.nextInt(Sound.values().length)], 100.0f, pitch);
public void run() {
player.playSound(randomOffset(player.getLocation(), 5.0),
Sound.values()[random.nextInt(Sound.values().length)], 100.0f, pitch);
}
}.runTaskLater(plugin, Math.round(20.0 * percent * 2.0));
}
@ -32,14 +43,4 @@ public class Command_deafen extends FreedomCommand {
return true;
}
private static Location randomOffset(Location a, double magnitude)
{
return a.clone().add(randomDoubleRange(-1.0, 1.0) * magnitude, randomDoubleRange(-1.0, 1.0) * magnitude, randomDoubleRange(-1.0, 1.0) * magnitude);
}
private static Double randomDoubleRange(double min, double max)
{
return min + (random.nextDouble() * ((max - min) + 1.0));
}
}

View file

@ -1,16 +1,62 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.lang.reflect.Field;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.lang.reflect.Field;
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE)
public class Command_debug extends FreedomCommand {
public static void setStaticValue(final String className, final String fieldName,
final String newValueString) throws Exception {
Class<?> forName = Class.forName(className);
if (forName != null) {
final Field field = forName.getDeclaredField(fieldName);
if (field != null) {
Object newValue;
Class<?> type = field.getType();
if (type.isPrimitive()) {
if (type.getName().equals("int")) {
newValue = Integer.parseInt(newValueString);
} else if (type.getName().equals("double")) {
newValue = Double.parseDouble(newValueString);
} else if (type.getName().equals("boolean")) {
newValue = Boolean.parseBoolean(newValueString);
} else {
throw new Exception("Unknown primitive field type.");
}
} else {
if (type.isAssignableFrom(Integer.class)) {
newValue = new Integer(newValueString);
} else if (type.isAssignableFrom(Double.class)) {
newValue = new Double(newValueString);
} else if (type.isAssignableFrom(Boolean.class)) {
newValue = Boolean.valueOf(newValueString);
} else if (type.isAssignableFrom(String.class)) {
newValue = newValueString;
} else {
throw new Exception("Unknown complex field type.");
}
}
field.setAccessible(true);
final Object oldValue = field.get(Class.forName(className));
if (oldValue != null) {
field.set(oldValue, newValue);
}
field.setAccessible(false);
}
}
}
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 3) {
return false;
}
@ -20,87 +66,17 @@ public class Command_debug extends FreedomCommand {
String fieldName = args[1];
String newValue = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ");
if (className.equalsIgnoreCase("_"))
{
if (className.equalsIgnoreCase("_")) {
className = "me.StevenLawson.TotalFreedomMod.TotalFreedomMod";
}
setStaticValue(className, fieldName, newValue);
sender.sendMessage("Debug: OK");
}
catch (Exception ex)
{
} catch (Exception ex) {
sender.sendMessage(ex.getMessage());
}
return true;
}
public static void setStaticValue(final String className, final String fieldName, final String newValueString) throws Exception
{
Class<?> forName = Class.forName(className);
if (forName != null)
{
final Field field = forName.getDeclaredField(fieldName);
if (field != null)
{
Object newValue;
Class<?> type = field.getType();
if (type.isPrimitive())
{
if (type.getName().equals("int"))
{
newValue = Integer.parseInt(newValueString);
}
else if (type.getName().equals("double"))
{
newValue = Double.parseDouble(newValueString);
}
else if (type.getName().equals("boolean"))
{
newValue = Boolean.parseBoolean(newValueString);
}
else
{
throw new Exception("Unknown primitive field type.");
}
}
else
{
if (type.isAssignableFrom(Integer.class))
{
newValue = new Integer(newValueString);
}
else if (type.isAssignableFrom(Double.class))
{
newValue = new Double(newValueString);
}
else if (type.isAssignableFrom(Boolean.class))
{
newValue = Boolean.valueOf(newValueString);
}
else if (type.isAssignableFrom(String.class))
{
newValue = newValueString;
}
else
{
throw new Exception("Unknown complex field type.");
}
}
field.setAccessible(true);
final Object oldValue = field.get(Class.forName(className));
if (oldValue != null)
{
field.set(oldValue, newValue);
}
field.setAccessible(false);
}
}
}
}

View file

@ -8,8 +8,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_denick extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Utilities.adminAction(sender.getName(), "Removing all nicknames", false);
for (Player player : server.getOnlinePlayers()) {

View file

@ -9,8 +9,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_deop extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
return false;
}
@ -18,15 +20,13 @@ public class Command_deop extends FreedomCommand {
OfflinePlayer player = null;
for (Player onlinePlayer : server.getOnlinePlayers()) {
if (args[0].equalsIgnoreCase(onlinePlayer.getName()))
{
if (args[0].equalsIgnoreCase(onlinePlayer.getName())) {
player = onlinePlayer;
}
}
// if the player is not online
if (player == null)
{
if (player == null) {
player = DeprecationUtil.getOfflinePlayer(server, args[0]);
}

View file

@ -7,8 +7,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_deopall extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Utilities.adminAction(sender.getName(), "De-opping all players on the server", true);
for (Player player : server.getOnlinePlayers()) {

View file

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.util.DeprecationUtil;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.apache.commons.lang3.StringUtils;
@ -12,20 +14,26 @@ import org.bukkit.command.CommandSender;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
public class Command_dispfill extends FreedomCommand {
private static void setDispenserContents(final Block targetBlock, final ItemStack[] items) {
if (targetBlock.getType() == Material.DISPENSER) {
final Inventory dispenserInv = ((Dispenser) targetBlock.getState()).getInventory();
dispenserInv.clear();
dispenserInv.addItem(items);
}
}
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 2) {
int radius;
try {
radius = Math.max(5, Math.min(25, Integer.parseInt(args[0])));
} catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
sender.sendMessage("Invalid radius.");
return true;
}
@ -33,26 +41,18 @@ public class Command_dispfill extends FreedomCommand {
final List<ItemStack> items = new ArrayList<ItemStack>();
final String[] itemsRaw = StringUtils.split(args[1], ",");
for (final String searchItem : itemsRaw)
{
for (final String searchItem : itemsRaw) {
Material material = Material.matchMaterial(searchItem);
if (material == null)
{
try
{
if (material == null) {
try {
material = DeprecationUtil.getMaterial(Integer.parseInt(searchItem));
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
}
}
if (material != null)
{
if (material != null) {
items.add(new ItemStack(material, 64));
}
else
{
} else {
sender.sendMessage("Skipping invalid item: " + searchItem);
}
}
@ -62,18 +62,17 @@ public class Command_dispfill extends FreedomCommand {
int affected = 0;
final Location centerLocation = sender_p.getLocation();
final Block centerBlock = centerLocation.getBlock();
for (int xOffset = -radius; xOffset <= radius; xOffset++)
{
for (int yOffset = -radius; yOffset <= radius; yOffset++)
{
for (int zOffset = -radius; zOffset <= radius; zOffset++)
{
final Block targetBlock = centerBlock.getRelative(xOffset, yOffset, zOffset);
if (targetBlock.getLocation().distanceSquared(centerLocation) < (radius * radius))
{
if (targetBlock.getType().equals(Material.DISPENSER))
{
sender.sendMessage("Filling dispenser @ " + Utilities.formatLocation(targetBlock.getLocation()));
for (int xOffset = -radius; xOffset <= radius; xOffset++) {
for (int yOffset = -radius; yOffset <= radius; yOffset++) {
for (int zOffset = -radius; zOffset <= radius; zOffset++) {
final Block targetBlock = centerBlock.getRelative(xOffset, yOffset,
zOffset);
if (targetBlock.getLocation().distanceSquared(centerLocation) < (radius
* radius)) {
if (targetBlock.getType().equals(Material.DISPENSER)) {
sender.sendMessage(
"Filling dispenser @ " + Utilities.formatLocation(
targetBlock.getLocation()));
setDispenserContents(targetBlock, itemsArray);
affected++;
}
@ -83,22 +82,10 @@ public class Command_dispfill extends FreedomCommand {
}
sender.sendMessage("Done. " + affected + " dispenser(s) filled.");
}
else
{
} else {
return false;
}
return true;
}
private static void setDispenserContents(final Block targetBlock, final ItemStack[] items)
{
if (targetBlock.getType() == Material.DISPENSER)
{
final Inventory dispenserInv = ((Dispenser) targetBlock.getState()).getInventory();
dispenserInv.clear();
dispenserInv.addItem(items);
}
}
}

View file

@ -8,8 +8,10 @@ import org.bukkit.inventory.ItemStack;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
public class Command_enchant extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 1) {
return false;
}
@ -21,95 +23,69 @@ public class Command_enchant extends FreedomCommand {
return true;
}
if (args[0].equalsIgnoreCase("list"))
{
if (args[0].equalsIgnoreCase("list")) {
boolean has_enchantments = false;
StringBuilder possible_ench = new StringBuilder("Possible enchantments for held item: ");
for (Enchantment ench : Enchantment.values())
{
if (ench.canEnchantItem(itemInHand))
{
StringBuilder possible_ench = new StringBuilder(
"Possible enchantments for held item: ");
for (Enchantment ench : Enchantment.values()) {
if (ench.canEnchantItem(itemInHand)) {
has_enchantments = true;
possible_ench.append(ench.getName()).append(", ");
}
}
if (has_enchantments)
{
if (has_enchantments) {
playerMsg(sender, possible_ench.toString());
}
else
{
} else {
playerMsg(sender, "The held item has no enchantments.");
}
}
else if (args[0].equalsIgnoreCase("addall"))
{
for (Enchantment ench : Enchantment.values())
{
try
{
if (ench.canEnchantItem(itemInHand))
{
} else if (args[0].equalsIgnoreCase("addall")) {
for (Enchantment ench : Enchantment.values()) {
try {
if (ench.canEnchantItem(itemInHand)) {
itemInHand.addEnchantment(ench, ench.getMaxLevel());
}
}
catch (Exception ex)
{
Log.info("Error using " + ench.getName() + " on " + itemInHand.getType().name() + " held by " + sender_p.getName() + ".");
} catch (Exception ex) {
Log.info("Error using " + ench.getName() + " on " + itemInHand.getType().name()
+ " held by " + sender_p.getName() + ".");
}
}
playerMsg(sender, "Added all possible enchantments for this item.");
}
else if (args[0].equalsIgnoreCase("reset"))
{
for (Enchantment ench : itemInHand.getEnchantments().keySet())
{
} else if (args[0].equalsIgnoreCase("reset")) {
for (Enchantment ench : itemInHand.getEnchantments().keySet()) {
itemInHand.removeEnchantment(ench);
}
playerMsg(sender, "Removed all enchantments.");
}
else
{
if (args.length < 2)
{
} else {
if (args.length < 2) {
return false;
}
Enchantment ench = null;
try
{
try {
ench = Enchantment.getByName(args[1]);
}
catch (Exception ex)
{
} catch (Exception ex) {
}
if (ench == null)
{
playerMsg(sender, args[1] + " is an invalid enchantment for the held item. Type \"/enchant list\" for valid enchantments for this item.");
if (ench == null) {
playerMsg(sender, args[1]
+ " is an invalid enchantment for the held item. Type \"/enchant list\" for valid enchantments for this item.");
return true;
}
if (args[0].equalsIgnoreCase("add"))
{
if (ench.canEnchantItem(itemInHand))
{
if (args[0].equalsIgnoreCase("add")) {
if (ench.canEnchantItem(itemInHand)) {
itemInHand.addEnchantment(ench, ench.getMaxLevel());
playerMsg(sender, "Added enchantment: " + ench.getName());
}
else
{
} else {
playerMsg(sender, "Can't use this enchantment on held item.");
}
}
else if (args[0].equals("remove"))
{
} else if (args[0].equals("remove")) {
itemInHand.removeEnchantment(ench);
playerMsg(sender, "Removed enchantment: " + ench.getName());

View file

@ -6,8 +6,10 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
public class Command_ender extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Utilities.gotoWorld(sender_p, server.getWorlds().get(0).getName() + "_the_end");
return true;
}

View file

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Location;
@ -8,33 +10,26 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.List;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
public class Command_expel extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
double radius = 20.0;
double strength = 5.0;
if (args.length >= 1) {
try {
radius = Math.max(1.0, Math.min(100.0, Double.parseDouble(args[0])));
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
}
}
if (args.length >= 2)
{
try
{
if (args.length >= 2) {
try {
strength = Math.max(0.0, Math.min(50.0, Double.parseDouble(args[1])));
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
}
}
@ -42,10 +37,8 @@ public class Command_expel extends FreedomCommand {
final Vector senderPos = sender_p.getLocation().toVector();
final List<Player> players = sender_p.getWorld().getPlayers();
for (final Player player : players)
{
if (player.equals(sender_p))
{
for (final Player player : players) {
if (player.equals(sender_p)) {
continue;
}
@ -53,16 +46,12 @@ public class Command_expel extends FreedomCommand {
final Vector targetPosVec = targetPos.toVector();
boolean inRange = false;
try
{
try {
inRange = targetPosVec.distanceSquared(senderPos) < (radius * radius);
}
catch (IllegalArgumentException ex)
{
} catch (IllegalArgumentException ex) {
}
if (inRange)
{
if (inRange) {
player.getWorld().createExplosion(targetPos, 0.0f, false);
Utilities.setFlying(player, false);
player.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength));
@ -70,13 +59,12 @@ public class Command_expel extends FreedomCommand {
}
}
if (pushedPlayers.isEmpty())
{
if (pushedPlayers.isEmpty()) {
playerMsg(sender, "No players pushed.");
}
else
{
playerMsg(sender, "Pushed " + pushedPlayers.size() + " players: " + StringUtils.join(pushedPlayers, ", "));
} else {
playerMsg(sender,
"Pushed " + pushedPlayers.size() + " players: " + StringUtils.join(pushedPlayers,
", "));
}
return true;

View file

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.player.PlayerList;
import me.StevenLawson.TotalFreedomMod.player.PlayerRank;
import org.apache.commons.lang3.StringUtils;
@ -7,13 +8,12 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_findip extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
return false;
}
@ -31,11 +31,11 @@ public class Command_findip extends FreedomCommand {
List<String> ipsToShow = PlayerList.getEntry(player).getIps();
if(rank.getOrdinal() < PlayerRank.SENIOR.getOrdinal() || targetRank.getOrdinal() >= rank.getOrdinal()) {
if (rank.getOrdinal() < PlayerRank.SENIOR.getOrdinal()
|| targetRank.getOrdinal() >= rank.getOrdinal()) {
ipsToShow = PlayerList.getEntry(player).getFuzziedIps();
}
playerMsg(sender, "Player IPs: " + StringUtils.join(ipsToShow, ", "));
return true;

View file

@ -7,8 +7,10 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
public class Command_flatlands extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (ConfigurationEntry.FLATLANDS_GENERATE.getBoolean()) {
FlatlandsWorld.getInstance().sendToWorld(sender_p);
} else {

View file

@ -11,10 +11,19 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_fr extends FreedomCommand {
private static boolean allFrozen = false;
public static void setAllFrozen(boolean freeze) {
allFrozen = freeze;
for (PlayerData data : PlayerData.PLAYER_DATA.values()) {
data.setFrozen(freeze);
}
}
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0) {
allFrozen = !allFrozen;
@ -24,34 +33,26 @@ public class Command_fr extends FreedomCommand {
setAllFrozen(true);
playerMsg(sender, "Players are now frozen.");
for (Player player : Bukkit.getOnlinePlayers())
{
if (!AdminList.isSuperAdmin(player))
{
playerMsg(player, "You have been frozen due to rulebreakers, you will be unfrozen soon.", ChatColor.RED);
for (Player player : Bukkit.getOnlinePlayers()) {
if (!AdminList.isSuperAdmin(player)) {
playerMsg(player,
"You have been frozen due to rulebreakers, you will be unfrozen soon.",
ChatColor.RED);
}
}
}
else
{
} else {
Utilities.adminAction(sender.getName(), "Unfreezing all players", false);
setAllFrozen(false);
playerMsg(sender, "Players are now free to move.");
}
}
else
{
if (args[0].equalsIgnoreCase("purge"))
{
} else {
if (args[0].equalsIgnoreCase("purge")) {
setAllFrozen(false);
Utilities.adminAction(sender.getName(), "Unfreezing all players", false);
}
else
{
} else {
final Player player = getPlayer(args[0]);
if (player == null)
{
if (player == null) {
playerMsg(sender, FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
return true;
}
@ -59,20 +60,15 @@ public class Command_fr extends FreedomCommand {
final PlayerData playerdata = PlayerData.getPlayerData(player);
playerdata.setFrozen(!playerdata.isFrozen());
playerMsg(sender, player.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
playerMsg(player, "You have been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".", ChatColor.AQUA);
playerMsg(sender,
player.getName() + " has been " + (playerdata.isFrozen() ? "frozen"
: "unfrozen") + ".");
playerMsg(player,
"You have been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".",
ChatColor.AQUA);
}
}
return true;
}
public static void setAllFrozen(boolean freeze)
{
allFrozen = freeze;
for (PlayerData data : PlayerData.PLAYER_DATA.values())
{
data.setFrozen(freeze);
}
}
}

View file

@ -6,8 +6,10 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_IN_GAME)
public class Command_fuckoff extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 1) {
return false;
}
@ -15,30 +17,25 @@ public class Command_fuckoff extends FreedomCommand {
boolean fuckoff_enabled = false;
double fuckoff_range = 25.0;
if (args[0].equalsIgnoreCase("on"))
{
if (args[0].equalsIgnoreCase("on")) {
fuckoff_enabled = true;
if (args.length >= 2)
{
try
{
if (args.length >= 2) {
try {
fuckoff_range = Math.max(5.0, Math.min(100.0, Double.parseDouble(args[1])));
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
}
}
}
TotalFreedomMod.fuckoffEnabledFor.remove(sender_p);
if (fuckoff_enabled)
{
if (fuckoff_enabled) {
TotalFreedomMod.fuckoffEnabledFor.put(sender_p, new Double(fuckoff_range));
}
playerMsg(sender, "Fuckoff " + (fuckoff_enabled ? ("enabled. Range: " + fuckoff_range + ".") : "disabled."));
playerMsg(sender, "Fuckoff " + (fuckoff_enabled ? ("enabled. Range: " + fuckoff_range + ".")
: "disabled."));
return true;
}

View file

@ -1,18 +1,155 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.Iterator;
import me.StevenLawson.TotalFreedomMod.ban.BanManager;
import me.StevenLawson.TotalFreedomMod.player.PlayerData;
import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.player.PlayerData;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Iterator;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_gadmin extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0) {
return false;
}
final GadminMode mode = GadminMode.findMode(args[0].toLowerCase());
if (mode == null) {
playerMsg(sender, "Invalid mode: " + args[0], ChatColor.RED);
return true;
}
final Iterator<? extends Player> it = server.getOnlinePlayers().iterator();
if (mode == GadminMode.LIST) {
playerMsg(sender, "[ Real Name ] : [ Display Name ] - Hash:");
while (it.hasNext()) {
final Player player = it.next();
final String hash = UUIDManager.getUniqueId(player).toString().substring(0, 4);
sender.sendMessage(ChatColor.GRAY + String.format("[ %s ] : [ %s ] - %s",
player.getName(),
ChatColor.stripColor(player.getDisplayName()),
hash));
}
return true;
}
if (args.length < 2) {
return false;
}
Player target = null;
while (it.hasNext() && target == null) {
final Player player = it.next();
final String hash = UUIDManager.getUniqueId(player).toString().substring(0, 4);
if (hash.equalsIgnoreCase(args[1])) {
target = player;
}
}
if (target == null) {
playerMsg(sender, "Invalid player hash: " + args[1], ChatColor.RED);
return true;
}
switch (mode) {
case KICK: {
Utilities.adminAction(sender.getName(),
String.format("Kicking: %s.", target.getName()), false);
target.kickPlayer("Kicked by Administrator");
break;
}
case NAMEBAN: {
BanManager.addUuidBan(target);
Utilities.adminAction(sender.getName(),
String.format("Banning Name: %s.", target.getName()), true);
target.kickPlayer("Username banned by Administrator.");
break;
}
case IPBAN: {
String ip = target.getAddress().getAddress().getHostAddress();
String[] ip_parts = ip.split("\\.");
if (ip_parts.length == 4) {
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
}
Utilities.adminAction(sender.getName(), String.format("Banning IP: %s.", ip), true);
BanManager.addIpBan(target);
target.kickPlayer("IP address banned by Administrator.");
break;
}
case BAN: {
String ip = target.getAddress().getAddress().getHostAddress();
String[] ip_parts = ip.split("\\.");
if (ip_parts.length == 4) {
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
}
Utilities.adminAction(sender.getName(),
String.format("Banning Name: %s, IP: %s.", target.getName(), ip), true);
BanManager.addUuidBan(target);
BanManager.addIpBan(target);
target.kickPlayer("IP and username banned by Administrator.");
break;
}
case OP: {
Utilities.adminAction(sender.getName(),
String.format("Opping %s.", target.getName()), false);
target.setOp(false);
target.sendMessage(FreedomCommand.YOU_ARE_OP);
break;
}
case DEOP: {
Utilities.adminAction(sender.getName(),
String.format("Deopping %s.", target.getName()), false);
target.setOp(false);
target.sendMessage(FreedomCommand.YOU_ARE_NOT_OP);
break;
}
case CI: {
target.getInventory().clear();
break;
}
case FR: {
PlayerData playerdata = PlayerData.getPlayerData(target);
playerdata.setFrozen(!playerdata.isFrozen());
playerMsg(sender,
target.getName() + " has been " + (playerdata.isFrozen() ? "frozen"
: "unfrozen") + ".");
target.sendMessage(
ChatColor.AQUA + "You have been " + (playerdata.isFrozen() ? "frozen"
: "unfrozen") + ".");
break;
}
case SMITE: {
Command_smite.smite(target);
break;
}
}
return true;
}
private enum GadminMode {
LIST("list"),
KICK("kick"),
@ -26,171 +163,21 @@ public class Command_gadmin extends FreedomCommand {
SMITE("smite");
private final String modeName;
GadminMode(String command)
{
GadminMode(String command) {
this.modeName = command;
}
public String getModeName()
{
return modeName;
}
public static GadminMode findMode(String needle)
{
for (final GadminMode mode : GadminMode.values())
{
if (needle.equalsIgnoreCase(mode.getModeName()))
{
public static GadminMode findMode(String needle) {
for (final GadminMode mode : GadminMode.values()) {
if (needle.equalsIgnoreCase(mode.getModeName())) {
return mode;
}
}
return null;
}
public String getModeName() {
return modeName;
}
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0) {
return false;
}
final GadminMode mode = GadminMode.findMode(args[0].toLowerCase());
if (mode == null) {
playerMsg(sender, "Invalid mode: " + args[0], ChatColor.RED);
return true;
}
final Iterator<? extends Player> it = server.getOnlinePlayers().iterator();
if (mode == GadminMode.LIST)
{
playerMsg(sender, "[ Real Name ] : [ Display Name ] - Hash:");
while (it.hasNext())
{
final Player player = it.next();
final String hash = UUIDManager.getUniqueId(player).toString().substring(0, 4);
sender.sendMessage(ChatColor.GRAY + String.format("[ %s ] : [ %s ] - %s",
player.getName(),
ChatColor.stripColor(player.getDisplayName()),
hash));
}
return true;
}
if (args.length < 2)
{
return false;
}
Player target = null;
while (it.hasNext() && target == null)
{
final Player player = it.next();
final String hash = UUIDManager.getUniqueId(player).toString().substring(0, 4);
if (hash.equalsIgnoreCase(args[1]))
{
target = player;
}
}
if (target == null)
{
playerMsg(sender, "Invalid player hash: " + args[1], ChatColor.RED);
return true;
}
switch (mode)
{
case KICK:
{
Utilities.adminAction(sender.getName(), String.format("Kicking: %s.", target.getName()), false);
target.kickPlayer("Kicked by Administrator");
break;
}
case NAMEBAN:
{
BanManager.addUuidBan(target);
Utilities.adminAction(sender.getName(), String.format("Banning Name: %s.", target.getName()), true);
target.kickPlayer("Username banned by Administrator.");
break;
}
case IPBAN:
{
String ip = target.getAddress().getAddress().getHostAddress();
String[] ip_parts = ip.split("\\.");
if (ip_parts.length == 4)
{
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
}
Utilities.adminAction(sender.getName(), String.format("Banning IP: %s.", ip), true);
BanManager.addIpBan(target);
target.kickPlayer("IP address banned by Administrator.");
break;
}
case BAN:
{
String ip = target.getAddress().getAddress().getHostAddress();
String[] ip_parts = ip.split("\\.");
if (ip_parts.length == 4)
{
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
}
Utilities.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", target.getName(), ip), true);
BanManager.addUuidBan(target);
BanManager.addIpBan(target);
target.kickPlayer("IP and username banned by Administrator.");
break;
}
case OP:
{
Utilities.adminAction(sender.getName(), String.format("Opping %s.", target.getName()), false);
target.setOp(false);
target.sendMessage(FreedomCommand.YOU_ARE_OP);
break;
}
case DEOP:
{
Utilities.adminAction(sender.getName(), String.format("Deopping %s.", target.getName()), false);
target.setOp(false);
target.sendMessage(FreedomCommand.YOU_ARE_NOT_OP);
break;
}
case CI:
{
target.getInventory().clear();
break;
}
case FR:
{
PlayerData playerdata = PlayerData.getPlayerData(target);
playerdata.setFrozen(!playerdata.isFrozen());
playerMsg(sender, target.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
target.sendMessage(ChatColor.AQUA + "You have been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
break;
}
case SMITE:
{
Command_smite.smite(target);
break;
}
}
return true;
}
}

View file

@ -1,59 +1,54 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
import me.StevenLawson.TotalFreedomMod.ban.Ban;
import me.StevenLawson.TotalFreedomMod.ban.BanManager;
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.player.Player;
import me.StevenLawson.TotalFreedomMod.player.PlayerList;
import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.List;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_glist extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 1) {
return false;
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("purge")) {
if (AdminList.isSeniorAdmin(sender))
{
if (AdminList.isSeniorAdmin(sender)) {
PlayerList.purgeAll();
playerMsg(sender, "Purged playerbase");
}
else
{
} else {
playerMsg(sender, "Only Senior Admins may purge the userlist.");
}
return true;
}
else
{
} else {
return false;
}
}
else if (args.length == 2)
{
} else if (args.length == 2) {
String username;
final List<String> ips = new ArrayList<String>();
final org.bukkit.entity.Player player = getPlayer(args[1]);
if (player == null)
{
final me.StevenLawson.TotalFreedomMod.player.Player entry = PlayerList.getEntry(UUIDManager.getUniqueId(args[1]));
if (player == null) {
final me.StevenLawson.TotalFreedomMod.player.Player entry = PlayerList.getEntry(
UUIDManager.getUniqueId(args[1]));
if (entry == null) {
playerMsg(sender, "Can't find that user. If target is not logged in, make sure that you spelled the name exactly.");
playerMsg(sender,
"Can't find that user. If target is not logged in, make sure that you spelled the name exactly.");
return true;
}
@ -61,9 +56,7 @@ public class Command_glist extends FreedomCommand {
for (String ip : entry.getIps()) {
ips.add(Utilities.getFuzzyIp(ip));
}
}
else
{
} else {
username = player.getName();
final Player entry = PlayerList.getEntry(UUIDManager.getUniqueId(player));
@ -74,47 +67,40 @@ public class Command_glist extends FreedomCommand {
}
String mode = args[0].toLowerCase();
if (mode.equalsIgnoreCase("ban"))
{
Utilities.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ", "), true);
if (mode.equalsIgnoreCase("ban")) {
Utilities.adminAction(sender.getName(),
"Banning " + username + " and IPs: " + StringUtils.join(ips, ", "), true);
final org.bukkit.entity.Player target = getPlayer(username, true);
if (target != null)
{
BanManager.addUuidBan(new Ban(UUIDManager.getUniqueId(target), target.getName()));
target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: " + ConfigurationEntry.SERVER_BAN_URL.getString());
}
else
{
if (target != null) {
BanManager.addUuidBan(
new Ban(UUIDManager.getUniqueId(target), target.getName()));
target.kickPlayer("You have been banned by " + sender.getName()
+ "\n If you think you have been banned wrongly, appeal here: "
+ ConfigurationEntry.SERVER_BAN_URL.getString());
} else {
BanManager.addUuidBan(new Ban(UUIDManager.getUniqueId(username), username));
}
for (String ip : ips)
{
for (String ip : ips) {
BanManager.addIpBan(new Ban(ip, username));
BanManager.addIpBan(new Ban(Utilities.getFuzzyIp(ip), username));
}
}
else if (mode.equalsIgnoreCase("unban"))
{
Utilities.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ", "), true);
} else if (mode.equalsIgnoreCase("unban")) {
Utilities.adminAction(sender.getName(),
"Unbanning " + username + " and IPs: " + StringUtils.join(ips, ", "), true);
BanManager.unbanUuid(UUIDManager.getUniqueId(username));
for (String ip : ips)
{
for (String ip : ips) {
BanManager.unbanIp(ip);
BanManager.unbanIp(Utilities.getFuzzyIp(ip));
}
}
else
{
} else {
return false;
}
return true;
}
else
{
} else {
return false;
}
}

View file

@ -16,8 +16,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_gtfo extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0) {
return false;
}
@ -30,20 +32,17 @@ public class Command_gtfo extends FreedomCommand {
}
String reason = null;
if (args.length >= 2)
{
if (args.length >= 2) {
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
}
Utilities.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);
Utilities.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.",
ChatColor.RED);
// Undo WorldEdits:
try
{
try {
WorldEditBridge.undo(player, 15);
}
catch (NoClassDefFoundError ex)
{
} catch (NoClassDefFoundError ex) {
}
// rollback
@ -61,11 +60,10 @@ public class Command_gtfo extends FreedomCommand {
// strike with lightning effect:
final Location targetPos = player.getLocation();
for (int x = -1; x <= 1; x++)
{
for (int z = -1; z <= 1; z++)
{
final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
final Location strike_pos = new Location(targetPos.getWorld(),
targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
targetPos.getWorld().strikeLightning(strike_pos);
}
}
@ -80,8 +78,7 @@ public class Command_gtfo extends FreedomCommand {
.append(", IP: ")
.append(ip);
if (reason != null)
{
if (reason != null) {
bcast.append(" - Reason: ").append(ChatColor.YELLOW).append(reason);
}
@ -90,10 +87,14 @@ public class Command_gtfo extends FreedomCommand {
BanManager.addIpBan(new Ban(ip, player.getName(), sender.getName(), null, reason));
// ban username:
BanManager.addUuidBan(new Ban(UUIDManager.getUniqueId(player), player.getName(), sender.getName(), null, reason));
BanManager.addUuidBan(
new Ban(UUIDManager.getUniqueId(player), player.getName(), sender.getName(), null,
reason));
// kick Player:
player.kickPlayer(ChatColor.RED + "GTFO" + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason) : ""));
player.kickPlayer(
ChatColor.RED + "GTFO" + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason)
: ""));
return true;
}

View file

@ -9,8 +9,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_halt extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
return false;
}
@ -18,10 +20,8 @@ public class Command_halt extends FreedomCommand {
if (args[0].equalsIgnoreCase("all")) {
Utilities.adminAction(sender.getName(), "Halting all non-superadmins.", true);
int counter = 0;
for (Player player : server.getOnlinePlayers())
{
if (!AdminList.isSuperAdmin(player))
{
for (Player player : server.getOnlinePlayers()) {
if (!AdminList.isSuperAdmin(player)) {
PlayerData.getPlayerData(player).setHalted(true);
counter++;
}
@ -30,15 +30,12 @@ public class Command_halt extends FreedomCommand {
return true;
}
if (args[0].equalsIgnoreCase("purge"))
{
if (args[0].equalsIgnoreCase("purge")) {
Utilities.adminAction(sender.getName(), "Unhalting all players.", true);
int counter = 0;
for (Player player : server.getOnlinePlayers())
{
for (Player player : server.getOnlinePlayers()) {
PlayerData playerdata = PlayerData.getPlayerData(player);
if (PlayerData.getPlayerData(player).isHalted())
{
if (PlayerData.getPlayerData(player).isHalted()) {
playerdata.setHalted(false);
counter++;
}
@ -47,25 +44,20 @@ public class Command_halt extends FreedomCommand {
return true;
}
if (args[0].equalsIgnoreCase("list"))
{
if (args[0].equalsIgnoreCase("list")) {
PlayerData info;
int count = 0;
for (Player hp : server.getOnlinePlayers())
{
for (Player hp : server.getOnlinePlayers()) {
info = PlayerData.getPlayerData(hp);
if (info.isHalted())
{
if (count == 0)
{
if (info.isHalted()) {
if (count == 0) {
playerMsg(sender, "Halted players:");
}
playerMsg(sender, "- " + hp.getName());
count++;
}
}
if (count == 0)
{
if (count == 0) {
playerMsg(sender, "There are currently no halted players.");
}
return true;
@ -73,21 +65,17 @@ public class Command_halt extends FreedomCommand {
final Player player = getPlayer(args[0]);
if (player == null)
{
if (player == null) {
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
PlayerData playerdata = PlayerData.getPlayerData(player);
if (!playerdata.isHalted())
{
if (!playerdata.isHalted()) {
Utilities.adminAction(sender.getName(), "Halting " + player.getName(), true);
playerdata.setHalted(true);
return true;
}
else
{
} else {
Utilities.adminAction(sender.getName(), "Unhalting " + player.getName(), true);
playerdata.setHalted(false);
return true;

View file

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.text.DecimalFormat;
import java.util.concurrent.atomic.AtomicInteger;
import me.StevenLawson.TotalFreedomMod.Log;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.apache.commons.lang.math.DoubleRange;
@ -9,47 +11,45 @@ import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import java.text.DecimalFormat;
import java.util.concurrent.atomic.AtomicInteger;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_health extends FreedomCommand {
private static final int BYTES_PER_MB = 1024 * 1024;
private static final DoubleRange TPS_RANGE = new DoubleRange(20.0 - 0.1, 20.0 + 0.1);
@Override
public boolean run(final CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(final CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Runtime runtime = Runtime.getRuntime();
long usedMem = runtime.totalMemory() - runtime.freeMemory();
playerMsg(sender, "Reserved Memory: " + (double) runtime.totalMemory() / (double) BYTES_PER_MB + "mb");
playerMsg(sender, "Used Memory: " + new DecimalFormat("#").format((double) usedMem / (double) BYTES_PER_MB) + "mb (" + new DecimalFormat("#").format(((double) usedMem / (double) runtime.totalMemory()) * 100.0) + "%)");
playerMsg(sender, "Max Memory: " + (double) runtime.maxMemory() / (double) BYTES_PER_MB + "mb");
playerMsg(sender,
"Reserved Memory: " + (double) runtime.totalMemory() / (double) BYTES_PER_MB + "mb");
playerMsg(sender, "Used Memory: " + new DecimalFormat("#").format(
(double) usedMem / (double) BYTES_PER_MB) + "mb (" + new DecimalFormat("#").format(
((double) usedMem / (double) runtime.totalMemory()) * 100.0) + "%)");
playerMsg(sender,
"Max Memory: " + (double) runtime.maxMemory() / (double) BYTES_PER_MB + "mb");
playerMsg(sender, "Calculating ticks per second, please wait...");
new BukkitRunnable()
{
new BukkitRunnable() {
@Override
public void run()
{
try
{
public void run() {
try {
TFM_TickMeter tickMeter = new TFM_TickMeter(plugin);
tickMeter.startTicking();
Thread.sleep(2500);
final double ticksPerSecond = tickMeter.stopTicking();
new BukkitRunnable()
{
new BukkitRunnable() {
@Override
public void run()
{
playerMsg(sender, "Ticks per second: " + (TPS_RANGE.containsDouble(ticksPerSecond) ? ChatColor.GREEN : ChatColor.RED) + ticksPerSecond);
public void run() {
playerMsg(sender,
"Ticks per second: " + (TPS_RANGE.containsDouble(ticksPerSecond)
? ChatColor.GREEN : ChatColor.RED) + ticksPerSecond);
}
}.runTask(plugin);
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.severe(ex);
}
}
@ -58,35 +58,30 @@ public class Command_health extends FreedomCommand {
return true;
}
private class TFM_TickMeter
{
private class TFM_TickMeter {
private final AtomicInteger ticks = new AtomicInteger();
private final TotalFreedomMod plugin;
private long startTime;
private BukkitTask task;
public TFM_TickMeter(TotalFreedomMod plugin)
{
public TFM_TickMeter(TotalFreedomMod plugin) {
this.plugin = plugin;
}
public void startTicking()
{
public void startTicking() {
startTime = System.currentTimeMillis();
ticks.set(0);
task = new BukkitRunnable()
{
task = new BukkitRunnable() {
@Override
public void run()
{
public void run() {
ticks.incrementAndGet();
}
}.runTaskTimer(plugin, 0L, 1L);
}
public double stopTicking()
{
public double stopTicking() {
task.cancel();
long elapsed = System.currentTimeMillis() - startTime;
int tickCount = ticks.get();

View file

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.apache.commons.lang3.StringUtils;
@ -8,20 +10,18 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList;
import java.util.List;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_invis extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
boolean smite = false;
if (args.length >= 1) {
if (args[0].equalsIgnoreCase("smite")) {
Utilities.adminAction(sender.getName(), "Smiting all invisible players", true);
smite = true;
} else
{
} else {
return false;
}
}
@ -29,32 +29,26 @@ public class Command_invis extends FreedomCommand {
List<String> players = new ArrayList<String>();
int smites = 0;
for (Player player : server.getOnlinePlayers())
{
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY))
{
for (Player player : server.getOnlinePlayers()) {
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
players.add(player.getName());
if (smite && !AdminList.isSuperAdmin(player))
{
if (smite && !AdminList.isSuperAdmin(player)) {
player.setHealth(0.0);
smites++;
}
}
}
if (players.isEmpty())
{
if (players.isEmpty()) {
playerMsg(sender, "There are no invisible players");
return true;
}
if (smite)
{
if (smite) {
playerMsg(sender, "Smitten " + smites + " players");
}
else
{
playerMsg(sender, "Invisble players (" + players.size() + "): " + StringUtils.join(players, ", "));
} else {
playerMsg(sender,
"Invisble players (" + players.size() + "): " + StringUtils.join(players, ", "));
}
return true;

View file

@ -8,76 +8,68 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_jumppads extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0 || args.length > 2) {
return false;
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("info")) {
playerMsg(sender, "Jumppads: " + (JumpPads.getMode().isOn() ? "Enabled" : "Disabled"), ChatColor.BLUE);
playerMsg(sender, "Sideways: " + (JumpPads.getMode() == JumpPads.JumpPadMode.NORMAL_AND_SIDEWAYS ? "Enabled" : "Disabled"), ChatColor.BLUE);
playerMsg(sender,
"Jumppads: " + (JumpPads.getMode().isOn() ? "Enabled" : "Disabled"),
ChatColor.BLUE);
playerMsg(sender,
"Sideways: " + (JumpPads.getMode() == JumpPads.JumpPadMode.NORMAL_AND_SIDEWAYS
? "Enabled" : "Disabled"), ChatColor.BLUE);
playerMsg(sender, "Strength: " + (JumpPads.getStrength() * 10 - 1), ChatColor.BLUE);
return true;
}
if ("off".equals(args[0]))
{
if ("off".equals(args[0])) {
Utilities.adminAction(sender.getName(), "Disabling Jumppads", false);
JumpPads.setMode(JumpPads.JumpPadMode.OFF);
}
else
{
} else {
Utilities.adminAction(sender.getName(), "Enabling Jumppads", false);
JumpPads.setMode(JumpPads.JumpPadMode.MADGEEK);
}
}
else
{
if (JumpPads.getMode() == JumpPads.JumpPadMode.OFF)
{
playerMsg(sender, "Jumppads are currently disabled, please enable them before changing jumppads settings.");
} else {
if (JumpPads.getMode() == JumpPads.JumpPadMode.OFF) {
playerMsg(sender,
"Jumppads are currently disabled, please enable them before changing jumppads settings.");
return true;
}
if (args[0].equalsIgnoreCase("sideways"))
{
if ("off".equals(args[1]))
{
Utilities.adminAction(sender.getName(), "Setting Jumppads mode to: Madgeek", false);
if (args[0].equalsIgnoreCase("sideways")) {
if ("off".equals(args[1])) {
Utilities.adminAction(sender.getName(), "Setting Jumppads mode to: Madgeek",
false);
JumpPads.setMode(JumpPads.JumpPadMode.MADGEEK);
}
else
{
Utilities.adminAction(sender.getName(), "Setting Jumppads mode to: Normal and Sideways", false);
} else {
Utilities.adminAction(sender.getName(),
"Setting Jumppads mode to: Normal and Sideways", false);
JumpPads.setMode(JumpPads.JumpPadMode.NORMAL_AND_SIDEWAYS);
}
}
else if (args[0].equalsIgnoreCase("strength"))
{
} else if (args[0].equalsIgnoreCase("strength")) {
final float strength;
try
{
try {
strength = Float.parseFloat(args[1]);
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
playerMsg(sender, "Invalid Strength");
return true;
}
if (strength > 10 || strength < 1)
{
if (strength > 10 || strength < 1) {
playerMsg(sender, "Invalid Strength: The strength may be 1 through 10.");
return true;
}
Utilities.adminAction(sender.getName(), "Setting Jumppads strength to: " + strength, false);
Utilities.adminAction(sender.getName(), "Setting Jumppads strength to: " + strength,
false);
JumpPads.setStrength((strength / 10) + 0.1F);
}
else
{
} else {
return false;
}
}

View file

@ -9,8 +9,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.BOTH, blockHostConsole = true)
public class Command_kicknoob extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Utilities.adminAction(sender.getName(), "Disconnecting all non-superadmins.", true);
for (Player player : server.getOnlinePlayers()) {

View file

@ -1,5 +1,8 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@ -10,14 +13,12 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
public class Command_landmine extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (!ConfigurationEntry.LANDMINES_ENABLED.getBoolean()) {
playerMsg(sender, "The landmine is currently disabled.", ChatColor.GREEN);
return true;
@ -30,53 +31,46 @@ public class Command_landmine extends FreedomCommand {
double radius = 2.0;
if (args.length >= 1)
{
if ("list".equalsIgnoreCase(args[0]))
{
if (args.length >= 1) {
if ("list".equalsIgnoreCase(args[0])) {
final Iterator<TFM_LandmineData> landmines = TFM_LandmineData.landmines.iterator();
while (landmines.hasNext())
{
while (landmines.hasNext()) {
playerMsg(sender, landmines.next().toString());
}
return true;
}
try
{
try {
radius = Math.max(2.0, Math.min(6.0, Double.parseDouble(args[0])));
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
}
}
final Block landmine = sender_p.getLocation().getBlock().getRelative(BlockFace.DOWN);
landmine.setType(Material.TNT);
TFM_LandmineData.landmines.add(new TFM_LandmineData(landmine.getLocation(), sender_p, radius));
TFM_LandmineData.landmines.add(
new TFM_LandmineData(landmine.getLocation(), sender_p, radius));
playerMsg(sender, "Landmine planted - Radius = " + radius + " blocks.", ChatColor.GREEN);
return true;
}
public static class TFM_LandmineData
{
public static class TFM_LandmineData {
public static final List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>();
public final Location location;
public final Player player;
public final double radius;
public TFM_LandmineData(Location location, Player player, double radius)
{
public TFM_LandmineData(Location location, Player player, double radius) {
this.location = location;
this.player = player;
this.radius = radius;
}
@Override
public String toString()
{
public String toString() {
return this.location.toString() + ", " + this.radius + ", " + this.player.getName();
}
}

View file

@ -8,8 +8,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_lastcmd extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0) {
return false;
}
@ -23,11 +25,9 @@ public class Command_lastcmd extends FreedomCommand {
final PlayerData playerdata = PlayerData.getPlayerData(player);
if (playerdata != null)
{
if (playerdata != null) {
String lastCommand = playerdata.getLastCommand();
if (lastCommand.isEmpty())
{
if (lastCommand.isEmpty()) {
lastCommand = "(none)";
}
playerMsg(sender, player.getName() + " - Last Command: " + lastCommand, ChatColor.GRAY);

View file

@ -15,12 +15,6 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
public class Command_list extends FreedomCommand {
private enum ListFilter {
ALL,
ADMINS,
IMPOSTORS
}
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
@ -66,8 +60,9 @@ public class Command_list extends FreedomCommand {
final List<String> names = new ArrayList<String>();
for (Player player : server.getOnlinePlayers()) {
if (VanishManager.isVanished(player))
if (VanishManager.isVanished(player)) {
continue;
}
if (listFilter == ListFilter.ADMINS && !AdminList.isSuperAdmin(player)) {
continue;
@ -94,4 +89,10 @@ public class Command_list extends FreedomCommand {
return true;
}
private enum ListFilter {
ALL,
ADMINS,
IMPOSTORS
}
}

View file

@ -5,10 +5,13 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
public class Command_localspawn extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
sender_p.teleport(sender_p.getWorld().getSpawnLocation());
playerMsg(sender, "Teleported to spawnpoint for world \"" + sender_p.getWorld().getName() + "\".");
playerMsg(sender,
"Teleported to spawnpoint for world \"" + sender_p.getWorld().getName() + "\".");
return true;
}
}

View file

@ -10,8 +10,10 @@ import org.bukkit.scheduler.BukkitTask;
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
public class Command_lockup extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 1) {
if (args[0].equalsIgnoreCase("all")) {
Utilities.adminAction(sender.getName(), "Locking up all players", true);
@ -20,30 +22,21 @@ public class Command_lockup extends FreedomCommand {
startLockup(player);
}
playerMsg(sender, "Locked up all players.");
}
else if (args[0].equalsIgnoreCase("purge"))
{
} else if (args[0].equalsIgnoreCase("purge")) {
Utilities.adminAction(sender.getName(), "Unlocking all players", true);
for (Player player : server.getOnlinePlayers())
{
for (Player player : server.getOnlinePlayers()) {
cancelLockup(player);
}
playerMsg(sender, "Unlocked all players.");
}
else
{
} else {
return false;
}
}
else if (args.length == 2)
{
if (args[1].equalsIgnoreCase("on"))
{
} else if (args.length == 2) {
if (args[1].equalsIgnoreCase("on")) {
final Player player = getPlayer(args[0]);
if (player == null)
{
if (player == null) {
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
@ -51,13 +44,10 @@ public class Command_lockup extends FreedomCommand {
Utilities.adminAction(sender.getName(), "Locking up " + player.getName(), true);
startLockup(player);
playerMsg(sender, "Locked up " + player.getName() + ".");
}
else if ("off".equals(args[1]))
{
} else if ("off".equals(args[1])) {
final Player player = getPlayer(args[0]);
if (player == null)
{
if (player == null) {
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
@ -65,52 +55,39 @@ public class Command_lockup extends FreedomCommand {
Utilities.adminAction(sender.getName(), "Unlocking " + player.getName(), true);
cancelLockup(player);
playerMsg(sender, "Unlocked " + player.getName() + ".");
}
else
{
} else {
return false;
}
}
else
{
} else {
return false;
}
return true;
}
private void cancelLockup(PlayerData playerdata)
{
private void cancelLockup(PlayerData playerdata) {
BukkitTask lockupScheduleID = playerdata.getLockupScheduleID();
if (lockupScheduleID != null)
{
if (lockupScheduleID != null) {
lockupScheduleID.cancel();
playerdata.setLockupScheduleID(null);
}
}
private void cancelLockup(final Player player)
{
private void cancelLockup(final Player player) {
cancelLockup(PlayerData.getPlayerData(player));
}
private void startLockup(final Player player)
{
private void startLockup(final Player player) {
final PlayerData playerdata = PlayerData.getPlayerData(player);
cancelLockup(playerdata);
playerdata.setLockupScheduleID(new BukkitRunnable()
{
playerdata.setLockupScheduleID(new BukkitRunnable() {
@Override
public void run()
{
if (player.isOnline())
{
public void run() {
if (player.isOnline()) {
player.openInventory(player.getInventory());
}
else
{
} else {
cancelLockup(playerdata);
}
}

View file

@ -1,5 +1,14 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import me.StevenLawson.TotalFreedomMod.Log;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.admin.Admin;
@ -11,44 +20,37 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.Map.Entry;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
public class Command_logs extends FreedomCommand {
public static void deactivateSuperadmin(Admin superadmin) {
for (String ip : superadmin.getIps()) {
updateLogsRegistration(null, superadmin.getLastLoginName(), ip, LogsRegistrationMode.DELETE);
updateLogsRegistration(null, superadmin.getLastLoginName(), ip,
LogsRegistrationMode.DELETE);
}
}
public static void updateLogsRegistration(final CommandSender sender, final Player target, final LogsRegistrationMode mode)
{
updateLogsRegistration(sender, target.getName(), target.getAddress().getAddress().getHostAddress().trim(), mode);
public static void updateLogsRegistration(final CommandSender sender, final Player target,
final LogsRegistrationMode mode) {
updateLogsRegistration(sender, target.getName(),
target.getAddress().getAddress().getHostAddress().trim(), mode);
}
public static void updateLogsRegistration(final CommandSender sender, final String targetName, final String targetIP, final LogsRegistrationMode mode)
{
public static void updateLogsRegistration(final CommandSender sender, final String targetName,
final String targetIP, final LogsRegistrationMode mode) {
final String logsRegisterURL = ConfigurationEntry.LOGS_URL.getString();
final String logsRegisterPassword = ConfigurationEntry.LOGS_SECRET.getString();
if (logsRegisterURL == null || logsRegisterPassword == null || logsRegisterURL.isEmpty() || logsRegisterPassword.isEmpty())
{
if (logsRegisterURL == null || logsRegisterPassword == null || logsRegisterURL.isEmpty()
|| logsRegisterPassword.isEmpty()) {
return;
}
new BukkitRunnable()
{
new BukkitRunnable() {
@Override
public void run()
{
try
{
if (sender != null)
{
public void run() {
try {
if (sender != null) {
sender.sendMessage(ChatColor.YELLOW + "Connecting...");
}
@ -67,20 +69,16 @@ public class Command_logs extends FreedomCommand {
final int responseCode = connection.getResponseCode();
if (sender != null)
{
new BukkitRunnable()
{
if (sender != null) {
new BukkitRunnable() {
@Override
public void run()
{
if (responseCode == 200)
{
sender.sendMessage(ChatColor.GREEN + "Registration " + mode + "d.");
}
else
{
sender.sendMessage(ChatColor.RED + "Error contacting logs registration server.");
public void run() {
if (responseCode == 200) {
sender.sendMessage(
ChatColor.GREEN + "Registration " + mode + "d.");
} else {
sender.sendMessage(ChatColor.RED
+ "Error contacting logs registration server.");
}
}
}.runTask(TotalFreedomMod.plugin);
@ -93,11 +91,13 @@ public class Command_logs extends FreedomCommand {
}
@Override
public boolean run(final CommandSender sender, final org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(final CommandSender sender, final org.bukkit.entity.Player sender_p,
Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
LogsRegistrationMode mode = LogsRegistrationMode.UPDATE;
if (args.length == 1) {
mode = ("off".equals(args[0]) ? LogsRegistrationMode.DELETE : LogsRegistrationMode.UPDATE);
mode = ("off".equals(args[0]) ? LogsRegistrationMode.DELETE
: LogsRegistrationMode.UPDATE);
}
updateLogsRegistration(sender, sender_p, mode);
@ -105,45 +105,38 @@ public class Command_logs extends FreedomCommand {
return true;
}
public enum LogsRegistrationMode
{
public enum LogsRegistrationMode {
UPDATE("update"), DELETE("delete");
private final String mode;
LogsRegistrationMode(String mode)
{
LogsRegistrationMode(String mode) {
this.mode = mode;
}
@Override
public String toString()
{
public String toString() {
return mode;
}
}
private static class URLBuilder
{
private static class URLBuilder {
private final String requestPath;
private final Map<String, String> queryStringMap = new HashMap<String, String>();
public URLBuilder(String requestPath)
{
public URLBuilder(String requestPath) {
this.requestPath = requestPath;
}
public URLBuilder addQueryParameter(String key, String value)
{
public URLBuilder addQueryParameter(String key, String value) {
queryStringMap.put(key, value);
return this;
}
public URL getURL() throws MalformedURLException
{
public URL getURL() throws MalformedURLException {
List<String> pairs = new ArrayList<String>();
Iterator<Entry<String, String>> it = queryStringMap.entrySet().iterator();
while (it.hasNext())
{
while (it.hasNext()) {
Entry<String, String> pair = it.next();
pairs.add(pair.getKey() + "=" + pair.getValue());
}

View file

@ -7,69 +7,66 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_CONSOLE)
public class Command_moblimiter extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 1) {
return false;
}
if (args[0].equalsIgnoreCase("on")) {
ConfigurationEntry.MOB_LIMITER_ENABLED.setBoolean(true);
}
else if (args[0].equalsIgnoreCase("off"))
{
} else if (args[0].equalsIgnoreCase("off")) {
ConfigurationEntry.MOB_LIMITER_ENABLED.setBoolean(false);
}
else if (args[0].equalsIgnoreCase("dragon"))
{
ConfigurationEntry.MOB_LIMITER_DISABLE_DRAGON.setBoolean(!ConfigurationEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean());
}
else if (args[0].equalsIgnoreCase("giant"))
{
ConfigurationEntry.MOB_LIMITER_DISABLE_GIANT.setBoolean(!ConfigurationEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean());
}
else if (args[0].equalsIgnoreCase("slime"))
{
ConfigurationEntry.MOB_LIMITER_DISABLE_SLIME.setBoolean(!ConfigurationEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean());
}
else if (args[0].equalsIgnoreCase("ghast"))
{
ConfigurationEntry.MOB_LIMITER_DISABLE_GHAST.setBoolean(!ConfigurationEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean());
}
else
{
if (args.length < 2)
{
} else if (args[0].equalsIgnoreCase("dragon")) {
ConfigurationEntry.MOB_LIMITER_DISABLE_DRAGON.setBoolean(
!ConfigurationEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean());
} else if (args[0].equalsIgnoreCase("giant")) {
ConfigurationEntry.MOB_LIMITER_DISABLE_GIANT.setBoolean(
!ConfigurationEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean());
} else if (args[0].equalsIgnoreCase("slime")) {
ConfigurationEntry.MOB_LIMITER_DISABLE_SLIME.setBoolean(
!ConfigurationEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean());
} else if (args[0].equalsIgnoreCase("ghast")) {
ConfigurationEntry.MOB_LIMITER_DISABLE_GHAST.setBoolean(
!ConfigurationEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean());
} else {
if (args.length < 2) {
return false;
}
if (args[0].equalsIgnoreCase("setmax"))
{
try
{
ConfigurationEntry.MOB_LIMITER_MAX.setInteger(Math.max(0, Math.min(2000, Integer.parseInt(args[1]))));
}
catch (NumberFormatException nfex)
{
if (args[0].equalsIgnoreCase("setmax")) {
try {
ConfigurationEntry.MOB_LIMITER_MAX.setInteger(
Math.max(0, Math.min(2000, Integer.parseInt(args[1]))));
} catch (NumberFormatException nfex) {
}
}
}
if (ConfigurationEntry.MOB_LIMITER_ENABLED.getBoolean())
{
sender.sendMessage("Moblimiter enabled. Maximum mobcount set to: " + ConfigurationEntry.MOB_LIMITER_MAX.getInteger() + ".");
if (ConfigurationEntry.MOB_LIMITER_ENABLED.getBoolean()) {
sender.sendMessage("Moblimiter enabled. Maximum mobcount set to: "
+ ConfigurationEntry.MOB_LIMITER_MAX.getInteger() + ".");
playerMsg(sender, "Dragon: " + (ConfigurationEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean() ? "disabled" : "enabled") + ".");
playerMsg(sender, "Giant: " + (ConfigurationEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean() ? "disabled" : "enabled") + ".");
playerMsg(sender, "Slime: " + (ConfigurationEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean() ? "disabled" : "enabled") + ".");
playerMsg(sender, "Ghast: " + (ConfigurationEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean() ? "disabled" : "enabled") + ".");
}
else
{
playerMsg(sender,
"Dragon: " + (ConfigurationEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean()
? "disabled" : "enabled") + ".");
playerMsg(sender,
"Giant: " + (ConfigurationEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean() ? "disabled"
: "enabled") + ".");
playerMsg(sender,
"Slime: " + (ConfigurationEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean() ? "disabled"
: "enabled") + ".");
playerMsg(sender,
"Ghast: " + (ConfigurationEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean() ? "disabled"
: "enabled") + ".");
} else {
playerMsg(sender, "Moblimiter is disabled. No mob restrictions are in effect.");
}
GameRuleHandler.setGameRule(GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING, !ConfigurationEntry.MOB_LIMITER_ENABLED.getBoolean());
GameRuleHandler.setGameRule(GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING,
!ConfigurationEntry.MOB_LIMITER_ENABLED.getBoolean());
return true;
}

View file

@ -4,26 +4,22 @@ import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.*;
import org.bukkit.entity.Ambient;
import org.bukkit.entity.Creature;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Slime;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_mp extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
playerMsg(sender, "Purging all mobs...");
playerMsg(sender, purgeMobs() + " mobs removed.");
return true;
}
public static int purgeMobs()
{
public static int purgeMobs() {
int removed = 0;
for (World world : Bukkit.getWorlds())
{
for (Entity ent : world.getLivingEntities())
{
if (ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime || ent instanceof EnderDragon || ent instanceof Ambient)
{
for (World world : Bukkit.getWorlds()) {
for (Entity ent : world.getLivingEntities()) {
if (ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime
|| ent instanceof EnderDragon || ent instanceof Ambient) {
ent.remove();
removed++;
}
@ -32,4 +28,12 @@ public class Command_mp extends FreedomCommand {
return removed;
}
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
playerMsg(sender, "Purging all mobs...");
playerMsg(sender, purgeMobs() + " mobs removed.");
return true;
}
}

View file

@ -10,8 +10,10 @@ import org.bukkit.inventory.ItemStack;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
public class Command_mp44 extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (!ConfigurationEntry.MP44_ENABLED.getBoolean()) {
playerMsg(sender, "The mp44 is currently disabled.", ChatColor.GREEN);
return true;
@ -23,17 +25,16 @@ public class Command_mp44 extends FreedomCommand {
PlayerData playerdata = PlayerData.getPlayerData(sender_p);
if (args[0].equalsIgnoreCase("draw"))
{
if (args[0].equalsIgnoreCase("draw")) {
playerdata.armMP44();
playerMsg(sender, "mp44 is ARMED! Left click with gunpowder to start firing, left click again to quit.", ChatColor.GREEN);
playerMsg(sender,
"mp44 is ARMED! Left click with gunpowder to start firing, left click again to quit.",
ChatColor.GREEN);
playerMsg(sender, "Type /mp44 sling to disable. -by Madgeek1450", ChatColor.GREEN);
sender_p.setItemInHand(new ItemStack(Material.SULPHUR, 1));
}
else
{
} else {
playerdata.disarmMP44();
sender.sendMessage(ChatColor.GREEN + "mp44 Disarmed.");

View file

@ -6,8 +6,10 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
public class Command_nether extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Utilities.gotoWorld(sender_p, server.getWorlds().get(0).getName() + "_nether");
return true;
}

View file

@ -1,5 +1,9 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.command.CommandBlocker;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
@ -8,16 +12,42 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
public class Command_nf extends FreedomCommand {
private static Player getPlayerByDisplayName(String needle) {
needle = needle.toLowerCase().trim();
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.getDisplayName().toLowerCase().trim().contains(needle)) {
return player;
}
}
return null;
}
private static Player getPlayerByDisplayNameAlt(String needle) {
needle = needle.toLowerCase().trim();
Integer minEditDistance = null;
Player minEditMatch = null;
for (Player player : Bukkit.getOnlinePlayers()) {
String haystack = player.getDisplayName().toLowerCase().trim();
int editDistance = StringUtils.getLevenshteinDistance(needle, haystack.toLowerCase());
if (minEditDistance == null || minEditDistance.intValue() > editDistance) {
minEditDistance = editDistance;
minEditMatch = player;
}
}
return minEditMatch;
}
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
boolean nickMatched = false;
final List<String> outputCommand = new ArrayList<String>();
@ -28,46 +58,39 @@ public class Command_nf extends FreedomCommand {
Player player = null;
Matcher matcher = Pattern.compile("^!(.+)$").matcher(arg);
if (matcher.find())
{
if (matcher.find()) {
String displayName = matcher.group(1);
player = getPlayerByDisplayName(displayName);
if (player == null)
{
if (player == null) {
player = getPlayerByDisplayNameAlt(displayName);
if (player == null)
{
sender.sendMessage(ChatColor.GRAY + "Can't find player by nickname: " + displayName);
if (player == null) {
sender.sendMessage(
ChatColor.GRAY + "Can't find player by nickname: " + displayName);
return true;
}
}
}
if (player == null)
{
if (player == null) {
outputCommand.add(arg);
}
else
{
} else {
nickMatched = true;
outputCommand.add(player.getName());
}
}
}
if (!nickMatched)
{
if (!nickMatched) {
sender.sendMessage("No nicknames replaced in command.");
return true;
}
String newCommand = StringUtils.join(outputCommand, " ");
if (CommandBlocker.isCommandBlocked(newCommand, sender))
{
if (CommandBlocker.isCommandBlocked(newCommand, sender)) {
// CommandBlocker handles messages and broadcasts
return true;
}
@ -77,40 +100,4 @@ public class Command_nf extends FreedomCommand {
return true;
}
private static Player getPlayerByDisplayName(String needle)
{
needle = needle.toLowerCase().trim();
for (Player player : Bukkit.getOnlinePlayers())
{
if (player.getDisplayName().toLowerCase().trim().contains(needle))
{
return player;
}
}
return null;
}
private static Player getPlayerByDisplayNameAlt(String needle)
{
needle = needle.toLowerCase().trim();
Integer minEditDistance = null;
Player minEditMatch = null;
for (Player player : Bukkit.getOnlinePlayers())
{
String haystack = player.getDisplayName().toLowerCase().trim();
int editDistance = StringUtils.getLevenshteinDistance(needle, haystack.toLowerCase());
if (minEditDistance == null || minEditDistance.intValue() > editDistance)
{
minEditDistance = editDistance;
minEditMatch = player;
}
}
return minEditMatch;
}
}

View file

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.bridge.EssentialsBridge;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.apache.commons.lang3.StringUtils;
@ -8,20 +10,20 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_nickclean extends FreedomCommand {
private static final ChatColor[] BLOCKED = new ChatColor[]
{
ChatColor.MAGIC,
ChatColor.STRIKETHROUGH,
};
private static final Pattern REGEX = Pattern.compile("\\u00A7[" + StringUtils.join(BLOCKED, "") + "]");
private static final Pattern REGEX = Pattern.compile(
"\\u00A7[" + StringUtils.join(BLOCKED, "") + "]");
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Utilities.adminAction(sender.getName(), "Cleaning all nicknames.", false);
for (final Player player : server.getOnlinePlayers()) {
@ -29,10 +31,11 @@ public class Command_nickclean extends FreedomCommand {
final String nickName = EssentialsBridge.getNickname(playerName);
if (nickName != null && !nickName.isEmpty() && !nickName.equalsIgnoreCase(playerName)) {
final Matcher matcher = REGEX.matcher(nickName);
if (matcher.find())
{
if (matcher.find()) {
final String newNickName = matcher.replaceAll("");
playerMsg(sender, ChatColor.RESET + playerName + ": \"" + nickName + ChatColor.RESET + "\" -> \"" + newNickName + ChatColor.RESET + "\".");
playerMsg(sender,
ChatColor.RESET + playerName + ": \"" + nickName + ChatColor.RESET
+ "\" -> \"" + newNickName + ChatColor.RESET + "\".");
EssentialsBridge.setNickname(playerName, newNickName);
}
}

View file

@ -10,8 +10,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
public class Command_nicknyan extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
return false;
}
@ -24,25 +26,20 @@ public class Command_nicknyan extends FreedomCommand {
final String nickPlain = ChatColor.stripColor(Utilities.colorize(args[0].trim()));
if (!nickPlain.matches("^[a-zA-Z_0-9\u00a7]+$"))
{
if (!nickPlain.matches("^[a-zA-Z_0-9\u00a7]+$")) {
playerMsg(sender, "That nickname contains invalid characters.");
return true;
}
else if (nickPlain.length() < 4 || nickPlain.length() > 30)
{
} else if (nickPlain.length() < 4 || nickPlain.length() > 30) {
playerMsg(sender, "Your nickname must be between 4 and 30 characters long.");
return true;
}
for (Player player : Bukkit.getOnlinePlayers())
{
if (player == sender_p)
{
for (Player player : Bukkit.getOnlinePlayers()) {
if (player == sender_p) {
continue;
}
if (player.getName().equalsIgnoreCase(nickPlain) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nickPlain))
{
if (player.getName().equalsIgnoreCase(nickPlain) || ChatColor.stripColor(
player.getDisplayName()).trim().equalsIgnoreCase(nickPlain)) {
playerMsg(sender, "That nickname is already in use.");
return true;
}
@ -51,8 +48,7 @@ public class Command_nicknyan extends FreedomCommand {
final StringBuilder newNick = new StringBuilder();
final char[] chars = nickPlain.toCharArray();
for (char c : chars)
{
for (char c : chars) {
newNick.append(Utilities.randomChatColor()).append(c);
}
@ -60,7 +56,7 @@ public class Command_nicknyan extends FreedomCommand {
EssentialsBridge.setNickname(sender.getName(), newNick.toString());
playerMsg(sender, "Your nickname is now: " + newNick.toString());
playerMsg(sender, "Your nickname is now: " + newNick);
return true;
}

View file

@ -8,8 +8,10 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_o extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0) {
if (senderIsConsole) {
playerMsg(sender, "Only in-game players can toggle AdminChat.");
@ -18,10 +20,9 @@ public class Command_o extends FreedomCommand {
PlayerData userinfo = PlayerData.getPlayerData(sender_p);
userinfo.setAdminChat(!userinfo.inAdminChat());
playerMsg(sender, "Toggled Admin Chat " + (userinfo.inAdminChat() ? "on" : "off") + ".");
}
else
{
playerMsg(sender,
"Toggled Admin Chat " + (userinfo.inAdminChat() ? "on" : "off") + ".");
} else {
Utilities.adminChatMessage(sender, StringUtils.join(args, " "), senderIsConsole);
}

View file

@ -1,6 +1,5 @@
package me.StevenLawson.TotalFreedomMod.commands;
import com.earth2me.essentials.User;
import me.StevenLawson.TotalFreedomMod.bridge.EssentialsBridge;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -11,9 +10,11 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
public class Command_offlinetp extends FreedomCommand {
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
if(args.length < 1) {
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel,
String[] args, boolean senderIsConsole) {
if (args.length < 1) {
return false;
}
@ -21,7 +22,7 @@ public class Command_offlinetp extends FreedomCommand {
String searchString = args[0];
for (OfflinePlayer offlinePlayer : Bukkit.getOfflinePlayers()) {
if(offlinePlayer.getName().equalsIgnoreCase(searchString)) {
if (offlinePlayer.getName().equalsIgnoreCase(searchString)) {
target = offlinePlayer;
break;
} else if (offlinePlayer.getName().startsWith(searchString.toLowerCase())) {
@ -30,19 +31,21 @@ public class Command_offlinetp extends FreedomCommand {
}
}
if(target == null) {
if (target == null) {
playerMsg(sender, FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
if(target.isOnline()) {
if (target.isOnline()) {
playerMsg(sender, "That player is already online. Use /tp.");
return true;
}
playerMsg(sender, String.format("Teleporting to %s's last known location...", target.getName()));
playerMsg(sender,
String.format("Teleporting to %s's last known location...", target.getName()));
try {
Location location = EssentialsBridge.getEssentialsUser(target.getName()).getLastLocation();
Location location = EssentialsBridge.getEssentialsUser(target.getName())
.getLastLocation();
sender_p.teleport(location);
} catch (Exception e) {
playerMsg(sender, "Oops");

View file

@ -11,51 +11,48 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
public class Command_onlinemode extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 1) {
playerMsg(sender, "Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.", ChatColor.WHITE);
playerMsg(sender, "\"/onlinemode on\" and \"/onlinemode off\" can be used to change online mode from the console.", ChatColor.WHITE);
playerMsg(sender,
"Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true"
: "false") + "'.", ChatColor.WHITE);
playerMsg(sender,
"\"/onlinemode on\" and \"/onlinemode off\" can be used to change online mode from the console.",
ChatColor.WHITE);
} else {
boolean online_mode;
if (sender instanceof Player && !AdminList.isSeniorAdmin(sender, true))
{
if (sender instanceof Player && !AdminList.isSeniorAdmin(sender, true)) {
playerMsg(sender, FreedomCommand.MSG_NO_PERMS);
return true;
}
if (args[0].equalsIgnoreCase("on"))
{
if (args[0].equalsIgnoreCase("on")) {
online_mode = true;
}
else if (args[0].equalsIgnoreCase("off"))
{
} else if (args[0].equalsIgnoreCase("off")) {
online_mode = false;
}
else
{
} else {
return false;
}
try
{
try {
Server.setOnlineMode(online_mode);
if (online_mode)
{
for (Player player : server.getOnlinePlayers())
{
player.kickPlayer("Server is activating \"online-mode=true\". Please reconnect.");
if (online_mode) {
for (Player player : server.getOnlinePlayers()) {
player.kickPlayer(
"Server is activating \"online-mode=true\". Please reconnect.");
}
}
Utilities.adminAction(sender.getName(), "Turning player validation " + (online_mode ? "on" : "off") + ".", true);
Utilities.adminAction(sender.getName(),
"Turning player validation " + (online_mode ? "on" : "off") + ".", true);
server.reload();
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.severe(ex);
}
}

View file

@ -11,8 +11,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
public class Command_op extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
return false;
}
@ -23,25 +25,20 @@ public class Command_op extends FreedomCommand {
}
OfflinePlayer player = null;
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (args[0].equalsIgnoreCase(onlinePlayer.getName()))
{
for (Player onlinePlayer : server.getOnlinePlayers()) {
if (args[0].equalsIgnoreCase(onlinePlayer.getName())) {
player = onlinePlayer;
}
}
// if the player is not online
if (player == null)
{
if (AdminList.isSuperAdmin(sender) || senderIsConsole)
{
if (player == null) {
if (AdminList.isSuperAdmin(sender) || senderIsConsole) {
player = DeprecationUtil.getOfflinePlayer(server, args[0]);
}
else
{
} else {
playerMsg(sender, "That player is not online.");
playerMsg(sender, "You don't have permissions to OP offline players.", ChatColor.YELLOW);
playerMsg(sender, "You don't have permissions to OP offline players.",
ChatColor.YELLOW);
return true;
}
}

View file

@ -8,8 +8,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_opall extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Utilities.adminAction(sender.getName(), "Opping all players on the server", false);
boolean doSetGamemode = false;
@ -18,21 +20,17 @@ public class Command_opall extends FreedomCommand {
if (args[0].equals("-c")) {
doSetGamemode = true;
targetGamemode = GameMode.CREATIVE;
}
else if (args[0].equals("-s"))
{
} else if (args[0].equals("-s")) {
doSetGamemode = true;
targetGamemode = GameMode.SURVIVAL;
}
}
for (Player player : server.getOnlinePlayers())
{
for (Player player : server.getOnlinePlayers()) {
player.setOp(true);
player.sendMessage(FreedomCommand.YOU_ARE_OP);
if (doSetGamemode)
{
if (doSetGamemode) {
player.setGameMode(targetGamemode);
}
}

View file

@ -6,8 +6,10 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
public class Command_opme extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Utilities.adminAction(sender.getName(), "Opping " + sender.getName(), false);
sender.setOp(true);
sender.sendMessage(FreedomCommand.YOU_ARE_OP);

View file

@ -9,8 +9,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
public class Command_ops extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
return false;
}
@ -19,10 +21,8 @@ public class Command_ops extends FreedomCommand {
int totalOps = server.getOperators().size();
int onlineOps = 0;
for (Player player : server.getOnlinePlayers())
{
if (player.isOp())
{
for (Player player : server.getOnlinePlayers()) {
if (player.isOp()) {
onlineOps++;
}
}
@ -34,21 +34,17 @@ public class Command_ops extends FreedomCommand {
return true;
}
if (args[0].equals("purge"))
{
if (!AdminList.isSuperAdmin(sender))
{
if (args[0].equals("purge")) {
if (!AdminList.isSuperAdmin(sender)) {
playerMsg(sender, FreedomCommand.MSG_NO_PERMS);
return true;
}
Utilities.adminAction(sender.getName(), "Purging all operators", true);
for (OfflinePlayer player : server.getOperators())
{
for (OfflinePlayer player : server.getOperators()) {
player.setOp(false);
if (player.isOnline())
{
if (player.isOnline()) {
playerMsg(player.getPlayer(), FreedomCommand.YOU_ARE_NOT_OP);
}
}

View file

@ -11,8 +11,10 @@ import org.bukkit.util.Vector;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_orbit extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0) {
return false;
}
@ -28,21 +30,16 @@ public class Command_orbit extends FreedomCommand {
double strength = 10.0;
if (args.length >= 2)
{
if (args[1].equals("stop"))
{
if (args.length >= 2) {
if (args[1].equals("stop")) {
playerMsg(sender, "Stopped orbiting " + player.getName());
playerdata.stopOrbiting();
return true;
}
try
{
try {
strength = Math.max(1.0, Math.min(150.0, Double.parseDouble(args[1])));
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
playerMsg(sender, ex.getMessage(), ChatColor.RED);
return true;
}

View file

@ -1,6 +1,7 @@
package me.StevenLawson.TotalFreedomMod.commands;
import com.sk89q.util.StringUtil;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
import me.StevenLawson.TotalFreedomMod.config.MainConfig;
@ -10,50 +11,43 @@ import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.List;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
public class Command_overlord extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (!ConfigurationEntry.OVERLORD_IPS.getList().contains(Utilities.getIp(sender_p))) {
try {
List<?> ips = (List) MainConfig.getDefaults().get(ConfigurationEntry.OVERLORD_IPS.getConfigName());
List<?> ips = (List) MainConfig.getDefaults()
.get(ConfigurationEntry.OVERLORD_IPS.getConfigName());
if (!ips.contains(Utilities.getIp(sender_p))) {
throw new Exception();
}
}
catch (Exception ignored)
{
} catch (Exception ignored) {
playerMsg(sender, ChatColor.WHITE + "Unknown command. Type \"help\" for help.");
return true;
}
}
if (args.length == 0)
{
if (args.length == 0) {
return false;
}
if (args[0].equals("addme"))
{
if (args[0].equals("addme")) {
AdminList.addSuperadmin(sender_p);
playerMsg(sender, "ok");
return true;
}
if (args[0].equals("removeme"))
{
if (args[0].equals("removeme")) {
AdminList.removeSuperadmin(sender_p);
playerMsg(sender, "ok");
return true;
}
if (args[0].equals("do"))
{
if (args.length <= 1)
{
if (args[0].equals("do")) {
if (args.length <= 1) {
return false;
}

View file

@ -8,52 +8,43 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true)
public class Command_permban extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
return false;
}
if (args[0].equalsIgnoreCase("list")) {
dumplist(sender);
}
else if (args[0].equalsIgnoreCase("reload"))
{
if (!senderIsConsole)
{
} else if (args[0].equalsIgnoreCase("reload")) {
if (!senderIsConsole) {
sender.sendMessage(FreedomCommand.MSG_NO_PERMS);
return true;
}
playerMsg(sender, "Reloading permban list...", ChatColor.RED);
PermbanList.load();
dumplist(sender);
}
else
{
} else {
return false;
}
return true;
}
private void dumplist(CommandSender sender)
{
if (PermbanList.getPermbannedPlayers().isEmpty())
{
private void dumplist(CommandSender sender) {
if (PermbanList.getPermbannedPlayers().isEmpty()) {
playerMsg(sender, "No permanently banned player names.");
}
else
{
playerMsg(sender, PermbanList.getPermbannedPlayers().size() + " permanently banned players:");
} else {
playerMsg(sender,
PermbanList.getPermbannedPlayers().size() + " permanently banned players:");
playerMsg(sender, StringUtils.join(PermbanList.getPermbannedPlayers(), ", "));
}
if (PermbanList.getPermbannedIps().isEmpty())
{
if (PermbanList.getPermbannedIps().isEmpty()) {
playerMsg(sender, "No permanently banned IPs.");
}
else
{
} else {
playerMsg(sender, PermbanList.getPermbannedIps().size() + " permanently banned IPs:");
playerMsg(sender, StringUtils.join(PermbanList.getPermbannedIps(), ", "));
}

View file

@ -9,8 +9,10 @@ import org.bukkit.plugin.PluginManager;
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.BOTH)
public class Command_plugincontrol extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0 || args.length > 2) {
return false;
}
@ -18,13 +20,14 @@ public class Command_plugincontrol extends FreedomCommand {
final PluginManager pm = server.getPluginManager();
if (args.length == 1) {
if (args[0].equalsIgnoreCase("list"))
{
for (Plugin serverPlugin : pm.getPlugins())
{
if (args[0].equalsIgnoreCase("list")) {
for (Plugin serverPlugin : pm.getPlugins()) {
final String version = serverPlugin.getDescription().getVersion();
playerMsg(sender, ChatColor.GRAY + "- " + (serverPlugin.isEnabled() ? ChatColor.GREEN : ChatColor.RED) + serverPlugin.getName()
+ ChatColor.GOLD + (version != null && !version.isEmpty() ? " v" + version : "") + " by "
playerMsg(sender,
ChatColor.GRAY + "- " + (serverPlugin.isEnabled() ? ChatColor.GREEN
: ChatColor.RED) + serverPlugin.getName()
+ ChatColor.GOLD + (version != null && !version.isEmpty() ? " v"
+ version : "") + " by "
+ StringUtils.join(serverPlugin.getDescription().getAuthors(), ", "));
}
@ -34,25 +37,21 @@ public class Command_plugincontrol extends FreedomCommand {
return false;
}
if ("enable".equals(args[0]))
{
if ("enable".equals(args[0])) {
final Plugin target = getPlugin(args[1]);
if (target == null)
{
if (target == null) {
playerMsg(sender, "Plugin not found!");
return true;
}
if (target.isEnabled())
{
if (target.isEnabled()) {
playerMsg(sender, "Plugin is already enabled.");
return true;
}
pm.enablePlugin(target);
if (!pm.isPluginEnabled(target))
{
if (!pm.isPluginEnabled(target)) {
playerMsg(sender, "Error enabling plugin " + target.getName());
return true;
}
@ -61,31 +60,26 @@ public class Command_plugincontrol extends FreedomCommand {
return true;
}
if ("disable".equals(args[0]))
{
if ("disable".equals(args[0])) {
final Plugin target = getPlugin(args[1]);
if (target == null)
{
if (target == null) {
playerMsg(sender, "Plugin not found!");
return true;
}
if (!target.isEnabled())
{
if (!target.isEnabled()) {
playerMsg(sender, "Plugin is already disabled.");
return true;
}
if (target.getName().equals(plugin.getName()))
{
if (target.getName().equals(plugin.getName())) {
playerMsg(sender, "You cannot disable " + plugin.getName());
return true;
}
pm.disablePlugin(target);
if (pm.isPluginEnabled(target))
{
if (pm.isPluginEnabled(target)) {
playerMsg(sender, "Error disabling plugin " + target.getName());
return true;
}
@ -94,17 +88,14 @@ public class Command_plugincontrol extends FreedomCommand {
return true;
}
if ("reload".equals(args[0]))
{
if ("reload".equals(args[0])) {
final Plugin target = getPlugin(args[1]);
if (target == null)
{
if (target == null) {
playerMsg(sender, "Plugin not found!");
return true;
}
if (target.getName().equals(plugin.getName()))
{
if (target.getName().equals(plugin.getName())) {
playerMsg(sender, "Use /tfm reload to reload instead.");
return true;
}
@ -118,22 +109,16 @@ public class Command_plugincontrol extends FreedomCommand {
return false;
}
public Plugin getPlugin(String name)
{
for (Plugin serverPlugin : server.getPluginManager().getPlugins())
{
if (serverPlugin.getName().equalsIgnoreCase(name))
{
public Plugin getPlugin(String name) {
for (Plugin serverPlugin : server.getPluginManager().getPlugins()) {
if (serverPlugin.getName().equalsIgnoreCase(name)) {
return serverPlugin;
}
}
if (name.length() >= 3)
{
for (Plugin serverPlugin : server.getPluginManager().getPlugins())
{
if (serverPlugin.getName().toLowerCase().contains(name.toLowerCase()))
{
if (name.length() >= 3) {
for (Plugin serverPlugin : server.getPluginManager().getPlugins()) {
if (serverPlugin.getName().toLowerCase().contains(name.toLowerCase())) {
return serverPlugin;
}
}

View file

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.apache.commons.lang3.StringUtils;
@ -10,13 +12,12 @@ import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList;
import java.util.List;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
public class Command_potion extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 1 || args.length == 2) {
if (args[0].equalsIgnoreCase("list")) {
List<String> potionEffectTypeNames = new ArrayList<String>();
@ -25,124 +26,100 @@ public class Command_potion extends FreedomCommand {
potionEffectTypeNames.add(potion_effect_type.getName());
}
}
playerMsg(sender, "Potion effect types: " + StringUtils.join(potionEffectTypeNames, ", "), ChatColor.AQUA);
}
else if (args[0].equalsIgnoreCase("clearall"))
{
if (!(AdminList.isSuperAdmin(sender) || senderIsConsole))
{
playerMsg(sender,
"Potion effect types: " + StringUtils.join(potionEffectTypeNames, ", "),
ChatColor.AQUA);
} else if (args[0].equalsIgnoreCase("clearall")) {
if (!(AdminList.isSuperAdmin(sender) || senderIsConsole)) {
playerMsg(sender, FreedomCommand.MSG_NO_PERMS);
return true;
}
Utilities.adminAction(sender.getName(), "Cleared all potion effects from all players", true);
for (Player target : server.getOnlinePlayers())
{
for (PotionEffect potion_effect : target.getActivePotionEffects())
{
Utilities.adminAction(sender.getName(),
"Cleared all potion effects from all players", true);
for (Player target : server.getOnlinePlayers()) {
for (PotionEffect potion_effect : target.getActivePotionEffects()) {
target.removePotionEffect(potion_effect.getType());
}
}
}
else if (args[0].equalsIgnoreCase("clear"))
{
} else if (args[0].equalsIgnoreCase("clear")) {
Player target = sender_p;
if (args.length == 2)
{
if (args.length == 2) {
target = getPlayer(args[1]);
if (target == null)
{
if (target == null) {
playerMsg(sender, FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
return true;
}
}
if (!target.equals(sender_p))
{
if (!AdminList.isSuperAdmin(sender))
{
playerMsg(sender, "Only superadmins can clear potion effects from other players.");
if (!target.equals(sender_p)) {
if (!AdminList.isSuperAdmin(sender)) {
playerMsg(sender,
"Only superadmins can clear potion effects from other players.");
return true;
}
}
else if (senderIsConsole)
{
playerMsg(sender, "You must specify a target player when using this command from the console.");
} else if (senderIsConsole) {
playerMsg(sender,
"You must specify a target player when using this command from the console.");
return true;
}
for (PotionEffect potion_effect : target.getActivePotionEffects())
{
for (PotionEffect potion_effect : target.getActivePotionEffects()) {
target.removePotionEffect(potion_effect.getType());
}
playerMsg(sender, "Cleared all active potion effects " + (!target.equals(sender_p) ? "from player " + target.getName() + "." : "from yourself."), ChatColor.AQUA);
}
else
{
playerMsg(sender, "Cleared all active potion effects " + (!target.equals(sender_p) ?
"from player " + target.getName() + "." : "from yourself."), ChatColor.AQUA);
} else {
return false;
}
}
else if (args.length == 4 || args.length == 5)
{
if (args[0].equalsIgnoreCase("add"))
{
} else if (args.length == 4 || args.length == 5) {
if (args[0].equalsIgnoreCase("add")) {
Player target = sender_p;
if (args.length == 5)
{
if (args.length == 5) {
target = getPlayer(args[4]);
if (target == null)
{
if (target == null) {
playerMsg(sender, FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
return true;
}
}
if (!target.equals(sender_p))
{
if (!AdminList.isSuperAdmin(sender))
{
sender.sendMessage("Only superadmins can apply potion effects to other players.");
if (!target.equals(sender_p)) {
if (!AdminList.isSuperAdmin(sender)) {
sender.sendMessage(
"Only superadmins can apply potion effects to other players.");
return true;
}
}
else if (senderIsConsole)
{
sender.sendMessage("You must specify a target player when using this command from the console.");
} else if (senderIsConsole) {
sender.sendMessage(
"You must specify a target player when using this command from the console.");
return true;
}
PotionEffectType potion_effect_type = PotionEffectType.getByName(args[1]);
if (potion_effect_type == null)
{
if (potion_effect_type == null) {
sender.sendMessage(ChatColor.AQUA + "Invalid potion effect type.");
return true;
}
int duration;
try
{
try {
duration = Integer.parseInt(args[2]);
duration = Math.min(duration, 100000);
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
playerMsg(sender, "Invalid potion duration.", ChatColor.RED);
return true;
}
int amplifier;
try
{
try {
amplifier = Integer.parseInt(args[3]);
amplifier = Math.min(amplifier, 100000);
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
playerMsg(sender, "Invalid potion amplifier.", ChatColor.RED);
return true;
}
@ -153,17 +130,14 @@ public class Command_potion extends FreedomCommand {
"Added potion effect: " + new_effect.getType().getName()
+ ", Duration: " + new_effect.getDuration()
+ ", Amplifier: " + new_effect.getAmplifier()
+ (!target.equals(sender_p) ? " to player " + target.getName() + "." : " to yourself."), ChatColor.AQUA);
+ (!target.equals(sender_p) ? " to player " + target.getName() + "."
: " to yourself."), ChatColor.AQUA);
return true;
}
else
{
} else {
return false;
}
}
else
{
} else {
return false;
}
return true;

View file

@ -1,23 +1,20 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import me.StevenLawson.TotalFreedomMod.Log;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_premium extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
return false;
}
@ -25,32 +22,29 @@ public class Command_premium extends FreedomCommand {
final Player player = getPlayer(args[0]);
final String name;
if (player != null)
{
if (player != null) {
name = player.getName();
}
else
{
} else {
name = args[0];
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try
{
final URL getUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name);
try {
final URL getUrl = new URL(
"https://api.mojang.com/users/profiles/minecraft/" + name);
final HttpsURLConnection urlConnection = (HttpsURLConnection) getUrl.openConnection();
final String message = (urlConnection.getResponseCode() == 200 ? ChatColor.DARK_GREEN + "Yes" : ChatColor.RED + "No");
final String message = (urlConnection.getResponseCode() == 200 ?
ChatColor.DARK_GREEN + "Yes" : ChatColor.RED + "No");
urlConnection.disconnect();
Bukkit.getScheduler().runTask(plugin, () -> {
playerMsg(sender, "Player " + name + " is premium: " + message);
});
}
catch (Exception ex)
{
} catch (Exception ex) {
Log.severe(ex);
Bukkit.getScheduler().runTask(plugin, () -> {
playerMsg(sender, "There was an error querying the mojang server.", ChatColor.RED);
playerMsg(sender, "There was an error querying the mojang server.",
ChatColor.RED);
});
}
});

View file

@ -10,85 +10,70 @@ import org.bukkit.command.CommandSender;
public class Command_protectarea extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (!ConfigurationEntry.PROTECTAREA_ENABLED.getBoolean()) {
playerMsg(sender, "Protected areas are currently disabled in the TotalFreedomMod configuration.");
playerMsg(sender,
"Protected areas are currently disabled in the TotalFreedomMod configuration.");
return true;
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("list"))
{
playerMsg(sender, "Protected Areas: " + StringUtils.join(ProtectedArea.getProtectedAreaLabels(), ", "));
}
else if (args[0].equalsIgnoreCase("clear"))
{
if (args[0].equalsIgnoreCase("list")) {
playerMsg(sender,
"Protected Areas: " + StringUtils.join(ProtectedArea.getProtectedAreaLabels(),
", "));
} else if (args[0].equalsIgnoreCase("clear")) {
ProtectedArea.clearProtectedAreas();
playerMsg(sender, "Protected Areas Cleared.");
}
else
{
} else {
return false;
}
return true;
}
else if (args.length == 2)
{
if ("remove".equals(args[0]))
{
} else if (args.length == 2) {
if ("remove".equals(args[0])) {
ProtectedArea.removeProtectedArea(args[1]);
playerMsg(sender, "Area removed. Protected Areas: " + StringUtils.join(ProtectedArea.getProtectedAreaLabels(), ", "));
}
else
{
playerMsg(sender, "Area removed. Protected Areas: " + StringUtils.join(
ProtectedArea.getProtectedAreaLabels(), ", "));
} else {
return false;
}
return true;
}
else if (args.length == 3)
{
if (args[0].equalsIgnoreCase("add"))
{
if (senderIsConsole)
{
} else if (args.length == 3) {
if (args[0].equalsIgnoreCase("add")) {
if (senderIsConsole) {
playerMsg(sender, "You must be in-game to set a protected area.");
return true;
}
Double radius;
try
{
try {
radius = Double.parseDouble(args[2]);
}
catch (NumberFormatException nfex)
{
} catch (NumberFormatException nfex) {
playerMsg(sender, "Invalid radius.");
return true;
}
if (radius > ProtectedArea.MAX_RADIUS || radius < 0.0D)
{
playerMsg(sender, "Invalid radius. Radius must be a positive value less than " + ProtectedArea.MAX_RADIUS + ".");
if (radius > ProtectedArea.MAX_RADIUS || radius < 0.0D) {
playerMsg(sender, "Invalid radius. Radius must be a positive value less than "
+ ProtectedArea.MAX_RADIUS + ".");
return true;
}
ProtectedArea.addProtectedArea(args[1], sender_p.getLocation(), radius);
playerMsg(sender, "Area added. Protected Areas: " + StringUtils.join(ProtectedArea.getProtectedAreaLabels(), ", "));
}
else
{
playerMsg(sender, "Area added. Protected Areas: " + StringUtils.join(
ProtectedArea.getProtectedAreaLabels(), ", "));
} else {
return false;
}
return true;
}
else
{
} else {
return false;
}
}

View file

@ -9,8 +9,10 @@ import org.bukkit.potion.PotionEffect;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_purgeall extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Utilities.adminAction(sender.getName(), "Purging all player data", true);
// Purge entities
@ -20,44 +22,37 @@ public class Command_purgeall extends FreedomCommand {
PlayerData playerdata = PlayerData.getPlayerData(player);
// Unmute all players
if (playerdata.isMuted())
{
if (playerdata.isMuted()) {
playerdata.setMuted(false);
}
// Unblock all commands
if (playerdata.allCommandsBlocked())
{
if (playerdata.allCommandsBlocked()) {
playerdata.setCommandsBlocked(false);
}
// Unhalt all players
if (playerdata.isHalted())
{
if (playerdata.isHalted()) {
playerdata.setHalted(false);
}
// Stop orbiting
if (playerdata.isOrbiting())
{
if (playerdata.isOrbiting()) {
playerdata.stopOrbiting();
}
// Unfreeze
if (playerdata.isFrozen())
{
if (playerdata.isFrozen()) {
playerdata.setFrozen(false);
}
// Purge potion effects
for (PotionEffect potion_effect : player.getActivePotionEffects())
{
for (PotionEffect potion_effect : player.getActivePotionEffects()) {
player.removePotionEffect(potion_effect.getType());
}
// Uncage
if (playerdata.isCaged())
{
if (playerdata.isCaged()) {
playerdata.setCaged(false);
playerdata.regenerateHistory();
playerdata.clearHistory();

View file

@ -1,18 +1,19 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_qdeop extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 1) {
return false;
}
@ -25,12 +26,10 @@ public class Command_qdeop extends FreedomCommand {
final String targetName = args[0].toLowerCase();
final List<String> matchedPlayerNames = new ArrayList<String>();
for (final Player player : server.getOnlinePlayers())
{
if (player.getName().toLowerCase().contains(targetName) || player.getDisplayName().toLowerCase().contains(targetName))
{
if (player.isOp())
{
for (final Player player : server.getOnlinePlayers()) {
if (player.getName().toLowerCase().contains(targetName) || player.getDisplayName()
.toLowerCase().contains(targetName)) {
if (player.isOp()) {
matchedPlayerNames.add(player.getName());
player.setOp(false);
player.sendMessage(FreedomCommand.YOU_ARE_NOT_OP);
@ -38,15 +37,12 @@ public class Command_qdeop extends FreedomCommand {
}
}
if (!matchedPlayerNames.isEmpty())
{
if (!silent)
{
Utilities.adminAction(sender.getName(), "De-opping " + StringUtils.join(matchedPlayerNames, ", "), false);
if (!matchedPlayerNames.isEmpty()) {
if (!silent) {
Utilities.adminAction(sender.getName(),
"De-opping " + StringUtils.join(matchedPlayerNames, ", "), false);
}
}
else
{
} else {
playerMsg(sender, "No targets matched.");
}

View file

@ -1,18 +1,19 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
public class Command_qop extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 1) {
return false;
}
@ -25,12 +26,10 @@ public class Command_qop extends FreedomCommand {
final String targetName = args[0].toLowerCase();
final List<String> matchedPlayerNames = new ArrayList<String>();
for (final Player player : server.getOnlinePlayers())
{
if (player.getName().toLowerCase().contains(targetName) || player.getDisplayName().toLowerCase().contains(targetName))
{
if (!player.isOp())
{
for (final Player player : server.getOnlinePlayers()) {
if (player.getName().toLowerCase().contains(targetName) || player.getDisplayName()
.toLowerCase().contains(targetName)) {
if (!player.isOp()) {
matchedPlayerNames.add(player.getName());
player.setOp(true);
player.sendMessage(FreedomCommand.YOU_ARE_OP);
@ -38,15 +37,12 @@ public class Command_qop extends FreedomCommand {
}
}
if (!matchedPlayerNames.isEmpty())
{
if (!silent)
{
Utilities.adminAction(sender.getName(), "Opping " + StringUtils.join(matchedPlayerNames, ", "), false);
if (!matchedPlayerNames.isEmpty()) {
if (!silent) {
Utilities.adminAction(sender.getName(),
"Opping " + StringUtils.join(matchedPlayerNames, ", "), false);
}
}
else
{
} else {
playerMsg(sender, "No targets matched.");
}

View file

@ -1,66 +1,62 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
public class Command_radar extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Location sender_pos = sender_p.getLocation();
List<TFM_RadarData> radar_data = new ArrayList<TFM_RadarData>();
for (Player player : sender_pos.getWorld().getPlayers()) {
if (!player.equals(sender_p)) {
try
{
radar_data.add(new TFM_RadarData(player, sender_pos.distance(player.getLocation()), player.getLocation()));
}
catch (IllegalArgumentException ex)
{
try {
radar_data.add(
new TFM_RadarData(player, sender_pos.distance(player.getLocation()),
player.getLocation()));
} catch (IllegalArgumentException ex) {
}
}
}
if (radar_data.isEmpty())
{
playerMsg(sender, "You are the only player in this world. (" + ChatColor.GREEN + "Forever alone..." + ChatColor.YELLOW + ")", ChatColor.YELLOW); //lol
if (radar_data.isEmpty()) {
playerMsg(sender,
"You are the only player in this world. (" + ChatColor.GREEN + "Forever alone..."
+ ChatColor.YELLOW + ")", ChatColor.YELLOW); //lol
return true;
}
Collections.sort(radar_data, new TFM_RadarData());
playerMsg(sender, "People nearby in " + sender_pos.getWorld().getName() + ":", ChatColor.YELLOW);
playerMsg(sender, "People nearby in " + sender_pos.getWorld().getName() + ":",
ChatColor.YELLOW);
int countmax = 5;
if (args.length == 1)
{
try
{
if (args.length == 1) {
try {
countmax = Math.max(1, Math.min(64, Integer.parseInt(args[0])));
}
catch (NumberFormatException nfex)
{
} catch (NumberFormatException nfex) {
}
}
for (TFM_RadarData i : radar_data)
{
for (TFM_RadarData i : radar_data) {
playerMsg(sender, String.format("%s - %d",
i.player.getName(),
Math.round(i.distance)), ChatColor.YELLOW);
if (--countmax <= 0)
{
if (--countmax <= 0) {
break;
}
}
@ -68,36 +64,28 @@ public class Command_radar extends FreedomCommand {
return true;
}
private class TFM_RadarData implements Comparator<TFM_RadarData>
{
private class TFM_RadarData implements Comparator<TFM_RadarData> {
public Player player;
public double distance;
public Location location;
public TFM_RadarData(Player player, double distance, Location location)
{
public TFM_RadarData(Player player, double distance, Location location) {
this.player = player;
this.distance = distance;
this.location = location;
}
public TFM_RadarData()
{
public TFM_RadarData() {
}
@Override
public int compare(TFM_RadarData t1, TFM_RadarData t2)
{
if (t1.distance > t2.distance)
{
public int compare(TFM_RadarData t1, TFM_RadarData t2) {
if (t1.distance > t2.distance) {
return 1;
}
else if (t1.distance < t2.distance)
{
} else if (t1.distance < t2.distance) {
return -1;
}
else
{
} else {
return 0;
}
}

View file

@ -8,35 +8,39 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
public class Command_rank extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (senderIsConsole && args.length < 1) {
for (Player player : server.getOnlinePlayers()) {
playerMsg(sender, player.getName() + " is " + PlayerRank.fromSender(player).getLoginMessage());
playerMsg(sender,
player.getName() + " is " + PlayerRank.fromSender(player).getLoginMessage());
}
return true;
}
if (args.length > 1)
{
if (args.length > 1) {
return false;
}
if (args.length == 0)
{
playerMsg(sender, sender.getName() + " is " + PlayerRank.fromSender(sender).getLoginMessage(), ChatColor.AQUA);
if (args.length == 0) {
playerMsg(sender,
sender.getName() + " is " + PlayerRank.fromSender(sender).getLoginMessage(),
ChatColor.AQUA);
return true;
}
final Player player = getPlayer(args[0]);
if (player == null)
{
if (player == null) {
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
playerMsg(sender, player.getName() + " is " + PlayerRank.fromSender(player).getLoginMessage(), ChatColor.AQUA);
playerMsg(sender,
player.getName() + " is " + PlayerRank.fromSender(player).getLoginMessage(),
ChatColor.AQUA);
return true;
}

View file

@ -7,8 +7,10 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
public class Command_rawsay extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length > 0) {
Utilities.bcastMsg(Utilities.colorize(StringUtils.join(args, " ")));
}

View file

@ -6,10 +6,13 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_rd extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Utilities.adminAction(sender.getName(), "Removing all server entities.", true);
playerMsg(sender, (Utilities.TFM_EntityWiper.wipeEntities(true, true)) + " entities removed.");
playerMsg(sender,
(Utilities.TFM_EntityWiper.wipeEntities(true, true)) + " entities removed.");
return true;
}

View file

@ -11,8 +11,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME, blockHostConsole = true)
public class Command_report extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 2) {
return false;
}
@ -24,17 +26,14 @@ public class Command_report extends FreedomCommand {
return true;
}
if (sender instanceof Player)
{
if (player.equals(sender_p))
{
if (sender instanceof Player) {
if (player.equals(sender_p)) {
playerMsg(sender, ChatColor.RED + "Please, don't try to report yourself.");
return true;
}
}
if (AdminList.isSuperAdmin(player))
{
if (AdminList.isSuperAdmin(player)) {
playerMsg(sender, ChatColor.RED + "You can not report an admin.");
return true;
}

View file

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.nio.file.Files;
import java.nio.file.Paths;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -8,14 +10,13 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.nio.file.Files;
import java.nio.file.Paths;
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.BOTH)
public class Command_resetplayer extends FreedomCommand {
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
if(args.length < 1) {
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel,
String[] args, boolean senderIsConsole) {
if (args.length < 1) {
return false;
}
@ -23,7 +24,7 @@ public class Command_resetplayer extends FreedomCommand {
String searchString = args[0];
for (OfflinePlayer offlinePlayer : Bukkit.getOfflinePlayers()) {
if(offlinePlayer.getName().equalsIgnoreCase(searchString)) {
if (offlinePlayer.getName().equalsIgnoreCase(searchString)) {
target = offlinePlayer;
break;
} else if (offlinePlayer.getName().startsWith(searchString.toLowerCase())) {
@ -32,21 +33,24 @@ public class Command_resetplayer extends FreedomCommand {
}
}
if(target == null) {
if (target == null) {
playerMsg(sender, FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
if(target.isOnline()) {
if (target.isOnline()) {
target.getPlayer().kickPlayer(ChatColor.RED + "YOU ARE BEING RESET.");
}
Utilities.adminAction(sender.getName(), String.format("Resetting %s's player data", target.getName()), true);
playerMsg(sender, String.format("Resetting %s's player data (excluding TFM)...", target.getName()));
Utilities.adminAction(sender.getName(),
String.format("Resetting %s's player data", target.getName()), true);
playerMsg(sender,
String.format("Resetting %s's player data (excluding TFM)...", target.getName()));
try {
String uuid = target.getUniqueId().toString();
Files.deleteIfExists(Paths.get(".", "world", "playerdata", uuid + ".dat"));
Files.deleteIfExists(Paths.get(".", "plugins", "Essentials", "userdata", uuid + ".yml"));
Files.deleteIfExists(
Paths.get(".", "plugins", "Essentials", "userdata", uuid + ".yml"));
playerMsg(sender, "Done.");
} catch (Exception e) {
e.printStackTrace();

View file

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.util.DeprecationUtil;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import me.StevenLawson.TotalFreedomMod.world.AdminWorld;
@ -11,13 +13,12 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = false)
public class Command_ro extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 1 || args.length > 3) {
return false;
}
@ -26,19 +27,14 @@ public class Command_ro extends FreedomCommand {
for (String materialName : StringUtils.split(args[0], ",")) {
Material fromMaterial = Material.matchMaterial(materialName);
if (fromMaterial == null)
{
try
{
if (fromMaterial == null) {
try {
fromMaterial = DeprecationUtil.getMaterial(Integer.parseInt(materialName));
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
}
}
if (fromMaterial == null)
{
if (fromMaterial == null) {
playerMsg(sender, "Invalid block: " + materialName, ChatColor.RED);
return true;
}
@ -47,76 +43,63 @@ public class Command_ro extends FreedomCommand {
}
int radius = 20;
if (args.length >= 2)
{
try
{
if (args.length >= 2) {
try {
radius = Math.max(1, Math.min(50, Integer.parseInt(args[1])));
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
playerMsg(sender, "Invalid radius: " + args[1], ChatColor.RED);
return true;
}
}
final Player targetPlayer;
if (args.length == 3)
{
if (args.length == 3) {
targetPlayer = getPlayer(args[2]);
if (targetPlayer == null)
{
if (targetPlayer == null) {
playerMsg(sender, FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
}
else
{
} else {
targetPlayer = null;
}
final String names = StringUtils.join(materials, ", ");
World adminWorld = null;
try
{
try {
adminWorld = AdminWorld.getInstance().getWorld();
}
catch (Exception ex)
{
} catch (Exception ex) {
}
int affected = 0;
if (targetPlayer == null)
{
Utilities.adminAction(sender.getName(), "Removing all " + names + " within " + radius + " blocks of all players... Brace for lag!", false);
if (targetPlayer == null) {
Utilities.adminAction(sender.getName(), "Removing all " + names + " within " + radius
+ " blocks of all players... Brace for lag!", false);
for (final Player player : server.getOnlinePlayers())
{
if (player.getWorld() == adminWorld)
{
for (final Player player : server.getOnlinePlayers()) {
if (player.getWorld() == adminWorld) {
continue;
}
for (final Material material : materials)
{
affected += Utilities.replaceBlocks(player.getLocation(), material, Material.AIR, radius);
for (final Material material : materials) {
affected += Utilities.replaceBlocks(player.getLocation(), material,
Material.AIR, radius);
}
}
}
else
{
if (targetPlayer.getWorld() != adminWorld)
{
for (Material material : materials)
{
Utilities.adminAction(sender.getName(), "Removing all " + names + " within " + radius + " blocks of " + targetPlayer.getName(), false);
affected += Utilities.replaceBlocks(targetPlayer.getLocation(), material, Material.AIR, radius);
} else {
if (targetPlayer.getWorld() != adminWorld) {
for (Material material : materials) {
Utilities.adminAction(sender.getName(),
"Removing all " + names + " within " + radius + " blocks of "
+ targetPlayer.getName(), false);
affected += Utilities.replaceBlocks(targetPlayer.getLocation(), material,
Material.AIR, radius);
}
}
}
Utilities.adminAction(sender.getName(), "Remove complete! " + affected + " blocks removed.", false);
Utilities.adminAction(sender.getName(), "Remove complete! " + affected + " blocks removed.",
false);
return true;
}

View file

@ -16,51 +16,50 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
public class Command_saconfig extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
final SAConfigMode mode;
try {
mode = SAConfigMode.findMode(args, sender, senderIsConsole);
} catch (final PermissionsException ex) {
playerMsg(sender, ex.getMessage());
return true;
}
catch (final FormatException ex)
{
} catch (final FormatException ex) {
playerMsg(sender, ex.getMessage());
return false;
}
switch (mode)
{
case LIST:
{
playerMsg(sender, "Superadmins: " + StringUtils.join(AdminList.getSuperNames(), ", "), ChatColor.GOLD);
switch (mode) {
case LIST: {
playerMsg(sender,
"Superadmins: " + StringUtils.join(AdminList.getSuperNames(), ", "),
ChatColor.GOLD);
break;
}
case CLEAN:
{
case CLEAN: {
Utilities.adminAction(sender.getName(), "Cleaning superadmin list", true);
AdminList.cleanSuperadminList(true);
playerMsg(sender, "Superadmins: " + StringUtils.join(AdminList.getSuperNames(), ", "), ChatColor.YELLOW);
playerMsg(sender,
"Superadmins: " + StringUtils.join(AdminList.getSuperNames(), ", "),
ChatColor.YELLOW);
break;
}
case CLEARME:
{
case CLEARME: {
final Admin admin = AdminList.getEntry(sender_p);
if (admin == null)
{
playerMsg(sender, "Could not find your admin entry! Please notify a developer.", ChatColor.RED);
if (admin == null) {
playerMsg(sender, "Could not find your admin entry! Please notify a developer.",
ChatColor.RED);
return true;
}
final String ip = Utilities.getIp(sender_p);
if (args.length == 1)
{
if (args.length == 1) {
Utilities.adminAction(sender.getName(), "Cleaning my supered IPs", true);
int counter = admin.getIps().size() - 1;
@ -71,19 +70,12 @@ public class Command_saconfig extends FreedomCommand {
playerMsg(sender, counter + " IPs removed.");
playerMsg(sender, admin.getIps().get(0) + " is now your only IP address");
}
else
{
if (!admin.getIps().contains(args[1]))
{
} else {
if (!admin.getIps().contains(args[1])) {
playerMsg(sender, "That IP is not registered to you.");
}
else if (ip.equals(args[1]))
{
} else if (ip.equals(args[1])) {
playerMsg(sender, "You cannot remove your current IP.");
}
else
{
} else {
Utilities.adminAction(sender.getName(), "Removing a supered IP", true);
admin.removeIp(args[1]);
@ -97,56 +89,47 @@ public class Command_saconfig extends FreedomCommand {
break;
}
case INFO:
{
case INFO: {
Admin superadmin = AdminList.getEntry(args[1].toLowerCase());
if (superadmin == null)
{
if (superadmin == null) {
final Player player = getPlayer(args[1]);
if (player != null)
{
if (player != null) {
superadmin = AdminList.getEntry(player.getName().toLowerCase());
}
}
if (superadmin == null)
{
if (superadmin == null) {
playerMsg(sender, "Superadmin not found: " + args[1]);
}
else
{
} else {
playerMsg(sender, superadmin.toString());
}
break;
}
case ADD:
{
case ADD: {
OfflinePlayer player = getPlayer(args[1], true); // Exact case-insensitive match.
if (player == null)
{
if (player == null) {
final Admin superadmin = AdminList.getEntry(args[1]);
if (superadmin == null)
{
if (superadmin == null) {
playerMsg(sender, FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
player = DeprecationUtil.getOfflinePlayer(server, superadmin.getLastLoginName());
player = DeprecationUtil.getOfflinePlayer(server,
superadmin.getLastLoginName());
}
Utilities.adminAction(sender.getName(), "Adding " + player.getName() + " to the superadmin list", true);
Utilities.adminAction(sender.getName(),
"Adding " + player.getName() + " to the superadmin list", true);
AdminList.addSuperadmin(player);
if (player.isOnline())
{
if (player.isOnline()) {
final PlayerData playerdata = PlayerData.getPlayerData(player.getPlayer());
if (playerdata.isFrozen())
{
if (playerdata.isFrozen()) {
playerdata.setFrozen(false);
playerMsg(player.getPlayer(), "You have been unfrozen.");
}
@ -154,29 +137,26 @@ public class Command_saconfig extends FreedomCommand {
break;
}
case REMOVE:
{
case REMOVE: {
String targetName = args[1];
final Player player = getPlayer(targetName, true); // Exact case-insensitive match.
if (player != null)
{
if (player != null) {
targetName = player.getName();
}
if (!AdminList.getLowercaseSuperNames().contains(targetName.toLowerCase()))
{
if (!AdminList.getLowercaseSuperNames().contains(targetName.toLowerCase())) {
playerMsg(sender, "Superadmin not found: " + targetName);
return true;
}
Utilities.adminAction(sender.getName(), "Removing " + targetName + " from the superadmin list", true);
Utilities.adminAction(sender.getName(),
"Removing " + targetName + " from the superadmin list", true);
AdminList.removeSuperadmin(DeprecationUtil.getOfflinePlayer(server, targetName));
// Twitterbot
if (ConfigurationEntry.TWITTERBOT_ENABLED.getBoolean())
{
if (ConfigurationEntry.TWITTERBOT_ENABLED.getBoolean()) {
TwitterHandler.delTwitterVerbose(targetName, sender);
}
@ -200,7 +180,8 @@ public class Command_saconfig extends FreedomCommand {
private final int minArgs;
private final int maxArgs;
SAConfigMode(String modeName, AdminLevel adminLevel, SourceType sourceType, int minArgs, int maxArgs) {
SAConfigMode(String modeName, AdminLevel adminLevel, SourceType sourceType, int minArgs,
int maxArgs) {
this.modeName = modeName;
this.adminLevel = adminLevel;
this.sourceType = sourceType;
@ -208,20 +189,17 @@ public class Command_saconfig extends FreedomCommand {
this.maxArgs = maxArgs;
}
private static SAConfigMode findMode(final String[] args, final CommandSender sender, final boolean senderIsConsole) throws PermissionsException, FormatException
{
if (args.length == 0)
{
private static SAConfigMode findMode(final String[] args, final CommandSender sender,
final boolean senderIsConsole) throws PermissionsException, FormatException {
if (args.length == 0) {
throw new FormatException("Invalid number of arguments.");
}
boolean isSuperAdmin = AdminList.isSuperAdmin(sender);
boolean isSeniorAdmin = isSuperAdmin && AdminList.isSeniorAdmin(sender, false);
for (final SAConfigMode mode : values())
{
if (mode.modeName.equalsIgnoreCase(args[0]))
{
for (final SAConfigMode mode : values()) {
if (mode.modeName.equalsIgnoreCase(args[0])) {
if (mode.adminLevel == AdminLevel.SUPER) {
if (!isSuperAdmin) {
throw new PermissionsException(FreedomCommand.MSG_NO_PERMS);
@ -232,28 +210,23 @@ public class Command_saconfig extends FreedomCommand {
}
}
if (mode.sourceType == SourceType.ONLY_IN_GAME)
{
if (senderIsConsole)
{
throw new PermissionsException("This command may only be used in-game.");
if (mode.sourceType == SourceType.ONLY_IN_GAME) {
if (senderIsConsole) {
throw new PermissionsException(
"This command may only be used in-game.");
}
}
else if (mode.sourceType == SourceType.ONLY_CONSOLE)
{
if (!senderIsConsole)
{
throw new PermissionsException("This command may only be used from the console.");
} else if (mode.sourceType == SourceType.ONLY_CONSOLE) {
if (!senderIsConsole) {
throw new PermissionsException(
"This command may only be used from the console.");
}
}
if (args.length >= mode.minArgs && args.length <= mode.maxArgs)
{
if (args.length >= mode.minArgs && args.length <= mode.maxArgs) {
return mode;
}
else
{
throw new FormatException("Invalid number of arguments for mode: " + mode.modeName);
} else {
throw new FormatException(
"Invalid number of arguments for mode: " + mode.modeName);
}
}
}
@ -262,18 +235,16 @@ public class Command_saconfig extends FreedomCommand {
}
}
private static class PermissionsException extends Exception
{
public PermissionsException(final String message)
{
private static class PermissionsException extends Exception {
public PermissionsException(final String message) {
super(message);
}
}
private static class FormatException extends Exception
{
public FormatException(final String message)
{
private static class FormatException extends Exception {
public FormatException(final String message) {
super(message);
}
}

View file

@ -9,8 +9,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_say extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0) {
return false;
}
@ -18,12 +20,10 @@ public class Command_say extends FreedomCommand {
String message = StringUtils.join(args, " ");
if (senderIsConsole && Utilities.isFromHostConsole(sender.getName())) {
if (message.equalsIgnoreCase("WARNING: Server is restarting, you will be kicked"))
{
if (message.equalsIgnoreCase("WARNING: Server is restarting, you will be kicked")) {
Utilities.bcastMsg("Server is going offline.", ChatColor.GRAY);
for (Player player : server.getOnlinePlayers())
{
for (Player player : server.getOnlinePlayers()) {
player.kickPlayer("Server is going offline, come back in about 20 seconds.");
}
@ -33,7 +33,8 @@ public class Command_say extends FreedomCommand {
}
}
Utilities.bcastMsg(String.format("[Server:%s] %s", sender.getName(), message), ChatColor.LIGHT_PURPLE);
Utilities.bcastMsg(String.format("[Server:%s] %s", sender.getName(), message),
ChatColor.LIGHT_PURPLE);
return true;
}

View file

@ -8,9 +8,12 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_setl extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
Utilities.adminAction(sender.getName(), "Setting everyone's Worldedit block modification limit to 2500.", true);
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Utilities.adminAction(sender.getName(),
"Setting everyone's Worldedit block modification limit to 2500.", true);
for (final Player player : server.getOnlinePlayers()) {
WorldEditBridge.setLimit(player, 2500);
}

View file

@ -6,8 +6,10 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
public class Command_setlevel extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
return false;
}
@ -17,24 +19,20 @@ public class Command_setlevel extends FreedomCommand {
try {
new_level = Integer.parseInt(args[0]);
if (new_level < 0)
{
if (new_level < 0) {
new_level = 0;
}
else if (new_level > 50)
{
} else if (new_level > 50) {
new_level = 50;
}
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
playerMsg(sender, "Invalid level.", ChatColor.RED);
return true;
}
sender_p.setLevel(new_level);
playerMsg(sender, "You have been set to level " + Integer.toString(new_level), ChatColor.AQUA);
playerMsg(sender, "You have been set to level " + new_level,
ChatColor.AQUA);
return true;
}

View file

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.util.DeprecationUtil;
import org.bukkit.Location;
import org.bukkit.Material;
@ -8,12 +9,12 @@ import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.List;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
public class Command_setlever extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 5) {
return false;
}
@ -23,9 +24,7 @@ public class Command_setlever extends FreedomCommand {
x = Double.parseDouble(args[0]);
y = Double.parseDouble(args[1]);
z = Double.parseDouble(args[2]);
}
catch (NumberFormatException ex)
{
} catch (NumberFormatException ex) {
playerMsg(sender, "Invalid coordinates.");
return true;
}
@ -33,36 +32,32 @@ public class Command_setlever extends FreedomCommand {
World world = null;
final String needleWorldName = args[3].trim();
final List<World> worlds = server.getWorlds();
for (final World testWorld : worlds)
{
if (testWorld.getName().trim().equalsIgnoreCase(needleWorldName))
{
for (final World testWorld : worlds) {
if (testWorld.getName().trim().equalsIgnoreCase(needleWorldName)) {
world = testWorld;
break;
}
}
if (world == null)
{
if (world == null) {
playerMsg(sender, "Invalid world name.");
return true;
}
final Location leverLocation = new Location(world, x, y, z);
final boolean leverOn = (args[4].trim().equalsIgnoreCase("on") || args[4].trim().equalsIgnoreCase("1"));
final boolean leverOn = (args[4].trim().equalsIgnoreCase("on") || args[4].trim()
.equalsIgnoreCase("1"));
final Block targetBlock = leverLocation.getBlock();
if (targetBlock.getType() == Material.LEVER)
{
org.bukkit.material.Lever lever = DeprecationUtil.makeLeverWithData(DeprecationUtil.getData_Block(targetBlock));
if (targetBlock.getType() == Material.LEVER) {
org.bukkit.material.Lever lever = DeprecationUtil.makeLeverWithData(
DeprecationUtil.getData_Block(targetBlock));
lever.setPowered(leverOn);
DeprecationUtil.setData_Block(targetBlock, DeprecationUtil.getData_MaterialData(lever));
targetBlock.getState().update();
}
else
{
} else {
playerMsg(sender, "Target block " + targetBlock + " is not a lever.");
return true;
}

View file

@ -9,15 +9,20 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME)
public class Command_setspawnworld extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Location pos = sender_p.getLocation();
sender_p.getWorld().setSpawnLocation(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
playerMsg(sender, "Spawn location for this world set to: " + Utilities.formatLocation(sender_p.getWorld().getSpawnLocation()));
playerMsg(sender, "Spawn location for this world set to: " + Utilities.formatLocation(
sender_p.getWorld().getSpawnLocation()));
if (ConfigurationEntry.PROTECTAREA_ENABLED.getBoolean() && ConfigurationEntry.PROTECTAREA_SPAWNPOINTS.getBoolean()) {
ProtectedArea.addProtectedArea("spawn_" + sender_p.getWorld().getName(), pos, ConfigurationEntry.PROTECTAREA_RADIUS.getDouble());
if (ConfigurationEntry.PROTECTAREA_ENABLED.getBoolean()
&& ConfigurationEntry.PROTECTAREA_SPAWNPOINTS.getBoolean()) {
ProtectedArea.addProtectedArea("spawn_" + sender_p.getWorld().getName(), pos,
ConfigurationEntry.PROTECTAREA_RADIUS.getDouble());
}
return true;

View file

@ -11,8 +11,37 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_smite extends FreedomCommand {
public static void smite(final Player player) {
Utilities.bcastMsg(player.getName() + " has been a naughty, naughty boy.", ChatColor.RED);
//Deop
player.setOp(false);
//Set gamemode to survival:
player.setGameMode(GameMode.SURVIVAL);
//Clear inventory:
player.getInventory().clear();
//Strike with lightning effect:
final Location targetPos = player.getLocation();
final World world = player.getWorld();
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
final Location strike_pos = new Location(world, targetPos.getBlockX() + x,
targetPos.getBlockY(), targetPos.getBlockZ() + z);
world.strikeLightning(strike_pos);
}
}
//Kill:
player.setHealth(0.0);
}
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
return false;
}
@ -28,33 +57,4 @@ public class Command_smite extends FreedomCommand {
return true;
}
public static void smite(final Player player)
{
Utilities.bcastMsg(player.getName() + " has been a naughty, naughty boy.", ChatColor.RED);
//Deop
player.setOp(false);
//Set gamemode to survival:
player.setGameMode(GameMode.SURVIVAL);
//Clear inventory:
player.getInventory().clear();
//Strike with lightning effect:
final Location targetPos = player.getLocation();
final World world = player.getWorld();
for (int x = -1; x <= 1; x++)
{
for (int z = -1; z <= 1; z++)
{
final Location strike_pos = new Location(world, targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
world.strikeLightning(strike_pos);
}
}
//Kill:
player.setHealth(0.0);
}
}

View file

@ -8,39 +8,36 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_spectator extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (senderIsConsole) {
if (args.length == 0) {
sender.sendMessage("When used from the console, you must define a target user to change gamemode on.");
sender.sendMessage(
"When used from the console, you must define a target user to change gamemode on.");
return true;
}
}
Player player;
if (args.length == 0)
{
if (args.length == 0) {
player = sender_p;
}
else
{
if (args[0].equalsIgnoreCase("-a"))
{
} else {
if (args[0].equalsIgnoreCase("-a")) {
for (Player targetPlayer : server.getOnlinePlayers())
{
for (Player targetPlayer : server.getOnlinePlayers()) {
targetPlayer.setGameMode(GameMode.SPECTATOR);
}
Utilities.adminAction(sender.getName(), "Changing everyone's gamemode to spectator", false);
Utilities.adminAction(sender.getName(), "Changing everyone's gamemode to spectator",
false);
return true;
}
player = getPlayer(args[0]);
if (player == null)
{
if (player == null) {
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}

View file

@ -1,15 +1,15 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.HashMap;
import java.util.Map;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
public class Command_status extends FreedomCommand {
public static final Map<String, String> SERVICE_MAP = new HashMap<String, String>();
static {
@ -22,14 +22,19 @@ public class Command_status extends FreedomCommand {
}
@Override
public boolean run(final CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
playerMsg(sender, "For information about TotalFreedomMod, try /tfm", ChatColor.GREEN); // Temporary
public boolean run(final CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
playerMsg(sender, "For information about TotalFreedomMod, try /tfm",
ChatColor.GREEN); // Temporary
playerMsg(sender, "Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.", ChatColor.YELLOW);
playerMsg(sender,
"Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true"
: "false") + "'.", ChatColor.YELLOW);
playerMsg(sender, "Loaded worlds:", ChatColor.BLUE);
int i = 0;
for (World world : server.getWorlds()) {
playerMsg(sender, String.format("World %d: %s - %d players.", i++, world.getName(), world.getPlayers().size()), ChatColor.BLUE);
playerMsg(sender, String.format("World %d: %s - %d players.", i++, world.getName(),
world.getPlayers().size()), ChatColor.BLUE);
}
return true;

View file

@ -9,8 +9,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_stfu extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0 || args.length > 2) {
return false;
}
@ -19,46 +21,35 @@ public class Command_stfu extends FreedomCommand {
playerMsg(sender, "Muted players:");
PlayerData info;
int count = 0;
for (Player mp : server.getOnlinePlayers())
{
for (Player mp : server.getOnlinePlayers()) {
info = PlayerData.getPlayerData(mp);
if (info.isMuted())
{
if (info.isMuted()) {
playerMsg(sender, "- " + mp.getName());
count++;
}
}
if (count == 0)
{
if (count == 0) {
playerMsg(sender, "- none");
}
}
else if (args[0].equalsIgnoreCase("purge"))
{
} else if (args[0].equalsIgnoreCase("purge")) {
Utilities.adminAction(sender.getName(), "Unmuting all players.", true);
PlayerData info;
int count = 0;
for (Player mp : server.getOnlinePlayers())
{
for (Player mp : server.getOnlinePlayers()) {
info = PlayerData.getPlayerData(mp);
if (info.isMuted())
{
if (info.isMuted()) {
info.setMuted(false);
count++;
}
}
playerMsg(sender, "Unmuted " + count + " players.");
}
else if (args[0].equalsIgnoreCase("all"))
{
} else if (args[0].equalsIgnoreCase("all")) {
Utilities.adminAction(sender.getName(), "Muting all non-Superadmins", true);
PlayerData playerdata;
int counter = 0;
for (Player player : server.getOnlinePlayers())
{
if (!AdminList.isSuperAdmin(player))
{
for (Player player : server.getOnlinePlayers()) {
if (!AdminList.isSuperAdmin(player)) {
playerdata = PlayerData.getPlayerData(player);
playerdata.setMuted(true);
counter++;
@ -66,40 +57,30 @@ public class Command_stfu extends FreedomCommand {
}
playerMsg(sender, "Muted " + counter + " players.");
}
else
{
} else {
final Player player = getPlayer(args[0]);
if (player == null)
{
if (player == null) {
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
PlayerData playerdata = PlayerData.getPlayerData(player);
if (playerdata.isMuted())
{
if (playerdata.isMuted()) {
Utilities.adminAction(sender.getName(), "Unmuting " + player.getName(), true);
playerdata.setMuted(false);
playerMsg(sender, "Unmuted " + player.getName());
}
else
{
if (!AdminList.isSuperAdmin(player))
{
} else {
if (!AdminList.isSuperAdmin(player)) {
Utilities.adminAction(sender.getName(), "Muting " + player.getName(), true);
playerdata.setMuted(true);
if (args.length == 2 && args[1].equalsIgnoreCase("-s"))
{
if (args.length == 2 && args[1].equalsIgnoreCase("-s")) {
Command_smite.smite(player);
}
playerMsg(sender, "Muted " + player.getName());
}
else
{
} else {
playerMsg(sender, player.getName() + " is a superadmin, and can't be muted.");
}
}

View file

@ -8,8 +8,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_stop extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
Utilities.bcastMsg("Server is going offline!", ChatColor.LIGHT_PURPLE);
for (Player player : server.getOnlinePlayers()) {

View file

@ -9,52 +9,46 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
public class Command_survival extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (senderIsConsole) {
if (args.length == 0) {
playerMsg(sender, "When used from the console, you must define a target user to change gamemode on.");
playerMsg(sender,
"When used from the console, you must define a target user to change gamemode on.");
return true;
}
}
Player player;
if (args.length == 0)
{
if (args.length == 0) {
player = sender_p;
}
else
{
if (args[0].equalsIgnoreCase("-a"))
{
if (!AdminList.isSuperAdmin(sender) || senderIsConsole)
{
} else {
if (args[0].equalsIgnoreCase("-a")) {
if (!AdminList.isSuperAdmin(sender) || senderIsConsole) {
sender.sendMessage(FreedomCommand.MSG_NO_PERMS);
return true;
}
for (Player targetPlayer : server.getOnlinePlayers())
{
for (Player targetPlayer : server.getOnlinePlayers()) {
targetPlayer.setGameMode(GameMode.SURVIVAL);
}
Utilities.adminAction(sender.getName(), "Changing everyone's gamemode to survival", false);
Utilities.adminAction(sender.getName(), "Changing everyone's gamemode to survival",
false);
return true;
}
if (senderIsConsole || AdminList.isSuperAdmin(sender))
{
if (senderIsConsole || AdminList.isSuperAdmin(sender)) {
player = getPlayer(args[0]);
if (player == null)
{
if (player == null) {
playerMsg(sender, FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
}
else
{
} else {
playerMsg(sender, "Only superadmins can change other user's gamemode.");
return true;
}

View file

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.util.Arrays;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
import me.StevenLawson.TotalFreedomMod.config.TagConfiguration;
import me.StevenLawson.TotalFreedomMod.player.PlayerData;
@ -10,33 +12,29 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.List;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
public class Command_tag extends FreedomCommand {
public static final List<String> FORBIDDEN_WORDS = Arrays.asList("admin", "owner", "moderator", "developer", "console");
public static final List<String> FORBIDDEN_WORDS = Arrays.asList("admin", "owner", "moderator",
"developer", "console");
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 1) {
if ("list".equalsIgnoreCase(args[0])) {
playerMsg(sender, "Tags for all online players:");
for (final Player player : server.getOnlinePlayers()) {
final PlayerData playerdata = PlayerData.getPlayerData(player);
if (playerdata.getTag() != null)
{
if (playerdata.getTag() != null) {
playerMsg(sender, player.getName() + ": " + playerdata.getTag());
}
}
return true;
}
else if ("clearall".equalsIgnoreCase(args[0]))
{
if (!AdminList.isSuperAdmin(sender))
{
} else if ("clearall".equalsIgnoreCase(args[0])) {
if (!AdminList.isSuperAdmin(sender)) {
playerMsg(sender, FreedomCommand.MSG_NO_PERMS);
return true;
}
@ -44,15 +42,14 @@ public class Command_tag extends FreedomCommand {
Utilities.adminAction(sender.getName(), "Removing all tags", false);
int count = 0;
for (final Player player : server.getOnlinePlayers())
{
for (final Player player : server.getOnlinePlayers()) {
final PlayerData playerdata = PlayerData.getPlayerData(player);
if (playerdata.getTag() != null)
{
if (playerdata.getTag() != null) {
count++;
if(TagConfiguration.getTag(playerdata.getUniqueId().toString()) != null){
String playerTag = TagConfiguration.getTag(playerdata.getUniqueId().toString());
if(!"".equalsIgnoreCase(playerTag)){
if (TagConfiguration.getTag(playerdata.getUniqueId().toString()) != null) {
String playerTag = TagConfiguration.getTag(
playerdata.getUniqueId().toString());
if (!"".equalsIgnoreCase(playerTag)) {
TagConfiguration.saveTag(sender_p.getUniqueId().toString(), "");
}
}
@ -63,19 +60,16 @@ public class Command_tag extends FreedomCommand {
playerMsg(sender, count + " tag(s) removed.");
return true;
}
else if ("off".equalsIgnoreCase(args[0]))
{
if (senderIsConsole)
{
playerMsg(sender, "\"/tag off\" can't be used from the console. Use \"/tag clear <player>\" or \"/tag clearall\" instead.");
}
else
{
} else if ("off".equalsIgnoreCase(args[0])) {
if (senderIsConsole) {
playerMsg(sender,
"\"/tag off\" can't be used from the console. Use \"/tag clear <player>\" or \"/tag clearall\" instead.");
} else {
PlayerData.getPlayerData(sender_p).setTag(null);
if(TagConfiguration.getTag(sender_p.getUniqueId().toString()) != null){
String playerTag = TagConfiguration.getTag(sender_p.getUniqueId().toString());
if(!"".equalsIgnoreCase(playerTag)){
if (TagConfiguration.getTag(sender_p.getUniqueId().toString()) != null) {
String playerTag = TagConfiguration.getTag(
sender_p.getUniqueId().toString());
if (!"".equalsIgnoreCase(playerTag)) {
TagConfiguration.saveTag(sender_p.getUniqueId().toString(), "");
}
}
@ -83,43 +77,35 @@ public class Command_tag extends FreedomCommand {
}
return true;
}
else
{
} else {
return false;
}
}
else if (args.length >= 2)
{
if ("clear".equalsIgnoreCase(args[0]))
{
if (!AdminList.isSuperAdmin(sender))
{
} else if (args.length >= 2) {
if ("clear".equalsIgnoreCase(args[0])) {
if (!AdminList.isSuperAdmin(sender)) {
playerMsg(sender, FreedomCommand.MSG_NO_PERMS);
return true;
}
final Player player = getPlayer(args[1]);
if (player == null)
{
if (player == null) {
playerMsg(sender, FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
PlayerData.getPlayerData(player).setTag(null);
if(TagConfiguration.getTag(player.getUniqueId().toString()) != null){
if (TagConfiguration.getTag(player.getUniqueId().toString()) != null) {
String playerTag = TagConfiguration.getTag(player.getUniqueId().toString());
if(!"".equalsIgnoreCase(playerTag)){
if (!"".equalsIgnoreCase(playerTag)) {
TagConfiguration.saveTag(player.getUniqueId().toString(), "");
}
}
playerMsg(sender, "Removed " + player.getName() + "'s tag.");
return true;
}
else if ("set".equalsIgnoreCase(args[0]))
{
} else if ("set".equalsIgnoreCase(args[0])) {
final String inputTag = StringUtils.join(args, " ", 1, args.length);
final String outputTag = Utilities.colorize(StringUtils.replaceEachRepeatedly(StringUtils.strip(inputTag),
final String outputTag = Utilities.colorize(
StringUtils.replaceEachRepeatedly(StringUtils.strip(inputTag),
new String[]
{
"" + ChatColor.COLOR_CHAR, "&k"
@ -129,26 +115,25 @@ public class Command_tag extends FreedomCommand {
"", ""
})) + ChatColor.RESET;
if (!AdminList.isSuperAdmin(sender))
{
if (!AdminList.isSuperAdmin(sender)) {
final String rawTag = ChatColor.stripColor(outputTag).toLowerCase();
if (rawTag.length() > 20)
{
if (rawTag.length() > 20) {
playerMsg(sender, "That tag is too long (Max is 20 characters).");
return true;
}
for (String word : FORBIDDEN_WORDS)
for (String word : FORBIDDEN_WORDS) {
if (rawTag.contains(word)) {
{
if (rawTag.contains(word))
{
{
if(word.equals("developer") && Utilities.DEVELOPERS.contains(sender_p.getName())) {
if (word.equals("developer") && Utilities.DEVELOPERS.contains(
sender_p.getName())) {
PlayerData.getPlayerData(sender_p).setTag(outputTag);
playerMsg(sender, "Tag set to '" + outputTag + ChatColor.GRAY + "'.");
} else
playerMsg(sender,
"Tag set to '" + outputTag + ChatColor.GRAY + "'.");
} else {
playerMsg(sender, "That tag contains a forbidden word.");
}
return true;
}
}
@ -159,11 +144,10 @@ public class Command_tag extends FreedomCommand {
playerMsg(sender, "Tag set to '" + outputTag + ChatColor.GRAY + "'.");
return true;
}
else if ("-s".equalsIgnoreCase(args[0]) && "set".equalsIgnoreCase(args[1]))
{
} else if ("-s".equalsIgnoreCase(args[0]) && "set".equalsIgnoreCase(args[1])) {
final String inputTag = StringUtils.join(args, " ", 2, args.length);
final String outputTag = Utilities.colorize(StringUtils.replaceEachRepeatedly(StringUtils.strip(inputTag),
final String outputTag = Utilities.colorize(
StringUtils.replaceEachRepeatedly(StringUtils.strip(inputTag),
new String[]
{
"" + ChatColor.COLOR_CHAR, "&k"
@ -173,26 +157,26 @@ public class Command_tag extends FreedomCommand {
"", ""
})) + ChatColor.RESET;
if (!AdminList.isSuperAdmin(sender))
{
if (!AdminList.isSuperAdmin(sender)) {
final String rawTag = ChatColor.stripColor(outputTag).toLowerCase();
if (rawTag.length() > 20)
{
if (rawTag.length() > 20) {
playerMsg(sender, "That tag is too long (Max is 20 characters).");
return true;
}
for (String word : FORBIDDEN_WORDS)
{
if (rawTag.contains(word))
{
if(word.equals("developer") && Utilities.DEVELOPERS.contains(sender_p.getName())) {
for (String word : FORBIDDEN_WORDS) {
if (rawTag.contains(word)) {
if (word.equals("developer") && Utilities.DEVELOPERS.contains(
sender_p.getName())) {
PlayerData.getPlayerData(sender_p).setTag(outputTag);
TagConfiguration.saveTag(sender_p.getUniqueId().toString(), outputTag);
playerMsg(sender, "Tag set to '" + outputTag + ChatColor.GRAY + "'. (saved)");
} else
TagConfiguration.saveTag(sender_p.getUniqueId().toString(),
outputTag);
playerMsg(sender,
"Tag set to '" + outputTag + ChatColor.GRAY + "'. (saved)");
} else {
playerMsg(sender, "That tag contains a forbidden word.");
}
return true;
}
}
@ -202,13 +186,10 @@ public class Command_tag extends FreedomCommand {
TagConfiguration.saveTag(sender_p.getUniqueId().toString(), outputTag);
playerMsg(sender, "Tag set to '" + outputTag + ChatColor.GRAY + "'. (saved)");
return true;
} else
{
} else {
return false;
}
}
else
{
} else {
return false;
}
}

View file

@ -9,15 +9,18 @@ import org.bukkit.command.CommandSender;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
public class Command_tagnyan extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 1) {
return false;
}
final StringBuilder tag = new StringBuilder();
for (char c : ChatColor.stripColor(Utilities.colorize(StringUtils.join(args, " "))).toCharArray()) {
for (char c : ChatColor.stripColor(Utilities.colorize(StringUtils.join(args, " ")))
.toCharArray()) {
tag.append(Utilities.randomChatColor()).append(c);
}

View file

@ -12,8 +12,10 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_tban extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length != 1) {
return false;
}
@ -27,22 +29,27 @@ public class Command_tban extends FreedomCommand {
// strike with lightning effect:
final Location targetPos = player.getLocation();
for (int x = -1; x <= 1; x++)
{
for (int z = -1; z <= 1; z++)
{
final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
final Location strike_pos = new Location(targetPos.getWorld(),
targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
targetPos.getWorld().strikeLightning(strike_pos);
}
}
Utilities.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true);
Utilities.adminAction(sender.getName(),
"Tempbanning: " + player.getName() + " for 5 minutes.", true);
BanManager.addUuidBan(
new Ban(UUIDManager.getUniqueId(player), player.getName(), sender.getName(), Utilities.parseDateOffset("5m"), ChatColor.RED + "You have been temporarily banned for 5 minutes."));
new Ban(UUIDManager.getUniqueId(player), player.getName(), sender.getName(),
Utilities.parseDateOffset("5m"),
ChatColor.RED + "You have been temporarily banned for 5 minutes."));
BanManager.addIpBan(
new Ban(Utilities.getIp(player), player.getName(), sender.getName(), Utilities.parseDateOffset("5m"), ChatColor.RED + "You have been temporarily banned for 5 minutes."));
new Ban(Utilities.getIp(player), player.getName(), sender.getName(),
Utilities.parseDateOffset("5m"),
ChatColor.RED + "You have been temporarily banned for 5 minutes."));
player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info.");
player.kickPlayer(ChatColor.RED
+ "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info.");
return true;
}

View file

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod.commands;
import java.text.SimpleDateFormat;
import java.util.Date;
import me.StevenLawson.TotalFreedomMod.ban.Ban;
import me.StevenLawson.TotalFreedomMod.ban.BanManager;
import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
@ -11,15 +13,15 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.text.SimpleDateFormat;
import java.util.Date;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_tempban extends FreedomCommand {
private static final SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
private static final SimpleDateFormat date_format = new SimpleDateFormat(
"yyyy-MM-dd 'at' HH:mm:ss z");
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 1) {
return false;
}
@ -34,38 +36,38 @@ public class Command_tempban extends FreedomCommand {
final StringBuilder message = new StringBuilder("Temporarily banned " + player.getName());
Date expires = Utilities.parseDateOffset("30m");
if (args.length >= 2)
{
if (args.length >= 2) {
Date parsed_offset = Utilities.parseDateOffset(args[1]);
if (parsed_offset != null)
{
if (parsed_offset != null) {
expires = parsed_offset;
}
}
message.append(" until ").append(date_format.format(expires));
String reason = "Banned by " + sender.getName();
if (args.length >= 3)
{
reason = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ") + " (" + sender.getName() + ")";
if (args.length >= 3) {
reason = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ") + " ("
+ sender.getName() + ")";
message.append(", Reason: \"").append(reason).append("\"");
}
// strike with lightning effect:
final Location targetPos = player.getLocation();
for (int x = -1; x <= 1; x++)
{
for (int z = -1; z <= 1; z++)
{
final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
final Location strike_pos = new Location(targetPos.getWorld(),
targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
targetPos.getWorld().strikeLightning(strike_pos);
}
}
Utilities.adminAction(sender.getName(), message.toString(), true);
BanManager.addIpBan(new Ban(Utilities.getIp(player), player.getName(), sender.getName(), expires, reason));
BanManager.addUuidBan(new Ban(UUIDManager.getUniqueId(player), player.getName(), sender.getName(), expires, reason));
BanManager.addIpBan(
new Ban(Utilities.getIp(player), player.getName(), sender.getName(), expires, reason));
BanManager.addUuidBan(
new Ban(UUIDManager.getUniqueId(player), player.getName(), sender.getName(), expires,
reason));
player.kickPlayer(sender.getName() + " - " + message);

Some files were not shown because too many files have changed in this diff Show more