From 646680c89a4253738854f21c280abfc7e93d8c66 Mon Sep 17 00:00:00 2001 From: Jake Moore Date: Wed, 24 Jul 2024 03:40:28 -0700 Subject: [PATCH] v2.1.6 -Update repo -Removed a LOT of reflection (having access to most jars and this modular gradle setup) --- build.gradle.kts | 2 +- .../object/TranslatedRole.java | 34 +- .../integrations/AtlasIntegration.java | 599 ++++-------------- .../integrations/JartexIntegration.java | 323 +++------- .../integrations/JerryIntegration.java | 131 +--- factions-joseph/build.gradle.kts | 2 +- factions-mc1.20/build.gradle.kts | 2 +- .../integrations/NewUUIDIntegration.java | 235 ++----- .../SaberFactionsIntegration.java | 500 +++------------ .../SaberFactionsXIntegration.java | 572 ++++------------- .../integrations/StellarIntegration.java | 2 + .../integrations/UUIDIntegration.java | 219 ++----- 12 files changed, 553 insertions(+), 2068 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8a5bfd3..9aee12d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -37,7 +37,7 @@ allprojects { maven("https://repo.luxiouslabs.net/repository/maven-public/") maven { name = "luxiousFactionsLibs" - url = uri("https://nexus.luxiouslabs.net/factions-libs") + url = uri("https://repo.luxiouslabs.net/repository/luxious-private/") credentials { username = System.getenv("LUXIOUS_NEXUS_USER") password = System.getenv("LUXIOUS_NEXUS_PASS") diff --git a/common/src/main/java/com/kamikazejam/factionintegrations/object/TranslatedRole.java b/common/src/main/java/com/kamikazejam/factionintegrations/object/TranslatedRole.java index ce1a221..39315cd 100644 --- a/common/src/main/java/com/kamikazejam/factionintegrations/object/TranslatedRole.java +++ b/common/src/main/java/com/kamikazejam/factionintegrations/object/TranslatedRole.java @@ -1,5 +1,9 @@ package com.kamikazejam.factionintegrations.object; +import lombok.Getter; + +@Getter +@SuppressWarnings("unused") public enum TranslatedRole { ADMIN(5), @@ -16,30 +20,20 @@ public enum TranslatedRole { private final int value; - private TranslatedRole(int value) { + TranslatedRole(int value) { this.value = value; } public static TranslatedRole getByValue(int value) { - switch (value) { - case 0: - return ALT; - case 1: - return RECRUIT; - case 2: - return MEMBER; - case 3: - return OFFICER; - case 4: - return CO_LEADER; - case 5: - return ADMIN; - } - return null; - } - - public int getValue() { - return this.value; + return switch (value) { + case 0 -> ALT; + case 1 -> RECRUIT; + case 2 -> MEMBER; + case 3 -> OFFICER; + case 4 -> CO_LEADER; + case 5 -> ADMIN; + default -> null; + }; } public boolean isGreaterThan(TranslatedRole translatedRole) { diff --git a/factions-atlas/src/main/java/com/kamikazejam/factionintegrations/integrations/AtlasIntegration.java b/factions-atlas/src/main/java/com/kamikazejam/factionintegrations/integrations/AtlasIntegration.java index ad169aa..63a4f6e 100644 --- a/factions-atlas/src/main/java/com/kamikazejam/factionintegrations/integrations/AtlasIntegration.java +++ b/factions-atlas/src/main/java/com/kamikazejam/factionintegrations/integrations/AtlasIntegration.java @@ -7,21 +7,27 @@ import com.kamikazejam.factionintegrations.utils.PluginSource; import com.massivecraft.factions.*; import com.massivecraft.factions.event.*; -import com.massivecraft.factions.iface.RelationParticipator; +import com.massivecraft.factions.listeners.FactionsBlockListener; +import com.massivecraft.factions.perms.Access; +import com.massivecraft.factions.perms.PermissableAction; +import com.massivecraft.factions.struct.Relation; +import com.massivecraft.factions.struct.Role; +import com.massivecraft.factions.upgrades.FactionUpgrade; +import com.massivecraft.factions.upgrades.UpgradeType; import org.bukkit.*; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.inventory.Inventory; import org.bukkit.scheduler.BukkitRunnable; +import org.jetbrains.annotations.Nullable; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.*; //AL56AF50 public class AtlasIntegration implements KFaction, ShieldIntegration { + public AtlasIntegration() {} + @EventHandler public void onFactionCreate(FactionCreateEvent e) { new BukkitRunnable() { @@ -110,272 +116,81 @@ public void onJoin(FPlayerLeaveEvent e) { } } - private Method add; - private Method take; - private Method getBalance; - - private Method getRole; - - private Method getOnlinePlayers; - - private Method relationTo; - - private Method canBuild; - - private Method chestInventory; - - private Method getStrikes, setRole; - - private Object leader, coleader, moderator, normal, recruit; - - private Field leaderP, coleaderP, moderatorP, normalP, recruitP, maxMembersField; - - private Method setFaction; - - private Method isInsideBaseRegion; - - private Method isShieldActive; - - private Field econEnabled; - - private Method getUpgrade; - - private Method getExpansion; - - private Object tntUpgrade; - - private Method getPrefix, getByValue; - - private Method getMoneyBalance, depositMoney, withdrawMoney; - - private Method leaveFaction; - - public AtlasIntegration() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException, InvocationTargetException { - Class factionClass = Class.forName("com.massivecraft.factions.Faction"); - - Class fplayerClass = Class.forName("com.massivecraft.factions.FPlayer"); - - isShieldActive = factionClass.getDeclaredMethod("isShieldActive"); - - isInsideBaseRegion = factionClass.getMethod("isInsideBaseRegion", FLocation.class); - - setFaction = fplayerClass.getMethod("setFaction", Faction.class, boolean.class); - - leaveFaction = fplayerClass.getMethod("leave"); - - add = factionClass.getMethod("depositTNT", long.class); - - getMoneyBalance = Faction.class.getDeclaredMethod("getBalance"); - - depositMoney = Faction.class.getDeclaredMethod("depositMoney", double.class); - - withdrawMoney = Faction.class.getDeclaredMethod("withdrawMoney", double.class); - - chestInventory = factionClass.getMethod("getChestInventory"); - - take = factionClass.getMethod("withdrawTNT", long.class); - - getBalance = factionClass.getMethod("getTNT"); - - getStrikes = factionClass.getMethod("getStrikes"); - - getRole = FPlayer.class.getMethod("getRole"); - - relationTo = RelationParticipator.class.getMethod("getRelationTo", RelationParticipator.class); - - Class roleClass = Class.forName("com.massivecraft.factions.struct.Role"); - - getPrefix = roleClass.getMethod("getPrefix"); - - getByValue = roleClass.getDeclaredMethod("getByValue", int.class); - - setRole = FPlayer.class.getMethod("setRole", roleClass); - - Class upgradeClass = Class.forName("com.massivecraft.factions.upgrades.FactionUpgrade"); - - Class aClass = Class.forName("com.massivecraft.factions.upgrades.UpgradeType"); - getUpgrade = Faction.class.getMethod("getUpgrade", aClass); - - getExpansion = upgradeClass.getMethod("getExpansion"); - - for (Object type : aClass.getEnumConstants()) { - String toString = ((Enum) type).name(); - if ("TNT_STORAGE".equalsIgnoreCase(toString)) { - tntUpgrade = type; - break; - } - } - - for (Object type : roleClass.getEnumConstants()) { - String toString = ((Enum) type).name(); - switch (toString.toUpperCase()) { - case "LEADER": - case "ADMIN": - leader = type; - break; - case "COLEADER": - coleader = type; - break; - case "MODERATOR": - moderator = type; - break; - case "NORMAL": - normal = type; - break; - case "RECRUIT": - recruit = type; - } - } - - Class confClass = Class.forName("com.massivecraft.factions.Conf"); - - maxMembersField = confClass.getField("factionMemberLimit"); - - leaderP = confClass.getField("prefixLeader"); - coleaderP = confClass.getField("prefixCoLeader"); - moderatorP = confClass.getField("prefixMod"); - normalP = confClass.getField("prefixNormal"); - recruitP = confClass.getField("prefixRecruit"); - - getOnlinePlayers = Faction.class.getMethod("getOnlinePlayers"); - - canBuild = Class.forName("com.massivecraft.factions.listeners.FactionsBlockListener").getMethod("playerCanBuildDestroyBlock", Player.class, Location.class, String.class, boolean.class); - Class permissableClass = Class.forName("com.massivecraft.factions.perms.Permissable"); - Class accessClass = Class.forName("com.massivecraft.factions.perms.Access"); - - Class relationClass = Class.forName("com.massivecraft.factions.struct.Relation"); - - valueOfRelation = relationClass.getMethod("valueOf", String.class); - - allowObject = accessClass.getMethod("valueOf", String.class).invoke(null, "ALLOW"); - - Class permissableActionClass = Class.forName("com.massivecraft.factions.perms.PermissableAction"); - - valueOf = permissableActionClass.getMethod("valueOf", String.class); - - setPermission = Faction.class.getMethod("setPermission", permissableClass, permissableActionClass, accessClass); - - setRelationWish = Faction.class.getMethod("setRelationWish", Faction.class, relationClass); - } - - private Object allowObject; - - private Method valueOf; - - private Method valueOfRelation; - - private Method setPermission; - - private Method setRelationWish; - @Override - public void setTnT(String id, long amountL) { - try { - int amount = (int) amountL; - Faction faction = Factions.getInstance().getFactionById(id); - - int limit = (int) getMaxTnt(id); + public void setTnT(String id, long amount) { + Faction faction = getFaction(id); + if (faction == null) { return; } + long limit = getMaxTnt(id); - take.invoke(faction, getBalance.invoke(faction)); - if (amount > limit) { - add.invoke(faction, limit); - return; - } - add.invoke(faction, amount); - } catch (IllegalAccessException | InvocationTargetException e) { - Bukkit.getLogger().severe("Error setting tnt bank balance!"); - } + // Can't set tnt directly -> withdraw and deposit + faction.withdrawTNT(faction.getTNT()); + faction.depositTNT(Math.min(amount, limit)); } @Override - public long addTnT(String id, long amountL) { - try { - int amount = (int) amountL; - Faction faction = Factions.getInstance().getFactionById(id); - int totalAmount = ((Long) getBalance.invoke(faction)).intValue(); + public long addTnT(String id, long amount) { + Faction faction = getFaction(id); + if (faction == null) { return 0; } - int limit = (int) getMaxTnt(id); + long totalAmount = faction.getTNT(); + long limit = getMaxTnt(id); - if (amount + totalAmount > limit) { - add.invoke(faction, limit - totalAmount); - return limit - totalAmount; - } - add.invoke(faction, amount); - return amount; - } catch (IllegalAccessException | InvocationTargetException e) { - Bukkit.getLogger().severe("Error setting tnt bank balance!"); + if (amount + totalAmount > limit) { + faction.depositTNT(limit - totalAmount); + return limit - totalAmount; } - return 0; + faction.depositTNT(amount); + return amount; } @Override public long getTnT(String id) { - try { - Faction faction = Factions.getInstance().getFactionById(id); - return ((Long) getBalance.invoke(faction)).intValue(); - } catch (IllegalAccessException | InvocationTargetException e) { - Bukkit.getLogger().severe("Error getting tnt bank balance!"); - } - return 0; + Faction faction = getFaction(id); + if (faction == null) { return 0; } + return faction.getTNT(); } @Override public long getMaxTnt(String id) { - try { - Object upgrade = getUpgrade.invoke(Factions.getInstance().getFactionById(id), tntUpgrade); - return (int) getExpansion.invoke(upgrade); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return 0; + Faction faction = getFaction(id); + if (faction == null) { return 0; } + + FactionUpgrade upgrade = faction.getUpgrade(UpgradeType.TNT_STORAGE); + return upgrade.getExpansion(); + } + + @Nullable + private static Faction getFaction(String id) { + return Factions.getInstance().getFactionById(id); } @Override public int getStrikes(String id) { - try { - Faction faction = Factions.getInstance().getFactionById(id); + Faction faction = getFaction(id); + if (faction == null) { return 0; } - if (faction == null) return 0; - - return ((Set) getStrikes.invoke(faction)).size(); - } catch (IllegalAccessException | InvocationTargetException | NullPointerException ignored) { - - } - return 0; + return faction.getStrikes().size(); } @Override public double getBalance(String id) { - Faction faction = Factions.getInstance().getFactionById(id); - - try { - return (double) getMoneyBalance.invoke(faction); - } catch (InvocationTargetException | IllegalAccessException ignored) { - - } - return 0.0D; + Faction faction = getFaction(id); + if (faction == null) { return 0D; } + return faction.getBalance(); } @Override public void addBalance(String id, double add) { - Faction faction = Factions.getInstance().getFactionById(id); - - try { - depositMoney.invoke(faction, add); - } catch (InvocationTargetException | IllegalAccessException ignored) { - - } + Faction faction = getFaction(id); + if (faction == null) { return; } + faction.depositMoney(add); } @Override public void subtractBalance(String id, double remove) { - Faction faction = Factions.getInstance().getFactionById(id); - - try { - withdrawMoney.invoke(faction, remove); - } catch (InvocationTargetException | IllegalAccessException ignored) { - - } + Faction faction = getFaction(id); + if (faction == null) { return; } + faction.withdrawMoney(remove); } @Override @@ -385,11 +200,11 @@ public boolean econEnabled() { @Override public boolean canPlayerBuildThere(Player player, Chunk chunk) { - if (isBypassing(player)) return true; + if (isBypassing(player)) { return true; } + FLocation fLocation = new FLocation(player.getWorld().getName(), chunk.getX(), chunk.getZ()); - Faction faction = Board.getInstance().getFactionAt(new FLocation(player.getWorld().getName(), chunk.getX(), chunk.getZ())); - - if (faction.isWilderness()) return true; + Faction faction = Board.getInstance().getFactionAt(fLocation); + if (faction.isWilderness()) { return true; } return getRelationToFaction(player, faction.getId()).isEqualTo(TranslatedRelation.MEMBER); } @@ -398,29 +213,19 @@ public boolean canPlayerBuildThere(Player player, Chunk chunk) { public boolean isBaseRegion(Location location, String id) { FLocation fLocation = new FLocation(location); Faction faction = Board.getInstance().getFactionAt(fLocation); - if (!id.equalsIgnoreCase(faction.getId())) - return false; - try { - return (Boolean) this.isInsideBaseRegion.invoke(faction, fLocation); - } catch (InvocationTargetException | IllegalAccessException e) { - Bukkit.getConsoleSender().sendMessage("Error getting base region!"); - return false; - } + if (!id.equalsIgnoreCase(faction.getId())) { return false; } + return faction.isInsideBaseRegion(fLocation); } @Override public boolean isSystemFac(String id) { - Faction factionById = Factions.getInstance().getFactionById(id); + Faction factionById = Objects.requireNonNull(getFaction(id)); return factionById.isSafeZone() || factionById.isWilderness() || factionById.isWarZone(); } @Override public boolean playerCanBuildThere(Player player, Location location) { - try { - return (boolean) canBuild.invoke(null, player, location, "build", true); - } catch (IllegalAccessException | InvocationTargetException e) { - return false; - } + return FactionsBlockListener.playerCanBuildDestroyBlock(player, location, "build", true); } @Override @@ -456,14 +261,9 @@ public boolean isLocked() { @Override public boolean isShieldActiveNow(String id) { - Faction faction = Factions.getInstance().getFactionById(id); - - try { - return (boolean) isShieldActive.invoke(faction); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return false; + Faction faction = getFaction(id); + if (faction == null) { return false; } + return faction.isShieldActive(); } @Override @@ -477,22 +277,17 @@ public int getMaxClaimWorldborder(World world) { @Override public int getClaimsInWorld(String id, World world) { - return Board.getInstance().getFactionCoordCountInWorld(Factions.getInstance().getFactionById(id), world.getName()); + return Board.getInstance().getFactionCoordCountInWorld(getFaction(id), world.getName()); } @Override public int getMaxPlayers(String id) { - try { - return (int) maxMembersField.get(null); - } catch (IllegalAccessException ignored) { - - } - return 0; + return Conf.factionMemberLimit; } @Override public int getSize(String id) { - Faction factionById = Factions.getInstance().getFactionById(id); + Faction factionById = getFaction(id); if (factionById == null) return 0; if (factionById.getFPlayers() == null) return 0; @@ -502,14 +297,9 @@ public int getSize(String id) { @Override public boolean isInFactionChest(Player player, String id) { - Faction faction = Factions.getInstance().getFactionById(id); - - try { - return ((Inventory) chestInventory.invoke(faction)).getViewers().contains(player); - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } - return false; + Faction faction = getFaction(id); + if (faction == null) { return false; } + return faction.getChestInventory().getViewers().contains(player); } @Override @@ -522,19 +312,11 @@ public void setFaction(Player player, String id) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); if (id == null) { - try { - leaveFaction.invoke(fPlayer); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } + fPlayer.leave(); return; } - try { - setFaction.invoke(fPlayer, Factions.getInstance().getFactionById(id), false); - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } + fPlayer.setFaction(getFaction(id), false); } @Override @@ -542,135 +324,77 @@ public void setFaction(OfflinePlayer player, String id) { FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(player); if (id == null) { - try { - leaveFaction.invoke(fPlayer); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } + fPlayer.leave(); return; } - try { - setFaction.invoke(fPlayer, Factions.getInstance().getFactionById(id), false); - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } + fPlayer.setFaction(getFaction(id), false); } @Override public void setRole(Player player, TranslatedRole translatedRole) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - try { - switch (translatedRole.getValue()) { - case 1: - setRole.invoke(fPlayer, recruit); - break; - case 2: - setRole.invoke(fPlayer, normal); - break; - case 3: - setRole.invoke(fPlayer, moderator); - break; - case 4: - setRole.invoke(fPlayer, coleader); - break; - case 5: - setRole.invoke(fPlayer, leader); - break; - } - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } + setFPlayerRole(translatedRole, fPlayer); } @Override public void setRole(OfflinePlayer offlinePlayer, TranslatedRole translatedRole) { FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(offlinePlayer); - try { - switch (translatedRole.getValue()) { - case 1: - setRole.invoke(fPlayer, recruit); - break; - case 2: - setRole.invoke(fPlayer, normal); - break; - case 3: - setRole.invoke(fPlayer, moderator); - break; - case 4: - setRole.invoke(fPlayer, coleader); - break; - case 5: - setRole.invoke(fPlayer, leader); - break; - } - } catch (IllegalAccessException | InvocationTargetException ignored) { + setFPlayerRole(translatedRole, fPlayer); + } + private void setFPlayerRole(TranslatedRole translatedRole, FPlayer fPlayer) { + switch (translatedRole.getValue()) { + case 1: + fPlayer.setRole(Role.RECRUIT); + break; + case 2: + fPlayer.setRole(Role.NORMAL); + break; + case 3: + fPlayer.setRole(Role.MODERATOR); + break; + case 4: + fPlayer.setRole(Role.COLEADER); + break; + case 5: + fPlayer.setRole(Role.LEADER); + break; } } @Override public void setPermission(String id, TranslatedRelation relation, String permission, boolean b) { - Faction faction = Factions.getInstance().getFactionById(id); - - try { - Object rel = null; - - switch (relation) { - case MEMBER: - rel = valueOfRelation.invoke(null, "MEMBER"); - break; - case ENEMY: - rel = valueOfRelation.invoke(null, "ENEMY"); - break; - case NEUTRAL: - rel = valueOfRelation.invoke(null, "NEUTRAL"); - break; - case ALLY: - rel = valueOfRelation.invoke(null, "ALLY"); - break; - case TRUCE: - rel = valueOfRelation.invoke(null, "TRUCE"); - } + Faction faction = getFaction(id); + if (faction == null) { return; } - setPermission.invoke(faction, rel, valueOf.invoke(null, permission), allowObject); - } catch (Exception ignored) { + Relation rel = switch (relation) { + case MEMBER -> Relation.MEMBER; + case ENEMY -> Relation.ENEMY; + case NEUTRAL -> Relation.NEUTRAL; + case ALLY -> Relation.ALLY; + case TRUCE -> Relation.TRUCE; + }; - } + faction.setPermission(rel, PermissableAction.valueOf(permission), (b) ? Access.ALLOW : Access.DENY); } @Override public void setRelationWish(String id, String other, TranslatedRelation relation) { - Faction a = Factions.getInstance().getFactionById(id); - - Faction b = Factions.getInstance().getFactionById(other); - - try { - Object rel = null; - - switch (relation) { - case MEMBER: - rel = valueOfRelation.invoke(null, "MEMBER"); - break; - case ENEMY: - rel = valueOfRelation.invoke(null, "ENEMY"); - break; - case NEUTRAL: - rel = valueOfRelation.invoke(null, "NEUTRAL"); - break; - case ALLY: - rel = valueOfRelation.invoke(null, "ALLY"); - break; - case TRUCE: - rel = valueOfRelation.invoke(null, "TRUCE"); - } + Faction a = Objects.requireNonNull(getFaction(id)); + Faction b = Objects.requireNonNull(getFaction(other)); - setRelationWish.invoke(a, b, rel); - } catch (Exception exc) { - exc.printStackTrace(); - } + Relation rel = switch (relation) { + case MEMBER -> Relation.MEMBER; + case ENEMY -> Relation.ENEMY; + case NEUTRAL -> Relation.NEUTRAL; + case ALLY -> Relation.ALLY; + case TRUCE -> Relation.TRUCE; + }; + + a.setRelationWish(b, rel); } @Override @@ -688,8 +412,8 @@ public String createFaction(String tag) { @Override public void setFactionPower(String id, double power) { - Faction faction = Factions.getInstance().getFactionById(id); - + Faction faction = getFaction(id); + if (faction == null) { return; } faction.setPermanentPower((int) power); } @@ -705,7 +429,7 @@ public void clearAllClaimsInWorld(String world) { @Override public void setFactionAt(int cx, int cz, String world, String faction) { - Board.getInstance().setFactionAt(Factions.getInstance().getFactionById(faction), new FLocation(world, cx, cz)); + Board.getInstance().setFactionAt(getFaction(faction), new FLocation(world, cx, cz)); } @Override @@ -736,14 +460,8 @@ public Map> getAllClaims(String id) { @Override public Inventory getChestInventory(Player player, String id) { - Faction faction = Factions.getInstance().getFactionById(id); - - try { - return (Inventory) chestInventory.invoke(faction); - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } - return null; + Faction faction = Objects.requireNonNull(getFaction(id)); + return faction.getChestInventory(); } @Override @@ -780,7 +498,7 @@ public String getFactionsIdAt(Integer[] coordinates, World world) { public String getTagFromId(String id) { if (id == null) return "None"; if (!Factions.getInstance().isValidFactionId(id)) return "None"; - Faction factionById = Factions.getInstance().getFactionById(id); + Faction factionById = getFaction(id); if (factionById == null) return "None"; return factionById.getTag(); } @@ -799,24 +517,16 @@ public String getWilderness() { @Override public String getRolePrefix(TranslatedRole translatedRole) { - String toReturn; - try { - if (translatedRole == TranslatedRole.ALT) return ""; - toReturn = (String) getPrefix.invoke(getByValue.invoke(null, translatedRole.getValue() - 1)); - } catch (Exception ignored) { - return "$"; - } - return toReturn; + if (translatedRole == TranslatedRole.ALT) return ""; + return Role.getByValue(translatedRole.getValue() - 1).getPrefix(); } @Override public List getOnlineMembers(String id) { - Faction faction = Factions.getInstance().getFactionById(id); - - if (faction == null) return new ArrayList<>(); + Faction faction = getFaction(id); + if (faction == null) { return new ArrayList<>(); } List players = new ArrayList<>(); - for (FPlayer fPlayer : faction.getFPlayersWhereOnline(true)) { players.add(Bukkit.getPlayer(UUID.fromString(fPlayer.getId()))); } @@ -827,7 +537,7 @@ public List getOnlineMembers(String id) { public List getOfflineMembers(String id) { List offliners = new ArrayList<>(); - Faction faction = Factions.getInstance().getFactionById(id); + Faction faction = getFaction(id); if (faction == null) return offliners; @@ -844,7 +554,7 @@ public List getOfflineMembers(String id) { @Override public UUID getLeader(String id) { - Faction faction = Factions.getInstance().getFactionById(id); + Faction faction = getFaction(id); if (faction == null) return null; @@ -855,7 +565,7 @@ public UUID getLeader(String id) { @Override public OfflinePlayer getOfflineLeader(String id) { - Faction faction = Factions.getInstance().getFactionById(id); + Faction faction = getFaction(id); if (faction == null) return null; @@ -899,90 +609,61 @@ public boolean isWildernessAt(Location location) { @Override public TranslatedRelation getRelationToFaction(Player player, String id) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - Faction faction = Factions.getInstance().getFactionById(id); - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(fPlayer, faction)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - return TranslatedRelation.ENEMY; - } + Faction faction = getFaction(id); + return TranslatedRelation.valueOf(fPlayer.getRelationTo(faction).name().toUpperCase()); } @Override public TranslatedRole getRole(Player player) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override public TranslatedRole getRole(OfflinePlayer player) { FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(player); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override public TranslatedRole getRole(UUID uuid) { FPlayer fPlayer = FPlayers.getInstance().getById(uuid.toString()); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override public TranslatedRelation getFactionRelationToFaction(String id1, String id2) { - Faction faction1 = Factions.getInstance().getFactionById(id1); - Faction faction2 = Factions.getInstance().getFactionById(id2); + Faction faction1 = getFaction(id1); + Faction faction2 = getFaction(id2); if (faction1 == null || faction2 == null) return TranslatedRelation.ENEMY; - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(faction1, faction2)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return TranslatedRelation.ENEMY; + return TranslatedRelation.valueOf(faction1.getRelationTo(faction2).name().toUpperCase()); } @Override public TranslatedRelation getRelationToPlayer(Player player, Player player2) { FPlayer fPlayer1 = FPlayers.getInstance().getByPlayer(player); FPlayer fPlayer2 = FPlayers.getInstance().getByPlayer(player2); - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(fPlayer1, fPlayer2)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return TranslatedRelation.ENEMY; + return TranslatedRelation.valueOf(fPlayer1.getRelationTo(fPlayer2).name().toUpperCase()); } @Override public void setOpen(String factionId, boolean open) { - Factions.getInstance().getFactionById(factionId).setOpen(open); + Objects.requireNonNull(getFaction(factionId)).setOpen(open); } @Override public void setPermanent(String factionId, boolean permanent) { - Factions.getInstance().getFactionById(factionId).setPermanent(permanent); + Objects.requireNonNull(getFaction(factionId)).setPermanent(permanent); } @Override public String getDescription(String factionId) { - return Factions.getInstance().getFactionById(factionId).getDescription(); + return Objects.requireNonNull(getFaction(factionId)).getDescription(); } @Override public void setDescription(String factionId, String description) { - Factions.getInstance().getFactionById(factionId).setDescription(description); + Objects.requireNonNull(getFaction(factionId)).setDescription(description); } @Override diff --git a/factions-jartex/src/main/java/com/kamikazejam/factionintegrations/integrations/JartexIntegration.java b/factions-jartex/src/main/java/com/kamikazejam/factionintegrations/integrations/JartexIntegration.java index c42d813..e2000c7 100644 --- a/factions-jartex/src/main/java/com/kamikazejam/factionintegrations/integrations/JartexIntegration.java +++ b/factions-jartex/src/main/java/com/kamikazejam/factionintegrations/integrations/JartexIntegration.java @@ -7,11 +7,12 @@ import com.kamikazejam.factionintegrations.utils.PluginSource; import com.massivecraft.factions.*; import com.massivecraft.factions.event.*; -import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.jartex.FactionsAPI; import com.massivecraft.factions.jartex.faction.permission.PRole; import com.massivecraft.factions.jartex.faction.permission.PTNormal; +import com.massivecraft.factions.listeners.FactionsBlockListener; import com.massivecraft.factions.struct.Relation; +import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.persist.MemoryBoard; import com.massivecraft.factions.zcore.persist.MemoryFaction; import lombok.SneakyThrows; @@ -21,11 +22,9 @@ import org.bukkit.inventory.Inventory; import org.bukkit.scheduler.BukkitRunnable; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.*; -@SuppressWarnings("deprecation") +@SuppressWarnings({"deprecation", "unused"}) public class JartexIntegration implements KFaction { @EventHandler @@ -128,124 +127,48 @@ public void onJoin(FPlayerLeaveEvent e) { } } - private Method canBuild; - - private Method getRole; - - private Method relationTo, setRole; - - private Object leader, coleader, moderator, normal, recruit; - - private Method setTNT, getTNT, getMaximumTNT; - - private Method getActiveStrikes; - - private Method setFaction; - - private Method getPermissions; - - private Method setRelationWish; - - private Method getAllClaims; - - private Method isAlt; - - private Method isAtLeast; - - private Method getByID; - - public JartexIntegration() throws ClassNotFoundException, NoSuchMethodException { - relationTo = RelationParticipator.class.getMethod("getRelationTo", RelationParticipator.class); - - getRole = FPlayer.class.getMethod("getRole"); - - Class roleClass = Class.forName("com.massivecraft.factions.struct.Role"); - - setRole = FPlayer.class.getMethod("setRole", roleClass); - - for (Object type : roleClass.getEnumConstants()) { - String toString = ((Enum) type).name(); - switch (toString.toUpperCase()) { - case "LEADER": - case "ADMIN": - leader = type; - break; - case "CO_ADMIN": - coleader = type; - break; - case "MODERATOR": - moderator = type; - break; - case "NORMAL": - normal = type; - break; - case "RECRUIT": - recruit = type; - } - } - - getActiveStrikes = Faction.class.getMethod("getActiveStrikes"); - - setFaction = FPlayer.class.getMethod("setFaction", Faction.class, boolean.class); - - isAtLeast = roleClass.getMethod("isAtLeast", roleClass); - - isAlt = FPlayer.class.getMethod("isAlt"); - - getPermissions = Faction.class.getMethod("getPermissions"); - - setRelationWish = Faction.class.getMethod("setRelationWish", Faction.class, Relation.class); - - getByID = FPlayers.class.getMethod("getById", UUID.class); - - getAllClaims = Board.class.getMethod("getAllClaims", Integer.class); - - getTNT = Faction.class.getMethod("getTNT"); - setTNT = Faction.class.getMethod("setTNT", int.class); - getMaximumTNT = Faction.class.getMethod("getMaximumTNT"); - - canBuild = Class.forName("com.massivecraft.factions.listeners.FactionsBlockListener").getMethod("playerCanBuildDestroyBlock", Player.class, Location.class, String.class, boolean.class); - } + public JartexIntegration() {} @SneakyThrows @Override - public void setTnT(String id, long amount) { + public void setTnT(String id, long amountL) { Faction faction = Factions.getInstance().getFactionById(id); - long limit = getMaxTnt(id); + int amount = (int) amountL; + int limit = (int) getMaxTnt(id); if (amount > limit) { - setTNT.invoke(faction, (int) limit); + faction.setTNT(limit); return; } - setTNT.invoke(faction, (int) amount); + faction.setTNT(amount); } @SneakyThrows @Override - public long addTnT(String id, long amount) { + public long addTnT(String id, long amountL) { Faction faction = Factions.getInstance().getFactionById(id); - int totalAmount = (int) getTNT.invoke(faction); - - long limit = getMaxTnt(id); + int amount = (int) amountL; + int totalAmount = faction.getTNT(); + int limit = (int) getMaxTnt(id); if (amount + totalAmount > limit) { - setTNT.invoke(faction, (int) limit); + faction.setTNT(limit); return limit - totalAmount; } - setTNT.invoke(faction, (int) (totalAmount + amount)); + faction.setTNT(totalAmount + amount); return amount; } @SneakyThrows @Override public long getTnT(String id) { - return (int) getTNT.invoke(Factions.getInstance().getFactionById(id)); + return Factions.getInstance().getFactionById(id).getTNT(); } @SneakyThrows @Override public long getMaxTnt(String id) { - int maxTNT = (int) getMaximumTNT.invoke(Factions.getInstance().getFactionById(id)); + int maxTNT = Factions.getInstance().getFactionById(id).getMaximumTNT(); return maxTNT <= 0 ? Integer.MAX_VALUE : maxTNT; } @@ -306,11 +229,7 @@ public boolean isSystemFac(String id) { @Override public boolean playerCanBuildThere(Player player, Location location) { - try { - return (boolean) canBuild.invoke(null, player, location, "build", true); - } catch (IllegalAccessException | InvocationTargetException e) { - return false; - } + return FactionsBlockListener.playerCanBuildDestroyBlock(player, location, "build", true); } @Override @@ -369,10 +288,8 @@ public int getClaimsInWorld(String id, World world) { @Override public int getStrikes(String id) { Faction faction = Factions.getInstance().getFactionById(id); - if (faction == null) return 0; - - return (int) getActiveStrikes.invoke(faction); + return faction.getActiveStrikes(); } @Override @@ -399,13 +316,11 @@ public boolean isFaction(String id) { @Override public void setFaction(Player player, String id) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - if (id == null) { fPlayer.leave(false); return; } - - setFaction.invoke(fPlayer, Factions.getInstance().getFactionById(id), false); + fPlayer.setFaction(Factions.getInstance().getFactionById(id), false); } @SneakyThrows @@ -417,105 +332,72 @@ public void setFaction(OfflinePlayer player, String id) { fPlayer.leave(false); return; } - - setFaction.invoke(fPlayer, Factions.getInstance().getFactionById(id), false); + fPlayer.setFaction(Factions.getInstance().getFactionById(id), false); } @Override public void setRole(Player player, TranslatedRole translatedRole) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - try { - switch (translatedRole.getValue()) { - case 1: - setRole.invoke(fPlayer, recruit); - break; - case 2: - setRole.invoke(fPlayer, normal); - break; - case 3: - setRole.invoke(fPlayer, moderator); - break; - case 4: - setRole.invoke(fPlayer, coleader); - break; - case 5: - setRole.invoke(fPlayer, leader); - break; - } - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } + setFPlayerRole(translatedRole, fPlayer); } @Override public void setRole(OfflinePlayer offlinePlayer, TranslatedRole translatedRole) { FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(offlinePlayer); - try { - switch (translatedRole.getValue()) { - case 1: - setRole.invoke(fPlayer, recruit); - break; - case 2: - setRole.invoke(fPlayer, normal); - break; - case 3: - setRole.invoke(fPlayer, moderator); - break; - case 4: - setRole.invoke(fPlayer, coleader); - break; - case 5: - setRole.invoke(fPlayer, leader); - break; - } - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } + setFPlayerRole(translatedRole, fPlayer); } - @SneakyThrows - @Override - public void setPermission(String id, TranslatedRelation relation, String permission, boolean b) { - Faction faction = Factions.getInstance().getFactionById(id); - - PRole rel = null; - - switch (relation) { - case MEMBER: - rel = PRole.NORMAL; + private void setFPlayerRole(TranslatedRole translatedRole, FPlayer fPlayer) { + switch (translatedRole.getValue()) { + case 1: + fPlayer.setRole(Role.RECRUIT); + break; + case 2: + fPlayer.setRole(Role.NORMAL); break; - case ENEMY: - rel = PRole.ENEMY; + case 3: + fPlayer.setRole(Role.MODERATOR); break; - case NEUTRAL: - rel = PRole.NEUTRAL; + case 4: + fPlayer.setRole(Role.CO_ADMIN); break; - case ALLY: - rel = PRole.ALLY; + case 5: + fPlayer.setRole(Role.ADMIN); break; - case TRUCE: - rel = PRole.TRUCE; } + } - List allowed = (List) ((Map) getPermissions.invoke(faction)).get(rel.name()); - - if (allowed == null) - return; - - if (allowed.contains(rel)) - return; - - allowed.add(rel); + @SneakyThrows + @Override + public void setPermission(String id, TranslatedRelation relation, String permission, boolean b) { + MemoryFaction faction = (MemoryFaction) Factions.getInstance().getFactionById(id); + + PRole rel = switch (relation) { + case MEMBER -> PRole.NORMAL; + case ENEMY -> PRole.ENEMY; + case NEUTRAL -> PRole.NEUTRAL; + case ALLY -> PRole.ALLY; + case TRUCE -> PRole.TRUCE; + }; + + Map> permMap = faction.getPermissions(); + List permissions = permMap.computeIfAbsent(permission, k -> new ArrayList<>()); + if (!b) { + permissions.removeIf(z -> z == rel); + }else { + if (!permissions.contains(rel)) { + permissions.add(rel); + } + } } @SneakyThrows @Override public void setRelationWish(String id, String other, TranslatedRelation relation) { Faction faction = Factions.getInstance().getFactionById(id); - - setRelationWish.invoke(faction, Factions.getInstance().getFactionById(other), Relation.valueOf(relation.toString())); + faction.setRelationWish(Factions.getInstance().getFactionById(other), Relation.valueOf(relation.toString())); } @Override @@ -579,7 +461,7 @@ public Set getAllFactions() { public Map> getAllClaims(String id) { Map> toReturn = new HashMap<>(); - Set all = (Set) getAllClaims.invoke(Board.getInstance(), Integer.valueOf(id)); + Set all = Board.getInstance().getAllClaims(Integer.valueOf(id)); for (FLocation fLocation : all) { toReturn.putIfAbsent(fLocation.getWorldName(), new HashSet<>()); @@ -649,25 +531,14 @@ public String getWilderness() { @Override public String getRolePrefix(TranslatedRole translatedRole) { - String toReturn = ""; - switch (translatedRole.getValue()) { - case 1: - toReturn = Conf.prefixRecruit; - break; - case 2: - toReturn = Conf.prefixNormal; - break; - case 3: - toReturn = Conf.prefixMod; - break; - case 4: - toReturn = Conf.prefixCoAdmin; - break; - case 5: - toReturn = Conf.prefixAdmin; - break; - } - return toReturn; + return switch (translatedRole.getValue()) { + case 1 -> Conf.prefixRecruit; + case 2 -> Conf.prefixNormal; + case 3 -> Conf.prefixMod; + case 4 -> Conf.prefixCoAdmin; + case 5 -> Conf.prefixAdmin; + default -> ""; + }; } @SneakyThrows @@ -680,7 +551,7 @@ public List getOnlineMembers(String id) { List players = new ArrayList<>(); for (FPlayer fPlayer : faction.getFPlayersWhereOnline(true)) { - if (!((boolean) isAtLeast.invoke(getRole.invoke(fPlayer), recruit)) || isAlt(fPlayer.getPlayer())) continue; + if (!(fPlayer.getRole().isAtLeast(Role.RECRUIT)) || isAlt(fPlayer.getPlayer())) continue; players.add(Bukkit.getPlayer(UUID.fromString(fPlayer.getAccountId()))); } return players; @@ -711,9 +582,8 @@ public OfflinePlayer getOfflineLeader(String id) { return Bukkit.getOfflinePlayer(id1); } - @SneakyThrows private boolean isAtLeastRecruitAndNotAlt(FPlayer fPlayer) { - return (boolean) isAtLeast.invoke(getRole.invoke(fPlayer), recruit) && !isAlt(fPlayer.getPlayer()); + return fPlayer.getRole().isAtLeast(Role.RECRUIT) && !isAlt(fPlayer.getPlayer()); } @Override @@ -749,9 +619,7 @@ public boolean hasFaction(OfflinePlayer player) { @SneakyThrows @Override public boolean hasFaction(UUID uuid) { - FPlayer fPlayer = (FPlayer) getByID.invoke(FPlayers.getInstance(), uuid); - - return fPlayer.hasFaction(); + return FPlayers.getInstance().getById(uuid).hasFaction(); } @Override @@ -769,45 +637,26 @@ public boolean isWildernessAt(Location location) { public TranslatedRelation getRelationToFaction(Player player, String id) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); Faction faction = Factions.getInstance().getFactionById(id); - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(fPlayer, faction)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - return TranslatedRelation.ENEMY; - } + return TranslatedRelation.valueOf(fPlayer.getRelationTo(faction).name().toUpperCase()); } @Override public TranslatedRole getRole(Player player) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override public TranslatedRole getRole(OfflinePlayer player) { FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(player); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @SneakyThrows @Override public TranslatedRole getRole(UUID uuid) { - FPlayer fPlayer = (FPlayer) getByID.invoke(FPlayers.getInstance(), uuid); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + FPlayer fPlayer = FPlayers.getInstance().getById(uuid); + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override @@ -815,32 +664,20 @@ public TranslatedRelation getFactionRelationToFaction(String id1, String id2) { Faction faction1 = Factions.getInstance().getFactionById(id1); Faction faction2 = Factions.getInstance().getFactionById(id2); if (faction1 == null || faction2 == null) return TranslatedRelation.ENEMY; - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(faction1, faction2)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return TranslatedRelation.ENEMY; + return TranslatedRelation.valueOf(faction1.getRelationTo(faction2).name().toUpperCase()); } @Override public TranslatedRelation getRelationToPlayer(Player player, Player player2) { FPlayer fPlayer1 = FPlayers.getInstance().getByPlayer(player); FPlayer fPlayer2 = FPlayers.getInstance().getByPlayer(player2); - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(fPlayer1, fPlayer2)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return TranslatedRelation.ENEMY; + return TranslatedRelation.valueOf(fPlayer1.getRelationTo(fPlayer2).name().toUpperCase()); } @SneakyThrows @Override public boolean isAlt(Player player) { - FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - - return (boolean) isAlt.invoke(fPlayer); + return FPlayers.getInstance().getByPlayer(player).isAlt(); } @EventHandler diff --git a/factions-jerry/src/main/java/com/kamikazejam/factionintegrations/integrations/JerryIntegration.java b/factions-jerry/src/main/java/com/kamikazejam/factionintegrations/integrations/JerryIntegration.java index 6dd115e..0b2bf62 100644 --- a/factions-jerry/src/main/java/com/kamikazejam/factionintegrations/integrations/JerryIntegration.java +++ b/factions-jerry/src/main/java/com/kamikazejam/factionintegrations/integrations/JerryIntegration.java @@ -4,135 +4,54 @@ import com.kamikazejam.factionintegrations.shield.ShieldIntegration; import com.massivecraft.factions.*; import com.massivecraft.factions.event.PowerLossEvent; +import com.massivecraft.factions.managers.UpgradesManager; import com.massivecraft.factions.objects.Strike; +import com.massivecraft.factions.objects.Upgrade; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.inventory.Inventory; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.List; import java.util.Set; public class JerryIntegration extends UUIDIntegration implements ShieldIntegration { - private Method getBaseRegionOptions; - - private Method isShielded; - - private Method getUpgradesManager; - - private Method getUpgrade; - - private Method getBoost; - - private Method getUpgradeLevel; - - private Method getInventory; - - private Field playersInProcessField; - - private Method getWhereAlt; - - private Method getStrikes; - - private Method isAlt; - - public JerryIntegration() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException { - getBaseRegionOptions = Faction.class.getMethod("getBaseRegionOptions"); - - getWhereAlt = Faction.class.getMethod("getFPlayersWhereAlt", boolean.class); - - isAlt = FPlayer.class.getMethod("isAlt"); - - isShielded = Faction.class.getMethod("isShielded"); - - getStrikes = Faction.class.getMethod("getStrikes"); - - getUpgradesManager = FactionsPlugin.class.getMethod("getUpgradesManager"); - - getUpgrade = Class.forName("com.massivecraft.factions.managers.UpgradesManager").getMethod("getUpgrade", String.class); - - Class aClass = Class.forName("com.massivecraft.factions.objects.Upgrade"); - - getBoost = aClass.getMethod("getBoost", int.class); - - getUpgradeLevel = Faction.class.getMethod("getUpgradeLevel", aClass); - - getInventory = Faction.class.getMethod("getInventory"); - - playersInProcessField = Class.forName("com.massivecraft.factions.listeners.FactionsChestListener").getDeclaredField("playersToProcess"); - - playersInProcessField.setAccessible(true); - } + public JerryIntegration() {} @Override public boolean isBaseRegion(Location location, String id) { Faction faction = Factions.getInstance().getFactionById(id); - if (faction == null) return false; - try { - Set fLocationSet = (Set) getBaseRegionOptions.invoke(faction); - - return fLocationSet.contains(new FLocation(location)); - } catch (IllegalAccessException | InvocationTargetException exc) { - - } - return false; + return faction.getBaseRegionOptions().contains(new FLocation(location)); } @Override public int getStrikes(String id) { Faction faction = Factions.getInstance().getFactionById(id); - if (faction == null) return 0; - try { - List strikes = (List) getStrikes.invoke(faction); - - return strikes.stream().mapToInt(Strike::getPoints).sum(); - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } - return 0; + return faction.getStrikes().stream().mapToInt(Strike::getPoints).sum(); } @Override public boolean isShieldActiveNow(String id) { - try { - Faction factionById = Factions.getInstance().getFactionById(id); - - if (factionById == null) return false; - - return (boolean) isShielded.invoke(factionById); - } catch (IllegalAccessException | InvocationTargetException ignored) { + Faction faction = Factions.getInstance().getFactionById(id); + if (faction == null) return false; - } - return false; + return faction.isShielded(); } @Override public long getMaxTnt(String id) { Faction faction = Factions.getInstance().getFactionById(id); - if (faction == null) return 0; - try { - Object upgradeManager = getUpgradesManager.invoke(FactionsPlugin.getInstance()); - - Object upgrade = getUpgrade.invoke(upgradeManager, "tnt"); - - int factionLevel = (int) getUpgradeLevel.invoke(faction, upgrade); - - return (int) getBoost.invoke(upgrade, factionLevel); - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } - return 0L; + UpgradesManager manager = FactionsPlugin.getInstance().getUpgradesManager(); + Upgrade upgrade = manager.getUpgrade("tnt"); + int factionLevel = faction.getUpgradeLevel(upgrade); + return upgrade.getBoost(factionLevel); } @Override @@ -148,26 +67,16 @@ public boolean isInFactionChest(Player player, String id) { @Override public int getSize(String id) { - try { - Set invoke = (Set) getWhereAlt.invoke(Factions.getInstance().getFactionById(id), false); - if (invoke == null) return 0; - return invoke.size(); - } catch (IllegalAccessException | InvocationTargetException exc) { - return 0; - } + Faction faction = Factions.getInstance().getFactionById(id); + Set set = faction.getFPlayersWhereAlt(false); + return (set == null) ? 0 : set.size(); } @Override public Inventory getChestInventory(Player player, String id) { Faction faction = Factions.getInstance().getFactionById(id); - if (faction == null) return null; - try { - return (Inventory) getInventory.invoke(faction); - } catch (IllegalAccessException | InvocationTargetException exc) { - - } - return null; + return faction.getInventory(); } @Override @@ -183,13 +92,7 @@ public boolean isShieldActive(String id) { @Override public boolean isAlt(Player player) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - - try { - return (boolean) isAlt.invoke(fPlayer); - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } - return false; + return fPlayer.isAlt(); } @EventHandler diff --git a/factions-joseph/build.gradle.kts b/factions-joseph/build.gradle.kts index a669d6f..20ca0ed 100644 --- a/factions-joseph/build.gradle.kts +++ b/factions-joseph/build.gradle.kts @@ -7,5 +7,5 @@ dependencies { compileOnly(project(":common")) compileOnly("com.massivecraft:Factions-Joseph:2.13.7") compileOnly("com.golfing8:FactionsKore:1.3.56.1") - compileOnly("com.massivecraft:massivecore:2.14.0") + compileOnly("com.massivecraft:MassiveCore:2.14.0") } \ No newline at end of file diff --git a/factions-mc1.20/build.gradle.kts b/factions-mc1.20/build.gradle.kts index 878f02a..05e6e59 100644 --- a/factions-mc1.20/build.gradle.kts +++ b/factions-mc1.20/build.gradle.kts @@ -6,5 +6,5 @@ dependencies { // Unique dependencies for this module compileOnly(project(":common")) compileOnly("com.massivecraft:Factions-MC1.20:2.13.7") - compileOnly("com.massivecraft:massivecore:2.14.0") + compileOnly("com.massivecraft:MassiveCore:2.14.0") } \ No newline at end of file diff --git a/factions-newuuid/src/main/java/com/kamikazejam/factionintegrations/integrations/NewUUIDIntegration.java b/factions-newuuid/src/main/java/com/kamikazejam/factionintegrations/integrations/NewUUIDIntegration.java index cec9100..65aacfc 100644 --- a/factions-newuuid/src/main/java/com/kamikazejam/factionintegrations/integrations/NewUUIDIntegration.java +++ b/factions-newuuid/src/main/java/com/kamikazejam/factionintegrations/integrations/NewUUIDIntegration.java @@ -7,8 +7,9 @@ import com.massivecraft.factions.*; import com.massivecraft.factions.data.MemoryFaction; import com.massivecraft.factions.event.*; -import com.massivecraft.factions.iface.RelationParticipator; +import com.massivecraft.factions.listeners.FactionsBlockListener; import com.massivecraft.factions.perms.PermSelector; +import com.massivecraft.factions.perms.PermissibleActions; import com.massivecraft.factions.perms.Relation; import com.massivecraft.factions.perms.Role; import com.massivecraft.factions.perms.selector.RelationAtLeastSelector; @@ -18,15 +19,16 @@ import org.bukkit.inventory.Inventory; import org.bukkit.scheduler.BukkitRunnable; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.*; /** * Integration for newer versions of FactionsUUID. */ +@SuppressWarnings("deprecation") public class NewUUIDIntegration implements KFaction { + public NewUUIDIntegration() {} + @EventHandler public void onFactionCreate(FactionCreateEvent e) { Bukkit.getPluginManager().callEvent(new KFactionCreateEvent(e.getFaction().getId())); @@ -109,61 +111,6 @@ public void onJoin(FPlayerLeaveEvent e) { } } - private Method canBuild; - - private Method getRole; - - private Object permissibleConstant; - - private Method relationTo, setRole, setPermissions; - - private Object leader, coleader, moderator, normal, recruit; - - public NewUUIDIntegration() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException { - Class permissibleEnum = Class.forName("com.massivecraft.factions.perms.PermissibleActions"); - Class permissibleClass = Class.forName("com.massivecraft.factions.perms.PermissibleAction"); - - for (Object object : permissibleEnum.getEnumConstants()) { - if (object.toString().equals("BUILD")) { - permissibleConstant = object; - break; - } - } - - relationTo = RelationParticipator.class.getMethod("getRelationTo", RelationParticipator.class); - - getRole = FPlayer.class.getMethod("getRole"); - - Class roleClass = Class.forName("com.massivecraft.factions.perms.Role"); - - setRole = FPlayer.class.getMethod("setRole", roleClass); - - for (Object type : roleClass.getEnumConstants()) { - String toString = ((Enum) type).name(); - switch (toString.toUpperCase()) { - case "LEADER": - case "ADMIN": - leader = type; - break; - case "COLEADER": - coleader = type; - break; - case "MODERATOR": - moderator = type; - break; - case "NORMAL": - normal = type; - break; - case "RECRUIT": - recruit = type; - } - } - - setPermissions = MemoryFaction.class.getMethod("setPermissions", LinkedHashMap.class); - - canBuild = Class.forName("com.massivecraft.factions.listeners.FactionsBlockListener").getMethod("playerCanBuildDestroyBlock", Player.class, Location.class, permissibleClass, boolean.class); - } - @Override public void setTnT(String id, long amount) { Faction faction = Factions.getInstance().getFactionById(id); @@ -264,11 +211,7 @@ public boolean isSystemFac(String id) { @Override public boolean playerCanBuildThere(Player player, Location location) { - try { - return (boolean) canBuild.invoke(null, player, location, permissibleConstant, true); - } catch (IllegalAccessException | InvocationTargetException e) { - return false; - } + return FactionsBlockListener.playerCanBuildDestroyBlock(player, location, PermissibleActions.BUILD, true); } @Override @@ -323,11 +266,6 @@ public int getClaimsInWorld(String id, World world) { return Board.getInstance().getFactionCoordCountInWorld(Factions.getInstance().getFactionById(id), world.getName()); } - @Override - public int getStrikes(String id) { - return 0; - } - @Override public int getMaxPlayers(String id) { return FactionsPlugin.getInstance().conf().factions().other().getFactionMemberLimit(); @@ -376,78 +314,47 @@ public void setFaction(OfflinePlayer player, String id) { public void setRole(Player player, TranslatedRole translatedRole) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - try { - switch (translatedRole.getValue()) { - case 1: - setRole.invoke(fPlayer, recruit); - break; - case 2: - setRole.invoke(fPlayer, normal); - break; - case 3: - setRole.invoke(fPlayer, moderator); - break; - case 4: - setRole.invoke(fPlayer, coleader); - break; - case 5: - setRole.invoke(fPlayer, leader); - break; - } - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } + setFPlayerRole(translatedRole, fPlayer); } @Override public void setRole(OfflinePlayer offlinePlayer, TranslatedRole translatedRole) { FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(offlinePlayer); - try { - switch (translatedRole.getValue()) { - case 1: - setRole.invoke(fPlayer, recruit); - break; - case 2: - setRole.invoke(fPlayer, normal); - break; - case 3: - setRole.invoke(fPlayer, moderator); - break; - case 4: - setRole.invoke(fPlayer, coleader); - break; - case 5: - setRole.invoke(fPlayer, leader); - break; - } - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } + setFPlayerRole(translatedRole, fPlayer); } - @Override - public void setPermission(String id, TranslatedRelation relation, String permission, boolean b) { - Faction faction = Factions.getInstance().getFactionById(id); - - Relation rel = null; - - switch (relation) { - case MEMBER: - rel = Relation.MEMBER; + private void setFPlayerRole(TranslatedRole translatedRole, FPlayer fPlayer) { + switch (translatedRole.getValue()) { + case 1: + fPlayer.setRole(Role.RECRUIT); + break; + case 2: + fPlayer.setRole(Role.NORMAL); break; - case ENEMY: - rel = Relation.ENEMY; + case 3: + fPlayer.setRole(Role.MODERATOR); break; - case NEUTRAL: - rel = Relation.NEUTRAL; + case 4: + fPlayer.setRole(Role.COLEADER); break; - case ALLY: - rel = Relation.ALLY; + case 5: + fPlayer.setRole(Role.ADMIN); break; - case TRUCE: - rel = Relation.TRUCE; } + } + + @Override + public void setPermission(String id, TranslatedRelation relation, String permission, boolean b) { + MemoryFaction faction = (MemoryFaction) Factions.getInstance().getFactionById(id); + + Relation rel = switch (relation) { + case MEMBER -> Relation.MEMBER; + case ENEMY -> Relation.ENEMY; + case NEUTRAL -> Relation.NEUTRAL; + case ALLY -> Relation.ALLY; + case TRUCE -> Relation.TRUCE; + }; LinkedHashMap> permissions = new LinkedHashMap<>(); RelationAtLeastSelector key = new RelationAtLeastSelector(rel); @@ -455,11 +362,7 @@ public void setPermission(String id, TranslatedRelation relation, String permiss old.put(permission, b); permissions.put(key, old); - try { - setPermissions.invoke(faction, permissions); - } catch (Exception ignored) { - - } + faction.setPermissions(permissions); } @Override @@ -588,25 +491,14 @@ public String getWilderness() { @Override public String getRolePrefix(TranslatedRole translatedRole) { - String toReturn = ""; - switch (translatedRole.getValue()) { - case 1: - toReturn = FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getRecruit(); - break; - case 2: - toReturn = FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getNormal(); - break; - case 3: - toReturn = FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getMod(); - break; - case 4: - toReturn = FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getColeader(); - break; - case 5: - toReturn = FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getAdmin(); - break; - } - return toReturn; + return switch (translatedRole.getValue()) { + case 1 -> FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getRecruit(); + case 2 -> FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getNormal(); + case 3 -> FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getMod(); + case 4 -> FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getColeader(); + case 5 -> FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getAdmin(); + default -> ""; + }; } @Override @@ -702,44 +594,25 @@ public boolean isWildernessAt(Location location) { public TranslatedRelation getRelationToFaction(Player player, String id) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); Faction faction = Factions.getInstance().getFactionById(id); - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(fPlayer, faction)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - return TranslatedRelation.ENEMY; - } + return TranslatedRelation.valueOf(fPlayer.getRelationTo(faction).name().toUpperCase()); } @Override public TranslatedRole getRole(Player player) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override public TranslatedRole getRole(OfflinePlayer player) { FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(player); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override public TranslatedRole getRole(UUID uuid) { FPlayer fPlayer = FPlayers.getInstance().getById(uuid.toString()); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override @@ -747,24 +620,14 @@ public TranslatedRelation getFactionRelationToFaction(String id1, String id2) { Faction faction1 = Factions.getInstance().getFactionById(id1); Faction faction2 = Factions.getInstance().getFactionById(id2); if (faction1 == null || faction2 == null) return TranslatedRelation.ENEMY; - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(faction1, faction2)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return TranslatedRelation.ENEMY; + return TranslatedRelation.valueOf(faction1.getRelationTo(faction2).name().toUpperCase()); } @Override public TranslatedRelation getRelationToPlayer(Player player, Player player2) { FPlayer fPlayer1 = FPlayers.getInstance().getByPlayer(player); FPlayer fPlayer2 = FPlayers.getInstance().getByPlayer(player2); - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(fPlayer1, fPlayer2)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return TranslatedRelation.ENEMY; + return TranslatedRelation.valueOf(fPlayer1.getRelationTo(fPlayer2).name().toUpperCase()); } @Override diff --git a/factions-saber/src/main/java/com/kamikazejam/factionintegrations/integrations/SaberFactionsIntegration.java b/factions-saber/src/main/java/com/kamikazejam/factionintegrations/integrations/SaberFactionsIntegration.java index e4b4aa7..b935668 100644 --- a/factions-saber/src/main/java/com/kamikazejam/factionintegrations/integrations/SaberFactionsIntegration.java +++ b/factions-saber/src/main/java/com/kamikazejam/factionintegrations/integrations/SaberFactionsIntegration.java @@ -5,19 +5,25 @@ import com.kamikazejam.factionintegrations.object.TranslatedRole; import com.kamikazejam.factionintegrations.utils.PluginSource; import com.massivecraft.factions.*; +import com.massivecraft.factions.cmd.CmdJoin; import com.massivecraft.factions.event.*; -import com.massivecraft.factions.iface.RelationParticipator; +import com.massivecraft.factions.listeners.FactionsBlockListener; +import com.massivecraft.factions.struct.Relation; +import com.massivecraft.factions.struct.Role; +import com.massivecraft.factions.zcore.fperms.Access; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import org.bukkit.*; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.inventory.Inventory; import org.bukkit.scheduler.BukkitRunnable; -import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.*; +// A minimal amount of reflection is required for a certain method inside of CmdJoin +@SuppressWarnings("deprecation") public class SaberFactionsIntegration implements KFaction { @EventHandler @@ -73,12 +79,7 @@ public void onLandUnclaimallEvent(LandUnclaimAllEvent e) { @Override public boolean isRelationColorsEnabled() { - try { - return (boolean) chatTagRelationColored.get(null); - } catch (IllegalAccessException ignored) { - - } - return true; + return Conf.chatTagRelationColored; } @EventHandler @@ -129,279 +130,81 @@ public void onJoin(FPlayerLeaveEvent e) { } } - private Method getLimit; - private Method add; - private Method setTnt; - private Method take; - private Method getBalance; - - private Method getRole; - - private Method getOnlinePlayers; - - private Method relationTo; - - private Method canBuild; - - private Method chestInventory; - - private Method getStrikes, setRole; - - private Method setFaction; - - private Object leader, coleader, moderator, normal, recruit; - - private Method maxMembers; - - private Field leaderP, coleaderP, moderatorP, normalP, recruitP; - - private Field econEnabled; - - private Object cmdJoin; - - private Field chatTagRelationColored; - - private Method getMoneyBalance, setMoneyBalance; - - private Method isAlt; - - public SaberFactionsIntegration() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException, InvocationTargetException { - Class factionClass = Class.forName("com.massivecraft.factions.Faction"); - - getLimit = factionClass.getMethod("getTntBankLimit"); - - chestInventory = factionClass.getMethod("getChestInventory"); - - add = factionClass.getMethod("addTnt", int.class); - - take = factionClass.getMethod("takeTnt", int.class); - - getBalance = factionClass.getMethod("getTnt"); - - setTnt = factionClass.getMethod("setTnt", long.class); - - getMoneyBalance = factionClass.getMethod("getFactionBalance"); - - setMoneyBalance = factionClass.getMethod("setFactionBalance", double.class); - - getStrikes = factionClass.getMethod("getStrikes"); - - getOnlinePlayers = Faction.class.getMethod("getOnlinePlayers"); - - relationTo = RelationParticipator.class.getMethod("getRelationTo", RelationParticipator.class); - - getRole = FPlayer.class.getMethod("getRole"); - - isAlt = FPlayer.class.getMethod("isAlt"); - - Class roleClass = Class.forName("com.massivecraft.factions.struct.Role"); - - setRole = FPlayer.class.getMethod("setRole", roleClass); - - setFaction = FPlayer.class.getMethod("setFaction", Faction.class, boolean.class); - - maxMembers = Class.forName("com.massivecraft.factions.cmd.CmdJoin").getDeclaredMethod("getFactionMemberLimit", Class.forName("com.massivecraft.factions.Faction")); - - Class aClass = Class.forName("com.massivecraft.factions.FactionsPlugin"); - - Object main = aClass.getField("instance").get(null); - - Object cmdBase = aClass.getField("cmdBase").get(main); - - Field cmdJoinField = cmdBase.getClass().getField("cmdJoin"); - - cmdJoin = cmdJoinField.get(cmdBase); - + private final Method maxMembers; + public SaberFactionsIntegration() throws NoSuchMethodException { + maxMembers = CmdJoin.class.getDeclaredMethod("getFactionMemberLimit", Faction.class); maxMembers.setAccessible(true); - - for (Object type : roleClass.getEnumConstants()) { - String toString = ((Enum) type).name(); - switch (toString.toUpperCase()) { - case "LEADER": - case "ADMIN": - leader = type; - break; - case "COLEADER": - coleader = type; - break; - case "MODERATOR": - moderator = type; - break; - case "NORMAL": - normal = type; - break; - case "RECRUIT": - recruit = type; - } - } - - Class confClass = Class.forName("com.massivecraft.factions.Conf"); - - leaderP = confClass.getField("prefixLeader"); - coleaderP = confClass.getField("prefixCoLeader"); - moderatorP = confClass.getField("prefixMod"); - normalP = confClass.getField("prefixNormal"); - recruitP = confClass.getField("prefixRecruit"); - - chatTagRelationColored = confClass.getField("chatTagRelationColored"); - - econEnabled = confClass.getField("econEnabled"); - - canBuild = Class.forName("com.massivecraft.factions.listeners.FactionsBlockListener") - .getMethod("playerCanBuildDestroyBlock", Player.class, Location.class, String.class, boolean.class); - - Class permissableClass = Class.forName("com.massivecraft.factions.zcore.fperms.Permissable"); - Class accessClass = Class.forName("com.massivecraft.factions.zcore.fperms.Access"); - - Class relationClass = Class.forName("com.massivecraft.factions.struct.Relation"); - - valueOfRelation = relationClass.getMethod("valueOf", String.class); - - allowObject = accessClass.getMethod("valueOf", String.class).invoke(null, "ALLOW"); - - Class permissableActionClass = Class.forName("com.massivecraft.factions.zcore.fperms.PermissableAction"); - - valueOf = permissableActionClass.getMethod("valueOf", String.class); - - setPermission = Faction.class.getMethod("setPermission", permissableClass, permissableActionClass, accessClass); - setRelationWish = Faction.class.getMethod("setRelationWish", Faction.class, relationClass); } - private Object allowObject; - - private Method valueOf; - - private Method valueOfRelation; - - private Method setPermission; - - private Method setRelationWish; - @Override public void setTnT(String id, long amount) { - try { - Faction faction = Factions.getInstance().getFactionById(id); - setTnt.invoke(faction, (int) amount); - } catch (IllegalAccessException | InvocationTargetException e) { - Bukkit.getLogger().severe("Error setting tnt bank balance!"); - } + Factions.getInstance().getFactionById(id).setTnt(amount); } @Override public long addTnT(String id, long amount) { - try { - Faction faction = Factions.getInstance().getFactionById(id); - long totalAmount = ((Number) getBalance.invoke(faction)).longValue(); - - long limit = ((Number) getLimit.invoke(faction)).longValue(); + Faction faction = Factions.getInstance().getFactionById(id); + long totalAmount = faction.getTnt(); + long limit = faction.getTntBankLimit(); - if (amount + totalAmount > limit) { - add.invoke(faction, (int) (limit - totalAmount)); - return (int) (limit - totalAmount); - } - add.invoke(faction, (int) amount); - return amount; - } catch (IllegalAccessException | InvocationTargetException e) { - Bukkit.getLogger().severe("Error setting tnt bank balance!"); + if (amount + totalAmount > limit) { + int add = (int) (limit - totalAmount); + faction.addTnt(add); + return add; } - return 0; + faction.addTnt((int) amount); + return amount; } @Override public long getTnT(String id) { - try { - Faction faction = Factions.getInstance().getFactionById(id); - return ((Number) getBalance.invoke(faction)).longValue(); - } catch (IllegalAccessException | InvocationTargetException e) { - Bukkit.getLogger().severe("Error getting tnt bank balance!"); - } - return 0; + return Factions.getInstance().getFactionById(id).getTnt(); } @Override public long getMaxTnt(String id) { - try { - Faction faction = Factions.getInstance().getFactionById(id); - return ((Number) getLimit.invoke(faction)).longValue(); - } catch (IllegalAccessException | InvocationTargetException e) { - Bukkit.getLogger().severe("Error getting tnt bank limit!"); - } - return Integer.MAX_VALUE; + return Factions.getInstance().getFactionById(id).getTntBankLimit(); } @Override public int getStrikes(String id) { - try { - Faction faction = Factions.getInstance().getFactionById(id); - - if (faction == null) return 0; + Faction faction = Factions.getInstance().getFactionById(id); + if (faction == null) return 0; - return (int) getStrikes.invoke(faction); - } catch (IllegalAccessException | InvocationTargetException e) { - Bukkit.getLogger().severe("Error getting faction strikes!"); - } - return 0; + return faction.getStrikes(); } @Override public double getBalance(String id) { Faction faction = Factions.getInstance().getFactionById(id); - - try { - return (double) getMoneyBalance.invoke(faction); - } catch (Exception ignored) { - - } - return 0; + return faction.getFactionBalance(); } @Override public void addBalance(String id, double add) { Faction faction = Factions.getInstance().getFactionById(id); - - try { - setMoneyBalance.invoke(faction, (double) getMoneyBalance.invoke(faction) + add); - } catch (Exception ignored) { - - } + faction.setFactionBalance(faction.getFactionBalance() + add); } @Override public void subtractBalance(String id, double remove) { Faction faction = Factions.getInstance().getFactionById(id); - - try { - setMoneyBalance.invoke(faction, (double) getMoneyBalance.invoke(faction) - remove); - } catch (Exception ignored) { - - } + faction.setFactionBalance(faction.getFactionBalance() - remove); } @Override public boolean econEnabled() { - try { - return (boolean) econEnabled.get(null); - } catch (IllegalAccessException ignored) { - - } - return false; + return Conf.econEnabled; } @Override public boolean isAlt(Player player) { - try { - FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - return (boolean) isAlt.invoke(fPlayer); - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } - return false; + return FPlayers.getInstance().getByPlayer(player).isAlt(); } @Override public boolean canPlayerBuildThere(Player player, Chunk chunk) { if (isBypassing(player)) return true; - Faction faction = Board.getInstance().getFactionAt(new FLocation(player.getWorld().getName(), chunk.getX(), chunk.getZ())); if (faction.isWilderness()) return true; @@ -422,11 +225,7 @@ public boolean isSystemFac(String id) { @Override public boolean playerCanBuildThere(Player player, Location location) { - try { - return (boolean) canBuild.invoke(null, player, location, "build", false); - } catch (IllegalAccessException | InvocationTargetException e) { - return false; - } + return FactionsBlockListener.playerCanBuildDestroyBlock(player, location, "build", false); } @Override @@ -483,11 +282,11 @@ public int getClaimsInWorld(String id, World world) { @Override public int getMaxPlayers(String id) { + CmdJoin cmdJoin = FactionsPlugin.instance.cmdBase.cmdJoin; + Faction faction = Factions.getInstance().getFactionById(id); try { - return (int) maxMembers.invoke(cmdJoin, Factions.getInstance().getFactionById(id)); - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } + return (int) maxMembers.invoke(cmdJoin, faction); + } catch (IllegalAccessException | InvocationTargetException ignored) {} return 0; } @@ -499,13 +298,7 @@ public int getSize(String id) { @Override public boolean isInFactionChest(Player player, String id) { Faction faction = Factions.getInstance().getFactionById(id); - - try { - return ((Inventory) chestInventory.invoke(faction)).getViewers().contains(player); - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } - return false; + return faction.getChestInventory().getViewers().contains(player); } @Override @@ -522,11 +315,7 @@ public void setFaction(Player player, String id) { return; } - try { - setFaction.invoke(fPlayer, Factions.getInstance().getFactionById(id), false); - } catch (Exception exc) { - exc.printStackTrace(); - } + fPlayer.setFaction(Factions.getInstance().getFactionById(id), false); } @Override @@ -538,64 +327,38 @@ public void setFaction(OfflinePlayer player, String id) { return; } - try { - setFaction.invoke(fPlayer, Factions.getInstance().getFactionById(id), false); - } catch (Exception exc) { - exc.printStackTrace(); - } + fPlayer.setFaction(Factions.getInstance().getFactionById(id), false); } @Override public void setRole(Player player, TranslatedRole translatedRole) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - - try { - switch (translatedRole.getValue()) { - case 1: - setRole.invoke(fPlayer, recruit); - break; - case 2: - setRole.invoke(fPlayer, normal); - break; - case 3: - setRole.invoke(fPlayer, moderator); - break; - case 4: - setRole.invoke(fPlayer, coleader); - break; - case 5: - setRole.invoke(fPlayer, leader); - break; - } - } catch (IllegalAccessException | InvocationTargetException exc) { - exc.printStackTrace(); - } + setFPlayerRole(translatedRole, fPlayer); } @Override public void setRole(OfflinePlayer offlinePlayer, TranslatedRole translatedRole) { FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(offlinePlayer); + setFPlayerRole(translatedRole, fPlayer); + } - try { - switch (translatedRole.getValue()) { - case 1: - setRole.invoke(fPlayer, recruit); - break; - case 2: - setRole.invoke(fPlayer, normal); - break; - case 3: - setRole.invoke(fPlayer, moderator); - break; - case 4: - setRole.invoke(fPlayer, coleader); - break; - case 5: - setRole.invoke(fPlayer, leader); - break; - } - } catch (IllegalAccessException | InvocationTargetException exc) { - exc.printStackTrace(); + private void setFPlayerRole(TranslatedRole translatedRole, FPlayer fPlayer) { + switch (translatedRole.getValue()) { + case 1: + fPlayer.setRole(Role.RECRUIT); + break; + case 2: + fPlayer.setRole(Role.NORMAL); + break; + case 3: + fPlayer.setRole(Role.MODERATOR); + break; + case 4: + fPlayer.setRole(Role.COLEADER); + break; + case 5: + fPlayer.setRole(Role.LEADER); + break; } } @@ -603,62 +366,31 @@ public void setRole(OfflinePlayer offlinePlayer, TranslatedRole translatedRole) public void setPermission(String id, TranslatedRelation relation, String permission, boolean b) { Faction faction = Factions.getInstance().getFactionById(id); - try { - Object rel = null; - - switch (relation) { - case MEMBER: - rel = valueOfRelation.invoke(null, "MEMBER"); - break; - case ENEMY: - rel = valueOfRelation.invoke(null, "ENEMY"); - break; - case NEUTRAL: - rel = valueOfRelation.invoke(null, "NEUTRAL"); - break; - case ALLY: - rel = valueOfRelation.invoke(null, "ALLY"); - break; - case TRUCE: - rel = valueOfRelation.invoke(null, "TRUCE"); - } + Relation rel = switch (relation) { + case MEMBER -> Relation.MEMBER; + case ENEMY -> Relation.ENEMY; + case NEUTRAL -> Relation.NEUTRAL; + case ALLY -> Relation.ALLY; + case TRUCE -> Relation.TRUCE; + }; - setPermission.invoke(faction, rel, valueOf.invoke(null, permission), allowObject); - } catch (Exception exc) { - exc.printStackTrace(); - } + faction.setPermission(rel, PermissableAction.valueOf(permission), (b) ? Access.ALLOW : Access.DENY); } @Override public void setRelationWish(String id, String other, TranslatedRelation relation) { Faction a = Factions.getInstance().getFactionById(id); - Faction b = Factions.getInstance().getFactionById(other); - try { - Object rel = null; - - switch (relation) { - case MEMBER: - rel = valueOfRelation.invoke(null, "MEMBER"); - break; - case ENEMY: - rel = valueOfRelation.invoke(null, "ENEMY"); - break; - case NEUTRAL: - rel = valueOfRelation.invoke(null, "NEUTRAL"); - break; - case ALLY: - rel = valueOfRelation.invoke(null, "ALLY"); - break; - case TRUCE: - rel = valueOfRelation.invoke(null, "TRUCE"); - } + Relation rel = switch (relation) { + case MEMBER -> Relation.MEMBER; + case ENEMY -> Relation.ENEMY; + case NEUTRAL -> Relation.NEUTRAL; + case ALLY -> Relation.ALLY; + case TRUCE -> Relation.TRUCE; + }; - setRelationWish.invoke(a, b, rel); - } catch (Exception exc) { - exc.printStackTrace(); - } + a.setRelationWish(b, rel); } @Override @@ -725,13 +457,7 @@ public Map> getAllClaims(String id) { @Override public Inventory getChestInventory(Player player, String id) { Faction faction = Factions.getInstance().getFactionById(id); - - try { - return (Inventory) chestInventory.invoke(faction); - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } - return null; + return faction.getChestInventory(); } @Override @@ -787,29 +513,14 @@ public String getWilderness() { @Override public String getRolePrefix(TranslatedRole translatedRole) { - String toReturn = ""; - try { - switch (translatedRole) { - case RECRUIT: - toReturn = (String) recruitP.get(null); - break; - case NORMAL: - toReturn = (String) normalP.get(null); - break; - case MODERATOR: - toReturn = (String) moderatorP.get(null); - break; - case COLEADER: - toReturn = (String) coleaderP.get(null); - break; - case ADMIN: - toReturn = (String) leaderP.get(null); - break; - } - } catch (IllegalAccessException ignored) { - - } - return toReturn; + return switch (translatedRole) { + case RECRUIT -> Conf.prefixRecruit; + case NORMAL -> Conf.prefixNormal; + case MODERATOR -> Conf.prefixMod; + case COLEADER -> Conf.prefixCoLeader; + case ADMIN -> Conf.prefixLeader; + default -> ""; + }; } @Override @@ -911,44 +622,25 @@ public boolean isWildernessAt(Location location) { public TranslatedRelation getRelationToFaction(Player player, String id) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); Faction faction = Factions.getInstance().getFactionById(id); - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(fPlayer, faction)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - return TranslatedRelation.ENEMY; - } + return TranslatedRelation.valueOf(fPlayer.getRelationTo(faction).name().toUpperCase()); } @Override public TranslatedRole getRole(Player player) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override public TranslatedRole getRole(OfflinePlayer player) { FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(player); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override public TranslatedRole getRole(UUID uuid) { FPlayer fPlayer = FPlayers.getInstance().getById(uuid.toString()); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override @@ -956,24 +648,14 @@ public TranslatedRelation getFactionRelationToFaction(String id1, String id2) { Faction faction1 = Factions.getInstance().getFactionById(id1); Faction faction2 = Factions.getInstance().getFactionById(id2); if (faction1 == null || faction2 == null) return TranslatedRelation.ENEMY; - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(faction1, faction2)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return TranslatedRelation.ENEMY; + return TranslatedRelation.valueOf(faction1.getRelationTo(faction2).name().toUpperCase()); } @Override public TranslatedRelation getRelationToPlayer(Player player, Player player2) { FPlayer fPlayer1 = FPlayers.getInstance().getByPlayer(player); FPlayer fPlayer2 = FPlayers.getInstance().getByPlayer(player2); - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(fPlayer1, fPlayer2)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return TranslatedRelation.ENEMY; + return TranslatedRelation.valueOf(fPlayer1.getRelationTo(fPlayer2).name().toUpperCase()); } @Override diff --git a/factions-saberx/src/main/java/com/kamikazejam/factionintegrations/integrations/SaberFactionsXIntegration.java b/factions-saberx/src/main/java/com/kamikazejam/factionintegrations/integrations/SaberFactionsXIntegration.java index 017e8df..ff183ad 100644 --- a/factions-saberx/src/main/java/com/kamikazejam/factionintegrations/integrations/SaberFactionsXIntegration.java +++ b/factions-saberx/src/main/java/com/kamikazejam/factionintegrations/integrations/SaberFactionsXIntegration.java @@ -6,15 +6,20 @@ import com.kamikazejam.factionintegrations.shield.ShieldIntegration; import com.kamikazejam.factionintegrations.utils.PluginSource; import com.massivecraft.factions.*; +import com.massivecraft.factions.cmd.CmdJoin; import com.massivecraft.factions.event.*; -import com.massivecraft.factions.iface.RelationParticipator; +import com.massivecraft.factions.listeners.FactionsBlockListener; +import com.massivecraft.factions.struct.Relation; +import com.massivecraft.factions.struct.Role; +import com.massivecraft.factions.util.FastChunk; +import com.massivecraft.factions.zcore.fperms.Access; +import com.massivecraft.factions.zcore.fperms.PermissableAction; import org.bukkit.*; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.inventory.Inventory; import org.bukkit.scheduler.BukkitRunnable; -import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.*; @@ -61,12 +66,7 @@ public void onLandUnclaimallEvent(LandUnclaimAllEvent e) { @Override public boolean isRelationColorsEnabled() { - try { - return (boolean) chatTagRelationColored.get(null); - } catch (IllegalAccessException ignored) { - - } - return true; + return Conf.chatTagRelationColored; } @EventHandler @@ -117,290 +117,83 @@ public void onJoin(FPlayerLeaveEvent e) { } } - private Method getLimit; - private Method add; - private Method take; - private Method getBalance; - - private Method getRole; - - private Method getOnlinePlayers; - - private Method relationTo; - - private Method canBuild; - - private Method chestInventory; - - private Method getStrikes, setRole; - - private Method setFaction; - - private Object leader, coleader, moderator, normal, recruit; - - private Method maxMembers; - - private Field leaderP, coleaderP, moderatorP, normalP, recruitP; - - private Field econEnabled; - - private Object cmdJoin; - - private Field chatTagRelationColored; - - private Method getMoneyBalance, setMoneyBalance; - - private Method isProtectedFaction; - private Method getBaseRegion; - - private Method getXFastChunk, getZFastChunk; - - private Method isAlt; - - public SaberFactionsXIntegration() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException, InvocationTargetException { - Class factionClass = Class.forName("com.massivecraft.factions.Faction"); - - Class fastChunkClass = Class.forName("com.massivecraft.factions.util.FastChunk"); - - getXFastChunk = fastChunkClass.getMethod("getX"); - getZFastChunk = fastChunkClass.getMethod("getZ"); - - getLimit = factionClass.getMethod("getTntBankLimit"); - - chestInventory = factionClass.getMethod("getChestInventory"); - - isProtectedFaction = factionClass.getMethod("isProtected"); - - getBaseRegion = factionClass.getMethod("getBaseRegion"); - - add = factionClass.getMethod("addTnt", int.class); - - take = factionClass.getMethod("takeTnt", int.class); - - try { - isAlt = FPlayer.class.getMethod("isAlt"); - } catch (Exception ignored) { - - } - - getBalance = factionClass.getMethod("getTnt"); - - getMoneyBalance = factionClass.getMethod("getFactionBalance"); - - setMoneyBalance = factionClass.getMethod("setFactionBalance", double.class); - - getStrikes = factionClass.getMethod("getStrikes"); - - getOnlinePlayers = Faction.class.getMethod("getOnlinePlayers"); - - relationTo = RelationParticipator.class.getMethod("getRelationTo", RelationParticipator.class); - - getRole = FPlayer.class.getMethod("getRole"); - - Class roleClass = Class.forName("com.massivecraft.factions.struct.Role"); - - setRole = FPlayer.class.getMethod("setRole", roleClass); - - setFaction = FPlayer.class.getMethod("setFaction", Faction.class, boolean.class); - - maxMembers = Class.forName("com.massivecraft.factions.cmd.CmdJoin").getDeclaredMethod("getFactionMemberLimit", Class.forName("com.massivecraft.factions.Faction")); - - Class aClass = Class.forName("com.massivecraft.factions.FactionsPlugin"); - - Object main = aClass.getField("instance").get(null); - - Object cmdBase = aClass.getField("cmdBase").get(main); - - Field cmdJoinField = cmdBase.getClass().getField("cmdJoin"); - - cmdJoin = cmdJoinField.get(cmdBase); - + private final Method maxMembers; + public SaberFactionsXIntegration() throws NoSuchMethodException { + maxMembers = CmdJoin.class.getDeclaredMethod("getFactionMemberLimit", Faction.class); maxMembers.setAccessible(true); - - for (Object type : roleClass.getEnumConstants()) { - String toString = ((Enum) type).name(); - switch (toString.toUpperCase()) { - case "LEADER": - case "ADMIN": - leader = type; - break; - case "COLEADER": - coleader = type; - break; - case "MODERATOR": - moderator = type; - break; - case "NORMAL": - normal = type; - break; - case "RECRUIT": - recruit = type; - } - } - - Class confClass = Class.forName("com.massivecraft.factions.Conf"); - - leaderP = confClass.getField("prefixLeader"); - coleaderP = confClass.getField("prefixCoLeader"); - moderatorP = confClass.getField("prefixMod"); - normalP = confClass.getField("prefixNormal"); - recruitP = confClass.getField("prefixRecruit"); - - chatTagRelationColored = confClass.getField("chatTagRelationColored"); - - econEnabled = confClass.getField("econEnabled"); - - canBuild = Class.forName("com.massivecraft.factions.listeners.FactionsBlockListener") - .getMethod("playerCanBuildDestroyBlock", Player.class, Location.class, String.class, boolean.class); - - Class permissableClass = Class.forName("com.massivecraft.factions.zcore.fperms.Permissable"); - Class accessClass = Class.forName("com.massivecraft.factions.zcore.fperms.Access"); - - Class relationClass = Class.forName("com.massivecraft.factions.struct.Relation"); - - valueOfRelation = relationClass.getMethod("valueOf", String.class); - - allowObject = accessClass.getMethod("valueOf", String.class).invoke(null, "ALLOW"); - - Class permissableActionClass = Class.forName("com.massivecraft.factions.zcore.fperms.PermissableAction"); - - valueOf = permissableActionClass.getMethod("valueOf", String.class); - - setPermission = Faction.class.getMethod("setPermission", permissableClass, permissableActionClass, accessClass); - setRelationWish = Faction.class.getMethod("setRelationWish", Faction.class, relationClass); } - private Object allowObject; - - private Method valueOf; - - private Method valueOfRelation; - - private Method setPermission; - - private Method setRelationWish; - @Override public void setTnT(String id, long amount) { - try { - Faction faction = Factions.getInstance().getFactionById(id); - int limit = (int) getLimit.invoke(faction); + Faction faction = Factions.getInstance().getFactionById(id); + int limit = faction.getTntBankLimit(); - take.invoke(faction, getBalance.invoke(faction)); - if (amount > limit) { - add.invoke(faction, limit); - return; - } - add.invoke(faction, (int) amount); - } catch (IllegalAccessException | InvocationTargetException e) { - Bukkit.getLogger().severe("Error setting tnt bank balance!"); + faction.takeTnt(faction.getTnt()); + if (amount > limit) { + faction.addTnt(limit); + return; } + faction.addTnt((int) amount); } @Override public long addTnT(String id, long amount) { - try { - Faction faction = Factions.getInstance().getFactionById(id); - int totalAmount = (int) getBalance.invoke(faction); - - int limit = (int) getLimit.invoke(faction); + Faction faction = Factions.getInstance().getFactionById(id); + int totalAmount = faction.getTnt(); + int limit = faction.getTntBankLimit(); - if (amount + totalAmount > limit) { - add.invoke(faction, limit - totalAmount); - return limit - totalAmount; - } - add.invoke(faction, (int) amount); - return amount; - } catch (IllegalAccessException | InvocationTargetException e) { - Bukkit.getLogger().severe("Error setting tnt bank balance!"); + if (amount + totalAmount > limit) { + faction.addTnt(limit - totalAmount); + return limit - totalAmount; } - return 0; + faction.addTnt((int) amount); + return amount; } @Override public long getTnT(String id) { - try { - Faction faction = Factions.getInstance().getFactionById(id); - return (int) getBalance.invoke(faction); - } catch (IllegalAccessException | InvocationTargetException e) { - Bukkit.getLogger().severe("Error getting tnt bank balance!"); - } - return 0; + return Factions.getInstance().getFactionById(id).getTnt(); } @Override public long getMaxTnt(String id) { - try { - Faction faction = Factions.getInstance().getFactionById(id); - return (int) getLimit.invoke(faction); - } catch (IllegalAccessException | InvocationTargetException e) { - Bukkit.getLogger().severe("Error getting tnt bank limit!"); - } - return Integer.MAX_VALUE; + return Factions.getInstance().getFactionById(id).getTntBankLimit(); } @Override public int getStrikes(String id) { - try { - Faction faction = Factions.getInstance().getFactionById(id); - - if (faction == null) return 0; + Faction faction = Factions.getInstance().getFactionById(id); + if (faction == null) return 0; - return (int) getStrikes.invoke(faction); - } catch (IllegalAccessException | InvocationTargetException e) { - Bukkit.getLogger().severe("Error getting faction strikes!"); - } - return 0; + return faction.getStrikes(); } @Override public double getBalance(String id) { Faction faction = Factions.getInstance().getFactionById(id); - - try { - return (double) getMoneyBalance.invoke(faction); - } catch (Exception ignored) { - - } - return 0; + return faction.getFactionBalance(); } @Override public void addBalance(String id, double add) { Faction faction = Factions.getInstance().getFactionById(id); - - try { - setMoneyBalance.invoke(faction, (double) getMoneyBalance.invoke(faction) + add); - } catch (Exception ignored) { - - } + faction.setFactionBalance(faction.getFactionBalance() + add); } @Override public void subtractBalance(String id, double remove) { Faction faction = Factions.getInstance().getFactionById(id); - - try { - setMoneyBalance.invoke(faction, (double) getMoneyBalance.invoke(faction) - remove); - } catch (Exception ignored) { - - } + faction.setFactionBalance(faction.getFactionBalance() - remove); } @Override public boolean econEnabled() { - try { - return (boolean) econEnabled.get(null); - } catch (IllegalAccessException ignored) { - - } - return false; + return Conf.econEnabled; } @Override public boolean canPlayerBuildThere(Player player, Chunk chunk) { if (isBypassing(player)) return true; - Faction faction = Board.getInstance().getFactionAt(new FLocation(player.getWorld().getName(), chunk.getX(), chunk.getZ())); if (faction.isWilderness()) return true; @@ -421,11 +214,7 @@ public boolean isSystemFac(String id) { @Override public boolean playerCanBuildThere(Player player, Location location) { - try { - return (boolean) canBuild.invoke(null, player, location, "build", false); - } catch (IllegalAccessException | InvocationTargetException e) { - return false; - } + return FactionsBlockListener.playerCanBuildDestroyBlock(player, location, "build", false); } @Override @@ -482,11 +271,11 @@ public int getClaimsInWorld(String id, World world) { @Override public int getMaxPlayers(String id) { + CmdJoin cmdJoin = FactionsPlugin.instance.cmdBase.cmdJoin; + Faction faction = Factions.getInstance().getFactionById(id); try { - return (int) maxMembers.invoke(cmdJoin, Factions.getInstance().getFactionById(id)); - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } + return (int) maxMembers.invoke(cmdJoin, faction); + } catch (IllegalAccessException | InvocationTargetException ignored) {} return 0; } @@ -498,13 +287,7 @@ public int getSize(String id) { @Override public boolean isInFactionChest(Player player, String id) { Faction faction = Factions.getInstance().getFactionById(id); - - try { - return ((Inventory) chestInventory.invoke(faction)).getViewers().contains(player); - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } - return false; + return faction.getChestInventory().getViewers().contains(player); } @Override @@ -520,12 +303,7 @@ public void setFaction(Player player, String id) { fPlayer.leave(false); return; } - - try { - setFaction.invoke(fPlayer, Factions.getInstance().getFactionById(id), false); - } catch (Exception exc) { - exc.printStackTrace(); - } + fPlayer.setFaction(Factions.getInstance().getFactionById(id), false); } @Override @@ -536,65 +314,38 @@ public void setFaction(OfflinePlayer player, String id) { fPlayer.leave(false); return; } - - try { - setFaction.invoke(fPlayer, Factions.getInstance().getFactionById(id), false); - } catch (Exception exc) { - exc.printStackTrace(); - } + fPlayer.setFaction(Factions.getInstance().getFactionById(id), false); } @Override public void setRole(Player player, TranslatedRole translatedRole) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - - try { - switch (translatedRole.getValue()) { - case 1: - setRole.invoke(fPlayer, recruit); - break; - case 2: - setRole.invoke(fPlayer, normal); - break; - case 3: - setRole.invoke(fPlayer, moderator); - break; - case 4: - setRole.invoke(fPlayer, coleader); - break; - case 5: - setRole.invoke(fPlayer, leader); - break; - } - } catch (IllegalAccessException | InvocationTargetException exc) { - exc.printStackTrace(); - } + setFPlayerRole(translatedRole, fPlayer); } @Override public void setRole(OfflinePlayer offlinePlayer, TranslatedRole translatedRole) { FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(offlinePlayer); + setFPlayerRole(translatedRole, fPlayer); + } - try { - switch (translatedRole.getValue()) { - case 1: - setRole.invoke(fPlayer, recruit); - break; - case 2: - setRole.invoke(fPlayer, normal); - break; - case 3: - setRole.invoke(fPlayer, moderator); - break; - case 4: - setRole.invoke(fPlayer, coleader); - break; - case 5: - setRole.invoke(fPlayer, leader); - break; - } - } catch (IllegalAccessException | InvocationTargetException exc) { - exc.printStackTrace(); + private void setFPlayerRole(TranslatedRole translatedRole, FPlayer fPlayer) { + switch (translatedRole.getValue()) { + case 1: + fPlayer.setRole(Role.RECRUIT); + break; + case 2: + fPlayer.setRole(Role.NORMAL); + break; + case 3: + fPlayer.setRole(Role.MODERATOR); + break; + case 4: + fPlayer.setRole(Role.COLEADER); + break; + case 5: + fPlayer.setRole(Role.LEADER); + break; } } @@ -602,62 +353,29 @@ public void setRole(OfflinePlayer offlinePlayer, TranslatedRole translatedRole) public void setPermission(String id, TranslatedRelation relation, String permission, boolean b) { Faction faction = Factions.getInstance().getFactionById(id); - try { - Object rel = null; - - switch (relation) { - case MEMBER: - rel = valueOfRelation.invoke(null, "MEMBER"); - break; - case ENEMY: - rel = valueOfRelation.invoke(null, "ENEMY"); - break; - case NEUTRAL: - rel = valueOfRelation.invoke(null, "NEUTRAL"); - break; - case ALLY: - rel = valueOfRelation.invoke(null, "ALLY"); - break; - case TRUCE: - rel = valueOfRelation.invoke(null, "TRUCE"); - } - - setPermission.invoke(faction, rel, valueOf.invoke(null, permission), allowObject); - } catch (Exception exc) { - exc.printStackTrace(); - } + Relation rel = switch (relation) { + case MEMBER -> Relation.MEMBER; + case ENEMY -> Relation.ENEMY; + case NEUTRAL -> Relation.NEUTRAL; + case ALLY -> Relation.ALLY; + case TRUCE -> Relation.TRUCE; + }; + faction.setPermission(rel, PermissableAction.valueOf(permission), (b) ? Access.ALLOW : Access.DENY); } @Override public void setRelationWish(String id, String other, TranslatedRelation relation) { Faction a = Factions.getInstance().getFactionById(id); - Faction b = Factions.getInstance().getFactionById(other); - try { - Object rel = null; - - switch (relation) { - case MEMBER: - rel = valueOfRelation.invoke(null, "MEMBER"); - break; - case ENEMY: - rel = valueOfRelation.invoke(null, "ENEMY"); - break; - case NEUTRAL: - rel = valueOfRelation.invoke(null, "NEUTRAL"); - break; - case ALLY: - rel = valueOfRelation.invoke(null, "ALLY"); - break; - case TRUCE: - rel = valueOfRelation.invoke(null, "TRUCE"); - } - - setRelationWish.invoke(a, b, rel); - } catch (Exception exc) { - exc.printStackTrace(); - } + Relation rel = switch (relation) { + case MEMBER -> Relation.MEMBER; + case ENEMY -> Relation.ENEMY; + case NEUTRAL -> Relation.NEUTRAL; + case ALLY -> Relation.ALLY; + case TRUCE -> Relation.TRUCE; + }; + a.setRelationWish(b, rel); } @Override @@ -724,13 +442,7 @@ public Map> getAllClaims(String id) { @Override public Inventory getChestInventory(Player player, String id) { Faction faction = Factions.getInstance().getFactionById(id); - - try { - return (Inventory) chestInventory.invoke(faction); - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } - return null; + return faction.getChestInventory(); } @Override @@ -786,29 +498,14 @@ public String getWilderness() { @Override public String getRolePrefix(TranslatedRole translatedRole) { - String toReturn = ""; - try { - switch (translatedRole) { - case RECRUIT: - toReturn = (String) recruitP.get(null); - break; - case NORMAL: - toReturn = (String) normalP.get(null); - break; - case MODERATOR: - toReturn = (String) moderatorP.get(null); - break; - case COLEADER: - toReturn = (String) coleaderP.get(null); - break; - case ADMIN: - toReturn = (String) leaderP.get(null); - break; - } - } catch (IllegalAccessException ignored) { - - } - return toReturn; + return switch (translatedRole) { + case RECRUIT -> Conf.prefixRecruit; + case NORMAL -> Conf.prefixNormal; + case MODERATOR -> Conf.prefixMod; + case COLEADER -> Conf.prefixCoLeader; + case ADMIN -> Conf.prefixLeader; + default -> ""; + }; } @Override @@ -900,16 +597,12 @@ public boolean isBypassing(Player player) { @Override public boolean isAlt(Player player) { - if (isAlt == null) - return false; - + FPlayer fPlayer = Objects.requireNonNull(FPlayers.getInstance().getByPlayer(player)); try { - FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - return (boolean) isAlt.invoke(fPlayer); - } catch (IllegalAccessException | InvocationTargetException ignored) { - + return fPlayer.isAlt(); + }catch (Throwable ignored) { + return false; } - return false; } @Override @@ -922,44 +615,25 @@ public boolean isWildernessAt(Location location) { public TranslatedRelation getRelationToFaction(Player player, String id) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); Faction faction = Factions.getInstance().getFactionById(id); - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(fPlayer, faction)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - return TranslatedRelation.ENEMY; - } + return TranslatedRelation.valueOf(fPlayer.getRelationTo(faction).name().toUpperCase()); } @Override public TranslatedRole getRole(Player player) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override public TranslatedRole getRole(OfflinePlayer player) { FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(player); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override public TranslatedRole getRole(UUID uuid) { FPlayer fPlayer = FPlayers.getInstance().getById(uuid.toString()); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override @@ -967,24 +641,14 @@ public TranslatedRelation getFactionRelationToFaction(String id1, String id2) { Faction faction1 = Factions.getInstance().getFactionById(id1); Faction faction2 = Factions.getInstance().getFactionById(id2); if (faction1 == null || faction2 == null) return TranslatedRelation.ENEMY; - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(faction1, faction2)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return TranslatedRelation.ENEMY; + return TranslatedRelation.valueOf(faction1.getRelationTo(faction2).name().toUpperCase()); } @Override public TranslatedRelation getRelationToPlayer(Player player, Player player2) { FPlayer fPlayer1 = FPlayers.getInstance().getByPlayer(player); FPlayer fPlayer2 = FPlayers.getInstance().getByPlayer(player2); - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(fPlayer1, fPlayer2)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return TranslatedRelation.ENEMY; + return TranslatedRelation.valueOf(fPlayer1.getRelationTo(fPlayer2).name().toUpperCase()); } @Override @@ -1020,43 +684,31 @@ public String getSafezone() { @Override public boolean isShieldRegionAt(String id, Location location) { Faction faction = Factions.getInstance().getFactionById(id); - - if (faction == null) + if (faction == null) { return false; + } - try { - Set baseRegions = (Set) getBaseRegion.invoke(faction); - - if (baseRegions.isEmpty()) - return false; + Set baseRegions = faction.getBaseRegion(); + if (baseRegions.isEmpty()) { + return false; + } - return baseRegions.stream().anyMatch(ps -> { - try { - int xLoc = (int) getXFastChunk.invoke(ps); - int zLoc = (int) getZFastChunk.invoke(ps); + return baseRegions.stream().anyMatch(ps -> { + int xLoc = ps.getX(); + int zLoc = ps.getZ(); - return xLoc == location.getBlockX() >> 4 && zLoc == location.getBlockZ() >> 4; - } catch (IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); - } - }); - } catch (IllegalAccessException | InvocationTargetException exc) { - throw new RuntimeException(exc); - } + return xLoc == location.getBlockX() >> 4 && zLoc == location.getBlockZ() >> 4; + }); } @Override public boolean isShieldActive(String id) { Faction faction = Factions.getInstance().getFactionById(id); - - if (faction == null) + if (faction == null) { return false; - - try { - return (boolean) isProtectedFaction.invoke(faction); - } catch (IllegalAccessException | InvocationTargetException exc) { - throw new RuntimeException(exc); } + + return faction.isProtected(); } @EventHandler diff --git a/factions-stellar/src/main/java/com/kamikazejam/factionintegrations/integrations/StellarIntegration.java b/factions-stellar/src/main/java/com/kamikazejam/factionintegrations/integrations/StellarIntegration.java index f8c443e..65f2f97 100644 --- a/factions-stellar/src/main/java/com/kamikazejam/factionintegrations/integrations/StellarIntegration.java +++ b/factions-stellar/src/main/java/com/kamikazejam/factionintegrations/integrations/StellarIntegration.java @@ -26,6 +26,8 @@ import java.util.List; import java.util.UUID; +// Don't have a StellarFactions jar file, can't replace the reflection :( +@SuppressWarnings({"all"}) public class StellarIntegration extends UUIDIntegration implements KFaction { @EventHandler diff --git a/factions-uuid/src/main/java/com/kamikazejam/factionintegrations/integrations/UUIDIntegration.java b/factions-uuid/src/main/java/com/kamikazejam/factionintegrations/integrations/UUIDIntegration.java index df6d48a..dd8db2a 100644 --- a/factions-uuid/src/main/java/com/kamikazejam/factionintegrations/integrations/UUIDIntegration.java +++ b/factions-uuid/src/main/java/com/kamikazejam/factionintegrations/integrations/UUIDIntegration.java @@ -5,8 +5,8 @@ import com.kamikazejam.factionintegrations.object.TranslatedRole; import com.massivecraft.factions.*; import com.massivecraft.factions.event.*; -import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.listeners.FactionsBlockListener; import com.massivecraft.factions.perms.PermissibleAction; import com.massivecraft.factions.perms.Relation; import com.massivecraft.factions.perms.Role; @@ -16,8 +16,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.inventory.Inventory; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.*; public class UUIDIntegration implements KFaction { @@ -116,58 +114,7 @@ public void onJoin(FPlayerLeaveEvent e) { } } - private Method canBuild; - - private Method getRole; - - private Object permissibleConstant; - - private Method relationTo, setRole; - - private Object leader, coleader, moderator, normal, recruit; - - public UUIDIntegration() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException { - Class permissibleEnum = Class.forName("com.massivecraft.factions.perms.PermissibleAction"); - - for (Object object : permissibleEnum.getEnumConstants()) { - if (object.toString().equals("BUILD")) { - permissibleConstant = object; - break; - } - } - - relationTo = RelationParticipator.class.getMethod("getRelationTo", RelationParticipator.class); - - getRole = FPlayer.class.getMethod("getRole"); - - Class roleClass = Class.forName("com.massivecraft.factions.perms.Role"); - - setRole = FPlayer.class.getMethod("setRole", roleClass); - - for (Object type : roleClass.getEnumConstants()) { - String toString = ((Enum) type).name(); - switch (toString.toUpperCase()) { - case "LEADER": - case "ADMIN": - leader = type; - break; - case "COLEADER": - coleader = type; - break; - case "MODERATOR": - moderator = type; - break; - case "NORMAL": - normal = type; - break; - case "RECRUIT": - recruit = type; - break; - } - } - - canBuild = Class.forName("com.massivecraft.factions.listeners.FactionsBlockListener").getMethod("playerCanBuildDestroyBlock", Player.class, Location.class, permissibleEnum, boolean.class); - } + public UUIDIntegration() {} @Override public void setTnT(String id, long amount) { @@ -254,11 +201,7 @@ public boolean isSystemFac(String id) { @Override public boolean playerCanBuildThere(Player player, Location location) { - try { - return (boolean) canBuild.invoke(null, player, location, permissibleConstant, true); - } catch (IllegalAccessException | InvocationTargetException e) { - return false; - } + return FactionsBlockListener.playerCanBuildDestroyBlock(player, location, PermissibleAction.BUILD, true); } @Override @@ -376,79 +319,47 @@ public void setFaction(OfflinePlayer player, String id) { public void setRole(Player player, TranslatedRole translatedRole) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - try { - switch (translatedRole.getValue()) { - case 1: - setRole.invoke(fPlayer, recruit); - break; - case 2: - setRole.invoke(fPlayer, normal); - break; - case 3: - setRole.invoke(fPlayer, moderator); - break; - case 4: - setRole.invoke(fPlayer, coleader); - break; - case 5: - setRole.invoke(fPlayer, leader); - break; - } - } catch (IllegalAccessException | InvocationTargetException ignored) { - - } + setFPlayerRole(translatedRole, fPlayer); } @Override public void setRole(OfflinePlayer offlinePlayer, TranslatedRole translatedRole) { FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(offlinePlayer); - try { - switch (translatedRole.getValue()) { - case 1: - setRole.invoke(fPlayer, recruit); - break; - case 2: - setRole.invoke(fPlayer, normal); - break; - case 3: - setRole.invoke(fPlayer, moderator); - break; - case 4: - setRole.invoke(fPlayer, coleader); - break; - case 5: - setRole.invoke(fPlayer, leader); - break; - } - } catch (IllegalAccessException | InvocationTargetException exc) { - // Failed to set role, print some information about it - exc.printStackTrace(); - } + setFPlayerRole(translatedRole, fPlayer); } - @Override - public void setPermission(String id, TranslatedRelation relation, String permission, boolean b) { - Faction faction = Factions.getInstance().getFactionById(id); - - Relation rel = null; - - switch (relation) { - case MEMBER: - rel = Relation.MEMBER; + private void setFPlayerRole(TranslatedRole translatedRole, FPlayer fPlayer) { + switch (translatedRole.getValue()) { + case 1: + fPlayer.setRole(Role.RECRUIT); break; - case ENEMY: - rel = Relation.ENEMY; + case 2: + fPlayer.setRole(Role.NORMAL); break; - case NEUTRAL: - rel = Relation.NEUTRAL; + case 3: + fPlayer.setRole(Role.MODERATOR); break; - case ALLY: - rel = Relation.ALLY; + case 4: + fPlayer.setRole(Role.COLEADER); + break; + case 5: + fPlayer.setRole(Role.ADMIN); break; - case TRUCE: - rel = Relation.TRUCE; } + } + + @Override + public void setPermission(String id, TranslatedRelation relation, String permission, boolean b) { + Faction faction = Factions.getInstance().getFactionById(id); + + Relation rel = switch (relation) { + case MEMBER -> Relation.MEMBER; + case ENEMY -> Relation.ENEMY; + case NEUTRAL -> Relation.NEUTRAL; + case ALLY -> Relation.ALLY; + case TRUCE -> Relation.TRUCE; + }; faction.setPermission(b, rel, PermissibleAction.valueOf(permission), true); } @@ -581,25 +492,14 @@ public String getWilderness() { @Override public String getRolePrefix(TranslatedRole translatedRole) { - String toReturn = ""; - switch (translatedRole.getValue()) { - case 1: - toReturn = FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getRecruit(); - break; - case 2: - toReturn = FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getNormal(); - break; - case 3: - toReturn = FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getMod(); - break; - case 4: - toReturn = FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getColeader(); - break; - case 5: - toReturn = FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getAdmin(); - break; - } - return toReturn; + return switch (translatedRole.getValue()) { + case 1 -> FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getRecruit(); + case 2 -> FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getNormal(); + case 3 -> FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getMod(); + case 4 -> FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getColeader(); + case 5 -> FactionsPlugin.getInstance().getConfigManager().getMainConfig().factions().prefixes().getAdmin(); + default -> ""; + }; } @Override @@ -695,44 +595,25 @@ public boolean isWildernessAt(Location location) { public TranslatedRelation getRelationToFaction(Player player, String id) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); Faction faction = Factions.getInstance().getFactionById(id); - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(fPlayer, faction)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - return TranslatedRelation.ENEMY; - } + return TranslatedRelation.valueOf(fPlayer.getRelationTo(faction).name().toUpperCase()); } @Override public TranslatedRole getRole(Player player) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override public TranslatedRole getRole(OfflinePlayer player) { FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(player); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override public TranslatedRole getRole(UUID uuid) { FPlayer fPlayer = FPlayers.getInstance().getById(uuid.toString()); - try { - return TranslatedRole.valueOf(((Enum) getRole.invoke(fPlayer)).name().toUpperCase()); - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return TranslatedRole.RECRUIT; + return TranslatedRole.valueOf(fPlayer.getRole().name().toUpperCase()); } @Override @@ -740,24 +621,14 @@ public TranslatedRelation getFactionRelationToFaction(String id1, String id2) { Faction faction1 = Factions.getInstance().getFactionById(id1); Faction faction2 = Factions.getInstance().getFactionById(id2); if (faction1 == null || faction2 == null) return TranslatedRelation.ENEMY; - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(faction1, faction2)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return TranslatedRelation.ENEMY; + return TranslatedRelation.valueOf(faction1.getRelationTo(faction2).name().toUpperCase()); } @Override public TranslatedRelation getRelationToPlayer(Player player, Player player2) { FPlayer fPlayer1 = FPlayers.getInstance().getByPlayer(player); FPlayer fPlayer2 = FPlayers.getInstance().getByPlayer(player2); - try { - return TranslatedRelation.valueOf(((Enum) relationTo.invoke(fPlayer1, fPlayer2)).name().toUpperCase()); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return TranslatedRelation.ENEMY; + return TranslatedRelation.valueOf(fPlayer1.getRelationTo(fPlayer2).name().toUpperCase()); } @Override