From 7f927189ea241dc3530854ced1a9be1e8edae439 Mon Sep 17 00:00:00 2001 From: Driftay Date: Mon, 25 May 2020 14:16:49 -0400 Subject: [PATCH] Alts Can No Longer Be Promoted --- .../massivecraft/factions/cmd/CmdAdmin.java | 4 + .../factions/cmd/CmdColeader.java | 4 + .../massivecraft/factions/cmd/CmdList.java | 129 +++++++++--------- .../com/massivecraft/factions/cmd/CmdMod.java | 4 + .../factions/cmd/roles/FPromoteCommand.java | 4 + .../factions/cmd/wild/CmdWild.java | 7 +- 6 files changed, 83 insertions(+), 69 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdAdmin.java b/src/main/java/com/massivecraft/factions/cmd/CmdAdmin.java index 21718cb9..2c7bbc05 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdAdmin.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdAdmin.java @@ -57,6 +57,10 @@ public class CmdAdmin extends FCommand { return; } + if(fyou.isAlt()){ + return; + } + // only perform a FPlayerJoinEvent when newLeader isn't actually in the faction if (fyou.getFaction() != targetFaction) { FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(context.player), targetFaction, FPlayerJoinEvent.PlayerJoinReason.LEADER); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdColeader.java b/src/main/java/com/massivecraft/factions/cmd/CmdColeader.java index b4f707b9..6fbac352 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdColeader.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdColeader.java @@ -55,6 +55,10 @@ public class CmdColeader extends FCommand { return; } + if(you.isAlt()){ + return; + } + if (context.fPlayer != null && context.fPlayer.getRole() != Role.LEADER && !permAny) { context.msg(TL.COMMAND_COLEADER_NOTADMIN); return; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdList.java b/src/main/java/com/massivecraft/factions/cmd/CmdList.java index 49280bc6..f75c08ec 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdList.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdList.java @@ -42,76 +42,75 @@ public class CmdList extends FCommand { // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay if (!context.payForCommand(Conf.econCostList, "to list the factions", "for listing the factions")) return; - FactionsPlugin.getInstance().getServer().getScheduler().runTaskAsynchronously(FactionsPlugin.instance, () -> { - ArrayList factionList = Factions.getInstance().getAllFactions(); - factionList.remove(Factions.getInstance().getWilderness()); - factionList.remove(Factions.getInstance().getSafeZone()); - factionList.remove(Factions.getInstance().getWarZone()); + ArrayList factionList = Factions.getInstance().getAllFactions(); + factionList.remove(Factions.getInstance().getWilderness()); + factionList.remove(Factions.getInstance().getSafeZone()); + factionList.remove(Factions.getInstance().getWarZone()); - // remove exempt factions - if (context.fPlayer != null && context.fPlayer.getPlayer() != null && !context.fPlayer.getPlayer().hasPermission("factions.show.bypassexempt")) { - List exemptFactions = FactionsPlugin.getInstance().getConfig().getStringList("show-exempt"); + // remove exempt factions + if (context.fPlayer != null && context.fPlayer.getPlayer() != null && !context.fPlayer.getPlayer().hasPermission("factions.show.bypassexempt")) { + List exemptFactions = FactionsPlugin.getInstance().getConfig().getStringList("show-exempt"); - factionList.removeIf(next -> exemptFactions.contains(next.getTag())); + factionList.removeIf(next -> exemptFactions.contains(next.getTag())); + } + + // Sort by total followers first + factionList.sort((f1, f2) -> { + int f1Size = f1.getFPlayers().size(); + int f2Size = f2.getFPlayers().size(); + if (f1Size < f2Size) { + return 1; + } else if (f1Size > f2Size) { + return -1; } - - // Sort by total followers first - factionList.sort((f1, f2) -> { - int f1Size = f1.getFPlayers().size(); - int f2Size = f2.getFPlayers().size(); - if (f1Size < f2Size) { - return 1; - } else if (f1Size > f2Size) { - return -1; - } - return 0; - }); - - // Then sort by how many members are online now - factionList.sort((f1, f2) -> { - int f1Size = f1.getFPlayersWhereOnline(true).size(); - int f2Size = f2.getFPlayersWhereOnline(true).size(); - if (f1Size < f2Size) { - return 1; - } else if (f1Size > f2Size) { - return -1; - } - return 0; - }); - - ArrayList lines = new ArrayList<>(); - - factionList.add(0, Factions.getInstance().getWilderness()); - - final int pageheight = 9; - int pagenumber = context.argAsInt(0, 1); - int pagecount = (factionList.size() / pageheight) + 1; - if (pagenumber > pagecount) { - pagenumber = pagecount; - } else if (pagenumber < 1) { - pagenumber = 1; - } - int start = (pagenumber - 1) * pageheight; - int end = start + pageheight; - if (end > factionList.size()) { - end = factionList.size(); - } - - - String header = FactionsPlugin.getInstance().getConfig().getString("list.header", defaults[0]); - header = header.replace("{pagenumber}", String.valueOf(pagenumber)).replace("{pagecount}", String.valueOf(pagecount)); - lines.add(FactionsPlugin.getInstance().txt.parse(header)); - - for (Faction faction : factionList.subList(start, end)) { - if (faction.isWilderness()) { - lines.add(FactionsPlugin.getInstance().txt.parse(TagUtil.parsePlain(faction, FactionsPlugin.getInstance().getConfig().getString("list.factionless", defaults[1])))); - continue; - } - lines.add(FactionsPlugin.getInstance().txt.parse(TagUtil.parsePlain(faction, context.fPlayer, FactionsPlugin.getInstance().getConfig().getString("list.entry", defaults[2])))); - } - context.sendMessage(lines); + return 0; }); + + // Then sort by how many members are online now + factionList.sort((f1, f2) -> { + int f1Size = f1.getFPlayersWhereOnline(true).size(); + int f2Size = f2.getFPlayersWhereOnline(true).size(); + if (f1Size < f2Size) { + return 1; + } else if (f1Size > f2Size) { + return -1; + } + return 0; + }); + + ArrayList lines = new ArrayList<>(); + + factionList.add(0, Factions.getInstance().getWilderness()); + + final int pageheight = 9; + int pagenumber = context.argAsInt(0, 1); + int pagecount = (factionList.size() / pageheight) + 1; + if (pagenumber > pagecount) { + pagenumber = pagecount; + } else if (pagenumber < 1) { + pagenumber = 1; + } + int start = (pagenumber - 1) * pageheight; + int end = start + pageheight; + if (end > factionList.size()) { + end = factionList.size(); + } + + + String header = FactionsPlugin.getInstance().getConfig().getString("list.header", defaults[0]); + assert header != null; + header = header.replace("{pagenumber}", String.valueOf(pagenumber)).replace("{pagecount}", String.valueOf(pagecount)); + lines.add(FactionsPlugin.getInstance().txt.parse(header)); + + for (Faction faction : factionList.subList(start, end)) { + if (faction.isWilderness()) { + lines.add(FactionsPlugin.getInstance().txt.parse(TagUtil.parsePlain(faction, FactionsPlugin.getInstance().getConfig().getString("list.factionless", defaults[1])))); + continue; + } + lines.add(FactionsPlugin.getInstance().txt.parse(TagUtil.parsePlain(faction, context.fPlayer, FactionsPlugin.getInstance().getConfig().getString("list.entry", defaults[2])))); + } + context.sendMessage(lines); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdMod.java b/src/main/java/com/massivecraft/factions/cmd/CmdMod.java index 82c2335a..e75a0fae 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdMod.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdMod.java @@ -50,6 +50,10 @@ public class CmdMod extends FCommand { return; } + if(you.isAlt()){ + return; + } + if (context.fPlayer != null && context.fPlayer.getRole() != Role.LEADER && !permAny) { context.msg(TL.COMMAND_MOD_NOTADMIN); return; diff --git a/src/main/java/com/massivecraft/factions/cmd/roles/FPromoteCommand.java b/src/main/java/com/massivecraft/factions/cmd/roles/FPromoteCommand.java index a4b70522..5fdac43d 100644 --- a/src/main/java/com/massivecraft/factions/cmd/roles/FPromoteCommand.java +++ b/src/main/java/com/massivecraft/factions/cmd/roles/FPromoteCommand.java @@ -74,6 +74,10 @@ public class FPromoteCommand extends FCommand { } } + if(target.isAlt()){ + return; + } + // Don't allow people to demote people who already have the lowest rank. if (current.value == 0 && relative <= 0) { context.msg(TL.COMMAND_PROMOTE_LOWEST_RANK, target.getName()); diff --git a/src/main/java/com/massivecraft/factions/cmd/wild/CmdWild.java b/src/main/java/com/massivecraft/factions/cmd/wild/CmdWild.java index 8a21ff8c..bdefeaaa 100644 --- a/src/main/java/com/massivecraft/factions/cmd/wild/CmdWild.java +++ b/src/main/java/com/massivecraft/factions/cmd/wild/CmdWild.java @@ -80,9 +80,9 @@ public class CmdWild extends FCommand implements WaitedTask { public void teleportPlayer(Player p, FLocation loc) { Location finalLoc; if (FactionsPlugin.getInstance().getConfig().getBoolean("Wild.Arrival.SpawnAbove")) { - finalLoc = new Location(p.getWorld(), loc.getX(), p.getWorld().getHighestBlockYAt(Math.round(loc.getX()), Math.round(loc.getZ())) + FactionsPlugin.getInstance().getConfig().getInt("Wild.Arrival.SpawnAboveBlocks", 1), loc.getZ()); + finalLoc = new Location(loc.getWorld(), loc.getX(), loc.getWorld().getHighestBlockYAt(Math.round(loc.getX()), Math.round(loc.getZ())) + FactionsPlugin.getInstance().getConfig().getInt("Wild.Arrival.SpawnAboveBlocks", 1), loc.getZ()); } else { - finalLoc = new Location(p.getWorld(), loc.getX(), p.getWorld().getHighestBlockYAt(Math.round(loc.getX()), Math.round(loc.getZ())), loc.getZ()); + finalLoc = new Location(loc.getWorld(), loc.getX(), loc.getWorld().getHighestBlockYAt(Math.round(loc.getX()), Math.round(loc.getZ())), loc.getZ()); } p.teleport(finalLoc, PlayerTeleportEvent.TeleportCause.PLUGIN); setTeleporting(p); @@ -115,5 +115,4 @@ public class CmdWild extends FCommand implements WaitedTask { player.sendMessage(TL.COMMAND_WILD_INTERUPTED.toString()); teleportRange.remove(player); } - -} +} \ No newline at end of file