[WIP / DO NOT USE ON PRODUCTION!!] Begin implementing support for SuperVanish and fix bugs

- Update dependencies in pom.xml
- Replace TotalFreedomMod's vanish system with SuperVanish. It's widely supported by many major plugins and does a better job vanishing players
- Fixed a typo in the SQL command for creating admin tables, where the table would not be created on a clean install of TFM
- Update bStats Metrics to latest version
- Remove the VanishHandler
- Sync the permissions.yml from whats on the server. Entries for Essentials and SuperVanish will be added soon

KNOWN BUG:
- Plugins override TFM commands (e.g. Essentials takes over /list instead of giving it to TFM). I noticed that there is a semicolon before every TFM command. (:/ban, :/list), which is the actual TFM command. I have no idea where / how this bug came from. Urgently needs to be fixed.
This commit is contained in:
Telesphoreo 2020-08-04 01:31:26 -05:00
parent e1b514ca85
commit 4555a7e3f2
25 changed files with 297 additions and 378 deletions

17
pom.xml
View File

@ -5,7 +5,7 @@
<groupId>me.totalfreedom</groupId>
<artifactId>TotalFreedomMod</artifactId>
<version>5.6</version>
<version>2020.9</version>
<packaging>jar</packaging>
<properties>
@ -117,14 +117,14 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<version>2.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
<version>3.11</version>
<scope>compile</scope>
</dependency>
@ -135,6 +135,13 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.MyzelYam</groupId>
<artifactId>SuperVanish</artifactId>
<version>6.1.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
@ -179,14 +186,14 @@
<dependency>
<groupId>net.coreprotect</groupId>
<artifactId>coreprotect</artifactId>
<version>2.16.3</version>
<version>2.18.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.2</version>
<version>7.0.3</version>
<scope>provided</scope>
</dependency>

View File

@ -3,7 +3,6 @@ package me.totalfreedom.totalfreedommod;
import java.io.File;
import java.io.InputStream;
import java.util.Properties;
import java.util.Set;
import me.totalfreedom.totalfreedommod.admin.ActivityLog;
import me.totalfreedom.totalfreedommod.admin.AdminList;
import me.totalfreedom.totalfreedommod.banning.BanManager;
@ -23,11 +22,11 @@ import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge;
import me.totalfreedom.totalfreedommod.bridge.FAWEBridge;
import me.totalfreedom.totalfreedommod.bridge.LibsDisguisesBridge;
import me.totalfreedom.totalfreedommod.bridge.TFGuildsBridge;
import me.totalfreedom.totalfreedommod.bridge.VanishBridge;
import me.totalfreedom.totalfreedommod.bridge.WorldEditBridge;
import me.totalfreedom.totalfreedommod.bridge.WorldGuardBridge;
import me.totalfreedom.totalfreedommod.caging.Cager;
import me.totalfreedom.totalfreedommod.command.CommandLoader;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.config.MainConfig;
import me.totalfreedom.totalfreedommod.discord.Discord;
import me.totalfreedom.totalfreedommod.freeze.Freezer;
@ -58,16 +57,17 @@ import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.reflections.Reflections;
import org.spigotmc.SpigotConfig;
public class TotalFreedomMod extends JavaPlugin
{
private static TotalFreedomMod plugin;
public static TotalFreedomMod getPlugin()
{
return plugin;
}
public static final String CONFIG_FILENAME = "config.yml";
//
public static final BuildProperties build = new BuildProperties();
@ -136,7 +136,7 @@ public class TotalFreedomMod extends JavaPlugin
public SignBlocker snp;
public EntityWiper ew;
public Sitter st;
public VanishHandler vh;
public VanishBridge vb;
//public HubWorldRestrictions hwr;
//
@ -185,17 +185,17 @@ public class TotalFreedomMod extends JavaPlugin
config = new MainConfig();
config.load();
if (FUtil.inDeveloperMode())
{
FLog.debug("Developer mode enabled.");
}
cl = new CommandLoader();
cl.loadCommands();
BackupManager backups = new BackupManager();
backups.createAllBackups();
if (FUtil.inDeveloperMode())
{
FLog.debug("Developer mode enabled.");
}
permissions = new PermissionConfig(this);
permissions.load();
@ -233,7 +233,7 @@ public class TotalFreedomMod extends JavaPlugin
snp = new SignBlocker();
ew = new EntityWiper();
st = new Sitter();
vh = new VanishHandler();
vb = new VanishBridge();
// Single admin utils
cs = new CommandSpy();
@ -281,8 +281,8 @@ public class TotalFreedomMod extends JavaPlugin
timer.update();
FLog.info("Version " + pluginVersion + " for " + ServerInterface.COMPILE_NMS_VERSION + " enabled in " + timer.getTotal() + "ms");
// Metrics @ https://bstats.org/plugin/bukkit/TotalFreedomMod
new Metrics(this);
// Metrics @ https://bstats.org/plugin/bukkit/TotalFreedomMod/2966
new Metrics(this, 2966);
// Add spawnpoints later - https://github.com/TotalFreedom/TotalFreedomMod/issues/438
new BukkitRunnable()
@ -313,7 +313,6 @@ public class TotalFreedomMod extends JavaPlugin
public static class BuildProperties
{
public String author;
public String codename;
public String version;

View File

@ -1,83 +0,0 @@
package me.totalfreedom.totalfreedommod;
import me.totalfreedom.totalfreedommod.util.FLog;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitRunnable;
public class VanishHandler extends FreedomService
{
@Override
public void onStart()
{
}
@Override
public void onStop()
{
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerJoin(PlayerJoinEvent event)
{
Player player = event.getPlayer();
for (Player p : server.getOnlinePlayers())
{
if (!plugin.al.isAdmin(player) && plugin.al.isVanished(p.getName()))
{
player.hidePlayer(plugin, p);
}
}
for (Player p : server.getOnlinePlayers())
{
if (!plugin.al.isAdmin(p) && plugin.al.isVanished(player.getName()))
{
p.hidePlayer(plugin, player);
}
}
if (plugin.al.isVanished(player.getName()))
{
plugin.esb.setVanished(player.getName(), true);
FLog.info(player.getName() + " joined while still vanished.");
plugin.al.messageAllAdmins(ChatColor.YELLOW + player.getName() + " has joined silently.");
event.setJoinMessage(null);
new BukkitRunnable()
{
@Override
public void run()
{
if (!plugin.al.isVanished(player.getName()))
{
this.cancel();
}
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.GOLD + "You are hidden from other players."));
}
}.runTaskTimer(plugin, 0L, 4L);
}
}
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event)
{
Player player = event.getPlayer();
if (plugin.al.isVanished(player.getName()))
{
event.setQuitMessage(null);
FLog.info(player.getName() + " left while still vanished.");
plugin.al.messageAllAdmins(ChatColor.YELLOW + player.getName() + " has left silently.");
}
}
}

