This commit is contained in:
Telesphoreo 2021-12-07 15:48:00 -06:00
commit 18e58efaff
329 changed files with 6207 additions and 7711 deletions

View file

@ -1,137 +0,0 @@
package me.totalfreedom.totalfreedommod;
import com.mattmalec.pterodactyl4j.Permission;
import com.mattmalec.pterodactyl4j.PowerAction;
import com.mattmalec.pterodactyl4j.PteroAction;
import com.mattmalec.pterodactyl4j.PteroBuilder;
import com.mattmalec.pterodactyl4j.application.entities.ApplicationUser;
import com.mattmalec.pterodactyl4j.application.entities.PteroApplication;
import com.mattmalec.pterodactyl4j.application.managers.UserAction;
import com.mattmalec.pterodactyl4j.client.entities.ClientServer;
import com.mattmalec.pterodactyl4j.client.entities.ClientSubuser;
import com.mattmalec.pterodactyl4j.client.entities.PteroClient;
import joptsimple.internal.Strings;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
public class Pterodactyl extends FreedomService
{
public final String URL = ConfigEntry.PTERO_URL.getString();
private final String ADMIN_KEY = ConfigEntry.PTERO_ADMIN_KEY.getString();
private final String CLIENT_KEY = ConfigEntry.PTERO_SERVER_KEY.getString();
private final String IDENTIFIER = ConfigEntry.PTERO_SERVER_UUID.getString();
PteroApplication adminAPI = PteroBuilder.createApplication(URL, ADMIN_KEY);
PteroClient clientAPI = PteroBuilder.createClient(URL, CLIENT_KEY);
private boolean enabled = !Strings.isNullOrEmpty(URL);
public void onStart()
{
}
public void onStop()
{
}
public void updateAccountStatus(Admin admin)
{
String id = admin.getPteroID();
if (Strings.isNullOrEmpty(id) || !enabled)
{
return;
}
if (!admin.isActive() || admin.getRank() != Rank.SENIOR_ADMIN)
{
FLog.debug("Disabling Pterodactyl account");
removeAccountFromServer(id);
return;
}
FLog.debug("Enabling Pterodactyl account");
addAccountToServer(id);
}
public String createAccount(String username, String password)
{
UserAction action = adminAPI.getUserManager().createUser()
.setUserName(username)
.setEmail(username.toLowerCase() + "@" + ConfigEntry.PTERO_DEFAULT_EMAIL_DOMAIN.getString())
.setFirstName(username)
.setLastName("\u200E") // Required - make it appear empty
.setPassword(password);
return action.execute().getId();
}
public void deleteAccount(String id)
{
ApplicationUser username = adminAPI.retrieveUserById(id).execute();
PteroAction<Void> action = adminAPI.getUserManager().deleteUser(username);
action.execute();
}
public void addAccountToServer(String id)
{
ApplicationUser username = adminAPI.retrieveUserById(id).execute();
String email = username.getEmail();
PteroAction<ClientServer> server = clientAPI.retrieveServerByIdentifier(IDENTIFIER);
server.execute().getSubuserManager().createUser()
.setEmail(email)
.setPermissions(Permission.CONTROL_PERMISSIONS).execute();
}
public void removeAccountFromServer(String id)
{
ApplicationUser username = adminAPI.retrieveUserById(id).execute();
PteroAction<ClientServer> server = clientAPI.retrieveServerByIdentifier(IDENTIFIER);
ClientSubuser clientSubuser = server.execute().getSubuser(username.getUUID()).retrieve().execute();
server.execute().getSubuserManager().deleteUser(clientSubuser).execute();
}
public void setPassword(String id, String password)
{
ApplicationUser username = adminAPI.retrieveUserById(id).execute();
UserAction action = adminAPI.getUserManager().editUser(username).setPassword(password);
action.execute();
}
public void restartServer()
{
clientAPI.retrieveServerByIdentifier(IDENTIFIER).flatMap(ClientServer::restart).execute();
}
public void fionnTheServer()
{
clientAPI.retrieveServerByIdentifier(IDENTIFIER).flatMap(ClientServer::stop).execute();
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, () -> clientAPI.retrieveServerByIdentifier(IDENTIFIER).flatMap(ClientServer::kill).execute(), 0, 60);
}
public String getURL()
{
return URL;
}
public String getServerKey()
{
return CLIENT_KEY;
}
public String getAdminKey()
{
return ADMIN_KEY;
}
public boolean isEnabled()
{
return enabled;
}
public void setEnabled(boolean enabled)
{
this.enabled = enabled;
}
}

View file

