morle 😢

This commit is contained in:
Business Goose 2022-03-31 03:00:43 +01:00
parent c8d686238c
commit b1882a2a10
No known key found for this signature in database
GPG key ID: 77DCA801362E9645
15 changed files with 1922 additions and 2081 deletions

View file

@ -16,7 +16,7 @@ import me.StevenLawson.TotalFreedomMod.httpd.HTTPDManager;
import me.StevenLawson.TotalFreedomMod.listener.*; import me.StevenLawson.TotalFreedomMod.listener.*;
import me.StevenLawson.TotalFreedomMod.player.HeartBeat; import me.StevenLawson.TotalFreedomMod.player.HeartBeat;
import me.StevenLawson.TotalFreedomMod.player.PlayerList; import me.StevenLawson.TotalFreedomMod.player.PlayerList;
import me.StevenLawson.TotalFreedomMod.player.UUIDManager; import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.util.Utilities; import me.StevenLawson.TotalFreedomMod.util.Utilities;
import me.StevenLawson.TotalFreedomMod.world.AdminWorld; import me.StevenLawson.TotalFreedomMod.world.AdminWorld;
import me.StevenLawson.TotalFreedomMod.world.FlatlandsWorld; import me.StevenLawson.TotalFreedomMod.world.FlatlandsWorld;

View file

