From 7a810519f30e86e1c47afc5ea55eccc19eef2149 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Sat, 15 Aug 2020 17:44:50 -0500 Subject: [PATCH] fuck intellij --- .../totalfreedommod/admin/AdminList.java | 370 ------------------ .../totalfreedommod/command/Command_list.java | 12 - .../command/Command_vanish.java | 112 +++++- .../totalfreedommod/staff/StaffList.java | 5 +- 4 files changed, 95 insertions(+), 404 deletions(-) delete mode 100644 src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java deleted file mode 100644 index 2b4d6c61..00000000 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java +++ /dev/null @@ -1,370 +0,0 @@ -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; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import lombok.Getter; -import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.config.ConfigEntry; -import me.totalfreedom.totalfreedommod.rank.Rank; -import me.totalfreedom.totalfreedommod.util.FLog; -import me.totalfreedom.totalfreedommod.util.FUtil; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class AdminList extends FreedomService -{ - @Getter - private final Set allAdmins = Sets.newHashSet(); // Includes disabled admins - // Only active admins below - @Getter - private final Set activeAdmins = Sets.newHashSet(); - private final Map nameTable = Maps.newHashMap(); - private final Map ipTable = Maps.newHashMap(); - public final List verifiedNoAdmins = new ArrayList<>(); - public final Map> verifiedNoAdminIps = Maps.newHashMap(); - - @Override - public void onStart() - { - load(); - deactivateOldEntries(false); - } - - @Override - public void onStop() - { - } - - public void load() - { - allAdmins.clear(); - try - { - ResultSet adminSet = plugin.sql.getAdminList(); - { - while (adminSet.next()) - { - Admin admin = new Admin(adminSet); - allAdmins.add(admin); - } - } - } - catch (SQLException e) - { - FLog.severe("Failed to load adminlist: " + e.getMessage()); - } - - updateTables(); - FLog.info("Loaded " + allAdmins.size() + " admins (" + nameTable.size() + " active, " + ipTable.size() + " IPs)"); - } - - public void messageAllAdmins(String message) - { - for (Player player : server.getOnlinePlayers()) - { - if (isAdmin(player)) - { - player.sendMessage(message); - } - } - } - - public synchronized boolean isAdminSync(CommandSender sender) - { - return isAdmin(sender); - } - - public List getActiveAdminNames() - { - List names = new ArrayList(); - for (Admin admin : activeAdmins) - { - names.add(admin.getName()); - } - return names; - } - - public boolean isAdmin(CommandSender sender) - { - if (!(sender instanceof Player)) - { - return true; - } - - Admin admin = getAdmin((Player)sender); - - return admin != null && admin.isActive(); - } - - public boolean isTelnetAdmin(CommandSender sender) - { - Admin admin = getAdmin(sender); - if (admin == null) - { - return false; - } - - return admin.getRank().ordinal() >= Rank.TELNET_ADMIN.ordinal(); - } - - public boolean isSeniorAdmin(CommandSender sender) - { - Admin admin = getAdmin(sender); - if (admin == null) - { - return false; - } - - return admin.getRank().ordinal() >= Rank.SENIOR_ADMIN.ordinal(); - } - - public Admin getAdmin(CommandSender sender) - { - if (sender instanceof Player) - { - return getAdmin((Player)sender); - } - - return getEntryByName(sender.getName()); - } - - public Admin getAdmin(Player player) - { - // Find admin - String ip = FUtil.getIp(player); - Admin admin = getEntryByName(player.getName()); - - // Admin by name - if (admin != null) - { - // Check if we're in online mode, - // Or the players IP is in the admin entry - if (Bukkit.getOnlineMode() || admin.getIps().contains(ip)) - { - if (!admin.getIps().contains(ip)) - { - // Add the new IP if we have to - admin.addIp(ip); - save(admin); - updateTables(); - } - return admin; - } - } - - // Admin by ip - admin = getEntryByIp(ip); - if (admin != null) - { - // Set the new username - String oldName = admin.getName(); - admin.setName(player.getName()); - plugin.sql.updateAdminName(oldName, admin.getName()); - updateTables(); - } - - return null; - } - - public Admin getEntryByName(String name) - { - return nameTable.get(name.toLowerCase()); - } - - public Admin getEntryByIp(String ip) - { - return ipTable.get(ip); - } - - public Admin getEntryByIpFuzzy(String needleIp) - { - final Admin directAdmin = getEntryByIp(needleIp); - if (directAdmin != null) - { - return directAdmin; - } - - for (String ip : ipTable.keySet()) - { - if (FUtil.fuzzyIpMatch(needleIp, ip, 3)) - { - return ipTable.get(ip); - } - } - - return null; - } - - public void updateLastLogin(Player player) - { - final Admin admin = getAdmin(player); - if (admin == null) - { - return; - } - - admin.setLastLogin(new Date()); - admin.setName(player.getName()); - save(admin); - } - - public boolean isAdminImpostor(Player player) - { - return getEntryByName(player.getName()) != null && !isAdmin(player) && !isVerifiedAdmin(player); - } - - public boolean isVerifiedAdmin(Player player) - { - return verifiedNoAdmins.contains(player.getName()) && verifiedNoAdminIps.get(player.getName()).contains(FUtil.getIp(player)); - } - - public boolean isIdentityMatched(Player player) - { - if (Bukkit.getOnlineMode()) - { - return true; - } - - Admin admin = getAdmin(player); - return admin == null ? false : admin.getName().equalsIgnoreCase(player.getName()); - } - - public boolean addAdmin(Admin admin) - { - if (!admin.isValid()) - { - logger.warning("Could not add admin: " + admin.getName() + " Admin is missing details!"); - return false; - } - - // Store admin, update views - allAdmins.add(admin); - updateTables(); - - // Save admin - plugin.sql.addAdmin(admin); - - return true; - } - - public boolean removeAdmin(Admin admin) - { - if (admin.getRank().isAtLeast(Rank.TELNET_ADMIN)) - { - if (plugin.btb != null) - { - plugin.btb.killTelnetSessions(admin.getName()); - } - } - - // Remove admin, update views - if (!allAdmins.remove(admin)) - { - return false; - } - updateTables(); - - // Unsave admin - plugin.sql.removeAdmin(admin); - - return true; - } - - public void updateTables() - { - activeAdmins.clear(); - nameTable.clear(); - ipTable.clear(); - - for (Admin admin : allAdmins) - { - if (!admin.isActive()) - { - continue; - } - - activeAdmins.add(admin); - nameTable.put(admin.getName().toLowerCase(), admin); - - for (String ip : admin.getIps()) - { - ipTable.put(ip, admin); - } - - } - } - - public Set getAdminNames() - { - return nameTable.keySet(); - } - - public Set getAdminIps() - { - return ipTable.keySet(); - } - - public void save(Admin admin) - { - try - { - ResultSet currentSave = plugin.sql.getAdminByName(admin.getName()); - for (Map.Entry entry : admin.toSQLStorable().entrySet()) - { - Object storedValue = plugin.sql.getValue(currentSave, entry.getKey(), entry.getValue()); - if (storedValue != null && !storedValue.equals(entry.getValue()) || storedValue == null && entry.getValue() != null || entry.getValue() == null) - { - plugin.sql.setAdminValue(admin, entry.getKey(), entry.getValue()); - } - } - } - catch (SQLException e) - { - FLog.severe("Failed to save admin: " + e.getMessage()); - } - } - - public void deactivateOldEntries(boolean verbose) - { - for (Admin admin : allAdmins) - { - if (!admin.isActive() || admin.getRank().isAtLeast(Rank.SENIOR_ADMIN)) - { - continue; - } - - final Date lastLogin = admin.getLastLogin(); - final long lastLoginHours = TimeUnit.HOURS.convert(new Date().getTime() - lastLogin.getTime(), TimeUnit.MILLISECONDS); - - if (lastLoginHours < ConfigEntry.ADMINLIST_CLEAN_THESHOLD_HOURS.getInteger()) - { - continue; - } - - if (verbose) - { - FUtil.adminAction("TotalFreedomMod", "Deactivating admin " + admin.getName() + ", inactive for " + lastLoginHours + " hours", true); - } - - admin.setActive(false); - save(admin); - } - - updateTables(); - } - - public boolean isVanished(Player player) - { - return VanishAPI.isInvisible(player); - } -} \ No newline at end of file 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 e2beade9..f6fcc6b5 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java @@ -3,11 +3,7 @@ package me.totalfreedom.totalfreedommod.command; import de.myzelyam.api.vanish.VanishAPI; import java.util.ArrayList; import java.util.List; -<<<<<<< HEAD -import me.totalfreedom.totalfreedommod.admin.Admin; -======= import me.totalfreedom.totalfreedommod.staff.StaffMember; ->>>>>>> parent of da80f1b6... Revert "Merge branch 'development' of https://github.com/TFPatches/TotalFreedomMod into development" import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.rank.Displayable; import me.totalfreedom.totalfreedommod.rank.Rank; @@ -113,19 +109,11 @@ public class Command_list extends FreedomCommand { continue; } -<<<<<<< HEAD - if (listFilter == ListFilter.ADMINS && plugin.al.isVanished(p)) - { - continue; - } - if (listFilter == ListFilter.VANISHED_ADMINS && !plugin.al.isVanished(p)) -======= if (listFilter == ListFilter.STAFF && plugin.sl.isVanished(p)) { continue; } if (listFilter == ListFilter.VANISHED_STAFF && !plugin.sl.isVanished(p)) ->>>>>>> parent of da80f1b6... Revert "Merge branch 'development' of https://github.com/TFPatches/TotalFreedomMod into development" { continue; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java index 8e3e92f8..8cceba70 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java @@ -1,47 +1,119 @@ package me.totalfreedom.totalfreedommod.command; -import de.myzelyam.api.vanish.VanishAPI; +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; -<<<<<<< HEAD @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME) -======= -@CommandPermissions(level = Rank.TRIAL_MOD, source = SourceType.ONLY_IN_GAME) ->>>>>>> parent of da80f1b6... Revert "Merge branch 'development' of https://github.com/TFPatches/TotalFreedomMod into development" -@CommandParameters(description = "Hide yourself from other players", usage = "/ [-s]", aliases = "v,ev,evanish") +@CommandParameters(description = "Vanish/unvanish yourself.", usage = "/ [-s[ilent]]", aliases = "v") public class Command_vanish extends FreedomCommand { - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + + public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole) { - if (args.length == 0) + Displayable display = plugin.rm.getDisplay(playerSender); + String displayName = display.getColor() + playerSender.getName(); + String tag = display.getColoredTag(); + boolean silent = false; + if (args.length > 0) { - if (!VanishAPI.isInvisible(playerSender)) + if (args[0].equalsIgnoreCase("-s") || args[0].equalsIgnoreCase("-silent")) { - VanishAPI.hidePlayer(playerSender); - } - else - { - VanishAPI.showPlayer(playerSender); + silent = true; } } - else if (args[0].equalsIgnoreCase("-s") || args[0].equalsIgnoreCase("-v")) + + if (plugin.al.isVanished(playerSender.getName())) { - if (!VanishAPI.isInvisible(playerSender)) + if (silent) { - VanishAPI.getPlugin().getVisibilityChanger().hidePlayer(playerSender, null, true); + msg(ChatColor.GOLD + "Silently unvanished."); } else { - VanishAPI.getPlugin().getVisibilityChanger().showPlayer(playerSender, null, true); + 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 { - return false; + 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.sl.vanished.add(playerSender.getName()); } return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/staff/StaffList.java b/src/main/java/me/totalfreedom/totalfreedommod/staff/StaffList.java index 667993ea..eb5a6924 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/staff/StaffList.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/staff/StaffList.java @@ -32,6 +32,7 @@ public class StaffList extends FreedomService private final Map ipTable = Maps.newHashMap(); public final List verifiedNoStaff = new ArrayList<>(); public final Map> verifiedNoStaffIps = Maps.newHashMap(); + public final List vanished = new ArrayList<>(); @Override public void onStart() @@ -363,8 +364,8 @@ public class StaffList extends FreedomService updateTables(); } - public boolean isVanished(Player player) + public boolean isVanished(String player) { - return VanishAPI.isInvisible(player); + return vanished.contains(player); } } \ No newline at end of file