@ -1,98 +0,0 @@
package me.totalfreedom.totalfreedommod;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Map;
import me.totalfreedom.totalfreedommod.util.FLog;
import static me.totalfreedom.totalfreedommod.util.FUtil.SAVED_FLAGS_FILENAME;
public class SavedFlags extends FreedomService
{
@Override
public void onStart()
{
}
@Override
public void onStop()
{
}
@SuppressWarnings("unchecked")
public Map<String, Boolean> getSavedFlags()
{
Map<String, Boolean> flags = null;
File input = new File(TotalFreedomMod.getPlugin().getDataFolder(), SAVED_FLAGS_FILENAME);
if (input.exists())
{
try
{
try (FileInputStream fis = new FileInputStream(input); ObjectInputStream ois = new ObjectInputStream(fis))
{
flags = (HashMap<String, Boolean>)ois.readObject();
}
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
return flags;
}
public boolean getSavedFlag(String flag) throws Exception
{
Boolean flagValue = null;
Map<String, Boolean> flags = getSavedFlags();
if (flags != null)
{
if (flags.containsKey(flag))
{
flagValue = flags.get(flag);
}
}
if (flagValue != null)
{
return flagValue;
}
else
{
throw new Exception();
}
}
public void setSavedFlag(String flag, boolean value)
{
Map<String, Boolean> flags = getSavedFlags();
if (flags == null)
{
flags = new HashMap<>();
}
flags.put(flag, value);
try
{
final FileOutputStream fos = new FileOutputStream(new File(plugin.getDataFolder(), SAVED_FLAGS_FILENAME));
final ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(flags);
oos.close();
fos.close();
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
}

View file

@ -1,71 +0,0 @@
package me.totalfreedom.totalfreedommod;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
public class ServerInterface extends FreedomService
{
public static final String COMPILE_NMS_VERSION = "v1_17_R1";
public static void warnVersion()
{
final String nms = FUtil.getNMSVersion();
if (!COMPILE_NMS_VERSION.equals(nms))
{
FLog.warning(TotalFreedomMod.pluginName + " is compiled for " + COMPILE_NMS_VERSION + " but the server is running version " + nms + "!");
FLog.warning("This might result in unexpected behaviour!");
}
}
@Override
public void onStart()
{
}
@Override
public void onStop()
{
}
public int purgeWhitelist()
{
Set<OfflinePlayer> whitelisted = Bukkit.getWhitelistedPlayers();
int size = whitelisted.size();
for (OfflinePlayer player : Bukkit.getWhitelistedPlayers())
{
Bukkit.getServer().getWhitelistedPlayers().remove(player);
}
try
{
Bukkit.reloadWhitelist();
}
catch (Exception ex)
{
FLog.warning("Could not purge the whitelist!");
FLog.warning(ex);
}
return size;
}
public boolean isWhitelisted()
{
return Bukkit.getServer().hasWhitelist();
}
public List<?> getWhitelisted()
{
return Collections.singletonList(Bukkit.getWhitelistedPlayers());
}
public String getVersion()
{
return Bukkit.getVersion();
}
}

View file

@ -1,12 +1,18 @@
package me.totalfreedom.totalfreedommod; package me.totalfreedom.totalfreedommod;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Properties; import java.util.Properties;
import me.totalfreedom.totalfreedommod.admin.ActivityLog; import me.totalfreedom.totalfreedommod.admin.ActivityLog;
import me.totalfreedom.totalfreedommod.admin.AdminList; import me.totalfreedom.totalfreedommod.admin.AdminList;
import me.totalfreedom.totalfreedommod.banning.BanManager; import me.totalfreedom.totalfreedommod.admin.module.CommandSpy;
import me.totalfreedom.totalfreedommod.banning.IndefiniteBanList; import me.totalfreedom.totalfreedommod.admin.module.Fuckoff;
import me.totalfreedom.totalfreedommod.admin.module.Muter;
import me.totalfreedom.totalfreedommod.admin.module.Orbiter;
import me.totalfreedom.totalfreedommod.anticheat.AutoEject;
import me.totalfreedom.totalfreedommod.punishments.banning.BanManager;
import me.totalfreedom.totalfreedommod.punishments.banning.IndefiniteBanList;
import me.totalfreedom.totalfreedommod.blocking.BlockBlocker; import me.totalfreedom.totalfreedommod.blocking.BlockBlocker;
import me.totalfreedom.totalfreedommod.blocking.EditBlocker; import me.totalfreedom.totalfreedommod.blocking.EditBlocker;
import me.totalfreedom.totalfreedommod.blocking.EventBlocker; import me.totalfreedom.totalfreedommod.blocking.EventBlocker;
@ -23,39 +29,43 @@ import me.totalfreedom.totalfreedommod.bridge.LibsDisguisesBridge;
import me.totalfreedom.totalfreedommod.bridge.TFGuildsBridge; import me.totalfreedom.totalfreedommod.bridge.TFGuildsBridge;
import me.totalfreedom.totalfreedommod.bridge.WorldEditBridge; import me.totalfreedom.totalfreedommod.bridge.WorldEditBridge;
import me.totalfreedom.totalfreedommod.bridge.WorldGuardBridge; import me.totalfreedom.totalfreedommod.bridge.WorldGuardBridge;
import me.totalfreedom.totalfreedommod.caging.Cager; import me.totalfreedom.totalfreedommod.punishments.caging.Cager;
import me.totalfreedom.totalfreedommod.command.CommandLoader; import me.totalfreedom.totalfreedommod.command.CommandLoader;
import me.totalfreedom.totalfreedommod.config.MainConfig; import me.totalfreedom.totalfreedommod.config.MainConfig;
import me.totalfreedom.totalfreedommod.discord.Discord; import me.totalfreedom.totalfreedommod.discord.Discord;
import me.totalfreedom.totalfreedommod.freeze.Freezer; import me.totalfreedom.totalfreedommod.punishments.freeze.Freezer;
import me.totalfreedom.totalfreedommod.fun.ItemFun; import me.totalfreedom.totalfreedommod.fun.ItemFun;
import me.totalfreedom.totalfreedommod.fun.Jumppads; import me.totalfreedom.totalfreedommod.fun.Jumppads;
import me.totalfreedom.totalfreedommod.fun.Landminer; import me.totalfreedom.totalfreedommod.fun.Landminer;
import me.totalfreedom.totalfreedommod.fun.MP44; import me.totalfreedom.totalfreedommod.fun.MP44;
import me.totalfreedom.totalfreedommod.fun.Trailer; import me.totalfreedom.totalfreedommod.fun.Trailer;
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon; import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
import me.totalfreedom.totalfreedommod.permissions.PermissionConfig; import me.totalfreedom.totalfreedommod.anticheat.AntiNuke;
import me.totalfreedom.totalfreedommod.permissions.PermissionManager; import me.totalfreedom.totalfreedommod.anticheat.AntiSpam;
import me.totalfreedom.totalfreedommod.anticheat.AutoKick;
import me.totalfreedom.totalfreedommod.player.permissions.PermissionConfig;
import me.totalfreedom.totalfreedommod.player.permissions.PermissionManager;
import me.totalfreedom.totalfreedommod.player.PlayerList; import me.totalfreedom.totalfreedommod.player.PlayerList;
import me.totalfreedom.totalfreedommod.punishments.PunishmentList; import me.totalfreedom.totalfreedommod.punishments.PunishmentList;
import me.totalfreedom.totalfreedommod.rank.RankManager; import me.totalfreedom.totalfreedommod.rank.RankManager;
import me.totalfreedom.totalfreedommod.services.ServiceHandler;
import me.totalfreedom.totalfreedommod.services.impl.*;
import me.totalfreedom.totalfreedommod.shop.Shop; import me.totalfreedom.totalfreedommod.shop.Shop;
import me.totalfreedom.totalfreedommod.shop.Votifier; import me.totalfreedom.totalfreedommod.shop.Votifier;
import me.totalfreedom.totalfreedommod.sql.SQLite; import me.totalfreedom.totalfreedommod.sql.SQLite;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import me.totalfreedom.totalfreedommod.util.MethodTimer; import me.totalfreedom.totalfreedommod.util.MethodTimer;
import me.totalfreedom.totalfreedommod.world.CleanroomChunkGenerator; import me.totalfreedom.totalfreedommod.world.generator.CleanroomChunkGenerator;
import me.totalfreedom.totalfreedommod.world.WorldManager; import me.totalfreedom.totalfreedommod.world.WorldManager;
import me.totalfreedom.totalfreedommod.world.WorldRestrictions; import me.totalfreedom.totalfreedommod.world.WorldRestrictions;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.spigotmc.SpigotCommand;
import org.spigotmc.SpigotConfig;
public class TotalFreedomMod extends JavaPlugin public class TotalFreedomMod extends JavaPlugin
{ {
@ -66,76 +76,80 @@ public class TotalFreedomMod extends JavaPlugin
public static String pluginName; public static String pluginName;
public static String pluginVersion; public static String pluginVersion;
private static TotalFreedomMod plugin; private static TotalFreedomMod plugin;
private File spigotFile;
private YamlConfiguration spigotConfig;
// //
public MainConfig config; public MainConfig config;
public PermissionConfig permissions; public PermissionConfig permissions;
// //
// Service Handler // Service Handler
public FreedomServiceHandler fsh; public ServiceHandler serviceHandler;
// Command Loader // Command Loader
public CommandLoader cl; public CommandLoader commandLoader;
// Services // Services
public ServerInterface si; public ServerInterface serverInterface;
public SavedFlags sf; public WorldManager worldManager;
public WorldManager wm; public LogViewer logViewer;
public LogViewer lv; public AdminList adminList;
public AdminList al; public ActivityLog activityLog;
public ActivityLog acl; public RankManager rankManager;
public RankManager rm; public CommandBlocker commandBlocker;
public CommandBlocker cb; public EventBlocker eventBlocker;
public EventBlocker eb; public BlockBlocker blockBlocker;
public BlockBlocker bb; public MobBlocker mobBlocker;
public MobBlocker mb; public InteractBlocker interactBlocker;
public InteractBlocker ib; public PotionBlocker potionBlocker;
public PotionBlocker pb; public LoginProcess loginProcess;
public LoginProcess lp; public AntiNuke antiNuke;
public AntiNuke nu; public AntiSpam antiSpam;
public AntiSpam as; public PlayerList playerList;
public PlayerList pl; public Shop shop;
public Shop sh; public Votifier votifier;
public Votifier vo;
public SQLite sql; public SQLite sql;
public Announcer an; public Announcer announcer;
public ChatManager cm; public ChatHandler chatManager;
public Discord dc; public Discord discord;
public PunishmentList pul; public PunishmentList punishmentList;
public BanManager bm; public BanManager banManager;
public IndefiniteBanList im; public IndefiniteBanList indefiniteBanList;
public PermissionManager pem; public PermissionManager permissionManager;
public GameRuleHandler gr; public GameRuleHandler gameRuleHandler;
public CommandSpy cs; public CommandSpy commandSpy;
public Cager ca; public Cager cager;
public Freezer fm; public Freezer freezer;
public EditBlocker ebl; public EditBlocker editBlocker;
public PVPBlocker pbl; public PVPBlocker pvpBlocker;
public Orbiter or; public Orbiter orbiter;
public Muter mu; public Muter muter;
public Fuckoff fo; public Fuckoff fuckoff;
public AutoKick ak; public AutoKick autoKick;
public AutoEject ae; public AutoEject autoEject;
public Monitors mo; public Monitors monitors;
public MovementValidator mv; public MovementValidator movementValidator;
public ServerPing sp; public ServerPing serverPing;
public ItemFun it; public ItemFun itemFun;
public Landminer lm; public Landminer landMiner;
public MP44 mp; public MP44 mp44;
public Jumppads jp; public Jumppads jumpPads;
public Trailer tr; public Trailer trailer;
public HTTPDaemon hd; public HTTPDaemon httpDaemon;
public WorldRestrictions wr; public WorldRestrictions worldRestrictions;
public SignBlocker snp; public SignBlocker signBlocker;
public EntityWiper ew; public EntityWiper entityWiper;
public VanishHandler vh; public Sitter sitter;
public Pterodactyl ptero; public VanishHandler vanishHandler;
public Pterodactyl pterodactyl;
// //
// Bridges // Bridges
public BukkitTelnetBridge btb; public BukkitTelnetBridge bukkitTelnetBridge;
public EssentialsBridge esb; public EssentialsBridge essentialsBridge;
public LibsDisguisesBridge ldb; public LibsDisguisesBridge libsDisguisesBridge;
public CoreProtectBridge cpb; public CoreProtectBridge coreProtectBridge;
public TFGuildsBridge tfg; public TFGuildsBridge tfGuildsBridge;
public WorldEditBridge web; public WorldEditBridge worldEditBridge;
public WorldGuardBridge wgb; public WorldGuardBridge worldGuardBridge;
public static TotalFreedomMod getPlugin() public static TotalFreedomMod getPlugin()
{ {
@ -178,13 +192,13 @@ public class TotalFreedomMod extends JavaPlugin
timer.start(); timer.start();
// Warn if we're running on a wrong version // Warn if we're running on a wrong version
ServerInterface.warnVersion(); //ServerInterface.warnVersion();no more nms
// Delete unused files // Delete unused files
FUtil.deleteCoreDumps(); FUtil.deleteCoreDumps();
FUtil.deleteFolder(new File("./_deleteme")); FUtil.deleteFolder(new File("./_deleteme"));
fsh = new FreedomServiceHandler(); serviceHandler = new ServiceHandler();
config = new MainConfig(); config = new MainConfig();
config.load(); config.load();
@ -194,39 +208,53 @@ public class TotalFreedomMod extends JavaPlugin
FLog.debug("Developer mode enabled."); FLog.debug("Developer mode enabled.");
} }
cl = new CommandLoader(); commandLoader = new CommandLoader();
cl.loadCommands(); commandLoader.loadCommands();
BackupManager backups = new BackupManager(); BackupHandler backups = new BackupHandler();
backups.createAllBackups(); backups.createAllBackups();
permissions = new PermissionConfig(); permissions = new PermissionConfig();
permissions.load(); permissions.load();
mv = new MovementValidator(); movementValidator = new MovementValidator();
sp = new ServerPing(); serverPing = new ServerPing();
new Initializer(); new Initializer();
fsh.startServices(); serviceHandler.startServices();
FLog.info("Started " + fsh.getServiceAmount() + " services."); FLog.info("Started " + serviceHandler.getServiceAmount() + " services.");
timer.update(); timer.update();
FLog.info("Version " + pluginVersion + " for " + ServerInterface.COMPILE_NMS_VERSION + " enabled in " + timer.getTotal() + "ms"); FLog.info("Version " + pluginVersion + " for " + getServer().getBukkitVersion() + " enabled in " + timer.getTotal() + "ms");
// Metrics @ https://bstats.org/plugin/bukkit/TotalFreedomMod/2966 // Metrics @ https://bstats.org/plugin/bukkit/TotalFreedomMod/2966
new Metrics(this, 2966); new Metrics(this, 2966);
// Revert AMP changes // little workaround to stop spigot from autorestarting - causing AMP to detach from process.
SpigotConfig.config.set("settings.restart-on-crash", true); //SpigotConfig.config.set("settings.restart-on-crash", false);
this.spigotFile = new File(getServer().getWorldContainer(), "spigot.yml");
this.spigotConfig = YamlConfiguration.loadConfiguration(this.spigotFile);
this.spigotConfig.set("settings.restart-on-crash", false);
try {
this.spigotConfig.save(this.spigotFile);
} catch (IOException e) {
e.printStackTrace();
}
// Possibly could make it so after reloads, players regain their tag
Bukkit.getOnlinePlayers().forEach(player -> this.rankManager.updateDisplay(player));
} }
@Override @Override
public void onDisable() public void onDisable()
{ {
// Stop services and bridges // Stop services and bridges
fsh.stopServices(); serviceHandler.stopServices();
getServer().getScheduler().cancelTasks(plugin); getServer().getScheduler().cancelTasks(plugin);
@ -266,7 +294,7 @@ public class TotalFreedomMod extends JavaPlugin
number = props.getProperty("buildNumber", "1"); number = props.getProperty("buildNumber", "1");
date = props.getProperty("buildDate", "unknown"); date = props.getProperty("buildDate", "unknown");
// Need to do this or it will display ${git.commit.id.abbrev} // Need to do this or it will display ${git.commit.id.abbrev}
head = props.getProperty("buildHead", "unknown"); head = props.getProperty("buildHead", "unknown").replace("${git.commit.id.abbrev}", "unknown");
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -298,83 +326,100 @@ public class TotalFreedomMod extends JavaPlugin
private void initServices() private void initServices()
{ {
// Start services // Start services
si = new ServerInterface(); serverInterface = new ServerInterface();
sf = new SavedFlags(); gameRuleHandler = new GameRuleHandler();
wm = new WorldManager(); worldManager = new WorldManager();
lv = new LogViewer(); logViewer = new LogViewer();
sql = new SQLite(); sql = new SQLite();
al = new AdminList(); adminList = new AdminList();
acl = new ActivityLog(); activityLog = new ActivityLog();
rm = new RankManager(); rankManager = new RankManager();
cb = new CommandBlocker(); commandBlocker = new CommandBlocker();
eb = new EventBlocker(); eventBlocker = new EventBlocker();
bb = new BlockBlocker(); blockBlocker = new BlockBlocker();
mb = new MobBlocker(); mobBlocker = new MobBlocker();
ib = new InteractBlocker(); interactBlocker = new InteractBlocker();
pb = new PotionBlocker(); potionBlocker = new PotionBlocker();
lp = new LoginProcess(); loginProcess = new LoginProcess();
nu = new AntiNuke(); antiNuke = new AntiNuke();
as = new AntiSpam(); antiSpam = new AntiSpam();
wr = new WorldRestrictions(); playerList = new PlayerList();
pl = new PlayerList(); shop = new Shop();
sh = new Shop(); votifier = new Votifier();
vo = new Votifier(); announcer = new Announcer();
an = new Announcer(); chatManager = new ChatHandler();
cm = new ChatManager(); discord = new Discord();
dc = new Discord(); punishmentList = new PunishmentList();
pul = new PunishmentList(); banManager = new BanManager();
bm = new BanManager(); indefiniteBanList = new IndefiniteBanList();
im = new IndefiniteBanList(); permissionManager = new PermissionManager();
pem = new PermissionManager(); signBlocker = new SignBlocker();
gr = new GameRuleHandler(); entityWiper = new EntityWiper();
snp = new SignBlocker(); sitter = new Sitter();
ew = new EntityWiper(); vanishHandler = new VanishHandler();
vh = new VanishHandler(); pterodactyl = new Pterodactyl();
ptero = new Pterodactyl();
if (isPluginPresent("WorldGuard"))
worldRestrictions = new WorldRestrictions();
} }
private void initAdminUtils() private void initAdminUtils()
{ {
// Single admin utils // Single admin utils
cs = new CommandSpy(); commandSpy = new CommandSpy();
ca = new Cager(); cager = new Cager();
fm = new Freezer(); freezer = new Freezer();
or = new Orbiter(); orbiter = new Orbiter();
mu = new Muter(); muter = new Muter();
ebl = new EditBlocker(); editBlocker = new EditBlocker();
pbl = new PVPBlocker(); pvpBlocker = new PVPBlocker();
fo = new Fuckoff(); fuckoff = new Fuckoff();
ak = new AutoKick(); autoKick = new AutoKick();
ae = new AutoEject(); autoEject = new AutoEject();
mo = new Monitors(); monitors = new Monitors();
} }
private void initBridges() private void initBridges()
{ {
// Start bridges // Start bridges
btb = new BukkitTelnetBridge(); if (isPluginPresent("BukkitTelnet"))
cpb = new CoreProtectBridge(); bukkitTelnetBridge = new BukkitTelnetBridge();
esb = new EssentialsBridge(); if (isPluginPresent("CoreProtect"))
ldb = new LibsDisguisesBridge(); coreProtectBridge = new CoreProtectBridge();
tfg = new TFGuildsBridge(); if (isPluginPresent("WorldGuard"))
web = new WorldEditBridge(); worldGuardBridge = new WorldGuardBridge();
wgb = new WorldGuardBridge(); if (isPluginPresent("WorldEdit"))
worldEditBridge = new WorldEditBridge();
essentialsBridge = new EssentialsBridge();
libsDisguisesBridge = new LibsDisguisesBridge();
tfGuildsBridge = new TFGuildsBridge();
} }
private void initFun() private void initFun()
{ {
// Fun // Fun
it = new ItemFun(); itemFun = new ItemFun();
lm = new Landminer(); landMiner = new Landminer();
mp = new MP44(); mp44 = new MP44();
jp = new Jumppads(); jumpPads = new Jumppads();
tr = new Trailer(); trailer = new Trailer();
} }
private void initHTTPD() private void initHTTPD()
{ {
// HTTPD // HTTPD
hd = new HTTPDaemon(); httpDaemon = new HTTPDaemon();
}
private boolean isPluginPresent(String plugin)
{
return TotalFreedomMod.getPlugin().getServer().getPluginManager().isPluginEnabled(plugin);
} }
} }
public YamlConfiguration getSpigotConfig() {
return spigotConfig;
}
} }

View file

@ -1,8 +1,13 @@
package me.totalfreedom.totalfreedommod.admin; package me.totalfreedom.totalfreedommod.admin;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import java.time.Instant;
import java.util.Date;
import java.util.Map; import java.util.Map;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.config.YamlConfig; import me.totalfreedom.totalfreedommod.config.YamlConfig;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
@ -14,7 +19,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
public class ActivityLog extends FreedomService public class ActivityLog extends AbstractService
{ {
public static final String FILENAME = "activitylog.yml"; public static final String FILENAME = "activitylog.yml";
@ -170,23 +175,26 @@ public class ActivityLog extends FreedomService
public void onPlayerJoin(PlayerJoinEvent event) public void onPlayerJoin(PlayerJoinEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (plugin.al.isAdmin(player)) if (plugin.adminList.isAdmin(player))
{ {
getActivityLog(event.getPlayer()).addLogin(); getActivityLog(event.getPlayer()).addLogin();
plugin.acl.save(); plugin.activityLog.save();
plugin.acl.updateTables(); plugin.activityLog.updateTables();
} }
FPlayer fPlayer = plugin.playerList.getPlayer(player);
fPlayer.setCurrentSessionStart(new Date());
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onPlayerQuit(PlayerQuitEvent event) public void onPlayerQuit(PlayerQuitEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (plugin.al.isAdmin(player)) if (plugin.adminList.isAdmin(player))
{ {
getActivityLog(event.getPlayer()).addLogout(); getActivityLog(event.getPlayer()).addLogout();
plugin.acl.save(); plugin.activityLog.save();
plugin.acl.updateTables(); plugin.activityLog.updateTables();
} }
} }

View file

@ -4,7 +4,10 @@ import com.google.common.collect.Lists;
import java.time.Instant; import java.time.Instant;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.config.IConfig; import me.totalfreedom.totalfreedommod.config.IConfig;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -14,15 +17,20 @@ public class ActivityLogEntry implements IConfig
{ {
public static final String FILENAME = "activitylog.yml"; public static final String FILENAME = "activitylog.yml";
private final List<String> ips = Lists.newArrayList(); private final List<String> ips = Lists.newArrayList();
private final List<String> timestamps = Lists.newArrayList(); private final List<String> timestamps = Lists.newArrayList();
private final List<String> durations = Lists.newArrayList(); private final List<String> durations = Lists.newArrayList();
private Player player;
private String configKey; private String configKey;
private String name; private String name;
public ActivityLogEntry(Player player) public ActivityLogEntry(Player player)
{ {
this.configKey = player.getName().toLowerCase(); this(player.getName().toLowerCase());
this.player = player;
this.name = player.getName(); this.name = player.getName();
} }
@ -73,15 +81,22 @@ public class ActivityLogEntry implements IConfig
public void addLogout() public void addLogout()
{ {
// Fix of Array index out of bonds issue: FS-131 // Fix of Array index out of bonds issue: FS-131
String lastLoginString; String lastLoginString = null;
if (timestamps.size() > 1)
if(timestamps.size() > 1)
{ {
lastLoginString = timestamps.get(timestamps.size() - 1); lastLoginString = timestamps.get(timestamps.size() - 1);
} }
else else if (!timestamps.isEmpty())
{ {
lastLoginString = timestamps.get(0); lastLoginString = timestamps.get(0);
} }
if (lastLoginString == null)
{
FPlayer fPlayer = TotalFreedomMod.getPlugin().playerList.getPlayer(this.player);
lastLoginString = "Login: " + FUtil.dateToString(fPlayer.getCurrentSessionStart());
}
Date currentTime = Date.from(Instant.now()); Date currentTime = Date.from(Instant.now());
timestamps.add("Logout: " + FUtil.dateToString(currentTime)); timestamps.add("Logout: " + FUtil.dateToString(currentTime));
lastLoginString = lastLoginString.replace("Login: ", ""); lastLoginString = lastLoginString.replace("Login: ", "");

View file

@ -7,7 +7,7 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import me.totalfreedom.totalfreedommod.LogViewer.LogsRegistrationMode; import me.totalfreedom.totalfreedommod.services.impl.LogViewer.LogsRegistrationMode;
import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
@ -158,13 +158,13 @@ public class Admin
{ {
if (getRank().isAtLeast(Rank.ADMIN)) if (getRank().isAtLeast(Rank.ADMIN))
{ {
if (plugin.btb != null) if (plugin.bukkitTelnetBridge != null)
{ {
plugin.btb.killTelnetSessions(getName()); plugin.bukkitTelnetBridge.killTelnetSessions(getName());
} }
} }
plugin.lv.updateLogsRegistration(null, getName(), LogsRegistrationMode.DELETE); plugin.logViewer.updateLogsRegistration(null, getName(), LogsRegistrationMode.DELETE);
} }
} }

View file

@ -10,7 +10,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
@ -19,7 +19,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class AdminList extends FreedomService public class AdminList extends AbstractService
{ {
public static final List<String> vanished = new ArrayList<>(); public static final List<String> vanished = new ArrayList<>();
public final Map<String, List<String>> verifiedNoAdmin = Maps.newHashMap(); public final Map<String, List<String>> verifiedNoAdmin = Maps.newHashMap();
@ -275,9 +275,9 @@ public class AdminList extends FreedomService
{ {
if (admin.getRank().isAtLeast(Rank.ADMIN)) if (admin.getRank().isAtLeast(Rank.ADMIN))
{ {
if (plugin.btb != null) if (plugin.bukkitTelnetBridge != null)
{ {
plugin.btb.killTelnetSessions(admin.getName()); plugin.bukkitTelnetBridge.killTelnetSessions(admin.getName());
} }
} }

View file

@ -1,12 +1,13 @@
package me.totalfreedom.totalfreedommod; package me.totalfreedom.totalfreedommod.admin.module;
import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class CommandSpy extends FreedomService public class CommandSpy extends AbstractService
{ {
@Override @Override
public void onStart() public void onStart()
@ -23,7 +24,7 @@ public class CommandSpy extends FreedomService
{ {
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers())
{ {
if (plugin.al.isAdmin(player) && plugin.al.getAdmin(player).getCommandSpy()) if (plugin.adminList.isAdmin(player) && plugin.adminList.getAdmin(player).getCommandSpy())
{ {
if (plugin.al.isAdmin(event.getPlayer()) && !plugin.al.isSeniorAdmin(player)) if (plugin.al.isAdmin(event.getPlayer()) && !plugin.al.isSeniorAdmin(player))
{ {

View file

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod; package me.totalfreedom.totalfreedommod.admin.module;
import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.FPlayer;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -7,7 +8,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
public class Fuckoff extends FreedomService public class Fuckoff extends AbstractService
{ {
@Override @Override
public void onStart() public void onStart()
@ -25,7 +26,7 @@ public class Fuckoff extends FreedomService
final Player fuckoffPlayer = event.getPlayer(); final Player fuckoffPlayer = event.getPlayer();
for (Player onlinePlayer : server.getOnlinePlayers()) for (Player onlinePlayer : server.getOnlinePlayers())
{ {
final FPlayer fPlayer = plugin.pl.getPlayer(onlinePlayer); final FPlayer fPlayer = plugin.playerList.getPlayer(onlinePlayer);
if (!fPlayer.isFuckOff() if (!fPlayer.isFuckOff()
|| fuckoffPlayer.equals(onlinePlayer)) || fuckoffPlayer.equals(onlinePlayer))
{ {

View file

@ -1,7 +1,9 @@
package me.totalfreedom.totalfreedommod; package me.totalfreedom.totalfreedommod.admin.module;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
@ -15,7 +17,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
public class Muter extends FreedomService public class Muter extends AbstractService
{ {
public final List<String> MUTED_PLAYERS = new ArrayList<>(); public final List<String> MUTED_PLAYERS = new ArrayList<>();
@ -35,14 +37,14 @@ public class Muter extends FreedomService
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
FPlayer fPlayer = plugin.pl.getPlayerSync(player); FPlayer fPlayer = plugin.playerList.getPlayerSync(player);
if (!fPlayer.isMuted()) if (!fPlayer.isMuted())
{ {
return; return;
} }
if (plugin.al.isAdminSync(player)) if (plugin.adminList.isAdminSync(player))
{ {
fPlayer.setMuted(false); fPlayer.setMuted(false);
MUTED_PLAYERS.remove(player.getName()); MUTED_PLAYERS.remove(player.getName());
@ -58,7 +60,7 @@ public class Muter extends FreedomService
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
FPlayer fPlayer = plugin.pl.getPlayer(event.getPlayer()); FPlayer fPlayer = plugin.playerList.getPlayer(event.getPlayer());
// Block commands if player is muted // Block commands if player is muted
if (!fPlayer.isMuted()) if (!fPlayer.isMuted())
@ -67,7 +69,7 @@ public class Muter extends FreedomService
} }
String message = event.getMessage(); String message = event.getMessage();
if (plugin.al.isAdmin(player)) if (plugin.adminList.isAdmin(player))
{ {
fPlayer.setMuted(false); fPlayer.setMuted(false);
return; return;
@ -103,7 +105,7 @@ public class Muter extends FreedomService
public void onPlayerJoin(PlayerJoinEvent event) public void onPlayerJoin(PlayerJoinEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
FPlayer playerdata = plugin.pl.getPlayer(player); FPlayer playerdata = plugin.playerList.getPlayer(player);
if (MUTED_PLAYERS.contains(player.getName())) if (MUTED_PLAYERS.contains(player.getName()))
{ {

View file

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod; package me.totalfreedom.totalfreedommod.admin.module;
import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.FPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -7,7 +8,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class Orbiter extends FreedomService public class Orbiter extends AbstractService
{ {
@Override @Override
public void onStart() public void onStart()
@ -24,7 +25,7 @@ public class Orbiter extends FreedomService
{ {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final FPlayer fPlayer = plugin.pl.getPlayer(player); final FPlayer fPlayer = plugin.playerList.getPlayer(player);
if (!fPlayer.isOrbiting()) if (!fPlayer.isOrbiting())
{ {

View file

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod; package me.totalfreedom.totalfreedommod.anticheat;
import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
@ -10,7 +11,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
public class AntiNuke extends FreedomService public class AntiNuke extends AbstractService
{ {
@Override @Override
public void onStart() public void onStart()
@ -31,7 +32,7 @@ public class AntiNuke extends FreedomService
} }
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final FPlayer fPlayer = plugin.pl.getPlayer(player); final FPlayer fPlayer = plugin.playerList.getPlayer(player);
if (fPlayer.incrementAndGetBlockDestroyCount() > ConfigEntry.NUKE_MONITOR_COUNT_BREAK.getInteger()) if (fPlayer.incrementAndGetBlockDestroyCount() > ConfigEntry.NUKE_MONITOR_COUNT_BREAK.getInteger())
{ {
@ -54,7 +55,7 @@ public class AntiNuke extends FreedomService
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
FPlayer fPlayer = plugin.pl.getPlayer(player); FPlayer fPlayer = plugin.playerList.getPlayer(player);
if (fPlayer.incrementAndGetBlockPlaceCount() > ConfigEntry.NUKE_MONITOR_COUNT_PLACE.getInteger()) if (fPlayer.incrementAndGetBlockPlaceCount() > ConfigEntry.NUKE_MONITOR_COUNT_PLACE.getInteger())
{ {

View file

@ -1,7 +1,6 @@
package me.totalfreedom.totalfreedommod; package me.totalfreedom.totalfreedommod.anticheat;
import java.util.HashMap; import me.totalfreedom.totalfreedommod.services.AbstractService;
import java.util.Map;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.util.FSync; import me.totalfreedom.totalfreedommod.util.FSync;
@ -15,14 +14,17 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
public class AntiSpam extends FreedomService import java.util.HashMap;
import java.util.Map;
public class AntiSpam extends AbstractService
{ {
public static final int MSG_PER_CYCLE = 8; public static final int MSG_PER_CYCLE = 8;
public static final int TICKS_PER_CYCLE = 2 * 10; public static final int TICKS_PER_CYCLE = 2 * 10;
// //
public BukkitTask cycleTask = null; public BukkitTask cycleTask = null;
private final Map<Player, Integer> muteCounts = new HashMap<>(); private Map<Player, Integer> muteCounts = new HashMap<>();
@Override @Override
public void onStart() public void onStart()
@ -48,7 +50,7 @@ public class AntiSpam extends FreedomService
{ {
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers())
{ {
final FPlayer playerdata = plugin.pl.getPlayer(player); final FPlayer playerdata = plugin.playerList.getPlayer(player);
// TODO: Move each to their own section // TODO: Move each to their own section
playerdata.resetMsgCount(); playerdata.resetMsgCount();
@ -62,12 +64,12 @@ public class AntiSpam extends FreedomService
{ {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (plugin.al.isAdmin(player)) if (plugin.adminList.isAdmin(player))
{ {
return; return;
} }
final FPlayer playerdata = plugin.pl.getPlayerSync(player); final FPlayer playerdata = plugin.playerList.getPlayerSync(player);
int count = muteCounts.getOrDefault(player, 0); int count = muteCounts.getOrDefault(player, 0);
int minutes = ConfigEntry.ANTISPAM_MINUTES.getInteger(); int minutes = ConfigEntry.ANTISPAM_MINUTES.getInteger();
@ -81,8 +83,8 @@ public class AntiSpam extends FreedomService
playerdata.setMuted(true, time); playerdata.setMuted(true, time);
FSync.bcastMsg(String.format("%s has automatically been muted for %d minutes for spamming chat.", FSync.bcastMsg(String.format("%s has automatically been muted for %d minutes for spamming chat.",
player.getName(), player.getName(),
time), time),
ChatColor.RED); ChatColor.RED);
playerdata.resetMsgCount(); playerdata.resetMsgCount();
@ -101,7 +103,7 @@ public class AntiSpam extends FreedomService
{ {
String command = event.getMessage(); String command = event.getMessage();
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final FPlayer fPlayer = plugin.pl.getPlayer(player); final FPlayer fPlayer = plugin.playerList.getPlayer(player);
fPlayer.setLastCommand(command); fPlayer.setLastCommand(command);
if (fPlayer.allCommandsBlocked()) if (fPlayer.allCommandsBlocked())
@ -111,7 +113,7 @@ public class AntiSpam extends FreedomService
return; return;
} }
if (plugin.al.isAdmin(player)) if (plugin.adminList.isAdmin(player))
{ {
return; return;
} }
@ -119,7 +121,7 @@ public class AntiSpam extends FreedomService
if (fPlayer.incrementAndGetMsgCount() > MSG_PER_CYCLE) if (fPlayer.incrementAndGetMsgCount() > MSG_PER_CYCLE)
{ {
FUtil.bcastMsg(player.getName() + " was automatically kicked for spamming commands.", ChatColor.RED); FUtil.bcastMsg(player.getName() + " was automatically kicked for spamming commands.", ChatColor.RED);
plugin.ae.autoEject(player, "Kicked for spamming commands."); plugin.autoEject.autoEject(player, "Kicked for spamming commands.");
fPlayer.resetMsgCount(); fPlayer.resetMsgCount();
event.setCancelled(true); event.setCancelled(true);

View file

@ -1,11 +1,13 @@
package me.totalfreedom.totalfreedommod; package me.totalfreedom.totalfreedommod.anticheat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import me.totalfreedom.totalfreedommod.banning.Ban;
import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.punishments.banning.Ban;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -13,7 +15,7 @@ import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class AutoEject extends FreedomService public class AutoEject extends AbstractService
{ {
private final Map<String, Integer> ejects = new HashMap<>(); // ip -> amount private final Map<String, Integer> ejects = new HashMap<>(); // ip -> amount
@ -68,7 +70,7 @@ public class AutoEject extends FreedomService
FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 5 minutes."); FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 5 minutes.");
plugin.bm.addBan(Ban.forPlayer(player, Bukkit.getConsoleSender(), expires, kickMessage)); plugin.banManager.addBan(Ban.forPlayer(player, Bukkit.getConsoleSender(), expires, kickMessage));
player.kickPlayer(kickMessage); player.kickPlayer(kickMessage);
break; break;
@ -81,13 +83,13 @@ public class AutoEject extends FreedomService
FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 10 minutes."); FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 10 minutes.");
plugin.bm.addBan(Ban.forPlayer(player, Bukkit.getConsoleSender(), expires, kickMessage)); plugin.banManager.addBan(Ban.forPlayer(player, Bukkit.getConsoleSender(), expires, kickMessage));
player.kickPlayer(kickMessage); player.kickPlayer(kickMessage);
break; break;
} }
case STRIKE_THREE: case STRIKE_THREE:
{ {
plugin.bm.addBan(Ban.forPlayerFuzzy(player, Bukkit.getConsoleSender(), null, kickMessage)); plugin.banManager.addBan(Ban.forPlayerFuzzy(player, Bukkit.getConsoleSender(), null, kickMessage));
FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned."); FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned.");

View file

@ -1,12 +1,13 @@
package me.totalfreedom.totalfreedommod; package me.totalfreedom.totalfreedommod.anticheat;
import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
public class AutoKick extends FreedomService public class AutoKick extends AbstractService
{ {
public static final long AUTOKICK_RATE = 10 * 20L; public static final long AUTOKICK_RATE = 10 * 20L;
@ -48,7 +49,7 @@ public class AutoKick extends FreedomService
{ {
// No type cast was provided, one has been supplied. // No type cast was provided, one has been supplied.
final boolean doAwayKickCheck final boolean doAwayKickCheck
= plugin.esb.isEnabled() = plugin.essentialsBridge.isEnabled()
&& (((float)server.getOnlinePlayers().size() / (float)server.getMaxPlayers()) > autoKickThreshold); && (((float)server.getOnlinePlayers().size() / (float)server.getMaxPlayers()) > autoKickThreshold);
if (!doAwayKickCheck) if (!doAwayKickCheck)
@ -58,7 +59,7 @@ public class AutoKick extends FreedomService
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers())
{ {
final long lastActivity = plugin.esb.getLastActivity(player.getName()); final long lastActivity = plugin.essentialsBridge.getLastActivity(player.getName());
if (lastActivity > 0 && lastActivity + autoKickTicks < System.currentTimeMillis()) if (lastActivity > 0 && lastActivity + autoKickTicks < System.currentTimeMillis())
{ {
player.kickPlayer("Automatically kicked by server for inactivity."); player.kickPlayer("Automatically kicked by server for inactivity.");

View file

@ -1,7 +1,7 @@
package me.totalfreedom.totalfreedommod.blocking; package me.totalfreedom.totalfreedommod.blocking;
import java.util.List; import java.util.List;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.Groups; import me.totalfreedom.totalfreedommod.util.Groups;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -17,7 +17,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
public class BlockBlocker extends FreedomService public class BlockBlocker extends AbstractService
{ {
@Override @Override
public void onStart() public void onStart()

View file

@ -1,7 +1,7 @@
package me.totalfreedom.totalfreedommod.blocking; package me.totalfreedom.totalfreedommod.blocking;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.util.FSync; import me.totalfreedom.totalfreedommod.util.FSync;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -10,7 +10,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
public class EditBlocker extends FreedomService public class EditBlocker extends AbstractService
{ {
@Override @Override
public void onStart() public void onStart()
@ -25,13 +25,13 @@ public class EditBlocker extends FreedomService
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onBlockPlace(BlockPlaceEvent event) public void onBlockPlace(BlockPlaceEvent event)
{ {
FPlayer fPlayer = plugin.pl.getPlayerSync(event.getPlayer()); FPlayer fPlayer = plugin.playerList.getPlayerSync(event.getPlayer());
if (!fPlayer.isEditBlocked()) if (!fPlayer.isEditBlocked())
{ {
return; return;
} }
if (plugin.al.isAdminSync(event.getPlayer())) if (plugin.adminList.isAdminSync(event.getPlayer()))
{ {
fPlayer.setEditBlocked(false); fPlayer.setEditBlocked(false);
return; return;
@ -44,13 +44,13 @@ public class EditBlocker extends FreedomService
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onBlockBreak(BlockBreakEvent event) public void onBlockBreak(BlockBreakEvent event)
{ {
FPlayer fPlayer = plugin.pl.getPlayerSync(event.getPlayer()); FPlayer fPlayer = plugin.playerList.getPlayerSync(event.getPlayer());
if (!fPlayer.isEditBlocked()) if (!fPlayer.isEditBlocked())
{ {
return; return;
} }
if (plugin.al.isAdminSync(event.getPlayer())) if (plugin.adminList.isAdminSync(event.getPlayer()))
{ {
fPlayer.setEditBlocked(false); fPlayer.setEditBlocked(false);
return; return;

View file

@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import me.totalfreedom.totalfreedommod.util.Groups; import me.totalfreedom.totalfreedommod.util.Groups;
@ -38,7 +38,7 @@ import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
public class EventBlocker extends FreedomService public class EventBlocker extends AbstractService
{ {
/** /**
* /@EventHandler(priority = EventPriority.HIGH) * /@EventHandler(priority = EventPriority.HIGH)
@ -159,7 +159,7 @@ public class EventBlocker extends FreedomService
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerDropItem(PlayerDropItemEvent event) public void onPlayerDropItem(PlayerDropItemEvent event)
{ {
if (!plugin.al.isAdmin(event.getPlayer())) if (!plugin.adminList.isAdmin(event.getPlayer()))
{ {
event.setCancelled(true); event.setCancelled(true);
} }

View file

@ -1,6 +1,6 @@
package me.totalfreedom.totalfreedommod.blocking; package me.totalfreedom.totalfreedommod.blocking;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.Groups; import me.totalfreedom.totalfreedommod.util.Groups;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -12,7 +12,7 @@ import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class InteractBlocker extends FreedomService public class InteractBlocker extends AbstractService
{ {
@Override @Override
public void onStart() public void onStart()
@ -89,7 +89,7 @@ public class InteractBlocker extends FreedomService
{ {
case WATER_BUCKET: case WATER_BUCKET:
{ {
if (plugin.al.isAdmin(player) || ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) if (plugin.adminList.isAdmin(player) || ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
{ {
break; break;
} }
@ -102,7 +102,7 @@ public class InteractBlocker extends FreedomService
case LAVA_BUCKET: case LAVA_BUCKET:
{ {
if (plugin.al.isAdmin(player) || ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) if (plugin.adminList.isAdmin(player) || ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
{ {
break; break;
} }

View file

@ -1,7 +1,7 @@
package me.totalfreedom.totalfreedommod.blocking; package me.totalfreedom.totalfreedommod.blocking;
import java.util.Objects; import java.util.Objects;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import org.bukkit.attribute.Attributable; import org.bukkit.attribute.Attributable;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
@ -19,7 +19,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.EntitySpawnEvent;
public class MobBlocker extends FreedomService public class MobBlocker extends AbstractService
{ {
@Override @Override
public void onStart() public void onStart()

View file

@ -1,6 +1,6 @@
package me.totalfreedom.totalfreedommod.blocking; package me.totalfreedom.totalfreedommod.blocking;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;
@ -12,7 +12,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
public class PVPBlocker extends FreedomService public class PVPBlocker extends AbstractService
{ {
@Override @Override
public void onStart() public void onStart()
@ -70,24 +70,24 @@ public class PVPBlocker extends FreedomService
} }
} }
if (player != null & !plugin.al.isAdmin(player)) if (player != null & !plugin.adminList.isAdmin(player))
{ {
if (player.getGameMode() == GameMode.CREATIVE) if (player.getGameMode() == GameMode.CREATIVE)
{ {
player.sendMessage(ChatColor.RED + "Creative PvP is not allowed!"); player.sendMessage(ChatColor.RED + "Creative PvP is not allowed!");
event.setCancelled(true); event.setCancelled(true);
} }
else if (plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) else if (plugin.essentialsBridge.getEssentialsUser(player.getName()).isGodModeEnabled())
{ {
player.sendMessage(ChatColor.RED + "God mode PvP is not allowed!"); player.sendMessage(ChatColor.RED + "God mode PvP is not allowed!");
event.setCancelled(true); event.setCancelled(true);
} }
else if (plugin.pl.getPlayer(target).isPvpBlocked()) else if (plugin.playerList.getPlayer(target).isPvpBlocked())
{ {
player.sendMessage(ChatColor.RED + target.getName() + " has PvP disabled!"); player.sendMessage(ChatColor.RED + target.getName() + " has PvP disabled!");
event.setCancelled(true); event.setCancelled(true);
} }
else if (plugin.pl.getPlayer(player).isPvpBlocked()) else if (plugin.playerList.getPlayer(player).isPvpBlocked())
{ {
player.sendMessage(ChatColor.RED + "You have PvP disabled!"); player.sendMessage(ChatColor.RED + "You have PvP disabled!");
event.setCancelled(true); event.setCancelled(true);

View file

@ -1,7 +1,7 @@
package me.totalfreedom.totalfreedommod.blocking; package me.totalfreedom.totalfreedommod.blocking;
import java.util.Collection; import java.util.Collection;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.ThrownPotion; import org.bukkit.entity.ThrownPotion;
@ -13,7 +13,7 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.projectiles.ProjectileSource; import org.bukkit.projectiles.ProjectileSource;
public class PotionBlocker extends FreedomService public class PotionBlocker extends AbstractService
{ {
public static final int POTION_BLOCK_RADIUS_SQUARED = 20 * 20; public static final int POTION_BLOCK_RADIUS_SQUARED = 20 * 20;

View file

@ -1,10 +1,8 @@
package me.totalfreedom.totalfreedommod.blocking; package me.totalfreedom.totalfreedommod.blocking;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import net.minecraft.nbt.NBTTagCompound;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Tag; import org.bukkit.Tag;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -15,7 +13,7 @@ import org.bukkit.inventory.ItemStack;
//codebeat:disable[LOC,ABC] //codebeat:disable[LOC,ABC]
public class SignBlocker extends FreedomService public class SignBlocker extends AbstractService
{ {
@Override @Override
public void onStart() public void onStart()
@ -27,11 +25,13 @@ public class SignBlocker extends FreedomService
{ {
} }
//TODO: KYORI
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerPlaceBlock(BlockPlaceEvent event) public void onPlayerPlaceBlock(BlockPlaceEvent event)
{ {
final Player player = event.getPlayer(); /*final Player player = event.getPlayer();
if (Tag.SIGNS.getValues().contains(event.getBlock().getType())) if (Tag.SIGNS.getValues().contains(event.getBlock().getType()))
{ {
ItemStack sign = event.getItemInHand(); ItemStack sign = event.getItemInHand();
@ -48,7 +48,7 @@ public class SignBlocker extends FreedomService
player.sendMessage(ChatColor.GRAY + "You are not allowed to place command signs."); player.sendMessage(ChatColor.GRAY + "You are not allowed to place command signs.");
event.setCancelled(true); event.setCancelled(true);
} }
} }*/
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)

View file

@ -7,7 +7,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
@ -22,7 +22,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.SimplePluginManager; import org.bukkit.plugin.SimplePluginManager;
public class CommandBlocker extends FreedomService public class CommandBlocker extends AbstractService
{ {
private final Pattern flagPattern = Pattern.compile("(:([0-9]){5,})"); private final Pattern flagPattern = Pattern.compile("(:([0-9]){5,})");
@ -171,7 +171,7 @@ public class CommandBlocker extends FreedomService
for (String part : commandParts) for (String part : commandParts)
{ {
if (command.startsWith("/") && !plugin.al.isAdmin(sender) && (part.contains("#copy") || part.contains("#clipboard"))) if (command.startsWith("/") && !plugin.adminList.isAdmin(sender) && (part.contains("#copy") || part.contains("#clipboard")))
{ {
FUtil.playerMsg(sender, "WorldEdit copy variables are disabled."); FUtil.playerMsg(sender, "WorldEdit copy variables are disabled.");
return true; return true;

View file

@ -5,12 +5,8 @@ import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.spigotmc.SpigotConfig;
public class CommandBlockerEntry public class CommandBlockerEntry
{ {
private final CommandBlockerRank rank; private final CommandBlockerRank rank;
private final CommandBlockerAction action; private final CommandBlockerAction action;
@ -39,13 +35,14 @@ public class CommandBlockerEntry
{ {
if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player) if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player)
{ {
TotalFreedomMod.getPlugin().ae.autoEject((Player)sender, "You used a prohibited command: " + command); TotalFreedomMod.getPlugin().autoEject.autoEject((Player)sender, "You used a prohibited command: " + command);
FUtil.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED); FUtil.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED);
return; return;
} }
if (action == CommandBlockerAction.BLOCK_UNKNOWN) if (action == CommandBlockerAction.BLOCK_UNKNOWN)
{ {
sender.sendMessage(SpigotConfig.unknownCommandMessage); String spigotUnknownCMD = TotalFreedomMod.getPlugin().getSpigotConfig().getString("messages.unknown-command");
sender.sendMessage(spigotUnknownCMD == null || spigotUnknownCMD.isEmpty() ? "Unknown command. Type \"/help\" for help." : spigotUnknownCMD);
return; return;
} }
FUtil.playerMsg(sender, FUtil.colorize(message)); FUtil.playerMsg(sender, FUtil.colorize(message));

View file

@ -22,7 +22,7 @@ public enum CommandBlockerRank
public static CommandBlockerRank fromSender(CommandSender sender) public static CommandBlockerRank fromSender(CommandSender sender)
{ {
Admin admin = TotalFreedomMod.getPlugin().al.getAdmin(sender); Admin admin = TotalFreedomMod.getPlugin().adminList.getAdmin(sender);
if (admin != null) if (admin != null)
{ {
if (admin.getRank() == Rank.SENIOR_ADMIN) if (admin.getRank() == Rank.SENIOR_ADMIN)

View file

@ -8,7 +8,7 @@ import me.totalfreedom.bukkittelnet.api.TelnetCommandEvent;
import me.totalfreedom.bukkittelnet.api.TelnetPreLoginEvent; import me.totalfreedom.bukkittelnet.api.TelnetPreLoginEvent;
import me.totalfreedom.bukkittelnet.api.TelnetRequestDataTagsEvent; import me.totalfreedom.bukkittelnet.api.TelnetRequestDataTagsEvent;
import me.totalfreedom.bukkittelnet.session.ClientSession; import me.totalfreedom.bukkittelnet.session.ClientSession;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
@ -17,7 +17,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class BukkitTelnetBridge extends FreedomService public class BukkitTelnetBridge extends AbstractService
{ {
private BukkitTelnet bukkitTelnetPlugin = null; private BukkitTelnet bukkitTelnetPlugin = null;
@ -42,7 +42,7 @@ public class BukkitTelnetBridge extends FreedomService
return; return;
} }
final Admin admin = plugin.al.getEntryByIpFuzzy(ip); final Admin admin = plugin.adminList.getEntryByIpFuzzy(ip);
if (admin == null || !admin.isActive() || !admin.getRank().hasConsoleVariant()) if (admin == null || !admin.isActive() || !admin.getRank().hasConsoleVariant())
{ {
@ -56,7 +56,7 @@ public class BukkitTelnetBridge extends FreedomService
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onTelnetCommand(TelnetCommandEvent event) public void onTelnetCommand(TelnetCommandEvent event)
{ {
if (plugin.cb.isCommandBlocked(event.getCommand(), event.getSender())) if (plugin.commandBlocker.isCommandBlocked(event.getCommand(), event.getSender()))
{ {
event.setCancelled(true); event.setCancelled(true);
} }
@ -74,7 +74,7 @@ public class BukkitTelnetBridge extends FreedomService
boolean isTelnetAdmin = false; boolean isTelnetAdmin = false;
boolean isSeniorAdmin = false; boolean isSeniorAdmin = false;
final Admin admin = plugin.al.getAdmin(player); final Admin admin = plugin.adminList.getAdmin(player);
if (admin != null) if (admin != null)
{ {
boolean active = admin.isActive(); boolean active = admin.isActive();
@ -88,9 +88,9 @@ public class BukkitTelnetBridge extends FreedomService
playerTags.put("tfm.admin.isTelnetAdmin", isTelnetAdmin); playerTags.put("tfm.admin.isTelnetAdmin", isTelnetAdmin);
playerTags.put("tfm.admin.isSeniorAdmin", isSeniorAdmin); playerTags.put("tfm.admin.isSeniorAdmin", isSeniorAdmin);
playerTags.put("tfm.playerdata.getTag", plugin.pl.getPlayer(player).getTag()); playerTags.put("tfm.playerdata.getTag", plugin.playerList.getPlayer(player).getTag());
playerTags.put("tfm.essentialsBridge.getNickname", plugin.esb.getNickname(player.getName())); playerTags.put("tfm.essentialsBridge.getNickname", plugin.essentialsBridge.getNickname(player.getName()));
} }
} }
@ -126,7 +126,7 @@ public class BukkitTelnetBridge extends FreedomService
{ {
for (ClientSession session : telnet.appender.getSessions()) for (ClientSession session : telnet.appender.getSessions())
{ {
Admin admin = plugin.al.getEntryByName(session.getUserName().toLowerCase()); Admin admin = plugin.adminList.getEntryByName(session.getUserName().toLowerCase());
if (admin != null && !admins.contains(admin)) if (admin != null && !admins.contains(admin))
{ {
admins.add(admin); admins.add(admin);

View file

@ -1,18 +1,14 @@
package me.totalfreedom.totalfreedommod.bridge; package me.totalfreedom.totalfreedommod.bridge;
import java.io.File; import java.io.File;
import java.sql.Connection; import java.sql.*;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
@ -34,7 +30,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
public class CoreProtectBridge extends FreedomService public class CoreProtectBridge extends AbstractService
{ {
public static Map<Player, FUtil.PaginationList<String>> HISTORY_MAP = new HashMap<>(); public static Map<Player, FUtil.PaginationList<String>> HISTORY_MAP = new HashMap<>();
private final List<String> tables = Arrays.asList("co_sign", "co_session", "co_container", "co_block"); private final List<String> tables = Arrays.asList("co_sign", "co_session", "co_container", "co_block");
@ -196,7 +192,6 @@ public class CoreProtectBridge extends FreedomService
return (megabytes / 1024); return (megabytes / 1024);
} }
// Wipes DB for the specified world
public void clearDatabase(World world) public void clearDatabase(World world)
{ {
clearDatabase(world, false); clearDatabase(world, false);
@ -264,46 +259,43 @@ public class CoreProtectBridge extends FreedomService
{ {
FLog.warning("Failed to delete the CoreProtect data for the " + world.getName()); FLog.warning("Failed to delete the CoreProtect data for the " + world.getName());
} }
// This exits for flatlands wipes
if (shutdown)
{
server.shutdown();
}
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerInteract(PlayerInteractEvent event) public void onPlayerInteract(PlayerInteractEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
PlayerData data = plugin.pl.getData(player); PlayerData data = plugin.playerList.getData(player);
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
final CoreProtectAPI coreProtect = getCoreProtectAPI(); final CoreProtectAPI coreProtect = getCoreProtectAPI();
// TODO: Rewrite this
if (data.hasInspection()) if (data.hasInspection())
{ {
int cooldownTime = 3;
// Cooldown check
if ((event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)
&& cooldown.containsKey(player.getName()))
{
long secondsLeft = getSecondsLeft(cooldown.get(player.getName()), cooldownTime);
if (secondsLeft > 0L)
{
event.setCancelled(true);
player.sendMessage(ChatColor.RED + String.valueOf(secondsLeft) + " seconds left before next query.");
return;
}
}
// Actual lookup time
if (event.getAction() == Action.LEFT_CLICK_BLOCK) if (event.getAction() == Action.LEFT_CLICK_BLOCK)
{ {
if (block != null) if (block != null)
{ {
event.setCancelled(true); event.setCancelled(true);
int cooldownTime = 3;
if (cooldown.containsKey(player.getName()))
{
long secondsLeft = getSecondsLeft(cooldown.get(player.getName()), cooldownTime);
if (secondsLeft > 0L)
{
event.setCancelled(true);
player.sendMessage(ChatColor.RED + String.valueOf(secondsLeft) + " seconds left before next query.");
return;
}
}
List<String[]> lookup = coreProtect.blockLookup(block, -1); List<String[]> lookup = coreProtect.blockLookup(block, -1);
if (!plugin.al.isAdmin(player)) if (!plugin.adminList.isAdmin(player))
{ {
cooldown.put(player.getName(), System.currentTimeMillis()); cooldown.put(player.getName(), System.currentTimeMillis());
} }
@ -320,8 +312,8 @@ public class CoreProtectBridge extends FreedomService
HISTORY_MAP.put(event.getPlayer(), new FUtil.PaginationList<>(10)); HISTORY_MAP.put(event.getPlayer(), new FUtil.PaginationList<>(10));
FUtil.PaginationList<String> paged = HISTORY_MAP.get(event.getPlayer()); FUtil.PaginationList<String> paged = HISTORY_MAP.get(event.getPlayer());
player.sendMessage("---- " + net.md_5.bungee.api.ChatColor.of("#30ade4") + "Block Inspector" + ChatColor.WHITE + " ---- " player.sendMessage("---- " + net.md_5.bungee.api.ChatColor.of("#30ade4") + "Block Inspector" + ChatColor.WHITE + " ---- " +
+ ChatColor.GRAY + "(x" + block.getX() + "/" + "y" + block.getY() + "/" + "z" + block.getZ() + ")"); ChatColor.GRAY + "(x" + block.getX() + "/" + "y" + block.getY() + "/" + "z" + block.getZ() + ")");
for (String[] value : lookup) for (String[] value : lookup)
{ {
@ -351,8 +343,8 @@ public class CoreProtectBridge extends FreedomService
int time = (int)(System.currentTimeMillis() / 1000L); int time = (int)(System.currentTimeMillis() / 1000L);
paged.add(ChatColor.GRAY + getTimeAgo(result.getTime(), time) + ChatColor.WHITE + " - " + net.md_5.bungee.api.ChatColor.of("#30ade4") paged.add(ChatColor.GRAY + getTimeAgo(result.getTime(), time) + ChatColor.WHITE + " - " + net.md_5.bungee.api.ChatColor.of("#30ade4") +
+ st + result.getPlayer() + ChatColor.WHITE + st + s + net.md_5.bungee.api.ChatColor.of("#30ade4") + st + bl.getMaterial().toString().toLowerCase()); st + result.getPlayer() + ChatColor.WHITE + st + s + net.md_5.bungee.api.ChatColor.of("#30ade4") + st + bl.getMaterial().toString().toLowerCase());
} }
List<String> page = paged.getPage(1); List<String> page = paged.getPage(1);
@ -369,91 +361,75 @@ public class CoreProtectBridge extends FreedomService
{ {
if (block != null) if (block != null)
{ {
if (data.hasInspection()) BlockState blockState = block.getRelative(event.getBlockFace()).getState();
{ Block placedBlock = blockState.getBlock();
BlockState blockState = block.getRelative(event.getBlockFace()).getState(); event.setCancelled(true);
Block placedBlock = blockState.getBlock(); List<String[]> lookup = coreProtect.blockLookup(placedBlock, -1);
event.setCancelled(true);
List<String[]> lookup = coreProtect.blockLookup(placedBlock, -1);
if (lookup.isEmpty())
{
lookup = coreProtect.blockLookup(block, -1);
}
if (!plugin.adminList.isAdmin(player))
{
cooldown.put(player.getName(), System.currentTimeMillis());
}
if (lookup != null)
{
if (lookup.isEmpty()) if (lookup.isEmpty())
{ {
lookup = coreProtect.blockLookup(block, -1); player.sendMessage(net.md_5.bungee.api.ChatColor.of("#30ade4") + "Block Inspector " + ChatColor.WHITE + "- " + "No block data found for this location");
return;
} }
int cooldownTime = 3; HISTORY_MAP.remove(event.getPlayer());
HISTORY_MAP.put(event.getPlayer(), new FUtil.PaginationList<>(10));
FUtil.PaginationList<String> paged = HISTORY_MAP.get(event.getPlayer());
if (cooldown.containsKey(player.getName())) player.sendMessage("---- " + net.md_5.bungee.api.ChatColor.of("#30ade4") + "Block Inspector" + ChatColor.WHITE + " ---- " +
ChatColor.GRAY + "(x" + block.getX() + "/" + "y" + block.getY() + "/" + "z" + block.getZ() + ")");
for (String[] value : lookup)
{ {
long secondsLeft = getSecondsLeft(cooldown.get(player.getName()), cooldownTime); CoreProtectAPI.ParseResult result = coreProtect.parseResult(value);
if (secondsLeft > 0L) BlockData bl = result.getBlockData();
String s;
String st = "";
if (result.getActionString().equals("Placement"))
{ {
event.setCancelled(true); s = " placed ";
player.sendMessage(ChatColor.RED + String.valueOf(secondsLeft) + " seconds left before next query.");
return;
} }
else if (result.getActionString().equals("Removal"))
{
s = " broke ";
}
else
{
s = " interacted with ";
}
if (result.isRolledBack())
{
st += "§m";
}
int time = (int)(System.currentTimeMillis() / 1000L);
paged.add(ChatColor.GRAY + getTimeAgo(result.getTime(), time) + ChatColor.WHITE + " - " + net.md_5.bungee.api.ChatColor.of("#30ade4") +
st + result.getPlayer() + ChatColor.WHITE + st + s + net.md_5.bungee.api.ChatColor.of("#30ade4") + st + bl.getMaterial().toString().toLowerCase());
} }
if (!plugin.al.isAdmin(player)) List<String> page = paged.getPage(1);
for (String entries : page)
{ {
cooldown.put(player.getName(), System.currentTimeMillis()); player.sendMessage(entries);
} }
if (lookup != null) player.sendMessage("Page 1/" + paged.getPageCount() + " | To index through the pages, type " + net.md_5.bungee.api.ChatColor.of("#30ade4") + "/ins history <page>");
{
if (lookup.isEmpty())
{
player.sendMessage(net.md_5.bungee.api.ChatColor.of("#30ade4") + "Block Inspector " + ChatColor.WHITE + "- " + "No block data found for this location");
return;
}
HISTORY_MAP.remove(event.getPlayer());
HISTORY_MAP.put(event.getPlayer(), new FUtil.PaginationList<>(10));
FUtil.PaginationList<String> paged = HISTORY_MAP.get(event.getPlayer());
player.sendMessage("---- " + net.md_5.bungee.api.ChatColor.of("#30ade4") + "Block Inspector" + ChatColor.WHITE + " ---- "
+ ChatColor.GRAY + "(x" + block.getX() + "/" + "y" + block.getY() + "/" + "z" + block.getZ() + ")");
for (String[] value : lookup)
{
CoreProtectAPI.ParseResult result = coreProtect.parseResult(value);
BlockData bl = result.getBlockData();
String s;
String st = "";
if (result.getActionString().equals("Placement"))
{
s = " placed ";
}
else if (result.getActionString().equals("Removal"))
{
s = " broke ";
}
else
{
s = " interacted with ";
}
if (result.isRolledBack())
{
st += "§m";
}
int time = (int)(System.currentTimeMillis() / 1000L);
paged.add(ChatColor.GRAY + getTimeAgo(result.getTime(), time) + ChatColor.WHITE + " - " + net.md_5.bungee.api.ChatColor.of("#30ade4")
+ st + result.getPlayer() + ChatColor.WHITE + st + s + net.md_5.bungee.api.ChatColor.of("#30ade4") + st + bl.getMaterial().toString().toLowerCase());
}
List<String> page = paged.getPage(1);
for (String entries : page)
{
player.sendMessage(entries);
}
player.sendMessage("Page 1/" + paged.getPageCount() + " | To index through the pages, type " + net.md_5.bungee.api.ChatColor.of("#30ade4") + "/ins history <page>");
}
} }
} }
} }

View file

@ -2,7 +2,7 @@ package me.totalfreedom.totalfreedommod.bridge;
import com.earth2me.essentials.Essentials; import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
@ -20,7 +20,7 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class EssentialsBridge extends FreedomService public class EssentialsBridge extends AbstractService
{ {
private Essentials essentialsPlugin = null; private Essentials essentialsPlugin = null;
@ -139,6 +139,7 @@ public class EssentialsBridge extends FreedomService
{ {
FLog.severe(ex); FLog.severe(ex);
} }
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
@ -148,15 +149,15 @@ public class EssentialsBridge extends FreedomService
Inventory inventory = event.getView().getTopInventory(); Inventory inventory = event.getView().getTopInventory();
InventoryType inventoryType = inventory.getType(); InventoryType inventoryType = inventory.getType();
Player player = (Player)event.getWhoClicked(); Player player = (Player)event.getWhoClicked();
FPlayer fPlayer = plugin.pl.getPlayer(player); FPlayer fPlayer = plugin.playerList.getPlayer(player);
if (inventoryType == InventoryType.PLAYER && fPlayer.isInvSee()) if (inventoryType == InventoryType.PLAYER && fPlayer.isInvSee())
{ {
final InventoryHolder inventoryHolder = inventory.getHolder(); final InventoryHolder inventoryHolder = inventory.getHolder();
if (inventoryHolder instanceof HumanEntity) if (inventoryHolder instanceof HumanEntity)
{ {
Player invOwner = (Player)inventoryHolder; Player invOwner = (Player)inventoryHolder;
Rank recieverRank = plugin.rm.getRank(player); Rank recieverRank = plugin.rankManager.getRank(player);
Rank playerRank = plugin.rm.getRank(invOwner); Rank playerRank = plugin.rankManager.getRank(invOwner);
if (playerRank.ordinal() >= recieverRank.ordinal() || !invOwner.isOnline()) if (playerRank.ordinal() >= recieverRank.ordinal() || !invOwner.isOnline())
{ {
event.setCancelled(true); event.setCancelled(true);
@ -185,7 +186,7 @@ public class EssentialsBridge extends FreedomService
Inventory inventory = event.getView().getTopInventory(); Inventory inventory = event.getView().getTopInventory();
InventoryType inventoryType = inventory.getType(); InventoryType inventoryType = inventory.getType();
Player player = (Player)event.getPlayer(); Player player = (Player)event.getPlayer();
FPlayer fPlayer = plugin.pl.getPlayer(player); FPlayer fPlayer = plugin.playerList.getPlayer(player);
if (inventoryType == InventoryType.PLAYER && fPlayer.isInvSee()) if (inventoryType == InventoryType.PLAYER && fPlayer.isInvSee())
{ {
fPlayer.setInvSee(false); fPlayer.setInvSee(false);

View file

@ -3,12 +3,12 @@ package me.totalfreedom.totalfreedommod.bridge;
import me.libraryaddict.disguise.BlockedDisguises; import me.libraryaddict.disguise.BlockedDisguises;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class LibsDisguisesBridge extends FreedomService public class LibsDisguisesBridge extends AbstractService
{ {
private LibsDisguises libsDisguisesPlugin = null; private LibsDisguises libsDisguisesPlugin = null;
@ -61,7 +61,7 @@ public class LibsDisguisesBridge extends FreedomService
{ {
if (DisguiseAPI.isDisguised(player)) if (DisguiseAPI.isDisguised(player))
{ {
if (!admin && plugin.al.isAdmin(player)) if (!admin && plugin.adminList.isAdmin(player))
{ {
continue; continue;
} }

View file

@ -2,11 +2,11 @@ package me.totalfreedom.totalfreedommod.bridge;
import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds; import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class TFGuildsBridge extends FreedomService public class TFGuildsBridge extends AbstractService
{ {
public boolean enabled = false; public boolean enabled = false;

View file

@ -3,12 +3,12 @@ package me.totalfreedom.totalfreedommod.bridge;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.BukkitPlayer; import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class WorldEditBridge extends FreedomService public class WorldEditBridge extends AbstractService
{ {
// //

View file

@ -1,21 +1,26 @@
package me.totalfreedom.totalfreedommod.bridge; package me.totalfreedom.totalfreedommod.bridge;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer; import com.sk89q.worldguard.protection.regions.RegionContainer;
import java.util.Map; import java.util.Map;
import me.totalfreedom.totalfreedommod.FreedomService;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import me.totalfreedom.totalfreedommod.services.AbstractService;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class WorldGuardBridge extends FreedomService public class WorldGuardBridge extends AbstractService
{ {
@Override @Override
public void onStart() public void onStart()
{ {
plugin.wr.protectWorld(plugin.wm.masterBuilderWorld.getWorld()); plugin.worldRestrictions.protectWorld(plugin.worldManager.masterBuilderWorld.getWorld());
} }
@Override @Override
@ -23,6 +28,16 @@ public class WorldGuardBridge extends FreedomService
{ {
} }
public boolean canEditCurrentWorld(Player player)
{
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = container.createQuery();
return query.testBuild(localPlayer.getLocation(), localPlayer);
}
public RegionManager getRegionManager(World world) public RegionManager getRegionManager(World world)
{ {
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();

View file

@ -1,13 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
public class CommandFailException extends RuntimeException
{
private static final long serialVersionUID = -92333791173123L;
public CommandFailException(String message)
{
super(message);
}
}

View file

@ -1,85 +1,83 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.services.AbstractService;
import me.totalfreedom.totalfreedommod.util.FLog;
import org.reflections.Reflections;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.util.FLog;
import org.reflections.Reflections;
public class CommandLoader extends FreedomService public class CommandLoader extends AbstractService {
{
private final List<FreedomCommand> commands; private final List<FreedomCommand> commands;
public CommandLoader() public CommandLoader() {
{
commands = new ArrayList<>(); commands = new ArrayList<>();
} }
@Override @Override
public void onStart() public void onStart() {
{
} }
@Override @Override
public void onStop() public void onStop() {
{
} }
public void add(FreedomCommand command) public void add(Class<? extends FreedomCommand> command) {
{ FreedomCommand cmd = null;
commands.add(command); try {
command.register(); Constructor<?> constructor = command.getDeclaredConstructor();
constructor.setAccessible(true);
cmd = (FreedomCommand) constructor.newInstance();
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
if (cmd != null) {
commands.add(cmd);
cmd.register();
}
} }
public FreedomCommand getByName(String name) public FreedomCommand getByName(String name) {
{ for (FreedomCommand command : commands) {
for (FreedomCommand command : commands) if (name.equals(command.getName())) {
{
if (name.equals(command.getName()))
{
return command; return command;
} }
} }
return null; return null;
} }
public boolean isAlias(String alias) public boolean isAlias(String alias) {
{ for (FreedomCommand command : commands) {
for (FreedomCommand command : commands) if (Arrays.asList(command.getAliases().split(",")).contains(alias)) {
{
if (Arrays.asList(command.getAliases().split(",")).contains(alias))
{
return true; return true;
} }
} }
return false; return false;
} }
public void loadCommands() public void loadCommands() {
{
Reflections commandDir = new Reflections("me.totalfreedom.totalfreedommod.command"); Reflections commandDir = new Reflections("me.totalfreedom.totalfreedommod.command");
Set<Class<? extends FreedomCommand>> commandClasses = commandDir.getSubTypesOf(FreedomCommand.class); Set<Class<? extends FreedomCommand>> commandClasses = commandDir.getSubTypesOf(FreedomCommand.class);
for (Class<? extends FreedomCommand> commandClass : commandClasses) for (Class<? extends FreedomCommand> commandClass : commandClasses) {
{ try {
try add(commandClass);
{ } catch (ExceptionInInitializerError ex) {
add(commandClass.newInstance()); FLog.warning("Failed to register command: /" + commandClass.getSimpleName().replace("CMD", ""));
}
catch (InstantiationException | IllegalAccessException | ExceptionInInitializerError ex)
{
FLog.warning("Failed to register command: /" + commandClass.getSimpleName().replace("Command_", ""));
} }
} }
FLog.info("Loaded " + commands.size() + " commands"); FLog.info("Loaded " + commands.size() + " commands");
} }
public List<FreedomCommand> getCommands() public List<FreedomCommand> getCommands() {
{
return commands; return commands;
} }
} }

View file

@ -1,25 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Make an announcement anonymously to operators.", usage = "/<command> <message>")
public class Command_announce extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length < 1)
{
return false;
}
plugin.an.announce(StringUtils.join(args, " "));
return true;
}
}

View file

@ -1,36 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Toggle whether or not a player has their inventory automatically cleared when they join", usage = "/<command> <player>")
public class Command_autoclear extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0)
{
return false;
}
boolean enabled = plugin.lp.CLEAR_ON_JOIN.contains(args[0]);
if (enabled)
{
plugin.lp.CLEAR_ON_JOIN.remove(args[0]);
}
else
{
plugin.lp.CLEAR_ON_JOIN.add(args[0]);
}
msg(args[0] + " will " + (enabled ? "no longer" : "now") + " have their inventory cleared when they join.");
return true;
}
}

View file

@ -1,36 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Toggle whether or not a player is automatically teleported when they join", usage = "/<command> <player>")
public class Command_autotp extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0)
{
return false;
}
boolean enabled = plugin.lp.TELEPORT_ON_JOIN.contains(args[0]);
if (enabled)
{
plugin.lp.TELEPORT_ON_JOIN.remove(args[0]);
}
else
{
plugin.lp.TELEPORT_ON_JOIN.add(args[0]);
}
msg(args[0] + " will " + (enabled ? "no longer" : "now") + " be automatically teleported when they join.");
return true;
}
}

View file

@ -1,36 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Shows all banned player names. Admins may optionally use 'purge' to clear the list.", usage = "/<command> [purge]")
public class Command_banlist extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length > 0)
{
if (args[0].equalsIgnoreCase("purge"))
{
checkRank(Rank.SENIOR_ADMIN);
FUtil.adminAction(sender.getName(), "Purging the ban list", true);
int amount = plugin.bm.purge();
msg("Purged " + amount + " player bans.");
return true;
}
return false;
}
msg(plugin.bm.getAllBans().size() + " player bans ("
+ plugin.bm.getUsernameBans().size() + " usernames, "
+ plugin.bm.getIpBans().size() + " IPs)");
return true;
}
}

View file

@ -1,30 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Clears the chat.", usage = "/<command>", aliases = "cc")
public class Command_cleanchat extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
for (Player player : server.getOnlinePlayers())
{
if (!plugin.al.isAdmin(player))
{
for (int i = 0; i < 100; i++)
{
msg(player, "");
}
}
}
FUtil.adminAction(sender.getName(), "Cleared chat", true);
return true;
}
}

View file

@ -1,19 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.ONLY_CONSOLE)
@CommandParameters(description = "Clear the Discord message queue.", usage = "/<command>")
public class Command_cleardiscordqueue extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
plugin.dc.clearQueue();
msg("Cleared the Discord message queue.");
return true;
}
}

View file

@ -1,29 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.shop.ShopItem;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Obtain a clown fish", usage = "/<command>")
public class Command_clownfish extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (plugin.pl.getData(playerSender).hasItem(ShopItem.CLOWN_FISH) && (!plugin.lp.CLOWNFISH_TOGGLE.contains(playerSender.getName())))
{
playerSender.getInventory().addItem(plugin.sh.getClownFish());
msg("You have been given a Clown Fish", ChatColor.GREEN);
}
else
{
msg("You do not own a Clown Fish or an admin has toggled your ability to use it. Purchase one from the shop.", ChatColor.RED);
}
return true;
}
}

View file

@ -1,24 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Spy on commands", usage = "/<command>", aliases = "commandspy")
public class Command_cmdspy extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
Admin admin = plugin.al.getAdmin(playerSender);
admin.setCommandSpy(!admin.getCommandSpy());
msg("CommandSpy " + (admin.getCommandSpy() ? "enabled." : "disabled."));
plugin.al.save(admin);
plugin.al.updateTables();
return true;
}
}

View file

@ -1,54 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Shows the amount of coins you have or another player has", usage = "/<command> [playername]")
public class Command_coins extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!ConfigEntry.SHOP_ENABLED.getBoolean())
{
msg("The shop is currently disabled!", ChatColor.RED);
return true;
}
Player p;
final String prefix = FUtil.colorize(ConfigEntry.SHOP_PREFIX.getString() + " ");
if (args.length > 0)
{
if (getPlayer(args[0]) != null)
{
p = getPlayer(args[0]);
}
else
{
msg(PLAYER_NOT_FOUND);
return true;
}
}
else
{
if (senderIsConsole)
{
msg(prefix + ChatColor.RED + "You are not a player, use /coins <playername>");
return true;
}
else
{
p = playerSender;
}
}
PlayerData playerData = plugin.pl.getData(p);
msg(prefix + ChatColor.GREEN + (args.length > 0 ? p.getName() + " has " : "You have ") + ChatColor.RED + playerData.getCoins() + ChatColor.GREEN + " coins.");
return true;
}
}

View file

@ -1,32 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Essentials Interface Command - Remove the nickname of all players on the server.", usage = "/<command>")
public class Command_denick extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!plugin.esb.isEnabled())
{
msg("Essentials is not enabled on this server.");
return true;
}
FUtil.adminAction(sender.getName(), "Removing all nicknames", false);
for (Player player : server.getOnlinePlayers())
{
plugin.esb.setNickname(player.getName(), null);
}
return true;
}
}

View file

@ -1,38 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Toggle LibsDisguises for everyone online.", usage = "/<command>", aliases = "dtoggle")
public class Command_disguisetoggle extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!plugin.ldb.isEnabled())
{
msg("LibsDisguises is not enabled.");
return true;
}
FUtil.adminAction(sender.getName(), (plugin.ldb.isDisguisesEnabled() ? "Disabling" : "Enabling") + " disguises", false);
if (plugin.ldb.isDisguisesEnabled())
{
plugin.ldb.undisguiseAll(true);
plugin.ldb.setDisguisesEnabled(false);
}
else
{
plugin.ldb.setDisguisesEnabled(true);
}
msg("Disguises are now " + (plugin.ldb.isDisguisesEnabled() ? "enabled." : "disabled."));
return true;
}
}

View file

@ -1,40 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Eject players that are riding you.", usage = "/<command>")
public class Command_eject extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
List<String> names = new ArrayList<>();
for (Entity entity : playerSender.getPassengers())
{
names.add(entity.getName());
}
if (names.isEmpty())
{
msg("Nothing was ejected.", ChatColor.GREEN);
return true;
}
msg("Ejecting " + StringUtils.join(names, ", ") + ".", ChatColor.GREEN);
playerSender.eject();
return true;
}
}

View file

@ -1,19 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.NON_OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Go to \"The End\".", usage = "/<command>")
public class Command_end extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
plugin.wm.gotoWorld(playerSender, server.getWorlds().get(0).getName() + "_the_end");
return true;
}
}

View file

@ -1,31 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Make arrows explode", usage = "/<command>", aliases = "ea")
public class Command_explosivearrows extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
boolean onList = plugin.it.explosivePlayers.contains(playerSender);
if (onList)
{
plugin.it.explosivePlayers.remove(playerSender);
msg("You no longer have explosive arrows", ChatColor.RED);
}
else
{
plugin.it.explosivePlayers.add(playerSender);
msg("You now have explosive arrows", ChatColor.GREEN);
}
return true;
}
}

View file

@ -1,35 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Shows all IPs registered to a player", usage = "/<command> <player>", aliases = "showip,listip")
public class Command_findip extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
{
return false;
}
final Player player = getPlayer(args[0]);
if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
msg("Player IPs: " + StringUtils.join(plugin.pl.getData(player).getIps(), ", "));
return true;
}
}

View file

@ -1,29 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.shop.ShopItem;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Obtain a fire ball", usage = "/<command>")
public class Command_fireball extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (plugin.pl.getData(playerSender).hasItem(ShopItem.FIRE_BALL))
{
playerSender.getInventory().addItem(plugin.sh.getFireBall());
msg("You have been given a Fire Ball", ChatColor.GREEN);
}
else
{
msg("You do not own a Fire Ball! Purchase one from the shop.", ChatColor.RED);
}
return true;
}
}

View file

@ -1,27 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.NON_OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Go to the Flatlands.", usage = "/<command>")
public class Command_flatlands extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (ConfigEntry.FLATLANDS_GENERATE.getBoolean())
{
plugin.wm.flatlands.sendToWorld(playerSender);
}
else
{
msg("Flatlands is currently disabled in the TotalFreedomMod configuration.");
}
return true;
}
}

View file

@ -1,37 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Forcefully kill someone - for those who REALLY need to die.", usage = "/<command> <playername>")
public class Command_forcekill extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!plugin.al.isAdmin(sender) && !senderIsConsole)
{
playerSender.setHealth(0);
return true;
}
if (args.length < 1)
{
return false;
}
final Player player = getPlayer(args[0]);
if (player == null)
{
msg(PLAYER_NOT_FOUND);
return true;
}
player.setHealth(0);
return true;
}
}

View file

@ -1,29 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.shop.ShopItem;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Obtain a grappling hook", usage = "/<command>")
public class Command_grapplinghook extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (plugin.pl.getData(playerSender).hasItem(ShopItem.GRAPPLING_HOOK))
{
playerSender.getInventory().addItem(plugin.sh.getGrapplingHook());
msg("You have been given a Grappling Hook", ChatColor.GREEN);
}
else
{
msg("You do not own a Grappling Hook! Purchase one from the shop.", ChatColor.RED);
}
return true;
}
}

View file

@ -1,32 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE)
@CommandParameters(description = "Reload the indefinite ban list.", usage = "/<command> <reload>", aliases = "ib")
public class Command_indefban extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
{
return false;
}
if (!args[0].equalsIgnoreCase("reload"))
{
return false;
}
msg("Reloading the indefinite ban list...");
plugin.im.onStop();
plugin.im.onStart();
msg("Reloaded the indefinite ban list.");
return true;
}
}

View file

@ -1,116 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.totalfreedommod.fun.Jumppads;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Toggles jumppads on/off, view the status of jumppads, or make them sideways.", usage = "/<command> <on | off | info | sideways <on | off>>", aliases = "launchpads,jp")
public class Command_jumppads extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, 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"))
{
msg("Jumppads: " + (plugin.jp.players.get(playerSender).isOn() ? "Enabled" : "Disabled"), ChatColor.BLUE);
msg("Sideways: " + (plugin.jp.players.get(playerSender) == Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS ? "Enabled" : "Disabled"), ChatColor.BLUE);
return true;
}
if (args[0].equalsIgnoreCase("off"))
{
if (plugin.jp.players.get(playerSender) == Jumppads.JumpPadMode.OFF)
{
msg("Your jumppads are already disabled.");
return true;
}
msg("Disabled your jumppads.", ChatColor.GRAY);
plugin.jp.players.put(playerSender, Jumppads.JumpPadMode.OFF);
}
else
{
if (plugin.jp.players.get(playerSender) != Jumppads.JumpPadMode.OFF)
{
msg("Your jumppads are already enabled.");
return true;
}
msg("Enabled your jumpppads.", ChatColor.GRAY);
plugin.jp.players.put(playerSender, Jumppads.JumpPadMode.MADGEEK);
}
}
else
{
if (plugin.jp.players.get(playerSender) == Jumppads.JumpPadMode.OFF)
{
msg("Your jumppads are currently disabled, please enable them before changing jumppads settings.");
return true;
}
if (args[0].equalsIgnoreCase("sideways"))
{
if ("off".equals(args[1]))
{
if (plugin.jp.players.get(playerSender) == Jumppads.JumpPadMode.MADGEEK)
{
msg("Your jumppads are already set to normal mode.");
return true;
}
msg("Set Jumppads mode to: Normal", ChatColor.GRAY);
plugin.jp.players.put(playerSender, Jumppads.JumpPadMode.MADGEEK);
}
else
{
if (plugin.jp.players.get(playerSender) == Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS)
{
msg("Your jumppads are already set to normal and sideways mode.");
return true;
}
msg("Set Jumppads mode to: Normal and Sideways", ChatColor.GRAY);
plugin.jp.players.put(playerSender, Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS);
}
}
else
{
return false;
}
}
return true;
}
@Override
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
{
if (!plugin.al.isAdmin(sender))
{
return Collections.emptyList();
}
if (args.length == 1)
{
return Arrays.asList("on", "off", "info", "sideways");
}
else if (args.length == 2)
{
if (args[0].equals("sideways"))
{
return Arrays.asList("on", "off");
}
}
return Collections.emptyList();
}
}

View file

@ -1,29 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.shop.ShopItem;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Obtain a lightning rod", usage = "/<command>")
public class Command_lightningrod extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (plugin.pl.getData(playerSender).hasItem(ShopItem.LIGHTNING_ROD))
{
playerSender.getInventory().addItem(plugin.sh.getLightningRod());
msg("You have been given a Lightning Rod", ChatColor.GREEN);
}
else
{
msg("You do not own a Lightning Rod! Purchase one from the shop.", ChatColor.RED);
}
return true;
}
}

View file

@ -1,60 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.discord.Discord;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Link your Discord account to your Minecraft account", usage = "/<command> [<name> <id>]")
public class Command_linkdiscord extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!plugin.dc.enabled)
{
msg("The Discord verification system is currently disabled.", ChatColor.RED);
return true;
}
if (args.length > 1 && plugin.al.isAdmin(playerSender))
{
PlayerData playerData = plugin.pl.getData(args[0]);
if (playerData == null)
{
msg(PLAYER_NOT_FOUND);
return true;
}
playerData.setDiscordID(args[1]);
msg("Linked " + args[0] + "'s Discord account.", ChatColor.GREEN);
return true;
}
String code;
PlayerData data = plugin.pl.getData(playerSender);
if (data.getDiscordID() != null)
{
msg("Your Minecraft account is already linked to a Discord account.", ChatColor.RED);
return true;
}
if (Discord.LINK_CODES.containsValue(data))
{
code = Discord.getCode(data);
}
else
{
code = plugin.dc.generateCode(5);
Discord.LINK_CODES.put(code, data);
}
msg("Your linking code is " + ChatColor.AQUA + code, ChatColor.GREEN);
msg("Take this code and DM the server bot (" + plugin.dc.formatBotTag() + ") the code (do not put anything else in the message, only the code)");
return true;
}
}

View file

@ -1,26 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.LogViewer.LogsRegistrationMode;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Register your connection with the TFM logviewer.", usage = "/<command> [off]")
public class Command_logs extends FreedomCommand
{
@Override
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
LogsRegistrationMode mode = LogsRegistrationMode.ADD;
if (args.length == 1 && "off".equalsIgnoreCase(args[0]))
{
mode = LogsRegistrationMode.DELETE;
}
plugin.lv.updateLogsRegistration(sender, playerSender, mode);
return true;
}
}

View file

@ -1,96 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.RegionGroup;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.HashMap;
import java.util.Map;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Make a WorldGuard region for an OP.", usage = "/<command> <playername> <name>", aliases = "mor")
public class Command_makeopregion extends FreedomCommand
{
final Map<Flag<?>, Object> flags = new HashMap<Flag<?>, Object>()
{{
put(Flags.BLOCK_PLACE, StateFlag.State.ALLOW);
put(Flags.BLOCK_BREAK, StateFlag.State.ALLOW);
put(Flags.BUILD, StateFlag.State.ALLOW);
put(Flags.PLACE_VEHICLE, StateFlag.State.ALLOW);
put(Flags.DESTROY_VEHICLE, StateFlag.State.ALLOW);
put(Flags.ENTITY_ITEM_FRAME_DESTROY, StateFlag.State.ALLOW);
put(Flags.ENTITY_PAINTING_DESTROY, StateFlag.State.ALLOW);
put(net.goldtreeservers.worldguardextraflags.flags.Flags.WORLDEDIT, StateFlag.State.ALLOW);
}};
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
{
if (args.length < 2)
{
return false;
}
final Player player = getPlayer(args[0]);
if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
String name = args[1];
LocalSession session = plugin.web.getWorldEditPlugin().getSession(playerSender);
Region selection;
try
{
selection = session.getSelection(session.getSelectionWorld());
}
catch (IncompleteRegionException e)
{
msg("Please make a WorldEdit selection", ChatColor.RED);
return true;
}
if (selection == null)
{
msg("Please make a WorldEdit selection", ChatColor.RED);
return true;
}
ProtectedRegion region = new ProtectedCuboidRegion(name, selection.getMinimumPoint(), selection.getMaximumPoint());
DefaultDomain owners = new DefaultDomain();
owners.addPlayer(playerSender.getName());
owners.addPlayer(player.getName());
region.setOwners(owners);
region.setFlags(flags);
for (Flag<?> flag : flags.keySet())
{
region.setFlag(flag.getRegionGroupFlag(), RegionGroup.MEMBERS);
}
RegionManager regionManager = plugin.wgb.getRegionManager(playerSender.getWorld());
regionManager.addRegion(region);
msg("Successfully created the region '" + name + "' for " + player.getName(), ChatColor.GREEN);
return true;
}
}

View file

@ -1,265 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.List;
import java.util.SplittableRandom;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffectType;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Modify the current item you are holding.", usage = "/<command> <name <message> | lore <message> | enchant <enchantment> <level> | potion <effect> <duration> <amplifier> | attribute <name> <amount> | clear>", aliases = "mi")
public class Command_modifyitem extends FreedomCommand
{
@SuppressWarnings("deprecation")
@Override
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length < 1)
{
return false;
}
ItemStack item = playerSender.getInventory().getItemInMainHand();
if (item.getType().equals(Material.AIR))
{
msg("You must have an item in your hand!");
return true;
}
if (args[0].equalsIgnoreCase("clear"))
{
item.setItemMeta(null);
playerSender.getInventory().setItemInMainHand(item);
return true;
}
if (args.length < 2)
{
return false;
}
ItemMeta meta = item.getItemMeta();
assert meta != null;
switch (args[0])
{
case "name":
String name = FUtil.colorize(StringUtils.join(args, " ", 1, args.length));
meta.setDisplayName(name);
item.setItemMeta(meta);
break;
case "lore":
List<String> lore = new ArrayList<>();
for (String line : StringUtils.join(args, " ", 1, args.length).split("\\\\n"))
{
lore.add(FUtil.colorize(line));
}
meta.setLore(lore);
item.setItemMeta(meta);
break;
case "enchant":
if (args.length < 3)
{
return false;
}
Enchantment enchantment = Enchantment.getByName(args[1].toUpperCase());
if (enchantment == null)
{
msg("Invalid enchantment. Please run /enchant list for a list of valid enchantments.");
return true;
}
int level;
try
{
level = Integer.parseInt(args[2]);
}
catch (NumberFormatException ex)
{
msg("The level specified is not a valid integer.");
return true;
}
meta.addEnchant(enchantment, level, true);
item.setItemMeta(meta);
break;
case "potion":
{
if (!item.getType().equals(Material.POTION) & !item.getType().equals(Material.SPLASH_POTION) & !item.getType().equals(Material.LINGERING_POTION) & !item.getType().equals(Material.TIPPED_ARROW))
{
msg("This item can not have potion effects added to it.");
return true;
}
if (args.length < 4)
{
return false;
}
PotionEffectType type = PotionEffectType.getByName(args[1]);
if (type == null)
{
msg("Invalid potion effect. Please run /potion list for a list of valid potion effects.");
return true;
}
int duration;
try
{
duration = Math.max(1, Math.min(1000000, Integer.parseInt(args[2])));
}
catch (NumberFormatException ex)
{
msg("The duration specified is not a valid integer.");
return true;
}
int amplifier;
try
{
amplifier = Math.max(1, Math.min(256, Integer.parseInt(args[2])));
}
catch (NumberFormatException ex)
{
msg("The amplifier specified is not a valid integer.");
return true;
}
PotionMeta potionMeta = (PotionMeta)meta;
potionMeta.addCustomEffect(type.createEffect(duration, amplifier), true);
item.setItemMeta(potionMeta);
break;
}
case "attribute":
if (args.length < 3)
{
return false;
}
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = getAttributeList(nmsStack);
NBTTagCompound cmpnd = new NBTTagCompound();
Attribute attribute = Attribute.getByName(args[1].toUpperCase());
if (attribute == null)
{
msg("Invalid attribute. Please run /attributelist for a list of valid attributes.");
return true;
}
cmpnd.setString("AttributeName", attribute.getAttribute());
cmpnd.setString("Name", attribute.getAttribute());
double amount;
try
{
amount = Double.parseDouble(args[2]);
}
catch (NumberFormatException ex)
{
msg("The amount specified is not a valid integer.");
return true;
}
if (Double.isNaN(amount))
{
msg("The amount specified is illegal.");
return true;
}
cmpnd.setDouble("Amount", amount);
cmpnd.setInt("Operation", 0);
SplittableRandom random = new SplittableRandom();
cmpnd.setIntArray("UUID", new int[]
{
random.nextInt(),
random.nextInt(),
random.nextInt(),
random.nextInt()
});
cmpnd.setString("Slot", "mainhand");
modifiers.add(cmpnd);
assert compound != null;
compound.set("AttributeModifiers", modifiers);
nmsStack.setTag(compound);
item = CraftItemStack.asBukkitCopy(nmsStack);
break;
default:
return false;
}
playerSender.getInventory().setItemInMainHand(item);
return true;
}
private NBTTagList getAttributeList(net.minecraft.world.item.ItemStack stack)
{
if (stack.getTag() == null)
{
stack.setTag(new NBTTagCompound());
}
NBTTagList attr = stack.getTag().getList("AttributeModifiers", 10);
if (attr == null)
{
stack.getTag().set("AttributeModifiers", new NBTTagList());
}
return stack.getTag().getList("AttributeModifiers", 10);
}
private enum Attribute
{
GENERIC_MAX_HEALTH("GENERIC_MAX_HEALTH", "generic.max_health"),
GENERIC_FOLLOW_RANGE("GENERIC_FOLLOW_RANGE", "generic.follow_range"),
GENERIC_KNOCKBACK_RESISTANCE("GENERIC_KNOCKBACK_RESISTANCE", "generic.knockback_resistance"),
GENERIC_MOVEMENT_SPEED("GENERIC_MOVEMENT_SPEED", "generic.movement_speed"),
GENERIC_FLYING_SPEED("GENERIC_FLYING_SPEED", "generic.flying_speed"),
GENERIC_ATTACK_DAMAGE("GENERIC_ATTACK_DAMAGE", "generic.attack_damage"),
GENERIC_ATTACK_SPEED("GENERIC_ATTACK_SPEED", "generic.attack_speed"),
GENERIC_ARMOR("GENERIC_ARMOR", "generic.armor"),
GENERIC_ARMOR_TOUGHNESS("GENERIC_ARMOR_TOUGHNESS", "generic.armor_toughmess"),
GENERIC_LUCK("GENERIC_LUCK", "generic.luck"),
HORSE_JUMP_STRENGTH("GENERIC_MAX_HEALTH", "horse.jump_strength"),
ZOMBIE_SPAWN_REINFORCEMENTS("ZOMBIE_SPAWN_REINFORCEMENTS", "zombie.spawn_reinforcements");
private final String name;
private final String attribute;
Attribute(String name, String attribute)
{
this.name = name;
this.attribute = attribute;
}
public static Attribute getByName(String name)
{
for (Attribute attr : Attribute.values())
{
if (attr.toString().toUpperCase().equals(name))
{
return attr;
}
}
return null;
}
public String getAttribute()
{
return attribute;
}
@Override
public String toString()
{
return name;
}
}
}

View file

@ -1,18 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Check your personal data", usage = "/<command>")
public class Command_myinfo extends FreedomCommand
{
@Override
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
msg(plugin.pl.getData(playerSender).toString());
return true;
}
}

View file

@ -1,23 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.History;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Check the name history of a specified player.", usage = "/<command> <username>", aliases = "nh")
public class Command_namehistory extends FreedomCommand
{
@Override
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
{
return false;
}
History.reportHistory(sender, args[0]);
return true;
}
}

View file

@ -1,19 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.NON_OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Go to the Nether.", usage = "/<command>", aliases = "hell")
public class Command_nether extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
plugin.wm.gotoWorld(playerSender, server.getWorlds().get(0).getName() + "_nether");
return true;
}
}

View file

@ -1,31 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH, cooldown = 30)
@CommandParameters(description = "OP everyone on the server.", usage = "/<command>")
public class Command_opall extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
FUtil.adminAction(sender.getName(), "Opping all players on the server", false);
for (Player player : server.getOnlinePlayers())
{
if (!player.isOp())
{
player.setOp(true);
msg(player, YOU_ARE_OP);
plugin.rm.updateDisplay(player);
}
}
return true;
}
}

View file

@ -1,26 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Forcefully start a reaction", usage = "/<command>")
public class Command_reactionbar extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!FUtil.isDeveloper(playerSender))
{
return noPerms();
}
plugin.sh.forceStartReaction();
msg("Started a reaction.");
return true;
}
}

View file

@ -1,41 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Release parrots from your shoulders.", usage = "/<command>", aliases = "removeparrots")
public class Command_releaseparrots extends FreedomCommand
{
@SuppressWarnings("deprecation")
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
Entity leftShoulderEntity = playerSender.getShoulderEntityLeft();
Entity rightShoulderEntity = playerSender.getShoulderEntityRight();
if (rightShoulderEntity == null && leftShoulderEntity == null)
{
msg("No parrots were detected on either of your shoulders.");
return true;
}
if (leftShoulderEntity != null && leftShoulderEntity.getType().equals(EntityType.PARROT))
{
playerSender.setShoulderEntityLeft(null);
msg("Removed the parrot on your left shoulder.");
}
if (rightShoulderEntity != null && rightShoulderEntity.getType().equals(EntityType.PARROT))
{
playerSender.setShoulderEntityRight(null);
msg("Removed the parrot on your right shoulder.");
}
return true;
}
}

View file

@ -1,29 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.shop.ShopItem;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Obtain a rideable ender pearl", usage = "/<command>")
public class Command_rideablepearl extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (plugin.pl.getData(playerSender).hasItem(ShopItem.RIDEABLE_PEARL))
{
playerSender.getInventory().addItem(plugin.sh.getRideablePearl());
msg("You have been given a Rideable Ender Pearl", ChatColor.GREEN);
}
else
{
msg("You do not own a Rideable Ender Pearl! Purchase one from the shop.", ChatColor.RED);
}
return true;
}
}

View file

@ -1,28 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Check the status of the server, including opped players, admins, etc.", usage = "/<command>", aliases = "ss")
public class Command_serverstats extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
msg("-==" + ConfigEntry.SERVER_NAME.getString() + " server stats==-", ChatColor.GOLD);
msg("Total opped players: " + server.getOperators().size(), ChatColor.RED);
msg("Total admins: " + plugin.al.getAllAdmins().size() + " (" + plugin.al.getActiveAdmins().size() + " active)", ChatColor.BLUE);
int bans = plugin.im.getIndefBans().size();
int nameBans = plugin.im.getNameBanCount();
int uuidBans = plugin.im.getUuidBanCount();
int ipBans = plugin.im.getIpBanCount();
msg("Total indefinite ban entries: " + bans + " (" + nameBans + " name bans, " + uuidBans + " UUID bans, and " + ipBans + " IP bans)", ChatColor.GREEN);
return true;
}
}

View file

@ -1,49 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Sets your experience level (XP).", usage = "/<command> [level]")
public class Command_setlevel extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
{
return false;
}
int new_level;
try
{
new_level = Integer.parseInt(args[0]);
if (new_level < 0)
{
new_level = 0;
}
else if (new_level > 50)
{
new_level = 50;
}
}
catch (NumberFormatException ex)
{
msg("Invalid level.", ChatColor.RED);
return true;
}
playerSender.setLevel(new_level);
msg("Your XP level is now set to " + ChatColor.GOLD + new_level);
return true;
}
}

View file

@ -1,50 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Sets everyone's WorldEdit block modification limit to the default limit or to a custom limit.", usage = "/<command> [limit]", aliases = "setl,swl")
public class Command_setlimit extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
int amount = plugin.web.getDefaultLimit();
if (args.length > 0)
{
try
{
amount = Math.max(-1, Math.min(plugin.web.getMaxLimit(), Integer.parseInt(args[0])));
}
catch (NumberFormatException ex)
{
msg("Invalid number: " + args[0], ChatColor.RED);
return true;
}
}
boolean success = false;
for (final Player player : server.getOnlinePlayers())
{
try
{
plugin.web.setLimit(player, amount);
success = true;
}
catch (NoClassDefFoundError | NullPointerException ex)
{
msg("WorldEdit is not enabled on this server.");
success = false;
}
}
if (success)
{
FUtil.adminAction(sender.getName(), "Setting everyone's WorldEdit block modification limit to " + amount + ".", true);
}
return true;
}
}

View file

@ -1,26 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Open the shop GUI", usage = "/<command>", aliases = "sh")
public class Command_shop extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!ConfigEntry.SHOP_ENABLED.getBoolean())
{
msg("The shop is currently disabled!", ChatColor.RED);
return true;
}
playerSender.openInventory(plugin.sh.generateShopGUI(plugin.pl.getData(playerSender)));
return true;
}
}

View file

@ -1,29 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.shop.ShopItem;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Obtain a stacking potato", usage = "/<command>")
public class Command_stackingpotato extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (plugin.pl.getData(playerSender).hasItem(ShopItem.STACKING_POTATO))
{
playerSender.getInventory().addItem(plugin.sh.getStackingPotato());
msg("You have been given a Stacking Potato", ChatColor.GREEN);
}
else
{
msg("You do not own the Stacking Potato! Purchase one from the shop.", ChatColor.RED);
}
return true;
}
}

View file

@ -1,36 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Toggle whether or not a player has the ability to use clownfish", usage = "/<command> <player>", aliases = "togglecf")
public class Command_toggleclownfish extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0)
{
return false;
}
boolean enabled = plugin.lp.CLOWNFISH_TOGGLE.contains(args[0]);
if (enabled)
{
plugin.lp.CLOWNFISH_TOGGLE.remove(args[0]);
}
else
{
plugin.lp.CLOWNFISH_TOGGLE.add(args[0]);
}
msg(args[0] + " will " + (enabled ? "now" : "no longer") + " have the ability to use clownfish.");
return true;
}
}

View file

@ -1,22 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Toggle the display of Discord messages in-game.", usage = "/<command>", aliases = "tdiscord,tdisc")
public class Command_togglediscord extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
PlayerData data = plugin.pl.getData(playerSender);
data.setDisplayDiscord(!data.doesDisplayDiscord());
plugin.pl.save(data);
msg("Discord messages will " + (data.doesDisplayDiscord() ? "now" : "no longer") + " be shown.");
return true;
}
}

View file

@ -1,29 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Trails rainbow wool behind you as you walk/fly.", usage = "/<command>")
public class Command_trail extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (plugin.tr.contains(playerSender))
{
plugin.tr.remove(playerSender);
msg("Trail disabled.");
}
else
{
plugin.tr.add(playerSender);
msg("Trail enabled. Use \"/trail off\" to disable.");
}
return true;
}
}

View file

@ -1,66 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.totalfreedommod.banning.Ban;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Unbans the specified player.", usage = "/<command> <username> [-r]")
public class Command_unban extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length > 0)
{
String username;
final PlayerData entry = plugin.pl.getData(args[0]);
if (entry == null)
{
msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly.");
return true;
}
username = entry.getName();
final List<String> ips = new ArrayList<>(entry.getIps());
FUtil.adminAction(sender.getName(), "Unbanning " + username, true);
msg(username + " has been unbanned along with the following IPs: " + StringUtils.join(ips, ", "));
plugin.bm.removeBan(plugin.bm.getByUsername(username));
if (args.length >= 2)
{
if (args[1].equalsIgnoreCase("-r"))
{
plugin.cpb.restore(username);
msg("Restored edits for: " + username);
}
}
for (String ip : ips)
{
Ban ban = plugin.bm.getByIp(ip);
if (ban != null)
{
plugin.bm.removeBan(ban);
}
ban = plugin.bm.getByIp(FUtil.getFuzzyIp(ip));
if (ban != null)
{
plugin.bm.removeBan(ban);
}
}
return true;
}
return false;
}
}

View file

@ -1,101 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.discord.Discord;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.IMPOSTOR, source = SourceType.BOTH)
@CommandParameters(description = "Sends a verification code to the player, or the player can input the sent code. Admins can manually verify a player impostor.", usage = "/<command> <code | <playername>>")
public class Command_verify extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
boolean verificationEnabled = ConfigEntry.DISCORD_VERIFICATION.getBoolean();
if (!plugin.dc.enabled)
{
msg("The Discord verification system is currently disabled.", ChatColor.RED);
return true;
}
if (!verificationEnabled)
{
msg("The Discord verification system is currently disabled.", ChatColor.RED);
return true;
}
if (senderIsConsole)
{
msg("/manuallyverify <playername>", ChatColor.WHITE);
return true;
}
if (!plugin.pl.IsImpostor(playerSender))
{
msg("You are not an impostor, therefore you do not need to verify.", ChatColor.RED);
return true;
}
PlayerData playerData = plugin.pl.getData(playerSender);
String discordId = playerData.getDiscordID();
if (playerData.getDiscordID() == null)
{
msg("You do not have a Discord account linked to your Minecraft account, please verify the manual way.", ChatColor.RED);
return true;
}
if (args.length == 0)
{
String code = plugin.dc.generateCode(10);
plugin.dc.addVerificationCode(code, playerData);
plugin.dc.getUser(discordId).openPrivateChannel().complete().sendMessage("A user with the IP `" + FUtil.getIp(playerSender) + "` has sent a verification request. Please run the following in-game command: `/verify " + code + "`").complete();
msg("A verification code has been sent to your account, please copy the code and run /verify <code>", ChatColor.GREEN);
return true;
}
String code = args[0];
String backupCode = null;
if (plugin.pl.IsImpostor(playerSender))
{
PlayerData mapPlayer = plugin.dc.getVerificationCodes().get(code);
if (mapPlayer == null)
{
if (!playerData.getBackupCodes().contains(Discord.getMD5(code)))
{
msg("You have entered an invalid verification code", ChatColor.RED);
return true;
}
else
{
backupCode = Discord.getMD5(code);
}
}
else
{
plugin.dc.removeVerificationCode(code);
}
final FPlayer fPlayer = plugin.pl.getPlayer(playerSender);
if (fPlayer.getFreezeData().isFrozen())
{
fPlayer.getFreezeData().setFrozen(false);
msg("You have been unfrozen.");
}
FUtil.bcastMsg(playerSender.getName() + " has verified!", ChatColor.GOLD);
playerSender.setOp(true);
plugin.pl.verify(playerSender, backupCode);
return true;
}
return true;
}
}

View file

@ -0,0 +1,25 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import org.bukkit.command.Command;
public abstract class FreedomCMD extends Command
{
protected final TotalFreedomMod plugin = TotalFreedomMod.plugin();
private final CommandParameters parameters;
private final CommandPermissions permissions;
public FreedomCMD() {
super("");
this.parameters = this.getClass().getDeclaredAnnotation(CommandParameters.class);
this.permissions = this.getClass().getDeclaredAnnotation(CommandPermissions.class);
this.setName(parameters.name());
this.setLabel(parameters.name());
}
}

View file

@ -1,16 +1,12 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.command.exception.CommandFailException;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
@ -18,20 +14,15 @@ import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.Command; import org.bukkit.command.*;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public abstract class FreedomCommand implements CommandExecutor, TabCompleter import java.lang.reflect.Field;
{ import java.util.*;
public static final String COMMAND_PREFIX = "Command_";
public abstract class FreedomCommand implements CommandExecutor, TabCompleter {
public static final String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!"; public static final String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!";
public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!"; public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!";
public static final String PLAYER_NOT_FOUND = ChatColor.GRAY + "Player not found!"; public static final String PLAYER_NOT_FOUND = ChatColor.GRAY + "Player not found!";
@ -55,11 +46,10 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
private final CommandPermissions perms; private final CommandPermissions perms;
protected CommandSender sender; protected CommandSender sender;
FreedomCommand() public FreedomCommand() {
{ this.params = getClass().getAnnotation(CommandParameters.class);
params = getClass().getAnnotation(CommandParameters.class); this.perms = getClass().getAnnotation(CommandPermissions.class);
perms = getClass().getAnnotation(CommandPermissions.class); this.name = params.name();
this.name = getClass().getSimpleName().replace(COMMAND_PREFIX, "").toLowerCase();
this.description = params.description(); this.description = params.description();
this.usage = params.usage(); this.usage = params.usage();
this.aliases = params.aliases(); this.aliases = params.aliases();
@ -69,148 +59,109 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
this.cooldown = perms.cooldown(); this.cooldown = perms.cooldown();
} }
public static CommandMap getCommandMap() public static CommandMap getCommandMap() {
{ if (commandMap == null) {
if (commandMap == null) try {
{
try
{
final Field f = Bukkit.getServer().getPluginManager().getClass().getDeclaredField("commandMap"); final Field f = Bukkit.getServer().getPluginManager().getClass().getDeclaredField("commandMap");
f.setAccessible(true); f.setAccessible(true);
commandMap = (CommandMap)f.get(Bukkit.getServer().getPluginManager()); commandMap = (CommandMap) f.get(Bukkit.getServer().getPluginManager());
} } catch (Exception e) {
catch (Exception e)
{
e.printStackTrace(); e.printStackTrace();
} }
} }
return commandMap; return commandMap;
} }
public static FreedomCommand getFrom(Command command) public static FreedomCommand getFrom(Command command) {
{ try {
try return (FreedomCommand) (((PluginCommand) command).getExecutor());
{ } catch (Exception ex) {
return (FreedomCommand)(((PluginCommand)command).getExecutor());
}
catch (Exception ex)
{
return null; return null;
} }
} }
public static String getCommandPrefix() public void register() {
{
return COMMAND_PREFIX;
}
public void register()
{
FCommand cmd = new FCommand(this.name); FCommand cmd = new FCommand(this.name);
if (this.aliases != null) if (this.aliases != null) {
{
cmd.setAliases(Arrays.asList(StringUtils.split(this.aliases, ","))); cmd.setAliases(Arrays.asList(StringUtils.split(this.aliases, ",")));
} }
if (this.description != null) if (this.description != null) {
{
cmd.setDescription(this.description); cmd.setDescription(this.description);
} }
if (this.usage != null) if (this.usage != null) {
{
cmd.setUsage(this.usage); cmd.setUsage(this.usage);
} }
getCommandMap().register("totalfreedommod", cmd); getCommandMap().register("totalfreedommod", cmd);
cmd.setExecutor(this); cmd.setExecutor(this);
} }
protected void msg(CommandSender sender, String message) protected void msg(CommandSender sender, String message) {
{
sender.sendMessage(ChatColor.GRAY + message); sender.sendMessage(ChatColor.GRAY + message);
} }
protected void msg(Player player, String message) protected void msg(Player player, String message) {
{
player.sendMessage(ChatColor.GRAY + message); player.sendMessage(ChatColor.GRAY + message);
} }
protected void msg(Player player, String message, ChatColor color) protected void msg(Player player, String message, ChatColor color) {
{
player.sendMessage(color + message); player.sendMessage(color + message);
} }
protected void msg(String message) protected void msg(String message) {
{
msg(sender, message); msg(sender, message);
} }
protected void msg(String message, ChatColor color) protected void msg(String message, ChatColor color) {
{
msg(color + message); msg(color + message);
} }
protected void msg(String message, net.md_5.bungee.api.ChatColor color) protected void msg(String message, net.md_5.bungee.api.ChatColor color) {
{
msg(color + message); msg(color + message);
} }
protected boolean isAdmin(Player player) protected boolean isAdmin(Player player) {
{ return plugin.adminList.isAdmin(player);
return plugin.al.isAdmin(player);
} }
protected boolean isAdmin(CommandSender sender) protected boolean isAdmin(CommandSender sender) {
{ return plugin.adminList.isAdmin(sender);
return plugin.al.isAdmin(sender);
} }
protected void checkConsole() protected void checkConsole() {
{ if (!isConsole()) {
if (!isConsole())
{
throw new CommandFailException(ONLY_CONSOLE); throw new CommandFailException(ONLY_CONSOLE);
} }
} }
protected void checkPlayer() protected void checkPlayer() {
{ if (isConsole()) {
if (isConsole())
{
throw new CommandFailException(ONLY_IN_GAME); throw new CommandFailException(ONLY_IN_GAME);
} }
} }
protected void checkRank(Rank rank) protected void checkRank(Rank rank) {
{ if (!plugin.rankManager.getRank(sender).isAtLeast(rank)) {
if (!plugin.rm.getRank(sender).isAtLeast(rank))
{
noPerms(); noPerms();
} }
} }
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String commandLabel, @NotNull String[] args) public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String commandLabel, @NotNull String[] args) {
{ try {
try boolean run = run(sender, sender instanceof ConsoleCommandSender ? null : (Player) sender, cmd, commandLabel, args, sender instanceof ConsoleCommandSender);
{ if (!run) {
boolean run = run(sender, sender instanceof ConsoleCommandSender ? null : (Player)sender, cmd, commandLabel, args, sender instanceof ConsoleCommandSender);
if (!run)
{
msg(ChatColor.WHITE + cmd.getUsage().replace("<command>", cmd.getLabel())); msg(ChatColor.WHITE + cmd.getUsage().replace("<command>", cmd.getLabel()));
return true; return true;
} }
} } catch (CommandFailException ex) {
catch (CommandFailException ex)
{
msg(ChatColor.RED + ex.getMessage()); msg(ChatColor.RED + ex.getMessage());
} }
return false; return false;
} }
@NotNull @NotNull
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
{
List<String> options = getTabCompleteOptions(sender, command, alias, args); List<String> options = getTabCompleteOptions(sender, command, alias, args);
if (options == null) if (options == null) {
{
return new ArrayList<>(); return new ArrayList<>();
} }
return StringUtil.copyPartialMatches(args[args.length - 1], options, Lists.newArrayList()); return StringUtil.copyPartialMatches(args[args.length - 1], options, Lists.newArrayList());
@ -218,136 +169,108 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
public abstract boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole); public abstract boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole);
protected List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) protected List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) {
{
return FUtil.getPlayerList(); return FUtil.getPlayerList();
} }
protected boolean isConsole() protected boolean isConsole() {
{
return sender instanceof ConsoleCommandSender; return sender instanceof ConsoleCommandSender;
} }
protected Player getPlayer(String name) protected Player getPlayer(String name) {
{
return Bukkit.getPlayer(name); return Bukkit.getPlayer(name);
} }
protected Player getPlayer(String name, Boolean nullVanished) protected Player getPlayer(String name, Boolean nullVanished) {
{
Player player = Bukkit.getPlayer(name); Player player = Bukkit.getPlayer(name);
if (player != null) if (player != null) {
{ if (nullVanished && plugin.adminList.isVanished(player.getName()) && !plugin.adminList.isAdmin(sender)) {
if (nullVanished && plugin.al.isVanished(player.getName()) && !plugin.al.isAdmin(sender))
{
return null; return null;
} }
} }
return player; return player;
} }
protected Admin getAdmin(CommandSender sender) protected Admin getAdmin(CommandSender sender) {
{ return plugin.adminList.getAdmin(sender);
return plugin.al.getAdmin(sender);
} }
protected Admin getAdmin(Player player) protected Admin getAdmin(Player player) {
{ return plugin.adminList.getAdmin(player);
return plugin.al.getAdmin(player);
} }
protected PlayerData getData(Player player) protected PlayerData getData(Player player) {
{ return plugin.playerList.getData(player);
return plugin.pl.getData(player);
} }
protected boolean noPerms() protected boolean noPerms() {
{
throw new CommandFailException(NO_PERMISSION); throw new CommandFailException(NO_PERMISSION);
} }
public String getName() public String getName() {
{
return name; return name;
} }
public String getDescription() public String getDescription() {
{
return description; return description;
} }
public String getUsage() public String getUsage() {
{
return usage; return usage;
} }
public String getAliases() public String getAliases() {
{
return aliases; return aliases;
} }
public Rank getLevel() public Rank getLevel() {
{
return level; return level;
} }
public SourceType getSource() public SourceType getSource() {
{
return source; return source;
} }
public boolean isBlockHostConsole() public boolean isBlockHostConsole() {
{
return blockHostConsole; return blockHostConsole;
} }
public int getCooldown() public int getCooldown() {
{
return cooldown; return cooldown;
} }
public CommandParameters getParams() public CommandParameters getParams() {
{
return params; return params;
} }
public CommandPermissions getPerms() public CommandPermissions getPerms() {
{
return perms; return perms;
} }
private final class FCommand extends Command private final class FCommand extends Command {
{
private FreedomCommand cmd = null; private FreedomCommand cmd = null;
private FCommand(String command) private FCommand(String command) {
{
super(command); super(command);
} }
public void setExecutor(FreedomCommand cmd) public void setExecutor(FreedomCommand cmd) {
{
this.cmd = cmd; this.cmd = cmd;
} }
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, String[] args) public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, String[] args) {
{ if (cmd != null) {
if (cmd != null)
{
cmd.sender = sender; cmd.sender = sender;
if (func4()) if (func4()) {
{
return true; return true;
} }
if (func1()) if (func1()) {
{
return true; return true;
} }
if (func2()) if (func2()) {
{
return true; return true;
} }
@ -358,16 +281,13 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
return false; return false;
} }
public boolean func1() public boolean func1() {
{ if (perms.source() == SourceType.ONLY_CONSOLE && sender instanceof Player) {
if (perms.source() == SourceType.ONLY_CONSOLE && sender instanceof Player)
{
msg(ONLY_CONSOLE); msg(ONLY_CONSOLE);
return true; return true;
} }
if (perms.source() == SourceType.ONLY_IN_GAME && sender instanceof ConsoleCommandSender) if (perms.source() == SourceType.ONLY_IN_GAME && sender instanceof ConsoleCommandSender) {
{
msg(ONLY_IN_GAME); msg(ONLY_IN_GAME);
return true; return true;
} }
@ -375,42 +295,33 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
return false; return false;
} }
public boolean func2() public boolean func2() {
{ if (!plugin.rankManager.getRank(sender).isAtLeast(perms.level())) {
if (!plugin.rm.getRank(sender).isAtLeast(perms.level()))
{
msg(NO_PERMISSION); msg(NO_PERMISSION);
return true; return true;
} }
if (perms.blockHostConsole() && FUtil.isFromHostConsole(sender.getName()) && !FUtil.inDeveloperMode()) if (perms.blockHostConsole() && FUtil.isFromHostConsole(sender.getName()) && !FUtil.inDeveloperMode()) {
{
msg(ChatColor.RED + "Host console is not allowed to use this command!"); msg(ChatColor.RED + "Host console is not allowed to use this command!");
return true; return true;
} }
return false; return false;
} }
public void func3() public void func3() {
{ if (perms.cooldown() != 0 && !isAdmin(sender)) {
if (perms.cooldown() != 0 && !isAdmin(sender))
{
COOLDOWN_TIMERS.put(sender, cmd); COOLDOWN_TIMERS.put(sender, cmd);
timer.schedule(new TimerTask() timer.schedule(new TimerTask() {
{
@Override @Override
public void run() public void run() {
{
COOLDOWN_TIMERS.remove(sender); COOLDOWN_TIMERS.remove(sender);
} }
}, perms.cooldown() * 1000L); }, perms.cooldown() * 1000L);
} }
} }
public boolean func4() public boolean func4() {
{ if (COOLDOWN_TIMERS.containsKey(sender) && COOLDOWN_TIMERS.containsValue(cmd)) {
if (COOLDOWN_TIMERS.containsKey(sender) && COOLDOWN_TIMERS.containsValue(cmd))
{
msg(ChatColor.RED + "You are on cooldown for this command."); msg(ChatColor.RED + "You are on cooldown for this command.");
return true; return true;
} }
@ -419,10 +330,8 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
@NotNull @NotNull
@Override @Override
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, String[] args) public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, String[] args) {
{ if (cmd != null) {
if (cmd != null)
{
return cmd.onTabComplete(sender, this, alias, args); return cmd.onTabComplete(sender, this, alias, args);
} }
return new ArrayList<>(); return new ArrayList<>();

View file

@ -1,6 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
public enum SourceType
{
ONLY_IN_GAME, ONLY_CONSOLE, BOTH
}

View file

@ -0,0 +1,11 @@
package me.totalfreedom.totalfreedommod.command.exception;
public class CommandFailException extends RuntimeException {
private static final long serialVersionUID = -92333791173123L;
public CommandFailException(String message) {
super(message);
}
}

View file

@ -1,5 +1,9 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command.impl;
import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.World; import org.bukkit.World;
@ -10,21 +14,16 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH) @CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Clears lingering potion area effect clouds.", usage = "/<command>", aliases = "aec") @CommandParameters(name = "aeclear", description = "Clears lingering potion area effect clouds.", usage = "/<command>", aliases = "aec")
public class Command_aeclear extends FreedomCommand public class AEClearCMD extends FreedomCommand {
{
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
{
FUtil.adminAction(sender.getName(), "Removing all area effect clouds", true); FUtil.adminAction(sender.getName(), "Removing all area effect clouds", true);
int removed = 0; int removed = 0;
for (World world : server.getWorlds()) for (World world : server.getWorlds()) {
{ for (Entity entity : world.getEntities()) {
for (Entity entity : world.getEntities()) if (entity instanceof AreaEffectCloud) {
{
if (entity instanceof AreaEffectCloud)
{
entity.remove(); entity.remove();
removed++; removed++;
} }

View file

@ -1,5 +1,9 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command.impl;
import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -8,28 +12,22 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH) @CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Talk privately with other admins on the server.", usage = "/<command> [message]", aliases = "o,sc,ac,staffchat") @CommandParameters(name = "adminchat", description = "Talk privately with other admins on the server.", usage = "/<command> [message]", aliases = "o,sc,ac,staffchat")
public class Command_adminchat extends FreedomCommand public class AdminChatCMD extends FreedomCommand {
{
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
{ if (args.length == 0) {
if (args.length == 0) if (senderIsConsole) {
{
if (senderIsConsole)
{
msg("You must be in-game to toggle admin chat, it cannot be toggled via CONSOLE or Telnet."); msg("You must be in-game to toggle admin chat, it cannot be toggled via CONSOLE or Telnet.");
return true; return true;
} }
FPlayer userinfo = plugin.pl.getPlayer(playerSender); FPlayer userinfo = plugin.playerList.getPlayer(playerSender);
userinfo.setAdminChat(!userinfo.inAdminChat()); userinfo.setAdminChat(!userinfo.inAdminChat());
msg("Admin chat turned " + (userinfo.inAdminChat() ? "on" : "off") + "."); msg("Admin chat turned " + (userinfo.inAdminChat() ? "on" : "off") + ".");
} } else {
else plugin.chatManager.adminChat(sender, StringUtils.join(args, " "));
{
plugin.cm.adminChat(sender, StringUtils.join(args, " "));
} }
return true; return true;
} }

View file

@ -1,11 +1,10 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.discord.Discord; import me.totalfreedom.totalfreedommod.discord.Discord;
import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.FPlayer;
@ -17,81 +16,70 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.*;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH) @CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "List, add, remove, or set the rank of admins, clean or reload the admin list, or view admin information.", usage = "/<command> <list | clean | reload | | setrank <username> <rank> | <add | remove | info> <username>>", aliases = "slconfig") @CommandParameters(name = "saconfig", description = "List, add, remove, or set the rank of admins, clean or reload the admin list, or view admin information.", usage = "/<command> <list | clean | reload | | setrank <username> <rank> | <add | remove | info> <username>>", aliases = "slconfig")
public class Command_saconfig extends FreedomCommand public class AdminConfigCMD extends FreedomCommand {
{
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
{ if (args.length < 1) {
if (args.length < 1)
{
return false; return false;
} }
switch (args[0]) switch (args[0]) {
{ case "list": {
case "list": msg("Admins: " + StringUtils.join(plugin.adminList.getAdminNames(), ", "), ChatColor.GOLD);
{
msg("Admins: " + StringUtils.join(plugin.al.getAdminNames(), ", "), ChatColor.GOLD);
return true; return true;
} }
case "clean": case "clean": {
{
checkConsole(); checkConsole();
checkRank(Rank.SENIOR_ADMIN); checkRank(Rank.SENIOR_ADMIN);
FUtil.adminAction(sender.getName(), "Cleaning the admin list", true); FUtil.adminAction(sender.getName(), "Cleaning the admin list", true);
plugin.al.deactivateOldEntries(true); plugin.adminList.deactivateOldEntries(true);
msg("Admins: " + StringUtils.join(plugin.al.getAdminNames(), ", "), ChatColor.GOLD); msg("Admins: " + StringUtils.join(plugin.adminList.getAdminNames(), ", "), ChatColor.GOLD);
return true; return true;
} }
case "reload": case "reload": {
{
checkRank(Rank.SENIOR_ADMIN); checkRank(Rank.SENIOR_ADMIN);
FUtil.adminAction(sender.getName(), "Reloading the admin list", true); FUtil.adminAction(sender.getName(), "Reloading the admin list", true);
plugin.al.load(); plugin.adminList.load();
msg("Admin list reloaded!"); msg("Admin list reloaded!");
return true; return true;
} }
case "setrank": case "setrank": {
{
checkConsole(); checkConsole();
checkRank(Rank.SENIOR_ADMIN); checkRank(Rank.SENIOR_ADMIN);
if (args.length < 3) if (args.length < 3) {
{
return false; return false;
} }
Rank rank = Rank.findRank(args[2]); Rank rank = Rank.findRank(args[2]);
if (rank == null) if (rank == null) {
{
msg("Unknown rank: " + args[2]); msg("Unknown rank: " + args[2]);
return true; return true;
} }
if (rank.isConsole()) if (rank.isConsole()) {
{
msg("You cannot set players to a console rank"); msg("You cannot set players to a console rank");
return true; return true;
} }
if (!rank.isAtLeast(Rank.ADMIN)) if (!rank.isAtLeast(Rank.ADMIN)) {
{
msg("Rank must be Admin or higher.", ChatColor.RED); msg("Rank must be Admin or higher.", ChatColor.RED);
return true; return true;
} }
Admin admin = plugin.al.getEntryByName(args[1]); Admin admin = plugin.adminList.getEntryByName(args[1]);
if (admin == null) if (admin == null) {
{
msg("Unknown admin: " + args[1]); msg("Unknown admin: " + args[1]);
return true; return true;
} }
@ -99,61 +87,50 @@ public class Command_saconfig extends FreedomCommand
FUtil.adminAction(sender.getName(), "Setting " + admin.getName() + "'s rank to " + rank.getName(), true); FUtil.adminAction(sender.getName(), "Setting " + admin.getName() + "'s rank to " + rank.getName(), true);
admin.setRank(rank); admin.setRank(rank);
plugin.al.save(admin); plugin.adminList.save(admin);
Player player = getPlayer(admin.getName()); Player player = getPlayer(admin.getName());
if (player != null) if (player != null) {
{ plugin.rankManager.updateDisplay(player);
plugin.rm.updateDisplay(player);
} }
if (plugin.dc.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean()) if (plugin.discord.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean()) {
{ Discord.syncRoles(admin, plugin.playerList.getData(admin.getName()).getDiscordID());
Discord.syncRoles(admin, plugin.pl.getData(admin.getName()).getDiscordID());
} }
plugin.ptero.updateAccountStatus(admin); plugin.pterodactyl.updateAccountStatus(admin);
msg("Set " + admin.getName() + "'s rank to " + rank.getName()); msg("Set " + admin.getName() + "'s rank to " + rank.getName());
return true; return true;
} }
case "info": case "info": {
{ if (args.length < 2) {
if (args.length < 2)
{
return false; return false;
} }
checkRank(Rank.ADMIN); checkRank(Rank.ADMIN);
Admin admin = plugin.al.getEntryByName(args[1]); Admin admin = plugin.adminList.getEntryByName(args[1]);
if (admin == null) if (admin == null) {
{
final Player player = getPlayer(args[1]); final Player player = getPlayer(args[1]);
if (player != null) if (player != null) {
{ admin = plugin.adminList.getAdmin(player);
admin = plugin.al.getAdmin(player);
} }
} }
if (admin == null) if (admin == null) {
{
msg("Admin not found: " + args[1]); msg("Admin not found: " + args[1]);
} } else {
else
{
msg(admin.toString()); msg(admin.toString());
} }
return true; return true;
} }
case "add": case "add": {
{ if (args.length < 2) {
if (args.length < 2)
{
return false; return false;
} }
@ -163,14 +140,12 @@ public class Command_saconfig extends FreedomCommand
// Player already admin? // Player already admin?
final Player player = getPlayer(args[1]); final Player player = getPlayer(args[1]);
if (player == null) if (player == null) {
{
msg(FreedomCommand.PLAYER_NOT_FOUND); msg(FreedomCommand.PLAYER_NOT_FOUND);
return true; return true;
} }
if (plugin.al.isAdmin(player)) if (plugin.adminList.isAdmin(player)) {
{
msg("That player is already an admin."); msg("That player is already an admin.");
return true; return true;
} }
@ -178,17 +153,14 @@ public class Command_saconfig extends FreedomCommand
// Find the old admin entry // Find the old admin entry
String name = player.getName(); String name = player.getName();
Admin admin = null; Admin admin = null;
for (Admin loopAdmin : plugin.al.getAllAdmins()) for (Admin loopAdmin : plugin.adminList.getAllAdmins()) {
{ if (loopAdmin.getName().equalsIgnoreCase(name) || loopAdmin.getIps().contains(FUtil.getIp(player))) {
if (loopAdmin.getName().equalsIgnoreCase(name) || loopAdmin.getIps().contains(FUtil.getIp(player)))
{
admin = loopAdmin; admin = loopAdmin;
break; break;
} }
} }
if (plugin.pl.isPlayerImpostor(player)) if (plugin.playerList.isPlayerImpostor(player)) {
{
msg("This player was labeled as a Player impostor and is not an admin, therefore they cannot be added to the admin list.", ChatColor.RED); msg("This player was labeled as a Player impostor and is not an admin, therefore they cannot be added to the admin list.", ChatColor.RED);
return true; return true;
} }
@ -199,16 +171,14 @@ public class Command_saconfig extends FreedomCommand
FUtil.adminAction(sender.getName(), "Adding " + player.getName() + " to the admin list", true); FUtil.adminAction(sender.getName(), "Adding " + player.getName() + " to the admin list", true);
admin = new Admin(player); admin = new Admin(player);
plugin.al.addAdmin(admin); plugin.adminList.addAdmin(admin);
plugin.rm.updateDisplay(player); plugin.rankManager.updateDisplay(player);
} } else // Existing admin
else // Existing admin
{ {
FUtil.adminAction(sender.getName(), "Re-adding " + player.getName() + " to the admin list", true); FUtil.adminAction(sender.getName(), "Re-adding " + player.getName() + " to the admin list", true);
String oldName = admin.getName(); String oldName = admin.getName();
if (!oldName.equals(player.getName())) if (!oldName.equals(player.getName())) {
{
admin.setName(player.getName()); admin.setName(player.getName());
plugin.sql.updateAdminName(oldName, admin.getName()); plugin.sql.updateAdminName(oldName, admin.getName());
} }
@ -217,41 +187,35 @@ public class Command_saconfig extends FreedomCommand
admin.setActive(true); admin.setActive(true);
admin.setLastLogin(new Date()); admin.setLastLogin(new Date());
if (plugin.al.isVerifiedAdmin(player)) if (plugin.adminList.isVerifiedAdmin(player)) {
{ plugin.adminList.verifiedNoAdmin.remove(player.getName());
plugin.al.verifiedNoAdmin.remove(player.getName());
} }
plugin.al.save(admin); plugin.adminList.save(admin);
plugin.al.updateTables(); plugin.adminList.updateTables();
plugin.rm.updateDisplay(player); plugin.rankManager.updateDisplay(player);
if (plugin.dc.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean()) if (plugin.discord.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean()) {
{ Discord.syncRoles(admin, plugin.playerList.getData(player).getDiscordID());
Discord.syncRoles(admin, plugin.pl.getData(player).getDiscordID());
} }
} }
plugin.ptero.updateAccountStatus(admin); plugin.pterodactyl.updateAccountStatus(admin);
final FPlayer fPlayer = plugin.pl.getPlayer(player); final FPlayer fPlayer = plugin.playerList.getPlayer(player);
if (fPlayer.getFreezeData().isFrozen()) if (fPlayer.getFreezeData().isFrozen()) {
{
fPlayer.getFreezeData().setFrozen(false); fPlayer.getFreezeData().setFrozen(false);
msg(player, "You have been unfrozen."); msg(player, "You have been unfrozen.");
} }
if (!player.isOp()) if (!player.isOp()) {
{
player.setOp(true); player.setOp(true);
msg(player, YOU_ARE_OP); msg(player, YOU_ARE_OP);
} }
return true; return true;
} }
case "remove": case "remove": {
{ if (args.length < 2) {
if (args.length < 2)
{
return false; return false;
} }
@ -259,10 +223,9 @@ public class Command_saconfig extends FreedomCommand
checkRank(Rank.ADMIN); checkRank(Rank.ADMIN);
Player player = getPlayer(args[1]); Player player = getPlayer(args[1]);
Admin admin = player != null ? plugin.al.getAdmin(player) : plugin.al.getEntryByName(args[1]); Admin admin = player != null ? plugin.adminList.getAdmin(player) : plugin.adminList.getEntryByName(args[1]);
if (admin == null) if (admin == null) {
{
msg("Admin not found: " + args[1]); msg("Admin not found: " + args[1]);
return true; return true;
} }
@ -270,58 +233,49 @@ public class Command_saconfig extends FreedomCommand
FUtil.adminAction(sender.getName(), "Removing " + admin.getName() + " from the admin list", true); FUtil.adminAction(sender.getName(), "Removing " + admin.getName() + " from the admin list", true);
admin.setActive(false); admin.setActive(false);
plugin.al.save(admin); plugin.adminList.save(admin);
plugin.al.updateTables(); plugin.adminList.updateTables();
if (player != null) if (player != null) {
{ plugin.rankManager.updateDisplay(player);
plugin.rm.updateDisplay(player); plugin.playerList.getPlayer(player).setAdminChat(false);
plugin.pl.getPlayer(player).setAdminChat(false);
} }
if (plugin.dc.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean()) if (plugin.discord.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean()) {
{ Discord.syncRoles(admin, plugin.playerList.getData(admin.getName()).getDiscordID());
Discord.syncRoles(admin, plugin.pl.getData(admin.getName()).getDiscordID());
} }
plugin.ptero.updateAccountStatus(admin); plugin.pterodactyl.updateAccountStatus(admin);
return true; return true;
} }
default: default: {
{
return false; return false;
} }
} }
} }
@Override @Override
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) {
{ if (args.length == 1) {
if (args.length == 1)
{
List<String> arguments = new ArrayList<>(); List<String> arguments = new ArrayList<>();
arguments.add("list"); arguments.add("list");
if (plugin.al.isAdmin(sender)) if (plugin.adminList.isAdmin(sender)) {
{
arguments.add("info"); arguments.add("info");
arguments.add("add"); arguments.add("add");
arguments.add("remove"); arguments.add("remove");
} }
if (plugin.al.isSeniorAdmin(sender)) if (plugin.adminList.isSeniorAdmin(sender)) {
{
arguments.add("reload"); arguments.add("reload");
arguments.add("clean"); arguments.add("clean");
arguments.add("setrank"); arguments.add("setrank");
} }
return arguments; return arguments;
} }
if (args.length == 2 && (args[0].equals("add") || args[0].equals("remove") || args[0].equals("setrank") || args[0].equals("info"))) if (args.length == 2 && (args[0].equals("add") || args[0].equals("remove") || args[0].equals("setrank") || args[0].equals("info"))) {
{
return FUtil.getPlayerList(); return FUtil.getPlayerList();
} }
if (args.length == 3 && args[0].equals("setrank")) if (args.length == 3 && args[0].equals("setrank")) {
{
return Arrays.asList("ADMIN", "SENIOR_ADMIN"); return Arrays.asList("ADMIN", "SENIOR_ADMIN");
} }

View file

@ -1,6 +1,9 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command.impl;
import java.util.List; import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
@ -10,22 +13,19 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH) @CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Information on how to apply for admin.", usage = "/<command>", aliases = "si,ai,staffinfo") @CommandParameters(name = "admininfo", description = "Information on how to apply for admin.", usage = "/<command>", aliases = "si,ai,staffinfo")
public class Command_admininfo extends FreedomCommand public class AdminInfoCMD extends FreedomCommand {
{
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
{
List<String> adminInfo = ConfigEntry.ADMIN_INFO.getStringList(); List<String> adminInfo = ConfigEntry.ADMIN_INFO.getStringList();
if (adminInfo.isEmpty()) if (adminInfo.isEmpty()) {
{
msg("The admin information section of the config.yml file has not been configured.", ChatColor.RED); msg("The admin information section of the config.yml file has not been configured.", ChatColor.RED);
} } else {
else
{
msg(FUtil.colorize(StringUtils.join(adminInfo, "\n"))); msg(FUtil.colorize(StringUtils.join(adminInfo, "\n")));
} }
return true; return true;

View file

@ -1,8 +1,9 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command.impl;
import java.util.Arrays; import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import java.util.Collections; import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import java.util.List; import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
@ -10,33 +11,29 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH) @CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Denies joining of operators and only allows admins to join.", usage = "/<command> [on | off]", aliases = "staffmode") @CommandParameters(name = "adminmode", description = "Denies joining of operators and only allows admins to join.", usage = "/<command> [on | off]", aliases = "staffmode")
public class Command_adminmode extends FreedomCommand public class AdminModeCMD extends FreedomCommand {
{
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
{ if (args.length != 1) {
if (args.length != 1)
{
return false; return false;
} }
if (args[0].equalsIgnoreCase("off")) if (args[0].equalsIgnoreCase("off")) {
{
ConfigEntry.ADMIN_ONLY_MODE.setBoolean(false); ConfigEntry.ADMIN_ONLY_MODE.setBoolean(false);
FUtil.adminAction(sender.getName(), "Opening the server to all players", true); FUtil.adminAction(sender.getName(), "Opening the server to all players", true);
return true; return true;
} } else if (args[0].equalsIgnoreCase("on")) {
else if (args[0].equalsIgnoreCase("on"))
{
ConfigEntry.ADMIN_ONLY_MODE.setBoolean(true); ConfigEntry.ADMIN_ONLY_MODE.setBoolean(true);
FUtil.adminAction(sender.getName(), "Closing the server to non-admins", true); FUtil.adminAction(sender.getName(), "Closing the server to non-admins", true);
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers()) {
{ if (!isAdmin(player)) {
if (!isAdmin(player))
{
player.kickPlayer("Server is now closed to non-admins."); player.kickPlayer("Server is now closed to non-admins.");
} }
} }
@ -47,10 +44,8 @@ public class Command_adminmode extends FreedomCommand
} }
@Override @Override
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) {
{ if (args.length == 1 && plugin.adminList.isAdmin(sender) && !(sender instanceof Player)) {
if (args.length == 1 && plugin.al.isAdmin(sender) && !(sender instanceof Player))
{
return Arrays.asList("on", "off"); return Arrays.asList("on", "off");
} }

View file

@ -1,140 +1,108 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command.impl;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import java.util.Arrays; import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import java.util.Collections; import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import java.util.List; import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.world.WorldTime; import me.totalfreedom.totalfreedommod.world.manager.WorldTime;
import me.totalfreedom.totalfreedommod.world.WorldWeather; import me.totalfreedom.totalfreedommod.world.manager.WorldWeather;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH) @CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Allows for admins to configure time, and weather of the AdminWorld, and allows for admins and ops to go to the AdminWorld.", @CommandParameters(name = "adminworld", description = "Allows for admins to configure time, and weather of the AdminWorld, and allows for admins and ops to go to the AdminWorld.",
usage = "/<command> [time <morning | noon | evening | night> | weather <off | rain | storm>]", usage = "/<command> [time <morning | noon | evening | night> | weather <off | rain | storm>]",
aliases = "sw,aw,staffworld") aliases = "sw,aw,staffworld")
public class Command_adminworld extends FreedomCommand public class AdminWorldCMD extends FreedomCommand {
{
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
{
CommandMode commandMode = null; CommandMode commandMode = null;
if (args.length == 0) if (args.length == 0) {
{
commandMode = CommandMode.TELEPORT; commandMode = CommandMode.TELEPORT;
} } else if (args.length >= 2) {
else if (args.length >= 2) if ("time".equalsIgnoreCase(args[0])) {
{
if ("time".equalsIgnoreCase(args[0]))
{
commandMode = CommandMode.TIME; commandMode = CommandMode.TIME;
} } else if ("weather".equalsIgnoreCase(args[0])) {
else if ("weather".equalsIgnoreCase(args[0]))
{
commandMode = CommandMode.WEATHER; commandMode = CommandMode.WEATHER;
} }
} }
if (commandMode == null) if (commandMode == null) {
{
return false; return false;
} }
try try {
{ switch (commandMode) {
switch (commandMode) case TELEPORT: {
{ if (!(sender instanceof Player) || playerSender == null) {
case TELEPORT:
{
if (!(sender instanceof Player) || playerSender == null)
{
return false; return false;
} }
World adminWorld = null; World adminWorld = null;
try try {
{ adminWorld = plugin.worldManager.adminworld.getWorld();
adminWorld = plugin.wm.adminworld.getWorld(); } catch (Exception ignored) {
}
catch (Exception ignored)
{
} }
if (adminWorld == null || playerSender.getWorld() == adminWorld) if (adminWorld == null || playerSender.getWorld() == adminWorld) {
{
msg("Going to the main world."); msg("Going to the main world.");
PaperLib.teleportAsync(playerSender, server.getWorlds().get(0).getSpawnLocation()); PaperLib.teleportAsync(playerSender, server.getWorlds().get(0).getSpawnLocation());
} } else {
else
{
msg("Going to the AdminWorld."); msg("Going to the AdminWorld.");
plugin.wm.adminworld.sendToWorld(playerSender); plugin.worldManager.adminworld.sendToWorld(playerSender);
} }
break; break;
} }
case TIME: case TIME: {
{
assertCommandPerms(sender, playerSender); assertCommandPerms(sender, playerSender);
if (args.length == 2) if (args.length == 2) {
{
WorldTime timeOfDay = WorldTime.getByAlias(args[1]); WorldTime timeOfDay = WorldTime.getByAlias(args[1]);
if (timeOfDay != null) if (timeOfDay != null) {
{ plugin.worldManager.adminworld.setTimeOfDay(timeOfDay);
plugin.wm.adminworld.setTimeOfDay(timeOfDay);
msg("AdminWorld time set to: " + timeOfDay.name()); msg("AdminWorld time set to: " + timeOfDay.name());
} } else {
else
{
msg("Invalid time of day. Can be: sunrise, noon, sunset, midnight"); msg("Invalid time of day. Can be: sunrise, noon, sunset, midnight");
} }
} } else {
else
{
return false; return false;
} }
break; break;
} }
case WEATHER: case WEATHER: {
{
assertCommandPerms(sender, playerSender); assertCommandPerms(sender, playerSender);
if (args.length == 2) if (args.length == 2) {
{
WorldWeather weatherMode = WorldWeather.getByAlias(args[1]); WorldWeather weatherMode = WorldWeather.getByAlias(args[1]);
if (weatherMode != null) if (weatherMode != null) {
{ plugin.worldManager.adminworld.setWeatherMode(weatherMode);
plugin.wm.adminworld.setWeatherMode(weatherMode);
msg("AdminWorld weather set to: " + weatherMode.name()); msg("AdminWorld weather set to: " + weatherMode.name());
} } else {
else
{
msg("Invalid weather mode. Can be: off, rain, storm"); msg("Invalid weather mode. Can be: off, rain, storm");
} }
} } else {
else
{
return false; return false;
} }
break; break;
} }
default: default: {
{
return false; return false;
} }
} }
} } catch (PermissionDeniedException ex) {
catch (PermissionDeniedException ex) if (ex.getMessage().isEmpty()) {
{
if (ex.getMessage().isEmpty())
{
return noPerms(); return noPerms();
} }
msg(ex.getMessage()); msg(ex.getMessage());
@ -145,56 +113,42 @@ public class Command_adminworld extends FreedomCommand
} }
// TODO: Redo this properly // TODO: Redo this properly
private void assertCommandPerms(CommandSender sender, Player playerSender) throws PermissionDeniedException private void assertCommandPerms(CommandSender sender, Player playerSender) throws PermissionDeniedException {
{ if (!(sender instanceof Player) || playerSender == null || !isAdmin(sender)) {
if (!(sender instanceof Player) || playerSender == null || !isAdmin(sender))
{
throw new PermissionDeniedException(); throw new PermissionDeniedException();
} }
} }
@Override @Override
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) {
{ if (!plugin.adminList.isAdmin(sender)) {
if (!plugin.al.isAdmin(sender))
{
return Collections.emptyList(); return Collections.emptyList();
} }
if (args.length == 1) if (args.length == 1) {
{
return Arrays.asList("time", "weather"); return Arrays.asList("time", "weather");
} } else if (args.length == 2) {
else if (args.length == 2) if (args[0].equals("time")) {
{
if (args[0].equals("time"))
{
return Arrays.asList("morning", "noon", "evening", "night"); return Arrays.asList("morning", "noon", "evening", "night");
} } else if (args[0].equals("weather")) {
else if (args[0].equals("weather"))
{
return Arrays.asList("off", "rain", "storm"); return Arrays.asList("off", "rain", "storm");
} }
} }
return Collections.emptyList(); return Collections.emptyList();
} }
private enum CommandMode private enum CommandMode {
{
TELEPORT, TIME, WEATHER TELEPORT, TIME, WEATHER
} }
private static class PermissionDeniedException extends Exception private static class PermissionDeniedException extends Exception {
{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private PermissionDeniedException() private PermissionDeniedException() {
{
super(""); super("");
} }
private PermissionDeniedException(String string) private PermissionDeniedException(String string) {
{
super(string); super(string);
} }
} }

View file

@ -1,5 +1,9 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command.impl;
import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -8,17 +12,13 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH) @CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Quickly change your own gamemode to adventure, define someone's username to change theirs, or change everyone's gamemode on the server.", usage = "/<command> <[partialname] | -a>", aliases = "gma") @CommandParameters(name = "adventure", description = "Quickly change your own gamemode to adventure, define someone's username to change theirs, or change everyone's gamemode on the server.", usage = "/<command> <[partialname] | -a>", aliases = "gma")
public class Command_adventure extends FreedomCommand public class AdventureCMD extends FreedomCommand {
{
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
{ if (args.length == 0) {
if (args.length == 0) if (isConsole()) {
{
if (isConsole())
{
msg("When used from the console, you must define a target player."); msg("When used from the console, you must define a target player.");
return true; return true;
} }
@ -30,10 +30,8 @@ public class Command_adventure extends FreedomCommand
checkRank(Rank.ADMIN); checkRank(Rank.ADMIN);
if (args[0].equals("-a")) if (args[0].equals("-a")) {
{ for (Player targetPlayer : server.getOnlinePlayers()) {
for (Player targetPlayer : server.getOnlinePlayers())
{
targetPlayer.setGameMode(GameMode.ADVENTURE); targetPlayer.setGameMode(GameMode.ADVENTURE);
} }
@ -44,8 +42,7 @@ public class Command_adventure extends FreedomCommand
Player player = getPlayer(args[0]); Player player = getPlayer(args[0]);
if (player == null) if (player == null) {
{
msg(PLAYER_NOT_FOUND); msg(PLAYER_NOT_FOUND);
return true; return true;
} }

View file

@ -0,0 +1,26 @@
package me.totalfreedom.totalfreedommod.command.impl;
import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(name = "announce", description = "Make an announcement anonymously to operators.", usage = "/<command> <message>")
public class AnnounceCMD extends FreedomCommand {
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 1) {
return false;
}
plugin.announcer.announce(StringUtils.join(args, " "));
return true;
}
}

View file

@ -1,5 +1,9 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command.impl;
import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -7,17 +11,14 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH) @CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Lists all possible attributes.", usage = "/<command>") @CommandParameters(name = "attributelist", description = "Lists all possible attributes.", usage = "/<command>", aliases = "attrlist")
public class Command_attributelist extends FreedomCommand public class AttributeListCMD extends FreedomCommand {
{
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
{
StringBuilder list = new StringBuilder("All possible attributes: "); StringBuilder list = new StringBuilder("All possible attributes: ");
for (Attribute attribute : Attribute.values()) for (Attribute attribute : Attribute.values()) {
{
list.append(attribute.name()).append(", "); list.append(attribute.name()).append(", ");
} }

View file

@ -0,0 +1,34 @@
package me.totalfreedom.totalfreedommod.command.impl;
import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(name = "autoclear", description = "Toggle whether or not a player has their inventory automatically cleared when they join", usage = "/<command> <player>")
public class AutoClearCMD extends FreedomCommand {
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0) {
return false;
}
boolean enabled = plugin.loginProcess.CLEAR_ON_JOIN.contains(args[0]);
if (enabled) {
plugin.loginProcess.CLEAR_ON_JOIN.remove(args[0]);
} else {
plugin.loginProcess.CLEAR_ON_JOIN.add(args[0]);
}
msg(args[0] + " will " + (enabled ? "no longer" : "now") + " have their inventory cleared when they join.");
return true;
}
}

View file

@ -0,0 +1,34 @@
package me.totalfreedom.totalfreedommod.command.impl;
import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(name = "autotp", description = "Toggle whether or not a player is automatically teleported when they join", usage = "/<command> <player>")
public class AutoTPCMD extends FreedomCommand {
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0) {
return false;
}
boolean enabled = plugin.loginProcess.TELEPORT_ON_JOIN.contains(args[0]);
if (enabled) {
plugin.loginProcess.TELEPORT_ON_JOIN.remove(args[0]);
} else {
plugin.loginProcess.TELEPORT_ON_JOIN.add(args[0]);
}
msg(args[0] + " will " + (enabled ? "no longer" : "now") + " be automatically teleported when they join.");
return true;
}
}

View file

@ -1,9 +1,11 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command.impl;
import java.util.ArrayList; import com.earth2me.essentials.User;
import java.util.List; import me.totalfreedom.totalfreedommod.command.input.SourceType;
import java.util.Objects; import me.totalfreedom.totalfreedommod.punishments.banning.Ban;
import me.totalfreedom.totalfreedommod.banning.Ban; import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.Punishment;
import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
@ -19,69 +21,64 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Objects;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH, blockHostConsole = true) @CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH, blockHostConsole = true)
@CommandParameters(description = "Bans the specified player.", usage = "/<command> <username> [reason] [-nrb | -q]", aliases = "gtfo") @CommandParameters(name = "ban", description = "Bans the specified player.", usage = "/<command> <username> [reason] [-nrb | -q]", aliases = "gtfo")
public class Command_ban extends FreedomCommand public class BanCMD extends FreedomCommand {
{
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
{ if (args.length == 0) {
if (args.length == 0)
{
return false; return false;
} }
String reason = null; String reason = null;
boolean silent = false; boolean silent = false;
boolean cancelRollback = false; boolean cancelRollback = false;
if (args.length >= 2) if (args.length >= 2) {
{ if (args[args.length - 1].equalsIgnoreCase("-nrb") || args[args.length - 1].equalsIgnoreCase("-q")) {
if (args[args.length - 1].equalsIgnoreCase("-nrb") || args[args.length - 1].equalsIgnoreCase("-q")) if (args[args.length - 1].equalsIgnoreCase("-nrb")) {
{
if (args[args.length - 1].equalsIgnoreCase("-nrb"))
{
cancelRollback = true; cancelRollback = true;
} }
if (args[args.length - 1].equalsIgnoreCase("-q")) if (args[args.length - 1].equalsIgnoreCase("-q")) {
{
silent = true; silent = true;
} }
if (args.length >= 3) if (args.length >= 3) {
{
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " "); reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
} }
} } else {
else
{
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " "); reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
} }
} }
final String username; final String username;
final List<String> ips = new ArrayList<>(); final String ip;
final Player player = getPlayer(args[0]); final Player player = getPlayer(args[0]);
if (player == null) if (player == null) {
{ // Gets the IP using Essentials data if available
final PlayerData entry = plugin.pl.getData(args[0]); if (plugin.essentialsBridge.isEnabled() && plugin.essentialsBridge.getEssentialsUser(args[0]) != null) {
User essUser = plugin.essentialsBridge.getEssentialsUser(args[0]);
if (entry == null) //
{ username = essUser.getName();
msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly."); ip = essUser.getLastLoginAddress();
return true;
} }
// Last resort - Getting the first result from the username itself
username = entry.getName(); else {
ips.addAll(entry.getIps()); PlayerData entry = plugin.playerList.getData(args[0]);
} if (entry == null) {
else msg(PLAYER_NOT_FOUND);
{ return true;
final PlayerData entry = plugin.pl.getData(player); } else {
username = entry.getName();
ip = entry.getIps().get(0);
}
}
} else {
username = player.getName(); username = player.getName();
//ips.addAll(entry.getIps());/ ip = FUtil.getIp(player);
ips.add(FUtil.getIp(player));
// Deop // Deop
player.setOp(false); player.setOp(false);
@ -92,21 +89,16 @@ public class Command_ban extends FreedomCommand
// Clear inventory // Clear inventory
player.getInventory().clear(); player.getInventory().clear();
if (!silent) if (!silent) {
{
// Strike with lightning // Strike with lightning
final Location targetPos = player.getLocation(); final Location targetPos = player.getLocation();
for (int x = -1; x <= 1; x++) for (int x = -1; x <= 1; x++) {
{ for (int z = -1; z <= 1; z++) {
for (int z = -1; z <= 1; z++)
{
final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z); final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
Objects.requireNonNull(targetPos.getWorld()).strikeLightning(strike_pos); Objects.requireNonNull(targetPos.getWorld()).strikeLightning(strike_pos);
} }
} }
} } else {
else
{
msg("Banned " + player.getName() + " quietly."); msg("Banned " + player.getName() + " quietly.");
} }
// Kill player // Kill player
@ -114,65 +106,50 @@ public class Command_ban extends FreedomCommand
} }
// Checks if CoreProtect is loaded and installed, and skips the rollback and uses CoreProtect directly // Checks if CoreProtect is loaded and installed, and skips the rollback and uses CoreProtect directly
if (!cancelRollback) if (!cancelRollback) {
{ plugin.coreProtectBridge.rollback(username);
plugin.cpb.rollback(username);
} }
if (player != null && !silent) if (player != null && !silent) {
{
FUtil.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED); FUtil.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);
} }
// Ban player // Ban player
Ban ban; Ban ban;
if (player != null) {
if (player != null)
{
ban = Ban.forPlayer(player, sender, null, reason); ban = Ban.forPlayer(player, sender, null, reason);
} } else {
else
{
ban = Ban.forPlayerName(username, sender, null, reason); ban = Ban.forPlayerName(username, sender, null, reason);
} }
ban.addIp(ip);
for (String ip : ips) plugin.banManager.addBan(ban);
{
ban.addIp(ip);
ban.addIp(FUtil.getFuzzyIp(ip));
}
plugin.bm.addBan(ban);
if (!silent) if (!silent) {
{
// Broadcast // Broadcast
final StringBuilder bcast = new StringBuilder() final StringBuilder bcast = new StringBuilder()
.append("Banning: ") .append("Banning: ")
.append(username); .append(username);
if (reason != null) if (reason != null) {
{
bcast.append(" - Reason: ").append(ChatColor.YELLOW).append(reason); bcast.append(" - Reason: ").append(ChatColor.YELLOW).append(reason);
} }
msg(sender, ChatColor.GRAY + username + " has been banned and IP is: " + StringUtils.join(ips, ", ")); msg(sender, ChatColor.GRAY + username + " has been banned and IP is: " + ip);
FUtil.adminAction(sender.getName(), bcast.toString(), true); FUtil.adminAction(sender.getName(), bcast.toString(), true);
} }
// Kick player and handle others on IP // Kick player and handle others on IP
if (player != null) if (player != null) {
{
player.kickPlayer(ban.bakeKickMessage()); player.kickPlayer(ban.bakeKickMessage());
for (Player p : Bukkit.getOnlinePlayers()) for (Player p : Bukkit.getOnlinePlayers()) {
{ if (FUtil.getIp(p).equals(FUtil.getIp(player))) {
if (FUtil.getIp(p).equals(FUtil.getIp(player)))
{
p.kickPlayer(ChatColor.RED + "You've been kicked because someone on your IP has been banned."); p.kickPlayer(ChatColor.RED + "You've been kicked because someone on your IP has been banned.");
} }
} }
} }
// Log ban // Log ban
plugin.pul.logPunishment(new Punishment(username, ips.get(0), sender.getName(), PunishmentType.BAN, reason)); plugin.punishmentList.logPunishment(new Punishment(username, ip, sender.getName(), PunishmentType.BAN, reason));
return true; return true;
} }

View file

@ -1,6 +1,10 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command.impl;
import me.totalfreedom.totalfreedommod.banning.Ban; import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.punishments.banning.Ban;
import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
@ -12,15 +16,12 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH, blockHostConsole = true) @CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH, blockHostConsole = true)
@CommandParameters(description = "Bans the specified ip.", usage = "/<command> <ip> [reason] [-q]") @CommandParameters(name = "banip", description = "Bans the specified ip.", usage = "/<command> <ip> [reason] [-q]")
public class Command_banip extends FreedomCommand public class BanIPCMD extends FreedomCommand {
{
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
{ if (args.length == 0) {
if (args.length == 0)
{
return false; return false;
} }
@ -30,49 +31,40 @@ public class Command_banip extends FreedomCommand
String ip = args[0]; String ip = args[0];
if (FUtil.isValidIPv4(ip)) if (FUtil.isValidIPv4(ip)) {
{
msg(ip + " is not a valid IP address", ChatColor.RED); msg(ip + " is not a valid IP address", ChatColor.RED);
return true; return true;
} }
if (plugin.bm.getByIp(ip) != null) if (plugin.banManager.getByIp(ip) != null) {
{
msg("The IP " + ip + " is already banned", ChatColor.RED); msg("The IP " + ip + " is already banned", ChatColor.RED);
return true; return true;
} }
if (args[args.length - 1].equalsIgnoreCase("-q")) if (args[args.length - 1].equalsIgnoreCase("-q")) {
{
silent = true; silent = true;
if (args.length >= 2) if (args.length >= 2) {
{
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " "); reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
} }
} } else if (args.length > 1) {
else if (args.length > 1)
{
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " "); reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
} }
// Ban player // Ban player
Ban ban = Ban.forPlayerIp(ip, sender, null, reason); Ban ban = Ban.forPlayerIp(ip, sender, null, reason);
plugin.bm.addBan(ban); plugin.banManager.addBan(ban);
// Kick player and handle others on IP // Kick player and handle others on IP
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers()) {
{ if (FUtil.getIp(player).equals(ip)) {
if (FUtil.getIp(player).equals(ip))
{
player.kickPlayer(ban.bakeKickMessage()); player.kickPlayer(ban.bakeKickMessage());
} }
if (!silent) if (!silent) {
{
// Broadcast // Broadcast
FLog.info(ChatColor.RED + sender.getName() + " - Banned the IP " + ip); FLog.info(ChatColor.RED + sender.getName() + " - Banned the IP " + ip);
String message = sender.getName() + " - Banned " + (plugin.al.isAdmin(player) ? "the IP " + ip : "an IP"); String message = sender.getName() + " - Banned " + (plugin.adminList.isAdmin(player) ? "the IP " + ip : "an IP");
msg(player, message, ChatColor.RED); msg(player, message, ChatColor.RED);
} }
} }

View file

@ -0,0 +1,36 @@
package me.totalfreedom.totalfreedommod.command.impl;
import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(name = "banlist", description = "Shows all banned player names. Admins may optionally use 'purge' to clear the list.", usage = "/<command> [purge]")
public class BanListCMD extends FreedomCommand {
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length > 0) {
if (args[0].equalsIgnoreCase("purge")) {
checkRank(Rank.SENIOR_ADMIN);
FUtil.adminAction(sender.getName(), "Purging the ban list", true);
int amount = plugin.banManager.purge();
msg("Purged " + amount + " player bans.");
return true;
}
return false;
}
msg(plugin.banManager.getAllBans().size() + " player bans ("
+ plugin.banManager.getUsernameBans().size() + " usernames, "
+ plugin.banManager.getIpBans().size() + " IPs)");
return true;
}
}

View file

@ -1,6 +1,10 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command.impl;
import me.totalfreedom.totalfreedommod.banning.Ban; import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.punishments.banning.Ban;
import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
@ -11,15 +15,12 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH, blockHostConsole = true) @CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH, blockHostConsole = true)
@CommandParameters(description = "Bans the specified name.", usage = "/<command> <name> [reason] [-q]") @CommandParameters(name = "banname", description = "Bans the specified name.", usage = "/<command> <name> [reason] [-q]")
public class Command_banname extends FreedomCommand public class BanNameCMD extends FreedomCommand {
{
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
{ if (args.length == 0) {
if (args.length == 0)
{
return false; return false;
} }
@ -29,38 +30,31 @@ public class Command_banname extends FreedomCommand
String name = args[0]; String name = args[0];
if (plugin.bm.getByUsername(name) != null) if (plugin.banManager.getByUsername(name) != null) {
{
msg("The name " + name + " is already banned", ChatColor.RED); msg("The name " + name + " is already banned", ChatColor.RED);
return true; return true;
} }
if (args[args.length - 1].equalsIgnoreCase("-q")) if (args[args.length - 1].equalsIgnoreCase("-q")) {
{
silent = true; silent = true;
if (args.length >= 2) if (args.length >= 2) {
{
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " "); reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
} }
} } else if (args.length > 1) {
else if (args.length > 1)
{
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " "); reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
} }
// Ban player // Ban player
Ban ban = Ban.forPlayerName(name, sender, null, reason); Ban ban = Ban.forPlayerName(name, sender, null, reason);
plugin.bm.addBan(ban); plugin.banManager.addBan(ban);
if (!silent) if (!silent) {
{
FUtil.adminAction(sender.getName(), "Banned the name " + name, true); FUtil.adminAction(sender.getName(), "Banned the name " + name, true);
} }
Player player = getPlayer(name); Player player = getPlayer(name);
if (player != null) if (player != null) {
{
player.kickPlayer(ban.bakeKickMessage()); player.kickPlayer(ban.bakeKickMessage());
} }
return true; return true;

View file

@ -1,8 +1,9 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command.impl;
import java.util.Arrays; import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import java.util.List; import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import java.util.SplittableRandom; import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -10,22 +11,23 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.List;
import java.util.SplittableRandom;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME) @CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Spawns a random type of fish at your location.", usage = "/<command>") @CommandParameters(name = "bird", description = "Spawns a random type of fish at your location.", usage = "/<command>")
public class Command_bird extends FreedomCommand public class BirdCMD extends FreedomCommand {
{
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
{
Location location = playerSender.getTargetBlock(null, 15).getLocation().add(0, 1, 0); Location location = playerSender.getTargetBlock(null, 15).getLocation().add(0, 1, 0);
playerSender.getWorld().spawnEntity(location, getRandomFish()); playerSender.getWorld().spawnEntity(location, getRandomFish());
msg(":goodbird:"); msg(":goodbird:");
return true; return true;
} }
public EntityType getRandomFish() public EntityType getRandomFish() {
{
List<EntityType> fishTypes = Arrays.asList(EntityType.COD, EntityType.SALMON, EntityType.PUFFERFISH, EntityType.TROPICAL_FISH); List<EntityType> fishTypes = Arrays.asList(EntityType.COD, EntityType.SALMON, EntityType.PUFFERFISH, EntityType.TROPICAL_FISH);
SplittableRandom random = new SplittableRandom(); SplittableRandom random = new SplittableRandom();
return fishTypes.get(random.nextInt(fishTypes.size())); return fishTypes.get(random.nextInt(fishTypes.size()));

View file

@ -1,5 +1,9 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command.impl;
import me.totalfreedom.totalfreedommod.command.input.CommandParameters;
import me.totalfreedom.totalfreedommod.command.input.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.input.SourceType;
import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.Punishment;
import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
@ -11,27 +15,21 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH) @CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Block all commands for everyone on the server, or a specific player.", usage = "/<command> <-a | purge | <player>>", aliases = "blockcommands,blockcommand,bc,bcmd") @CommandParameters(name = "blockcommand", description = "Block all commands for everyone on the server, or a specific player.", usage = "/<command> <-a | purge | <player>>", aliases = "blockcommands,blockcmd,bc,bcmd")
public class Command_blockcmd extends FreedomCommand public class BlockCommandCMD extends FreedomCommand {
{
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
{ if (args.length != 1) {
if (args.length != 1)
{
return false; return false;
} }
if (args[0].equals("purge")) if (args[0].equals("purge")) {
{
FUtil.adminAction(sender.getName(), "Unblocking commands for all players", true); FUtil.adminAction(sender.getName(), "Unblocking commands for all players", true);
int counter = 0; int counter = 0;
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers()) {
{ FPlayer playerdata = plugin.playerList.getPlayer(player);
FPlayer playerdata = plugin.pl.getPlayer(player); if (playerdata.allCommandsBlocked()) {
if (playerdata.allCommandsBlocked())
{
counter += 1; counter += 1;
playerdata.setCommandsBlocked(false); playerdata.setCommandsBlocked(false);
} }
@ -40,19 +38,16 @@ public class Command_blockcmd extends FreedomCommand
return true; return true;
} }
if (args[0].equals("-a")) if (args[0].equals("-a")) {
{
FUtil.adminAction(sender.getName(), "Blocking commands for all non-admins", true); FUtil.adminAction(sender.getName(), "Blocking commands for all non-admins", true);
int counter = 0; int counter = 0;
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers()) {
{ if (isAdmin(player)) {
if (isAdmin(player))
{
continue; continue;
} }
counter += 1; counter += 1;
plugin.pl.getPlayer(player).setCommandsBlocked(true); plugin.playerList.getPlayer(player).setCommandsBlocked(true);
msg(player, "Your commands have been blocked by an admin.", ChatColor.RED); msg(player, "Your commands have been blocked by an admin.", ChatColor.RED);
} }
@ -62,28 +57,24 @@ public class Command_blockcmd extends FreedomCommand
final Player player = getPlayer(args[0]); final Player player = getPlayer(args[0]);
if (player == null) if (player == null) {
{
msg(FreedomCommand.PLAYER_NOT_FOUND); msg(FreedomCommand.PLAYER_NOT_FOUND);
return true; return true;
} }
if (isAdmin(player)) if (isAdmin(player)) {
{
msg(player.getName() + " is an admin, and cannot have their commands blocked."); msg(player.getName() + " is an admin, and cannot have their commands blocked.");
return true; return true;
} }
FPlayer playerdata = plugin.pl.getPlayer(player); FPlayer playerdata = plugin.playerList.getPlayer(player);
if (!playerdata.allCommandsBlocked()) if (!playerdata.allCommandsBlocked()) {
{
FUtil.adminAction(sender.getName(), "Blocking all commands for " + player.getName(), true); FUtil.adminAction(sender.getName(), "Blocking all commands for " + player.getName(), true);
playerdata.setCommandsBlocked(true); playerdata.setCommandsBlocked(true);
msg("Blocked commands for " + player.getName() + "."); msg("Blocked commands for " + player.getName() + ".");
plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.BLOCKCMD, null));
} plugin.punishmentList.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.BLOCKCMD, null));
else } else {
{
msg("That players commands are already blocked.", ChatColor.RED); msg("That players commands are already blocked.", ChatColor.RED);
} }
return true; return true;

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