From 8b425967a48f965bf80bee79d5c758dc03fa088c Mon Sep 17 00:00:00 2001 From: Lemon Date: Fri, 9 Feb 2018 13:21:44 +0500 Subject: [PATCH] Fix #25 and #23 with other misc. fixes. Signed-off-by: Lemon --- pom.xml | 10 +-- .../totalfreedommod/TotalFreedomMod.java | 32 +++----- .../bridge/WorldGuardBridge.java | 80 +++++++++++++++++++ .../command/Command_blockpvp.java | 22 ++--- .../totalfreedommod/command/Command_list.java | 33 ++++---- .../command/Command_wiperegions.java | 48 +++-------- .../command/Command_wipeuserdata.java | 11 ++- .../totalfreedommod/discord/Discord.java | 22 ++--- .../discord/MessageListener.java | 4 +- 9 files changed, 148 insertions(+), 114 deletions(-) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java diff --git a/pom.xml b/pom.xml index 1eff2198..0c3fceb5 100644 --- a/pom.xml +++ b/pom.xml @@ -142,9 +142,9 @@ me.libraryaddict - LibsDisguise - 9.4.0-SNAPSHOT - provided + LibsDisguises + system + ${project.basedir}/lib/LibsDisguises.jar @@ -158,9 +158,9 @@ net.dv8tion JDA - 3.4.0_317-withDependencies + 3.5.0_327-withDependencies system - ${project.basedir}/lib/JDA-3.4.0_317-withDependencies.jar + ${project.basedir}/lib/JDA-3.5.0_327-withDependencies.jar diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 6255e11e..d0a89d9f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -1,36 +1,17 @@ package me.totalfreedom.totalfreedommod; -import me.totalfreedom.totalfreedommod.fun.Trailer; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; import me.totalfreedom.totalfreedommod.admin.AdminList; import me.totalfreedom.totalfreedommod.banning.BanManager; import me.totalfreedom.totalfreedommod.banning.PermbanList; -import me.totalfreedom.totalfreedommod.blocking.BlockBlocker; -import me.totalfreedom.totalfreedommod.blocking.EditBlocker; -import me.totalfreedom.totalfreedommod.blocking.EventBlocker; -import me.totalfreedom.totalfreedommod.blocking.InteractBlocker; -import me.totalfreedom.totalfreedommod.blocking.MobBlocker; -import me.totalfreedom.totalfreedommod.blocking.PVPBlocker; -import me.totalfreedom.totalfreedommod.blocking.PotionBlocker; -import me.totalfreedom.totalfreedommod.blocking.SignBlocker; +import me.totalfreedom.totalfreedommod.blocking.*; import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker; -import me.totalfreedom.totalfreedommod.bridge.CoreProtectBridge; -import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge; -import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge; -import me.totalfreedom.totalfreedommod.bridge.LibsDisguisesBridge; -import me.totalfreedom.totalfreedommod.bridge.WorldEditBridge; +import me.totalfreedom.totalfreedommod.bridge.*; import me.totalfreedom.totalfreedommod.caging.Cager; import me.totalfreedom.totalfreedommod.command.CommandLoader; import me.totalfreedom.totalfreedommod.config.MainConfig; import me.totalfreedom.totalfreedommod.discord.Discord; import me.totalfreedom.totalfreedommod.freeze.Freezer; -import me.totalfreedom.totalfreedommod.fun.ItemFun; -import me.totalfreedom.totalfreedommod.fun.Jumppads; -import me.totalfreedom.totalfreedommod.fun.Landminer; -import me.totalfreedom.totalfreedommod.fun.MP44; +import me.totalfreedom.totalfreedommod.fun.*; import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon; import me.totalfreedom.totalfreedommod.player.PlayerList; import me.totalfreedom.totalfreedommod.rank.RankManager; @@ -47,6 +28,11 @@ import org.bukkit.scheduler.BukkitRunnable; import org.mcstats.Metrics; import org.spigotmc.SpigotConfig; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + public class TotalFreedomMod extends AeroPlugin { @@ -116,6 +102,7 @@ public class TotalFreedomMod extends AeroPlugin public LibsDisguisesBridge ldb; public CoreProtectBridge cpb; public WorldEditBridge web; + public WorldGuardBridge wgb; @Override public void load() @@ -225,6 +212,7 @@ public class TotalFreedomMod extends AeroPlugin esb = bridges.registerService(EssentialsBridge.class); ldb = bridges.registerService(LibsDisguisesBridge.class); web = bridges.registerService(WorldEditBridge.class); + wgb = bridges.registerService(WorldGuardBridge.class); bridges.start(); timer.update(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java new file mode 100644 index 00000000..a0b8d120 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java @@ -0,0 +1,80 @@ +package me.totalfreedom.totalfreedommod.bridge; + +import com.sk89q.worldguard.bukkit.RegionContainer; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.util.FLog; +import org.bukkit.World; +import org.bukkit.plugin.Plugin; + +import java.util.Map; + +public class WorldGuardBridge extends FreedomService +{ + + private WorldGuardPlugin worldGuardPlugin; + + public WorldGuardBridge(TotalFreedomMod plugin) + { + super(plugin); + } + + @Override + protected void onStart() + { + } + + @Override + protected void onStop() + { + } + + public WorldGuardPlugin getWorldGuardPlugin() + { + if (worldGuardPlugin == null) + { + try + { + final Plugin worldGuard = server.getPluginManager().getPlugin("WorldGuard"); + if (worldGuard != null) + { + if (worldGuard instanceof WorldGuardPlugin) + { + worldGuardPlugin = (WorldGuardPlugin) worldGuard; + } + } + } + catch (Exception ex) + { + FLog.severe(ex); + } + } + + return worldGuardPlugin; + } + + public Boolean wipeRegions(World world) + { + RegionContainer container = getWorldGuardPlugin().getRegionContainer(); + RegionManager rm = container.get(world); + if (rm != null) + { + Map regions = rm.getRegions(); + for (ProtectedRegion region : regions.values()) + { + rm.removeRegion(region.getId()); + } + return true; + } + return false; + } + + public boolean isPluginEnabled() { + Plugin wr = getWorldGuardPlugin(); + + return wr != null && wr.isEnabled(); + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockpvp.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockpvp.java index 912bd4c8..df8609d7 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockpvp.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_blockpvp.java @@ -1,14 +1,14 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.player.FPlayer; -import org.bukkit.ChatColor; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.ArrayUtils; -import me.totalfreedom.totalfreedommod.util.FUtil; -import org.bukkit.command.Command; -import org.bukkit.entity.Player; -import org.bukkit.command.CommandSender; import me.totalfreedom.totalfreedommod.rank.Rank; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Toggle PVP mode for players.", usage = "/ [[-s] [reason] | list | purge | all]", aliases = "pvpblock,pvpmode") @@ -68,7 +68,7 @@ public class Command_blockpvp extends FreedomCommand int counter = 0; for (Player player : server.getOnlinePlayers()) { - if (!plugin.al.isAdmin((CommandSender) player)) + if (!plugin.al.isAdmin(player)) { final FPlayer playerdata = plugin.pl.getPlayer(player); playerdata.setPvpBlocked(true); @@ -83,7 +83,7 @@ public class Command_blockpvp extends FreedomCommand final boolean smite = args[0].equals("-s"); if (smite) { - args = (String[]) ArrayUtils.subarray(args, 1, args.length); + args = ArrayUtils.subarray(args, 1, args.length); if (args.length < 1) { return false; @@ -109,11 +109,11 @@ public class Command_blockpvp extends FreedomCommand FUtil.adminAction(sender.getName(), "Enabling PVP for " + p.getName(), true); pd.setPvpBlocked(false); msg("Enabling PVP for " + p.getName()); - msg((CommandSender) p, "Your PVP have been enabled.", ChatColor.GREEN); + msg(p, "Your PVP have been enabled.", ChatColor.GREEN); } else { - if (plugin.al.isAdmin((CommandSender) p)) + if (plugin.al.isAdmin(p)) { msg(p.getName() + " is an admin, and cannot have their PVP disabled."); return true; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java index 92005fd0..7268bfca 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java @@ -1,19 +1,20 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.rank.Displayable; import me.totalfreedom.totalfreedommod.rank.Rank; -import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FUtil; -import java.util.List; -import org.bukkit.ChatColor; import org.apache.commons.lang3.StringUtils; -import java.util.ArrayList; +import org.bukkit.ChatColor; import org.bukkit.command.Command; -import org.bukkit.entity.Player; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; @CommandPermissions(level = Rank.IMPOSTOR, source = SourceType.BOTH) -@CommandParameters(description = "Lists the real names of all online players.", usage = "/ [-a | -i | -f]", aliases = "who") +@CommandParameters(description = "Lists the real names of all online players.", usage = "/ [-a | -i | -f | -v]", aliases = "who") public class Command_list extends FreedomCommand { public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole) { @@ -23,15 +24,15 @@ public class Command_list extends FreedomCommand } if (FUtil.isFromHostConsole(sender.getName())) { - List names = new ArrayList(); + List names = new ArrayList<>(); for (Player player : server.getOnlinePlayers()) { names.add(player.getName()); } - msg("There are " + names.size() + "/" + server.getMaxPlayers() + " players online:\n" + StringUtils.join((Iterable)names, ", "), ChatColor.WHITE); + msg("There are " + names.size() + "/" + server.getMaxPlayers() + " players online:\n" + StringUtils.join(names, ", "), ChatColor.WHITE); return true; } - ListFilter listFilter = null; + ListFilter listFilter; if (args.length == 1) { String s = args[0]; @@ -44,6 +45,7 @@ public class Command_list extends FreedomCommand } case "-v": { + checkRank(Rank.SUPER_ADMIN); listFilter = ListFilter.VANISHED_ADMINS; break; } @@ -76,7 +78,7 @@ public class Command_list extends FreedomCommand .append(server.getMaxPlayers()) .append(ChatColor.BLUE) .append(" players online."); - List n = new ArrayList(); + List n = new ArrayList<>(); for (Player p : server.getOnlinePlayers()) { if (listFilter == ListFilter.ADMINS && !plugin.al.isAdmin(p)) @@ -91,7 +93,7 @@ public class Command_list extends FreedomCommand { continue; } - if (listFilter == ListFilter.IMPOSTORS && plugin.al.isAdminImpostor(p)) + if (listFilter == ListFilter.IMPOSTORS && !plugin.al.isAdminImpostor(p)) { continue; } @@ -106,10 +108,11 @@ public class Command_list extends FreedomCommand final Displayable display = plugin.rm.getDisplay(p); n.add(display.getColoredTag() + p.getName()); } - String playerType = (listFilter == null) ? "players" : listFilter.toString().toLowerCase().replace('_', ' '); + String playerType = listFilter.toString().toLowerCase().replace('_', ' '); onlineUsers.append("Connected ") - .append(playerType + ": ") - .append(StringUtils.join((Iterable)n, ChatColor.WHITE + ", ")); + .append(playerType) + .append(": ") + .append(StringUtils.join(n, ChatColor.WHITE + ", ")); if (senderIsConsole) { sender.sendMessage(ChatColor.stripColor(onlineStats.toString())); @@ -130,6 +133,6 @@ public class Command_list extends FreedomCommand ADMINS, VANISHED_ADMINS, FAMOUS_PLAYERS, - IMPOSTORS; + IMPOSTORS } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wiperegions.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wiperegions.java index d2129f59..e9518ddd 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wiperegions.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wiperegions.java @@ -1,47 +1,26 @@ package me.totalfreedom.totalfreedommod.command; -import com.sk89q.worldguard.bukkit.RegionContainer; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import java.util.Map; + import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; @CommandPermissions(level = Rank.TELNET_ADMIN, source = SourceType.BOTH) @CommandParameters(description = "Wipe all WorldGuard regions for a specified world.", usage = "/ ", aliases = "wiperegions") -public class Command_wiperegions extends FreedomCommand -{ - - public WorldGuardPlugin getWorldGuard() - { - Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard"); - - if (plugin == null || !(plugin instanceof WorldGuardPlugin)) - { - return null; - } - - return (WorldGuardPlugin) plugin; - } +public class Command_wiperegions extends FreedomCommand { @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (getWorldGuard() == null) + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { + if (!plugin.wgb.isPluginEnabled()) { - msg("WorldGuard is not installed.", ChatColor.GRAY); + msg("WorldGuard is not enabled.", ChatColor.GRAY); return true; } - if (args.length != 1) - { + if (args.length != 1) { return false; } World world = server.getWorld(args[0]); @@ -50,20 +29,12 @@ public class Command_wiperegions extends FreedomCommand msg("World : \"" + args[0] + "\" not found.", ChatColor.GRAY); return true; } - if (world.equals(plugin.wm.adminworld.getWorld()) && !plugin.rm.getRank(sender).isAtLeast(Rank.SENIOR_ADMIN)) + if (world.equals(plugin.wm.adminworld.getWorld())) { - msg("You do not have permission to wipe adminworld.", ChatColor.RED); - return true; + checkRank(Rank.SENIOR_ADMIN); } - RegionContainer container = getWorldGuard().getRegionContainer(); - RegionManager rm = container.get(world); - if (rm != null) + if (plugin.wgb.wipeRegions(world)) { - Map regions = rm.getRegions(); - for (ProtectedRegion region : regions.values()) - { - rm.removeRegion(region.getId()); - } FUtil.adminAction(sender.getName(), "Wiping regions for world: " + world.getName(), true); return true; } @@ -73,5 +44,4 @@ public class Command_wiperegions extends FreedomCommand return true; } } - } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wipeuserdata.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wipeuserdata.java index c652b605..75604d70 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wipeuserdata.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wipeuserdata.java @@ -1,16 +1,15 @@ package me.totalfreedom.totalfreedommod.command; -import java.io.File; -import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.Bukkit; -import static org.bukkit.Bukkit.getServer; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.io.File; + @CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true) @CommandParameters(description = "Removes essentials playerdata", usage = "/") public class Command_wipeuserdata extends FreedomCommand @@ -25,13 +24,13 @@ public class Command_wipeuserdata extends FreedomCommand return true; } - FUtil.adminAction(sender.getName(), "Wiping Essentials and Worlds playerdata", true); + FUtil.adminAction(sender.getName(), "Wiping Essentials and worlds playerdata", true); for (World w : Bukkit.getWorlds()) { - if (w.getName().equals(plugin.wm.adminworld.getWorld())) + if (w.getName().equals(plugin.wm.adminworld.getWorld().getName())) { - return true; + continue; } FUtil.deleteFolder(new File(server.getPluginManager().getPlugin("Essentials").getDataFolder(), "userdata")); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index fe0d0b11..bbc2ad88 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -1,28 +1,26 @@ package me.totalfreedom.totalfreedommod.discord; import com.google.common.base.Strings; -import me.totalfreedom.totalfreedommod.discord.MessageListener; -import me.totalfreedom.totalfreedommod.util.FLog; -import me.totalfreedom.totalfreedommod.admin.Admin; -import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.util.FLog; +import net.dv8tion.jda.core.AccountType; import net.dv8tion.jda.core.JDA; import net.dv8tion.jda.core.JDABuilder; -import net.dv8tion.jda.core.entities.MessageChannel; -import net.dv8tion.jda.core.AccountType; -import net.dv8tion.jda.core.exceptions.RateLimitedException; + +import javax.security.auth.login.LoginException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.ArrayList; -import javax.security.auth.login.LoginException; public class Discord extends FreedomService { public static HashMap LINK_CODES = new HashMap<>(); public static List VERIFY_CODES = new ArrayList(); public static JDA bot = null; - public static Boolean enabled = false; + public Boolean enabled = false; public Discord(TotalFreedomMod plugin) { @@ -52,10 +50,6 @@ public class Discord extends FreedomService { FLog.warning("An invalid token for the discord verification bot, the bot will not enable."); } - catch (RateLimitedException e) - { - FLog.warning("The discord verification bot was ratelimited trying to login, please try again later."); - } catch (IllegalArgumentException | InterruptedException e) { FLog.warning("Discord verification bot failed to start."); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/MessageListener.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/MessageListener.java index f9412b7c..c63d6a3a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/MessageListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/MessageListener.java @@ -14,14 +14,14 @@ public class MessageListener extends ListenerAdapter // Handle link code if (event.getMessage().getContentRaw().matches("[0-9][0-9][0-9][0-9][0-9]")) { - String code = event.getMessage().getRawContent(); + String code = event.getMessage().getContentRaw(); if (Discord.LINK_CODES.get(code) != null) { Admin admin = Discord.LINK_CODES.get(code); admin.setDiscordID(event.getMessage().getAuthor().getId()); Discord.LINK_CODES.remove(code); event.getChannel().sendMessage("Link successful. Now this Discord account is linked with the Minecraft account `" + admin.getName() + "`.\n " - + "Now when you are an impostor on the server, you may use `/verify` to verify.").complete();; + + "Now when you are an impostor on the server, you may use `/verify` to verify.").complete(); } } }