View File

@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.admin;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import de.myzelyam.api.vanish.VanishAPI;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
@ -19,6 +20,7 @@ import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.metadata.MetadataValue;
public class AdminList extends FreedomService
{
@ -31,7 +33,6 @@ public class AdminList extends FreedomService
private final Map<String, Admin> ipTable = Maps.newHashMap();
public final List<String> verifiedNoAdmins = new ArrayList<>();
public final Map<String, List<String>> verifiedNoAdminIps = Maps.newHashMap();
public static List<String> vanished = new ArrayList<>();
@Override
public void onStart()
@ -363,8 +364,8 @@ public class AdminList extends FreedomService
updateTables();
}
public boolean isVanished(String player)
public boolean isVanished(Player player)
{
return vanished.contains(player);
return VanishAPI.isInvisible(player);
}
}

View File

@ -0,0 +1,48 @@
package me.totalfreedom.totalfreedommod.bridge;
import de.myzelyam.api.vanish.PlayerHideEvent;
import de.myzelyam.api.vanish.PlayerShowEvent;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Displayable;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
public class VanishBridge extends FreedomService
{
@Override
public void onStart()
{
}
@Override
public void onStop()
{
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerUnvanish(PlayerShowEvent event)
{
Player player = event.getPlayer();
Displayable display = plugin.rm.getDisplay(player);
String tag = display.getColoredTag();
FUtil.bcastMsg(plugin.rm.craftLoginMessage(event.getPlayer(), null));
plugin.dc.messageChatChannel("**" + player.getName() + " joined the server" + "**");
PlayerData playerData = plugin.pl.getData(player);
if (playerData.getTag() != null)
{
tag = FUtil.colorize(playerData.getTag());
}
playerData.setTag(tag);
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerVanish(PlayerHideEvent event)
{
Player player = event.getPlayer();
plugin.dc.messageChatChannel("**" + player.getName() + " left the server" + "**");
}
}

View File

@ -22,7 +22,6 @@ import org.bukkit.entity.Player;
@CommandParameters(description = "Bans the specified player.", usage = "/<command> <username> [reason] [-nrb | -q]", aliases = "gtfo")
public class Command_ban extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{

View File

@ -31,12 +31,12 @@ public class Command_deop extends FreedomCommand
final String targetName = args[0].toLowerCase();
final List<String> matchedPlayerNames = new ArrayList<>();
for (final Player player : server.getOnlinePlayers())
for (Player player : server.getOnlinePlayers())
{
if (player.getName().toLowerCase().contains(targetName) || player.getDisplayName().toLowerCase().contains(targetName)
|| player.getName().contains(targetName) || player.getDisplayName().contains(targetName))
{
if (player.isOp() && !AdminList.vanished.contains(player.getName()))
if (player.isOp() && plugin.al.isVanished(player))
{
matchedPlayerNames.add(player.getName());
player.setOp(false);

View File

@ -43,7 +43,7 @@ public class Command_invis extends FreedomCommand
for (Player player : server.getOnlinePlayers())
{
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY) && !plugin.al.isVanished(player.getName()))
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY) && !plugin.al.isVanished(player))
{
players.add(player.getName());
if (clear && !plugin.al.isAdmin(player))

View File

@ -1,5 +1,6 @@
package me.totalfreedom.totalfreedommod.command;
import de.myzelyam.api.vanish.VanishAPI;
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.totalfreedommod.admin.Admin;
@ -18,7 +19,7 @@ import org.bukkit.entity.Player;
@CommandParameters(description = "Lists the real names of all online players.", usage = "/<command> [-a | -i | -f | -v]", aliases = "who,lsit")
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)
{
if (args.length > 1)
@ -96,7 +97,7 @@ public class Command_list extends FreedomCommand
}
else
{
onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(server.getOnlinePlayers().size() - AdminList.vanished.size())
onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(server.getOnlinePlayers().size() - VanishAPI.getInvisiblePlayers().size())
.append(ChatColor.BLUE)
.append(" out of a maximum ")
.append(ChatColor.RED)
@ -109,11 +110,11 @@ public class Command_list extends FreedomCommand
{
continue;
}
if (listFilter == ListFilter.ADMINS && AdminList.vanished.contains(p.getName()))
if (listFilter == ListFilter.ADMINS && plugin.al.isVanished(p))
{
continue;
}
if (listFilter == ListFilter.VANISHED_ADMINS && !AdminList.vanished.contains(p.getName()))
if (listFilter == ListFilter.VANISHED_ADMINS && !plugin.al.isVanished(p))
{
continue;
}
@ -125,7 +126,7 @@ public class Command_list extends FreedomCommand
{
continue;
}
if (listFilter == ListFilter.PLAYERS && AdminList.vanished.contains(p.getName()))
if (listFilter == ListFilter.PLAYERS && plugin.al.isVanished(p))
{
continue;
}

View File

@ -41,11 +41,11 @@ public class Command_nickfilter extends FreedomCommand
player = getPlayerByDisplayName(displayName);
if (player == null || plugin.al.isVanished(player.getName()) && !plugin.al.isAdmin(sender))
if (player == null || plugin.al.isVanished(player) && !plugin.al.isAdmin(sender))
{
player = getPlayerByDisplayNameAlt(displayName);
if (player == null || !plugin.al.isVanished(player.getName()) && !plugin.al.isAdmin(sender))
if (player == null || !plugin.al.isVanished(player) && !plugin.al.isAdmin(sender))
{
sender.sendMessage(ChatColor.GRAY + "Can't find player by nickname: " + displayName);
return true;

View File

@ -37,7 +37,7 @@ public class Command_op extends FreedomCommand
if (player.getName().toLowerCase().contains(targetName) || player.getDisplayName().toLowerCase().contains(targetName)
|| player.getName().contains(targetName) || player.getDisplayName().contains(targetName))
{
if (!player.isOp() && !AdminList.vanished.contains(player.getName()))
if (!player.isOp() && !plugin.al.isVanished(player))
{
matchedPlayerNames.add(player.getName());
player.setOp(true);

View File

@ -104,7 +104,7 @@ public class Command_potion extends FreedomCommand
{
target = getPlayer(args[4]);
if (target == null || plugin.al.isVanished(target.getName()) && !plugin.al.isAdmin(sender))
if (target == null || plugin.al.isVanished(target) && !plugin.al.isAdmin(sender))
{
msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
return true;

View File

@ -48,7 +48,7 @@ public class Command_tag extends FreedomCommand
for (final Player player : server.getOnlinePlayers())
{
if (plugin.al.isVanished(player.getName()) && !plugin.al.isAdmin(sender))
if (plugin.al.isVanished(player) && !plugin.al.isAdmin(sender))
{
continue;
}

View File

@ -1,120 +0,0 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Displayable;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Vanish/unvanish yourself.", usage = "/<command> [-s[ilent]]", aliases = "v")
public class Command_vanish extends FreedomCommand
{
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
{
Displayable display = plugin.rm.getDisplay(playerSender);
String displayName = display.getColor() + playerSender.getName();
String tag = display.getColoredTag();
boolean silent = false;
if (args.length > 0)
{
if (args[0].equalsIgnoreCase("-s") || args[0].equalsIgnoreCase("-silent"))
{
silent = true;
}
}
if (plugin.al.isVanished(playerSender.getName()))
{
if (silent)
{
msg(ChatColor.GOLD + "Silently unvanished.");
}
else
{
msg("You have unvanished.", ChatColor.GOLD);
FUtil.bcastMsg(plugin.rm.craftLoginMessage(playerSender, null));
FUtil.bcastMsg(playerSender.getName() + " joined the game.", ChatColor.YELLOW);
plugin.dc.messageChatChannel("**" + playerSender.getName() + " joined the server" + "**");
}
PlayerData playerData = plugin.pl.getData(playerSender);
if (playerData.getTag() != null)
{
tag = FUtil.colorize(playerData.getTag());
}
plugin.pl.getData(playerSender).setTag(tag);
FLog.info(playerSender.getName() + " is no longer vanished.");
for (Player player : server.getOnlinePlayers())
{
if (plugin.al.isAdmin(player))
{
playerMsg(player, ChatColor.YELLOW + sender.getName() + " has unvanished and is now visible to everyone.");
}
if (!plugin.al.isAdmin(player))
{
player.showPlayer(plugin, playerSender);
}
}
plugin.esb.setVanished(playerSender.getName(), false);
playerSender.setPlayerListName(StringUtils.substring(displayName, 0, 16));
plugin.al.vanished.remove(playerSender.getName());
}
else
{
new BukkitRunnable()
{
@Override
public void run()
{
if (plugin.al.isVanished(playerSender.getName()))
{
playerSender.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.GOLD + "You are hidden from other players."));
}
}
}.runTaskTimer(plugin, 0L, 4L);
if (silent)
{
msg("Silently vanished.", ChatColor.GOLD);
}
else
{
msg ("You have vanished.", ChatColor.GOLD);
FUtil.bcastMsg(playerSender.getName() + " left the game.", ChatColor.YELLOW);
plugin.dc.messageChatChannel("**" + playerSender.getName() + " left the server" + "**");
}
FLog.info(playerSender.getName() + " is now vanished.");
for (Player player : server.getOnlinePlayers())
{
{
if (plugin.al.isAdmin(player))
{
playerMsg(player, ChatColor.YELLOW + sender.getName() + " has vanished and is now only visible to admins.");
}
if (!plugin.al.isAdmin(player))
{
player.hidePlayer(plugin, playerSender);
}
}
}
plugin.esb.setVanished(playerSender.getName(), true);
plugin.al.vanished.add(playerSender.getName());
}
return true;
}
}

View File

@ -40,7 +40,7 @@ public class Command_whohas extends FreedomCommand
for (final Player player : server.getOnlinePlayers())
{
if (!plugin.al.isAdmin(sender) && plugin.al.isVanished(player.getName()))
if (!plugin.al.isAdmin(sender) && plugin.al.isVanished(player))
{
continue;
}

View File

@ -305,7 +305,7 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
Player player = Bukkit.getPlayer(name);
if (player != null)
{
if (nullVanished && plugin.al.isVanished(player.getName()) && !plugin.al.isAdmin(sender))
if (nullVanished && plugin.al.isVanished(player) && !plugin.al.isAdmin(sender))
{
return null;
}

View File

@ -254,7 +254,7 @@ public class Discord extends FreedomService
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event)
{
if (!plugin.al.isVanished(event.getPlayer().getName()))
if (!plugin.al.isVanished(event.getPlayer()))
{
messageChatChannel("**" + deformat(event.getPlayer().getName()) + " joined the server" + "**");
}
@ -263,7 +263,7 @@ public class Discord extends FreedomService
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLeave(PlayerQuitEvent event)
{
if (!plugin.al.isVanished(event.getPlayer().getName()))
if (!plugin.al.isVanished(event.getPlayer()))
{
messageChatChannel("**" + deformat(event.getPlayer().getName()) + " left the server" + "**");
}

View File

@ -40,7 +40,7 @@ public class Module_list extends HTTPDModule
for (Player player : Bukkit.getOnlinePlayers())
{
if (plugin.al.isVanished(player.getName()))
if (plugin.al.isVanished(player))
{
continue;
}
@ -128,7 +128,7 @@ public class Module_list extends HTTPDModule
for (Player player : onlinePlayers)
{
if (plugin.al.isVanished(player.getName()))
if (plugin.al.isVanished(player))
{
continue;
}

View File

@ -36,7 +36,7 @@ public class Module_players extends HTTPDModule
// All online players
for (Player player : Bukkit.getOnlinePlayers())
{
if (!plugin.al.isVanished(player.getName()))
if (!plugin.al.isVanished(player))
{
players.add(player.getName());
if (plugin.al.isAdmin(player) && !plugin.al.isAdminImpostor(player))

View File

@ -250,7 +250,7 @@ public class RankManager extends FreedomService
// Broadcast login message
if (isAdmin || FUtil.isDeveloper(player.getName()) || plugin.pl.getData(player).isMasterBuilder() || plugin.pl.getData(player).isDonator())
{
if (!plugin.al.isVanished(player.getName()))
if (!plugin.al.isVanished(player))
{
FUtil.bcastMsg(craftLoginMessage(player, null));
}

View File

@ -84,7 +84,7 @@ public class SQLite extends FreedomService
{
try
{
connection.createStatement().execute("CREATE TABLE `admins` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `rank` VARCHAR NOT NULL, `active` BOOLEAN NOT NULL, `last_login` LONG NOT NULL, `login_message` VARCHAR, `command_spy` BOOLEAN NOT NULL, `potion_spy` BOOLEAN NOT NULL, `ac_format` VARCHAR, `old_tags` BOOLEAN NOT NULL, `log_stick` BOOLEAN NOT NULL, `display_discord` BOOLEAN NOT NULL,);");
connection.createStatement().execute("CREATE TABLE `admins` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `rank` VARCHAR NOT NULL, `active` BOOLEAN NOT NULL, `last_login` LONG NOT NULL, `login_message` VARCHAR, `command_spy` BOOLEAN NOT NULL, `potion_spy` BOOLEAN NOT NULL, `ac_format` VARCHAR, `old_tags` BOOLEAN NOT NULL, `log_stick` BOOLEAN NOT NULL, `display_discord` BOOLEAN NOT NULL);");
}
catch (SQLException e)
{

View File

@ -146,7 +146,7 @@ public class FUtil
List<String> names = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers())
{
if (!TotalFreedomMod.plugin().al.isVanished(player.getName()))
if (!TotalFreedomMod.plugin().al.isVanished(player))
{
names.add(player.getName());
}

View File

@ -1,12 +1,19 @@
package org.bstats;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -15,23 +22,22 @@ import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
import javax.net.ssl.HttpsURLConnection;
import me.totalfreedom.totalfreedommod.util.FLog;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
/**
* bStats collects some data for plugin authors.
* <p>
* Check out https://bStats.org/ to learn more about bStats!
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public class Metrics
{
static
@ -57,14 +63,26 @@ public class Metrics
// The url to which the data is sent
private static final String URL = "https://bStats.org/submitData/bukkit";
// Is bStats enabled on this server?
private boolean enabled;
// Should failed requests be logged?
private static boolean logFailedRequests;
// Should the sent data be logged?
private static boolean logSentData;
// Should the response text be logged?
private static boolean logResponseStatusText;
// The uuid of the server
private static String serverUUID;
// The plugin
private final JavaPlugin plugin;
private final Plugin plugin;
// The plugin id
private final int pluginId;
// A list with all custom charts
private final List<CustomChart> charts = new ArrayList<>();
@ -72,15 +90,18 @@ public class Metrics
/**
* Class constructor.
*
* @param plugin The plugin which stats should be submitted.
* @param plugin The plugin which stats should be submitted.
* @param pluginId The id of the plugin.
* It can be found at <a href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
*/
public Metrics(JavaPlugin plugin)
public Metrics(Plugin plugin, int pluginId)
{
if (plugin == null)
{
throw new IllegalArgumentException("Plugin cannot be null!");
}
this.plugin = plugin;
this.pluginId = pluginId;
// Get the config file
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
@ -90,12 +111,17 @@ public class Metrics
// Check if the config file exists
if (!config.isSet("serverUuid"))
{
// Add default values
config.addDefault("enabled", true);
// Every server gets it's unique random id.
config.addDefault("serverUuid", UUID.randomUUID().toString());
// Should failed request be logged?
config.addDefault("logFailedRequests", false);
// Should the sent data be logged?
config.addDefault("logSentData", false);
// Should the response text be logged?
config.addDefault("logResponseStatusText", false);
// Inform the server owners about bStats
config.options().header(
@ -114,9 +140,13 @@ public class Metrics
}
// Load the data
enabled = config.getBoolean("enabled", true);
serverUUID = config.getString("serverUuid");
logFailedRequests = config.getBoolean("logFailedRequests", false);
if (config.getBoolean("enabled", true))
logSentData = config.getBoolean("logSentData", false);
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
if (enabled)
{
boolean found = false;
// Search for all other bStats Metrics classes to see if we are the first one
@ -142,6 +172,16 @@ public class Metrics
}
}
/**
* Checks if bStats is enabled.
*
* @return Whether bStats is enabled or not.
*/
public boolean isEnabled()
{
return enabled;
}
/**
* Adds a custom chart.
*
@ -174,14 +214,7 @@ public class Metrics
}
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
Bukkit.getScheduler().runTask(plugin, new Runnable()
{
@Override
public void run()
{
submitData();
}
});
Bukkit.getScheduler().runTask(plugin, () -> submitData());
}
}, 1000 * 60 * 5, 1000 * 60 * 30);
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
@ -195,26 +228,28 @@ public class Metrics
*
* @return The plugin specific data.
*/
public JSONObject getPluginData()
public JsonObject getPluginData()
{
JSONObject data = new JSONObject();
JsonObject data = new JsonObject();
String pluginName = plugin.getDescription().getName();
String pluginVersion = plugin.getDescription().getVersion();
data.put("pluginName", "TotalFreedomMod"); // Append the name of the plugin
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
JSONArray customCharts = new JSONArray();
data.addProperty("pluginName", pluginName); // Append the name of the plugin
data.addProperty("id", pluginId); // Append the id of the plugin
data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin
JsonArray customCharts = new JsonArray();
for (CustomChart customChart : charts)
{
// Add the data of the custom charts
JSONObject chart = customChart.getRequestJsonObject();
JsonObject chart = customChart.getRequestJsonObject();
if (chart == null)
{ // If the chart is null, we skip it
continue;
}
customCharts.add(chart);
}
data.put("customCharts", customCharts);
data.add("customCharts", customCharts);
return data;
}
@ -224,7 +259,7 @@ public class Metrics
*
* @return The server specific data.
*/
private JSONObject getServerData()
private JsonObject getServerData()
{
// Minecraft specific data
int playerAmount;
@ -242,8 +277,8 @@ public class Metrics
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
}
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
String bukkitVersion = org.bukkit.Bukkit.getVersion();
bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1);
String bukkitVersion = Bukkit.getVersion();
String bukkitName = Bukkit.getName();
// OS/Java specific data
String javaVersion = System.getProperty("java.version");
@ -252,19 +287,20 @@ public class Metrics
String osVersion = System.getProperty("os.version");
int coreCount = Runtime.getRuntime().availableProcessors();
JSONObject data = new JSONObject();
JsonObject data = new JsonObject();
data.put("serverUUID", serverUUID);
data.addProperty("serverUUID", serverUUID);
data.put("playerAmount", playerAmount);
data.put("onlineMode", onlineMode);
data.put("bukkitVersion", bukkitVersion);
data.addProperty("playerAmount", playerAmount);
data.addProperty("onlineMode", onlineMode);
data.addProperty("bukkitVersion", bukkitVersion);
data.addProperty("bukkitName", bukkitName);
data.put("javaVersion", javaVersion);
data.put("osName", osName);
data.put("osArch", osArch);
data.put("osVersion", osVersion);
data.put("coreCount", coreCount);
data.addProperty("javaVersion", javaVersion);
data.addProperty("osName", osName);
data.addProperty("osArch", osArch);
data.addProperty("osVersion", osVersion);
data.addProperty("coreCount", coreCount);
return data;
}
@ -274,9 +310,9 @@ public class Metrics
*/
private void submitData()
{
final JSONObject data = getServerData();
final JsonObject data = getServerData();
JSONArray pluginData = new JSONArray();
JsonArray pluginData = new JsonArray();
// Search for all other bStats Metrics classes to get their plugin data
for (Class<?> service : Bukkit.getServicesManager().getKnownServices())
{
@ -288,7 +324,34 @@ public class Metrics
{
try
{
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider());
if (plugin instanceof JsonObject)
{
pluginData.add((JsonObject)plugin);
}
else
{ // old bstats version compatibility
try
{
Class<?> jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject");
if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple))
{
Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString");
jsonStringGetter.setAccessible(true);
String jsonString = (String)jsonStringGetter.invoke(plugin);
JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject();
pluginData.add(object);
}
}
catch (ClassNotFoundException e)
{
// minecraft version 1.14+
if (logFailedRequests)
{
this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception", e);
}
}
}
}
catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored)
{
@ -300,26 +363,22 @@ public class Metrics
}
}
data.put("plugins", pluginData);
data.add("plugins", pluginData);
// Create a new thread for the connection to the bStats server
new Thread(new Runnable()
new Thread(() ->
{
@Override
public void run()
try
{
try
// Send the data
sendData(plugin, data);
}
catch (Exception e)
{
// Something went wrong! :(
if (logFailedRequests)
{
// Send the data
sendData(data);
}
catch (Exception e)
{
// Something went wrong! :(
if (logFailedRequests)
{
FLog.warning("Could not submit plugin stats of " + plugin.getName() + e);
}
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
}
}
}).start();
@ -328,10 +387,11 @@ public class Metrics
/**
* Sends the data to the bStats server.
*
* @param data The data to send.
* @param plugin Any plugin. It's just used to get a logger instance.
* @param data The data to send.
* @throws Exception If the request failed.
*/
private static void sendData(JSONObject data) throws Exception
private static void sendData(Plugin plugin, JsonObject data) throws Exception
{
if (data == null)
{
@ -341,6 +401,10 @@ public class Metrics
{
throw new IllegalAccessException("This method must not be called from the main thread!");
}
if (logSentData)
{
plugin.getLogger().info("Sending data to bStats: " + data);
}
HttpsURLConnection connection = (HttpsURLConnection)new URL(URL).openConnection();
// Compress the data to save bandwidth
@ -357,12 +421,25 @@ public class Metrics
// Send data
connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.write(compressedData);
outputStream.flush();
outputStream.close();
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()))
{
outputStream.write(compressedData);
}
connection.getInputStream().close(); // We don't care about the response - Just send our data :)
StringBuilder builder = new StringBuilder();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream())))
{
String line;
while ((line = bufferedReader.readLine()) != null)
{
builder.append(line);
}
}
if (logResponseStatusText)
{
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
}
}
/**
@ -379,9 +456,10 @@ public class Metrics
return null;
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
gzip.write(str.getBytes("UTF-8"));
gzip.close();
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream))
{
gzip.write(str.getBytes(StandardCharsets.UTF_8));
}
return outputStream.toByteArray();
}
@ -408,32 +486,32 @@ public class Metrics
this.chartId = chartId;
}
private JSONObject getRequestJsonObject()
private JsonObject getRequestJsonObject()
{
JSONObject chart = new JSONObject();
chart.put("chartId", chartId);
JsonObject chart = new JsonObject();
chart.addProperty("chartId", chartId);
try
{
JSONObject data = getChartData();
JsonObject data = getChartData();
if (data == null)
{
// If the data is null we don't send the chart.
return null;
}
chart.put("data", data);
chart.add("data", data);
}
catch (Throwable t)
{
if (logFailedRequests)
{
FLog.warning("Failed to get data for custom chart with id " + chartId + t);
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
}
return null;
}
return chart;
}
protected abstract JSONObject getChartData() throws Exception;
protected abstract JsonObject getChartData() throws Exception;
}
@ -458,16 +536,16 @@ public class Metrics
}
@Override
protected JSONObject getChartData() throws Exception
protected JsonObject getChartData() throws Exception
{
JSONObject data = new JSONObject();
JsonObject data = new JsonObject();
String value = callable.call();
if (value == null || value.isEmpty())
{
// Null = skip the chart
return null;
}
data.put("value", value);
data.addProperty("value", value);
return data;
}
}
@ -493,10 +571,10 @@ public class Metrics
}
@Override
protected JSONObject getChartData() throws Exception
protected JsonObject getChartData() throws Exception
{
JSONObject data = new JSONObject();
JSONObject values = new JSONObject();
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty())
{
@ -511,14 +589,14 @@ public class Metrics
continue; // Skip this invalid
}
allSkipped = false;
values.put(entry.getKey(), entry.getValue());
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped)
{
// Null = skip the chart
return null;
}
data.put("values", values);
data.add("values", values);
return data;
}
}
@ -544,10 +622,10 @@ public class Metrics
}
@Override
public JSONObject getChartData() throws Exception
public JsonObject getChartData() throws Exception
{
JSONObject data = new JSONObject();
JSONObject values = new JSONObject();
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Map<String, Integer>> map = callable.call();
if (map == null || map.isEmpty())
{
@ -557,17 +635,17 @@ public class Metrics
boolean reallyAllSkipped = true;
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet())
{
JSONObject value = new JSONObject();
JsonObject value = new JsonObject();
boolean allSkipped = true;
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet())
{
value.put(valueEntry.getKey(), valueEntry.getValue());
value.addProperty(valueEntry.getKey(), valueEntry.getValue());
allSkipped = false;
}
if (!allSkipped)
{
reallyAllSkipped = false;
values.put(entryValues.getKey(), value);
values.add(entryValues.getKey(), value);
}
}
if (reallyAllSkipped)
@ -575,7 +653,7 @@ public class Metrics
// Null = skip the chart
return null;
}
data.put("values", values);
data.add("values", values);
return data;
}
}
@ -601,16 +679,16 @@ public class Metrics
}
@Override
protected JSONObject getChartData() throws Exception
protected JsonObject getChartData() throws Exception
{
JSONObject data = new JSONObject();
JsonObject data = new JsonObject();
int value = callable.call();
if (value == 0)
{
// Null = skip the chart
return null;
}
data.put("value", value);
data.addProperty("value", value);
return data;
}
@ -637,10 +715,10 @@ public class Metrics
}
@Override
protected JSONObject getChartData() throws Exception
protected JsonObject getChartData() throws Exception
{
JSONObject data = new JSONObject();
JSONObject values = new JSONObject();
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty())
{
@ -655,14 +733,14 @@ public class Metrics
continue; // Skip this invalid
}
allSkipped = false;
values.put(entry.getKey(), entry.getValue());
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped)
{
// Null = skip the chart
return null;
}
data.put("values", values);
data.add("values", values);
return data;
}
@ -689,10 +767,10 @@ public class Metrics
}
@Override
protected JSONObject getChartData() throws Exception
protected JsonObject getChartData() throws Exception
{
JSONObject data = new JSONObject();
JSONObject values = new JSONObject();
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty())
{
@ -701,11 +779,11 @@ public class Metrics
}
for (Map.Entry<String, Integer> entry : map.entrySet())
{
JSONArray categoryValues = new JSONArray();
categoryValues.add(entry.getValue());
values.put(entry.getKey(), categoryValues);
JsonArray categoryValues = new JsonArray();
categoryValues.add(new JsonPrimitive(entry.getValue()));
values.add(entry.getKey(), categoryValues);
}
data.put("values", values);
data.add("values", values);
return data;
}
@ -732,10 +810,10 @@ public class Metrics
}
@Override
protected JSONObject getChartData() throws Exception
protected JsonObject getChartData() throws Exception
{
JSONObject data = new JSONObject();
JSONObject values = new JSONObject();
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, int[]> map = callable.call();
if (map == null || map.isEmpty())
{
@ -750,19 +828,19 @@ public class Metrics
continue; // Skip this invalid
}
allSkipped = false;
JSONArray categoryValues = new JSONArray();
JsonArray categoryValues = new JsonArray();
for (int categoryValue : entry.getValue())
{
categoryValues.add(categoryValue);
categoryValues.add(new JsonPrimitive(categoryValue));
}
values.put(entry.getKey(), categoryValues);
values.add(entry.getKey(), categoryValues);
}
if (allSkipped)
{
// Null = skip the chart
return null;
}
data.put("values", values);
data.add("values", values);
return data;
}
}

View File

@ -9,7 +9,8 @@
# This is used to remove all permission begging with the root node
# This is useful when a plugin gives all permissions to a player because they are opped
remove:
- "coreprotect"
- "voxelsniper"
- "bending"
# Operator permission nodes
operators:
@ -35,27 +36,12 @@ operators:
- "worldedit.removebelow"
- "worldedit.removenear"
- "worldedit.replacenear"
- "worldedit.clipboard.save"
- "worldedit.clipboard.load"
- "worldedit.schematic.save"
- "worldedit.schematic.load"
- "worldedit.schematic.formats"
# CoreProtect
- "coreprotect.inspect"
- "coreprotect.lookup"
- "coreprotect.help"
- "coreprotect.status"
- "coreprotect.lookup.block"
- "coreprotect.lookup.click"
- "coreprotect.lookup.container"
- "coreprotect.container"
- "coreprotect.core"
- "coreprotect.coreprotect"
- "coreprotect.co"
# LibsDisguises
- "libsdisguises.noactionbar"
# WorldGuard
- "worldguard.region.list.own"
- "worldgyardregion.list.own"
- "worldguard.region.addmember.own.*"
- "worldguard.region.removemember.own.*"
- "worldguard.region.info.*"
@ -70,16 +56,19 @@ master_builders:
- "worldedit.thaw"
- "worldguard.region.bypass.hubworld"
- "worldguard.region.bypass.masterbuilderworld"
- "voxelsniper.sniper"
- "voxelsniper.goto"
- "voxelsniper.brush.*"
# Super Admin permission nodes
super_admins:
- "coreprotect.*"
- "worldedit.*"
- "worldguard.*"
- "bending.*"
# Telnet Admin permission nodes
telnet_admins: []
# Senior Admin permission nodes
senior_admins: []
senior_admins: []

View File

@ -2,6 +2,6 @@ name: TotalFreedomMod
main: me.totalfreedom.totalfreedommod.TotalFreedomMod
version: ${project.version}
description: Plugin for the Total Freedom server.
softdepend: [BukkitTelnet, Essentials, LibsDisguises, WorldEdit, WorldGuard, WorldGuardExtraFlags, TFGuilds]
softdepend: [BukkitTelnet, Essentials, LibsDisguises, WorldEdit, WorldGuard, WorldGuardExtraFlags, TFGuilds, SuperVanish, PremiumVanish]
authors: [Madgeek1450, Prozza]
api-version: 1.16