From a3ab6d34f8c7743b941d891e63342746245c7620 Mon Sep 17 00:00:00 2001 From: Jeremy Wood Date: Thu, 8 Oct 2020 02:25:32 -0400 Subject: [PATCH 01/14] Bumped version to 5.0.0-SNAPSHOT for development of next major version. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5665f92..ebb4d1c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.onarandombox.multiverseportals Multiverse-Portals - 4.2.2-SNAPSHOT + 5.0.0-SNAPSHOT Multiverse-Portals Multiverse Portals module From 3a6a06d1fabb4fca312e016a43ad3a6e3fdce0dc Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:43:21 +0800 Subject: [PATCH 02/14] Base build of mv-portals working with MV5 --- build.gradle | 29 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../commands/ConfigCommand.java | 99 ------ .../commands/CreateCommand.java | 109 ------- .../commands/DebugCommand.java | 54 ---- .../commands/InfoCommand.java | 48 --- .../commands/ListCommand.java | 148 --------- .../commands/ModifyCommand.java | 191 ------------ .../commands/PortalCommand.java | 32 -- .../commands/RemoveCommand.java | 46 --- .../commands/SelectCommand.java | 65 ---- .../commands/WandCommand.java | 76 ----- .../destination/PortalDestination.java | 151 ---------- .../destination/RandomPortalDestination.java | 116 ------- .../listeners/MVPTravelAgent.java | 27 -- .../listeners/PlayerListenerHelper.java | 92 ------ .../multiverse/portals}/MVPortal.java | 152 ++++++---- .../portals}/MultiversePortals.java | 215 ++++--------- .../MultiversePortalsPluginBinder.java | 19 ++ .../multiverse/portals}/PortalLocation.java | 22 +- .../portals}/PortalPlayerSession.java | 78 ++--- .../portals}/WorldEditConnection.java | 284 +++++++++--------- .../portals/commands/PortalsCommand.java | 16 + .../destination/PortalDestination.java | 55 ++++ .../PortalDestinationInstance.java | 62 ++++ .../destination/RandomPortalDestination.java | 41 +++ .../RandomPortalDestinationInstance.java | 59 ++++ .../multiverse/portals}/enums/MoveType.java | 32 +- .../portals}/enums/PortalConfigProperty.java | 56 ++-- .../multiverse/portals}/enums/PortalType.java | 34 +-- .../portals}/enums/SetProperties.java | 24 +- .../portals}/event/MVPortalEvent.java | 30 +- .../portals}/listeners/MVPBlockListener.java | 22 +- .../portals}/listeners/MVPCoreListener.java | 38 ++- .../portals}/listeners/MVPPlayerListener.java | 107 +++---- .../listeners/MVPPlayerMoveListener.java | 89 +++--- .../portals}/listeners/MVPPluginListener.java | 20 +- .../listeners/MVPVehicleListener.java | 142 +++++---- .../listeners/PlayerListenerHelper.java | 49 +++ .../portals/listeners/PortalsListener.java | 11 + .../portals}/utils/DisplayUtils.java | 42 ++- .../portals}/utils/MultiverseRegion.java | 185 ++++++------ .../portals}/utils/PortalFiller.java | 27 +- .../portals}/utils/PortalManager.java | 42 +-- 44 files changed, 1137 insertions(+), 2101 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiversePortals/commands/ConfigCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiversePortals/commands/CreateCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiversePortals/commands/DebugCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiversePortals/commands/InfoCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiversePortals/commands/ListCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiversePortals/commands/ModifyCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiversePortals/commands/PortalCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiversePortals/commands/RemoveCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiversePortals/commands/SelectCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiversePortals/commands/WandCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiversePortals/destination/PortalDestination.java delete mode 100644 src/main/java/com/onarandombox/MultiversePortals/destination/RandomPortalDestination.java delete mode 100644 src/main/java/com/onarandombox/MultiversePortals/listeners/MVPTravelAgent.java delete mode 100644 src/main/java/com/onarandombox/MultiversePortals/listeners/PlayerListenerHelper.java rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/MVPortal.java (83%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/MultiversePortals.java (70%) create mode 100644 src/main/java/org/mvplugins/multiverse/portals/MultiversePortalsPluginBinder.java rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/PortalLocation.java (85%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/PortalPlayerSession.java (78%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/WorldEditConnection.java (96%) create mode 100644 src/main/java/org/mvplugins/multiverse/portals/commands/PortalsCommand.java create mode 100644 src/main/java/org/mvplugins/multiverse/portals/destination/PortalDestination.java create mode 100644 src/main/java/org/mvplugins/multiverse/portals/destination/PortalDestinationInstance.java create mode 100644 src/main/java/org/mvplugins/multiverse/portals/destination/RandomPortalDestination.java create mode 100644 src/main/java/org/mvplugins/multiverse/portals/destination/RandomPortalDestinationInstance.java rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/enums/MoveType.java (84%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/enums/PortalConfigProperty.java (89%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/enums/PortalType.java (85%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/enums/SetProperties.java (84%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/event/MVPortalEvent.java (75%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/listeners/MVPBlockListener.java (52%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/listeners/MVPCoreListener.java (68%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/listeners/MVPPlayerListener.java (79%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/listeners/MVPPlayerMoveListener.java (67%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/listeners/MVPPluginListener.java (73%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/listeners/MVPVehicleListener.java (50%) create mode 100644 src/main/java/org/mvplugins/multiverse/portals/listeners/PlayerListenerHelper.java create mode 100644 src/main/java/org/mvplugins/multiverse/portals/listeners/PortalsListener.java rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/utils/DisplayUtils.java (56%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/utils/MultiverseRegion.java (79%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/utils/PortalFiller.java (81%) rename src/main/java/{com/onarandombox/MultiversePortals => org/mvplugins/multiverse/portals}/utils/PortalManager.java (90%) diff --git a/build.gradle b/build.gradle index 8c03fc5..2ae36e7 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.multiverseportals' +group = 'org.mvplugins.multiverse.portals' description = 'Multiverse-Portals' -java.sourceCompatibility = JavaVersion.VERSION_11 +compileJava { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} repositories { mavenLocal() @@ -33,10 +36,12 @@ repositories { dependencies { // Spigot - implementation 'org.bukkit:bukkit:1.13.2-R0.1-SNAPSHOT' + implementation('org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT') { + exclude group: 'junit', module: 'junit' + } // Core - implementation 'com.onarandombox.multiversecore:Multiverse-Core:4.2.2' + implementation 'org.mvplugins.multiverse.core:multiverse-core:local' //WorldEdit implementation('com.sk89q.worldedit:worldedit-bukkit:7.2.9') { @@ -125,8 +130,20 @@ shadowJar { 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-portals-$version" + ".jar", + '--locator', 'Multiverse-Portals', + ] +} +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/MultiversePortals/commands/ConfigCommand.java b/src/main/java/com/onarandombox/MultiversePortals/commands/ConfigCommand.java deleted file mode 100644 index 61c22c5..0000000 --- a/src/main/java/com/onarandombox/MultiversePortals/commands/ConfigCommand.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.commands; - -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import com.onarandombox.MultiversePortals.MultiversePortals; -import com.onarandombox.MultiversePortals.enums.PortalConfigProperty; - -public class ConfigCommand extends PortalCommand { - - public ConfigCommand(MultiversePortals plugin) { - super(plugin); - this.setName("Configuration"); - this.setCommandUsage("/mvp config " + ChatColor.GREEN + "{PROPERTY} {VALUE}"); - this.setArgRange(1, 2); - this.addKey("mvp config"); - this.addKey("mvpconfig"); - this.addKey("mvp conf"); - this.addKey("mvpconf"); - this.addCommandExample("All values: " + PortalConfigProperty.getAllValues()); - this.addCommandExample("/mvp config show"); - this.addCommandExample("/mvp config " + ChatColor.GREEN + "wand" + ChatColor.AQUA + " 271"); - this.addCommandExample("/mvp config " + ChatColor.GREEN + "useonmove" + ChatColor.AQUA + " false"); - this.addCommandExample("/mvp config " + ChatColor.GREEN + "enforceportalaccess" + ChatColor.AQUA + " true"); - this.setPermission("multiverse.portal.config", "Allows you to set Global MV Portals Variables.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - if (args.size() == 1) { - if (args.get(0).equalsIgnoreCase("show")) { - String[] allProps = PortalConfigProperty.getAllValues().split(" "); - String currentvals = ""; - for (String prop : allProps) { - currentvals += ChatColor.GREEN; - currentvals += prop; - currentvals += ChatColor.WHITE; - currentvals += " = "; - currentvals += ChatColor.GOLD; - currentvals += this.plugin.getMainConfig().get(prop, "NOT SET"); - currentvals += ChatColor.WHITE; - currentvals += ", "; - } - sender.sendMessage(currentvals.substring(0,currentvals.length() - 2)); - return; - } - - } - if (args.get(0).equalsIgnoreCase("wand") || args.get(0).equalsIgnoreCase("portalcooldown")) { - if(args.size() == 1) { - sender.sendMessage(ChatColor.AQUA + args.get(0) + ChatColor.WHITE + " has value " + ChatColor.GREEN + this.plugin.getMainConfig().get(args.get(0).toLowerCase())); - return; - } else { - try { - this.plugin.getMainConfig().set(args.get(0).toLowerCase(), Integer.parseInt(args.get(1))); - } catch (NumberFormatException e) { - sender.sendMessage(ChatColor.RED + "Sorry, " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE + " must be an integer!"); - return; - } - } - } else { - PortalConfigProperty property = null; - try { - property = PortalConfigProperty.valueOf(args.get(0).toLowerCase()); - } catch (IllegalArgumentException e) { - sender.sendMessage(ChatColor.RED + "Sorry, " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE + " you can't set " + ChatColor.AQUA + args.get(0)); - sender.sendMessage(ChatColor.GREEN + "Valid values are:"); - sender.sendMessage(PortalConfigProperty.getAllValues()); - return; - } - - if (property != null) { - try { - this.plugin.getMainConfig().set(args.get(0).toLowerCase(), Boolean.parseBoolean(args.get(1))); - } catch (Exception e) { - sender.sendMessage(ChatColor.RED + "Sorry, " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE + " must be true or false!"); - return; - } - - } - } - if (this.plugin.saveMainConfig()) { - sender.sendMessage(ChatColor.GREEN + "SUCCESS!" + ChatColor.WHITE + " Values were updated successfully!"); - this.plugin.reloadConfigs(false); - } else { - sender.sendMessage(ChatColor.RED + "FAIL!" + ChatColor.WHITE + " Check your console for details!"); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiversePortals/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiversePortals/commands/CreateCommand.java deleted file mode 100644 index 6ddbc68..0000000 --- a/src/main/java/com/onarandombox/MultiversePortals/commands/CreateCommand.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.commands; - -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.utils.LocationManipulation; -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.MultiversePortals; -import com.onarandombox.MultiversePortals.PortalLocation; -import com.onarandombox.MultiversePortals.PortalPlayerSession; -import com.onarandombox.MultiversePortals.utils.MultiverseRegion; - -public class CreateCommand extends PortalCommand { - - public CreateCommand(MultiversePortals plugin) { - super(plugin); - this.setName("Create a Portal"); - this.setCommandUsage("/mvp create" + ChatColor.GREEN + " {NAME}" + ChatColor.GOLD + " [DESTINATION]"); - this.setArgRange(1, 2); - this.addKey("mvp create"); - this.addKey("mvpc"); - this.addKey("mvpcreate"); - this.setPermission("multiverse.portal.create", "Creates a new portal, assuming you have a region selected.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - Player p = null; - if (!(sender instanceof Player)) { - sender.sendMessage("This command must be run by a player"); - return; - } - p = (Player) sender; - - if (!this.plugin.getCore().getMVWorldManager().isMVWorld(p.getWorld().getName())) { - this.plugin.getCore().showNotMVWorldMessage(sender, p.getWorld().getName()); - return; - } - MultiverseWorld world = this.plugin.getCore().getMVWorldManager().getMVWorld(p.getWorld().getName()); - - PortalPlayerSession ps = this.plugin.getPortalSession(p); - - MultiverseRegion r = ps.getSelectedRegion(); - if (r == null) { - return; - } - - String portalName = args.get(0); - if (!MVPortal.PORTAL_NAME_PATTERN.matcher(portalName).matches()) { - sender.sendMessage(String.format("%sInvalid portal name. It must not contain dot or special characters.", ChatColor.RED)); - return; - } - - MVPortal portal = this.plugin.getPortalManager().getPortal(portalName); - PortalLocation location = new PortalLocation(r.getMinimumPoint(), r.getMaximumPoint(), world); - if (this.plugin.getPortalManager().addPortal(world, portalName, p.getName(), location)) { - sender.sendMessage("New portal (" + ChatColor.DARK_AQUA + portalName + ChatColor.WHITE + ") created and selected!"); - // If the portal did not exist, ie: we're creating it. - // we have to re select it, because it would be null - portal = this.plugin.getPortalManager().getPortal(portalName); - - } else { - sender.sendMessage("New portal (" + ChatColor.DARK_AQUA + portalName + ChatColor.WHITE + ") was NOT created!"); - sender.sendMessage("It already existed and has been selected."); - } - - ps.selectPortal(portal); - - if (args.size() > 1 && portal != null) { - String dest = args.get(1); - if (dest.equalsIgnoreCase("here")) { - MVPortal standingIn = ps.getUncachedStandingInPortal(); - if (standingIn != null) { - // If they're standing in a portal. treat it differently, niftily you might say... - String cardinal = LocationManipulation.getDirection(p.getLocation()); - portal.setDestination("p:" + standingIn.getName() + ":" + cardinal); - } else { - portal.setExactDestination(p.getLocation()); - } - } else if (dest.matches("(i?)cannon-[\\d]+(\\.[\\d]+)?")) { - // We found a Cannon Destination! - Location l = p.getLocation(); - try { - double speed = Double.parseDouble(args.get(1).split("-")[1]); - portal.setDestination("ca:" + l.getWorld().getName() + ":" + l.getX() + "," + l.getY() + "," + l.getZ() + ":" + l.getPitch() + ":" + l.getYaw() + ":" + speed); - } catch (NumberFormatException e) { - portal.setDestination("i:invalid"); - } - - } else { - portal.setDestination(args.get(1)); - } - - } - } -} diff --git a/src/main/java/com/onarandombox/MultiversePortals/commands/DebugCommand.java b/src/main/java/com/onarandombox/MultiversePortals/commands/DebugCommand.java deleted file mode 100644 index 3263103..0000000 --- a/src/main/java/com/onarandombox/MultiversePortals/commands/DebugCommand.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.commands; - -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import com.onarandombox.MultiversePortals.MultiversePortals; -import com.onarandombox.MultiversePortals.PortalPlayerSession; - -public class DebugCommand extends PortalCommand { - - public DebugCommand(MultiversePortals plugin) { - super(plugin); - this.setName("Portal Debug Mode"); - this.setCommandUsage("/mvp debug" + ChatColor.GOLD + " [on|off]"); - this.setArgRange(0, 1); - this.addKey("mvp debug"); - this.addKey("mvpd"); - this.addKey("mvpdebug"); - this.setPermission("multiverse.portal.debug", "Instead of teleporting you to a place when you walk into a portal you will see the details about it. This command toggles.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - Player p = null; - if (!(sender instanceof Player)) { - sender.sendMessage("This command must be run by a player"); - return; - } - p = (Player) sender; - - if (!this.plugin.getCore().getMVWorldManager().isMVWorld(p.getWorld().getName())) { - this.plugin.getCore().showNotMVWorldMessage(sender, p.getWorld().getName()); - return; - } - - PortalPlayerSession ps = this.plugin.getPortalSession(p); - if (args.size() == 1) { - ps.setDebugMode(args.get(0).equalsIgnoreCase("on")); - return; - } - ps.setDebugMode(!ps.isDebugModeOn()); - } -} diff --git a/src/main/java/com/onarandombox/MultiversePortals/commands/InfoCommand.java b/src/main/java/com/onarandombox/MultiversePortals/commands/InfoCommand.java deleted file mode 100644 index 2ae6f57..0000000 --- a/src/main/java/com/onarandombox/MultiversePortals/commands/InfoCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.commands; - -import java.util.List; - -import com.onarandombox.MultiversePortals.utils.DisplayUtils; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.MultiversePortals; - -public class InfoCommand extends PortalCommand { - - public InfoCommand(MultiversePortals plugin) { - super(plugin); - this.setName("Portal Information"); - this.setCommandUsage("/mvp info " + ChatColor.GREEN + "{PORTAL}"); - this.setArgRange(1, 1); - this.addKey("mvp info"); - this.addKey("mvpi"); - this.addKey("mvpinfo"); - this.setPermission("multiverse.portal.info", "Displays information about a portal.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - MVPortal selected = this.plugin.getPortalManager().getPortal(args.get(0), sender); - if(selected == null) { - sender.sendMessage("Sorry! That portal doesn't exist or you're not allowed to use it!"); - return; - } - if(sender instanceof Player) { - Player p = (Player) sender; - this.plugin.getPortalSession(p).showDebugInfo(selected); - } else { - DisplayUtils.showStaticInfo(sender, selected, "Portal Info: "); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiversePortals/commands/ListCommand.java b/src/main/java/com/onarandombox/MultiversePortals/commands/ListCommand.java deleted file mode 100644 index 29f10a1..0000000 --- a/src/main/java/com/onarandombox/MultiversePortals/commands/ListCommand.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.commands; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.MultiversePortals; - -public class ListCommand extends PortalCommand { - - int itemsPerPage = 9; - - public ListCommand(MultiversePortals plugin) { - super(plugin); - this.setName("Portal Listing"); - this.setCommandUsage("/mvp list " + ChatColor.GOLD + "[FILTER/WORLD] [PAGE]"); - this.setArgRange(0, 2); - this.addKey("mvp list"); - this.addKey("mvpl"); - this.addKey("mvplist"); - this.setPermission("multiverse.portal.list", "Displays a listing of all portals that you can enter.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - MultiverseWorld world = null; - String filter = null; - int page = 1; - - if(args.size() == 1) { - try { - page = Integer.parseInt(args.get(0)); - } catch(NumberFormatException e) { - filter = args.get(0); - } - } - - if(args.size() == 2) { - try { - page = Integer.parseInt(args.get(1)); - filter = args.get(0); - } catch(NumberFormatException e) { - - } - } - - if(args.size() > 0) { - world = this.plugin.getCore().getMVWorldManager().getMVWorld(args.get(0)); - if (world != null) { - filter = null; - } - } - - List portals = new ArrayList<>(); - portals.addAll(getPortals(sender, world, filter, page)); - - if(portals.size() == 0 && filter == null) { - page = (int) Math.ceil(1F*getPortals(sender, world, filter).size()/itemsPerPage); - portals.addAll(getPortals(sender, world, filter, page)); - } - - String titleString = ChatColor.AQUA + String.valueOf(getPortals(sender, world, filter).size()) + " Portals"; - if (world != null) { - titleString += " in " + ChatColor.YELLOW + world.getAlias(); - } - if (filter != null) { - titleString += ChatColor.GOLD + " [" + filter + "]"; - } - - titleString += ChatColor.GOLD + " - Page " + page + "/" + (int) Math.ceil(1F*getPortals(sender, world, filter).size()/itemsPerPage); - sender.sendMessage(ChatColor.AQUA + "--- " + titleString + ChatColor.AQUA + " ---"); - - for(String portal : portals) { - sender.sendMessage(portal); - } - } - - private List getPortals(CommandSender sender, MultiverseWorld world, String filter) { - List portals = new ArrayList<>(); - if (filter == null) { - filter = ""; - } - for (MVPortal portal : (world == null) ? this.plugin.getPortalManager().getPortals(sender) : this.plugin.getPortalManager().getPortals(sender, world)) { - String destination = ""; - if(portal.getDestination() != null) { - destination = portal.getDestination().toString(); - String destType = portal.getDestination().getIdentifier(); - if(destType.equals("w")) { - MultiverseWorld destWorld = this.plugin.getCore().getMVWorldManager().getMVWorld(destination); - if (destWorld != null) { - destination = "(World) " + ChatColor.DARK_AQUA + destination; - } - } - if (destType.equals("p")) { - String targetWorldName = plugin.getPortalManager().getPortal(portal.getDestination().getName()).getWorld().getName(); - destination = "(Portal) " + ChatColor.DARK_AQUA + portal.getDestination().getName() + ChatColor.GRAY + " (" + targetWorldName + ")"; - } - if (destType.equals("e")) { - String destinationWorld = portal.getDestination().toString().split(":")[1]; - String destPart = portal.getDestination().toString().split(":")[2]; - String[] locParts = destPart.split(","); - int x, y, z; - try { - x = (int) Double.parseDouble(locParts[0]); - y = (int) Double.parseDouble(locParts[1]); - z = (int) Double.parseDouble(locParts[2]); - } catch(NumberFormatException e) { - e.printStackTrace(); - continue; - } - if(destType.equals("i")) { - destination = ChatColor.RED + "Invalid destination"; - } - destination = "(Location) " + ChatColor.DARK_AQUA + destinationWorld + ", " + x + ", " + y + ", " + z; - } - } - - if (portal.getName().toLowerCase().contains(filter.toLowerCase()) || ( portal.getDestination() != null && destination.toLowerCase().contains(filter.toLowerCase()))) { - portals.add(ChatColor.YELLOW + portal.getName() + ((portal.getDestination() != null) ? (ChatColor.AQUA + " -> " + ChatColor.GOLD + destination) : "")); - } - } - java.util.Collections.sort(portals); - return portals; - } - - private List getPortals(CommandSender sender, MultiverseWorld world, String filter, int page) { - List portals = new ArrayList<>(); - for(int i = 0; i < getPortals(sender, world, filter).size(); i++) { - if((i >= (page*itemsPerPage)-itemsPerPage && i <= (page*itemsPerPage)-1)) { - portals.add(getPortals(sender, world, filter).get(i)); - } - } - return portals; - } -} diff --git a/src/main/java/com/onarandombox/MultiversePortals/commands/ModifyCommand.java b/src/main/java/com/onarandombox/MultiversePortals/commands/ModifyCommand.java deleted file mode 100644 index 9122dc0..0000000 --- a/src/main/java/com/onarandombox/MultiversePortals/commands/ModifyCommand.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.commands; - -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.utils.LocationManipulation; -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.MultiversePortals; -import com.onarandombox.MultiversePortals.PortalLocation; -import com.onarandombox.MultiversePortals.PortalPlayerSession; -import com.onarandombox.MultiversePortals.enums.SetProperties; -import com.onarandombox.MultiversePortals.utils.MultiverseRegion; - -/** - * Allows modification of portal location, destination and owner. NOT name at this time. - */ -public class ModifyCommand extends PortalCommand { - - public ModifyCommand(MultiversePortals plugin) { - super(plugin); - this.setName("Modify a Portal (Set a value)"); - this.setCommandUsage("/mvp modify" + ChatColor.GREEN + " {PROPERTY}" + ChatColor.GOLD + " [VALUE] -p [PORTAL]"); - this.setArgRange(1, 4); - this.addKey("mvp modify"); - this.addKey("mvpmodify"); - this.addKey("mvpm"); - this.setPermission("multiverse.portal.modify", "Allows you to modify all values that can be set.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - Player player = null; - if ((sender instanceof Player)) { - player = (Player) sender; - } - - if (!validateAction(args.get(0))) { - sender.sendMessage("Sorry, you cannot " + ChatColor.AQUA + "SET" + ChatColor.WHITE + " the property " + - ChatColor.DARK_AQUA + args.get(0) + ChatColor.WHITE + "."); - return; - } - - final SetProperties operator = SetProperties.valueOf(args.get(0)); - - if (!validCommand(args, operator)) { - sender.sendMessage("Looks like you forgot or added an extra parameter."); - sender.sendMessage("Please try again or see our Wiki for help!"); - return; - } - String portalName = extractPortalName(args); - MVPortal selectedPortal = null; - // If they provided -p PORTALNAME, try to retrieve it - if (portalName != null) { - selectedPortal = this.plugin.getPortalManager().getPortal(portalName); - if (selectedPortal == null) { - sender.sendMessage("Sorry, the portal " + ChatColor.RED + portalName + ChatColor.WHITE + " did not exist!"); - return; - } - } else if (player == null) { - // If the player is null (so it's not a player sending the command and we don't have a portalName, we - // have to return here. portalName cannot be derived if we have no player. - sender.sendMessage("You NEED to enter -p PORTALNAME if you're using this from a command block or console!" + - " Not running modify command."); - return; - } - // If they didn't provide -p, then try to use their selected portal - if (selectedPortal == null) { - selectedPortal = this.getUserSelectedPortal(player); - } - - if (selectedPortal == null) { - sender.sendMessage("You need to select a portal using " + ChatColor.AQUA + "/mvp select {NAME}"); - sender.sendMessage("or append " + ChatColor.DARK_AQUA + "-p {PORTAL}" + ChatColor.WHITE + " to this command."); - return; - } else { - portalName = selectedPortal.getName(); - } - - if (portalName != null) { - // Simply chop off the rest, if they have loc, that's good enough! - if (operator == SetProperties.loc || operator == SetProperties.location) { - this.setLocation(selectedPortal, player); - return; - } - - if (operator == SetProperties.dest || - operator == SetProperties.destination) { - if (args.get(1).equalsIgnoreCase("here") && player != null) { - PortalPlayerSession ps = this.plugin.getPortalSession(player); - MVPortal standingIn = ps.getUncachedStandingInPortal(); - Location l = player.getLocation(); - if (standingIn != null) { - String cardinal = LocationManipulation.getDirection(l); - args.set(1, "p:" + standingIn.getName() + ":" + cardinal); - } else { - args.set(1, "e:" + l.getWorld().getName() + ":" + l.getX() + "," + l.getY() + "," + l.getZ() + ":" + l.getPitch() + ":" + l.getYaw()); - } - } else if (args.get(1).matches("(i?)cannon-[\\d]+(\\.[\\d]+)?") && player != null) { - // We found a Cannon Destination! - Location l = player.getLocation(); - try { - Double speed = Double.parseDouble(args.get(1).split("-")[1]); - args.set(1, "ca:" + l.getWorld().getName() + ":" + l.getX() + "," + l.getY() + "," + l.getZ() + ":" + l.getPitch() + ":" + l.getYaw() + ":" + speed); - } catch (NumberFormatException e) { - } - - } - } - - if (this.setProperty(selectedPortal, args.get(0), args.get(1))) { - sender.sendMessage("Property " + args.get(0) + " of Portal " + ChatColor.YELLOW + selectedPortal.getName() + ChatColor.GREEN + " was set to " + ChatColor.AQUA + args.get(1)); - } else { - sender.sendMessage("Property " + args.get(0) + " of Portal " + ChatColor.YELLOW + selectedPortal.getName() + ChatColor.RED + " was NOT set to " + ChatColor.AQUA + args.get(1)); - if (args.get(0).equalsIgnoreCase("dest") || args.get(0).equalsIgnoreCase("destination")) { - sender.sendMessage("Multiverse could not find the destination: " + ChatColor.GOLD + args.get(1)); - } - } - } - } - - private boolean setProperty(MVPortal selectedPortal, String property, String value) { - return selectedPortal.setProperty(property, value); - } - - private void setLocation(MVPortal selectedPortal, Player player) { - PortalPlayerSession ps = this.plugin.getPortalSession(player); - MultiverseRegion r = ps.getSelectedRegion(); - if (r != null) { - MultiverseWorld world = this.plugin.getCore().getMVWorldManager().getMVWorld(player.getWorld().getName()); - PortalLocation location = new PortalLocation(r.getMinimumPoint(), r.getMaximumPoint(), world); - selectedPortal.setPortalLocation(location); - player.sendMessage("Portal location has been set to your " + ChatColor.GREEN + "selection" + ChatColor.WHITE + "!"); - } - } - - private MVPortal getUserSelectedPortal(Player player) { - PortalPlayerSession ps = this.plugin.getPortalSession(player); - return ps.getSelectedPortal(); - } - - private boolean validCommand(List args, SetProperties property) { - // This means that they did not specify the -p or forgot the [PORTAL] - - if (property == SetProperties.loc && args.size() % 2 == 0) { - return false; - } else if (property != SetProperties.loc && args.size() % 2 != 0) { - return false; - } - return true; - } - - private String extractPortalName(List args) { - if (!args.contains("-p")) { - return null; - } - - int index = args.indexOf("-p"); - - // Now we remove the -p - args.remove(index); - - // Now we remove and return the portalname if present - if (index < args.size()) { - return args.remove(index); - } - - return null; - } - - protected static boolean validateAction(String property) { - try { - SetProperties.valueOf(property); - return true; - } catch (IllegalArgumentException e) { - return false; - } - } -} diff --git a/src/main/java/com/onarandombox/MultiversePortals/commands/PortalCommand.java b/src/main/java/com/onarandombox/MultiversePortals/commands/PortalCommand.java deleted file mode 100644 index 202146d..0000000 --- a/src/main/java/com/onarandombox/MultiversePortals/commands/PortalCommand.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.commands; - -import java.util.List; - -import com.onarandombox.commandhandler.Command; -import org.bukkit.command.CommandSender; - -import com.onarandombox.MultiversePortals.MultiversePortals; -/** - * Convenience class so we don't have to cast each time. - * @author fernferret - * - */ -public abstract class PortalCommand extends Command { - - protected MultiversePortals plugin; - public PortalCommand(MultiversePortals plugin) { - super(plugin); - this.plugin = plugin; - } - - @Override - public abstract void runCommand(CommandSender sender, List args); - -} diff --git a/src/main/java/com/onarandombox/MultiversePortals/commands/RemoveCommand.java b/src/main/java/com/onarandombox/MultiversePortals/commands/RemoveCommand.java deleted file mode 100644 index 8910eb3..0000000 --- a/src/main/java/com/onarandombox/MultiversePortals/commands/RemoveCommand.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.commands; - -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.MultiversePortals; -/** - * Allows removal of portals. - * @author fernferret - * - */ -public class RemoveCommand extends PortalCommand { - - public RemoveCommand(MultiversePortals plugin) { - super(plugin); - this.setName("Remove a Portal"); - this.setCommandUsage("/mvp remove" + ChatColor.GREEN + " {NAME}"); - // make it so no one can ever execute this. - this.setArgRange(1, 1); - this.addKey("mvp remove"); - this.addKey("mvpremove"); - this.addKey("mvpr"); - this.setPermission("multiverse.portal.remove", "Allows you to modify all existing portal.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - if (this.plugin.getPortalManager().isPortal(args.get(0))) { - MVPortal portal = this.plugin.getPortalManager().removePortal(args.get(0), true); - sender.sendMessage("Portal " + ChatColor.DARK_AQUA + portal.getName() + ChatColor.WHITE + " was removed successfully!"); - return; - } - sender.sendMessage("The portal Portal " + ChatColor.DARK_AQUA + args.get(0) + ChatColor.WHITE + " does NOT exist!"); - } -} diff --git a/src/main/java/com/onarandombox/MultiversePortals/commands/SelectCommand.java b/src/main/java/com/onarandombox/MultiversePortals/commands/SelectCommand.java deleted file mode 100644 index 68560ad..0000000 --- a/src/main/java/com/onarandombox/MultiversePortals/commands/SelectCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.commands; - -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.PermissionDefault; - -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.MultiversePortals; - -public class SelectCommand extends PortalCommand { - - public SelectCommand(MultiversePortals plugin) { - super(plugin); - this.setName("Select a portal"); - this.setCommandUsage("/mvp select " + ChatColor.GREEN + "{PORTAL}"); - this.setArgRange(0, 1); - this.addKey("mvp select"); - this.addKey("mvps"); - this.addKey("mvpselect"); - this.setPermission("multiverse.portal.select", "Selects a portal so you can perform multiple modifications on it.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - if (!(sender instanceof Player)) { - sender.sendMessage("This command must be run as a player, sorry. :("); - return; - } - Player p = (Player) sender; - if (!this.plugin.getCore().getMVPerms().hasPermission(p, "multiverse.portal.create", true)) { - p.sendMessage("You need create permissions to do this!(multiverse.portal.create)"); - return; - } - if (args.size() == 0) { - MVPortal selected = this.plugin.getPortalSession(p).getSelectedPortal(); - if (this.plugin.getPortalSession(p).getSelectedPortal() == null) { - p.sendMessage("You have not selected a portal yet!"); - ItemStack wand = new ItemStack(plugin.getWandMaterial()); - p.sendMessage("Use a " + ChatColor.GREEN + wand.getType() + ChatColor.WHITE + " to do so!"); - return; - } - p.sendMessage("You have selected: " + ChatColor.DARK_AQUA + selected.getName()); - return; - } - - MVPortal selected = this.plugin.getPortalManager().getPortal(args.get(0)); - this.plugin.getPortalSession(p).selectPortal(selected); - if (selected != null) { - p.sendMessage("Portal: " + ChatColor.DARK_AQUA + selected.getName() + ChatColor.WHITE + " has been selected."); - } else { - p.sendMessage("Could not find portal: " + ChatColor.RED + args.get(0)); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiversePortals/commands/WandCommand.java b/src/main/java/com/onarandombox/MultiversePortals/commands/WandCommand.java deleted file mode 100644 index d6aff73..0000000 --- a/src/main/java/com/onarandombox/MultiversePortals/commands/WandCommand.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.commands; - -import java.util.List; - -import com.onarandombox.MultiversePortals.WorldEditConnection; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.PermissionDefault; - -import com.onarandombox.MultiversePortals.MultiversePortals; - -public class WandCommand extends PortalCommand { - - public WandCommand(MultiversePortals plugin) { - super(plugin); - this.setName("Gives a Portal Creation Wand"); - this.setCommandUsage("/mvp wand"); - this.setArgRange(0, 1); - this.addKey("mvp wand"); - this.addKey("mvpwand"); - this.addKey("mvpw"); - this.setPermission("multiverse.portal.givewand", "Gives you the wand that MV uses. This will only work if you are NOT using WorldEdit.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - // Check for enabling/disabling wand - if (args.size() > 0) { - String arg = args.get(0); - if (arg.equals("enable")) { - this.plugin.setWandEnabled(true); - } else if (arg.equals("disable")) { - this.plugin.setWandEnabled(false); - } else if (arg.equals("toggle")) { - this.plugin.setWandEnabled(!this.plugin.isWandEnabled()); - } else { - sender.sendMessage(ChatColor.RED + "You must specify one of 'enable,' 'disable,' or 'toggle!'"); - } - return; - } - - // Do the normal wand thing - if (sender instanceof Player) { - Player p = (Player) sender; - - WorldEditConnection worldEdit = plugin.getWorldEditConnection(); - if (worldEdit != null && worldEdit.isConnected()) { - p.sendMessage(ChatColor.GREEN + "Cool!" + ChatColor.WHITE + " You're using" + ChatColor.AQUA + " WorldEdit! "); - p.sendMessage("Just use " + ChatColor.GOLD + "the WorldEdit wand " + ChatColor.WHITE + "to perform portal selections!"); - return; - } - ItemStack wand = new ItemStack(plugin.getWandMaterial(), 1); - - if (p.getItemInHand().getAmount() == 0) { - p.setItemInHand(wand); - p.sendMessage("You have been given a " + ChatColor.GREEN + "Multiverse Portal Wand(" + wand.getType() + ")!"); - } else { - if (p.getInventory().addItem(wand).isEmpty()) { - p.sendMessage("A " + ChatColor.GREEN + "Multiverse Portal Wand(" + wand.getType() + ")" + ChatColor.WHITE + " has been placed in your inventory."); - } else { - p.sendMessage("Your Inventory is full. A " + ChatColor.GREEN + "Multiverse Portal Wand(" + wand.getType() + ")" + ChatColor.WHITE + " has been placed dropped nearby."); - p.getWorld().dropItemNaturally(p.getLocation(), wand); - } - } - } - } -} diff --git a/src/main/java/com/onarandombox/MultiversePortals/destination/PortalDestination.java b/src/main/java/com/onarandombox/MultiversePortals/destination/PortalDestination.java deleted file mode 100644 index 9c74e4c..0000000 --- a/src/main/java/com/onarandombox/MultiversePortals/destination/PortalDestination.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.destination; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.BlockSafety; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Entity; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; - -import com.onarandombox.MultiverseCore.api.MVDestination; -import com.onarandombox.MultiverseCore.utils.LocationManipulation; -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.MultiversePortals; -import com.onarandombox.MultiversePortals.PortalLocation; - -public class PortalDestination implements MVDestination { - private MVPortal portal; - private boolean isValid; - private String orientationString; - - @Override - public String getIdentifier() { - return "p"; - } - - @Override - public boolean isThisType(JavaPlugin plugin, String dest) { - // If this class exists, then this plugin MUST exist! - MultiversePortals portalPlugin = (MultiversePortals) plugin.getServer().getPluginManager().getPlugin("Multiverse-Portals"); - String[] split = dest.split(":"); - if (split.length > 3 || split.length < 2) { - return false; - } - if (split[0].equalsIgnoreCase("p")) { - if (portalPlugin.getPortalManager().isPortal(split[1])) { - return true; - } - } - return false; - } - - @Override - public Location getLocation(Entity e) { - PortalLocation pl = this.portal.getLocation(); - double portalWidth = Math.abs((pl.getMaximum().getBlockX()) - pl.getMinimum().getBlockX()) + 1; - double portalDepth = Math.abs((pl.getMaximum().getBlockZ()) - pl.getMinimum().getBlockZ()) + 1; - - double finalX = (portalWidth / 2.0) + pl.getMinimum().getBlockX(); - // double finalY = pl.getMinimum().getBlockY(); - double finalZ = (portalDepth / 2.0) + pl.getMinimum().getBlockZ(); - double finalY = this.getMinimumWith2Air((int) finalX, (int) finalZ, pl.getMinimum().getBlockY(), pl.getMaximum().getBlockY(), this.portal.getWorld()); - return new Location(this.portal.getWorld(), finalX, finalY, finalZ, LocationManipulation.getYaw(this.orientationString), 0); - } - - /** - * Allows us to check the column first but only when doing portals - * - * @param finalX - * @param finalZ - * @param y - * @param yMax - * @param w - * - * @return - */ - private double getMinimumWith2Air(int finalX, int finalZ, int y, int yMax, World w) { - // If this class exists, then this Multiverse-Core MUST exist! - // TODO there really ought to be a better way! - MultiverseCore mvCore = (MultiverseCore) Bukkit.getPluginManager().getPlugin("Multiverse-Core"); - BlockSafety bs = mvCore.getBlockSafety(); - for (int i = y; i < yMax; i++) { - if (bs.playerCanSpawnHereSafely(w, finalX, i, finalZ)) { - return i; - } - } - return y; - } - - @Override - public boolean isValid() { - return this.isValid; - } - - @Override - public void setDestination(JavaPlugin plugin, String dest) { - // If this class exists, then this plugin MUST exist! - MultiversePortals portalPlugin = (MultiversePortals) plugin.getServer().getPluginManager().getPlugin("Multiverse-Portals"); - String[] split = dest.split(":"); - if (split.length > 3) { - this.isValid = false; - return; - } - if (split.length >= 2 && split[0].equalsIgnoreCase("p")) { - if (!portalPlugin.getPortalManager().isPortal(split[1])) { - this.isValid = false; - return; - } - this.isValid = true; - this.portal = portalPlugin.getPortalManager().getPortal(split[1]); - if (split.length == 3) { - this.orientationString = split[2]; - } - } - } - - @Override - public String getType() { - return "Portal"; - } - - @Override - public String getName() { - return this.portal.getName(); - } - - @Override - public String toString() { - if (this.orientationString != null && this.orientationString.length() > 0) { - return "p:" + this.portal.getName() + ":" + this.orientationString; - } - return "p:" + this.portal.getName(); - - } - - public String getOrientationString() { - return this.orientationString; - } - - public String getRequiredPermission() { - return "multiverse.portal.access." + this.portal.getName(); - } - - public Vector getVelocity() { - return new Vector(0, 0, 0); - } - - @Override - public boolean useSafeTeleporter() { - return this.portal.useSafeTeleporter(); - } - -} diff --git a/src/main/java/com/onarandombox/MultiversePortals/destination/RandomPortalDestination.java b/src/main/java/com/onarandombox/MultiversePortals/destination/RandomPortalDestination.java deleted file mode 100644 index dbd090b..0000000 --- a/src/main/java/com/onarandombox/MultiversePortals/destination/RandomPortalDestination.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2013. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.destination; - -import com.onarandombox.MultiverseCore.api.Core; -import com.onarandombox.MultiverseCore.api.MVDestination; -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.MultiversePortals; -import com.onarandombox.MultiversePortals.PortalLocation; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Entity; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -public class RandomPortalDestination implements MVDestination { - private static final Random RANDOM = new Random(); - private List portals; - private Core core; - - @Override - public String getIdentifier() { - return "rp"; - } - - @Override - public boolean isThisType(JavaPlugin plugin, String dest) { - this.core = (Core) plugin.getServer().getPluginManager().getPlugin("Multiverse-Core"); - // If this class exists, then this plugin MUST exist! - return dest.startsWith("rp:"); - } - - @Override - public Location getLocation(Entity e) { - MVPortal portal = portals.get(RANDOM.nextInt(portals.size())); - PortalLocation pl = portal.getLocation(); - double portalWidth = Math.abs((pl.getMaximum().getBlockX()) - pl.getMinimum().getBlockX()) + 1; - double portalDepth = Math.abs((pl.getMaximum().getBlockZ()) - pl.getMinimum().getBlockZ()) + 1; - - double finalX = (portalWidth / 2.0) + pl.getMinimum().getBlockX(); - double finalZ = (portalDepth / 2.0) + pl.getMinimum().getBlockZ(); - double finalY = this.getMinimumWith2Air((int) finalX, (int) finalZ, pl.getMinimum().getBlockY(), - pl.getMaximum().getBlockY(), portal.getWorld()); - return new Location(portal.getWorld(), finalX, finalY, finalZ); - } - - // copied from PortalDestination... - private double getMinimumWith2Air(int finalX, int finalZ, int y, int yMax, World w) { - for (int i = y; i < yMax; i++) { - if (core.getBlockSafety().playerCanSpawnHereSafely(w, finalX, i, finalZ)) { - return i; - } - } - return y; - } - - @Override - public boolean isValid() { - return !this.portals.isEmpty(); - } - - @Override - public void setDestination(JavaPlugin plugin, String dest) { - this.portals = new ArrayList(); - // If this class exists, then this plugin MUST exist! - MultiversePortals portalPlugin = (MultiversePortals) plugin.getServer().getPluginManager().getPlugin("Multiverse-Portals"); - String[] split = dest.split(":"); - // iterate over splits, split[0] = getIdentifier() - MVPortal portal; - for (int i = 1; i < split.length; i++) - if ((portal = portalPlugin.getPortalManager().getPortal(split[i])) != null) - this.portals.add(portal); - } - - @Override - public String getType() { - return "Portal"; - } - - @Override - public String getName() { - return "Random portal!"; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(getIdentifier()); - for (MVPortal portal : portals) - builder.append(':').append(portal.getName()); - return builder.toString(); - } - - @Override - public String getRequiredPermission() { - return "multiverse.portal.random"; - } - - @Override - public Vector getVelocity() { - return new Vector(0, 0, 0); - } - - @Override - public boolean useSafeTeleporter() { - return true; - } -} diff --git a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPTravelAgent.java b/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPTravelAgent.java deleted file mode 100644 index b567188..0000000 --- a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPTravelAgent.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.onarandombox.MultiversePortals.listeners; - -import java.util.logging.Level; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVDestination; -import com.onarandombox.MultiverseCore.utils.BukkitTravelAgent; -import com.onarandombox.MultiverseCore.utils.MVTravelAgent; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerPortalEvent; - -class MVPTravelAgent extends MVTravelAgent { - - MVPTravelAgent(MultiverseCore multiverseCore, MVDestination d, Player p) { - super(multiverseCore, d, p); - } - - void setPortalEventTravelAgent(PlayerPortalEvent event) { - try { - Class.forName("org.bukkit.TravelAgent"); - new BukkitTravelAgent(this).setPortalEventTravelAgent(event); - } catch (ClassNotFoundException ignore) { - Logging.fine("TravelAgent not available for PlayerPortalEvent for " + player.getName()); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiversePortals/listeners/PlayerListenerHelper.java b/src/main/java/com/onarandombox/MultiversePortals/listeners/PlayerListenerHelper.java deleted file mode 100644 index da64c27..0000000 --- a/src/main/java/com/onarandombox/MultiversePortals/listeners/PlayerListenerHelper.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.onarandombox.MultiversePortals.listeners; - -import java.io.File; -import java.util.Date; -import java.util.logging.Level; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.api.MVDestination; -import com.onarandombox.MultiverseCore.api.SafeTTeleporter; -import com.onarandombox.MultiverseCore.enums.TeleportResult; -import com.onarandombox.MultiverseCore.utils.MVTravelAgent; -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.MultiversePortals; -import com.onarandombox.MultiversePortals.PortalPlayerSession; -import com.onarandombox.MultiversePortals.event.MVPortalEvent; -import com.onarandombox.buscript.Buscript; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -public class PlayerListenerHelper { - - private MultiversePortals plugin; - - public PlayerListenerHelper(MultiversePortals plugin) { - this.plugin = plugin; - } - - void stateSuccess(String playerName, String worldName) { - Logging.fine(String.format( - "MV-Portals is allowing Player '%s' to use the portal '%s'.", - playerName, worldName)); - } - - void stateFailure(String playerName, String portalName) { - Logging.fine(String.format( - "MV-Portals is DENYING Player '%s' access to use the portal '%s'.", - playerName, portalName)); - } - - void performTeleport(Player player, Location to, PortalPlayerSession ps, MVDestination d) { - if (!plugin.getCore().getMVConfig().getEnforceAccess() || (d.getRequiredPermission() == null) - || (d.getRequiredPermission().length() == 0) || player.hasPermission(d.getRequiredPermission())) { - SafeTTeleporter playerTeleporter = this.plugin.getCore().getSafeTTeleporter(); - TeleportResult result = playerTeleporter.safelyTeleport(player, player, d); - if (result == TeleportResult.SUCCESS) { - ps.playerDidTeleport(to); - ps.setTeleportTime(new Date()); - this.stateSuccess(player.getDisplayName(), d.getName()); - return; - } - } - this.stateFailure(player.getDisplayName(), d.getName()); - } - - boolean scriptPortal(Player player, MVDestination d, MVPortal portal, PortalPlayerSession ps) { - Buscript buscript = plugin.getCore().getScriptAPI(); - File handlerScript = new File(buscript.getScriptFolder(), portal.getHandlerScript()); - if (handlerScript.exists()) { - MVPTravelAgent agent = new MVPTravelAgent(this.plugin.getCore(), d, player); - buscript.setScriptVariable("portal", portal); - buscript.setScriptVariable("player", player); - buscript.setScriptVariable("travelAgent", agent); - buscript.setScriptVariable("allowPortal", true); - buscript.setScriptVariable("portalSession", ps); - buscript.executeScript(handlerScript, player.getName()); - buscript.setScriptVariable("portal", null); - buscript.setScriptVariable("player", null); - buscript.setScriptVariable("travelAgent", null); - buscript.setScriptVariable("portalSession", null); - Object allowObject = buscript.getScriptVariable("allowPortal"); - buscript.setScriptVariable("allowPortal", null); - if (allowObject instanceof Boolean) { - if (((Boolean) allowObject)) { - MVPortalEvent portalEvent = new MVPortalEvent(d, player, agent, portal); - this.plugin.getServer().getPluginManager().callEvent(portalEvent); - if (!portalEvent.isCancelled()) { - return true; - } - Logging.fine("A plugin cancelled the portal after script handling."); - return false; - } else { - Logging.fine("Portal denied by script!"); - return false; - } - } else { - Logging.fine("Portal denied by script because allowPortal not a boolean!"); - return false; - } - } - throw new IllegalStateException(); - } -} diff --git a/src/main/java/com/onarandombox/MultiversePortals/MVPortal.java b/src/main/java/org/mvplugins/multiverse/portals/MVPortal.java similarity index 83% rename from src/main/java/com/onarandombox/MultiversePortals/MVPortal.java rename to src/main/java/org/mvplugins/multiverse/portals/MVPortal.java index e4087c6..9c6e997 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/MVPortal.java +++ b/src/main/java/org/mvplugins/multiverse/portals/MVPortal.java @@ -5,7 +5,7 @@ * with this project */ -package com.onarandombox.MultiversePortals; +package org.mvplugins.multiverse.portals; import java.util.Arrays; import java.util.Collection; @@ -13,12 +13,18 @@ import java.util.List; import java.util.Set; import java.util.Stack; -import java.util.logging.Level; import java.util.regex.Pattern; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.utils.MaterialConverter; -import com.onarandombox.MultiversePortals.enums.PortalType; +import org.mvplugins.multiverse.core.api.BlockSafety; +import org.mvplugins.multiverse.core.destination.DestinationInstance; +import org.mvplugins.multiverse.core.destination.DestinationsProvider; +import org.mvplugins.multiverse.core.utils.MaterialConverter; +import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; +import org.mvplugins.multiverse.core.world.MultiverseWorld; +import org.mvplugins.multiverse.core.world.WorldManager; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.portals.enums.PortalType; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -28,29 +34,28 @@ import org.bukkit.permissions.PermissionDefault; import org.bukkit.util.Vector; -import com.onarandombox.MultiverseCore.api.MVDestination; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.destination.ExactDestination; -import com.onarandombox.MultiverseCore.destination.InvalidDestination; -import com.onarandombox.MultiversePortals.utils.MultiverseRegion; +import org.mvplugins.multiverse.portals.utils.MultiverseRegion; public class MVPortal { - private String name; + private final MultiversePortals plugin; + private final WorldManager worldManager; + private final DestinationsProvider destinationsProvider; + private final BlockSafety blockSafety; + + private final String name; + private final String portalConfigString; + private final FileConfiguration config; + private PortalLocation location; - private MVDestination destination; - private MultiversePortals plugin; + private DestinationInstance destination; private String owner; - private String portalConfigString; private Permission permission; private Permission fillPermission; private Permission exempt; private Material currency = null; private double price = 0.0; - private MVWorldManager worldManager; private boolean safeTeleporter; private boolean teleportNonPlayers; - private FileConfiguration config; private boolean allowSave; private String handlerScript; @@ -63,25 +68,40 @@ public static boolean isPortalInterior(Material material) { return INTERIOR_MATERIALS.contains(material); } - public MVPortal(MultiversePortals instance, String name) { - init(instance, name, true); + public MVPortal(@NotNull MultiversePortals plugin, @NotNull String name) { + this(plugin, name, true); + } + + public MVPortal(LoadedMultiverseWorld world, MultiversePortals instance, String name, String owner, String location) { + this(instance, name); + this.setOwner(owner); + this.setPortalLocation(location, world); } - private MVPortal(MultiversePortals instance, String name, boolean allowSave) { - init(instance, name, allowSave); + public MVPortal(MultiversePortals plugin, String name, String owner, PortalLocation location) { + this(plugin, name); + this.setOwner(owner); + this.setPortalLocation(location); } // If this is called with allowSave=false, the caller needs to be sure to // call allowSave() when they're finished modifying it. - private void init(MultiversePortals instance, String name, boolean allowSave) { + private MVPortal( + MultiversePortals plugin, + String name, + boolean allowSave) { // Disallow saving until initialization is finished. this.allowSave = false; - this.plugin = instance; + this.plugin = plugin; + this.worldManager = this.plugin.getServiceLocator().getService(WorldManager.class); + this.destinationsProvider = this.plugin.getServiceLocator().getService(DestinationsProvider.class); + this.blockSafety = this.plugin.getServiceLocator().getService(BlockSafety.class); + this.config = this.plugin.getPortalsConfig(); this.name = name; this.portalConfigString = "portals." + this.name; - this.setCurrency(MaterialConverter.convertConfigType(this.config, this.portalConfigString + ".entryfee.currency")); + this.setCurrency(MaterialConverter.stringToMaterial(this.config.getString(this.portalConfigString + ".entryfee.currency"))); this.setPrice(this.config.getDouble(this.portalConfigString + ".entryfee.amount", 0.0)); this.setUseSafeTeleporter(this.config.getBoolean(this.portalConfigString + ".safeteleport", true)); this.setTeleportNonPlayers(this.config.getBoolean(this.portalConfigString + ".teleportnonplayers", false)); @@ -103,7 +123,6 @@ private void init(MultiversePortals instance, String name, boolean allowSave) { this.plugin.getServer().getPluginManager().addPermission(this.exempt); } this.addToUpperLists(); - this.worldManager = this.plugin.getCore().getMVWorldManager(); if (allowSave) { this.allowSave = true; @@ -188,7 +207,7 @@ public static MVPortal loadMVPortalFromConfig(MultiversePortals instance, String portal.setPortalLocation(portalLocString, worldString); portal.setOwner(portal.config.getString(portal.portalConfigString + ".owner", "")); - portal.setCurrency(MaterialConverter.convertConfigType(portal.config, portal.portalConfigString + ".entryfee.currency")); + portal.setCurrency(MaterialConverter.stringToMaterial(portal.config.getString(portal.portalConfigString + ".entryfee.currency"))); portal.setPrice(portal.config.getDouble(portal.portalConfigString + ".entryfee.amount", 0.0)); // We've finished reading the portal from the config file. Any further @@ -226,27 +245,15 @@ private void saveConfig() { } } - public MVPortal(MultiverseWorld world, MultiversePortals instance, String name, String owner, String location) { - this(instance, name); - this.setOwner(owner); - this.setPortalLocation(location, world); - } - - public MVPortal(MultiversePortals instance, String name, String owner, PortalLocation location) { - this(instance, name); - this.setOwner(owner); - this.setPortalLocation(location); - } - public boolean setPortalLocation(String locationString, String worldString) { - MultiverseWorld world = null; - if (this.worldManager.isMVWorld(worldString)) { - world = this.worldManager.getMVWorld(worldString); + LoadedMultiverseWorld world = null; + if (this.worldManager.isWorld(worldString)) { + world = this.worldManager.getLoadedWorld(worldString).getOrNull(); } return this.setPortalLocation(locationString, world); } - public boolean setPortalLocation(String locationString, MultiverseWorld world) { + public boolean setPortalLocation(String locationString, LoadedMultiverseWorld world) { return this.setPortalLocation(PortalLocation.parseLocation(locationString, world, this.name)); } @@ -277,21 +284,8 @@ private boolean setOwner(String owner) { } public boolean setDestination(String destinationString) { - this.destination = this.plugin.getCore().getDestFactory().getDestination(destinationString); - if (this.destination instanceof InvalidDestination) { - Logging.warning("Portal " + this.name + " has an invalid DESTINATION!"); - return false; - } - this.config.set(this.portalConfigString + ".destination", this.destination.toString()); - saveConfig(); - return !(this.destination instanceof InvalidDestination); - } - - public boolean setExactDestination(Location location) { - this.destination = new ExactDestination(); - ((ExactDestination) this.destination).setDestination(location); - if (!this.destination.isValid()) { - this.destination = new InvalidDestination(); + this.destination = this.destinationsProvider.parseDestination(destinationString).getOrNull(); + if (this.destination == null) { Logging.warning("Portal " + this.name + " has an invalid DESTINATION!"); return false; } @@ -308,6 +302,40 @@ public PortalLocation getLocation() { return this.location; } + public Location getSafePlayerSpawnLocation() { + PortalLocation pl = this.location; + double portalWidth = Math.abs((pl.getMaximum().getBlockX()) - pl.getMinimum().getBlockX()) + 1; + double portalDepth = Math.abs((pl.getMaximum().getBlockZ()) - pl.getMinimum().getBlockZ()) + 1; + + double finalX = (portalWidth / 2.0) + pl.getMinimum().getBlockX(); + // double finalY = pl.getMinimum().getBlockY(); + double finalZ = (portalDepth / 2.0) + pl.getMinimum().getBlockZ(); + double finalY = this.getMinimumWith2Air((int) finalX, (int) finalZ, pl.getMinimum().getBlockY(), pl.getMaximum().getBlockY(), this.getWorld()); + return new Location(this.getWorld(), finalX, finalY, finalZ); + } + + /** + * Allows us to check the column first but only when doing portals + * + * @param finalX + * @param finalZ + * @param y + * @param yMax + * @param w + * + * @return + */ + private double getMinimumWith2Air(int finalX, int finalZ, int y, int yMax, World w) { + // If this class exists, then this Multiverse-Core MUST exist! + // TODO there really ought to be a better way! + for (int i = y; i < yMax; i++) { + if (blockSafety.playerCanSpawnHereSafely(w, finalX, i, finalZ)) { + return i; + } + } + return y; + } + /** * Gets the Material that fills this portal. Specifically, * this gets the Material at the center of the portal. @@ -323,7 +351,7 @@ public Material getFillMaterial() throws IllegalStateException { } return this.location.getMinimum().getMidpoint(this.location.getMaximum()) - .toLocation(this.location.getMVWorld().getCBWorld()).getBlock().getType(); + .toLocation(this.location.getMVWorld().getBukkitWorld().getOrNull()).getBlock().getType(); } /** @@ -355,14 +383,14 @@ public boolean isLegacyPortal() throws IllegalStateException { } public boolean playerCanEnterPortal(Player player) { - return (this.plugin.getCore().getMVPerms().hasPermission(player, this.permission.getName(), true)); + return player.hasPermission(this.permission); } public boolean playerCanFillPortal(Player player) { - return (this.plugin.getCore().getMVPerms().hasPermission(player, this.fillPermission.getName(), true)); + return player.hasPermission(this.fillPermission); } - public MVDestination getDestination() { + public DestinationInstance getDestination() { return this.destination; } @@ -410,11 +438,11 @@ public boolean setProperty(String property, String value) { } public World getWorld() { - MultiverseWorld mvWorld = this.location.getMVWorld(); + LoadedMultiverseWorld mvWorld = this.location.getMVWorld(); if (mvWorld == null) { return null; } - return mvWorld.getCBWorld(); + return mvWorld.getBukkitWorld().getOrNull(); } public String getHandlerScript() { diff --git a/src/main/java/com/onarandombox/MultiversePortals/MultiversePortals.java b/src/main/java/org/mvplugins/multiverse/portals/MultiversePortals.java similarity index 70% rename from src/main/java/com/onarandombox/MultiversePortals/MultiversePortals.java rename to src/main/java/org/mvplugins/multiverse/portals/MultiversePortals.java index 4e6b2d2..31ddc90 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/MultiversePortals.java +++ b/src/main/java/org/mvplugins/multiverse/portals/MultiversePortals.java @@ -5,7 +5,7 @@ * with this project */ -package com.onarandombox.MultiversePortals; +package org.mvplugins.multiverse.portals; import java.io.BufferedReader; import java.io.File; @@ -13,8 +13,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -25,14 +23,20 @@ import java.util.stream.Collectors; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.utils.MaterialConverter; -import com.onarandombox.MultiversePortals.listeners.MVPPlayerMoveListener; -import com.onarandombox.MultiversePortals.listeners.PlayerListenerHelper; -import com.onarandombox.MultiversePortals.utils.DisplayUtils; -import com.onarandombox.commandhandler.CommandHandler; +import org.mvplugins.multiverse.core.MultiverseCore; +import org.mvplugins.multiverse.core.api.MVPlugin; +import org.mvplugins.multiverse.core.config.MVCoreConfig; +import org.mvplugins.multiverse.core.destination.DestinationsProvider; +import org.mvplugins.multiverse.core.inject.PluginServiceLocator; +import org.mvplugins.multiverse.core.utils.MaterialConverter; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jakarta.inject.Provider; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.external.vavr.control.Try; +import org.mvplugins.multiverse.portals.destination.PortalDestination; +import org.mvplugins.multiverse.portals.destination.RandomPortalDestination; +import org.mvplugins.multiverse.portals.listeners.*; import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; import org.bukkit.configuration.Configuration; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; @@ -50,44 +54,29 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVPlugin; -import com.onarandombox.MultiverseCore.commands.HelpCommand; -import com.onarandombox.MultiversePortals.commands.ConfigCommand; -import com.onarandombox.MultiversePortals.commands.CreateCommand; -import com.onarandombox.MultiversePortals.commands.DebugCommand; -import com.onarandombox.MultiversePortals.commands.InfoCommand; -import com.onarandombox.MultiversePortals.commands.ListCommand; -import com.onarandombox.MultiversePortals.commands.ModifyCommand; -import com.onarandombox.MultiversePortals.commands.RemoveCommand; -import com.onarandombox.MultiversePortals.commands.SelectCommand; -import com.onarandombox.MultiversePortals.commands.WandCommand; -import com.onarandombox.MultiversePortals.destination.PortalDestination; -import com.onarandombox.MultiversePortals.destination.RandomPortalDestination; -import com.onarandombox.MultiversePortals.enums.PortalConfigProperty; -import com.onarandombox.MultiversePortals.listeners.MVPBlockListener; -import com.onarandombox.MultiversePortals.listeners.MVPCoreListener; -import com.onarandombox.MultiversePortals.listeners.MVPPlayerListener; -import com.onarandombox.MultiversePortals.listeners.MVPPluginListener; -import com.onarandombox.MultiversePortals.listeners.MVPVehicleListener; -import com.onarandombox.MultiversePortals.utils.PortalManager; +import org.mvplugins.multiverse.portals.utils.PortalManager; +@Service public class MultiversePortals extends JavaPlugin implements MVPlugin { private MultiverseCore core; + private PluginServiceLocator serviceLocator; + + @Inject + private Provider portalManager; + @Inject + private Provider destinationsProvider; private FileConfiguration MVPPortalConfig; private FileConfiguration MVPConfig; - private CommandHandler commandHandler; private WorldEditConnection worldEditConnection; - private PortalManager portalManager; private Map portalSessions; private static final Material DEFAULT_WAND = Material.WOODEN_AXE; private long portalCooldown = 0; - private final static int requiresProtocol = 24; + private final static int requiresProtocol = 50; public static boolean UseOnMove = true; public static boolean bucketFilling = true; public static boolean EnforcePortalAccess = true; @@ -124,7 +113,9 @@ public void onEnable() { return; } - Logging.setDebugLevel(core.getMVConfig().getGlobalDebug()); + initializeDependencyInjection(); + + Logging.setDebugLevel(serviceLocator.getActiveService(MVCoreConfig.class).getGlobalDebug()); // Register ourselves with Core this.core.incrementPluginCount(); @@ -135,10 +126,11 @@ public void onEnable() { // Ensure permissions are created this.createDefaultPerms(); - this.portalManager = new PortalManager(this); this.portalSessions = new HashMap(); - this.getCore().getDestFactory().registerDestinationType(PortalDestination.class, "p"); - this.getCore().getDestFactory().registerDestinationType(RandomPortalDestination.class, "rp"); + + + this.destinationsProvider.get().registerDestination(this.serviceLocator.getService(PortalDestination.class)); + this.destinationsProvider.get().registerDestination(this.serviceLocator.getService(RandomPortalDestination.class)); this.loadPortals(); this.loadConfig(); @@ -149,30 +141,33 @@ public void onEnable() { getServer().getPluginManager().registerEvents(new WorldEditPluginListener(), this); Logging.log(true, Level.INFO, " Enabled - By %s", getAuthors()); + } - DisplayUtils.plugin = this; + private void initializeDependencyInjection() { + serviceLocator = core.getServiceLocatorFactory() + .registerPlugin(new MultiversePortalsPluginBinder(this), core.getServiceLocator()) + .flatMap(PluginServiceLocator::enable) + .getOrElseThrow(exception -> { + Logging.severe("Failed to initialize dependency injection!"); + getServer().getPluginManager().disablePlugin(this); + return new RuntimeException(exception); + }); } private void registerEvents() { - // Initialize our listeners - MVPPluginListener pluginListener = new MVPPluginListener(this); - PlayerListenerHelper playerListenerHelper = new PlayerListenerHelper(this); - MVPPlayerListener playerListener = new MVPPlayerListener(this, playerListenerHelper); - MVPBlockListener blockListener = new MVPBlockListener(this); - MVPCoreListener coreListener = new MVPCoreListener(this); - - // Register our listeners with the Bukkit Server - PluginManager pm = getServer().getPluginManager(); - pm.registerEvents(pluginListener, this); - pm.registerEvents(playerListener, this); - pm.registerEvents(blockListener, this); + var pluginManager = getServer().getPluginManager(); + + Try.run(() -> serviceLocator.getAllServices(PortalsListener.class).forEach( + listener -> pluginManager.registerEvents(listener, this))) + .onFailure(e -> { + throw new RuntimeException("Failed to register listeners. Terminating...", e); + }); if (MultiversePortals.TeleportVehicles) { - pm.registerEvents(new MVPVehicleListener(this), this); + pluginManager.registerEvents(serviceLocator.getService(MVPVehicleListener.class), this); } if (MultiversePortals.UseOnMove) { - pm.registerEvents(new MVPPlayerMoveListener(this, playerListenerHelper), this); + pluginManager.registerEvents(serviceLocator.getService(MVPPlayerMoveListener.class), this); } - pm.registerEvents(coreListener, this); } /** Create the higher level permissions so we can add finer ones to them. */ @@ -234,7 +229,7 @@ private void loadPortals() { for (String pname : keys) { MVPortal portal = MVPortal.loadMVPortalFromConfig(this, pname); if (portal.getLocation().isValidLocation()) { - this.portalManager.addPortal(portal); + this.portalManager.get().addPortal(portal); } else { Logging.warning(String.format("Portal '%s' not loaded due to invalid location!", portal.getName())); } @@ -243,7 +238,7 @@ private void loadPortals() { } // Now Resolve destinations - for (MVPortal portal : this.portalManager.getAllPortals()) { + for (MVPortal portal : this.portalManager.get().getAllPortals()) { String dest = this.MVPPortalConfig.getString("portals." + portal.getName() + ".destination", ""); if (!dest.equals("")) { portal.setDestination(dest); @@ -319,9 +314,10 @@ public void loadConfig() { } private List migrateFrameMaterials(ConfigurationSection config) { + //todo (MV5 migrate): re-add MaterialConverter return config.getList("framematerials", Collections.emptyList()).stream() .map(Object::toString) - .map(MaterialConverter::convertTypeString) + .map(MaterialConverter::stringToMaterial) .filter(Objects::nonNull) .collect(Collectors.toList()); } @@ -352,32 +348,7 @@ public void onDisable() { /** 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 InfoCommand(this)); - this.commandHandler.registerCommand(new ListCommand(this)); - this.commandHandler.registerCommand(new CreateCommand(this)); - this.commandHandler.registerCommand(new DebugCommand(this)); - this.commandHandler.registerCommand(new RemoveCommand(this)); - this.commandHandler.registerCommand(new ModifyCommand(this)); - this.commandHandler.registerCommand(new SelectCommand(this)); - this.commandHandler.registerCommand(new WandCommand(this)); - this.commandHandler.registerCommand(new ConfigCommand(this)); - for (com.onarandombox.commandhandler.Command c : this.commandHandler.getAllCommands()) { - if (c instanceof HelpCommand) { - c.addKey("mvp"); - } - } - } - - @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); + //todo (MV5 migrate): commands } /** @@ -385,7 +356,8 @@ public boolean onCommand(CommandSender sender, Command command, String commandLa * * @return String containing all the authors formatted correctly with ',' and 'and'. */ - private String getAuthors() { + @Override + public String getAuthors() { String authors = ""; for (int i = 0; i < this.getDescription().getAuthors().size(); i++) { if (i == this.getDescription().getAuthors().size() - 1) { @@ -397,6 +369,11 @@ private String getAuthors() { return authors.substring(2); } + @Override + public PluginServiceLocator getServiceLocator() { + return null; + } + /** * Returns the WorldEdit compatibility object. Use this to check for WorldEdit and get a player's WorldEdit selection. * @@ -410,10 +387,6 @@ public MultiverseCore getCore() { return this.core; } - public PortalManager getPortalManager() { - return this.portalManager; - } - public FileConfiguration getPortalsConfig() { return this.MVPPortalConfig; } @@ -437,7 +410,7 @@ public void reloadConfigs() { public void reloadConfigs(boolean reloadPortals) { if (reloadPortals) { - this.portalManager.removeAll(false); + this.portalManager.get().removeAll(false); this.loadPortals(); } @@ -449,7 +422,7 @@ public void reloadConfigs(boolean reloadPortals) { if (MultiversePortals.TeleportVehicles != previousTeleportVehicles) { if (MultiversePortals.TeleportVehicles) { - pm.registerEvents(new MVPVehicleListener(this), this); + pm.registerEvents(serviceLocator.getService(MVPVehicleListener.class), this); } else { VehicleMoveEvent.getHandlerList().unregister(this); } @@ -457,7 +430,7 @@ public void reloadConfigs(boolean reloadPortals) { if (MultiversePortals.UseOnMove != previousUseOnMove) { if (MultiversePortals.UseOnMove) { - pm.registerEvents(new MVPPlayerMoveListener(this, new PlayerListenerHelper(this)), this); + pm.registerEvents(serviceLocator.getService(MVPPlayerMoveListener.class), this);; } else { BlockFromToEvent.getHandlerList().unregister(this); PlayerMoveEvent.getHandlerList().unregister(this); @@ -465,60 +438,9 @@ public void reloadConfigs(boolean reloadPortals) { } } - /** - * Logs a message to Multiverse-Portal's Logger. If the Message is of fine-finest level, it will be logged to the - * debug log if enabled. - * @param level - * @param msg - * @deprecated - */ - @Deprecated - public static void staticLog(Level level, String msg) { - Logging.log(level, msg); - } - - /** - * - * @param level - * @param msg - * @deprecated - */ - @Deprecated - public static void staticDebugLog(Level level, String msg) { - Logging.log(level, msg); - } - - /** - * {@inheritDoc} - * - * @deprecated This is now deprecated, nobody needs it any longer. - * All logging is now done with {@link Logging}. - */ - @Override - @Deprecated - public void log(Level level, String msg) { - Logging.log(level, msg); - } - - @Override - public String dumpVersionInfo(String buffer) { - buffer += logAndAddToPasteBinBuffer("Multiverse-Portals Version: " + this.getDescription().getVersion()); - buffer += logAndAddToPasteBinBuffer("Bukkit Version: " + this.getServer().getVersion()); - buffer += logAndAddToPasteBinBuffer("Loaded Portals: " + this.getPortalManager().getAllPortals().size()); - buffer += logAndAddToPasteBinBuffer("Dumping Portal Values: (version " + this.getMainConfig().getString("version", "NOT SET") + ")"); - for (PortalConfigProperty property : PortalConfigProperty.values()) { - String propStr = property.toString(); - if (!("version".equals(propStr))) { - buffer += logAndAddToPasteBinBuffer(propStr + ": " + this.getMainConfig().getString(propStr, "NOT SET")); - } - } - buffer += logAndAddToPasteBinBuffer("Special Code: FRN001"); - return buffer; - } - public String getVersionInfo() { return "[Multiverse-Portals] Multiverse-Portals Version: " + this.getDescription().getVersion() + '\n' - + "[Multiverse-Portals] Loaded Portals: " + this.getPortalManager().getAllPortals().size() + '\n' + + "[Multiverse-Portals] Loaded Portals: " + this.portalManager.get().getAllPortals().size() + '\n' + "[Multiverse-Portals] Dumping Portal Values: (version " + this.getMainConfig().getDouble("version", -1) + ')' + '\n' + "[Multiverse-Portals] wand: " + this.getMainConfig().get("wand", "NOT SET") + '\n' + "[Multiverse-Portals] useonmove: " + this.getMainConfig().get("useonmove", "NOT SET") + '\n' @@ -531,11 +453,6 @@ public String getVersionInfo() { + "[Multiverse-Portals] Special Code: FRN001" + '\n'; } - private String logAndAddToPasteBinBuffer(String string) { - Logging.info(string); - return "[Multiverse-Portals] " + string + "\n"; - } - public long getCooldownTime() { return this.portalCooldown; } @@ -549,7 +466,7 @@ public void setWandEnabled(boolean enabled) { } public Material getWandMaterial() { - Material m = MaterialConverter.convertConfigType(getMainConfig(),"wand"); + Material m = MaterialConverter.stringToMaterial(getMainConfig().getString("wand")); if (m == null) { m = MultiversePortals.DEFAULT_WAND; } diff --git a/src/main/java/org/mvplugins/multiverse/portals/MultiversePortalsPluginBinder.java b/src/main/java/org/mvplugins/multiverse/portals/MultiversePortalsPluginBinder.java new file mode 100644 index 0000000..7c6e4cb --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/MultiversePortalsPluginBinder.java @@ -0,0 +1,19 @@ +package org.mvplugins.multiverse.portals; + +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 MultiversePortalsPluginBinder extends JavaPluginBinder { + + protected MultiversePortalsPluginBinder(@NotNull MultiversePortals plugin) { + super(plugin); + } + + @Override + protected ScopedBindingBuilder bindPluginClass( + ScopedBindingBuilder bindingBuilder) { + return super.bindPluginClass(bindingBuilder).to(MVPlugin.class).to(MultiversePortals.class); + } +} diff --git a/src/main/java/com/onarandombox/MultiversePortals/PortalLocation.java b/src/main/java/org/mvplugins/multiverse/portals/PortalLocation.java similarity index 85% rename from src/main/java/com/onarandombox/MultiversePortals/PortalLocation.java rename to src/main/java/org/mvplugins/multiverse/portals/PortalLocation.java index cd7b375..8d3c42c 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/PortalLocation.java +++ b/src/main/java/org/mvplugins/multiverse/portals/PortalLocation.java @@ -5,27 +5,25 @@ * with this project */ -package com.onarandombox.MultiversePortals; +package org.mvplugins.multiverse.portals; import java.util.Arrays; import java.util.List; -import java.util.logging.Level; import com.dumptruckman.minecraft.util.Logging; -import org.bukkit.Location; +import com.sk89q.worldedit.math.BlockVector3; import org.bukkit.util.Vector; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiversePortals.utils.MultiverseRegion; +import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; +import org.mvplugins.multiverse.portals.utils.MultiverseRegion; public class PortalLocation { private MultiverseRegion region; private boolean validLocation = false; - public PortalLocation(Vector pos1, Vector pos2, MultiverseWorld world) { + public PortalLocation(Vector pos1, Vector pos2, LoadedMultiverseWorld world) { this.validLocation = this.setLocation(pos1, pos2, world); - ; } public PortalLocation() { @@ -37,11 +35,11 @@ public PortalLocation() { * @param minPt * @param maxPt */ - public PortalLocation(com.sk89q.worldedit.math.BlockVector3 minPt, com.sk89q.worldedit.math.BlockVector3 maxPt, MultiverseWorld world) { + public PortalLocation(BlockVector3 minPt, BlockVector3 maxPt, LoadedMultiverseWorld world) { this(new Vector(minPt.getX(), minPt.getY(), minPt.getZ()), new Vector(maxPt.getX(), maxPt.getY(), maxPt.getZ()), world); } - public static PortalLocation parseLocation(String locationString, MultiverseWorld world, String portalName) { + public static PortalLocation parseLocation(String locationString, LoadedMultiverseWorld world, String portalName) { String[] split = locationString.split(":"); if (split.length != 2) { Logging.warning("Failed Parsing Location for: " + portalName + " (Format Error, was expecting: `X,Y,Z:X,Y,Z`, but got: `" + locationString + "`)"); @@ -81,7 +79,7 @@ private static Vector parseVector(String vectorString) { return new Vector(coords[0], coords[1], coords[2]); } - public boolean setLocation(Vector v1, Vector v2, MultiverseWorld world) { + public boolean setLocation(Vector v1, Vector v2, LoadedMultiverseWorld world) { if (v1 == null || v2 == null || world == null) { this.validLocation = false; this.region = null; @@ -92,7 +90,7 @@ public boolean setLocation(Vector v1, Vector v2, MultiverseWorld world) { return this.validLocation; } - public boolean setLocation(String v1, String v2, MultiverseWorld world) { + public boolean setLocation(String v1, String v2, LoadedMultiverseWorld world) { if (v1 == null || v2 == null) { this.validLocation = false; this.region = null; @@ -134,7 +132,7 @@ public String toString() { return sb.toString(); } - public MultiverseWorld getMVWorld() { + public LoadedMultiverseWorld getMVWorld() { if (this.region == null) { return null; } diff --git a/src/main/java/com/onarandombox/MultiversePortals/PortalPlayerSession.java b/src/main/java/org/mvplugins/multiverse/portals/PortalPlayerSession.java similarity index 78% rename from src/main/java/com/onarandombox/MultiversePortals/PortalPlayerSession.java rename to src/main/java/org/mvplugins/multiverse/portals/PortalPlayerSession.java index 226a28d..49fd9ec 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/PortalPlayerSession.java +++ b/src/main/java/org/mvplugins/multiverse/portals/PortalPlayerSession.java @@ -5,25 +5,31 @@ * with this project */ -package com.onarandombox.MultiversePortals; +package org.mvplugins.multiverse.portals; import java.util.Date; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiversePortals.enums.MoveType; -import com.onarandombox.MultiversePortals.utils.DisplayUtils; +import org.mvplugins.multiverse.core.economy.MVEconomist; +import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; +import org.mvplugins.multiverse.core.world.WorldManager; +import org.mvplugins.multiverse.portals.enums.MoveType; +import org.mvplugins.multiverse.portals.utils.DisplayUtils; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiversePortals.utils.MultiverseRegion; -import com.onarandombox.MultiversePortals.utils.PortalManager; +import org.mvplugins.multiverse.portals.utils.MultiverseRegion; +import org.mvplugins.multiverse.portals.utils.PortalManager; public class PortalPlayerSession { private final MultiversePortals plugin; + private final PortalManager portalManager; + private final WorldManager worldManager; + private final DisplayUtils displayUtils; + private final MVEconomist economist; private final Player player; private MVPortal portalSelection = null; @@ -34,12 +40,16 @@ public class PortalPlayerSession { private Location loc; private Vector rightClick; private Vector leftClick; - private MultiverseWorld rightClickWorld; - private MultiverseWorld leftClickWorld; + private LoadedMultiverseWorld rightClickWorld; + private LoadedMultiverseWorld leftClickWorld; private Date lastTeleportTime; public PortalPlayerSession(MultiversePortals plugin, Player p) { this.plugin = plugin; + this.portalManager = plugin.getServiceLocator().getService(PortalManager.class); + this.worldManager = plugin.getServiceLocator().getService(WorldManager.class); + this.displayUtils = plugin.getServiceLocator().getService(DisplayUtils.class); + this.economist = plugin.getServiceLocator().getService(MVEconomist.class); this.player = p; this.setLocation(p.getLocation()); this.lastTeleportTime = new Date(new Date().getTime() - this.plugin.getCooldownTime()); @@ -83,10 +93,10 @@ private void setLocation(Location loc) { private void setStandingInLocation() { // If they're not in a portal and this location is a portal - if (this.standingIn == null && this.plugin.getPortalManager().isPortal(this.loc)) { - this.standingIn = this.plugin.getPortalManager().getPortal(this.loc); + if (this.standingIn == null && this.portalManager.isPortal(this.loc)) { + this.standingIn = this.portalManager.getPortal(this.loc); // There is no portal here. - } else if (!this.plugin.getPortalManager().isPortal(this.loc)) { + } else if (!this.portalManager.isPortal(this.loc)) { this.hasMovedOutOfPortal = true; this.standingIn = null; } else { @@ -124,7 +134,7 @@ public void setStaleLocation(Location loc, MoveType moveType) { } } - public boolean setLeftClickSelection(Vector v, MultiverseWorld world) { + public boolean setLeftClickSelection(Vector v, LoadedMultiverseWorld world) { if(!this.plugin.isWandEnabled()) { return false; } @@ -139,7 +149,7 @@ public boolean setLeftClickSelection(Vector v, MultiverseWorld world) { return true; } - public boolean setRightClickSelection(Vector v, MultiverseWorld world) { + public boolean setRightClickSelection(Vector v, LoadedMultiverseWorld world) { if(!this.plugin.isWandEnabled()) { return false; } @@ -163,7 +173,7 @@ public MultiverseRegion getSelectedRegion() { Location maxPoint = worldEdit.getSelectionMaxPoint(this.player); if (minPoint != null && maxPoint != null && minPoint.getWorld().equals(maxPoint.getWorld())) { return new MultiverseRegion(minPoint, maxPoint, - plugin.getCore().getMVWorldManager().getMVWorld(minPoint.getWorld().getName())); + this.worldManager.getLoadedWorld(minPoint.getWorld().getName()).getOrNull()); } else { this.player.sendMessage("You haven't finished your selection."); return null; @@ -184,8 +194,8 @@ public MultiverseRegion getSelectedRegion() { } if (!this.leftClickWorld.equals(this.rightClickWorld)) { this.player.sendMessage("You need to select both coords in the same world!"); - this.player.sendMessage("Left Click Position was in:" + this.leftClickWorld.getColoredWorldString()); - this.player.sendMessage("Right Click Position was in:" + this.rightClickWorld.getColoredWorldString()); + this.player.sendMessage("Left Click Position was in:" + this.leftClickWorld.getAlias()); + this.player.sendMessage("Right Click Position was in:" + this.rightClickWorld.getAlias()); return null; } return new MultiverseRegion(this.leftClick, this.rightClick, this.leftClickWorld); @@ -207,7 +217,7 @@ public MVPortal getStandingInPortal() { * @return The {@link MVPortal} the player is standing in. */ public MVPortal getUncachedStandingInPortal() { - return this.standingIn = this.plugin.getPortalManager().getPortal(this.loc); + return this.standingIn = this.portalManager.getPortal(this.loc); } /** @@ -216,8 +226,7 @@ public MVPortal getUncachedStandingInPortal() { * @param location */ public void playerDidTeleport(Location location) { - PortalManager pm = this.plugin.getPortalManager(); - if (pm.getPortal(location) != null) { + if (portalManager.getPortal(location) != null) { this.hasMovedOutOfPortal = false; return; } @@ -237,44 +246,21 @@ public boolean showDebugInfo() { return false; } - DisplayUtils.showStaticInfo(this.player, this.standingIn, "You are currently standing in "); - DisplayUtils.showPortalPriceInfo(this.standingIn, this.player); + displayUtils.showStaticInfo(this.player, this.standingIn, "You are currently standing in "); + displayUtils.showPortalPriceInfo(this.standingIn, this.player); return true; } public boolean showDebugInfo(MVPortal portal) { if (portal.playerCanEnterPortal(this.player)) { - DisplayUtils.showStaticInfo(this.player, portal, "Portal Info "); - DisplayUtils.showPortalPriceInfo(portal, this.player); + displayUtils.showStaticInfo(this.player, portal, "Portal Info "); + displayUtils.showPortalPriceInfo(portal, this.player); } else { Logging.info("Player " + this.player.getName() + " walked through" + portal.getName() + " with debug on."); } return true; } - @Deprecated - private void showPortalPriceInfo(MVPortal portal) { - if (portal.getPrice() > 0D) { - this.player.sendMessage("Price: " + ChatColor.GREEN + plugin.getCore().getEconomist().formatPrice(portal.getPrice(), portal.getCurrency())); - } else if (portal.getPrice() < 0D) { - this.player.sendMessage("Price: " + ChatColor.GREEN + plugin.getCore().getEconomist().formatPrice(-portal.getPrice(), portal.getCurrency())); - } else { - this.player.sendMessage("Price: " + ChatColor.GREEN + "FREE!"); - } - } - - @Deprecated - public static void showStaticInfo(CommandSender sender, MVPortal portal, String message) { - sender.sendMessage(message + ChatColor.DARK_AQUA + portal.getName()); - sender.sendMessage("It's coords are: " + ChatColor.GOLD + portal.getLocation().toString()); - if (portal.getDestination() == null) { - sender.sendMessage("This portal has " + ChatColor.RED + "NO DESTINATION SET."); - } else { - sender.sendMessage("It will take you to a location of type: " + ChatColor.AQUA + portal.getDestination().getType()); - sender.sendMessage("The destination's name is: " + ChatColor.GREEN + portal.getDestination().getName()); - } - } - public void setTeleportTime(Date date) { this.lastTeleportTime = date; } diff --git a/src/main/java/com/onarandombox/MultiversePortals/WorldEditConnection.java b/src/main/java/org/mvplugins/multiverse/portals/WorldEditConnection.java similarity index 96% rename from src/main/java/com/onarandombox/MultiversePortals/WorldEditConnection.java rename to src/main/java/org/mvplugins/multiverse/portals/WorldEditConnection.java index 5b4241e..b3ce9f1 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/WorldEditConnection.java +++ b/src/main/java/org/mvplugins/multiverse/portals/WorldEditConnection.java @@ -1,142 +1,142 @@ -package com.onarandombox.MultiversePortals; - -import com.sk89q.worldedit.IncompleteRegionException; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.bukkit.BukkitPlayer; -import com.sk89q.worldedit.bukkit.BukkitWorld; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.regions.Region; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -public class WorldEditConnection { - - private final Plugin connectingPlugin; - - private WorldEditPlugin worldEditPlugin; - WorldEdit worldEdit; - - WorldEditConnection(Plugin plugin) { - if (plugin == null) { - throw new RuntimeException("plugin must not be null."); - } - this.connectingPlugin = plugin; - } - - private WorldEditPlugin retrieveWorldEditPluginFromServer() { - Plugin plugin = connectingPlugin.getServer().getPluginManager().getPlugin("WorldEdit"); - if (plugin == null) { - plugin = connectingPlugin.getServer().getPluginManager().getPlugin("FastAsyncWorldEdit"); - } - - if (plugin == null) { - return null; - } else if (plugin instanceof WorldEditPlugin) { - return (WorldEditPlugin) plugin; - } else { - connectingPlugin.getLogger().warning("WorldEdit v" + plugin.getDescription().getVersion() - + " is incompatible with " + connectingPlugin.getDescription().getName() + " v" - + connectingPlugin.getDescription().getVersion()); - return null; - } - } - - /** - * Attempts to connect to the WorldEdit plugin. - * - * @return true if the WorldEdit plugin is available and able to be interfaced with. - */ - boolean connect() { - if (!isConnected()) { - worldEditPlugin = retrieveWorldEditPluginFromServer(); - if (worldEditPlugin != null) { - this.worldEdit = worldEditPlugin.getWorldEdit(); - connectingPlugin.getLogger().info(String.format("Found %s. Using it for selections.", worldEditPlugin.getName())); - return true; - } - } - return false; - } - - void disconnect() { - worldEditPlugin = null; - this.worldEdit = null; - } - - /** - * Tests the connection to the WorldEdit plugin. - * - * @return true if current connected to the WorldEdit plugin. - */ - public boolean isConnected() { - return worldEditPlugin != null; - } - - private Region getSelection(Player player) { - if (!isConnected()) { - throw new RuntimeException("WorldEdit connection is unavailable."); - } - try { - return worldEdit.getSessionManager().get(new BukkitPlayer(worldEditPlugin, player)).getSelection(new BukkitWorld(player.getWorld())); - } catch (IncompleteRegionException e) { - return null; - } - } - - /** - * @return the maximum point of the player's WorldEdit selection or null if the player has no selection. - */ - public Location getSelectionMaxPoint(Player player) { - if (player == null) { - throw new RuntimeException("player must not be null."); - } - - if (!isConnected()) { - throw new RuntimeException("WorldEdit connection is unavailable."); - } - - Region selection = getSelection(player); - if (selection != null) { - BlockVector3 point = selection.getMaximumPoint(); - return new Location(player.getWorld(), point.getBlockX(), point.getBlockY(), point.getBlockZ()); - } - return null; - } - - /** - * @return the minimum point of the player's WorldEdit selection or null if the player has no selection. - */ - public Location getSelectionMinPoint(Player player) { - if (player == null) { - throw new RuntimeException("player must not be null."); - } - - if (!isConnected()) { - throw new RuntimeException("WorldEdit connection is unavailable."); - } - - Region selection = getSelection(player); - if (selection != null) { - BlockVector3 point = selection.getMinimumPoint(); - return new Location(player.getWorld(), point.getBlockX(), point.getBlockY(), point.getBlockZ()); - } - return null; - } - - /** - * @return true if the player has currently has a WorldEdit selection. - */ - public boolean isSelectionAvailable(Player player) { - if (player == null) { - throw new RuntimeException("player must not be null."); - } - - if (!isConnected()) { - throw new RuntimeException("WorldEdit connection is unavailable."); - } - - return getSelection(player) != null; - } -} +package org.mvplugins.multiverse.portals; + +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitPlayer; +import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.Region; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class WorldEditConnection { + + private final Plugin connectingPlugin; + + private WorldEditPlugin worldEditPlugin; + WorldEdit worldEdit; + + WorldEditConnection(Plugin plugin) { + if (plugin == null) { + throw new RuntimeException("plugin must not be null."); + } + this.connectingPlugin = plugin; + } + + private WorldEditPlugin retrieveWorldEditPluginFromServer() { + Plugin plugin = connectingPlugin.getServer().getPluginManager().getPlugin("WorldEdit"); + if (plugin == null) { + plugin = connectingPlugin.getServer().getPluginManager().getPlugin("FastAsyncWorldEdit"); + } + + if (plugin == null) { + return null; + } else if (plugin instanceof WorldEditPlugin) { + return (WorldEditPlugin) plugin; + } else { + connectingPlugin.getLogger().warning("WorldEdit v" + plugin.getDescription().getVersion() + + " is incompatible with " + connectingPlugin.getDescription().getName() + " v" + + connectingPlugin.getDescription().getVersion()); + return null; + } + } + + /** + * Attempts to connect to the WorldEdit plugin. + * + * @return true if the WorldEdit plugin is available and able to be interfaced with. + */ + boolean connect() { + if (!isConnected()) { + worldEditPlugin = retrieveWorldEditPluginFromServer(); + if (worldEditPlugin != null) { + this.worldEdit = worldEditPlugin.getWorldEdit(); + connectingPlugin.getLogger().info(String.format("Found %s. Using it for selections.", worldEditPlugin.getName())); + return true; + } + } + return false; + } + + void disconnect() { + worldEditPlugin = null; + this.worldEdit = null; + } + + /** + * Tests the connection to the WorldEdit plugin. + * + * @return true if current connected to the WorldEdit plugin. + */ + public boolean isConnected() { + return worldEditPlugin != null; + } + + private Region getSelection(Player player) { + if (!isConnected()) { + throw new RuntimeException("WorldEdit connection is unavailable."); + } + try { + return worldEdit.getSessionManager().get(new BukkitPlayer(worldEditPlugin, player)).getSelection(new BukkitWorld(player.getWorld())); + } catch (IncompleteRegionException e) { + return null; + } + } + + /** + * @return the maximum point of the player's WorldEdit selection or null if the player has no selection. + */ + public Location getSelectionMaxPoint(Player player) { + if (player == null) { + throw new RuntimeException("player must not be null."); + } + + if (!isConnected()) { + throw new RuntimeException("WorldEdit connection is unavailable."); + } + + Region selection = getSelection(player); + if (selection != null) { + BlockVector3 point = selection.getMaximumPoint(); + return new Location(player.getWorld(), point.getBlockX(), point.getBlockY(), point.getBlockZ()); + } + return null; + } + + /** + * @return the minimum point of the player's WorldEdit selection or null if the player has no selection. + */ + public Location getSelectionMinPoint(Player player) { + if (player == null) { + throw new RuntimeException("player must not be null."); + } + + if (!isConnected()) { + throw new RuntimeException("WorldEdit connection is unavailable."); + } + + Region selection = getSelection(player); + if (selection != null) { + BlockVector3 point = selection.getMinimumPoint(); + return new Location(player.getWorld(), point.getBlockX(), point.getBlockY(), point.getBlockZ()); + } + return null; + } + + /** + * @return true if the player has currently has a WorldEdit selection. + */ + public boolean isSelectionAvailable(Player player) { + if (player == null) { + throw new RuntimeException("player must not be null."); + } + + if (!isConnected()) { + throw new RuntimeException("WorldEdit connection is unavailable."); + } + + return getSelection(player) != null; + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/commands/PortalsCommand.java b/src/main/java/org/mvplugins/multiverse/portals/commands/PortalsCommand.java new file mode 100644 index 0000000..0b779cb --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/commands/PortalsCommand.java @@ -0,0 +1,16 @@ +package org.mvplugins.multiverse.portals.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 portal commands + */ +@Contract +public abstract class PortalsCommand extends MultiverseCommand { + protected PortalsCommand(@NotNull MVCommandManager commandManager) { + super(commandManager); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/destination/PortalDestination.java b/src/main/java/org/mvplugins/multiverse/portals/destination/PortalDestination.java new file mode 100644 index 0000000..bf8c201 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/destination/PortalDestination.java @@ -0,0 +1,55 @@ +package org.mvplugins.multiverse.portals.destination; + +import org.mvplugins.multiverse.core.api.LocationManipulation; +import org.mvplugins.multiverse.core.destination.Destination; +import org.mvplugins.multiverse.external.acf.commands.BukkitCommandIssuer; +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.portals.MVPortal; +import org.mvplugins.multiverse.portals.utils.PortalManager; + +import java.util.Collection; + +@Service +public class PortalDestination implements Destination { + + private final PortalManager portalManager; + private final LocationManipulation locationManipulation; + + @Inject + PortalDestination(@NotNull PortalManager portalManager, @NotNull LocationManipulation locationManipulation) { + this.portalManager = portalManager; + this.locationManipulation = locationManipulation; + } + + @Override + public @NotNull String getIdentifier() { + return "p"; + } + + @Override + public @Nullable PortalDestinationInstance getDestinationInstance(@Nullable String destinationParams) { + String[] items = destinationParams.split(":"); + if (items.length > 3) { + return null; + } + + String portalName = items[0]; + MVPortal portal = portalManager.getPortal(portalName); + if (portal == null) { + return null; + } + + String direction = (items.length == 2) ? items[1] : null; + float yaw = direction != null ? this.locationManipulation.getYaw(direction) : -1; + + return new PortalDestinationInstance(this, portal, direction, yaw); + } + + @Override + public @NotNull Collection suggestDestinations(@NotNull BukkitCommandIssuer bukkitCommandIssuer, @Nullable String s) { + return portalManager.getAllPortals().stream().map(MVPortal::getName).toList(); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/destination/PortalDestinationInstance.java b/src/main/java/org/mvplugins/multiverse/portals/destination/PortalDestinationInstance.java new file mode 100644 index 0000000..19575f1 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/destination/PortalDestinationInstance.java @@ -0,0 +1,62 @@ +package org.mvplugins.multiverse.portals.destination; + +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; +import org.mvplugins.multiverse.core.destination.DestinationInstance; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jetbrains.annotations.Nullable; +import org.mvplugins.multiverse.external.vavr.control.Option; +import org.mvplugins.multiverse.portals.MVPortal; + +public class PortalDestinationInstance extends DestinationInstance { + + private final MVPortal portal; + private final String direction; + private final float yaw; + + protected PortalDestinationInstance( + @NotNull PortalDestination destination, + @NotNull MVPortal portal, + @Nullable String direction, + float yaw + ) { + super(destination); + this.portal = portal; + this.direction = direction; + this.yaw = yaw; + } + + public String getDirection() { + return direction; + } + + @Override + public @NotNull Option getLocation(@NotNull Entity teleportee) { + return Option.of(portal.getSafePlayerSpawnLocation()) + .peek(l -> l.setYaw(yaw)); + } + + @Override + public @NotNull Option getVelocity(@NotNull Entity teleportee) { + return Option.none(); + } + + @Override + public boolean checkTeleportSafety() { + return portal.useSafeTeleporter(); + } + + @Override + public @NotNull Option getFinerPermissionSuffix() { + return Option.of(portal.getName()); + } + + @Override + protected @NotNull String serialise() { + if (this.direction != null) { + return this.portal.getName() + ":" + this.direction; + } + return this.portal.getName(); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/destination/RandomPortalDestination.java b/src/main/java/org/mvplugins/multiverse/portals/destination/RandomPortalDestination.java new file mode 100644 index 0000000..81f660a --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/destination/RandomPortalDestination.java @@ -0,0 +1,41 @@ +package org.mvplugins.multiverse.portals.destination; + +import org.mvplugins.multiverse.core.destination.Destination; +import org.mvplugins.multiverse.external.acf.commands.BukkitCommandIssuer; +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.portals.utils.PortalManager; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +@Service +public class RandomPortalDestination implements Destination { + + private final PortalManager portalManager; + + @Inject + RandomPortalDestination(PortalManager portalManager) { + this.portalManager = portalManager; + } + + @Override + public @NotNull String getIdentifier() { + return "rp"; + } + + @Override + public @Nullable RandomPortalDestinationInstance getDestinationInstance(@Nullable String destinationParams) { + List portalNames = Arrays.stream(destinationParams.split(",")).toList(); + return new RandomPortalDestinationInstance(this, portalManager, portalNames); + } + + @Override + public @NotNull Collection suggestDestinations(@NotNull BukkitCommandIssuer bukkitCommandIssuer, @Nullable String s) { + // todo: suggest all the portal names comma seperated + return List.of(); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/destination/RandomPortalDestinationInstance.java b/src/main/java/org/mvplugins/multiverse/portals/destination/RandomPortalDestinationInstance.java new file mode 100644 index 0000000..abcefc9 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/destination/RandomPortalDestinationInstance.java @@ -0,0 +1,59 @@ +package org.mvplugins.multiverse.portals.destination; + +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; +import org.mvplugins.multiverse.core.destination.DestinationInstance; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.vavr.control.Option; +import org.mvplugins.multiverse.portals.MVPortal; +import org.mvplugins.multiverse.portals.utils.PortalManager; + +import java.util.List; + +import static org.mvplugins.multiverse.external.acf.commands.ACFUtil.RANDOM; + +public class RandomPortalDestinationInstance extends DestinationInstance { + + private final PortalManager portalManager; + private final List portalNames; + + public RandomPortalDestinationInstance( + @NotNull RandomPortalDestination destination, + @NotNull PortalManager portalManager, + @NotNull List portalNames) { + super(destination); + this.portalManager = portalManager; + this.portalNames = portalNames; + } + + @Override + public @NotNull Option getLocation(@NotNull Entity teleportee) { + List portalNames = this.portalNames.isEmpty() + ? portalManager.getAllPortals().stream().map(MVPortal::getName).toList() + : this.portalNames; + String targetPortalName = portalNames.get(RANDOM.nextInt(portalNames.size())); + return Option.of(portalManager.getPortal(targetPortalName)) + .map(MVPortal::getSafePlayerSpawnLocation); + } + + @Override + public @NotNull Option getVelocity(@NotNull Entity teleportee) { + return Option.none(); + } + + @Override + public boolean checkTeleportSafety() { + return true; + } + + @Override + public @NotNull Option getFinerPermissionSuffix() { + return Option.none(); + } + + @Override + protected @NotNull String serialise() { + return String.join(",", portalNames); + } +} diff --git a/src/main/java/com/onarandombox/MultiversePortals/enums/MoveType.java b/src/main/java/org/mvplugins/multiverse/portals/enums/MoveType.java similarity index 84% rename from src/main/java/com/onarandombox/MultiversePortals/enums/MoveType.java rename to src/main/java/org/mvplugins/multiverse/portals/enums/MoveType.java index 11be134..776011b 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/enums/MoveType.java +++ b/src/main/java/org/mvplugins/multiverse/portals/enums/MoveType.java @@ -1,16 +1,16 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2012. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.enums; - -/** - * This is here until I decide what to do with the old - * Type enum that we were using. - */ -public enum MoveType { - VEHICLE_MOVE, PLAYER_MOVE -} +/* + * Multiverse 2 Copyright (c) the Multiverse Team 2012. + * Multiverse 2 is licensed under the BSD License. + * For more information please check the README.md file included + * with this project + */ + +package org.mvplugins.multiverse.portals.enums; + +/** + * This is here until I decide what to do with the old + * Type enum that we were using. + */ +public enum MoveType { + VEHICLE_MOVE, PLAYER_MOVE +} diff --git a/src/main/java/com/onarandombox/MultiversePortals/enums/PortalConfigProperty.java b/src/main/java/org/mvplugins/multiverse/portals/enums/PortalConfigProperty.java similarity index 89% rename from src/main/java/com/onarandombox/MultiversePortals/enums/PortalConfigProperty.java rename to src/main/java/org/mvplugins/multiverse/portals/enums/PortalConfigProperty.java index 4cbb827..db0b378 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/enums/PortalConfigProperty.java +++ b/src/main/java/org/mvplugins/multiverse/portals/enums/PortalConfigProperty.java @@ -1,28 +1,28 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.enums; - -/** - * Multiverse 2 - * - * @author fernferret - */ -public enum PortalConfigProperty { - wand, useonmove, portalsdefaulttonether, enforceportalaccess, - portalcooldown, clearonremove, teleportvehicles; - - - public static String getAllValues() { - String buffer = ""; - for (PortalConfigProperty c : PortalConfigProperty.values()) { - // All values will NOT Contain spaces. - buffer += c.toString() + " "; - } - return buffer; - } -} +/* + * Multiverse 2 Copyright (c) the Multiverse Team 2011. + * Multiverse 2 is licensed under the BSD License. + * For more information please check the README.md file included + * with this project + */ + +package org.mvplugins.multiverse.portals.enums; + +/** + * Multiverse 2 + * + * @author fernferret + */ +public enum PortalConfigProperty { + wand, useonmove, portalsdefaulttonether, enforceportalaccess, + portalcooldown, clearonremove, teleportvehicles; + + + public static String getAllValues() { + String buffer = ""; + for (PortalConfigProperty c : PortalConfigProperty.values()) { + // All values will NOT Contain spaces. + buffer += c.toString() + " "; + } + return buffer; + } +} diff --git a/src/main/java/com/onarandombox/MultiversePortals/enums/PortalType.java b/src/main/java/org/mvplugins/multiverse/portals/enums/PortalType.java similarity index 85% rename from src/main/java/com/onarandombox/MultiversePortals/enums/PortalType.java rename to src/main/java/org/mvplugins/multiverse/portals/enums/PortalType.java index 67a37b9..5bcf090 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/enums/PortalType.java +++ b/src/main/java/org/mvplugins/multiverse/portals/enums/PortalType.java @@ -1,17 +1,17 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.enums; - -/** - * What type of portal was used? - * - * If Legacy, a MV1 style portal was used. - * If Normal, a Nether style portal (with purple goo) was used. - * - */ -public enum PortalType { Legacy, Normal } +/* + * Multiverse 2 Copyright (c) the Multiverse Team 2011. + * Multiverse 2 is licensed under the BSD License. + * For more information please check the README.md file included + * with this project + */ + +package org.mvplugins.multiverse.portals.enums; + +/** + * What type of portal was used? + * + * If Legacy, a MV1 style portal was used. + * If Normal, a Nether style portal (with purple goo) was used. + * + */ +public enum PortalType { Legacy, Normal } diff --git a/src/main/java/com/onarandombox/MultiversePortals/enums/SetProperties.java b/src/main/java/org/mvplugins/multiverse/portals/enums/SetProperties.java similarity index 84% rename from src/main/java/com/onarandombox/MultiversePortals/enums/SetProperties.java rename to src/main/java/org/mvplugins/multiverse/portals/enums/SetProperties.java index 4feccb5..6900ebd 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/enums/SetProperties.java +++ b/src/main/java/org/mvplugins/multiverse/portals/enums/SetProperties.java @@ -1,12 +1,12 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.enums; - -public enum SetProperties { - destination, dest, owner, loc, location, price, currency, curr, safe, telenonplayers, handlerscript -} +/* + * Multiverse 2 Copyright (c) the Multiverse Team 2011. + * Multiverse 2 is licensed under the BSD License. + * For more information please check the README.md file included + * with this project + */ + +package org.mvplugins.multiverse.portals.enums; + +public enum SetProperties { + destination, dest, owner, loc, location, price, currency, curr, safe, telenonplayers, handlerscript +} diff --git a/src/main/java/com/onarandombox/MultiversePortals/event/MVPortalEvent.java b/src/main/java/org/mvplugins/multiverse/portals/event/MVPortalEvent.java similarity index 75% rename from src/main/java/com/onarandombox/MultiversePortals/event/MVPortalEvent.java rename to src/main/java/org/mvplugins/multiverse/portals/event/MVPortalEvent.java index aebbd81..cd62197 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/event/MVPortalEvent.java +++ b/src/main/java/org/mvplugins/multiverse/portals/event/MVPortalEvent.java @@ -5,17 +5,16 @@ * with this project */ -package com.onarandombox.MultiversePortals.event; +package org.mvplugins.multiverse.portals.event; -import com.onarandombox.MultiverseCore.utils.MVTravelAgent; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import com.onarandombox.MultiverseCore.api.MVDestination; -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.enums.PortalType; +import org.mvplugins.multiverse.core.destination.DestinationInstance; +import org.mvplugins.multiverse.portals.MVPortal; +import org.mvplugins.multiverse.portals.enums.PortalType; /** * Multiverse 2 @@ -25,19 +24,17 @@ public class MVPortalEvent extends Event implements Cancellable { private Player teleportee; private MVPortal sendingPortal; - private MVDestination destination; - private MVTravelAgent travelAgent; + private DestinationInstance destination; private boolean isCancelled; - public MVPortalEvent(MVDestination destination, Player teleportee, MVTravelAgent travelAgent, MVPortal sendingPortal) { + public MVPortalEvent(DestinationInstance destination, Player teleportee, MVPortal sendingPortal) { this.teleportee = teleportee; this.destination = destination; - this.travelAgent = travelAgent; this.sendingPortal = sendingPortal; } - public MVPortalEvent(MVDestination destination, Player teleportee) { - this(destination, teleportee, null, null); + public MVPortalEvent(DestinationInstance destination, Player teleportee) { + this(destination, teleportee, null); } private static final HandlerList HANDLERS = new HandlerList(); @@ -81,7 +78,7 @@ public Location getFrom() { * * @return The destination the player will spawn at. */ - public MVDestination getDestination() { + public DestinationInstance getDestination() { return this.destination; } @@ -99,15 +96,6 @@ public PortalType getPortalType() throws IllegalStateException { return this.getSendingPortal().getPortalType(); } - /** - * Returns the MVTravelAgent being used, or null if none. - * - * @return The {@link MVTravelAgent}. - */ - public MVTravelAgent getTravelAgent() { - return this.travelAgent; - } - /** * Returns the Portal sending the player * diff --git a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPBlockListener.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPBlockListener.java similarity index 52% rename from src/main/java/com/onarandombox/MultiversePortals/listeners/MVPBlockListener.java rename to src/main/java/org/mvplugins/multiverse/portals/listeners/MVPBlockListener.java index e9834cf..bd43abb 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPBlockListener.java +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPBlockListener.java @@ -5,21 +5,24 @@ * with this project */ -package com.onarandombox.MultiversePortals.listeners; +package org.mvplugins.multiverse.portals.listeners; import org.bukkit.Material; import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPhysicsEvent; -import com.onarandombox.MultiversePortals.MultiversePortals; -import com.onarandombox.MultiversePortals.utils.PortalManager; +import org.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.portals.utils.PortalManager; -public class MVPBlockListener implements Listener { - private MultiversePortals plugin; +@Service +public class MVPBlockListener implements PortalsListener { + private final PortalManager portalManager; - public MVPBlockListener(MultiversePortals plugin) { - this.plugin = plugin; + @Inject + MVPBlockListener(@NotNull PortalManager portalManager) { + this.portalManager = portalManager; } @EventHandler @@ -28,8 +31,7 @@ public void blockPhysics(BlockPhysicsEvent event) { return; } if (event.getChangedType() == Material.NETHER_PORTAL || event.getBlock().getType() == Material.NETHER_PORTAL) { - PortalManager pm = this.plugin.getPortalManager(); - if (pm.isPortal(event.getBlock().getLocation())) { + if (portalManager.isPortal(event.getBlock().getLocation())) { event.setCancelled(true); } } diff --git a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPCoreListener.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPCoreListener.java similarity index 68% rename from src/main/java/com/onarandombox/MultiversePortals/listeners/MVPCoreListener.java rename to src/main/java/org/mvplugins/multiverse/portals/listeners/MVPCoreListener.java index 54c93eb..d9c89e2 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPCoreListener.java +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPCoreListener.java @@ -5,28 +5,34 @@ * with this project */ -package com.onarandombox.MultiversePortals.listeners; +package org.mvplugins.multiverse.portals.listeners; import java.io.File; -import java.util.logging.Level; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.event.MVDebugModeEvent; -import com.onarandombox.MultiversePortals.MVPortal; +import org.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.core.event.MVConfigReloadEvent; +import org.mvplugins.multiverse.core.event.MVDebugModeEvent; +import org.mvplugins.multiverse.core.event.MVPlayerTouchedPortalEvent; +import org.mvplugins.multiverse.core.event.MVVersionEvent; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.portals.MVPortal; import org.bukkit.Location; import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import com.onarandombox.MultiverseCore.event.MVConfigReloadEvent; -import com.onarandombox.MultiverseCore.event.MVPlayerTouchedPortalEvent; -import com.onarandombox.MultiverseCore.event.MVVersionEvent; -import com.onarandombox.MultiversePortals.MultiversePortals; +import org.mvplugins.multiverse.portals.MultiversePortals; +import org.mvplugins.multiverse.portals.utils.PortalManager; -public class MVPCoreListener implements Listener { - private MultiversePortals plugin; +@Service +public class MVPCoreListener implements PortalsListener { + private final MultiversePortals plugin; + private final PortalManager portalManager; - public MVPCoreListener(MultiversePortals plugin) { + @Inject + MVPCoreListener(@NotNull MultiversePortals plugin, @NotNull PortalManager portalManager) { this.plugin = plugin; + this.portalManager = portalManager; } /** @@ -66,24 +72,24 @@ public void debugModeChange(MVDebugModeEvent event) { public void portalTouchEvent(MVPlayerTouchedPortalEvent event) { Logging.finer("Found The TouchedPortal event."); Location l = event.getBlockTouched(); - if (event.canUseThisPortal() && (this.plugin.getPortalManager().isPortal(l))) { + if (event.canUseThisPortal() && (this.portalManager.isPortal(l))) { if (this.plugin.getPortalSession(event.getPlayer()).isDebugModeOn()) { event.setCancelled(true); return; } // This is a valid portal, and they can use it so far... - MVPortal p = this.plugin.getPortalManager().getPortal(event.getPlayer(), l); + MVPortal p = this.portalManager.getPortal(event.getPlayer(), l); if (p == null) { // The player can't see this portal, and can't use it. Logging.finer(String.format("'%s' was DENIED access to this portal event.", event.getPlayer().getName())); event.setCanUseThisPortal(false); - } else if (p.getDestination() == null || !p.getDestination().isValid()) { + } else if (p.getDestination() == null) { if (this.plugin.getMainConfig().getBoolean("portalsdefaulttonether", false)) { Logging.finer("Allowing MVPortal to act as nether portal."); return; } // They can see it, is it val - this.plugin.getCore().getMessaging().sendMessage(event.getPlayer(), "This Multiverse Portal does not have a valid destination!", false); + event.getPlayer().sendMessage("This Multiverse Portal does not have a valid destination!"); event.setCanUseThisPortal(false); } } diff --git a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerListener.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPlayerListener.java similarity index 79% rename from src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerListener.java rename to src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPlayerListener.java index 5b336ba..d24bd1d 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerListener.java +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPlayerListener.java @@ -5,24 +5,25 @@ * with this project */ -package com.onarandombox.MultiversePortals.listeners; - -import java.util.Date; -import java.util.logging.Level; +package org.mvplugins.multiverse.portals.listeners; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.api.MVDestination; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.api.SafeTTeleporter; -import com.onarandombox.MultiverseCore.destination.InvalidDestination; -import com.onarandombox.MultiverseCore.utils.MVEconomist; -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.MultiversePortals; -import com.onarandombox.MultiversePortals.PortalPlayerSession; -import com.onarandombox.MultiversePortals.WorldEditConnection; -import com.onarandombox.MultiversePortals.event.MVPortalEvent; -import com.onarandombox.MultiversePortals.utils.PortalFiller; -import com.onarandombox.MultiversePortals.utils.PortalManager; +import org.mvplugins.multiverse.core.api.BlockSafety; +import org.mvplugins.multiverse.core.api.LocationManipulation; +import org.mvplugins.multiverse.core.destination.DestinationInstance; +import org.mvplugins.multiverse.core.economy.MVEconomist; +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; +import org.mvplugins.multiverse.portals.MVPortal; +import org.mvplugins.multiverse.portals.MultiversePortals; +import org.mvplugins.multiverse.portals.PortalPlayerSession; +import org.mvplugins.multiverse.portals.WorldEditConnection; +import org.mvplugins.multiverse.portals.event.MVPortalEvent; +import org.mvplugins.multiverse.portals.utils.PortalFiller; +import org.mvplugins.multiverse.portals.utils.PortalManager; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -41,18 +42,36 @@ import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.inventory.EquipmentSlot; +@Service public class MVPPlayerListener implements Listener { private final MultiversePortals plugin; private final PortalFiller filler; private final PortalManager portalManager; private final PlayerListenerHelper helper; - - public MVPPlayerListener(MultiversePortals plugin, PlayerListenerHelper helper) { + private final LocationManipulation locationManipulation; + private final WorldManager worldManager; + private final BlockSafety blockSafety; + private final MVEconomist economist; + + @Inject + MVPPlayerListener( + @NotNull MultiversePortals plugin, + @NotNull PlayerListenerHelper helper, + @NotNull PortalManager portalManager, + @NotNull PortalFiller filler, + @NotNull LocationManipulation locationManipulation, + @NotNull WorldManager worldManager, + @NotNull BlockSafety blockSafety, + @NotNull MVEconomist economist) { this.plugin = plugin; this.helper = helper; - this.portalManager = plugin.getPortalManager(); - this.filler = new PortalFiller(plugin.getCore()); + this.portalManager = portalManager; + this.filler = filler; + this.locationManipulation = locationManipulation; + this.worldManager = worldManager; + this.blockSafety = blockSafety; + this.economist = economist; } @EventHandler @@ -143,7 +162,7 @@ public void playerInteract(PlayerInteractEvent event) { // Portal lighting stuff if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getMaterial() == Material.FLINT_AND_STEEL) { // They're lighting somethin' - Logging.finer("Player is lighting block: " + this.plugin.getCore().getLocationManipulation().strCoordsRaw(event.getClickedBlock().getLocation())); + Logging.finer("Player is lighting block: " + this.locationManipulation.strCoordsRaw(event.getClickedBlock().getLocation())); PortalPlayerSession ps = this.plugin.getPortalSession(event.getPlayer()); Location translatedLocation = this.getTranslatedLocation(event.getClickedBlock(), event.getBlockFace()); if (!portalManager.isPortal(translatedLocation)) { @@ -153,7 +172,7 @@ public void playerInteract(PlayerInteractEvent event) { if (event.getItem() == null) { return; } - if (!this.plugin.getCore().getMVPerms().hasPermission(event.getPlayer(), "multiverse.portal.create", true)) { + if (!event.getPlayer().hasPermission("multiverse.portal.create")) { return; } Material inHand = event.getItem().getType(); @@ -195,16 +214,16 @@ public void playerInteract(PlayerInteractEvent event) { WorldEditConnection worldEdit = plugin.getWorldEditConnection(); if ((worldEdit != null && worldEdit.isConnected()) || event.getPlayer().getItemInHand().getType() != itemType - || !this.plugin.getCore().getMVPerms().hasPermission(event.getPlayer(), "multiverse.portal.create", true) + || !event.getPlayer().hasPermission("multiverse.portal.create") || event.getHand() != EquipmentSlot.HAND) { return; } if (event.getAction() == Action.LEFT_CLICK_BLOCK) { - MultiverseWorld world = this.plugin.getCore().getMVWorldManager().getMVWorld(event.getPlayer().getWorld().getName()); + LoadedMultiverseWorld world = this.worldManager.getLoadedWorld(event.getPlayer().getWorld().getName()).getOrNull(); event.setCancelled(this.plugin.getPortalSession(event.getPlayer()).setLeftClickSelection(event.getClickedBlock().getLocation().toVector(), world)); } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { - MultiverseWorld world = this.plugin.getCore().getMVWorldManager().getMVWorld(event.getPlayer().getWorld().getName()); + LoadedMultiverseWorld world = this.worldManager.getLoadedWorld(event.getPlayer().getWorld().getName()).getOrNull(); event.setCancelled(this.plugin.getPortalSession(event.getPlayer()).setRightClickSelection(event.getClickedBlock().getLocation().toVector(), world)); } } @@ -224,25 +243,24 @@ public void playerPortal(PlayerPortalEvent event) { return; } Logging.finer("onPlayerPortal called!"); - PortalManager pm = this.plugin.getPortalManager(); Location playerPortalLoc = event.getPlayer().getLocation(); // Determine if we're in a portal - MVPortal portal = pm.getPortal(event.getPlayer(), playerPortalLoc, false); + MVPortal portal = portalManager.getPortal(event.getPlayer(), playerPortalLoc, false); Player p = event.getPlayer(); // Even if the location was null, we still have to see if // someone wasn't exactly on (because they can do this). if (portal == null) { // Check around the player to make sure - playerPortalLoc = this.plugin.getCore().getSafeTTeleporter().findPortalBlockNextTo(event.getFrom()); + playerPortalLoc = this.blockSafety.findPortalBlockNextTo(event.getFrom()); if (playerPortalLoc != null) { Logging.finer("Player was outside of portal, The location has been successfully translated."); - portal = pm.getPortal(event.getPlayer(), playerPortalLoc, false); + portal = portalManager.getPortal(event.getPlayer(), playerPortalLoc, false); } } if (portal != null) { Logging.finer("There was a portal found!"); - MVDestination portalDest = portal.getDestination(); - if (portalDest != null && !(portalDest instanceof InvalidDestination)) { + DestinationInstance portalDest = portal.getDestination(); + if (portalDest != null) { // this is a valid MV Portal, so we'll cancel the event event.setCancelled(true); @@ -251,52 +269,38 @@ public void playerPortal(PlayerPortalEvent event) { return; } - Location destLocation = portalDest.getLocation(event.getPlayer()); + Location destLocation = portalDest.getLocation(event.getPlayer()).getOrNull(); if (destLocation == null) { Logging.fine("Unable to teleport player because destination is null!"); return; } - if (!this.plugin.getCore().getMVWorldManager().isMVWorld(destLocation.getWorld())) { + if (!this.worldManager.isLoadedWorld(destLocation.getWorld())) { Logging.fine("Unable to teleport player because the destination world is not managed by Multiverse!"); return; } event.setTo(destLocation); - if (portalDest.useSafeTeleporter()) { - SafeTTeleporter teleporter = this.plugin.getCore().getSafeTTeleporter(); - event.setTo(teleporter.getSafeLocation(event.getPlayer(), portalDest)); + if (portalDest.checkTeleportSafety()) { + event.setTo(blockSafety.getSafeLocation(portalDest.getLocation(event.getPlayer()).getOrNull())); } PortalPlayerSession ps = this.plugin.getPortalSession(event.getPlayer()); - if (portal.getHandlerScript() != null && !portal.getHandlerScript().isEmpty()) { - try { - if (helper.scriptPortal(event.getPlayer(), portalDest, portal, ps)) { - event.getPlayer().teleport(event.getTo()); - } - return; - } catch (IllegalStateException ignore) { - // Portal not handled by script - } - } if (ps.checkAndSendCooldownMessage()) { Logging.fine("Player denied teleportation due to cooldown."); return; } // If they're using Access and they don't have permission and they're NOT exempt, return, they're not allowed to tp. // No longer checking exemption status - if (MultiversePortals.EnforcePortalAccess && !this.plugin.getCore().getMVPerms().hasPermission(event.getPlayer(), portal.getPermission().getName(), true)) { + if (MultiversePortals.EnforcePortalAccess && !event.getPlayer().hasPermission(portal.getPermission())) { this.helper.stateFailure(p.getDisplayName(), portal.getName()); return; } - MVPTravelAgent agent = new MVPTravelAgent(this.plugin.getCore(), portalDest, event.getPlayer()); - boolean shouldPay = false; double price = portal.getPrice(); Material currency = portal.getCurrency(); - MVEconomist economist = plugin.getCore().getEconomist(); // Stop the player if the portal costs and they can't pay if (price != 0D && !p.hasPermission(portal.getExempt())) { @@ -308,8 +312,7 @@ public void playerPortal(PlayerPortalEvent event) { } } - agent.setPortalEventTravelAgent(event); - MVPortalEvent portalEvent = new MVPortalEvent(portalDest, event.getPlayer(), agent, portal); + MVPortalEvent portalEvent = new MVPortalEvent(portalDest, event.getPlayer(), portal); this.plugin.getServer().getPluginManager().callEvent(portalEvent); if (portalEvent.isCancelled()) { diff --git a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerMoveListener.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPlayerMoveListener.java similarity index 67% rename from src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerMoveListener.java rename to src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPlayerMoveListener.java index 8818714..039ac99 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPlayerMoveListener.java +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPlayerMoveListener.java @@ -5,39 +5,52 @@ * with this project */ -package com.onarandombox.MultiversePortals.listeners; - -import java.util.Date; -import java.util.logging.Level; +package org.mvplugins.multiverse.portals.listeners; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.api.MVDestination; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.destination.InvalidDestination; -import com.onarandombox.MultiverseCore.utils.MVEconomist; -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.MultiversePortals; -import com.onarandombox.MultiversePortals.PortalPlayerSession; -import com.onarandombox.MultiversePortals.enums.MoveType; -import com.onarandombox.MultiversePortals.event.MVPortalEvent; +import org.bukkit.event.Listener; +import org.mvplugins.multiverse.core.destination.DestinationInstance; +import org.mvplugins.multiverse.core.economy.MVEconomist; +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; +import org.mvplugins.multiverse.portals.MVPortal; +import org.mvplugins.multiverse.portals.MultiversePortals; +import org.mvplugins.multiverse.portals.PortalPlayerSession; +import org.mvplugins.multiverse.portals.enums.MoveType; +import org.mvplugins.multiverse.portals.event.MVPortalEvent; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.player.PlayerMoveEvent; +import org.mvplugins.multiverse.portals.utils.PortalManager; +@Service public class MVPPlayerMoveListener implements Listener { - private MultiversePortals plugin; - private PlayerListenerHelper helper; - - public MVPPlayerMoveListener(MultiversePortals plugin, PlayerListenerHelper helper) { + private final MultiversePortals plugin; + private final PlayerListenerHelper helper; + private final PortalManager portalManager; + private final WorldManager worldManager; + private final MVEconomist economist; + + @Inject + MVPPlayerMoveListener( + @NotNull MultiversePortals plugin, + @NotNull PlayerListenerHelper helper, + @NotNull PortalManager portalManager, + @NotNull WorldManager worldManager, + @NotNull MVEconomist economist) { this.plugin = plugin; this.helper = helper; + this.portalManager = portalManager; + this.worldManager = worldManager; + this.economist = economist; } @EventHandler(priority = EventPriority.LOW) @@ -53,12 +66,12 @@ public void blockFromTo(BlockFromToEvent event) { } // If lava/something else is trying to flow in... - if (plugin.getPortalManager().isPortal(event.getToBlock().getLocation())) { + if (portalManager.isPortal(event.getToBlock().getLocation())) { event.setCancelled(true); return; } // If something is trying to flow out, stop that too, unless bucketFilling has been disabled - if (plugin.getPortalManager().isPortal(event.getBlock().getLocation()) && MultiversePortals.bucketFilling) { + if (portalManager.isPortal(event.getBlock().getLocation()) && MultiversePortals.bucketFilling) { event.setCancelled(true); } } @@ -87,24 +100,20 @@ public void playerMove(PlayerMoveEvent event) { && ps.doTeleportPlayer(MoveType.PLAYER_MOVE) && !ps.showDebugInfo()) { - MVDestination d = portal.getDestination(); + DestinationInstance d = portal.getDestination(); if (d == null) { - return; - } - p.setFallDistance(0); - - if (d instanceof InvalidDestination) { Logging.fine("Invalid Destination!"); return; } + p.setFallDistance(0); - Location destLocation = d.getLocation(p); + Location destLocation = d.getLocation(p).getOrNull(); if (destLocation == null) { Logging.fine("Unable to teleport player because destination is null!"); return; } - if (!this.plugin.getCore().getMVWorldManager().isMVWorld(destLocation.getWorld())) { + if (!this.worldManager.isLoadedWorld(destLocation.getWorld())) { Logging.fine("Unable to teleport player because the destination world is not managed by Multiverse!"); return; } @@ -112,40 +121,23 @@ public void playerMove(PlayerMoveEvent event) { p.sendMessage("This portal's frame is made of an " + ChatColor.RED + "incorrect material. You should exit it now."); return; } - if (portal.getHandlerScript() != null && !portal.getHandlerScript().isEmpty()) { - if (plugin.getCore().getScriptAPI() != null) { - try { - if (helper.scriptPortal(event.getPlayer(), d, portal, ps)) { - // Portal handled by script - helper.performTeleport(event.getPlayer(), event.getTo(), ps, d); - } - return; - } catch (IllegalStateException ignore) { - // Portal not handled by script - } - } else { - Logging.warning("Buscript wasn't initialized, so we can't use scripts!"); - } - } if (ps.checkAndSendCooldownMessage()) { return; } // If they're using Access and they don't have permission and they're NOT excempt, return, they're not allowed to tp. // No longer checking exemption status - if (MultiversePortals.EnforcePortalAccess && !this.plugin.getCore().getMVPerms().hasPermission(event.getPlayer(), portal.getPermission().getName(), true)) { + if (MultiversePortals.EnforcePortalAccess && !event.getPlayer().hasPermission(portal.getPermission())) { this.helper.stateFailure(p.getDisplayName(), portal.getName()); return; } - MVEconomist economist = plugin.getCore().getEconomist(); double price = portal.getPrice(); Material currency = portal.getCurrency(); if (price != 0D && !p.hasPermission(portal.getExempt())) { if (price < 0D || economist.isPlayerWealthyEnough(p, price, currency)) { // call event for other plugins - MVPTravelAgent agent = new MVPTravelAgent(this.plugin.getCore(), d, event.getPlayer()); - MVPortalEvent portalEvent = new MVPortalEvent(d, event.getPlayer(), agent, portal); + MVPortalEvent portalEvent = new MVPortalEvent(d, event.getPlayer(), portal); this.plugin.getServer().getPluginManager().callEvent(portalEvent); if (!portalEvent.isCancelled()) { if (price < 0D) { @@ -165,8 +157,7 @@ public void playerMove(PlayerMoveEvent event) { } } else { // call event for other plugins - MVPTravelAgent agent = new MVPTravelAgent(this.plugin.getCore(), d, event.getPlayer()); - MVPortalEvent portalEvent = new MVPortalEvent(d, event.getPlayer(), agent, portal); + MVPortalEvent portalEvent = new MVPortalEvent(d, event.getPlayer(), portal); this.plugin.getServer().getPluginManager().callEvent(portalEvent); if (!portalEvent.isCancelled()) { helper.performTeleport(event.getPlayer(), event.getTo(), ps, d); diff --git a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPluginListener.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPluginListener.java similarity index 73% rename from src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPluginListener.java rename to src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPluginListener.java index 3659e83..400bc9f 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPPluginListener.java +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPluginListener.java @@ -5,23 +5,25 @@ * with this project */ -package com.onarandombox.MultiversePortals.listeners; +package org.mvplugins.multiverse.portals.listeners; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiversePortals.MultiversePortals; +import org.mvplugins.multiverse.core.MultiverseCore; +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.portals.MultiversePortals; import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; -import java.util.logging.Level; +@Service +public class MVPPluginListener implements PortalsListener { -public class MVPPluginListener implements Listener { + private final MultiversePortals plugin; - private MultiversePortals plugin; - - public MVPPluginListener(MultiversePortals plugin) { + @Inject + MVPPluginListener(@NotNull MultiversePortals plugin) { this.plugin = plugin; } diff --git a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPVehicleListener.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPVehicleListener.java similarity index 50% rename from src/main/java/com/onarandombox/MultiversePortals/listeners/MVPVehicleListener.java rename to src/main/java/org/mvplugins/multiverse/portals/listeners/MVPVehicleListener.java index 768d6b2..5322310 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/listeners/MVPVehicleListener.java +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPVehicleListener.java @@ -5,39 +5,50 @@ * with this project */ -package com.onarandombox.MultiversePortals.listeners; +package org.mvplugins.multiverse.portals.listeners; import java.util.Date; -import com.onarandombox.MultiversePortals.enums.MoveType; +import com.dumptruckman.minecraft.util.Logging; +import org.bukkit.event.Listener; +import org.mvplugins.multiverse.core.api.LocationManipulation; +import org.mvplugins.multiverse.core.destination.DestinationInstance; +import org.mvplugins.multiverse.core.teleportation.AsyncSafetyTeleporter; +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.portals.destination.PortalDestinationInstance; +import org.mvplugins.multiverse.portals.enums.MoveType; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Vehicle; import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; import org.bukkit.event.vehicle.VehicleMoveEvent; import org.bukkit.util.Vector; -import com.onarandombox.MultiverseCore.api.MVDestination; -import com.onarandombox.MultiverseCore.destination.InvalidDestination; -import com.onarandombox.MultiverseCore.enums.TeleportResult; -import com.onarandombox.MultiverseCore.api.LocationManipulation; -import com.onarandombox.MultiverseCore.api.SafeTTeleporter; -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.MultiversePortals; -import com.onarandombox.MultiversePortals.PortalPlayerSession; -import com.onarandombox.MultiversePortals.destination.PortalDestination; +import org.mvplugins.multiverse.portals.MVPortal; +import org.mvplugins.multiverse.portals.MultiversePortals; +import org.mvplugins.multiverse.portals.PortalPlayerSession; +import org.mvplugins.multiverse.portals.utils.PortalManager; +@Service public class MVPVehicleListener implements Listener { - private MultiversePortals plugin; - private LocationManipulation locationManipulation; - private SafeTTeleporter safeTTeleporter; - - public MVPVehicleListener(MultiversePortals plugin) { + private final MultiversePortals plugin; + private final PortalManager portalManager; + private final LocationManipulation locationManipulation; + private final AsyncSafetyTeleporter safetyTeleporter; + + @Inject + MVPVehicleListener( + @NotNull MultiversePortals plugin, + @NotNull PortalManager portalManager, + @NotNull LocationManipulation locationManipulation, + @NotNull AsyncSafetyTeleporter safetyTeleporter) { this.plugin = plugin; - this.locationManipulation = this.plugin.getCore().getLocationManipulation(); - this.safeTTeleporter = this.plugin.getCore().getSafeTTeleporter(); + this.portalManager = portalManager; + this.locationManipulation = locationManipulation; + this.safetyTeleporter = safetyTeleporter; } @EventHandler @@ -55,10 +66,10 @@ public void vehicleMove(VehicleMoveEvent event) { // Teleport the Player teleportVehicle(p, v, event.getTo()); } else { - MVPortal portal = this.plugin.getPortalManager().getPortal(event.getFrom()); + MVPortal portal = this.portalManager.getPortal(event.getFrom()); if ((portal != null) && (portal.getTeleportNonPlayers())) { - MVDestination dest = portal.getDestination(); - if (dest == null || dest instanceof InvalidDestination) + DestinationInstance dest = portal.getDestination(); + if (dest == null) return; // Check the portal's frame. @@ -67,11 +78,10 @@ public void vehicleMove(VehicleMoveEvent event) { } Vector vehicleVec = event.getVehicle().getVelocity(); - Location target = dest.getLocation(event.getVehicle()); - if (dest instanceof PortalDestination) { - PortalDestination pd = (PortalDestination) dest; + Location target = dest.getLocation(event.getVehicle()).getOrNull(); + if (dest instanceof PortalDestinationInstance pd) { // Translate the direction of travel. - vehicleVec = this.locationManipulation.getTranslatedVector(vehicleVec, pd.getOrientationString()); + vehicleVec = this.locationManipulation.getTranslatedVector(vehicleVec, pd.getDirection()); } this.setVehicleVelocity(vehicleVec, dest, event.getVehicle()); @@ -105,8 +115,8 @@ private boolean teleportVehicle(Player p, Vehicle v, Location to) { return false; } // TODO: Money - MVDestination d = portal.getDestination(); - if (d == null || d instanceof InvalidDestination) { + DestinationInstance d = portal.getDestination(); + if (d == null) { return false; } @@ -115,15 +125,13 @@ private boolean teleportVehicle(Player p, Vehicle v, Location to) { return false; } - Location l = d.getLocation(p); + Location l = d.getLocation(p).getOrNull(); Vector vehicleVec = v.getVelocity(); // 0 Yaw in dest = 0,X - if (d instanceof PortalDestination) { - PortalDestination pd = (PortalDestination) d; - + if (d instanceof PortalDestinationInstance pd) { // Translate the direction of travel. - vehicleVec = this.locationManipulation.getTranslatedVector(vehicleVec, pd.getOrientationString()); + vehicleVec = this.locationManipulation.getTranslatedVector(vehicleVec, pd.getDirection()); } // Set the velocity @@ -135,53 +143,57 @@ private boolean teleportVehicle(Player p, Vehicle v, Location to) { // The worlds are different! Ahhh! if (!l.getWorld().equals(p.getWorld())) { - return teleportVehicleSeperately(p, v, d, ps, this.safeTTeleporter); + return teleportVehicleSeperately(p, v, d, ps); } - if (this.safeTTeleporter.safelyTeleport(p, v, d) == TeleportResult.SUCCESS) { - ps.playerDidTeleport(to); - ps.setTeleportTime(new Date()); - } + this.safetyTeleporter.teleportSafely(p, v, d) + .onSuccess(() -> { + ps.playerDidTeleport(to); + ps.setTeleportTime(new Date()); + }); return true; } return false; } - private boolean teleportVehicleSeperately(Player p, Vehicle v, MVDestination to, PortalPlayerSession ps, SafeTTeleporter tp) { + private boolean teleportVehicleSeperately( + Player player, + Vehicle vehicle, + DestinationInstance destination, + PortalPlayerSession ps) { // Remove the player from the old one. - v.eject(); - Location toLocation = to.getLocation(v); + vehicle.eject(); + Location vehicleToLocation = destination.getLocation(vehicle).getOrNull(); + Location playerToLocation = destination.getLocation(player).getOrNull(); // Add an offset to ensure the player is 1 higher than where the cart was. - to.getLocation(p).add(0, .5, 0); - // If they didn't teleport, return false and place them back into their vehicle. - if (!(tp.safelyTeleport(p, p, to) == TeleportResult.SUCCESS)) { - v.setPassenger(p); - return false; - } - - // Now create a new vehicle: - Vehicle newVehicle = toLocation.getWorld().spawn(toLocation, v.getClass()); - - // Set the vehicle's velocity to ours. - this.setVehicleVelocity(v.getVelocity(), to, newVehicle); - - // Set the new player - newVehicle.setPassenger(p); - - // They did teleport. Let's delete the old vehicle. - v.remove(); + playerToLocation.add(0, 0.5, 0); + + safetyTeleporter.teleportSafely(player, player, destination) + .onSuccess(() -> { + // Now create a new vehicle: + Vehicle newVehicle = vehicleToLocation.getWorld().spawn(vehicleToLocation, vehicle.getClass()); + // Set the vehicle's velocity to ours. + this.setVehicleVelocity(vehicle.getVelocity(), destination, newVehicle); + // Set the new player + newVehicle.addPassenger(player); + // They did teleport. Let's delete the old vehicle. + vehicle.remove(); + }) + .onFailure(reason -> { + Logging.fine("Failed to teleport player '%s' to destination '%s'. Reason: %s", player.getDisplayName(), destination, reason); + vehicle.addPassenger(player); + }); return true; } - private void setVehicleVelocity(Vector calculated, MVDestination to, Vehicle newVehicle) { + private void setVehicleVelocity(Vector calculated, DestinationInstance to, Vehicle newVehicle) { // If the destination has a non-zero velocity, use that, // otherwise use the existing velocity, because velocities // are preserved through portals... duh. - if (!to.getVelocity().equals(new Vector(0, 0, 0))) { - newVehicle.setVelocity(to.getVelocity()); - } else { - newVehicle.setVelocity(calculated); - } + to.getVelocity(newVehicle) + .filter(v -> !v.equals(new Vector(0, 0, 0))) + .peek(newVehicle::setVelocity) + .onEmpty(() -> newVehicle.setVelocity(calculated)); } } diff --git a/src/main/java/org/mvplugins/multiverse/portals/listeners/PlayerListenerHelper.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/PlayerListenerHelper.java new file mode 100644 index 0000000..1271de5 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/PlayerListenerHelper.java @@ -0,0 +1,49 @@ +package org.mvplugins.multiverse.portals.listeners; + +import java.util.Date; + +import com.dumptruckman.minecraft.util.Logging; +import org.mvplugins.multiverse.core.destination.DestinationInstance; +import org.mvplugins.multiverse.core.teleportation.AsyncSafetyTeleporter; +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.portals.PortalPlayerSession; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +@Service +public class PlayerListenerHelper { + + private final AsyncSafetyTeleporter safetyTeleporter; + + @Inject + PlayerListenerHelper(@NotNull AsyncSafetyTeleporter safetyTeleporter) { + this.safetyTeleporter = safetyTeleporter; + } + + void stateSuccess(String playerName, String worldName) { + Logging.fine(String.format( + "MV-Portals is allowing Player '%s' to use the portal '%s'.", + playerName, worldName)); + } + + void stateFailure(String playerName, String portalName) { + Logging.fine(String.format( + "MV-Portals is DENYING Player '%s' access to use the portal '%s'.", + playerName, portalName)); + } + + void performTeleport(Player player, Location to, PortalPlayerSession ps, DestinationInstance destination) { + safetyTeleporter.teleportSafely(player, destination) + .onSuccess(() -> { + ps.playerDidTeleport(to); + ps.setTeleportTime(new Date()); + this.stateSuccess(player.getDisplayName(), destination.toString()); + }) + .onFailure(reason -> Logging.fine( + "Failed to teleport player '%s' to destination '%s'. Reason: %s", + player.getDisplayName(), destination, reason) + ); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/listeners/PortalsListener.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/PortalsListener.java new file mode 100644 index 0000000..03485c7 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/PortalsListener.java @@ -0,0 +1,11 @@ +package org.mvplugins.multiverse.portals.listeners; + +import org.bukkit.event.Listener; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Contract; + +/** + * Base implementation for all portal listeners + */ +@Contract +public interface PortalsListener extends Listener { +} diff --git a/src/main/java/com/onarandombox/MultiversePortals/utils/DisplayUtils.java b/src/main/java/org/mvplugins/multiverse/portals/utils/DisplayUtils.java similarity index 56% rename from src/main/java/com/onarandombox/MultiversePortals/utils/DisplayUtils.java rename to src/main/java/org/mvplugins/multiverse/portals/utils/DisplayUtils.java index 7063988..ba2e599 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/utils/DisplayUtils.java +++ b/src/main/java/org/mvplugins/multiverse/portals/utils/DisplayUtils.java @@ -1,16 +1,33 @@ -package com.onarandombox.MultiversePortals.utils; +package org.mvplugins.multiverse.portals.utils; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.MultiversePortals; +import org.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.core.economy.MVEconomist; +import org.mvplugins.multiverse.core.world.MultiverseWorld; +import org.mvplugins.multiverse.core.world.WorldManager; +import org.mvplugins.multiverse.external.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.portals.MVPortal; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +@Service public class DisplayUtils { - public static MultiversePortals plugin; + private final PortalManager portalManager; + private final WorldManager worldManager; + private final MVEconomist economist; - public static void showStaticInfo(CommandSender sender, MVPortal portal, String message) { + @Inject + DisplayUtils( + @NotNull PortalManager portalManager, + @NotNull WorldManager worldManager, + @NotNull MVEconomist economist) { + this.portalManager = portalManager; + this.worldManager = worldManager; + this.economist = economist; + } + + public void showStaticInfo(CommandSender sender, MVPortal portal, String message) { sender.sendMessage(ChatColor.AQUA + "--- " + message + ChatColor.DARK_AQUA + portal.getName() + ChatColor.AQUA + " ---"); String[] locParts = portal.getLocation().toString().split(":"); sender.sendMessage("Coords: " + ChatColor.GOLD + locParts[0] + ChatColor.WHITE + " to " + ChatColor.GOLD + locParts[1] + ChatColor.WHITE + " in " + ChatColor.GOLD + portal.getWorld().getName() ); @@ -20,14 +37,15 @@ public static void showStaticInfo(CommandSender sender, MVPortal portal, String String destination = portal.getDestination().toString(); String destType = portal.getDestination().getIdentifier(); if (destType.equals("w")) { - MultiverseWorld destWorld = plugin.getCore().getMVWorldManager().getMVWorld(destination); + MultiverseWorld destWorld = worldManager.getWorld(destination).getOrNull(); if (destWorld != null) { destination = "(World) " + ChatColor.DARK_AQUA + destination; } } if (destType.equals("p")) { - String targetWorldName = plugin.getPortalManager().getPortal(portal.getDestination().getName()).getWorld().getName(); - destination = "(Portal) " + ChatColor.DARK_AQUA + portal.getDestination().getName() + ChatColor.GRAY + " (" + targetWorldName + ")"; + // todo: I think should use instance check instead of destType prefix + // String targetWorldName = portalManager.getPortal(portal.getDestination().getName()).getWorld().getName(); + // destination = "(Portal) " + ChatColor.DARK_AQUA + portal.getDestination().getName() + ChatColor.GRAY + " (" + targetWorldName + ")"; } if (destType.equals("e")) { String destinationWorld = portal.getDestination().toString().split(":")[1]; @@ -51,11 +69,11 @@ public static void showStaticInfo(CommandSender sender, MVPortal portal, String } } - public static void showPortalPriceInfo(MVPortal portal, CommandSender sender) { + public void showPortalPriceInfo(MVPortal portal, CommandSender sender) { if (portal.getPrice() > 0D) { - sender.sendMessage("Price: " + ChatColor.GREEN + plugin.getCore().getEconomist().formatPrice(portal.getPrice(), portal.getCurrency())); + sender.sendMessage("Price: " + ChatColor.GREEN + economist.formatPrice(portal.getPrice(), portal.getCurrency())); } else if (portal.getPrice() < 0D) { - sender.sendMessage("Price: " + ChatColor.GREEN + plugin.getCore().getEconomist().formatPrice(-portal.getPrice(), portal.getCurrency())); + sender.sendMessage("Price: " + ChatColor.GREEN + economist.formatPrice(-portal.getPrice(), portal.getCurrency())); } else { sender.sendMessage("Price: " + ChatColor.GREEN + "FREE!"); } diff --git a/src/main/java/com/onarandombox/MultiversePortals/utils/MultiverseRegion.java b/src/main/java/org/mvplugins/multiverse/portals/utils/MultiverseRegion.java similarity index 79% rename from src/main/java/com/onarandombox/MultiversePortals/utils/MultiverseRegion.java rename to src/main/java/org/mvplugins/multiverse/portals/utils/MultiverseRegion.java index 34d081d..53a41b3 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/utils/MultiverseRegion.java +++ b/src/main/java/org/mvplugins/multiverse/portals/utils/MultiverseRegion.java @@ -1,93 +1,92 @@ -/* - * Multiverse 2 Copyright (c) the Multiverse Team 2011. - * Multiverse 2 is licensed under the BSD License. - * For more information please check the README.md file included - * with this project - */ - -package com.onarandombox.MultiversePortals.utils; - -import org.bukkit.Location; -import org.bukkit.util.Vector; - -import com.onarandombox.MultiverseCore.api.MultiverseWorld; - -/** - * This is a placeholder of good things to come... - * - * @author fernferret - */ -public class MultiverseRegion { - - private Vector min; - private Vector max; - private MultiverseWorld world; - - public MultiverseRegion(Object pos1, Object pos2, MultiverseWorld w) { - // Creating soft dependencies on WE - if (pos1 instanceof com.sk89q.worldedit.math.BlockVector3 && pos2 instanceof com.sk89q.worldedit.math.BlockVector3) { - com.sk89q.worldedit.math.BlockVector3 weV1 = (com.sk89q.worldedit.math.BlockVector3) pos1; - com.sk89q.worldedit.math.BlockVector3 weV2 = (com.sk89q.worldedit.math.BlockVector3) pos2; - Vector tmp1 = new Vector(weV1.getX(), weV1.getY(), weV1.getZ()); - Vector tmp2 = new Vector(weV2.getX(), weV2.getY(), weV2.getZ()); - this.min = Vector.getMinimum(tmp1, tmp2); - this.max = Vector.getMaximum(tmp1, tmp2); - this.world = w; - } - } - - public MultiverseRegion(Location loc1, Location loc2, MultiverseWorld w) { - this(loc1.toVector(), loc2.toVector(), w); - } - - public MultiverseRegion(Vector pos1, Vector pos2, MultiverseWorld w) { - this.min = Vector.getMinimum(pos1, pos2); - this.max = Vector.getMaximum(pos1, pos2); - this.world = w; - } - - public Vector getMinimumPoint() { - return this.min; - } - - public Vector getMaximumPoint() { - return this.max; - } - - public MultiverseWorld getWorld() { - return this.world; - } - - public int getWidth() { - return Math.abs((this.max.getBlockX() + 1) - this.min.getBlockX()); - } - - public int getHeight() { - return Math.abs((this.max.getBlockY() + 1) - this.min.getBlockY()); - } - - public int getDepth() { - return Math.abs((this.max.getBlockZ() + 1) - this.min.getBlockZ()); - } - - public int getArea() { - return this.getWidth() * this.getHeight() * this.getDepth(); - } - - public boolean containsVector(Location l) { - if (!this.world.getCBWorld().equals(l.getWorld())) { - return false; - } - if (!(l.getBlockX() >= min.getBlockX() && l.getBlockX() <= max.getBlockX())) { - return false; - } - if (!(l.getBlockZ() >= min.getBlockZ() && l.getBlockZ() <= max.getBlockZ())) { - return false; - } - if (!(l.getBlockY() >= min.getBlockY() && l.getBlockY() <= max.getBlockY())) { - return false; - } - return true; - } - -} +/* + * Multiverse 2 Copyright (c) the Multiverse Team 2011. + * Multiverse 2 is licensed under the BSD License. + * For more information please check the README.md file included + * with this project + */ + +package org.mvplugins.multiverse.portals.utils; + +import org.bukkit.Location; +import org.bukkit.util.Vector; +import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; + +/** + * This is a placeholder of good things to come... + * + * @author fernferret + */ +public class MultiverseRegion { + + private Vector min; + private Vector max; + private LoadedMultiverseWorld world; + + public MultiverseRegion(Object pos1, Object pos2, LoadedMultiverseWorld w) { + // Creating soft dependencies on WE + if (pos1 instanceof com.sk89q.worldedit.math.BlockVector3 && pos2 instanceof com.sk89q.worldedit.math.BlockVector3) { + com.sk89q.worldedit.math.BlockVector3 weV1 = (com.sk89q.worldedit.math.BlockVector3) pos1; + com.sk89q.worldedit.math.BlockVector3 weV2 = (com.sk89q.worldedit.math.BlockVector3) pos2; + Vector tmp1 = new Vector(weV1.getX(), weV1.getY(), weV1.getZ()); + Vector tmp2 = new Vector(weV2.getX(), weV2.getY(), weV2.getZ()); + this.min = Vector.getMinimum(tmp1, tmp2); + this.max = Vector.getMaximum(tmp1, tmp2); + this.world = w; + } + } + + public MultiverseRegion(Location loc1, Location loc2, LoadedMultiverseWorld w) { + this(loc1.toVector(), loc2.toVector(), w); + } + + public MultiverseRegion(Vector pos1, Vector pos2, LoadedMultiverseWorld w) { + this.min = Vector.getMinimum(pos1, pos2); + this.max = Vector.getMaximum(pos1, pos2); + this.world = w; + } + + public Vector getMinimumPoint() { + return this.min; + } + + public Vector getMaximumPoint() { + return this.max; + } + + public LoadedMultiverseWorld getWorld() { + return this.world; + } + + public int getWidth() { + return Math.abs((this.max.getBlockX() + 1) - this.min.getBlockX()); + } + + public int getHeight() { + return Math.abs((this.max.getBlockY() + 1) - this.min.getBlockY()); + } + + public int getDepth() { + return Math.abs((this.max.getBlockZ() + 1) - this.min.getBlockZ()); + } + + public int getArea() { + return this.getWidth() * this.getHeight() * this.getDepth(); + } + + public boolean containsVector(Location l) { + if (!this.world.getBukkitWorld().map(w -> w.equals(l.getWorld())).getOrElse(false)) { + return false; + } + if (!(l.getBlockX() >= min.getBlockX() && l.getBlockX() <= max.getBlockX())) { + return false; + } + if (!(l.getBlockZ() >= min.getBlockZ() && l.getBlockZ() <= max.getBlockZ())) { + return false; + } + if (!(l.getBlockY() >= min.getBlockY() && l.getBlockY() <= max.getBlockY())) { + return false; + } + return true; + } + +} diff --git a/src/main/java/com/onarandombox/MultiversePortals/utils/PortalFiller.java b/src/main/java/org/mvplugins/multiverse/portals/utils/PortalFiller.java similarity index 81% rename from src/main/java/com/onarandombox/MultiversePortals/utils/PortalFiller.java rename to src/main/java/org/mvplugins/multiverse/portals/utils/PortalFiller.java index f509efc..0d88417 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/utils/PortalFiller.java +++ b/src/main/java/org/mvplugins/multiverse/portals/utils/PortalFiller.java @@ -5,9 +5,7 @@ * with this project */ -package com.onarandombox.MultiversePortals.utils; - -import java.util.logging.Level; +package org.mvplugins.multiverse.portals.utils; import com.dumptruckman.minecraft.util.Logging; import org.bukkit.Axis; @@ -18,14 +16,19 @@ import org.bukkit.block.data.Orientable; import org.bukkit.entity.Player; -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiversePortals.MVPortal; +import org.mvplugins.multiverse.core.api.LocationManipulation; +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.portals.MVPortal; +@Service public class PortalFiller { - private MultiverseCore plugin; + private final LocationManipulation locationManipulation; - public PortalFiller(MultiverseCore plugin) { - this.plugin = plugin; + @Inject + PortalFiller(@NotNull LocationManipulation locationManipulation) { + this.locationManipulation = locationManipulation; } public boolean fillRegion(MultiverseRegion r, Location l, Material type, Player player) { @@ -83,7 +86,7 @@ private void doFill(Block newLoc, int useX, int useZ, MultiverseRegion r, Materi if (!r.containsVector(tmpLoc.getLocation())) { return; } - Logging.finest("Moving Right/Left: " + this.plugin.getLocationManipulation().strCoordsRaw(tmpLoc.getLocation())); + Logging.finest("Moving Right/Left: " + this.locationManipulation.strCoordsRaw(tmpLoc.getLocation())); doFill(tmpLoc, useX, useZ, r, type); } if (isValidPortalRegion(newLoc.getRelative(useX * 0, 1, useZ * 0).getLocation(), type)) { @@ -91,7 +94,7 @@ private void doFill(Block newLoc, int useX, int useZ, MultiverseRegion r, Materi if (!r.containsVector(tmpLoc.getLocation())) { return; } - Logging.finest("Moving Up" + this.plugin.getLocationManipulation().strCoordsRaw(tmpLoc.getLocation())); + Logging.finest("Moving Up" + this.locationManipulation.strCoordsRaw(tmpLoc.getLocation())); doFill(tmpLoc, useX, useZ, r, type); } if (isValidPortalRegion(newLoc.getRelative(useX * -1, 0, useZ * -1).getLocation(), type)) { @@ -99,7 +102,7 @@ private void doFill(Block newLoc, int useX, int useZ, MultiverseRegion r, Materi if (!r.containsVector(tmpLoc.getLocation())) { return; } - Logging.finest("Moving Left/Right" + this.plugin.getLocationManipulation().strCoordsRaw(tmpLoc.getLocation())); + Logging.finest("Moving Left/Right" + this.locationManipulation.strCoordsRaw(tmpLoc.getLocation())); doFill(tmpLoc, useX, useZ, r, type); } if (isValidPortalRegion(newLoc.getRelative(useX * 0, -1, useZ * 0).getLocation(), type)) { @@ -107,7 +110,7 @@ private void doFill(Block newLoc, int useX, int useZ, MultiverseRegion r, Materi if (!r.containsVector(tmpLoc.getLocation())) { return; } - Logging.finest("Moving Down" + this.plugin.getLocationManipulation().strCoordsRaw(tmpLoc.getLocation())); + Logging.finest("Moving Down" + this.locationManipulation.strCoordsRaw(tmpLoc.getLocation())); doFill(tmpLoc, useX, useZ, r, type); } } diff --git a/src/main/java/com/onarandombox/MultiversePortals/utils/PortalManager.java b/src/main/java/org/mvplugins/multiverse/portals/utils/PortalManager.java similarity index 90% rename from src/main/java/com/onarandombox/MultiversePortals/utils/PortalManager.java rename to src/main/java/org/mvplugins/multiverse/portals/utils/PortalManager.java index c8e3048..38947f9 100644 --- a/src/main/java/com/onarandombox/MultiversePortals/utils/PortalManager.java +++ b/src/main/java/org/mvplugins/multiverse/portals/utils/PortalManager.java @@ -5,7 +5,7 @@ * with this project */ -package com.onarandombox.MultiversePortals.utils; +package org.mvplugins.multiverse.portals.utils; import java.util.ArrayList; import java.util.Collection; @@ -23,10 +23,14 @@ import org.bukkit.permissions.Permission; import org.bukkit.util.Vector; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiversePortals.MVPortal; -import com.onarandombox.MultiversePortals.MultiversePortals; -import com.onarandombox.MultiversePortals.PortalLocation; +import org.mvplugins.multiverse.core.world.MultiverseWorld; +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; +import org.mvplugins.multiverse.portals.MVPortal; +import org.mvplugins.multiverse.portals.MultiversePortals; +import org.mvplugins.multiverse.portals.PortalLocation; /** @@ -34,21 +38,25 @@ * * @author fernferret */ +@Service public class PortalManager { - private MultiversePortals plugin; - private Map portals; + private final MultiversePortals plugin; + private final WorldManager worldManager; + private final Map portals; // For each world, keep a map of chunk hashes (see hashChunk()) to lists of // portals in those chunks. - private Map>> worldChunkPortals; + private final Map>> worldChunkPortals; // getNearbyPortals() returns this instead of null. =) private static final Collection emptyPortalSet = new ArrayList(); - public PortalManager(MultiversePortals plugin) { + @Inject + PortalManager(@NotNull MultiversePortals plugin, @NotNull WorldManager worldManager) { this.plugin = plugin; - this.portals = new HashMap(); - this.worldChunkPortals = new HashMap>>(); + this.worldManager = worldManager; + this.portals = new HashMap<>(); + this.worldChunkPortals = new HashMap<>(); } /** @@ -74,11 +82,11 @@ public MVPortal getPortal(Player sender, Location l) { * @return A MVPortal if it's valid, null if not. */ public MVPortal getPortal(Player sender, Location l, boolean checkPermission) { - if (!this.plugin.getCore().getMVWorldManager().isMVWorld(l.getWorld().getName())) { + if (!this.worldManager.isLoadedWorld(l.getWorld().getName())) { return null; } - MultiverseWorld world = this.plugin.getCore().getMVWorldManager().getMVWorld(l.getWorld().getName()); + MultiverseWorld world = this.worldManager.getLoadedWorld(l.getWorld().getName()).getOrNull(); for (MVPortal portal : getNearbyPortals(world, l)) { // Ignore portals the player can't use. @@ -119,7 +127,7 @@ public boolean isPortal(Location l) { * @return Null if no portal found, otherwise the MVPortal at that location. */ public MVPortal getPortal(Location l) { - MultiverseWorld world = this.plugin.getCore().getMVWorldManager().getMVWorld(l.getWorld().getName()); + MultiverseWorld world = this.worldManager.getLoadedWorld(l.getWorld().getName()).getOrNull(); for (MVPortal portal : getNearbyPortals(world, l)) { MultiverseRegion r = portal.getLocation().getRegion(); if (r != null && r.containsVector(l)) { @@ -131,7 +139,7 @@ public MVPortal getPortal(Location l) { public boolean addPortal(MVPortal portal) { if (!this.portals.containsKey(portal.getName())) { - MultiverseWorld world = this.plugin.getCore().getMVWorldManager().getMVWorld(portal.getWorld()); + MultiverseWorld world = this.worldManager.getLoadedWorld(portal.getWorld()).getOrNull(); addUniquePortal(world, portal.getName(), portal); return true; } @@ -167,7 +175,7 @@ private MVPortal removePortal(String portalName, boolean removeFromConfigs, bool } MVPortal removed = this.portals.remove(portalName); - MultiverseWorld world = this.plugin.getCore().getMVWorldManager().getMVWorld(removed.getWorld()); + MultiverseWorld world = this.worldManager.getLoadedWorld(removed.getWorld()).getOrNull(); removeFromWorldChunkPortals(world, removed); removed.removePermission(); @@ -277,7 +285,7 @@ public MVPortal getPortal(String portalName) { * @return */ public MVPortal getPortal(String portalName, CommandSender sender) { - if (!this.plugin.getCore().getMVPerms().hasPermission(sender, "multiverse.portal.access." + portalName, true)) { + if (!sender.hasPermission("multiverse.portal.access." + portalName)) { return null; } return this.getPortal(portalName); From c72fe504ab005816c2bcabb4fe9d2e7c3d588cd4 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 21 Nov 2024 17:04:58 +0800 Subject: [PATCH 03/14] Fix bugs and add create, remove, wand command --- .../multiverse/portals/MVPortal.java | 9 +- .../multiverse/portals/MultiversePortals.java | 27 ++++-- .../portals/commands/CreateCommand.java | 93 +++++++++++++++++++ .../portals/commands/RemoveCommand.java | 51 ++++++++++ .../portals/commands/WandCommand.java | 83 +++++++++++++++++ .../portals/listeners/MVPPlayerListener.java | 5 +- src/main/resources/plugin.yml | 41 +------- 7 files changed, 259 insertions(+), 50 deletions(-) create mode 100644 src/main/java/org/mvplugins/multiverse/portals/commands/CreateCommand.java create mode 100644 src/main/java/org/mvplugins/multiverse/portals/commands/RemoveCommand.java create mode 100644 src/main/java/org/mvplugins/multiverse/portals/commands/WandCommand.java diff --git a/src/main/java/org/mvplugins/multiverse/portals/MVPortal.java b/src/main/java/org/mvplugins/multiverse/portals/MVPortal.java index 9c6e997..9f67ee1 100644 --- a/src/main/java/org/mvplugins/multiverse/portals/MVPortal.java +++ b/src/main/java/org/mvplugins/multiverse/portals/MVPortal.java @@ -284,11 +284,16 @@ private boolean setOwner(String owner) { } public boolean setDestination(String destinationString) { - this.destination = this.destinationsProvider.parseDestination(destinationString).getOrNull(); - if (this.destination == null) { + DestinationInstance newDestination = this.destinationsProvider.parseDestination(destinationString).getOrNull(); + return setDestination(newDestination); + } + + public boolean setDestination(DestinationInstance newDestination) { + if (newDestination == null) { Logging.warning("Portal " + this.name + " has an invalid DESTINATION!"); return false; } + this.destination = newDestination; this.config.set(this.portalConfigString + ".destination", this.destination.toString()); saveConfig(); return true; diff --git a/src/main/java/org/mvplugins/multiverse/portals/MultiversePortals.java b/src/main/java/org/mvplugins/multiverse/portals/MultiversePortals.java index 31ddc90..77b4dce 100644 --- a/src/main/java/org/mvplugins/multiverse/portals/MultiversePortals.java +++ b/src/main/java/org/mvplugins/multiverse/portals/MultiversePortals.java @@ -25,6 +25,7 @@ import com.dumptruckman.minecraft.util.Logging; 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.destination.DestinationsProvider; import org.mvplugins.multiverse.core.inject.PluginServiceLocator; @@ -33,6 +34,7 @@ import org.mvplugins.multiverse.external.jakarta.inject.Provider; import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; import org.mvplugins.multiverse.external.vavr.control.Try; +import org.mvplugins.multiverse.portals.commands.PortalsCommand; import org.mvplugins.multiverse.portals.destination.PortalDestination; import org.mvplugins.multiverse.portals.destination.RandomPortalDestination; import org.mvplugins.multiverse.portals.listeners.*; @@ -66,6 +68,10 @@ public class MultiversePortals extends JavaPlugin implements MVPlugin { private Provider portalManager; @Inject private Provider destinationsProvider; + @Inject + private Provider commandManager; + @Inject + private Provider mvCoreConfig; private FileConfiguration MVPPortalConfig; private FileConfiguration MVPConfig; @@ -115,7 +121,7 @@ public void onEnable() { initializeDependencyInjection(); - Logging.setDebugLevel(serviceLocator.getActiveService(MVCoreConfig.class).getGlobalDebug()); + Logging.setDebugLevel(mvCoreConfig.get().getGlobalDebug()); // Register ourselves with Core this.core.incrementPluginCount(); @@ -124,10 +130,10 @@ public void onEnable() { this.registerCommands(); // Ensure permissions are created - this.createDefaultPerms(); - - this.portalSessions = new HashMap(); + // todo: Should we still have this? Luckperms does the wildcards for us now + // this.createDefaultPerms(); + this.portalSessions = new HashMap<>(); this.destinationsProvider.get().registerDestination(this.serviceLocator.getService(PortalDestination.class)); this.destinationsProvider.get().registerDestination(this.serviceLocator.getService(RandomPortalDestination.class)); @@ -348,7 +354,13 @@ public void onDisable() { /** Register commands to Multiverse's CommandHandler so we get a super sexy single menu */ private void registerCommands() { - //todo (MV5 migrate): commands + Try.of(() -> commandManager.get()) + .andThenTry(commandManager -> serviceLocator.getAllServices(PortalsCommand.class) + .forEach(commandManager::registerCommand)) + .onFailure(e -> { + Logging.severe("Failed to register commands"); + e.printStackTrace(); + }); } /** @@ -369,9 +381,12 @@ public String getAuthors() { return authors.substring(2); } + /** + * {@inheritDoc} + */ @Override public PluginServiceLocator getServiceLocator() { - return null; + return serviceLocator; } /** diff --git a/src/main/java/org/mvplugins/multiverse/portals/commands/CreateCommand.java b/src/main/java/org/mvplugins/multiverse/portals/commands/CreateCommand.java new file mode 100644 index 0000000..ddc0409 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/commands/CreateCommand.java @@ -0,0 +1,93 @@ +package org.mvplugins.multiverse.portals.commands; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.core.destination.DestinationInstance; +import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; +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.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.portals.MVPortal; +import org.mvplugins.multiverse.portals.MultiversePortals; +import org.mvplugins.multiverse.portals.PortalLocation; +import org.mvplugins.multiverse.portals.PortalPlayerSession; +import org.mvplugins.multiverse.portals.utils.MultiverseRegion; +import org.mvplugins.multiverse.portals.utils.PortalManager; + +@Service +@CommandAlias("mvp") +public class CreateCommand extends PortalsCommand { + + private final MultiversePortals plugin; + private final PortalManager portalManager; + + @Inject + protected CreateCommand( + @NotNull MVCommandManager commandManager, + @NotNull MultiversePortals plugin, + @NotNull PortalManager portalManager) { + super(commandManager); + this.plugin = plugin; + this.portalManager = portalManager; + } + + @CommandAlias("mvpcreate|mvpc") + @Subcommand("create") + @CommandPermission("multiverse.portal.create") + @CommandCompletion("@empty @mvworlds|@destinations") + @Syntax(" ") + @Description("Creates a new portal, assuming you have a region selected.") + void onCreateCommand( + @Flags("resolve=issuerOnly") + Player player, + + @Flags("resolve=issuerOnly") + LoadedMultiverseWorld world, + + @Syntax("") + String portalName, + + @Syntax("") + DestinationInstance destination + ) { + // todo: maybe make a CommandContext for PortalPlayerSession + PortalPlayerSession ps = this.plugin.getPortalSession(player); + + MultiverseRegion region = ps.getSelectedRegion(); + if (region == null) { + return; + } + + if (!MVPortal.PORTAL_NAME_PATTERN.matcher(portalName).matches()) { + player.sendMessage(String.format("%sInvalid portal name. It must not contain dot or special characters.", ChatColor.RED)); + return; + } + + MVPortal portal = this.portalManager.getPortal(portalName); + PortalLocation location = new PortalLocation(region.getMinimumPoint(), region.getMaximumPoint(), world); + if (this.portalManager.addPortal(world, portalName, player.getName(), location)) { + player.sendMessage("New portal (" + ChatColor.DARK_AQUA + portalName + ChatColor.WHITE + ") created and selected!"); + // If the portal did not exist, ie: we're creating it. + // we have to re select it, because it would be null + portal = this.portalManager.getPortal(portalName); + + } else { + player.sendMessage("New portal (" + ChatColor.DARK_AQUA + portalName + ChatColor.WHITE + ") was NOT created!"); + player.sendMessage("It already existed and has been selected."); + } + + ps.selectPortal(portal); + portal.setDestination(destination); + + // todo: Automatically get exact destination from player location + // todo: Automatically get portal destination from player location + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/commands/RemoveCommand.java b/src/main/java/org/mvplugins/multiverse/portals/commands/RemoveCommand.java new file mode 100644 index 0000000..47a3dca --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/commands/RemoveCommand.java @@ -0,0 +1,51 @@ +package org.mvplugins.multiverse.portals.commands; + +import org.bukkit.ChatColor; +import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +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.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.portals.MVPortal; +import org.mvplugins.multiverse.portals.utils.PortalManager; + +@Service +@CommandAlias("mvp") +public class RemoveCommand extends PortalsCommand { + + private final PortalManager portalManager; + + @Inject + protected RemoveCommand(@NotNull MVCommandManager commandManager, @NotNull PortalManager portalManager) { + super(commandManager); + this.portalManager = portalManager; + } + + @CommandAlias("mvpremove|mvpr") + @Subcommand("remove") + @CommandPermission("multiverse.portal.remove") + @CommandCompletion("@empty") // todo: @mvportals CommandCompletion + @Syntax("") + @Description("Removes a existing portal.") + void onRemoveCommand( + MVCommandIssuer issuer, + + @Syntax("") + @Description("The name of the portal to remove.") + String portalName + ) { + if (!this.portalManager.isPortal(portalName)) { + issuer.sendMessage("The portal Portal " + ChatColor.DARK_AQUA + portalName + ChatColor.WHITE + " does NOT exist!"); + return; + } + + MVPortal portal = this.portalManager.removePortal(portalName, true); + issuer.sendMessage("Portal " + ChatColor.DARK_AQUA + portal.getName() + ChatColor.WHITE + " was removed successfully!"); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/commands/WandCommand.java b/src/main/java/org/mvplugins/multiverse/portals/commands/WandCommand.java new file mode 100644 index 0000000..27d0715 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/commands/WandCommand.java @@ -0,0 +1,83 @@ +package org.mvplugins.multiverse.portals.commands; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +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.Optional; +import org.mvplugins.multiverse.external.acf.commands.annotation.Single; +import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand; +import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax; +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.portals.MultiversePortals; +import org.mvplugins.multiverse.portals.WorldEditConnection; + +@Service +@CommandAlias("mvp") +public class WandCommand extends PortalsCommand { + + private final MultiversePortals plugin; + + @Inject + protected WandCommand(@NotNull MVCommandManager commandManager, @NotNull MultiversePortals plugin) { + super(commandManager); + this.plugin = plugin; + } + + @CommandAlias("mvpwand|mvpw") + @Subcommand("wand") + @CommandPermission("multiverse.portal.givewand") + @CommandCompletion("enable|disable|toggle") + @Syntax("[enable|disable|toggle]") + @Description("Gives you the wand that MV uses. This will only work if you are NOT using WorldEdit.") + void onWandCommand( + @Flags("resolve=issuerOnly") + Player player, + + @Optional + @Single + @Syntax("[enable|disable|toggle]") + @Description("Enable, disable, or toggle the wand.") + String action + ) { + if (action != null) { + if (action.equals("enable")) { + this.plugin.setWandEnabled(true); + } else if (action.equals("disable")) { + this.plugin.setWandEnabled(false); + } else if (action.equals("toggle")) { + this.plugin.setWandEnabled(!this.plugin.isWandEnabled()); + } else { + player.sendMessage(ChatColor.RED + "You must specify one of 'enable,' 'disable,' or 'toggle!'"); + } + return; + } + + WorldEditConnection worldEdit = plugin.getWorldEditConnection(); + if (worldEdit != null && worldEdit.isConnected()) { + player.sendMessage(ChatColor.GREEN + "Cool!" + ChatColor.WHITE + " You're using" + ChatColor.AQUA + " WorldEdit! "); + player.sendMessage("Just use " + ChatColor.GOLD + "the WorldEdit wand " + ChatColor.WHITE + "to perform portal selections!"); + return; + } + ItemStack wand = new ItemStack(plugin.getWandMaterial(), 1); + + if (player.getInventory().getItemInMainHand().getAmount() == 0) { + player.getInventory().setItemInMainHand(wand); + player.sendMessage("You have been given a " + ChatColor.GREEN + "Multiverse Portal Wand(" + wand.getType() + ")!"); + } else { + if (player.getInventory().addItem(wand).isEmpty()) { + player.sendMessage("A " + ChatColor.GREEN + "Multiverse Portal Wand(" + wand.getType() + ")" + ChatColor.WHITE + " has been placed in your inventory."); + } else { + player.sendMessage("Your Inventory is full. A " + ChatColor.GREEN + "Multiverse Portal Wand(" + wand.getType() + ")" + ChatColor.WHITE + " has been placed dropped nearby."); + player.getWorld().dropItemNaturally(player.getLocation(), wand); + } + } + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPlayerListener.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPlayerListener.java index d24bd1d..2f89ee9 100644 --- a/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPlayerListener.java +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPlayerListener.java @@ -32,7 +32,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketFillEvent; @@ -43,7 +42,7 @@ import org.bukkit.inventory.EquipmentSlot; @Service -public class MVPPlayerListener implements Listener { +public class MVPPlayerListener implements PortalsListener { private final MultiversePortals plugin; private final PortalFiller filler; @@ -213,7 +212,7 @@ public void playerInteract(PlayerInteractEvent event) { // Also return if this isn't the player's main hand WorldEditConnection worldEdit = plugin.getWorldEditConnection(); if ((worldEdit != null && worldEdit.isConnected()) - || event.getPlayer().getItemInHand().getType() != itemType + || event.getPlayer().getInventory().getItemInMainHand().getType() != itemType || !event.getPlayer().hasPermission("multiverse.portal.create") || event.getHand() != EquipmentSlot.HAND) { return; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e9af59a..75dfa42 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,44 +1,7 @@ name: Multiverse-Portals -main: com.onarandombox.MultiversePortals.MultiversePortals -authors: ['Rigby', 'fernferret'] +main: org.mvplugins.multiverse.portals.MultiversePortals +authors: ['Rigby', 'fernferret', 'benwoo1110'] version: ${version} api-version: 1.13 depend: ['Multiverse-Core'] softdepend: ['WorldEdit'] -commands: - mvp: - description: Generic Multiverse-Portals Command - usage: / - mvpc: - description: Generic Multiverse-Portals Command - usage: / - mvpcreate: - description: Generic Multiverse-Portals Command - usage: / - mvpl: - description: Generic Multiverse-Portals Command - usage: / - mvplist: - description: Generic Multiverse-Portals Command - usage: / - mvpm: - description: Generic Multiverse-Portals Command - usage: / - mvpmodify: - description: Generic Multiverse-Portals Command - usage: / - mvpms: - description: Generic Multiverse-Portals Command - usage: / - mvps: - description: Generic Multiverse-Portals Command - usage: / - mvpselect: - description: Generic Multiverse-Portals Command - usage: / - mvpr: - description: Generic Multiverse-Portals Command - usage: / - mvpremove: - description: Generic Multiverse-Portals Command - usage: / \ No newline at end of file From 12b932a7fa4acaff6e3ed1254e6c78af72753232 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 21 Nov 2024 22:36:52 +0800 Subject: [PATCH 04/14] Implement modify command and add autocomplete --- .../multiverse/portals/MultiversePortals.java | 9 +- .../portals/commands/ModifyCommand.java | 103 ++++++++++++++++++ .../portals/commands/RemoveCommand.java | 2 +- .../PortalsCommandCompletions.java | 36 ++++++ .../commandtools/PortalsCommandContexts.java | 72 ++++++++++++ 5 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/mvplugins/multiverse/portals/commands/ModifyCommand.java create mode 100644 src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandCompletions.java create mode 100644 src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandContexts.java diff --git a/src/main/java/org/mvplugins/multiverse/portals/MultiversePortals.java b/src/main/java/org/mvplugins/multiverse/portals/MultiversePortals.java index 77b4dce..1d7255e 100644 --- a/src/main/java/org/mvplugins/multiverse/portals/MultiversePortals.java +++ b/src/main/java/org/mvplugins/multiverse/portals/MultiversePortals.java @@ -35,6 +35,8 @@ import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; import org.mvplugins.multiverse.external.vavr.control.Try; import org.mvplugins.multiverse.portals.commands.PortalsCommand; +import org.mvplugins.multiverse.portals.commandtools.PortalsCommandCompletions; +import org.mvplugins.multiverse.portals.commandtools.PortalsCommandContexts; import org.mvplugins.multiverse.portals.destination.PortalDestination; import org.mvplugins.multiverse.portals.destination.RandomPortalDestination; import org.mvplugins.multiverse.portals.listeners.*; @@ -71,6 +73,10 @@ public class MultiversePortals extends JavaPlugin implements MVPlugin { @Inject private Provider commandManager; @Inject + private Provider portalsCommandCompletions; + @Inject + private Provider portalsCommandContexts; + @Inject private Provider mvCoreConfig; private FileConfiguration MVPPortalConfig; @@ -320,7 +326,6 @@ public void loadConfig() { } private List migrateFrameMaterials(ConfigurationSection config) { - //todo (MV5 migrate): re-add MaterialConverter return config.getList("framematerials", Collections.emptyList()).stream() .map(Object::toString) .map(MaterialConverter::stringToMaterial) @@ -355,6 +360,8 @@ public void onDisable() { /** Register commands to Multiverse's CommandHandler so we get a super sexy single menu */ private void registerCommands() { Try.of(() -> commandManager.get()) + .andThenTry(commandManager -> portalsCommandCompletions.get().registerCompletions(commandManager.getCommandCompletions())) + .andThenTry(commandManager -> portalsCommandContexts.get().registerContexts(commandManager.getCommandContexts())) .andThenTry(commandManager -> serviceLocator.getAllServices(PortalsCommand.class) .forEach(commandManager::registerCommand)) .onFailure(e -> { diff --git a/src/main/java/org/mvplugins/multiverse/portals/commands/ModifyCommand.java b/src/main/java/org/mvplugins/multiverse/portals/commands/ModifyCommand.java new file mode 100644 index 0000000..4958ece --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/commands/ModifyCommand.java @@ -0,0 +1,103 @@ +package org.mvplugins.multiverse.portals.commands; + +import com.dumptruckman.minecraft.util.Logging; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; +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.Flags; +import org.mvplugins.multiverse.external.acf.commands.annotation.Single; +import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand; +import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax; +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.portals.MVPortal; +import org.mvplugins.multiverse.portals.MultiversePortals; +import org.mvplugins.multiverse.portals.PortalLocation; +import org.mvplugins.multiverse.portals.PortalPlayerSession; +import org.mvplugins.multiverse.portals.enums.SetProperties; +import org.mvplugins.multiverse.portals.utils.MultiverseRegion; + +@Service +@CommandAlias("mvp") +public class ModifyCommand extends PortalsCommand { + + private final MultiversePortals plugin; + private final WorldManager worldManager; + + @Inject + protected ModifyCommand( + @NotNull MVCommandManager commandManager, + @NotNull MultiversePortals plugin, + @NotNull WorldManager worldManager) { + super(commandManager); + this.plugin = plugin; + this.worldManager = worldManager; + } + + @CommandAlias("mvpmodify|mvpm") + @Subcommand("modify") + @CommandPermission("multiverse.portal.modify") + @CommandCompletion("@mvportals @setproperties @empty") + @Syntax("[portal] ") + @Description("Allows you to modify all values that can be set.") + public void onModifyCommand( + MVCommandIssuer issuer, + + @Flags("resolve=issuerAware") + @Syntax("[portal]") + @Description("The portal to modify.") + MVPortal portal, + + @Syntax("") + @Description("The property to modify.") + SetProperties property, + + @Single + @Syntax("") + @Description("The value to set.") + String value + ) { + Logging.info("Modifying portal: " + portal.getName() + " property: " + property + " value: " + value); + // Simply chop off the rest, if they have loc, that's good enough! + if (property == SetProperties.loc || property == SetProperties.location) { + if (!issuer.isPlayer()) { + issuer.sendMessage("You must be a player to use location property!"); + return; + } + this.setLocation(portal, issuer.getPlayer()); + return; + } + String propertyString = property.toString().toLowerCase(); + if (this.setProperty(portal, propertyString, value)) { + issuer.sendMessage("Property " + property + " of Portal " + ChatColor.YELLOW + portal.getName() + ChatColor.GREEN + " was set to " + ChatColor.AQUA + value); + } else { + issuer.sendMessage("Property " + property + " of Portal " + ChatColor.YELLOW + portal.getName() + ChatColor.RED + " was NOT set to " + ChatColor.AQUA + value); + if (propertyString.equalsIgnoreCase("dest") || propertyString.equalsIgnoreCase("destination")) { + issuer.sendMessage("Multiverse could not find the destination: " + ChatColor.GOLD + value); + } + } + } + + private boolean setProperty(MVPortal selectedPortal, String property, String value) { + return selectedPortal.setProperty(property, value); + } + + private void setLocation(MVPortal selectedPortal, Player player) { + PortalPlayerSession ps = this.plugin.getPortalSession(player); + MultiverseRegion r = ps.getSelectedRegion(); + if (r != null) { + LoadedMultiverseWorld world = this.worldManager.getLoadedWorld(player.getWorld().getName()).getOrNull(); + PortalLocation location = new PortalLocation(r.getMinimumPoint(), r.getMaximumPoint(), world); + selectedPortal.setPortalLocation(location); + player.sendMessage("Portal location has been set to your " + ChatColor.GREEN + "selection" + ChatColor.WHITE + "!"); + } + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/commands/RemoveCommand.java b/src/main/java/org/mvplugins/multiverse/portals/commands/RemoveCommand.java index 47a3dca..fdbef56 100644 --- a/src/main/java/org/mvplugins/multiverse/portals/commands/RemoveCommand.java +++ b/src/main/java/org/mvplugins/multiverse/portals/commands/RemoveCommand.java @@ -30,7 +30,7 @@ protected RemoveCommand(@NotNull MVCommandManager commandManager, @NotNull Porta @CommandAlias("mvpremove|mvpr") @Subcommand("remove") @CommandPermission("multiverse.portal.remove") - @CommandCompletion("@empty") // todo: @mvportals CommandCompletion + @CommandCompletion("@mvportals") @Syntax("") @Description("Removes a existing portal.") void onRemoveCommand( diff --git a/src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandCompletions.java b/src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandCompletions.java new file mode 100644 index 0000000..b928ce1 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandCompletions.java @@ -0,0 +1,36 @@ +package org.mvplugins.multiverse.portals.commandtools; + +import org.mvplugins.multiverse.core.commandtools.MVCommandCompletions; +import org.mvplugins.multiverse.external.acf.commands.BukkitCommandCompletionContext; +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.portals.MVPortal; +import org.mvplugins.multiverse.portals.enums.SetProperties; +import org.mvplugins.multiverse.portals.utils.PortalManager; + +import java.util.Collection; + +@Service +public class PortalsCommandCompletions { + + private final PortalManager portalManager; + + @Inject + PortalsCommandCompletions(@NotNull PortalManager portalManager) { + this.portalManager = portalManager; + } + + public void registerCompletions(MVCommandCompletions commandCompletions) { + commandCompletions.registerAsyncCompletion("mvportals", this::suggestPortals); + commandCompletions.registerStaticCompletion("setproperties", commandCompletions.suggestEnums(SetProperties.class)); + + commandCompletions.setDefaultCompletion("mvportals", MVPortal.class); + } + + private Collection suggestPortals(BukkitCommandCompletionContext context) { + return this.portalManager.getPortals(context.getSender()).stream() + .map(MVPortal::getName) + .toList(); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandContexts.java b/src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandContexts.java new file mode 100644 index 0000000..e6b308c --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandContexts.java @@ -0,0 +1,72 @@ +package org.mvplugins.multiverse.portals.commandtools; + +import org.mvplugins.multiverse.core.commandtools.MVCommandContexts; +import org.mvplugins.multiverse.external.acf.commands.BukkitCommandExecutionContext; +import org.mvplugins.multiverse.external.acf.commands.InvalidCommandArgument; +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.portals.MVPortal; +import org.mvplugins.multiverse.portals.MultiversePortals; +import org.mvplugins.multiverse.portals.utils.PortalManager; + +@Service +public class PortalsCommandContexts { + + private final MultiversePortals plugin; + private final PortalManager portalManager; + + @Inject + PortalsCommandContexts(@NotNull MultiversePortals plugin, @NotNull PortalManager portalManager) { + this.plugin = plugin; + this.portalManager = portalManager; + } + + public void registerContexts(MVCommandContexts commandContexts) { + commandContexts.registerIssuerAwareContext(MVPortal.class, this::parseMVPortal); + } + + private MVPortal parseMVPortal(BukkitCommandExecutionContext context) { + String resolve = context.getFlagValue("resolve", ""); + + MVPortal playerSelectedPortal = context.getIssuer().isPlayer() + ? this.plugin.getPortalSession(context.getPlayer()).getSelectedPortal() + : null; + + if (resolve.equals("issuerOnly")) { + if (context.getIssuer().isPlayer() && playerSelectedPortal != null) { + return playerSelectedPortal; + } + if (context.isOptional()) { + return null; + } + throw new InvalidCommandArgument("This command can only be used by a player that has selected a portal with `/mvp select`."); + } + + String portalName = context.getFirstArg(); + MVPortal portal = this.portalManager.getPortal(portalName); + + if (resolve.equals("issuerAware")) { + if (portal != null) { + context.popFirstArg(); + return portal; + } + if (context.getIssuer().isPlayer() && playerSelectedPortal != null) { + return playerSelectedPortal; + } + if (context.isOptional()) { + return null; + } + throw new InvalidCommandArgument("Either this command can only be used by a player that has selected a portal with `/mvp select` or the portal '" + portalName + "' does not exist."); + } + + if (portal != null) { + context.popFirstArg(); + return portal; + } + if (context.isOptional()) { + return null; + } + throw new InvalidCommandArgument("Portal '" + portalName + "' does not exist."); + } +} From 5980d0f437e1f2921e41b3dad0def34f008b267c Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 22 Nov 2024 12:54:54 +0800 Subject: [PATCH 05/14] Add todo for mv5 core dependency Co-authored-by: Jeremy Wood --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 2ae36e7..6b230b0 100644 --- a/build.gradle +++ b/build.gradle @@ -41,6 +41,7 @@ dependencies { } // Core + // TODO update to correct version once we have it published implementation 'org.mvplugins.multiverse.core:multiverse-core:local' //WorldEdit From ef1c2d6d4037b85eff19fad0a632d4f883e3bd3a Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 22 Nov 2024 22:48:03 +0800 Subject: [PATCH 06/14] Fix relocation package path --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 6b230b0..9f6c7c4 100644 --- a/build.gradle +++ b/build.gradle @@ -126,8 +126,8 @@ 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.portals.util.MVPLogging' + relocate 'com.dumptruckman.minecraft.util.DebugLog', 'org.mvplugins.multiverse.portals.util.DebugFileLogger' configurations = [project.configurations.api] From b3225c1ce356011dc32c2b937a27c5f170e7d056 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Sat, 23 Nov 2024 16:27:53 +0800 Subject: [PATCH 07/14] Use temp repo for mv5 to build --- build.gradle | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 9f6c7c4..a1f57bf 100644 --- a/build.gradle +++ b/build.gradle @@ -32,6 +32,12 @@ repositories { name = 'enginehub' url = uri('https://maven.enginehub.org/repo/') } + + maven { + // todo: remove before mv5 release + name = 'benwoo1110' + url = uri('https://repo.c0ding.party/multiverse-beta') + } } dependencies { @@ -41,8 +47,7 @@ dependencies { } // Core - // TODO update to correct version once we have it published - implementation 'org.mvplugins.multiverse.core:multiverse-core:local' + implementation 'org.mvplugins.multiverse.core:multiverse-core:5.0.0-SNAPSHOT' //WorldEdit implementation('com.sk89q.worldedit:worldedit-bukkit:7.2.9') { From e52f3fd6365d831897f025c355131b1272b38fd7 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Sat, 23 Nov 2024 16:32:58 +0800 Subject: [PATCH 08/14] Use pr test workflow from MV5 instead of main --- .github/workflows/pr.test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.test.yml b/.github/workflows/pr.test.yml index 431a5ee..2a1f048 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-portals From 7db6523232f0efb1ff2df712cb294e52592da1f8 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 22 Nov 2024 22:47:34 +0800 Subject: [PATCH 09/14] Implement config, debug, info, list and select commands --- .../portals/commands/ConfigCommand.java | 98 ++++++++++++ .../portals/commands/DebugCommand.java | 54 +++++++ .../portals/commands/InfoCommand.java | 59 +++++++ .../portals/commands/ListCommand.java | 148 ++++++++++++++++++ .../portals/commands/SelectCommand.java | 63 ++++++++ .../PortalsCommandCompletions.java | 2 + .../commandtools/PortalsCommandContexts.java | 6 +- 7 files changed, 427 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/mvplugins/multiverse/portals/commands/ConfigCommand.java create mode 100644 src/main/java/org/mvplugins/multiverse/portals/commands/DebugCommand.java create mode 100644 src/main/java/org/mvplugins/multiverse/portals/commands/InfoCommand.java create mode 100644 src/main/java/org/mvplugins/multiverse/portals/commands/ListCommand.java create mode 100644 src/main/java/org/mvplugins/multiverse/portals/commands/SelectCommand.java diff --git a/src/main/java/org/mvplugins/multiverse/portals/commands/ConfigCommand.java b/src/main/java/org/mvplugins/multiverse/portals/commands/ConfigCommand.java new file mode 100644 index 0000000..523d107 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/commands/ConfigCommand.java @@ -0,0 +1,98 @@ +package org.mvplugins.multiverse.portals.commands; + +import org.bukkit.ChatColor; +import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +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.Single; +import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand; +import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax; +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.portals.MultiversePortals; +import org.mvplugins.multiverse.portals.enums.PortalConfigProperty; + +@Service +@CommandAlias("mvp") +public class ConfigCommand extends PortalsCommand { + + private final MultiversePortals plugin; + + @Inject + ConfigCommand(@NotNull MVCommandManager commandManager, @NotNull MultiversePortals plugin) { + super(commandManager); + this.plugin = plugin; + } + + @CommandAlias("mvpconfig|mvpconf") + @Subcommand("config|conf") + @CommandPermission("multiverse.portal.config") + @CommandCompletion("@portalconfigproperty @empty") + @Syntax(" ") + @Description("Allows you to set Global MV Portals Variables.") + void onConfigCommand( + @NotNull MVCommandIssuer issuer, + + @Optional + @Syntax("") + @Description("The property to set.") + PortalConfigProperty property, + + @Optional + @Single + @Syntax("") + @Description("The value to set.") + String value + ) { + if (property == null) { + String[] allProps = PortalConfigProperty.getAllValues().split(" "); + StringBuilder currentvals = new StringBuilder(); + for (String prop : allProps) { + currentvals.append(ChatColor.GREEN); + currentvals.append(prop); + currentvals.append(ChatColor.WHITE); + currentvals.append(" = "); + currentvals.append(ChatColor.GOLD); + currentvals.append(this.plugin.getMainConfig().get(prop, "NOT SET")); + currentvals.append(ChatColor.WHITE); + currentvals.append(", "); + } + issuer.sendMessage(currentvals.substring(0,currentvals.length() - 2)); + return; + } + + if (value == null) { + issuer.sendMessage(ChatColor.AQUA + property.name() + ChatColor.WHITE + " has value " + + ChatColor.GREEN + this.plugin.getMainConfig().get(property.name().toLowerCase())); + return; + } + + if (property.equals(PortalConfigProperty.wand) || property.equals(PortalConfigProperty.portalcooldown)) { + try { + this.plugin.getMainConfig().set(property.name(), Integer.parseInt(value)); + } catch (NumberFormatException e) { + issuer.sendMessage(ChatColor.RED + "Sorry, " + ChatColor.AQUA + property.name() + ChatColor.WHITE + " must be an integer!"); + return; + } + } else { + try { + this.plugin.getMainConfig().set(property.name().toLowerCase(), Boolean.parseBoolean(value)); + } catch (Exception e) { + issuer.sendMessage(ChatColor.RED + "Sorry, " + ChatColor.AQUA + property.name() + ChatColor.WHITE + " must be true or false!"); + return; + } + } + + if (this.plugin.saveMainConfig()) { + issuer.sendMessage(ChatColor.GREEN + "SUCCESS!" + ChatColor.WHITE + " Values were updated successfully!"); + this.plugin.reloadConfigs(false); + } else { + issuer.sendMessage(ChatColor.RED + "FAIL!" + ChatColor.WHITE + " Check your console for details!"); + } + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/commands/DebugCommand.java b/src/main/java/org/mvplugins/multiverse/portals/commands/DebugCommand.java new file mode 100644 index 0000000..75310ac --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/commands/DebugCommand.java @@ -0,0 +1,54 @@ +package org.mvplugins.multiverse.portals.commands; + +import org.bukkit.entity.Player; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +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.Optional; +import org.mvplugins.multiverse.external.acf.commands.annotation.Single; +import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand; +import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax; +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.portals.MultiversePortals; +import org.mvplugins.multiverse.portals.PortalPlayerSession; + +@Service +@CommandAlias("mvp") +public class DebugCommand extends PortalsCommand { + + private final MultiversePortals plugin; + + @Inject + DebugCommand(@NotNull MVCommandManager commandManager, @NotNull MultiversePortals plugin) { + super(commandManager); + this.plugin = plugin; + } + + @CommandAlias("mvpdebug|mvpd") + @Subcommand("debug") + @CommandPermission("multiverse.portal.debug") + @CommandCompletion("on|off") + @Syntax("[on|off]") + @Description("Instead of teleporting you to a place when you walk into a portal you will see the details about it. This command toggles.") + void onDebugCommand( + @Flags("resolve=issuerOnly") + Player player, + + @Optional + @Single + @Syntax("[on|off]") + String toggle + ) { + PortalPlayerSession ps = this.plugin.getPortalSession(player); + if (toggle != null) { + ps.setDebugMode(toggle.equalsIgnoreCase("on")); + return; + } + ps.setDebugMode(!ps.isDebugModeOn()); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/commands/InfoCommand.java b/src/main/java/org/mvplugins/multiverse/portals/commands/InfoCommand.java new file mode 100644 index 0000000..9eabe58 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/commands/InfoCommand.java @@ -0,0 +1,59 @@ +package org.mvplugins.multiverse.portals.commands; + +import org.bukkit.entity.Player; +import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +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.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.portals.MVPortal; +import org.mvplugins.multiverse.portals.MultiversePortals; +import org.mvplugins.multiverse.portals.utils.DisplayUtils; + +@Service +@CommandAlias("mvp") +public class InfoCommand extends PortalsCommand { + + private final MultiversePortals plugin; + private final DisplayUtils displayUtils; + + @Inject + InfoCommand( + @NotNull MVCommandManager commandManager, + @NotNull MultiversePortals plugin, + @NotNull DisplayUtils displayUtils + ) { + super(commandManager); + this.plugin = plugin; + this.displayUtils = displayUtils; + } + + @CommandAlias("mvpinfo|mvpi") + @Subcommand("info") + @CommandPermission("multiverse.portal.info") + @CommandCompletion("@mvportals") + @Syntax("[portal]") + @Description("Displays information about a portal.") + void onInfoCommand( + @NotNull MVCommandIssuer issuer, + + @Flags("resolve=issuerAware") + @Syntax("[portal]") + @Description("The portal to show info") + MVPortal portal + ) { + if(issuer.isPlayer()) { + Player p = issuer.getPlayer(); + this.plugin.getPortalSession(p).showDebugInfo(portal); + } else { + displayUtils.showStaticInfo(issuer.getIssuer(), portal, "Portal Info: "); + } + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/commands/ListCommand.java b/src/main/java/org/mvplugins/multiverse/portals/commands/ListCommand.java new file mode 100644 index 0000000..519a596 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/commands/ListCommand.java @@ -0,0 +1,148 @@ +package org.mvplugins.multiverse.portals.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +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.Default; +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.jakarta.inject.Inject; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.portals.MVPortal; +import org.mvplugins.multiverse.portals.utils.PortalManager; + +import java.util.ArrayList; +import java.util.List; + +@Service +@CommandAlias("mvp") +public class ListCommand extends PortalsCommand { + + private static final int ITEMS_PER_PAGE = 9; + + private final PortalManager portalManager; + private final WorldManager worldManager; + + @Inject + ListCommand(MVCommandManager commandManager, PortalManager portalManager, WorldManager worldManager) { + super(commandManager); + this.portalManager = portalManager; + this.worldManager = worldManager; + } + + @CommandAlias("mvplist|mvpl") + @Subcommand("list") + @CommandPermission("multiverse.portal.list") + @CommandCompletion("@empty @empty") + @Syntax("[filter/world] [page]") + @Description("Displays a listing of all portals that you can enter.") + void onListCommand( + @NotNull CommandSender sender, + + @Optional + @Syntax("[filter/world]") + @Description("Filter by name or world") + String filterOrWorld, + + @Default("1") + @Syntax("[page]") + @Description("Page to display") + int page + ) { + String filter = filterOrWorld; + + MultiverseWorld world = this.worldManager.getLoadedWorld(filter).getOrNull(); + if (world != null) { + filter = null; + } + + List portals = new ArrayList<>(getPortals(sender, world, filter, page)); + + if(portals.isEmpty() && filter == null) { + page = (int) Math.ceil(1F*getPortals(sender, world, filter).size()/ITEMS_PER_PAGE); + portals.addAll(getPortals(sender, world, filter, page)); + } + + String titleString = ChatColor.AQUA + String.valueOf(getPortals(sender, world, filter).size()) + " Portals"; + if (world != null) { + titleString += " in " + ChatColor.YELLOW + world.getAlias(); + } + if (filter != null) { + titleString += ChatColor.GOLD + " [" + filter + "]"; + } + + titleString += ChatColor.GOLD + " - Page " + page + "/" + (int) Math.ceil(1F*getPortals(sender, world, filter).size()/ITEMS_PER_PAGE); + sender.sendMessage(ChatColor.AQUA + "--- " + titleString + ChatColor.AQUA + " ---"); + + for(String portal : portals) { + sender.sendMessage(portal); + } + } + + private List getPortals(CommandSender sender, MultiverseWorld world, String filter) { + List portals = new ArrayList<>(); + if (filter == null) { + filter = ""; + } + for (MVPortal portal : (world == null) ? this.portalManager.getPortals(sender) : this.portalManager.getPortals(sender, world)) { + String destination = ""; + if(portal.getDestination() != null) { + destination = portal.getDestination().toString(); + String destType = portal.getDestination().getIdentifier(); + if(destType.equals("w")) { + MultiverseWorld destWorld = this.worldManager.getLoadedWorld(destination).getOrNull(); + if (destWorld != null) { + destination = "(World) " + ChatColor.DARK_AQUA + destination; + } + } + if (destType.equals("p")) { + // todo: I think should use instance check instead of destType prefix + // String targetWorldName = this.portalManager.getPortal(portal.getDestination().getName()).getWorld().getName(); + // destination = "(Portal) " + ChatColor.DARK_AQUA + portal.getDestination().getName() + ChatColor.GRAY + " (" + targetWorldName + ")"; + } + if (destType.equals("e")) { + String destinationWorld = portal.getDestination().toString().split(":")[1]; + String destPart = portal.getDestination().toString().split(":")[2]; + String[] locParts = destPart.split(","); + int x, y, z; + try { + x = (int) Double.parseDouble(locParts[0]); + y = (int) Double.parseDouble(locParts[1]); + z = (int) Double.parseDouble(locParts[2]); + } catch(NumberFormatException e) { + e.printStackTrace(); + continue; + } + if(destType.equals("i")) { + destination = ChatColor.RED + "Invalid destination"; + } + destination = "(Location) " + ChatColor.DARK_AQUA + destinationWorld + ", " + x + ", " + y + ", " + z; + } + } + + if (portal.getName().toLowerCase().contains(filter.toLowerCase()) || ( portal.getDestination() != null && destination.toLowerCase().contains(filter.toLowerCase()))) { + portals.add(ChatColor.YELLOW + portal.getName() + ((portal.getDestination() != null) ? (ChatColor.AQUA + " -> " + ChatColor.GOLD + destination) : "")); + } + } + java.util.Collections.sort(portals); + return portals; + } + + private List getPortals(CommandSender sender, MultiverseWorld world, String filter, int page) { + List portals = new ArrayList<>(); + for(int i = 0; i < getPortals(sender, world, filter).size(); i++) { + if((i >= (page* ITEMS_PER_PAGE)- ITEMS_PER_PAGE && i <= (page* ITEMS_PER_PAGE)-1)) { + portals.add(getPortals(sender, world, filter).get(i)); + } + } + return portals; + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/commands/SelectCommand.java b/src/main/java/org/mvplugins/multiverse/portals/commands/SelectCommand.java new file mode 100644 index 0000000..f23448b --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/portals/commands/SelectCommand.java @@ -0,0 +1,63 @@ +package org.mvplugins.multiverse.portals.commands; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +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.Optional; +import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand; +import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax; +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.portals.MVPortal; +import org.mvplugins.multiverse.portals.MultiversePortals; + +@Service +@CommandAlias("mvp") +public class SelectCommand extends PortalsCommand { + + private final MultiversePortals plugin; + + @Inject + SelectCommand(@NotNull MVCommandManager commandManager, @NotNull MultiversePortals plugin) { + super(commandManager); + this.plugin = plugin; + } + + @CommandAlias("mvpselect|mvps") + @Subcommand("select") + @CommandPermission("multiverse.portal.select,multiverse.portal.create") + @CommandCompletion("@mvportals") + @Syntax("") + @Description("Selects a portal so you can perform multiple modifications on it.") + void onSelectCommand( + @Flags("resolve=issuerOnly") + Player player, + + @Optional + @Syntax("") + @Description("The portal to select") + MVPortal portal + ) { + if (portal == null) { + MVPortal selected = this.plugin.getPortalSession(player).getSelectedPortal(); + if (this.plugin.getPortalSession(player).getSelectedPortal() == null) { + player.sendMessage("You have not selected a portal yet!"); + player.sendMessage("Use a " + ChatColor.GREEN + plugin.getWandMaterial() + ChatColor.WHITE + " to do so!"); + return; + } + player.sendMessage("You have selected: " + ChatColor.DARK_AQUA + selected.getName()); + return; + } + + this.plugin.getPortalSession(player).selectPortal(portal); + player.sendMessage("Portal: " + ChatColor.DARK_AQUA + portal.getName() + ChatColor.WHITE + " has been selected."); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandCompletions.java b/src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandCompletions.java index b928ce1..257a6fa 100644 --- a/src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandCompletions.java +++ b/src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandCompletions.java @@ -6,6 +6,7 @@ import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; import org.mvplugins.multiverse.portals.MVPortal; +import org.mvplugins.multiverse.portals.enums.PortalConfigProperty; import org.mvplugins.multiverse.portals.enums.SetProperties; import org.mvplugins.multiverse.portals.utils.PortalManager; @@ -24,6 +25,7 @@ public class PortalsCommandCompletions { public void registerCompletions(MVCommandCompletions commandCompletions) { commandCompletions.registerAsyncCompletion("mvportals", this::suggestPortals); commandCompletions.registerStaticCompletion("setproperties", commandCompletions.suggestEnums(SetProperties.class)); + commandCompletions.registerStaticCompletion("portalconfigproperty", commandCompletions.suggestEnums(PortalConfigProperty.class)); commandCompletions.setDefaultCompletion("mvportals", MVPortal.class); } diff --git a/src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandContexts.java b/src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandContexts.java index e6b308c..1085bef 100644 --- a/src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandContexts.java +++ b/src/main/java/org/mvplugins/multiverse/portals/commandtools/PortalsCommandContexts.java @@ -44,7 +44,7 @@ private MVPortal parseMVPortal(BukkitCommandExecutionContext context) { } String portalName = context.getFirstArg(); - MVPortal portal = this.portalManager.getPortal(portalName); + MVPortal portal = this.portalManager.getPortal(portalName, context.getSender()); if (resolve.equals("issuerAware")) { if (portal != null) { @@ -57,7 +57,7 @@ private MVPortal parseMVPortal(BukkitCommandExecutionContext context) { if (context.isOptional()) { return null; } - throw new InvalidCommandArgument("Either this command can only be used by a player that has selected a portal with `/mvp select` or the portal '" + portalName + "' does not exist."); + throw new InvalidCommandArgument("The portal '" + portalName + "' doesn't exist or you're not allowed to use it!"); } if (portal != null) { @@ -67,6 +67,6 @@ private MVPortal parseMVPortal(BukkitCommandExecutionContext context) { if (context.isOptional()) { return null; } - throw new InvalidCommandArgument("Portal '" + portalName + "' does not exist."); + throw new InvalidCommandArgument("The portal '" + portalName + "' doesn't exist or you're not allowed to use it!"); } } From 4c3b4c9a8a70c1b29ac2975a16df013d223fcd1d Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Sun, 24 Nov 2024 13:47:51 +0800 Subject: [PATCH 10/14] Update from using MVVersionEvent to MVDumpsDebugInfoEvent --- .../multiverse/portals/listeners/MVPCoreListener.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPCoreListener.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPCoreListener.java index d9c89e2..cd5bba3 100644 --- a/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPCoreListener.java +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPCoreListener.java @@ -13,8 +13,8 @@ import org.jetbrains.annotations.NotNull; 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.core.event.MVPlayerTouchedPortalEvent; -import org.mvplugins.multiverse.core.event.MVVersionEvent; import org.mvplugins.multiverse.external.jakarta.inject.Inject; import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; import org.mvplugins.multiverse.portals.MVPortal; @@ -40,13 +40,14 @@ public class MVPCoreListener implements PortalsListener { * @param event The Version event. */ @EventHandler - public void versionRequest(MVVersionEvent event) { - event.appendVersionInfo(this.plugin.getVersionInfo()); + public void dumpsDebugInfoRequest(MVDumpsDebugInfoEvent event) { + event.appendDebugInfo(this.plugin.getVersionInfo()); File configFile = new File(this.plugin.getDataFolder(), "config.yml"); File portalsFile = new File(this.plugin.getDataFolder(), "portals.yml"); - event.putDetailedVersionInfo("multiverse-portals/config.yml", configFile); - event.putDetailedVersionInfo("multiverse-portals/portals.yml", portalsFile); + event.putDetailedDebugInfo("multiverse-portals/config.yml", configFile); + event.putDetailedDebugInfo("multiverse-portals/portals.yml", portalsFile); } + /** * This method is called when Multiverse-Core wants to reload the configs. * @param event The Config Reload event. From 9890103c477e025357bf4478c6cd5525c12d8e5d Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Sun, 24 Nov 2024 13:48:15 +0800 Subject: [PATCH 11/14] Add temporary publishing repo --- build.gradle | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/build.gradle b/build.gradle index a1f57bf..5b374d6 100644 --- a/build.gradle +++ b/build.gradle @@ -97,6 +97,13 @@ publishing { password = System.getenv("GITHUB_TOKEN") } } + + maven { + // todo: remove before mv5 release + name = "multiverseBeta" + url = "https://repo.c0ding.party/multiverse-beta" + credentials(PasswordCredentials) + } } } From 7b3aee449b519173533d7ee40f959ef9928b7056 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Sun, 5 Jan 2025 11:36:35 +0800 Subject: [PATCH 12/14] Add check for unsafe portal destination --- .../portals/listeners/MVPPlayerListener.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPlayerListener.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPlayerListener.java index 2f89ee9..a8b5382 100644 --- a/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPlayerListener.java +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPPlayerListener.java @@ -279,10 +279,17 @@ public void playerPortal(PlayerPortalEvent event) { return; } - event.setTo(destLocation); if (portalDest.checkTeleportSafety()) { - event.setTo(blockSafety.getSafeLocation(portalDest.getLocation(event.getPlayer()).getOrNull())); + Location safeLocation = blockSafety.getSafeLocation(portalDest.getLocation(event.getPlayer()).getOrNull()); + if (safeLocation == null) { + event.setCancelled(true); + Logging.warning("Portal " + portal.getName() + " destination is not safe!"); + event.getPlayer().sendMessage(ChatColor.RED + "Portal " + portal.getName() + " destination is not safe!"); + return; + } + destLocation = safeLocation; } + event.setTo(destLocation); PortalPlayerSession ps = this.plugin.getPortalSession(event.getPlayer()); From cc2c23f153d8a7f9b08fa6e6930e950850312adb Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:38:49 +0800 Subject: [PATCH 13/14] Update to use new AsyncSafetyTeleporter api --- .../multiverse/portals/listeners/MVPVehicleListener.java | 4 ++-- .../multiverse/portals/listeners/PlayerListenerHelper.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPVehicleListener.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPVehicleListener.java index 5322310..7bec7ab 100644 --- a/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPVehicleListener.java +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPVehicleListener.java @@ -146,7 +146,7 @@ private boolean teleportVehicle(Player p, Vehicle v, Location to) { return teleportVehicleSeperately(p, v, d, ps); } - this.safetyTeleporter.teleportSafely(p, v, d) + this.safetyTeleporter.to(d).by(p).teleport(v) .onSuccess(() -> { ps.playerDidTeleport(to); ps.setTeleportTime(new Date()); @@ -168,7 +168,7 @@ private boolean teleportVehicleSeperately( // Add an offset to ensure the player is 1 higher than where the cart was. playerToLocation.add(0, 0.5, 0); - safetyTeleporter.teleportSafely(player, player, destination) + safetyTeleporter.to(destination).teleport(player) .onSuccess(() -> { // Now create a new vehicle: Vehicle newVehicle = vehicleToLocation.getWorld().spawn(vehicleToLocation, vehicle.getClass()); diff --git a/src/main/java/org/mvplugins/multiverse/portals/listeners/PlayerListenerHelper.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/PlayerListenerHelper.java index 1271de5..e10c610 100644 --- a/src/main/java/org/mvplugins/multiverse/portals/listeners/PlayerListenerHelper.java +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/PlayerListenerHelper.java @@ -35,7 +35,7 @@ void stateFailure(String playerName, String portalName) { } void performTeleport(Player player, Location to, PortalPlayerSession ps, DestinationInstance destination) { - safetyTeleporter.teleportSafely(player, destination) + safetyTeleporter.to(destination).teleport(player) .onSuccess(() -> { ps.playerDidTeleport(to); ps.setTeleportTime(new Date()); From d77237eb1ea66a65668a0527373abda14a831944 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Sun, 12 Jan 2025 22:40:09 +0800 Subject: [PATCH 14/14] Fix jetbrains notnull import issue --- .../multiverse/portals/listeners/MVPBlockListener.java | 2 +- .../mvplugins/multiverse/portals/listeners/MVPCoreListener.java | 2 +- .../org/mvplugins/multiverse/portals/utils/DisplayUtils.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPBlockListener.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPBlockListener.java index bd43abb..0afc4a9 100644 --- a/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPBlockListener.java +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPBlockListener.java @@ -11,7 +11,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockPhysicsEvent; -import org.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; import org.mvplugins.multiverse.external.jakarta.inject.Inject; import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service; import org.mvplugins.multiverse.portals.utils.PortalManager; diff --git a/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPCoreListener.java b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPCoreListener.java index cd5bba3..b4763f1 100644 --- a/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPCoreListener.java +++ b/src/main/java/org/mvplugins/multiverse/portals/listeners/MVPCoreListener.java @@ -10,7 +10,7 @@ import java.io.File; import com.dumptruckman.minecraft.util.Logging; -import org.jetbrains.annotations.NotNull; +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; import org.mvplugins.multiverse.core.event.MVConfigReloadEvent; import org.mvplugins.multiverse.core.event.MVDebugModeEvent; import org.mvplugins.multiverse.core.event.MVDumpsDebugInfoEvent; diff --git a/src/main/java/org/mvplugins/multiverse/portals/utils/DisplayUtils.java b/src/main/java/org/mvplugins/multiverse/portals/utils/DisplayUtils.java index ba2e599..e285497 100644 --- a/src/main/java/org/mvplugins/multiverse/portals/utils/DisplayUtils.java +++ b/src/main/java/org/mvplugins/multiverse/portals/utils/DisplayUtils.java @@ -1,10 +1,10 @@ package org.mvplugins.multiverse.portals.utils; -import org.jetbrains.annotations.NotNull; import org.mvplugins.multiverse.core.economy.MVEconomist; import org.mvplugins.multiverse.core.world.MultiverseWorld; 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; import org.mvplugins.multiverse.portals.MVPortal; import org.bukkit.ChatColor;