@ -2,6 +2,16 @@ package me.StevenLawson.TotalFreedomMod.admin;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import me.StevenLawson.TotalFreedomMod.Log; import me.StevenLawson.TotalFreedomMod.Log;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.commands.Command_logs; import me.StevenLawson.TotalFreedomMod.commands.Command_logs;
@ -10,8 +20,8 @@ import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
import me.StevenLawson.TotalFreedomMod.config.MainConfig; import me.StevenLawson.TotalFreedomMod.config.MainConfig;
import me.StevenLawson.TotalFreedomMod.deprecated.twitter.TwitterHandler; import me.StevenLawson.TotalFreedomMod.deprecated.twitter.TwitterHandler;
import me.StevenLawson.TotalFreedomMod.discord.sender.DiscordCommandSender; import me.StevenLawson.TotalFreedomMod.discord.sender.DiscordCommandSender;
import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.player.PlayerRank; import me.StevenLawson.TotalFreedomMod.player.PlayerRank;
import me.StevenLawson.TotalFreedomMod.player.UUIDManager;
import me.StevenLawson.TotalFreedomMod.util.Utilities; import me.StevenLawson.TotalFreedomMod.util.Utilities;
import me.StevenLawson.TotalFreedomMod.world.AdminWorld; import me.StevenLawson.TotalFreedomMod.world.AdminWorld;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -20,12 +30,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.*; public class AdminList {
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
public class AdminList
{
public static final Function<Player, Boolean> SUPERADMIN_SERVICE; public static final Function<Player, Boolean> SUPERADMIN_SERVICE;
private static final Map<UUID, Admin> adminList; private static final Map<UUID, Admin> adminList;
private static final Set<UUID> superUUIDs; private static final Set<UUID> superUUIDs;
@ -35,8 +41,7 @@ public class AdminList
private static final Set<String> superIps; private static final Set<String> superIps;
private static int cleanThreshold = 24 * 7; // 1 Week in hours private static int cleanThreshold = 24 * 7; // 1 Week in hours
static static {
{
adminList = new HashMap<UUID, Admin>(); adminList = new HashMap<UUID, Admin>();
superUUIDs = new HashSet<UUID>(); superUUIDs = new HashSet<UUID>();
telnetUUIDs = new HashSet<UUID>(); telnetUUIDs = new HashSet<UUID>();
@ -44,60 +49,48 @@ public class AdminList
seniorConsoleNames = new HashSet<String>(); seniorConsoleNames = new HashSet<String>();
superIps = new HashSet<String>(); superIps = new HashSet<String>();
SUPERADMIN_SERVICE = new Function<Player, Boolean>() SUPERADMIN_SERVICE = new Function<Player, Boolean>() {
{
@Override @Override
public Boolean apply(Player f) public Boolean apply(Player f) {
{
return isSuperAdmin(f); return isSuperAdmin(f);
} }
}; };
} }
private AdminList() private AdminList() {
{
throw new AssertionError(); throw new AssertionError();
} }
public static Set<UUID> getSuperUUIDs() public static Set<UUID> getSuperUUIDs() {
{
return Collections.unmodifiableSet(superUUIDs); return Collections.unmodifiableSet(superUUIDs);
} }
public static Set<UUID> getTelnetUUIDs() public static Set<UUID> getTelnetUUIDs() {
{
return Collections.unmodifiableSet(telnetUUIDs); return Collections.unmodifiableSet(telnetUUIDs);
} }
public static Set<UUID> getSeniorUUIDs() public static Set<UUID> getSeniorUUIDs() {
{
return Collections.unmodifiableSet(seniorUUIDs); return Collections.unmodifiableSet(seniorUUIDs);
} }
public static Set<String> getSeniorConsoleNames() public static Set<String> getSeniorConsoleNames() {
{
return Collections.unmodifiableSet(seniorConsoleNames); return Collections.unmodifiableSet(seniorConsoleNames);
} }
public static Set<String> getSuperadminIps() public static Set<String> getSuperadminIps() {
{
return Collections.unmodifiableSet(superIps); return Collections.unmodifiableSet(superIps);
} }
public static Set<Admin> getAllAdmins() public static Set<Admin> getAllAdmins() {
{
return Sets.newHashSet(adminList.values()); return Sets.newHashSet(adminList.values());
} }
public static Set<String> getSuperNames() public static Set<String> getSuperNames() {
{
final Set<String> names = new HashSet<String>(); final Set<String> names = new HashSet<String>();
for (Admin admin : adminList.values()) for (Admin admin : adminList.values()) {
{ if (!admin.isActivated()) {
if (!admin.isActivated())
{
continue; continue;
} }
@ -107,14 +100,11 @@ public class AdminList
return Collections.unmodifiableSet(names); return Collections.unmodifiableSet(names);
} }
public static Set<String> getLowercaseSuperNames() public static Set<String> getLowercaseSuperNames() {
{
final Set<String> names = new HashSet<String>(); final Set<String> names = new HashSet<String>();
for (Admin admin : adminList.values()) for (Admin admin : adminList.values()) {
{ if (!admin.isActivated()) {
if (!admin.isActivated())
{
continue; continue;
} }
@ -124,17 +114,16 @@ public class AdminList
return Collections.unmodifiableSet(names); return Collections.unmodifiableSet(names);
} }
public static void setUuid(Admin admin, UUID oldUuid, UUID newUuid) public static void setUuid(Admin admin, UUID oldUuid, UUID newUuid) {
{ if (!adminList.containsKey(oldUuid)) {
if (!adminList.containsKey(oldUuid)) Log.warning("Could not set new UUID for admin " + admin.getLastLoginName()
{ + ", admin is not loaded!");
Log.warning("Could not set new UUID for admin " + admin.getLastLoginName() + ", admin is not loaded!");
return; return;
} }
if (oldUuid.equals(newUuid)) if (oldUuid.equals(newUuid)) {
{ Log.warning(
Log.warning("could not set new UUID for admin " + admin.getLastLoginName() + ", UUIDs match."); "could not set new UUID for admin " + admin.getLastLoginName() + ", UUIDs match.");
return; return;
} }
@ -153,39 +142,36 @@ public class AdminList
// Remove old entry // Remove old entry
adminList.remove(oldUuid); adminList.remove(oldUuid);
final Configuration config = new Configuration(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true); final Configuration config = new Configuration(TotalFreedomMod.plugin,
TotalFreedomMod.SUPERADMIN_FILENAME, true);
config.load(); config.load();
config.set("admins." + oldUuid, null); config.set("admins." + oldUuid, null);
config.save(); config.save();
} }
public static void load() public static void load() {
{
adminList.clear(); adminList.clear();
final Configuration config = new Configuration(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true); final Configuration config = new Configuration(TotalFreedomMod.plugin,
TotalFreedomMod.SUPERADMIN_FILENAME, true);
config.load(); config.load();
cleanThreshold = config.getInt("clean_threshold_hours", cleanThreshold); cleanThreshold = config.getInt("clean_threshold_hours", cleanThreshold);
// Parse old superadmins // Parse old superadmins
if (config.isConfigurationSection("superadmins")) if (config.isConfigurationSection("superadmins")) {
{
parseOldConfig(config); parseOldConfig(config);
} }
if (!config.isConfigurationSection("admins")) if (!config.isConfigurationSection("admins")) {
{
Log.warning("Missing admins section in superadmin.yml."); Log.warning("Missing admins section in superadmin.yml.");
return; return;
} }
final ConfigurationSection section = config.getConfigurationSection("admins"); final ConfigurationSection section = config.getConfigurationSection("admins");
for (String uuidString : section.getKeys(false)) for (String uuidString : section.getKeys(false)) {
{ if (!Utilities.isUniqueId(uuidString)) {
if (!Utilities.isUniqueId(uuidString))
{
Log.warning("Invalid Unique ID: " + uuidString + " in superadmin.yml, ignoring"); Log.warning("Invalid Unique ID: " + uuidString + " in superadmin.yml, ignoring");
continue; continue;
} }
@ -198,21 +184,19 @@ public class AdminList
updateIndexLists(); updateIndexLists();
Log.info("Loaded " + adminList.size() + " admins (" + superUUIDs.size() + " active) and " + superIps.size() + " IPs."); Log.info("Loaded " + adminList.size() + " admins (" + superUUIDs.size() + " active) and "
+ superIps.size() + " IPs.");
} }
public static void updateIndexLists() public static void updateIndexLists() {
{
superUUIDs.clear(); superUUIDs.clear();
telnetUUIDs.clear(); telnetUUIDs.clear();
seniorUUIDs.clear(); seniorUUIDs.clear();
seniorConsoleNames.clear(); seniorConsoleNames.clear();
superIps.clear(); superIps.clear();
for (Admin admin : adminList.values()) for (Admin admin : adminList.values()) {
{ if (!admin.isActivated()) {
if (!admin.isActivated())
{
continue; continue;
} }
@ -220,23 +204,19 @@ public class AdminList
superUUIDs.add(uuid); superUUIDs.add(uuid);
for (String ip : admin.getIps()) for (String ip : admin.getIps()) {
{
superIps.add(ip); superIps.add(ip);
} }
if (admin.isTelnetAdmin()) if (admin.isTelnetAdmin()) {
{
telnetUUIDs.add(uuid); telnetUUIDs.add(uuid);
} }
if (admin.isSeniorAdmin()) if (admin.isSeniorAdmin()) {
{
seniorUUIDs.add(uuid); seniorUUIDs.add(uuid);
seniorConsoleNames.add(admin.getLastLoginName()); seniorConsoleNames.add(admin.getLastLoginName());
for (String alias : admin.getConsoleAliases()) for (String alias : admin.getConsoleAliases()) {
{
seniorConsoleNames.add(alias.toLowerCase()); seniorConsoleNames.add(alias.toLowerCase());
} }
} }
@ -245,8 +225,7 @@ public class AdminList
AdminWorld.getInstance().wipeAccessCache(); AdminWorld.getInstance().wipeAccessCache();
} }
private static void parseOldConfig(Configuration config) private static void parseOldConfig(Configuration config) {
{
Log.info("Old superadmin configuration found, parsing..."); Log.info("Old superadmin configuration found, parsing...");
final ConfigurationSection section = config.getConfigurationSection("superadmins"); final ConfigurationSection section = config.getConfigurationSection("superadmins");
@ -254,24 +233,27 @@ public class AdminList
int counter = 0; int counter = 0;
int errors = 0; int errors = 0;
for (String admin : config.getConfigurationSection("superadmins").getKeys(false)) for (String admin : config.getConfigurationSection("superadmins").getKeys(false)) {
{
final UUID uuid = UUIDManager.getUniqueId(admin); final UUID uuid = UUIDManager.getUniqueId(admin);
if (uuid == null) if (uuid == null) {
{
errors++; errors++;
Log.warning("Could not convert admin " + admin + ", UUID could not be found!"); Log.warning("Could not convert admin " + admin + ", UUID could not be found!");
continue; continue;
} }
config.set("admins." + uuid + ".last_login_name", uuid); config.set("admins." + uuid + ".last_login_name", uuid);
config.set("admins." + uuid + ".is_activated", section.getBoolean(admin + ".is_activated")); config.set("admins." + uuid + ".is_activated",
config.set("admins." + uuid + ".is_telnet_admin", section.getBoolean(admin + ".is_telnet_admin")); section.getBoolean(admin + ".is_activated"));
config.set("admins." + uuid + ".is_senior_admin", section.getBoolean(admin + ".is_senior_admin")); config.set("admins." + uuid + ".is_telnet_admin",
section.getBoolean(admin + ".is_telnet_admin"));
config.set("admins." + uuid + ".is_senior_admin",
section.getBoolean(admin + ".is_senior_admin"));
config.set("admins." + uuid + ".last_login", section.getString(admin + ".last_login")); config.set("admins." + uuid + ".last_login", section.getString(admin + ".last_login"));
config.set("admins." + uuid + ".custom_login_message", section.getString(admin + ".custom_login_message")); config.set("admins." + uuid + ".custom_login_message",
config.set("admins." + uuid + ".console_aliases", section.getStringList(admin + ".console_aliases")); section.getString(admin + ".custom_login_message"));
config.set("admins." + uuid + ".console_aliases",
section.getStringList(admin + ".console_aliases"));
config.set("admins." + uuid + ".ips", section.getStringList(admin + ".ips")); config.set("admins." + uuid + ".ips", section.getStringList(admin + ".ips"));
counter++; counter++;
@ -283,16 +265,15 @@ public class AdminList
Log.info("Done! " + counter + " admins parsed, " + errors + " errors"); Log.info("Done! " + counter + " admins parsed, " + errors + " errors");
} }
public static void saveAll() public static void saveAll() {
{ final Configuration config = new Configuration(TotalFreedomMod.plugin,
final Configuration config = new Configuration(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true); TotalFreedomMod.SUPERADMIN_FILENAME, true);
config.load(); config.load();
config.set("clean_threshold_hours", cleanThreshold); config.set("clean_threshold_hours", cleanThreshold);
final Iterator<Entry<UUID, Admin>> it = adminList.entrySet().iterator(); final Iterator<Entry<UUID, Admin>> it = adminList.entrySet().iterator();
while (it.hasNext()) while (it.hasNext()) {
{
final Entry<UUID, Admin> pair = it.next(); final Entry<UUID, Admin> pair = it.next();
final UUID uuid = pair.getKey(); final UUID uuid = pair.getKey();
@ -302,24 +283,27 @@ public class AdminList
config.set("admins." + uuid + ".is_activated", superadmin.isActivated()); config.set("admins." + uuid + ".is_activated", superadmin.isActivated());
config.set("admins." + uuid + ".is_telnet_admin", superadmin.isTelnetAdmin()); config.set("admins." + uuid + ".is_telnet_admin", superadmin.isTelnetAdmin());
config.set("admins." + uuid + ".is_senior_admin", superadmin.isSeniorAdmin()); config.set("admins." + uuid + ".is_senior_admin", superadmin.isSeniorAdmin());
config.set("admins." + uuid + ".last_login", Utilities.dateToString(superadmin.getLastLogin())); config.set("admins." + uuid + ".last_login",
config.set("admins." + uuid + ".custom_login_message", superadmin.getCustomLoginMessage()); Utilities.dateToString(superadmin.getLastLogin()));
config.set("admins." + uuid + ".console_aliases", Utilities.removeDuplicates(superadmin.getConsoleAliases())); config.set("admins." + uuid + ".custom_login_message",
superadmin.getCustomLoginMessage());
config.set("admins." + uuid + ".console_aliases",
Utilities.removeDuplicates(superadmin.getConsoleAliases()));
config.set("admins." + uuid + ".ips", Utilities.removeDuplicates(superadmin.getIps())); config.set("admins." + uuid + ".ips", Utilities.removeDuplicates(superadmin.getIps()));
} }
config.save(); config.save();
} }
public static void save(Admin admin) public static void save(Admin admin) {
{ if (!adminList.containsValue(admin)) {
if (!adminList.containsValue(admin)) Log.warning(
{ "Could not save admin " + admin.getLastLoginName() + ", admin is not loaded!");
Log.warning("Could not save admin " + admin.getLastLoginName() + ", admin is not loaded!");
return; return;
} }
final Configuration config = new Configuration(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILENAME, true); final Configuration config = new Configuration(TotalFreedomMod.plugin,
TotalFreedomMod.SUPERADMIN_FILENAME, true);
config.load(); config.load();
final UUID uuid = admin.getUniqueId(); final UUID uuid = admin.getUniqueId();
@ -330,62 +314,49 @@ public class AdminList
config.set("admins." + uuid + ".is_senior_admin", admin.isSeniorAdmin()); config.set("admins." + uuid + ".is_senior_admin", admin.isSeniorAdmin());
config.set("admins." + uuid + ".last_login", Utilities.dateToString(admin.getLastLogin())); config.set("admins." + uuid + ".last_login", Utilities.dateToString(admin.getLastLogin()));
config.set("admins." + uuid + ".custom_login_message", admin.getCustomLoginMessage()); config.set("admins." + uuid + ".custom_login_message", admin.getCustomLoginMessage());
config.set("admins." + uuid + ".console_aliases", Utilities.removeDuplicates(admin.getConsoleAliases())); config.set("admins." + uuid + ".console_aliases",
Utilities.removeDuplicates(admin.getConsoleAliases()));
config.set("admins." + uuid + ".ips", Utilities.removeDuplicates(admin.getIps())); config.set("admins." + uuid + ".ips", Utilities.removeDuplicates(admin.getIps()));
config.save(); config.save();
} }
public static Admin getEntry(Player player) public static Admin getEntry(Player player) {
{
return getEntry(UUIDManager.getUniqueId(player)); return getEntry(UUIDManager.getUniqueId(player));
} }
public static Admin getEntry(UUID uuid) public static Admin getEntry(UUID uuid) {
{
return adminList.get(uuid); return adminList.get(uuid);
} }
@Deprecated @Deprecated
public static Admin getEntry(String name) public static Admin getEntry(String name) {
{ for (UUID uuid : adminList.keySet()) {
for (UUID uuid : adminList.keySet()) if (adminList.get(uuid).getLastLoginName().equalsIgnoreCase(name)) {
{
if (adminList.get(uuid).getLastLoginName().equalsIgnoreCase(name))
{
return adminList.get(uuid); return adminList.get(uuid);
} }
} }
return null; return null;
} }
public static Admin getEntryByIp(String ip) public static Admin getEntryByIp(String ip) {
{
return getEntryByIp(ip, false); return getEntryByIp(ip, false);
} }
public static Admin getEntryByIp(String needleIp, boolean fuzzy) public static Admin getEntryByIp(String needleIp, boolean fuzzy) {
{
Iterator<Entry<UUID, Admin>> it = adminList.entrySet().iterator(); Iterator<Entry<UUID, Admin>> it = adminList.entrySet().iterator();
while (it.hasNext()) while (it.hasNext()) {
{
final Entry<UUID, Admin> pair = it.next(); final Entry<UUID, Admin> pair = it.next();
final Admin superadmin = pair.getValue(); final Admin superadmin = pair.getValue();
if (fuzzy) if (fuzzy) {
{ for (String haystackIp : superadmin.getIps()) {
for (String haystackIp : superadmin.getIps()) if (Utilities.fuzzyIpMatch(needleIp, haystackIp, 3)) {
{
if (Utilities.fuzzyIpMatch(needleIp, haystackIp, 3))
{
return superadmin; return superadmin;
} }
} }
} } else {
else if (superadmin.getIps().contains(needleIp)) {
{
if (superadmin.getIps().contains(needleIp))
{
return superadmin; return superadmin;
} }
} }
@ -393,11 +364,9 @@ public class AdminList
return null; return null;
} }
public static void updateLastLogin(Player player) public static void updateLastLogin(Player player) {
{
final Admin admin = getEntry(player); final Admin admin = getEntry(player);
if (admin == null) if (admin == null) {
{
return; return;
} }
admin.setLastLogin(new Date()); admin.setLastLogin(new Date());
@ -405,10 +374,8 @@ public class AdminList
saveAll(); saveAll();
} }
public static boolean isSuperAdminSafe(UUID uuid, String ip) public static boolean isSuperAdminSafe(UUID uuid, String ip) {
{ if (TotalFreedomMod.server.getOnlineMode() && uuid != null) {
if (TotalFreedomMod.server.getOnlineMode() && uuid != null)
{
return AdminList.getSuperUUIDs().contains(uuid); return AdminList.getSuperUUIDs().contains(uuid);
} }
@ -416,71 +383,58 @@ public class AdminList
return admin != null && admin.isActivated(); return admin != null && admin.isActivated();
} }
public static synchronized boolean isSuperAdminSync(CommandSender sender) public static synchronized boolean isSuperAdminSync(CommandSender sender) {
{
return isSuperAdmin(sender); return isSuperAdmin(sender);
} }
public static boolean isSuperAdmin(CommandSender sender) public static boolean isSuperAdmin(CommandSender sender) {
{ if (!(sender instanceof Player)) {
if (!(sender instanceof Player))
{
return true; return true;
} }
final Player player = (Player) sender; final Player player = (Player) sender;
if (superIps.contains(Utilities.getIp(player))) if (superIps.contains(Utilities.getIp(player))) {
{
return true; return true;
} }
return Bukkit.getOnlineMode() && superUUIDs.contains(UUIDManager.getUniqueId(player)); return Bukkit.getOnlineMode() && superUUIDs.contains(UUIDManager.getUniqueId(player));
} }
public static boolean isTelnetAdmin(CommandSender sender, boolean verifySuperadmin) public static boolean isTelnetAdmin(CommandSender sender, boolean verifySuperadmin) {
{ if (verifySuperadmin) {
if (verifySuperadmin) if (!isSuperAdmin(sender)) {
{
if (!isSuperAdmin(sender))
{
return false; return false;
} }
} }
if (!(sender instanceof Player)) if (!(sender instanceof Player)) {
{
return true; return true;
} }
final Admin entry = getEntry((Player) sender); final Admin entry = getEntry((Player) sender);
if (entry != null) if (entry != null) {
{
return entry.isTelnetAdmin(); return entry.isTelnetAdmin();
} }
return false; return false;
} }
public static boolean isSeniorAdmin(CommandSender sender) public static boolean isSeniorAdmin(CommandSender sender) {
{
return isSeniorAdmin(sender, false); return isSeniorAdmin(sender, false);
} }
public static boolean isSeniorAdmin(CommandSender sender, boolean verifySuperadmin) public static boolean isSeniorAdmin(CommandSender sender, boolean verifySuperadmin) {
{ if (verifySuperadmin) {
if (verifySuperadmin) if (!isSuperAdmin(sender)) {
{
if (!isSuperAdmin(sender))
{
return false; return false;
} }
} }
if (!(sender instanceof Player)) if (!(sender instanceof Player)) {
{
return seniorConsoleNames.contains(sender.getName()) return seniorConsoleNames.contains(sender.getName())
|| (MainConfig.getBoolean(ConfigurationEntry.CONSOLE_IS_SENIOR) && sender.getName().equals("CONSOLE")); || (MainConfig.getBoolean(ConfigurationEntry.CONSOLE_IS_SENIOR) && sender.getName()
.equals("CONSOLE"));
} }
if (sender instanceof DiscordCommandSender) { if (sender instanceof DiscordCommandSender) {
@ -492,29 +446,24 @@ public class AdminList
} }
final Admin entry = getEntry((Player) sender); final Admin entry = getEntry((Player) sender);
if (entry != null) if (entry != null) {
{
return entry.isSeniorAdmin(); return entry.isSeniorAdmin();
} }
return false; return false;
} }
public static boolean isIdentityMatched(Player player) public static boolean isIdentityMatched(Player player) {
{ if (!isSuperAdmin(player)) {
if (!isSuperAdmin(player))
{
return false; return false;
} }
if (Bukkit.getOnlineMode()) if (Bukkit.getOnlineMode()) {
{
return true; return true;
} }
final Admin entry = getEntry(player); final Admin entry = getEntry(player);
if (entry == null) if (entry == null) {
{
return false; return false;
} }
@ -522,40 +471,31 @@ public class AdminList
} }
@Deprecated @Deprecated
public static boolean checkPartialSuperadminIp(String ip, String name) public static boolean checkPartialSuperadminIp(String ip, String name) {
{
ip = ip.trim(); ip = ip.trim();
if (superIps.contains(ip)) if (superIps.contains(ip)) {
{
return true; return true;
} }
try try {
{
String matchIp = null; String matchIp = null;
for (String testIp : superIps) for (String testIp : superIps) {
{ if (Utilities.fuzzyIpMatch(ip, testIp, 3)) {
if (Utilities.fuzzyIpMatch(ip, testIp, 3))
{
matchIp = testIp; matchIp = testIp;
break; break;
} }
} }
if (matchIp != null) if (matchIp != null) {
{
final Admin entry = getEntryByIp(matchIp); final Admin entry = getEntryByIp(matchIp);
if (entry == null) if (entry == null) {
{
return true; return true;
} }
if (entry.getLastLoginName().equalsIgnoreCase(name)) if (entry.getLastLoginName().equalsIgnoreCase(name)) {
{ if (!entry.getIps().contains(ip)) {
if (!entry.getIps().contains(ip))
{
entry.addIp(ip); entry.addIp(ip);
} }
saveAll(); saveAll();
@ -563,42 +503,34 @@ public class AdminList
return true; return true;
} }
} } catch (Exception ex) {
catch (Exception ex)
{
Log.severe(ex); Log.severe(ex);
} }
return false; return false;
} }
public static boolean isAdminImpostor(Player player) public static boolean isAdminImpostor(Player player) {
{ if (superUUIDs.contains(UUIDManager.getUniqueId(player))) {
if (superUUIDs.contains(UUIDManager.getUniqueId(player)))
{
return !isSuperAdmin(player); return !isSuperAdmin(player);
} }
return false; return false;
} }
public static void addSuperadmin(OfflinePlayer player) public static void addSuperadmin(OfflinePlayer player) {
{
final UUID uuid = UUIDManager.getUniqueId(player); final UUID uuid = UUIDManager.getUniqueId(player);
final String ip = Utilities.getIp(player); final String ip = Utilities.getIp(player);
final boolean canSuperIp = !MainConfig.getList(ConfigurationEntry.NOADMIN_IPS).contains(ip); final boolean canSuperIp = !MainConfig.getList(ConfigurationEntry.NOADMIN_IPS).contains(ip);
if (adminList.containsKey(uuid)) if (adminList.containsKey(uuid)) {
{
final Admin superadmin = adminList.get(uuid); final Admin superadmin = adminList.get(uuid);
superadmin.setActivated(true); superadmin.setActivated(true);
if (player.isOnline()) if (player.isOnline()) {
{
superadmin.setLastLogin(new Date()); superadmin.setLastLogin(new Date());
if (ip != null && canSuperIp) if (ip != null && canSuperIp) {
{
superadmin.addIp(ip); superadmin.addIp(ip);
} }
} }
@ -608,15 +540,13 @@ public class AdminList
return; return;
} }
if (ip == null) if (ip == null) {
{
Log.severe("Could not add superadmin: " + Utilities.formatPlayer(player)); Log.severe("Could not add superadmin: " + Utilities.formatPlayer(player));
Log.severe("Could not retrieve IP!"); Log.severe("Could not retrieve IP!");
return; return;
} }
if (!canSuperIp) if (!canSuperIp) {
{
Log.warning("Could not add superadmin: " + Utilities.formatPlayer(player)); Log.warning("Could not add superadmin: " + Utilities.formatPlayer(player));
Log.warning("IP " + ip + " may not be supered."); Log.warning("IP " + ip + " may not be supered.");
return; return;
@ -638,12 +568,10 @@ public class AdminList
updateIndexLists(); updateIndexLists();
} }
public static void removeSuperadmin(OfflinePlayer player) public static void removeSuperadmin(OfflinePlayer player) {
{
final UUID uuid = UUIDManager.getUniqueId(player); final UUID uuid = UUIDManager.getUniqueId(player);
if (!adminList.containsKey(uuid)) if (!adminList.containsKey(uuid)) {
{
Log.warning("Could not remove admin: " + Utilities.formatPlayer(player)); Log.warning("Could not remove admin: " + Utilities.formatPlayer(player));
Log.warning("Player is not an admin!"); Log.warning("Player is not an admin!");
return; return;
@ -657,27 +585,25 @@ public class AdminList
updateIndexLists(); updateIndexLists();
} }
public static void cleanSuperadminList(boolean verbose) public static void cleanSuperadminList(boolean verbose) {
{
Iterator<Entry<UUID, Admin>> it = adminList.entrySet().iterator(); Iterator<Entry<UUID, Admin>> it = adminList.entrySet().iterator();
while (it.hasNext()) while (it.hasNext()) {
{
final Entry<UUID, Admin> pair = it.next(); final Entry<UUID, Admin> pair = it.next();
final Admin superadmin = pair.getValue(); final Admin superadmin = pair.getValue();
if (!superadmin.isActivated() || superadmin.isSeniorAdmin()) if (!superadmin.isActivated() || superadmin.isSeniorAdmin()) {
{
continue; continue;
} }
final Date lastLogin = superadmin.getLastLogin(); final Date lastLogin = superadmin.getLastLogin();
final long lastLoginHours = TimeUnit.HOURS.convert(new Date().getTime() - lastLogin.getTime(), TimeUnit.MILLISECONDS); final long lastLoginHours = TimeUnit.HOURS.convert(
new Date().getTime() - lastLogin.getTime(), TimeUnit.MILLISECONDS);
if (lastLoginHours > cleanThreshold) if (lastLoginHours > cleanThreshold) {
{ if (verbose) {
if (verbose) Utilities.adminAction("TotalFreedomMod",
{ "Deactivating superadmin " + superadmin.getLastLoginName()
Utilities.adminAction("TotalFreedomMod", "Deactivating superadmin " + superadmin.getLastLoginName() + ", inactive for " + lastLoginHours + " hours.", true); + ", inactive for " + lastLoginHours + " hours.", true);
} }
superadmin.setActivated(false); superadmin.setActivated(false);

View file

@ -5,8 +5,8 @@ import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.ban.Ban.BanType; import me.StevenLawson.TotalFreedomMod.ban.Ban.BanType;
import me.StevenLawson.TotalFreedomMod.config.Configuration; import me.StevenLawson.TotalFreedomMod.config.Configuration;
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry; import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
import me.StevenLawson.TotalFreedomMod.player.UUIDManager; import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.player.UUIDManager.TFM_UuidResolver; import me.StevenLawson.TotalFreedomMod.manager.UUIDManager.TFM_UuidResolver;
import me.StevenLawson.TotalFreedomMod.util.Utilities; import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View file

@ -2,7 +2,7 @@ package me.StevenLawson.TotalFreedomMod.commands;
import me.StevenLawson.TotalFreedomMod.ban.BanManager; import me.StevenLawson.TotalFreedomMod.ban.BanManager;
import me.StevenLawson.TotalFreedomMod.player.PlayerData; import me.StevenLawson.TotalFreedomMod.player.PlayerData;
import me.StevenLawson.TotalFreedomMod.player.UUIDManager; import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.util.Utilities; import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;

View file

@ -6,7 +6,7 @@ import me.StevenLawson.TotalFreedomMod.ban.BanManager;
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry; import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
import me.StevenLawson.TotalFreedomMod.player.Player; import me.StevenLawson.TotalFreedomMod.player.Player;
import me.StevenLawson.TotalFreedomMod.player.PlayerList; import me.StevenLawson.TotalFreedomMod.player.PlayerList;
import me.StevenLawson.TotalFreedomMod.player.UUIDManager; import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.util.Utilities; import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;

View file

@ -3,7 +3,7 @@ package me.StevenLawson.TotalFreedomMod.commands;
import me.StevenLawson.TotalFreedomMod.ban.Ban; import me.StevenLawson.TotalFreedomMod.ban.Ban;
import me.StevenLawson.TotalFreedomMod.ban.BanManager; import me.StevenLawson.TotalFreedomMod.ban.BanManager;
import me.StevenLawson.TotalFreedomMod.bridge.WorldEditBridge; import me.StevenLawson.TotalFreedomMod.bridge.WorldEditBridge;
import me.StevenLawson.TotalFreedomMod.player.UUIDManager; import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.util.Utilities; import me.StevenLawson.TotalFreedomMod.util.Utilities;
import me.StevenLawson.TotalFreedomMod.world.RollbackManager; import me.StevenLawson.TotalFreedomMod.world.RollbackManager;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;

View file

@ -14,6 +14,7 @@ public class Command_myadmin extends FreedomCommand {
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel,
String[] args, boolean senderIsConsole) { String[] args, boolean senderIsConsole) {
final UUID uuid = sender_p.getUniqueId(); // Get the sender's uuid as a variable. final UUID uuid = sender_p.getUniqueId(); // Get the sender's uuid as a variable.
if (args.length == 1) { if (args.length == 1) {

View file

@ -2,7 +2,7 @@ package me.StevenLawson.TotalFreedomMod.commands;
import me.StevenLawson.TotalFreedomMod.ban.Ban; import me.StevenLawson.TotalFreedomMod.ban.Ban;
import me.StevenLawson.TotalFreedomMod.ban.BanManager; import me.StevenLawson.TotalFreedomMod.ban.BanManager;
import me.StevenLawson.TotalFreedomMod.player.UUIDManager; import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.util.Utilities; import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;

View file

@ -2,7 +2,7 @@ package me.StevenLawson.TotalFreedomMod.commands;
import me.StevenLawson.TotalFreedomMod.ban.Ban; import me.StevenLawson.TotalFreedomMod.ban.Ban;
import me.StevenLawson.TotalFreedomMod.ban.BanManager; import me.StevenLawson.TotalFreedomMod.ban.BanManager;
import me.StevenLawson.TotalFreedomMod.player.UUIDManager; import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.util.Utilities; import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;

View file

@ -3,6 +3,7 @@ package me.StevenLawson.TotalFreedomMod.commands;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class Commands { public class Commands {
public static void registerCommands(JavaPlugin plugin) { public static void registerCommands(JavaPlugin plugin) {
plugin.getCommand("adminmode").setExecutor(new Command_adminmode()); plugin.getCommand("adminmode").setExecutor(new Command_adminmode());
plugin.getCommand("adminworld").setExecutor(new Command_adminworld()); plugin.getCommand("adminworld").setExecutor(new Command_adminworld());
@ -108,5 +109,6 @@ public class Commands {
plugin.getCommand("wipeuserdata").setExecutor(new Command_wipeuserdata()); plugin.getCommand("wipeuserdata").setExecutor(new Command_wipeuserdata());
plugin.getCommand("whoami").setExecutor(new Command_whoami()); plugin.getCommand("whoami").setExecutor(new Command_whoami());
plugin.getCommand("resetplayer").setExecutor(new Command_resetplayer()); plugin.getCommand("resetplayer").setExecutor(new Command_resetplayer());
plugin.getCommand("vanish").setExecutor(new Command_vanish());
} }
} }

View file

@ -1,11 +1,15 @@
package me.StevenLawson.TotalFreedomMod.discord.bridge; package me.StevenLawson.TotalFreedomMod.discord.bridge;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.Log; import me.StevenLawson.TotalFreedomMod.Log;
import me.StevenLawson.TotalFreedomMod.admin.AdminList; import me.StevenLawson.TotalFreedomMod.admin.AdminList;
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry; import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
import me.StevenLawson.TotalFreedomMod.config.MainConfig; import me.StevenLawson.TotalFreedomMod.config.MainConfig;
import me.StevenLawson.TotalFreedomMod.discord.command.DiscordCommandManager; import me.StevenLawson.TotalFreedomMod.discord.command.DiscordCommandManager;
import me.StevenLawson.TotalFreedomMod.player.PlayerRank; import me.StevenLawson.TotalFreedomMod.util.Utilities;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
@ -21,14 +25,9 @@ import org.javacord.api.entity.message.MessageAuthor;
import org.javacord.api.entity.server.Server; import org.javacord.api.entity.server.Server;
import org.javacord.api.entity.user.User; import org.javacord.api.entity.user.User;
import org.javacord.api.event.message.MessageCreateEvent; import org.javacord.api.event.message.MessageCreateEvent;
import org.javacord.api.event.message.MessageEvent;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
public class DiscordBridge { public class DiscordBridge {
private static DiscordApi DISCORD_API; private static DiscordApi DISCORD_API;
private static TextChannel CHANNEL; private static TextChannel CHANNEL;
private static TextChannel ADMIN_CHANNEL; private static TextChannel ADMIN_CHANNEL;
@ -38,14 +37,18 @@ public class DiscordBridge {
boolean isAdmin = false; boolean isAdmin = false;
try { try {
isAdmin = message.getChannel().getIdAsString().equalsIgnoreCase(ADMIN_CHANNEL.getIdAsString()); isAdmin = message.getChannel().getIdAsString()
} catch (Exception ignored) {} .equalsIgnoreCase(ADMIN_CHANNEL.getIdAsString());
} catch (Exception ignored) {
}
String content = message.getMessage().getReadableContent(); String content = message.getMessage().getReadableContent();
String prefix = MainConfig.getString(ConfigurationEntry.DISCORD_PREFIX); String prefix = MainConfig.getString(ConfigurationEntry.DISCORD_PREFIX);
MessageAuthor author = message.getMessage().getAuthor(); MessageAuthor author = message.getMessage().getAuthor();
if (author.isBotUser() || !message.isServerMessage()) return; if (author.isBotUser() || !message.isServerMessage()) {
return;
}
Optional<Server> server = message.getServer(); Optional<Server> server = message.getServer();
Optional<User> user = author.asUser(); Optional<User> user = author.asUser();
@ -56,12 +59,14 @@ public class DiscordBridge {
} }
if (!server.isPresent()) { if (!server.isPresent()) {
Log.warning("Discord server wasn't present in message, this may be a sign you've not properly configured the intents for your bot."); Log.warning(
"Discord server wasn't present in message, this may be a sign you've not properly configured the intents for your bot.");
return; return;
} }
if (!user.isPresent()) { if (!user.isPresent()) {
Log.warning("Unable to get user of message author. This may be a sign you've not properly configured the intents for your bot."); Log.warning(
"Unable to get user of message author. This may be a sign you've not properly configured the intents for your bot.");
return; return;
} }
@ -73,25 +78,29 @@ public class DiscordBridge {
String reply = ""; String reply = "";
if (referenced.isPresent()) { if (referenced.isPresent()) {
Message replyingTo = referenced.get(); Message replyingTo = referenced.get();
reply = String.format(ChatColor.GRAY + "" + ChatColor.YELLOW + "%s" + ChatColor.GRAY + " %s\n" + ChatColor.WHITE, replyingTo.getAuthor().getDiscriminatedName(), replyingTo.getReadableContent()); reply = String.format(
ChatColor.GRAY + "" + ChatColor.YELLOW + "%s" + ChatColor.GRAY + " %s\n"
+ ChatColor.WHITE, replyingTo.getAuthor().getDiscriminatedName(),
replyingTo.getReadableContent());
} }
String format = MainConfig.getString((isAdmin) ? ConfigurationEntry.DISCORD_ADMIN_FORMAT : ConfigurationEntry.DISCORD_FORMAT); String format = MainConfig.getString(
(isAdmin) ? ConfigurationEntry.DISCORD_ADMIN_FORMAT : ConfigurationEntry.DISCORD_FORMAT);
format = format.replace("{TAG}", author.getDiscriminatedName()); format = format.replace("{TAG}", author.getDiscriminatedName());
format = format.replace("{USERNAME}", author.getName()); format = format.replace("{USERNAME}", author.getName());
BaseComponent[] components = TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', String.format(format, content))); BaseComponent[] components = TextComponent.fromLegacyText(
ChatColor.translateAlternateColorCodes('&', String.format(format, content)));
TextComponent component = new TextComponent(reply); TextComponent component = new TextComponent(reply);
for (BaseComponent baseComponent : components) { component.addExtra(Utilities.fromBaseComponents(components));
component.addExtra(baseComponent);
}
if (message.getMessageAttachments().size() > 0) { if (message.getMessageAttachments().size() > 0) {
int i = 0; int i = 0;
for (MessageAttachment messageAttachment : message.getMessageAttachments()) { for (MessageAttachment messageAttachment : message.getMessageAttachments()) {
String url = messageAttachment.getProxyUrl().toString(); String url = messageAttachment.getProxyUrl().toString();
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, url); ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, url);
TextComponent warningComponent = new TextComponent("WARNING: By clicking on this text, your client will open:\n\n"); TextComponent warningComponent = new TextComponent(
"WARNING: By clicking on this text, your client will open:\n\n");
warningComponent.setColor(net.md_5.bungee.api.ChatColor.RED); warningComponent.setColor(net.md_5.bungee.api.ChatColor.RED);
warningComponent.setBold(true); warningComponent.setBold(true);
TextComponent urlComponent = new TextComponent(url); TextComponent urlComponent = new TextComponent(url);
@ -99,8 +108,10 @@ public class DiscordBridge {
urlComponent.setUnderlined(true); urlComponent.setUnderlined(true);
urlComponent.setBold(false); urlComponent.setBold(false);
warningComponent.addExtra(urlComponent); warningComponent.addExtra(urlComponent);
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[]{warningComponent}); HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT,
TextComponent mediaComponent = new TextComponent((i == 0 && content.isEmpty()) ? "[Media]" : " [Media]"); new BaseComponent[]{warningComponent});
TextComponent mediaComponent = new TextComponent(
(i == 0 && content.isEmpty()) ? "[Media]" : " [Media]");
mediaComponent.setColor(net.md_5.bungee.api.ChatColor.YELLOW); mediaComponent.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
mediaComponent.setClickEvent(clickEvent); mediaComponent.setClickEvent(clickEvent);
mediaComponent.setHoverEvent(hoverEvent); mediaComponent.setHoverEvent(hoverEvent);
@ -110,10 +121,8 @@ public class DiscordBridge {
} }
if (isAdmin) { if (isAdmin) {
for (org.bukkit.entity.Player player : Bukkit.getOnlinePlayers()) for (org.bukkit.entity.Player player : Bukkit.getOnlinePlayers()) {
{ if (AdminList.isSuperAdmin(player)) {
if (AdminList.isSuperAdmin(player))
{
player.spigot().sendMessage(component); player.spigot().sendMessage(component);
} }
} }
@ -136,8 +145,10 @@ public class DiscordBridge {
.login() .login()
.join(); .join();
Optional<TextChannel> channelFuture = DISCORD_API.getTextChannelById(MainConfig.getString(ConfigurationEntry.DISCORD_CHANNEL)); Optional<TextChannel> channelFuture = DISCORD_API.getTextChannelById(
Optional<TextChannel> adminChannelFuture = DISCORD_API.getTextChannelById(MainConfig.getString(ConfigurationEntry.DISCORD_ADMIN_CHANNEL)); MainConfig.getString(ConfigurationEntry.DISCORD_CHANNEL));
Optional<TextChannel> adminChannelFuture = DISCORD_API.getTextChannelById(
MainConfig.getString(ConfigurationEntry.DISCORD_ADMIN_CHANNEL));
if (!channelFuture.isPresent()) { if (!channelFuture.isPresent()) {
Log.warning("TFM 4.3 Reloaded could not find your channel, stopping!"); Log.warning("TFM 4.3 Reloaded could not find your channel, stopping!");
@ -155,9 +166,11 @@ public class DiscordBridge {
ADMIN_CHANNEL.addMessageCreateListener(DiscordBridge::onMessageCreateEvent); ADMIN_CHANNEL.addMessageCreateListener(DiscordBridge::onMessageCreateEvent);
} }
} catch (Exception e) { } catch (Exception e) {
Log.warning("Uh oh! It looks like TFM 4.3 Reloaded Discord couldn't start! Please check you have defined the bot's token & channel and also given it the correct permissions! (Read Messages and Send Messages)"); Log.warning(
"Uh oh! It looks like TFM 4.3 Reloaded Discord couldn't start! Please check you have defined the bot's token & channel and also given it the correct permissions! (Read Messages and Send Messages)");
Log.warning("If you've already set that up however, you may to read the exception below."); Log.warning("If you've already set that up however, you may to read the exception below.");
Log.warning("If this is a bug with TFM 4.3 Reloaded, please report it at https://github.com/TheDeus-Group/TFM-4.3-Reloaded/issues or https://code.cat.casa/TheDeus-Group/TFM-4.3-Reloaded/issues"); Log.warning(
"If this is a bug with TFM 4.3 Reloaded, please report it at https://github.com/TheDeus-Group/TFM-4.3-Reloaded/issues or https://code.cat.casa/TheDeus-Group/TFM-4.3-Reloaded/issues");
e.printStackTrace(); e.printStackTrace();
return; return;
} }
@ -183,7 +196,9 @@ public class DiscordBridge {
} }
public static void transmitMessage(String message, boolean disconnectAfterwards) { public static void transmitMessage(String message, boolean disconnectAfterwards) {
if (CHANNEL == null) return; if (CHANNEL == null) {
return;
}
if (!disconnectAfterwards) { if (!disconnectAfterwards) {
CHANNEL.sendMessage(sanitizeMessage(message)); CHANNEL.sendMessage(sanitizeMessage(message));
} else { } else {
@ -211,7 +226,9 @@ public class DiscordBridge {
} }
public static void transmitAdminMessage(String message, boolean disconnectAfterwards) { public static void transmitAdminMessage(String message, boolean disconnectAfterwards) {
if (ADMIN_CHANNEL == null) return; if (ADMIN_CHANNEL == null) {
return;
}
if (!disconnectAfterwards) { if (!disconnectAfterwards) {
ADMIN_CHANNEL.sendMessage(sanitizeMessage(message)); ADMIN_CHANNEL.sendMessage(sanitizeMessage(message));
} else { } else {
@ -234,8 +251,7 @@ public class DiscordBridge {
Log.info("TFM 4.3 Reloaded Discord stopped."); Log.info("TFM 4.3 Reloaded Discord stopped.");
} }
public static String fullySanitizeDiscordMessage(String message) public static String fullySanitizeDiscordMessage(String message) {
{
String partiallySanitized = sanitizeMessage(message); String partiallySanitized = sanitizeMessage(message);
return partiallySanitized.replaceAll("([`_~*|\\\\])", "\\\\$1"); return partiallySanitized.replaceAll("([`_~*|\\\\])", "\\\\$1");
} }

View file

@ -80,7 +80,9 @@ public class PlayerListener implements Listener {
"I love FreedomForever!", "I'm here to collect my cupcake.", "Do you have any cupcakes?", "I love FreedomForever!", "I'm here to collect my cupcake.", "Do you have any cupcakes?",
"I like pineapple pizza.", "Do you have any pineapple pizza?", "I like pineapple pizza.", "Do you have any pineapple pizza?",
"I dislike Cherry Pepsi Max.", "I dislike Cherry Pepsi Max.",
"Guys, did you know my father is getting milk? He hasn't been back for hours, I'm worried..."); "Guys, did you know my father is getting milk? He hasn't been back for hours, I'm worried...",
"My wife's boyfriend is a nice guy.", "My wife's boyfriend got me a new Switch!",
"My wife's boyfriend got me a new PS5!");
public static final int MSG_PER_HEARTBEAT = 10; public static final int MSG_PER_HEARTBEAT = 10;
public static final int DEFAULT_PORT = 25565; public static final int DEFAULT_PORT = 25565;
public static final int MAX_XY_COORD = 30000000; public static final int MAX_XY_COORD = 30000000;

View file

@ -1,10 +1,9 @@
package me.StevenLawson.TotalFreedomMod.player; package me.StevenLawson.TotalFreedomMod.player;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
import me.StevenLawson.TotalFreedomMod.bridge.EssentialsBridge; import me.StevenLawson.TotalFreedomMod.bridge.EssentialsBridge;
import me.StevenLawson.TotalFreedomMod.commands.AdminLevel;
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry; import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.util.Utilities; import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;

View file

@ -4,6 +4,7 @@ import com.google.common.collect.Sets;
import me.StevenLawson.TotalFreedomMod.Log; import me.StevenLawson.TotalFreedomMod.Log;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.config.Configuration; import me.StevenLawson.TotalFreedomMod.config.Configuration;
import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
import me.StevenLawson.TotalFreedomMod.util.Utilities; import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;