diff --git a/.github/workflows/pr.test.yml b/.github/workflows/pr.test.yml index 6feb66f..ea072c5 100644 --- a/.github/workflows/pr.test.yml +++ b/.github/workflows/pr.test.yml @@ -6,6 +6,6 @@ on: jobs: test: - uses: Multiverse/Multiverse-Core/.github/workflows/generic.test.yml@main + uses: Multiverse/Multiverse-Core/.github/workflows/generic.test.yml@MV5 # todo: Change back to main before release with: plugin_name: multiverse-netherportals diff --git a/build.gradle b/build.gradle index 831e5f2..c5e5989 100644 --- a/build.gradle +++ b/build.gradle @@ -2,14 +2,17 @@ plugins { id 'java-library' id 'maven-publish' id 'checkstyle' - id 'com.github.johnrengelman.shadow' version '7.1.2' + id 'com.gradleup.shadow' version '8.3.5' } version = System.getenv('GITHUB_VERSION') ?: 'local' -group = 'com.onarandombox.multiversenetherportals' +group = 'org.mvplugins.multiverse.netherportals' description = 'Multiverse-NetherPortals' -java.sourceCompatibility = JavaVersion.VERSION_11 +compileJava { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} repositories { mavenLocal() @@ -24,17 +27,23 @@ repositories { name = 'onarandombox' url = uri('https://repo.onarandombox.com/content/groups/public') } + + maven { + // todo: remove before mv5 release + name = 'benwoo1110' + url = uri('https://repo.c0ding.party/multiverse-beta') + } } dependencies { // Spigot - implementation 'org.bukkit:bukkit:1.13.2-R0.1-SNAPSHOT' + implementation'org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT' // Multiverse-Core - implementation 'com.onarandombox.multiversecore:multiverse-core:4.3.11' + implementation 'org.mvplugins.multiverse.core:multiverse-core:5.0.0-SNAPSHOT' // Multiverse-Portals - implementation 'com.onarandombox.multiverseportals:multiverse-portals:4.2.2' + implementation 'org.mvplugins.multiverse.portals:multiverse-portals:5.0.0-SNAPSHOT' // Utils api('com.dumptruckman.minecraft:Logging:1.1.1') { @@ -113,13 +122,25 @@ javadoc { project.configurations.api.canBeResolved = true shadowJar { - relocate 'com.dumptruckman.minecraft.util.Logging', 'com.onarandombox.multiverseportals.util.MVPLogging' - relocate 'com.dumptruckman.minecraft.util.DebugLog', 'com.onarandombox.multiverseportals.util.DebugFileLogger' + relocate 'com.dumptruckman.minecraft.util.Logging', 'org.mvplugins.multiverse.netherportals.util.MVPLogging' + relocate 'com.dumptruckman.minecraft.util.DebugLog', 'org.mvplugins.multiverse.netherportals.util.DebugFileLogger' configurations = [project.configurations.api] - archiveFileName = "$baseName-$version.$extension" + archiveClassifier.set('') } build.dependsOn shadowJar jar.enabled = false + + +tasks.register('runHabitatGenerator', JavaExec) { + classpath = configurations["compileClasspath"] + mainClass.set('org.mvplugins.multiverse.external.jvnet.hk2.generator.HabitatGenerator') + + args = [ + '--file', "build/libs/multiverse-netherportals-$version" + ".jar", + '--locator', 'Multiverse-NetherPortals', + ] +} +tasks.named("build") { finalizedBy("runHabitatGenerator") } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f398c33..5c40527 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/commands/LinkCommand.java b/src/main/java/com/onarandombox/MultiverseNetherPortals/commands/LinkCommand.java deleted file mode 100644 index 3b922b5..0000000 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/commands/LinkCommand.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.onarandombox.MultiverseNetherPortals.commands; - -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals; -import org.bukkit.ChatColor; -import org.bukkit.PortalType; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -public class LinkCommand extends NetherPortalCommand { - private MVWorldManager worldManager; - - public LinkCommand(MultiverseNetherPortals plugin) { - super(plugin); - this.setName("Sets NP Destination"); - this.setCommandUsage("/mvnp link " + ChatColor.GREEN + "{end|nether} " + ChatColor.GOLD + "[FROM_WORLD] " + ChatColor.GREEN + " {TO_WORLD}"); - this.setArgRange(2, 3); - this.addKey("mvnp link"); - this.addKey("mvnpl"); - this.addKey("mvnplink"); - this.addCommandExample("/mvnp link end world world_nether"); - this.addCommandExample("/mvnp link end world_nether"); - this.setPermission("multiverse.netherportals.link", "Sets which world to link to when a player enters a NetherPortal in this world.", PermissionDefault.OP); - this.worldManager = this.plugin.getCore().getMVWorldManager(); - } - - @Override - public void runCommand(CommandSender sender, List args) { - if (!(sender instanceof Player) && args.size() == 2) { - sender.sendMessage("From the command line, FROM_WORLD is required"); - sender.sendMessage("No changes were made..."); - return; - } - - MultiverseWorld fromWorld; - MultiverseWorld toWorld; - String fromWorldString; - String toWorldString; - PortalType type; - Player p; - - if (args.get(0).equalsIgnoreCase("END")) { - type = PortalType.ENDER; - } else if (args.get(0).equalsIgnoreCase("NETHER")) { - type = PortalType.NETHER; - } else { - type = null; - } - - if (args.size() == 2) { - p = (Player) sender; - fromWorldString = p.getWorld().getName(); - toWorldString = args.get(1); - } else { - fromWorldString = args.get(1); - toWorldString = args.get(2); - } - - if (type == null) { - sender.sendMessage("The type must either be 'end' or 'nether'"); - return; - } - - fromWorld = this.worldManager.getMVWorld(fromWorldString); - toWorld = this.worldManager.getMVWorld(toWorldString); - - if (fromWorld == null) { - this.plugin.getCore().showNotMVWorldMessage(sender, fromWorldString); - return; - } - if (toWorld == null) { - this.plugin.getCore().showNotMVWorldMessage(sender, toWorldString); - return; - } - - this.plugin.addWorldLink(fromWorld.getName(), toWorld.getName(), type); - String coloredFrom = fromWorld.getColoredWorldString(); - String coloredTo = toWorld.getColoredWorldString(); - if (fromWorld.getName().equals(toWorld.getName())) { - sender.sendMessage(ChatColor.RED + "NOTE: " + ChatColor.WHITE + "You have successfully disabled " + type.toString() + " Portals in " + coloredTo); - } else { - sender.sendMessage("The " + type + " portals in " + coloredFrom + ChatColor.WHITE + " are now linked to " + coloredTo); - } - - } - -} diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/commands/NetherPortalCommand.java b/src/main/java/com/onarandombox/MultiverseNetherPortals/commands/NetherPortalCommand.java deleted file mode 100644 index 029667f..0000000 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/commands/NetherPortalCommand.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.onarandombox.MultiverseNetherPortals.commands; - -import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals; -import com.onarandombox.commandhandler.Command; -import org.bukkit.command.CommandSender; - -import java.util.List; - -public abstract class NetherPortalCommand extends Command { - - protected MultiverseNetherPortals plugin; - - public NetherPortalCommand(MultiverseNetherPortals plugin) { - super(plugin); - this.plugin = plugin; - - } - - @Override - public abstract void runCommand(CommandSender arg0, List arg1); - -} diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/commands/ShowLinkCommand.java b/src/main/java/com/onarandombox/MultiverseNetherPortals/commands/ShowLinkCommand.java deleted file mode 100644 index c100a11..0000000 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/commands/ShowLinkCommand.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.onarandombox.MultiverseNetherPortals.commands; - -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -public class ShowLinkCommand extends NetherPortalCommand { - - private static final int CMDS_PER_PAGE = 10; - private MVWorldManager worldManager; - - public ShowLinkCommand(MultiverseNetherPortals plugin) { - super(plugin); - this.setName("Displays all World Links"); - this.setCommandUsage("/mvnp show " + ChatColor.GOLD + "[type] [PAGE #]"); - this.setArgRange(0, 2); - this.addKey("mvnp show"); - this.addKey("mvnp list"); - this.addKey("mvnpli"); - this.addKey("mvnps"); - this.addKey("mvnplist"); - this.addKey("mvnpshow"); - this.setPermission("multiverse.netherportals.show", "Displays a nicely formatted list of links.", PermissionDefault.OP); - this.worldManager = this.plugin.getCore().getMVWorldManager(); - } - - @Override - public void runCommand(CommandSender sender, List args) { - Map links = this.plugin.getWorldLinks(); - Map endlinks = this.plugin.getEndWorldLinks(); - - boolean end = false; // true to display end; false otherwise - if(args.size() > 0) { - if(args.get(0).equalsIgnoreCase("end")) { - end = true; - } - } - - if (!(sender instanceof Player)) { - if(!end) { - sender.sendMessage(ChatColor.AQUA + "--- NetherPortal Links ---"); - for (Map.Entry link : links.entrySet()) { - showWorldLink(sender, link.getKey(), link.getValue()); - } - } else { - sender.sendMessage(ChatColor.AQUA + "--- EnderPortal Links ---"); - for (Map.Entry link : endlinks.entrySet()) { - showWorldLink(sender, link.getKey(), link.getValue()); - } - } - return; - } - int page = 1; - if (args.size() > 0) { - try { - page = Integer.parseInt(args.get(args.size() - 1)); - } catch (NumberFormatException e) { - } - if (page < 1) { - page = 1; - } - } - Map displayLinks = (end ? endlinks : links); - int totalPages = (int) Math.ceil(displayLinks.size() / (CMDS_PER_PAGE + 0.0)); - - if (page > totalPages) { - page = totalPages; - } - this.showPage(page, sender, displayLinks, totalPages, (end ? "EnderPortals" : "NetherPortals")); - } - - private void showWorldLink(CommandSender sender, String fromWorldString, String toWorldString) { - MultiverseWorld fromWorld = this.worldManager.getMVWorld(fromWorldString); - MultiverseWorld toWorld = this.worldManager.getMVWorld(toWorldString); - - if (fromWorld == null) { - fromWorldString = ChatColor.RED + "!!ERROR!!"; - } else { - fromWorldString = fromWorld.getColoredWorldString(); - } - if (toWorld == null) { - toWorldString = ChatColor.RED + "!!ERROR!!"; - } else { - toWorldString = toWorld.getColoredWorldString(); - } - sender.sendMessage(fromWorldString + ChatColor.WHITE + " -> " + toWorldString); - } - - private void showPage(int page, CommandSender sender, Map links, int totalpages, String headerLabel) { - int start = (page - 1) * CMDS_PER_PAGE; - int end = start + CMDS_PER_PAGE; - if (totalpages == 0) { - sender.sendMessage("You haven't setup " + ChatColor.AQUA + "ANY" + ChatColor.WHITE + " world " + ChatColor.DARK_AQUA + "Links" + ChatColor.WHITE + "."); - return; - } - sender.sendMessage(ChatColor.AQUA + "--- " + headerLabel + " Links " + ChatColor.LIGHT_PURPLE + "[Page " + page + " of " + totalpages + " ]" + ChatColor.AQUA + "---"); - Iterator> entries = links.entrySet().iterator(); - for (int i = 0; i < end; i++) { - if (entries.hasNext() && i >= start) { - Map.Entry entry = entries.next(); - this.showWorldLink(sender, entry.getKey(), entry.getValue()); - } else if (entries.hasNext()) { - entries.next(); - } - } - } - -} diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/commands/UnlinkCommand.java b/src/main/java/com/onarandombox/MultiverseNetherPortals/commands/UnlinkCommand.java deleted file mode 100644 index 641608f..0000000 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/commands/UnlinkCommand.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.onarandombox.MultiverseNetherPortals.commands; - -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals; - -import org.bukkit.ChatColor; -import org.bukkit.PortalType; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -public class UnlinkCommand extends NetherPortalCommand { - private MVWorldManager worldManager; - - public UnlinkCommand(MultiverseNetherPortals plugin) { - super(plugin); - this.setName("Remove NP Destination"); - this.setCommandUsage("/mvnp unlink " + ChatColor.GREEN + "{nether|end}" + ChatColor.GOLD + "[FROM_WORLD]"); - this.setArgRange(1, 2); - this.addKey("mvnp unlink"); - this.addKey("mvnpu"); - this.addKey("mvnpunlink"); - this.setPermission("multiverse.netherportals.unlink", "This will remove a world link that's been set. You do not need to do this before setting a new one.", PermissionDefault.OP); - this.worldManager = this.plugin.getCore().getMVWorldManager(); - } - - @Override - public void runCommand(CommandSender sender, List args) { - if (!(sender instanceof Player) && args.size() == 1) { - sender.sendMessage("From the command line, FROM_WORLD is required"); - sender.sendMessage("No changes were made..."); - return; - } - - MultiverseWorld fromWorld; - MultiverseWorld toWorld; - String fromWorldString; - String toWorldString; - PortalType type; - Player p; - - if (args.get(0).equalsIgnoreCase("END")) { - type = PortalType.ENDER; - } else if (args.get(0).equalsIgnoreCase("NETHER")) { - type = PortalType.NETHER; - } else { - type = null; - } - - if (args.size() == 1) { - p = (Player) sender; - fromWorldString = p.getWorld().getName(); - } else { - fromWorldString = args.get(1); - } - - if (type == null) { - this.showHelp(sender); - return; - } - - fromWorld = this.worldManager.getMVWorld(fromWorldString); - if (fromWorld == null) { - sender.sendMessage(ChatColor.RED + "Whoops!" + ChatColor.WHITE + " Doesn't look like Multiverse knows about '" + fromWorldString + "'"); - return; - } - - toWorldString = this.plugin.getWorldLink(fromWorld.getName(), type); - if (toWorldString == null) { - sender.sendMessage(ChatColor.RED + "Whoops!" + ChatColor.WHITE + " The world " + fromWorld.getColoredWorldString() + ChatColor.WHITE + " was never linked."); - return; - } - toWorld = this.worldManager.getMVWorld(toWorldString); - - String coloredFrom = fromWorld.getColoredWorldString(); - String coloredTo = toWorld.getColoredWorldString(); - sender.sendMessage("The " + type + " portals in " + coloredFrom + ChatColor.WHITE + " are now " + ChatColor.RED + "unlinked" + ChatColor.WHITE + " from " + coloredTo + ChatColor.WHITE + "."); - this.plugin.removeWorldLink(fromWorld.getName(), toWorld.getName(), type); - } - -} diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPPluginListener.java b/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPPluginListener.java deleted file mode 100644 index 07c19f1..0000000 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPPluginListener.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.onarandombox.MultiverseNetherPortals.listeners; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.server.PluginDisableEvent; -import org.bukkit.event.server.PluginEnableEvent; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals; - -public class MVNPPluginListener implements Listener { - - private final MultiverseNetherPortals plugin; - - public MVNPPluginListener(MultiverseNetherPortals plugin) { - this.plugin = plugin; - } - - @EventHandler - public void onPluginEnable(PluginEnableEvent event) { - if (event.getPlugin().getDescription().getName().equals("Multiverse-Core")) { - this.plugin.setCore(((MultiverseCore) this.plugin.getServer().getPluginManager().getPlugin("Multiverse-Core"))); - this.plugin.getServer().getPluginManager().enablePlugin(this.plugin); - } - if (event.getPlugin().getDescription().getName().equals("Multiverse-Portals")) { - this.plugin.setPortals(event.getPlugin()); - } - } - - @EventHandler - public void onPluginDisable(PluginDisableEvent event) { - if (event.getPlugin().getDescription().getName().equals("Multiverse-Core")) { - this.plugin.setCore(null); - this.plugin.getServer().getPluginManager().disablePlugin(this.plugin); - } - if (event.getPlugin().getDescription().getName().equals("Multiverse-Portals")) { - this.plugin.setPortals(null); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/utils/MVLinkChecker.java b/src/main/java/com/onarandombox/MultiverseNetherPortals/utils/MVLinkChecker.java deleted file mode 100755 index 6f59649..0000000 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/utils/MVLinkChecker.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.onarandombox.MultiverseNetherPortals.utils; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals; -import org.bukkit.Location; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -public class MVLinkChecker { - private final MultiverseNetherPortals plugin; - private final MVWorldManager worldManager; - - public MVLinkChecker(MultiverseNetherPortals plugin) { - this.plugin = plugin; - this.worldManager = this.plugin.getCore().getMVWorldManager(); - } - - public Location findNewTeleportLocation(Location fromLocation, String worldString, Entity e) { - MultiverseWorld tpTo = this.worldManager.getMVWorld(worldString); - - if (tpTo == null) { - Logging.fine("Can't find world " + worldString); - } else if (e instanceof Player && !this.plugin.getCore().getMVPerms().canEnterWorld((Player) e, tpTo)) { - Logging.warning("Player " + e.getName() + " can't enter world " + worldString); - } else if (!this.worldManager.isMVWorld(fromLocation.getWorld().getName())) { - Logging.warning("World " + fromLocation.getWorld().getName() + " is not a Multiverse world"); - } else { - String entityType = (e instanceof Player) ? " player " : " entity "; - Logging.fine("Finding new teleport location for" + entityType + e.getName() + " to world " + worldString); - - // Set the output location to the same XYZ coords but different world - double fromScaling = this.worldManager.getMVWorld(fromLocation.getWorld().getName()).getScaling(); - double toScaling = tpTo.getScaling(); - - this.scaleLocation(fromLocation, fromScaling / toScaling); - fromLocation.setWorld(tpTo.getCBWorld()); - return fromLocation; - } - - return null; - } - - private void scaleLocation(Location fromLocation, double scaling) { - fromLocation.setX(fromLocation.getX() * scaling); - fromLocation.setZ(fromLocation.getZ() * scaling); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/MultiverseNetherPortals.java b/src/main/java/org/mvplugins/multiverse/netherportals/MultiverseNetherPortals.java similarity index 69% rename from src/main/java/com/onarandombox/MultiverseNetherPortals/MultiverseNetherPortals.java rename to src/main/java/org/mvplugins/multiverse/netherportals/MultiverseNetherPortals.java index af4066e..f637ceb 100644 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/MultiverseNetherPortals.java +++ b/src/main/java/org/mvplugins/multiverse/netherportals/MultiverseNetherPortals.java @@ -1,39 +1,32 @@ -package com.onarandombox.MultiverseNetherPortals; +package org.mvplugins.multiverse.netherportals; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.logging.Level; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVPlugin; -import com.onarandombox.MultiverseCore.commands.HelpCommand; -import com.onarandombox.MultiverseNetherPortals.commands.LinkCommand; -import com.onarandombox.MultiverseNetherPortals.commands.ShowLinkCommand; -import com.onarandombox.MultiverseNetherPortals.commands.UnlinkCommand; -import com.onarandombox.MultiverseNetherPortals.listeners.MVNPCoreListener; -import com.onarandombox.MultiverseNetherPortals.listeners.MVNPEntityListener; -import com.onarandombox.MultiverseNetherPortals.listeners.MVNPPlayerListener; -import com.onarandombox.MultiverseNetherPortals.listeners.MVNPPluginListener; -import com.onarandombox.MultiverseNetherPortals.utils.MVLinkChecker; -import com.onarandombox.MultiverseNetherPortals.utils.MVNameChecker; -import com.onarandombox.MultiversePortals.MultiversePortals; -import com.onarandombox.commandhandler.CommandHandler; +import org.mvplugins.multiverse.netherportals.commands.NetherPortalsCommand; +import org.mvplugins.multiverse.netherportals.listeners.MVNPListener; import org.bukkit.Location; import org.bukkit.PortalType; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import org.mvplugins.multiverse.core.MultiverseCore; +import org.mvplugins.multiverse.core.api.MVPlugin; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.core.config.MVCoreConfig; +import org.mvplugins.multiverse.core.inject.PluginServiceLocator; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jakarta.inject.Provider; +import org.mvplugins.multiverse.external.vavr.control.Try; +import org.mvplugins.multiverse.portals.MultiversePortals; +import org.mvplugins.multiverse.portals.utils.PortalManager; public class MultiverseNetherPortals extends JavaPlugin implements MVPlugin { @@ -46,16 +39,20 @@ public class MultiverseNetherPortals extends JavaPlugin implements MVPlugin { protected MultiverseCore core; protected Plugin multiversePortals; - protected MVNPPluginListener pluginListener; - protected MVNPPlayerListener playerListener; - protected MVNPCoreListener customListener; protected FileConfiguration MVNPConfiguration; private Map linkMap; private Map endLinkMap; - protected CommandHandler commandHandler; - private MVNPEntityListener entityListener; - private MVLinkChecker linkChecker; - private MVNameChecker nameChecker; + + private PluginServiceLocator serviceLocator; + @Inject + private Provider mvCoreConfig; + @Inject + private Provider commandManager; + + @Override + public void onLoad() { + getDataFolder().mkdirs(); + } @Override public void onEnable() { @@ -79,35 +76,35 @@ public void onEnable() { return; } - Logging.setDebugLevel(core.getMVConfig().getGlobalDebug()); + initializeDependencyInjection(); + Logging.setDebugLevel(mvCoreConfig.get().getGlobalDebug()); this.core.incrementPluginCount(); // As soon as we know MVCore was found, we can use the debug log! - this.linkChecker = new MVLinkChecker(this); - this.nameChecker = new MVNameChecker(this); - - this.pluginListener = new MVNPPluginListener(this); - this.playerListener = new MVNPPlayerListener(this); - this.entityListener = new MVNPEntityListener(this); - this.customListener = new MVNPCoreListener(this); - PluginManager pm = this.getServer().getPluginManager(); - pm.registerEvents(this.pluginListener, this); - pm.registerEvents(this.playerListener, this); - pm.registerEvents(this.entityListener, this); - pm.registerEvents(this.customListener, this); - loadConfig(); this.registerCommands(); + this.registerEvents(); Logging.log(true, Level.INFO, " Enabled - By %s", getAuthors()); } + private void initializeDependencyInjection() { + serviceLocator = core.getServiceLocatorFactory() + .registerPlugin(new MultiverseNetherPortalsPluginBinder(this), core.getServiceLocator()) + .flatMap(PluginServiceLocator::enable) + .getOrElseThrow(exception -> { + Logging.severe("Failed to initialize dependency injection!"); + getServer().getPluginManager().disablePlugin(this); + return new RuntimeException(exception); + }); + } + public void loadConfig() { initMVNPConfig(); - this.linkMap = new HashMap(); - this.endLinkMap = new HashMap(); + this.linkMap = new HashMap<>(); + this.endLinkMap = new HashMap<>(); this.setUsingBounceBack(this.isUsingBounceBack()); this.setTeleportingEntities(this.isTeleportingEntities()); @@ -170,28 +167,27 @@ private void initMVNPConfig() { } } - /** Register commands to Multiverse's CommandHandler so we get a super sexy single menu */ + /** + * Register commands to Multiverse's CommandHandler so we get a super sexy single menu + */ private void registerCommands() { - this.commandHandler = this.core.getCommandHandler(); - this.commandHandler.registerCommand(new LinkCommand(this)); - this.commandHandler.registerCommand(new UnlinkCommand(this)); - this.commandHandler.registerCommand(new ShowLinkCommand(this)); - for (com.onarandombox.commandhandler.Command c : this.commandHandler.getAllCommands()) { - if (c instanceof HelpCommand) { - c.addKey("mvnp"); - } - } + Try.of(() -> commandManager.get()) + .andThenTry(commandManager -> serviceLocator.getAllServices(NetherPortalsCommand.class) + .forEach(commandManager::registerCommand)) + .onFailure(e -> { + Logging.severe("Failed to register commands"); + e.printStackTrace(); + }); } - @Override - public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { - if (!this.isEnabled()) { - sender.sendMessage("This plugin is Disabled!"); - return true; - } - ArrayList allArgs = new ArrayList(Arrays.asList(args)); - allArgs.add(0, command.getName()); - return this.commandHandler.locateAndRunCommand(sender, allArgs); + private void registerEvents() { + var pluginManager = getServer().getPluginManager(); + + Try.run(() -> serviceLocator.getAllServices(MVNPListener.class).forEach( + listener -> pluginManager.registerEvents(listener, this))) + .onFailure(e -> { + throw new RuntimeException("Failed to register listeners. Terminating...", e); + }); } @Override @@ -200,11 +196,7 @@ public void onDisable() { } @Override - public void onLoad() { - getDataFolder().mkdirs(); - } - - private String getAuthors() { + public String getAuthors() { String authors = ""; for (int i = 0; i < this.getDescription().getAuthors().size(); i++) { if (i == this.getDescription().getAuthors().size() - 1) { @@ -216,6 +208,11 @@ private String getAuthors() { return authors.substring(2); } + @Override + public PluginServiceLocator getServiceLocator() { + return serviceLocator; + } + public void setNetherPrefix(String netherPrefix) { this.MVNPConfiguration.set("portal-auto-link-when.nether.prefix", netherPrefix); } @@ -280,17 +277,17 @@ public boolean addWorldLink(String from, String to, PortalType type) { return true; } - public void removeWorldLink(String from, String to, PortalType type) { + public boolean removeWorldLink(String from, String to, PortalType type) { if (type == PortalType.NETHER) { this.linkMap.remove(from); } else if (type == PortalType.ENDER) { this.endLinkMap.remove(from); } else { - return; + return false; } this.MVNPConfiguration.set("worlds." + from + ".portalgoesto." + type, null); - this.saveMVNPConfig(); + return this.saveMVNPConfig(); } public boolean saveMVNPConfig() { @@ -298,7 +295,7 @@ public boolean saveMVNPConfig() { this.MVNPConfiguration.save(new File(this.getDataFolder(), NETHER_PORTALS_CONFIG)); return true; } catch (IOException e) { - this.log(Level.SEVERE, "Could not save " + NETHER_PORTALS_CONFIG); + Logging.severe("Could not save " + NETHER_PORTALS_CONFIG); } return false; } @@ -348,7 +345,8 @@ public boolean isHandledByNetherPortals(Location l) { // Catch errors which could occur if classes aren't present or are missing methods. try { MultiversePortals portals = (MultiversePortals) multiversePortals; - if (portals.getPortalManager().isPortal(l)) { + PortalManager portalManager = portals.getServiceLocator().getActiveService(PortalManager.class); + if (portalManager != null && portalManager.isPortal(l)) { return false; } } catch (Throwable t) { @@ -358,14 +356,6 @@ public boolean isHandledByNetherPortals(Location l) { return true; } - public MVLinkChecker getLinkChecker() { - return linkChecker; - } - - public MVNameChecker getNameChecker() { - return nameChecker; - } - public void setPortals(Plugin multiversePortals) { this.multiversePortals = multiversePortals; } @@ -379,45 +369,12 @@ public MultiverseCore getCore() { return this.core; } - @Override - public void log(Level level, String msg) { - Logging.log(level, msg); - } - - @Override - public void setCore(MultiverseCore core) { - this.core = core; - } - @Override public int getProtocolVersion() { return 1; } - @Override - public String dumpVersionInfo(String buffer) { - buffer += logAndAddToPasteBinBuffer("Multiverse-NetherPortals Version: " + this.getDescription().getVersion()); - buffer += logAndAddToPasteBinBuffer("Nether Prefix: " + this.getNetherPrefix()); - buffer += logAndAddToPasteBinBuffer("Nether Suffix: " + this.getNetherSuffix()); - buffer += logAndAddToPasteBinBuffer("End Prefix: " + this.getEndPrefix()); - buffer += logAndAddToPasteBinBuffer("End Suffix: " + this.getEndSuffix()); - buffer += logAndAddToPasteBinBuffer("Nether Links: " + this.getWorldLinks()); - buffer += logAndAddToPasteBinBuffer("End Links: " + this.getEndWorldLinks()); - buffer += logAndAddToPasteBinBuffer("Bounceback: " + this.isUsingBounceBack()); - buffer += logAndAddToPasteBinBuffer("Teleport Entities: " + this.isTeleportingEntities()); - buffer += logAndAddToPasteBinBuffer("Send Disabled Portal Message: " + this.isSendingDisabledPortalMessage()); - buffer += logAndAddToPasteBinBuffer("Send No Destination Message: " + this.isSendingNoDestinationMessage()); - buffer += logAndAddToPasteBinBuffer("End platform drops blocks: " + this.isEndPlatformDropBlocks()); - buffer += logAndAddToPasteBinBuffer("Special Code: FRN001"); - return buffer; - } - - private String logAndAddToPasteBinBuffer(String string) { - this.log(Level.INFO, string); - return "[Multiverse-NetherPortals] " + string + '\n'; - } - - public String getVersionInfo() { + public String getDebugInfo() { return "[Multiverse-NetherPortals] Multiverse-NetherPortals Version: " + this.getDescription().getVersion() + '\n' + "[Multiverse-NetherPortals] Nether Prefix: " + this.getNetherPrefix() + '\n' + "[Multiverse-NetherPortals] Nether Suffix: " + this.getNetherSuffix() + '\n' diff --git a/src/main/java/org/mvplugins/multiverse/netherportals/MultiverseNetherPortalsPluginBinder.java b/src/main/java/org/mvplugins/multiverse/netherportals/MultiverseNetherPortalsPluginBinder.java new file mode 100644 index 0000000..4a7213a --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/netherportals/MultiverseNetherPortalsPluginBinder.java @@ -0,0 +1,19 @@ +package org.mvplugins.multiverse.netherportals; + +import org.mvplugins.multiverse.core.api.MVPlugin; +import org.mvplugins.multiverse.core.inject.binder.JavaPluginBinder; +import org.mvplugins.multiverse.external.glassfish.hk2.utilities.binding.ScopedBindingBuilder; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; + +public class MultiverseNetherPortalsPluginBinder extends JavaPluginBinder { + + protected MultiverseNetherPortalsPluginBinder(@NotNull MultiverseNetherPortals plugin) { + super(plugin); + } + + @Override + protected ScopedBindingBuilder bindPluginClass( + ScopedBindingBuilder bindingBuilder) { + return super.bindPluginClass(bindingBuilder).to(MVPlugin.class).to(MultiverseNetherPortals.class); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/netherportals/commands/LinkCommand.java b/src/main/java/org/mvplugins/multiverse/netherportals/commands/LinkCommand.java new file mode 100644 index 0000000..ebabc04 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/netherportals/commands/LinkCommand.java @@ -0,0 +1,73 @@ +package org.mvplugins.multiverse.netherportals.commands; + +import org.bukkit.ChatColor; +import org.bukkit.PortalType; +import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.core.world.MultiverseWorld; +import org.mvplugins.multiverse.external.acf.commands.InvalidCommandArgument; +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandAlias; +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandCompletion; +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandPermission; +import org.mvplugins.multiverse.external.acf.commands.annotation.Description; +import org.mvplugins.multiverse.external.acf.commands.annotation.Flags; +import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand; +import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax; +import org.mvplugins.multiverse.external.acf.commands.annotation.Values; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.netherportals.MultiverseNetherPortals; + +import java.util.Objects; + +@Service +@CommandAlias("mvnp") +class LinkCommand extends NetherPortalsCommand { + + private final MultiverseNetherPortals plugin; + + @Inject + LinkCommand(@NotNull MVCommandManager commandManager, @NotNull MultiverseNetherPortals plugin) { + super(commandManager); + this.plugin = plugin; + } + + @CommandAlias("mvnplink|mvnpl") + @Subcommand("link") + @CommandPermission("multiverse.netherportals.link") + @CommandCompletion("nether|end @mvworlds @mvworlds") + @Syntax(" [fromWorld] ") + @Description("Sets which world to link to when a player enters a NetherPortal in this world.") + public void onLinkCommand( + @NotNull MVCommandIssuer issuer, + + @Values("nether|end") + @Syntax("") + @Description("Portal type to link.") + @NotNull String linkType, + + @Flags("resolve=issuerAware") + @Syntax("[fromWorld]") + @Description("World the portals are at.") + @NotNull MultiverseWorld fromWorld, + + @Syntax("") + @Description("World the portals should teleport to.") + @NotNull MultiverseWorld toWorld + ) { + PortalType portalType = Objects.equals(linkType, "nether") ? PortalType.NETHER : PortalType.ENDER; + if (!this.plugin.addWorldLink(fromWorld.getName(), toWorld.getName(), portalType)) { + throw new InvalidCommandArgument("There was an error creating the link! See console for more details."); + } + + String coloredFrom = fromWorld.getAlias(); + String coloredTo = toWorld.getAlias(); + + issuer.sendMessage((fromWorld.getName().equals(toWorld.getName())) + ? String.format("%sNOTE: %sYou have %ssuccessfully disabled %s%s Portals in %s.", + ChatColor.RED, ChatColor.WHITE, ChatColor.GREEN, ChatColor.WHITE, linkType, coloredTo) + : String.format("The %s portals in %s%s are now linked to %s.", + linkType, coloredFrom, ChatColor.WHITE, coloredTo)); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/netherportals/commands/ListCommand.java b/src/main/java/org/mvplugins/multiverse/netherportals/commands/ListCommand.java new file mode 100644 index 0000000..728aca8 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/netherportals/commands/ListCommand.java @@ -0,0 +1,133 @@ +package org.mvplugins.multiverse.netherportals.commands; + +import org.bukkit.ChatColor; +import org.bukkit.PortalType; +import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.core.display.ContentDisplay; +import org.mvplugins.multiverse.core.display.handlers.PagedSendHandler; +import org.mvplugins.multiverse.core.display.parsers.ListContentProvider; +import org.mvplugins.multiverse.core.world.MultiverseWorld; +import org.mvplugins.multiverse.core.world.WorldManager; +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandAlias; +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandCompletion; +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandPermission; +import org.mvplugins.multiverse.external.acf.commands.annotation.Description; +import org.mvplugins.multiverse.external.acf.commands.annotation.Optional; +import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand; +import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax; +import org.mvplugins.multiverse.external.acf.commands.annotation.Values; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jetbrains.annotations.Nullable; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.netherportals.MultiverseNetherPortals; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Service +@CommandAlias("mvnp") +class ListCommand extends NetherPortalsCommand { + + private final MultiverseNetherPortals plugin; + private final WorldManager worldManager; + + @Inject + ListCommand( + @NotNull MVCommandManager commandManager, + @NotNull MultiverseNetherPortals plugin, + @NotNull WorldManager worldManager) { + super(commandManager); + this.plugin = plugin; + this.worldManager = worldManager; + } + + // todo page and filter + @CommandAlias("mvnplist|mvnpli") + @Subcommand("list") + @CommandPermission("multiverse.netherportals.show") // todo: maybe change to multiverse.netherportals.list + @CommandCompletion("nether|end") + @Syntax("[nether|end]") + @Description("Displays a nicely formatted list of all portal links.") + void onListCommand( + @NotNull MVCommandIssuer issuer, + + @Optional + @Values("nether|end") + @Syntax("") + @Description("Portal type to list.") + @Nullable String linkTypeString + ) { + PortalType linkType = null; + if (linkTypeString != null && !linkTypeString.isEmpty()) { + if (linkTypeString.equalsIgnoreCase("nether")) { + linkType = PortalType.NETHER; + } else if (linkTypeString.equalsIgnoreCase("end")) { + linkType = PortalType.ENDER; + } + } + + String linkString = parseTypeString(linkType); + ContentDisplay.create() + .addContent(ListContentProvider.forContent(buildLinkContent(linkType))) + .withSendHandler(PagedSendHandler.create() + .withHeader(String.format("%s==== [ %s %sPortal Links ] ====", ChatColor.DARK_PURPLE, linkString, ChatColor.DARK_PURPLE)) + .noContentMessage(String.format("%sNo %s %slinks found.", ChatColor.WHITE, linkString, ChatColor.WHITE)) + .doPagination(false)) + .send(issuer); + } + + private String parseTypeString(@Nullable PortalType linkType) { + if (linkType == null) { + return "All"; + } + return switch (linkType) { + case NETHER -> ChatColor.RED + "Nether"; + case ENDER -> ChatColor.AQUA + "End"; + default -> "All"; + }; + } + + private List buildLinkContent(@Nullable PortalType linkType) { + return linkType == null ? getAllLinksContent() : buildLinkContent(linkType, ""); + } + + private List getAllLinksContent() { + List contents = buildLinkContent( + PortalType.NETHER, + ChatColor.DARK_RED + "[" + ChatColor.RED + "Nether" + ChatColor.DARK_RED + "] " + ); + contents.addAll(buildLinkContent( + PortalType.ENDER, + ChatColor.DARK_AQUA + "[" + ChatColor.AQUA + "End" + ChatColor.DARK_AQUA + "] " + )); + return contents; + } + + private List buildLinkContent(@NotNull PortalType linkType, + @NotNull String prefix) { + + Map links = (linkType == PortalType.NETHER) + ? this.plugin.getWorldLinks() + : this.plugin.getEndWorldLinks(); + + return links.entrySet().stream() + .map(link -> parseSingleLink(link.getKey(), link.getValue(), prefix)) + .collect(Collectors.toList()); + } + + private String parseSingleLink(@NotNull String fromWorldString, + @NotNull String toWorldString, + @NotNull String prefix) { + + return prefix + ChatColor.WHITE + ParseWorldString(fromWorldString) + ChatColor.WHITE + " -> " + ParseWorldString(toWorldString); + } + + private String ParseWorldString(@NotNull String worldName) { + return this.worldManager.getLoadedWorld(worldName) + .map(MultiverseWorld::getAlias) + .getOrElse(ChatColor.GRAY + worldName + ChatColor.RED + " !!ERROR!!"); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/netherportals/commands/NetherPortalsCommand.java b/src/main/java/org/mvplugins/multiverse/netherportals/commands/NetherPortalsCommand.java new file mode 100644 index 0000000..15c791e --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/netherportals/commands/NetherPortalsCommand.java @@ -0,0 +1,16 @@ +package org.mvplugins.multiverse.netherportals.commands; + +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.core.commandtools.MultiverseCommand; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Contract; + +/** + * Base class for all NetherPortals commands. + */ +@Contract +public abstract class NetherPortalsCommand extends MultiverseCommand { + protected NetherPortalsCommand(@NotNull MVCommandManager commandManager) { + super(commandManager); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/netherportals/commands/UnlinkCommand.java b/src/main/java/org/mvplugins/multiverse/netherportals/commands/UnlinkCommand.java new file mode 100644 index 0000000..359cade --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/netherportals/commands/UnlinkCommand.java @@ -0,0 +1,73 @@ +package org.mvplugins.multiverse.netherportals.commands; + +import org.bukkit.ChatColor; +import org.bukkit.PortalType; +import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.external.acf.commands.InvalidCommandArgument; +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandAlias; +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandCompletion; +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandPermission; +import org.mvplugins.multiverse.external.acf.commands.annotation.Description; +import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand; +import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax; +import org.mvplugins.multiverse.external.acf.commands.annotation.Values; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.netherportals.MultiverseNetherPortals; + +import java.util.Objects; + +@Service +@CommandAlias("mvnp") +class UnlinkCommand extends NetherPortalsCommand { + + private final MultiverseNetherPortals plugin; + + @Inject + UnlinkCommand(@NotNull MVCommandManager commandManager, @NotNull MultiverseNetherPortals plugin) { + super(commandManager); + this.plugin = plugin; + } + + @CommandAlias("mvnpunlink|mvnpu") + @Subcommand("unlink") + @CommandPermission("multiverse.netherportals.unlink") + @CommandCompletion("nether|end @mvworlds:scope=both") + @Syntax(" [fromWorld]") + @Description("This will remove a world link that's been set. You do not need to do this before setting a new one.") + public void onLinkCommand( + @NotNull MVCommandIssuer issuer, + + @Values("nether|end") + @Syntax("") + @Description("Portal type to unlink.") + @NotNull String linkType, + + @Syntax("") + @Description("World the portals are at.") + @NotNull String fromWorldString + ) { + PortalType portalType = Objects.equals(linkType, "nether") ? PortalType.NETHER : PortalType.ENDER; + String toWorldString = this.plugin.getWorldLink(fromWorldString, portalType); + if (toWorldString == null) { + issuer.sendMessage(ChatColor.RED + "Whoops!" + ChatColor.WHITE + " The world " + + fromWorldString + ChatColor.WHITE + " was never linked."); + return; + } + + if (!this.plugin.removeWorldLink(fromWorldString, toWorldString, portalType)) { + throw new InvalidCommandArgument("There was an issue unlinking the portals! Please check console for errors."); + } + + if (fromWorldString.equals(toWorldString)) { + issuer.sendMessage(String.format("You have %ssuccessfully enabled %s%s portals for world %s.", + ChatColor.GREEN, ChatColor.WHITE, linkType, fromWorldString)); + return; + } + + issuer.sendMessage(String.format("The %s portals in %s%s are now %sunlinked %sfrom %s%s.", + linkType, fromWorldString, ChatColor.WHITE, ChatColor.RED, ChatColor.WHITE, toWorldString, ChatColor.WHITE)); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPCoreListener.java b/src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPCoreListener.java similarity index 56% rename from src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPCoreListener.java rename to src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPCoreListener.java index 8d1363d..0dcaba5 100644 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPCoreListener.java +++ b/src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPCoreListener.java @@ -1,20 +1,23 @@ -package com.onarandombox.MultiverseNetherPortals.listeners; +package org.mvplugins.multiverse.netherportals.listeners; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.event.MVConfigReloadEvent; -import com.onarandombox.MultiverseCore.event.MVDebugModeEvent; -import com.onarandombox.MultiverseCore.event.MVVersionEvent; -import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals; +import org.mvplugins.multiverse.netherportals.MultiverseNetherPortals; import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; +import org.mvplugins.multiverse.core.event.MVConfigReloadEvent; +import org.mvplugins.multiverse.core.event.MVDebugModeEvent; +import org.mvplugins.multiverse.core.event.MVDumpsDebugInfoEvent; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; import java.io.File; -public class MVNPCoreListener implements Listener { +@Service +public class MVNPCoreListener implements MVNPListener { private final MultiverseNetherPortals plugin; - public MVNPCoreListener(MultiverseNetherPortals plugin) { + @Inject + MVNPCoreListener(MultiverseNetherPortals plugin) { this.plugin = plugin; } @@ -35,10 +38,10 @@ public void configReloadEvent(MVConfigReloadEvent event) { * @param event The Version event. */ @EventHandler - public void versionEvent(MVVersionEvent event) { - event.appendVersionInfo(this.plugin.getVersionInfo()); + public void versionEvent(MVDumpsDebugInfoEvent event) { + event.appendDebugInfo(this.plugin.getDebugInfo()); File configFile = new File(this.plugin.getDataFolder(), "config.yml"); - event.putDetailedVersionInfo("multiverse-netherportals/config.yml", configFile); + event.putDetailedDebugInfo("multiverse-netherportals/config.yml", configFile); } /** diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPEntityListener.java b/src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPEntityListener.java similarity index 69% rename from src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPEntityListener.java rename to src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPEntityListener.java index e44a28f..a03cdef 100644 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPEntityListener.java +++ b/src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPEntityListener.java @@ -1,18 +1,11 @@ -package com.onarandombox.MultiverseNetherPortals.listeners; +package org.mvplugins.multiverse.netherportals.listeners; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.MVWorld; -import com.onarandombox.MultiverseCore.api.LocationManipulation; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseMessaging; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.event.MVPlayerTouchedPortalEvent; -import com.onarandombox.MultiverseCore.utils.PermissionTools; -import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals; -import com.onarandombox.MultiverseNetherPortals.utils.EndPlatformCreator; -import com.onarandombox.MultiverseNetherPortals.utils.MVEventRecord; -import com.onarandombox.MultiverseNetherPortals.utils.MVLinkChecker; -import com.onarandombox.MultiverseNetherPortals.utils.MVNameChecker; +import org.mvplugins.multiverse.netherportals.MultiverseNetherPortals; +import org.mvplugins.multiverse.netherportals.utils.EndPlatformCreator; +import org.mvplugins.multiverse.netherportals.utils.MVEventRecord; +import org.mvplugins.multiverse.netherportals.utils.MVLinkChecker; +import org.mvplugins.multiverse.netherportals.utils.MVNameChecker; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.PortalType; @@ -23,51 +16,70 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityPortalEnterEvent; import org.bukkit.event.entity.EntityPortalEvent; import org.bukkit.event.entity.EntityPortalExitEvent; import org.bukkit.util.Vector; -import org.jetbrains.annotations.Nullable; +import org.mvplugins.multiverse.core.api.LocationManipulation; +import org.mvplugins.multiverse.core.event.MVPlayerTouchedPortalEvent; +import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; +import org.mvplugins.multiverse.core.world.WorldManager; +import org.mvplugins.multiverse.core.world.entrycheck.WorldEntryCheckerProvider; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jetbrains.annotations.Nullable; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; import java.util.Date; import java.util.HashMap; import java.util.Map; -public class MVNPEntityListener implements Listener { +@Service +public class MVNPEntityListener implements MVNPListener { + + private static final int COOLDOWN = 250; + + private final Map playerErrors; private final MultiverseNetherPortals plugin; private final MVNameChecker nameChecker; private final MVLinkChecker linkChecker; - private final MVWorldManager worldManager; - private final PermissionTools pt; - private final int cooldown = 250; - private final MultiverseMessaging messaging; - private final Map playerErrors; + private final WorldEntryCheckerProvider entryCheckerProvider; + private final WorldManager worldManager; private final LocationManipulation locationManipulation; private final MVEventRecord eventRecord; + private final EndPlatformCreator endPlatformCreator; // the event record is used to track players that are currently standing // inside portals. it's used so that we don't need to run the the onEntityPortalEnter // listener more than once for a given player. that also means players are // only messaged once about why they can't go through a given portal. - public MVNPEntityListener(MultiverseNetherPortals plugin) { + @Inject + MVNPEntityListener( + @NotNull MultiverseNetherPortals plugin, + @NotNull MVNameChecker nameChecker, + @NotNull MVLinkChecker linkChecker, + @NotNull WorldEntryCheckerProvider entryCheckerProvider, + @NotNull WorldManager worldManager, + @NotNull LocationManipulation locationManipulation, + @NotNull MVEventRecord eventRecord, + @NotNull EndPlatformCreator endPlatformCreator) { + this.playerErrors = new HashMap<>(); this.plugin = plugin; - this.nameChecker = this.plugin.getNameChecker(); - this.linkChecker = this.plugin.getLinkChecker(); - this.worldManager = this.plugin.getCore().getMVWorldManager(); - this.pt = new PermissionTools(this.plugin.getCore()); - this.playerErrors = new HashMap(); - this.messaging = this.plugin.getCore().getMessaging(); - this.locationManipulation = this.plugin.getCore().getLocationManipulation(); - this.eventRecord = new MVEventRecord(this.plugin); + this.nameChecker = nameChecker; + this.linkChecker = linkChecker; + this.entryCheckerProvider = entryCheckerProvider; + this.worldManager = worldManager; + this.locationManipulation = locationManipulation; + this.eventRecord = eventRecord; + this.endPlatformCreator = endPlatformCreator; } /** * Shoot a player back from a portal. Returns true iff bounceback is * enabled and the PortalType is supported (see below), otherwise * returns false. - * + *

