From b260a4faecca0bbbb74fec00e80516adda82aacd Mon Sep 17 00:00:00 2001 From: Driftay Date: Tue, 2 Nov 2021 21:39:18 -0400 Subject: [PATCH] Revert Back To FastChunk Reference, Lunar Client Integration Started --- .../{LunarClientAPI.jar => bukkitapi.jar} | Bin pom.xml | 166 +++++++++--------- .../com/massivecraft/factions/Faction.java | 5 +- .../massivecraft/factions/FactionsPlugin.java | 6 + .../massivecraft/factions/cmd/CmdCreate.java | 1 + .../factions/cmd/CmdSpawnerChunk.java | 9 +- .../factions/integration/LunarAPI.java | 27 ++- .../listeners/FactionsPlayerListener.java | 5 + .../listeners/SpawnerChunkListener.java | 6 +- .../massivecraft/factions/util/FastChunk.java | 62 +++++++ .../util/flight/stuct/AsyncPlayerMap.java | 8 +- .../factions/zcore/persist/MemoryBoard.java | 6 +- .../factions/zcore/persist/MemoryFaction.java | 6 +- .../factions/zcore/util/StartupParameter.java | 7 + 14 files changed, 199 insertions(+), 115 deletions(-) rename dependencies/{LunarClientAPI.jar => bukkitapi.jar} (100%) create mode 100644 src/main/java/com/massivecraft/factions/util/FastChunk.java diff --git a/dependencies/LunarClientAPI.jar b/dependencies/bukkitapi.jar similarity index 100% rename from dependencies/LunarClientAPI.jar rename to dependencies/bukkitapi.jar diff --git a/pom.xml b/pom.xml index 1b6635722..967131d21 100644 --- a/pom.xml +++ b/pom.xml @@ -25,87 +25,89 @@ src/main/resources/ - - - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.1 - - false - - - me.lucko.helper - com.massivecraft.factions.shade.me.lucko.helper - - - com.github.cryptomorin - com.massivecraft.factions.shade.xseries - - - com.github.stefvanschie.inventoryframework - com.massivecraft.factions.shade.stefvanschie.inventoryframework - - - org.bstats - com.massivecraft.factions.shade.org.bstats - - - net.dv8tion - com.massivecraft.factions.shade.net.dv8tion - - - xyz.xenondevs - com.massivecraft.factions.shade.particlelib - - - mkremins.fanciful - com.massivecraft.factions.shade.mkremins.fanciful - - - com.google.gson - com.massivecraft.factions.shade.com.google.gson - - - com.darkblade12 - com.massivecraft.factions.shade.com.darkblade12 - - - de.tr7zw - com.massivecraft.factions.shade.nbtapi - - - - - - package - - shade - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.3.2 - - SaberFactions - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.0.1 - - + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + false + + + me.lucko.helper + com.massivecraft.factions.shade.me.lucko.helper + + + com.github.cryptomorin + com.massivecraft.factions.shade.xseries + + + com.github.stefvanschie.inventoryframework + com.massivecraft.factions.shade.stefvanschie.inventoryframework + + + + org.bstats + com.massivecraft.factions.shade.org.bstats + + + net.dv8tion + com.massivecraft.factions.shade.net.dv8tion + + + xyz.xenondevs + com.massivecraft.factions.shade.particlelib + + + mkremins.fanciful + com.massivecraft.factions.shade.mkremins.fanciful + + + com.google.gson + com.massivecraft.factions.shade.com.google.gson + + + com.darkblade12 + com.massivecraft.factions.shade.com.darkblade12 + + + de.tr7zw + com.massivecraft.factions.shade.nbtapi + + + + + + package + + shade + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.2 + + SaberFactions + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.0.1 + + @@ -295,7 +297,7 @@ LC-API system 1.16 - ${project.basedir}/dependencies/LunarClientAPI.jar + ${project.basedir}/dependencies/bukkitapi.jar club.minnced diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index 2684fff10..87b868105 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -7,6 +7,7 @@ import com.massivecraft.factions.struct.BanInfo; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; +import com.massivecraft.factions.util.FastChunk; import com.massivecraft.factions.util.LazyLocation; import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Permissable; @@ -101,9 +102,9 @@ public interface Faction extends EconomyParticipator { List getCompletedMissions(); - Set getSpawnerChunks(); + Set getSpawnerChunks(); - void setSpawnerChunks(Set fastChunks); + void setSpawnerChunks(Set fastChunks); void clearSpawnerChunks(); diff --git a/src/main/java/com/massivecraft/factions/FactionsPlugin.java b/src/main/java/com/massivecraft/factions/FactionsPlugin.java index d71b3f533..97a870556 100755 --- a/src/main/java/com/massivecraft/factions/FactionsPlugin.java +++ b/src/main/java/com/massivecraft/factions/FactionsPlugin.java @@ -2,6 +2,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; +import com.lunarclient.bukkitapi.LunarClientAPI; import com.massivecraft.factions.addon.AddonManager; import com.massivecraft.factions.addon.FactionsAddon; import com.massivecraft.factions.cmd.CmdAutoHelp; @@ -89,6 +90,7 @@ public class FactionsPlugin extends MPlugin { private boolean mvdwPlaceholderAPIManager = false; private Listener[] eventsListener; private Worldguard wg; + public LunarClientAPI lunarClientAPI; public FactionsPlugin() { instance = this; @@ -423,6 +425,10 @@ public void logFactionEvent(Faction faction, FLogType type, String... arguments) this.fLogManager.log(faction, type, arguments); } + public LunarClientAPI getLunarClientAPI() { + return lunarClientAPI; + } + public List getFactionReserves() { return this.reserveObjects; } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java b/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java index d46d05911..a7b92799a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java @@ -43,6 +43,7 @@ public void perform(CommandContext context) { context.player.sendMessage(ChatColor.translateAlternateColorCodes('&', TL.DISCORD_LINK_REQUIRED.toString())); return; } + String tag = context.argAsString(0); if (context.fPlayer.hasFaction()) { diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSpawnerChunk.java b/src/main/java/com/massivecraft/factions/cmd/CmdSpawnerChunk.java index a84fac296..bb5e7f4b4 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSpawnerChunk.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSpawnerChunk.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; +import com.massivecraft.factions.util.FastChunk; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Location; @@ -26,11 +27,11 @@ public CmdSpawnerChunk() { public void perform(CommandContext context) { Faction fac = context.faction; Location location = context.player.getLocation(); - FLocation fLocation = new FLocation(location); + FastChunk fastChunk = new FastChunk(location.getWorld().getName(), location.getChunk().getX(), location.getChunk().getZ()); if (fac.getSpawnerChunkCount() < fac.getAllowedSpawnerChunks()) { - if (context.fPlayer.attemptClaim(fac, fLocation, true)) { - if (!fac.getSpawnerChunks().contains(fLocation)) { - fac.getSpawnerChunks().add(fLocation); + if (context.fPlayer.attemptClaim(fac, new FLocation(context.player.getLocation()), true)) { + if (!fac.getSpawnerChunks().contains(fastChunk)) { + fac.getSpawnerChunks().add(fastChunk); context.fPlayer.msg(TL.COMMAND_SPAWNERCHUNK_CLAIM_SUCCESSFUL); } else { context.fPlayer.msg(TL.COMMAND_SPAWNERCHUNK_ALREADY_CHUNK); diff --git a/src/main/java/com/massivecraft/factions/integration/LunarAPI.java b/src/main/java/com/massivecraft/factions/integration/LunarAPI.java index a6dbba8b2..4502eb2f3 100644 --- a/src/main/java/com/massivecraft/factions/integration/LunarAPI.java +++ b/src/main/java/com/massivecraft/factions/integration/LunarAPI.java @@ -1,30 +1,29 @@ package com.massivecraft.factions.integration; -import com.lunarclient.bukkitapi.LunarClientAPI; import com.lunarclient.bukkitapi.object.LCWaypoint; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FactionsPlugin; +import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.entity.Player; public class LunarAPI { - public static void initLunarUser(FPlayer fPlayer) { - if(fPlayer.hasFaction()) { - Player player = fPlayer.getPlayer(); - Faction faction = fPlayer.getFaction(); - if(LunarClientAPI.getInstance().isRunningLunarClient(player)) { - LunarClientAPI.getInstance().registerPlayer(player); - LCWaypoint waypoint = new LCWaypoint("Faction Home", faction.getHome(), Color.LIME.asRGB(), true); - LunarClientAPI.getInstance().sendWaypoint(player, waypoint); - } - } + + public static boolean isLunarAPIEnabled() { + return Bukkit.getServer().getPluginManager().isPluginEnabled("LunarClient-API"); } - public static void exilLunarUser(FPlayer fPlayer) { - if(LunarClientAPI.getInstance().isRunningLunarClient(fPlayer.getPlayer())) { - LunarClientAPI.getInstance().unregisterPlayer(fPlayer.getPlayer(), true); + + public static void sendHomeWaypoint(FPlayer fPlayer) { + Player player = fPlayer.getPlayer(); + Faction faction = fPlayer.getFaction(); + if(fPlayer.hasFaction() && fPlayer.getFaction().getHome() != null) { + //FactionsPlugin.getInstance().getLunarClientAPI().registerPlayer(player); + LCWaypoint waypoint = new LCWaypoint("Faction Home", faction.getHome(), Color.LIME.asRGB(), true); + FactionsPlugin.getInstance().getLunarClientAPI().sendWaypoint(player, waypoint); } } diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 57f444876..3fede9695 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -11,6 +11,7 @@ import com.massivecraft.factions.event.FPlayerEnteredFactionEvent; import com.massivecraft.factions.event.FPlayerJoinEvent; import com.massivecraft.factions.event.FPlayerLeaveEvent; +import com.massivecraft.factions.integration.LunarAPI; import com.massivecraft.factions.scoreboards.FScoreboard; import com.massivecraft.factions.scoreboards.FTeamWrapper; import com.massivecraft.factions.scoreboards.sidebar.FDefaultSidebar; @@ -421,6 +422,10 @@ private void initPlayer(Player player) { me.setFlying(false); } + if(LunarAPI.isLunarAPIEnabled()) { + LunarAPI.sendHomeWaypoint(me); + } + } @EventHandler diff --git a/src/main/java/com/massivecraft/factions/listeners/SpawnerChunkListener.java b/src/main/java/com/massivecraft/factions/listeners/SpawnerChunkListener.java index 58afbf326..1061cafe3 100644 --- a/src/main/java/com/massivecraft/factions/listeners/SpawnerChunkListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/SpawnerChunkListener.java @@ -2,6 +2,7 @@ import com.cryptomorin.xseries.XMaterial; import com.massivecraft.factions.*; +import com.massivecraft.factions.util.FastChunk; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.Location; import org.bukkit.event.EventHandler; @@ -12,10 +13,9 @@ public class SpawnerChunkListener implements Listener { @EventHandler public void onSpawnerPlace(BlockPlaceEvent e) { - - if (e.getBlockPlaced().getType() == XMaterial.SPAWNER.parseMaterial()) { Location location = e.getBlockPlaced().getLocation(); + FastChunk fastChunk = new FastChunk(location.getWorld().getName(), location.getChunk().getX(), location.getChunk().getZ()); FLocation fLoc = new FLocation(location); Faction fac = Board.getInstance().getFactionAt(fLoc); FPlayer fPlayer = FPlayers.getInstance().getByPlayer(e.getPlayer()); @@ -26,7 +26,7 @@ public void onSpawnerPlace(BlockPlaceEvent e) { if (!Conf.allowSpawnersPlacedInWilderness) { if (fac.isNormal()) { - if (!fac.getSpawnerChunks().contains(fLoc)) { + if (!fac.getSpawnerChunks().contains(fastChunk)) { e.setCancelled(true); e.getPlayer().sendMessage(TL.SPAWNER_CHUNK_PLACE_DENIED_NOT_SPAWNERCHUNK.toString()); } diff --git a/src/main/java/com/massivecraft/factions/util/FastChunk.java b/src/main/java/com/massivecraft/factions/util/FastChunk.java new file mode 100644 index 000000000..3ffc8ffa9 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/util/FastChunk.java @@ -0,0 +1,62 @@ +package com.massivecraft.factions.util; + +import com.massivecraft.factions.FLocation; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; + +import java.util.Objects; + +public class FastChunk { + + private String world; + private int x, z; + + public FastChunk(String world, int x, int z) { + this.world = world; + this.x = x; + this.z = z; + } + + public FastChunk(String world, FLocation floc) { + this.world = world; + this.x = floc.getChunk().getX(); + this.z = floc.getChunk().getZ(); + } + + public FastChunk(FLocation floc) { + this.world = floc.getWorld().getName(); + this.x = floc.getChunk().getX(); + this.z = floc.getChunk().getZ(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + FastChunk fastChunk = (FastChunk) o; + return x == fastChunk.x && + z == fastChunk.z && + world.equals(fastChunk.world); + } + + @Override + public int hashCode() { + return Objects.hash(world, x, z); + } + + public String getWorld() { + return world; + } + + public int getX() { + return x; + } + + public int getZ() { + return z; + } + + public Chunk getChunk() { + return Bukkit.getWorld(world).getChunkAt(x, z); + } +} diff --git a/src/main/java/com/massivecraft/factions/util/flight/stuct/AsyncPlayerMap.java b/src/main/java/com/massivecraft/factions/util/flight/stuct/AsyncPlayerMap.java index 9ba852951..9b47faa1c 100644 --- a/src/main/java/com/massivecraft/factions/util/flight/stuct/AsyncPlayerMap.java +++ b/src/main/java/com/massivecraft/factions/util/flight/stuct/AsyncPlayerMap.java @@ -1,9 +1,7 @@ package com.massivecraft.factions.util.flight.stuct; -import com.massivecraft.factions.Board; -import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.FPlayers; -import com.massivecraft.factions.Faction; +import com.massivecraft.factions.*; +import com.massivecraft.factions.integration.LunarAPI; import com.massivecraft.factions.util.TitleUtil; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -32,7 +30,7 @@ public AsyncPlayerMap(Plugin bukkitPlugin) { public void run() { for (Player pl : Bukkit.getServer().getOnlinePlayers()) { - if(pl.hasMetadata("showFactionTitle")) { + if (pl.hasMetadata("showFactionTitle")) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(pl); Faction factionTo = Board.getInstance().getFactionAt(fPlayer.getLastStoodAt()); TitleUtil.sendFactionChangeTitle(fPlayer, factionTo); diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java index df2249066..74aee75ce 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java @@ -8,6 +8,7 @@ import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.util.AsciiCompass; import com.massivecraft.factions.util.CC; +import com.massivecraft.factions.util.FastChunk; import com.massivecraft.factions.util.Logger; import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TagReplacer; @@ -250,6 +251,7 @@ public ArrayList getMap(FPlayer fplayer, FLocation flocation, doub row.then("+").color(ChatColor.AQUA).tooltip(TL.CLAIM_YOUAREHERE.toString()); } else { FLocation flocationHere = topLeft.getRelative(dx, dz); + FastChunk fastChunk = new FastChunk(flocationHere); Faction factionHere = getFactionAt(flocationHere); Relation relation = fplayer.getRelationTo(factionHere); if (flocationHere.isOutsideWorldBorder(buffer)) { @@ -278,11 +280,11 @@ public ArrayList getMap(FPlayer fplayer, FLocation flocation, doub //row.then(String.valueOf(tag)).color(factionHere.getColorTo(faction)).tooltip(getToolTip(factionHere, fplayer)); //changed out with a performance friendly one line tooltip :D - if (factionHere.getSpawnerChunks().contains(flocationHere) && Conf.userSpawnerChunkSystem) { + if (factionHere.getSpawnerChunks().contains(fastChunk) && Conf.userSpawnerChunkSystem) { row.then(String.valueOf(tag)).color(Conf.spawnerChunkColor).tooltip(oneLineToolTip(factionHere, fplayer) + CC.Reset + CC.Blue + " " + Conf.spawnerChunkString); } else { row.then(String.valueOf(tag)).color(factionHere.getColorTo(faction)).tooltip(oneLineToolTip(factionHere, fplayer)); - } } else { + } } else { row.then("-").color(ChatColor.GRAY); } } diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java index dcf227cbf..499628075 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -93,7 +93,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { private String guildId; private String memberRoleId; private int allowedSpawnerChunks; - private Set spawnerChunks; + private Set spawnerChunks; private boolean protectedfac = true; private boolean cloaked; @@ -205,11 +205,11 @@ public void setAllowedSpawnerChunks(int chunks) { this.allowedSpawnerChunks = chunks; } - public Set getSpawnerChunks() { + public Set getSpawnerChunks() { return this.spawnerChunks; } - public void setSpawnerChunks(Set spawnerChunks) { + public void setSpawnerChunks(Set spawnerChunks) { this.spawnerChunks = spawnerChunks; } diff --git a/src/main/java/com/massivecraft/factions/zcore/util/StartupParameter.java b/src/main/java/com/massivecraft/factions/zcore/util/StartupParameter.java index 88833fc56..5bcef66f0 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/StartupParameter.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/StartupParameter.java @@ -1,6 +1,7 @@ package com.massivecraft.factions.zcore.util; import com.cryptomorin.xseries.XMaterial; +import com.lunarclient.bukkitapi.LunarClientAPI; import com.massivecraft.factions.*; import com.massivecraft.factions.cmd.Aliases; import com.massivecraft.factions.cmd.audit.FLogManager; @@ -16,6 +17,7 @@ import com.massivecraft.factions.util.Metrics; import com.massivecraft.factions.util.timer.TimerManager; import com.massivecraft.factions.zcore.file.impl.FileManager; +import org.bukkit.Bukkit; import org.bukkit.entity.EntityType; import org.bukkit.plugin.Plugin; import pw.saber.corex.CoreX; @@ -64,6 +66,11 @@ public static void initData(FactionsPlugin plugin) { Aliases.load(); EngineDynmap.getInstance().init(); + if(Bukkit.getPluginManager().isPluginEnabled("LunarClient-API")) { + FactionsPlugin.getInstance().lunarClientAPI = LunarClientAPI.getInstance(); + Logger.print("Implementing Lunar Client Integration", Logger.PrefixType.DEFAULT); + } + FactionsPlugin.getInstance().hookedPlayervaults = setupPlayerVaults(); Econ.setup();