mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 02:05:41 +00:00
fuck intellij
This commit is contained in:
parent
53038ca3b2
commit
7a810519f3
@ -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<Admin> allAdmins = Sets.newHashSet(); // Includes disabled admins
|
||||
// Only active admins below
|
||||
@Getter
|
||||
private final Set<Admin> activeAdmins = Sets.newHashSet();
|
||||
private final Map<String, Admin> nameTable = Maps.newHashMap();
|
||||
private final Map<String, Admin> ipTable = Maps.newHashMap();
|
||||
public final List<String> verifiedNoAdmins = new ArrayList<>();
|
||||
public final Map<String, List<String>> 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<String> getActiveAdminNames()
|
||||
{
|
||||
List<String> 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<String> getAdminNames()
|
||||
{
|
||||
return nameTable.keySet();
|
||||
}
|
||||
|
||||
public Set<String> getAdminIps()
|
||||
{
|
||||
return ipTable.keySet();
|
||||
}
|
||||
|
||||
public void save(Admin admin)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResultSet currentSave = plugin.sql.getAdminByName(admin.getName());
|
||||
for (Map.Entry<String, Object> 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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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 = "/<command> [-s]", aliases = "v,ev,evanish")
|
||||
@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 boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
public void run()
|
||||
{
|
||||
if (args.length == 0)
|
||||
if (plugin.al.isVanished(playerSender.getName()))
|
||||
{
|
||||
if (!VanishAPI.isInvisible(playerSender))
|
||||
playerSender.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.GOLD + "You are hidden from other players."));
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 0L, 4L);
|
||||
|
||||
if (silent)
|
||||
{
|
||||
VanishAPI.hidePlayer(playerSender);
|
||||
msg("Silently vanished.", ChatColor.GOLD);
|
||||
}
|
||||
else
|
||||
{
|
||||
VanishAPI.showPlayer(playerSender);
|
||||
msg ("You have vanished.", ChatColor.GOLD);
|
||||
FUtil.bcastMsg(playerSender.getName() + " left the game.", ChatColor.YELLOW);
|
||||
plugin.dc.messageChatChannel("**" + playerSender.getName() + " left the server" + "**");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("-s") || args[0].equalsIgnoreCase("-v"))
|
||||
|
||||
FLog.info(playerSender.getName() + " is now vanished.");
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (!VanishAPI.isInvisible(playerSender))
|
||||
{
|
||||
VanishAPI.getPlugin().getVisibilityChanger().hidePlayer(playerSender, null, true);
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
playerMsg(player, ChatColor.YELLOW + sender.getName() + " has vanished and is now only visible to admins.");
|
||||
}
|
||||
else
|
||||
if (!plugin.al.isAdmin(player))
|
||||
{
|
||||
VanishAPI.getPlugin().getVisibilityChanger().showPlayer(playerSender, null, true);
|
||||
player.hidePlayer(plugin, playerSender);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
plugin.esb.setVanished(playerSender.getName(), true);
|
||||
plugin.sl.vanished.add(playerSender.getName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ public class StaffList extends FreedomService
|
||||
private final Map<String, StaffMember> ipTable = Maps.newHashMap();
|
||||
public final List<String> verifiedNoStaff = new ArrayList<>();
|
||||
public final Map<String, List<String>> verifiedNoStaffIps = Maps.newHashMap();
|
||||
public final List<String> 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user