* Currently, only PortalType.NETHER is supported. * * @param p The Player to shoot back. @@ -224,7 +236,7 @@ public void onEntityPortalEnter(EntityPortalEnterEvent event) { if (this.playerErrors.containsKey(p.getName())) { Date lastTry = this.playerErrors.get(p.getName()); - if (lastTry.getTime() + this.cooldown > new Date().getTime()) { + if (lastTry.getTime() + this.COOLDOWN > new Date().getTime()) { return; } this.playerErrors.remove(p.getName()); @@ -242,18 +254,18 @@ public void onEntityPortalEnter(EntityPortalEnterEvent event) { if (currentWorld.equalsIgnoreCase(linkedWorld)) { if (this.plugin.isSendingDisabledPortalMessage()) { if (type == PortalType.ENDER) { - this.messaging.sendMessage(p, "End Portals have been disabled in this world!", false); + p.sendMessage("End Portals have been disabled in this world!"); } else { - this.messaging.sendMessage(p, "Nether Portals have been disabled in this world!", false); + p.sendMessage("Nether Portals have been disabled in this world!"); } } } else { if (this.plugin.isSendingNoDestinationMessage()) { - this.messaging.sendMessage(p, "This portal goes nowhere!", false); + p.sendMessage("This portal goes nowhere!"); if (type == PortalType.ENDER) { - this.messaging.sendMessage(p, "No specific end world has been linked to this world and '" + this.nameChecker.getEndName(currentWorld) + "' is not a world.", true); + p.sendMessage("No specific end world has been linked to this world and '" + this.nameChecker.getEndName(currentWorld) + "' is not a world."); } else { - this.messaging.sendMessage(p, "No specific nether world has been linked to this world and '" + this.nameChecker.getNetherName(currentWorld) + "' is not a world.", true); + p.sendMessage("No specific nether world has been linked to this world and '" + this.nameChecker.getNetherName(currentWorld) + "' is not a world."); } } } @@ -261,36 +273,25 @@ public void onEntityPortalEnter(EntityPortalEnterEvent event) { return; } - MultiverseWorld fromWorld = this.worldManager.getMVWorld(p.getLocation().getWorld().getName()); - MultiverseWorld toWorld = this.worldManager.getMVWorld(toLocation.getWorld().getName()); + LoadedMultiverseWorld fromWorld = this.worldManager.getLoadedWorld(p.getLocation().getWorld()).getOrNull(); + LoadedMultiverseWorld toWorld = this.worldManager.getLoadedWorld(toLocation.getWorld()).getOrNull(); - if (fromWorld.getCBWorld().equals(toWorld.getCBWorld())) { + if (fromWorld.getBukkitWorld().eq(toWorld.getBukkitWorld())) { // The player is Portaling to the same world. Logging.finer("Player '" + p.getName() + "' is portaling to the same world."); return; } - if (!pt.playerHasMoneyToEnter(fromWorld, toWorld, p, p, false)) { - if (this.shootPlayer(p, eventLocation.getBlock(), type)) { - eventRecord.removeFromRecord(type, p.getUniqueId()); - } - - Logging.fine("Player '" + p.getName() + "' was DENIED ACCESS to '" + toWorld.getCBWorld().getName() + - "' because they don't have the FUNDS required to enter."); - return; - } - if (this.plugin.getCore().getMVConfig().getEnforceAccess()) { - if (!pt.playerCanGoFromTo(fromWorld, toWorld, p, p)) { - if (this.shootPlayer(p, eventLocation.getBlock(), type)) { - eventRecord.removeFromRecord(type, p.getUniqueId()); - } - - Logging.fine("Player '" + p.getName() + "' was DENIED ACCESS to '" + toWorld.getCBWorld().getName() + - "' because they don't have: multiverse.access." + toWorld.getCBWorld().getName()); - } - } else { - Logging.fine("Player '" + p.getName() + "' was allowed to go to '" + toWorld.getCBWorld().getName() + "' because enforceaccess is off."); - } + entryCheckerProvider.forSender(p).canEnterWorld(fromWorld, toWorld) + .onSuccess((result) -> { + Logging.fine("Player '" + p.getName() + "' was ALLOWED ACCESS to '" + toWorld.getName() + "'" + ": " + result); + }) + .onFailure((result) -> { + if (this.shootPlayer(p, eventLocation.getBlock(), type)) { + eventRecord.removeFromRecord(type, p.getUniqueId()); + } + Logging.fine("Player '" + p.getName() + "' was DENIED ACCESS to '" + toWorld.getName() + "'" + ": " + result); + }); } @EventHandler @@ -340,16 +341,6 @@ public void onEntityPortal(EntityPortalEvent event) { return; } - // Are we allowed to use the nether portal travel agent? - if (type == PortalType.NETHER) { - try { - Class.forName("org.bukkit.TravelAgent"); - event.useTravelAgent(true); - } catch (ClassNotFoundException ignore) { - Logging.fine("TravelAgent not available for EntityPortalEvent for " + entity.getName()); - } - } - String fromWorldName = fromWorld.getName(); String linkedWorldName = this.plugin.getWorldLink(fromWorldName, type); Location newToLocation = getLocation(entity, fromLocation, type, fromWorldName, linkedWorldName); // Gets the player spawn location from the portal spawn location @@ -361,35 +352,28 @@ public void onEntityPortal(EntityPortalEvent event) { } event.setTo(newToLocation); - MultiverseWorld newToWorld = this.worldManager.getMVWorld(newToLocation.getWorld()); + LoadedMultiverseWorld newToWorld = this.worldManager.getLoadedWorld(newToLocation.getWorld()).getOrNull(); // If we are going to the overworld from the end if (fromWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) { - Logging.fine("Entity '" + entity.getName() + "' will be teleported to the spawn of '" + newToWorld.getName() + "' since they used an end exit portal."); - try { - Class.forName("org.bukkit.TravelAgent"); - event.getPortalTravelAgent().setCanCreatePortal(false); - } catch (ClassNotFoundException ignore) { - Logging.fine("TravelAgent not available for EntityPortalEvent for " + entity.getName() + ". There may be a portal created at spawn."); - } event.setTo(newToWorld.getSpawnLocation()); } // If we are going to the overworld from the nether - else if (fromWorld.getEnvironment() == World.Environment.NETHER && type == PortalType.NETHER) { - try { - Class.forName("org.bukkit.TravelAgent"); - event.getPortalTravelAgent().setCanCreatePortal(true); - event.setTo(event.getPortalTravelAgent().findOrCreate(newToLocation)); - } catch (ClassNotFoundException ignore) { - Logging.fine("TravelAgent not available for EntityPortalEvent for " + entity.getName() + ". Their destination may not be correct."); - event.setTo(newToLocation); - } - } +// else if (fromWorld.getEnvironment() == World.Environment.NETHER && type == PortalType.NETHER) { +// try { +// Class.forName("org.bukkit.TravelAgent"); +// event.getPortalTravelAgent().setCanCreatePortal(true); +// event.setTo(event.getPortalTravelAgent().findOrCreate(newToLocation)); +// } catch (ClassNotFoundException ignore) { +// Logging.fine("TravelAgent not available for EntityPortalEvent for " + entity.getName() + ". Their destination may not be correct."); +// event.setTo(newToLocation); +// } +// } // If we are going to the end from anywhere else if (newToWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) { - Location spawnLocation = EndPlatformCreator.getVanillaLocation(entity, newToWorld); + Location spawnLocation = endPlatformCreator.getVanillaLocation(entity, newToWorld); event.setTo(spawnLocation); - EndPlatformCreator.createEndPlatform(spawnLocation.getWorld(), plugin.isEndPlatformDropBlocks()); + endPlatformCreator.createEndPlatform(spawnLocation.getWorld(), plugin.isEndPlatformDropBlocks()); } } diff --git a/src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPListener.java b/src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPListener.java new file mode 100644 index 0000000..2c67c77 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPListener.java @@ -0,0 +1,8 @@ +package org.mvplugins.multiverse.netherportals.listeners; + +import org.bukkit.event.Listener; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Contract; + +@Contract +public interface MVNPListener extends Listener { +} diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPPlayerListener.java b/src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPPlayerListener.java similarity index 70% rename from src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPPlayerListener.java rename to src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPPlayerListener.java index 297541d..33ac590 100644 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPPlayerListener.java +++ b/src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPPlayerListener.java @@ -1,13 +1,10 @@ -package com.onarandombox.MultiverseNetherPortals.listeners; +package org.mvplugins.multiverse.netherportals.listeners; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.utils.PermissionTools; -import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals; -import com.onarandombox.MultiverseNetherPortals.utils.EndPlatformCreator; -import com.onarandombox.MultiverseNetherPortals.utils.MVLinkChecker; -import com.onarandombox.MultiverseNetherPortals.utils.MVNameChecker; +import org.mvplugins.multiverse.netherportals.MultiverseNetherPortals; +import org.mvplugins.multiverse.netherportals.utils.EndPlatformCreator; +import org.mvplugins.multiverse.netherportals.utils.MVLinkChecker; +import org.mvplugins.multiverse.netherportals.utils.MVNameChecker; import org.bukkit.Location; import org.bukkit.NamespacedKey; import org.bukkit.PortalType; @@ -16,29 +13,42 @@ import org.bukkit.advancement.AdvancementProgress; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerTeleportEvent; +import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; +import org.mvplugins.multiverse.core.world.WorldManager; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; -public class MVNPPlayerListener implements Listener { +@Service +public class MVNPPlayerListener implements MVNPListener { private final MultiverseNetherPortals plugin; private final MVNameChecker nameChecker; private final MVLinkChecker linkChecker; - private final MVWorldManager worldManager; - private final PermissionTools pt; + private final WorldManager worldManager; + private final EndPlatformCreator endPlatformCreator; + private final Advancement enterNetherAdvancement; private final Advancement enterEndAdvancement; private static final String ENTER_NETHER_CRITERIA = "entered_nether"; private static final String ENTER_END_CRITERIA = "entered_end"; - public MVNPPlayerListener(MultiverseNetherPortals plugin) { + @Inject + public MVNPPlayerListener( + @NotNull MultiverseNetherPortals plugin, + @NotNull MVNameChecker nameChecker, + @NotNull MVLinkChecker linkChecker, + @NotNull WorldManager worldManager, + @NotNull EndPlatformCreator endPlatformCreator) { this.plugin = plugin; - this.nameChecker = this.plugin.getNameChecker(); - this.worldManager = this.plugin.getCore().getMVWorldManager(); - this.pt = new PermissionTools(this.plugin.getCore()); - this.linkChecker = this.plugin.getLinkChecker(); + this.nameChecker = nameChecker; + this.linkChecker = linkChecker; + this.worldManager = worldManager; + this.endPlatformCreator = endPlatformCreator; + this.enterNetherAdvancement = this.plugin.getServer().getAdvancement(NamespacedKey.minecraft("story/enter_the_nether")); this.enterEndAdvancement = this.plugin.getServer().getAdvancement(NamespacedKey.minecraft("story/enter_the_end")); } @@ -66,15 +76,6 @@ public void onPlayerPortal(PlayerPortalEvent event) { Player player = event.getPlayer(); - if (type == PortalType.NETHER) { - try { - Class.forName("org.bukkit.TravelAgent"); - event.useTravelAgent(true); - } catch (ClassNotFoundException ignore) { - Logging.fine("TravelAgent not available for PlayerPortalEvent for " + player.getName()); - } - } - Location newTo; String currentWorld = currentLocation.getWorld().getName(); String linkedWorld = this.plugin.getWorldLink(currentWorld, type); @@ -109,38 +110,26 @@ public void onPlayerPortal(PlayerPortalEvent event) { return; } - MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName()); - MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName()); + LoadedMultiverseWorld fromWorld = this.worldManager.getLoadedWorld(event.getFrom().getWorld()).getOrNull(); + LoadedMultiverseWorld toWorld = this.worldManager.getLoadedWorld(event.getTo().getWorld()).getOrNull(); if (!event.isCancelled()) { if (fromWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) { Logging.fine("Player '" + player.getName() + "' will be teleported to the spawn of '" + toWorld.getName() + "' since they used an end exit portal."); - try { - Class.forName("org.bukkit.TravelAgent"); - event.getPortalTravelAgent().setCanCreatePortal(false); - } catch (ClassNotFoundException ignore) { - Logging.fine("TravelAgent not available for PlayerPortalEvent for " + player.getName() + ". There may be a portal created at spawn."); - } + event.setCanCreatePortal(false); if (toWorld.getBedRespawn() && player.getBedSpawnLocation() != null - && player.getBedSpawnLocation().getWorld().getUID() == toWorld.getCBWorld().getUID()) { + && toWorld.getUID().equals(player.getBedSpawnLocation().getWorld().getUID())) { event.setTo(player.getBedSpawnLocation()); } else { event.setTo(toWorld.getSpawnLocation()); } } else if (fromWorld.getEnvironment() == World.Environment.NETHER && type == PortalType.NETHER) { - try { - Class.forName("org.bukkit.TravelAgent"); - event.getPortalTravelAgent().setCanCreatePortal(true); - event.setTo(event.getPortalTravelAgent().findOrCreate(event.getTo())); - } catch (ClassNotFoundException ignore) { - Logging.fine("TravelAgent not available for PlayerPortalEvent for " + player.getName() + ". Their destination may not be correct."); - event.setTo(event.getTo()); - } + event.setCanCreatePortal(true); } else if (toWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) { - Location spawnLocation = EndPlatformCreator.getVanillaLocation(player, event.getTo().getWorld()); + Location spawnLocation = endPlatformCreator.getVanillaLocation(player, event.getTo().getWorld()); event.setTo(spawnLocation); - EndPlatformCreator.createEndPlatform(spawnLocation.getWorld(), plugin.isEndPlatformDropBlocks()); + endPlatformCreator.createEndPlatform(spawnLocation.getWorld(), plugin.isEndPlatformDropBlocks()); } // Advancements need to be triggered manually diff --git a/src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPPluginListener.java b/src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPPluginListener.java new file mode 100644 index 0000000..24e25f2 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/netherportals/listeners/MVNPPluginListener.java @@ -0,0 +1,34 @@ +package org.mvplugins.multiverse.netherportals.listeners; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.PluginEnableEvent; + +import org.mvplugins.multiverse.netherportals.MultiverseNetherPortals; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; + +@Service +public class MVNPPluginListener implements MVNPListener { + + private final MultiverseNetherPortals plugin; + + @Inject + public MVNPPluginListener(MultiverseNetherPortals plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onPluginEnable(PluginEnableEvent event) { + if (event.getPlugin().getDescription().getName().equals("Multiverse-Portals")) { + this.plugin.setPortals(event.getPlugin()); + } + } + + @EventHandler + public void onPluginDisable(PluginDisableEvent event) { + if (event.getPlugin().getDescription().getName().equals("Multiverse-Portals")) { + this.plugin.setPortals(null); + } + } +} diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/runnables/PlayerTouchingPortalTask.java b/src/main/java/org/mvplugins/multiverse/netherportals/runnables/PlayerTouchingPortalTask.java similarity index 89% rename from src/main/java/com/onarandombox/MultiverseNetherPortals/runnables/PlayerTouchingPortalTask.java rename to src/main/java/org/mvplugins/multiverse/netherportals/runnables/PlayerTouchingPortalTask.java index bc49613..2b24e77 100644 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/runnables/PlayerTouchingPortalTask.java +++ b/src/main/java/org/mvplugins/multiverse/netherportals/runnables/PlayerTouchingPortalTask.java @@ -1,6 +1,6 @@ -package com.onarandombox.MultiverseNetherPortals.runnables; +package org.mvplugins.multiverse.netherportals.runnables; -import com.onarandombox.MultiverseNetherPortals.utils.MVEventRecord; +import org.mvplugins.multiverse.netherportals.utils.MVEventRecord; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.PortalType; diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/utils/EndPlatformCreator.java b/src/main/java/org/mvplugins/multiverse/netherportals/utils/EndPlatformCreator.java similarity index 80% rename from src/main/java/com/onarandombox/MultiverseNetherPortals/utils/EndPlatformCreator.java rename to src/main/java/org/mvplugins/multiverse/netherportals/utils/EndPlatformCreator.java index 628fc43..74c7c52 100644 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/utils/EndPlatformCreator.java +++ b/src/main/java/org/mvplugins/multiverse/netherportals/utils/EndPlatformCreator.java @@ -1,7 +1,6 @@ -package com.onarandombox.MultiverseNetherPortals.utils; +package org.mvplugins.multiverse.netherportals.utils; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -9,7 +8,10 @@ import org.bukkit.block.BlockFace; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; +@Service public class EndPlatformCreator { /** @@ -18,7 +20,7 @@ public class EndPlatformCreator { * @param world The world to create the platform in * @param dropEndBlocks If the platform should drop the broken blocks or delete them */ - public static void createEndPlatform(World world, boolean dropEndBlocks) { + public void createEndPlatform(World world, boolean dropEndBlocks) { Block spawnLocation = new Location(world, 100, 49, 0).getBlock(); Logging.fine("Creating an end platform at " + spawnLocation); @@ -50,7 +52,7 @@ public static void createEndPlatform(World world, boolean dropEndBlocks) { /** * The default vanilla location for the end platform */ - public static Location getVanillaLocation(Entity entity, World world) { + public Location getVanillaLocation(Entity entity, World world) { return entity instanceof Player ? new Location(world, 100, 49, 0, 90, 0) : new Location(world, 100.5, 50, 0.5, 90, 0); @@ -59,7 +61,7 @@ public static Location getVanillaLocation(Entity entity, World world) { /** * The default vanilla location for the end platform */ - public static Location getVanillaLocation(Entity entity, MultiverseWorld world) { - return getVanillaLocation(entity, world.getCBWorld()); + public Location getVanillaLocation(Entity entity, LoadedMultiverseWorld world) { + return getVanillaLocation(entity, world.getBukkitWorld().getOrNull()); } } diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/utils/MVEventRecord.java b/src/main/java/org/mvplugins/multiverse/netherportals/utils/MVEventRecord.java similarity index 86% rename from src/main/java/com/onarandombox/MultiverseNetherPortals/utils/MVEventRecord.java rename to src/main/java/org/mvplugins/multiverse/netherportals/utils/MVEventRecord.java index a8ab37c..aa52534 100644 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/utils/MVEventRecord.java +++ b/src/main/java/org/mvplugins/multiverse/netherportals/utils/MVEventRecord.java @@ -1,20 +1,24 @@ -package com.onarandombox.MultiverseNetherPortals.utils; +package org.mvplugins.multiverse.netherportals.utils; -import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals; -import com.onarandombox.MultiverseNetherPortals.runnables.PlayerTouchingPortalTask; +import org.mvplugins.multiverse.netherportals.MultiverseNetherPortals; +import org.mvplugins.multiverse.netherportals.runnables.PlayerTouchingPortalTask; import org.bukkit.PortalType; import org.bukkit.scheduler.BukkitTask; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; import java.util.HashMap; import java.util.Map; import java.util.UUID; +@Service public class MVEventRecord { private final MultiverseNetherPortals plugin; private final Map ender; private final Map nether; - public MVEventRecord(MultiverseNetherPortals plugin) { + @Inject + MVEventRecord(MultiverseNetherPortals plugin) { this.plugin = plugin; this.ender = new HashMap<>(); this.nether = new HashMap<>(); diff --git a/src/main/java/org/mvplugins/multiverse/netherportals/utils/MVLinkChecker.java b/src/main/java/org/mvplugins/multiverse/netherportals/utils/MVLinkChecker.java new file mode 100644 index 0000000..06703d6 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/netherportals/utils/MVLinkChecker.java @@ -0,0 +1,54 @@ +package org.mvplugins.multiverse.netherportals.utils; + +import com.dumptruckman.minecraft.util.Logging; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; +import org.mvplugins.multiverse.core.world.WorldManager; +import org.mvplugins.multiverse.core.world.entrycheck.WorldEntryCheckerProvider; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; + +@Service +public class MVLinkChecker { + private final WorldManager worldManager; + private final WorldEntryCheckerProvider entryCheckerProvider; + + @Inject + MVLinkChecker(WorldManager worldManager, WorldEntryCheckerProvider entryCheckerProvider) { + this.worldManager = worldManager; + this.entryCheckerProvider = entryCheckerProvider; + } + + public Location findNewTeleportLocation(Location fromLocation, String worldString, Entity e) { + LoadedMultiverseWorld tpFrom = this.worldManager.getLoadedWorld(fromLocation.getWorld()).getOrNull(); + LoadedMultiverseWorld tpTo = this.worldManager.getLoadedWorld(worldString).getOrNull(); + + if (tpTo == null) { + Logging.fine("Can't find world " + worldString); + } else if (e instanceof Player && !this.entryCheckerProvider.forSender(e).canEnterWorld(tpFrom, tpTo).isSuccess()) { + Logging.warning("Player " + e.getName() + " can't enter world " + worldString); + } else if (!this.worldManager.isLoadedWorld(fromLocation.getWorld())) { + Logging.warning("World " + fromLocation.getWorld().getName() + " is not a Multiverse world"); + } else { + String entityType = (e instanceof Player) ? " player " : " entity "; + Logging.fine("Finding new teleport location for" + entityType + e.getName() + " to world " + worldString); + + // Set the output location to the same XYZ coords but different world + double fromScaling = tpFrom.getScale(); + double toScaling = tpTo.getScale(); + + this.scaleLocation(fromLocation, fromScaling / toScaling); + fromLocation.setWorld(tpTo.getBukkitWorld().getOrNull()); + return fromLocation; + } + + return null; + } + + private void scaleLocation(Location fromLocation, double scaling) { + fromLocation.setX(fromLocation.getX() * scaling); + fromLocation.setZ(fromLocation.getZ() * scaling); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/utils/MVNameChecker.java b/src/main/java/org/mvplugins/multiverse/netherportals/utils/MVNameChecker.java similarity index 77% rename from src/main/java/com/onarandombox/MultiverseNetherPortals/utils/MVNameChecker.java rename to src/main/java/org/mvplugins/multiverse/netherportals/utils/MVNameChecker.java index 5fbdeaf..a6e73a2 100644 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/utils/MVNameChecker.java +++ b/src/main/java/org/mvplugins/multiverse/netherportals/utils/MVNameChecker.java @@ -1,15 +1,25 @@ -package com.onarandombox.MultiverseNetherPortals.utils; +package org.mvplugins.multiverse.netherportals.utils; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals; +import org.mvplugins.multiverse.netherportals.MultiverseNetherPortals; import org.bukkit.PortalType; +import org.mvplugins.multiverse.core.world.WorldManager; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; +@Service public class MVNameChecker { + private final MultiverseNetherPortals plugin; + private final WorldManager worldManager; - public MVNameChecker(MultiverseNetherPortals plugin) { + @Inject + MVNameChecker(@NotNull MultiverseNetherPortals plugin, @NotNull WorldManager worldManager) { this.plugin = plugin; + this.worldManager = worldManager; } + /** * Returns true if the world meets the naming criteria for a nether world. It is NOT checked against the actual worlds here! * @@ -50,7 +60,7 @@ public boolean isValidEndName(String world) { */ public String getNetherName(String normalName) { final String netherName = this.plugin.getNetherPrefix() + normalName + this.plugin.getNetherSuffix(); - if (plugin.getCore().getMVWorldManager().isMVWorld(netherName)) { + if (worldManager.isLoadedWorld(netherName)) { Logging.finest("Selected nether world '" + netherName + "' for normal '" + normalName + "'"); } return netherName; @@ -64,7 +74,7 @@ public String getNetherName(String normalName) { */ public String getEndName(String normalName) { final String endName = this.plugin.getEndPrefix() + normalName + this.plugin.getEndSuffix(); - if (plugin.getCore().getMVWorldManager().isMVWorld(endName)) { + if (worldManager.isLoadedWorld(endName)) { Logging.finest("Selected end world '" + endName + "' for normal '" + normalName + "'"); } return endName; @@ -80,27 +90,27 @@ public String getNormalName(String netherName, PortalType type) { String normalName = netherName; // Chop off the prefix if (type == PortalType.NETHER) { - if (this.plugin.getNetherPrefix().length() > 0) { + if (!this.plugin.getNetherPrefix().isEmpty()) { String[] split = normalName.split(this.plugin.getNetherPrefix()); normalName = split[1]; } // Chop off the suffix - if (this.plugin.getNetherSuffix().length() > 0) { + if (!this.plugin.getNetherSuffix().isEmpty()) { String[] split = normalName.split(this.plugin.getNetherSuffix()); normalName = split[0]; } } else if (type == PortalType.ENDER) { - if (this.plugin.getNetherPrefix().length() > 0) { + if (!this.plugin.getNetherPrefix().isEmpty()) { String[] split = normalName.split(this.plugin.getEndPrefix()); normalName = split[1]; } // Chop off the suffix - if (this.plugin.getNetherSuffix().length() > 0) { + if (!this.plugin.getNetherSuffix().isEmpty()) { String[] split = normalName.split(this.plugin.getEndSuffix()); normalName = split[0]; } } - if (!normalName.equals(netherName) && plugin.getCore().getMVWorldManager().isMVWorld(normalName)) { + if (!normalName.equals(netherName) && worldManager.isLoadedWorld(normalName)) { Logging.finest("Selected normal world '" + normalName + "' for " + type + " '" + netherName + "'"); } // All we're left with is the normal world. Don't worry if it exists, the method below will handle that! diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4b9059d..32bd515 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,35 +1,7 @@ name: Multiverse-NetherPortals -main: com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals -authors: ['Rigby', 'fernferret'] +main: org.mvplugins.multiverse.netherportals.MultiverseNetherPortals +authors: ['Rigby', 'fernferret', 'benwoo1110'] version: ${version} api-version: 1.13 depend: ['Multiverse-Core'] softdepend: ['Multiverse-Portals'] -commands: - mvnp: - description: Generic Multiverse-NetherPortals Command - usage: / - mvnpl: - description: Generic Multiverse-NetherPortals Command - usage: / - mvnpli: - description: Generic Multiverse-NetherPortals Command - usage: / - mvnplist: - description: Generic Multiverse-NetherPortals Command - usage: / - mvnpu: - description: Generic Multiverse-NetherPortals Command - usage: / - mvnps: - description: Generic Multiverse-NetherPortals Command - usage: / - mvnplink: - description: Generic Multiverse-NetherPortals Command - usage: / - mvnpunlink: - description: Generic Multiverse-NetherPortals Command - usage: / - mvnpshow: - description: Generic Multiverse-NetherPortals Command - usage: / \ No newline at end of file