diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/DumpsCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/DumpsCommand.java index f01e543f7..e1cd1916f 100644 --- a/src/main/java/org/mvplugins/multiverse/core/commands/DumpsCommand.java +++ b/src/main/java/org/mvplugins/multiverse/core/commands/DumpsCommand.java @@ -25,11 +25,10 @@ import org.mvplugins.multiverse.core.MultiverseCore; import org.mvplugins.multiverse.core.commandtools.MVCommandManager; -import org.mvplugins.multiverse.core.commandtools.MultiverseCommand; import org.mvplugins.multiverse.core.commandtools.flags.CommandFlag; import org.mvplugins.multiverse.core.commandtools.flags.CommandValueFlag; import org.mvplugins.multiverse.core.commandtools.flags.ParsedCommandFlags; -import org.mvplugins.multiverse.core.event.MVVersionEvent; +import org.mvplugins.multiverse.core.event.MVDumpsDebugInfoEvent; import org.mvplugins.multiverse.core.utils.MVCorei18n; import org.mvplugins.multiverse.core.utils.webpaste.PasteFailedException; import org.mvplugins.multiverse.core.utils.webpaste.PasteService; @@ -100,13 +99,13 @@ void onDumpsCommand( final ServiceTypeOption servicesType = parsedFlags.flagValue(UPLOAD_FLAG, ServiceTypeOption.PASTEGG); // Initialise and add info to the debug event - MVVersionEvent versionEvent = new MVVersionEvent(); + MVDumpsDebugInfoEvent versionEvent = new MVDumpsDebugInfoEvent(); this.addDebugInfoToEvent(versionEvent); plugin.getServer().getPluginManager().callEvent(versionEvent); // Add plugin list if user isn't paranoid if (!paranoid) { - versionEvent.putDetailedVersionInfo("plugins.md", "# Plugins\n\n" + getPluginList()); + versionEvent.putDetailedDebugInfo("plugins.md", "# Plugins\n\n" + getPluginList()); } BukkitRunnable logPoster = new BukkitRunnable() { @@ -122,12 +121,12 @@ public void run() { case MCLOGS -> issuer.sendInfo(MVCorei18n.DUMPS_URL_LIST, "{service}", "Logs", "{link}", postToService(PasteServiceType.MCLOGS, true, getLogs(), null)); - case APPEND -> versionEvent.putDetailedVersionInfo("latest.log", getLogs()); + case APPEND -> versionEvent.putDetailedDebugInfo("latest.log", getLogs()); } } // Get the files from the event - final Map files = versionEvent.getDetailedVersionInfo(); + final Map files = versionEvent.getDetailedDebugInfo(); // Deal with uploading debug info switch (servicesType) { @@ -180,7 +179,7 @@ private String getLogs() { return "Could not read log"; } - private String getVersionString() { + private String getDebugInfoString() { return "# Multiverse-Core Version info" + "\n\n" + " - Multiverse-Core Version: " + this.plugin.getDescription().getVersion() + '\n' + " - Bukkit Version: " + this.plugin.getServer().getVersion() + '\n' @@ -188,28 +187,28 @@ private String getVersionString() { + " - Multiverse Plugins Loaded: " + this.plugin.getPluginCount() + '\n'; } - private void addDebugInfoToEvent(MVVersionEvent event) { + private void addDebugInfoToEvent(MVDumpsDebugInfoEvent event) { // Add the legacy file, but as markdown, so it's readable - event.putDetailedVersionInfo("version.md", this.getVersionString()); + event.putDetailedDebugInfo("version.md", this.getDebugInfoString()); // add config.yml File configFile = new File(plugin.getDataFolder(), "config.yml"); - event.putDetailedVersionInfo("multiverse-core/config.yml", configFile); + event.putDetailedDebugInfo("multiverse-core/config.yml", configFile); // add worlds.yml File worldsFile = new File(plugin.getDataFolder(), "worlds.yml"); - event.putDetailedVersionInfo("multiverse-core/worlds.yml", worldsFile); + event.putDetailedDebugInfo("multiverse-core/worlds.yml", worldsFile); // Add bukkit.yml if we found it if (getBukkitConfig() != null) { - event.putDetailedVersionInfo(getBukkitConfig().getPath(), getBukkitConfig()); + event.putDetailedDebugInfo(getBukkitConfig().getPath(), getBukkitConfig()); } else { Logging.warning("/mv version could not find bukkit.yml. Not including file"); } // Add server.properties if we found it if (getServerProperties() != null) { - event.putDetailedVersionInfo(getServerProperties().getPath(), getServerProperties()); + event.putDetailedDebugInfo(getServerProperties().getPath(), getServerProperties()); } else { Logging.warning("/mv version could not find server.properties. Not including file"); } diff --git a/src/main/java/org/mvplugins/multiverse/core/event/MVConfigReloadEvent.java b/src/main/java/org/mvplugins/multiverse/core/event/MVConfigReloadEvent.java index a80a39eeb..f6fcadf5d 100644 --- a/src/main/java/org/mvplugins/multiverse/core/event/MVConfigReloadEvent.java +++ b/src/main/java/org/mvplugins/multiverse/core/event/MVConfigReloadEvent.java @@ -16,7 +16,7 @@ * Called when the Multiverse-config should be reloaded. */ public class MVConfigReloadEvent extends Event { - private List configsLoaded; + private final List configsLoaded; public MVConfigReloadEvent(List configsLoaded) { this.configsLoaded = configsLoaded; diff --git a/src/main/java/org/mvplugins/multiverse/core/event/MVVersionEvent.java b/src/main/java/org/mvplugins/multiverse/core/event/MVDumpsDebugInfoEvent.java similarity index 77% rename from src/main/java/org/mvplugins/multiverse/core/event/MVVersionEvent.java rename to src/main/java/org/mvplugins/multiverse/core/event/MVDumpsDebugInfoEvent.java index d6b79900f..876208503 100644 --- a/src/main/java/org/mvplugins/multiverse/core/event/MVVersionEvent.java +++ b/src/main/java/org/mvplugins/multiverse/core/event/MVDumpsDebugInfoEvent.java @@ -16,14 +16,14 @@ /** * Called when somebody requests version information about Multiverse. */ -public class MVVersionEvent extends Event { +public class MVDumpsDebugInfoEvent extends Event { - private final StringBuilder versionInfoBuilder; - private final Map detailedVersionInfo; + private final StringBuilder debugInfoBuilder; + private final Map detailedDebugInfo; - public MVVersionEvent() { - versionInfoBuilder = new StringBuilder(); - detailedVersionInfo = new HashMap<>(); + public MVDumpsDebugInfoEvent() { + debugInfoBuilder = new StringBuilder(); + detailedDebugInfo = new HashMap<>(); } private static final HandlerList HANDLERS = new HandlerList(); @@ -48,8 +48,8 @@ public static HandlerList getHandlerList() { * Gets the version-info currently saved in this event. * @return The version-info. */ - public String getVersionInfo() { - return this.versionInfoBuilder.toString(); + public String getDebugInfo() { + return this.debugInfoBuilder.toString(); } /** @@ -63,16 +63,16 @@ public String getVersionInfo() { * * @return The immutable key value mapping of files and the contents of those files. */ - public Map getDetailedVersionInfo() { - return Collections.unmodifiableMap(this.detailedVersionInfo); + public Map getDetailedDebugInfo() { + return Collections.unmodifiableMap(this.detailedDebugInfo); } /** * Appends more version-info to the version-info currently saved in this event. * @param moreVersionInfo The version-info to add. Should end with '\n'. */ - public void appendVersionInfo(String moreVersionInfo) { - this.versionInfoBuilder.append(moreVersionInfo); + public void appendDebugInfo(String moreVersionInfo) { + this.debugInfoBuilder.append(moreVersionInfo); } private String readFile(final String filename) { @@ -104,8 +104,8 @@ private String readFile(final String filename) { * @param fileName The name of the file. * @param contents The contents of the file. */ - public void putDetailedVersionInfo(String fileName, String contents) { - this.detailedVersionInfo.put(fileName, contents); + public void putDetailedDebugInfo(String fileName, String contents) { + this.detailedDebugInfo.put(fileName, contents); } /** @@ -113,7 +113,7 @@ public void putDetailedVersionInfo(String fileName, String contents) { * @param filename The name of the file. * @param file The file. */ - public void putDetailedVersionInfo(String filename, File file) { - this.putDetailedVersionInfo(filename, readFile(file.getAbsolutePath())); + public void putDetailedDebugInfo(String filename, File file) { + this.putDetailedDebugInfo(filename, readFile(file.getAbsolutePath())); } } diff --git a/src/main/java/org/mvplugins/multiverse/core/event/MVPlayerTouchedPortalEvent.java b/src/main/java/org/mvplugins/multiverse/core/event/MVPlayerTouchedPortalEvent.java deleted file mode 100644 index 8f04f77b4..000000000 --- a/src/main/java/org/mvplugins/multiverse/core/event/MVPlayerTouchedPortalEvent.java +++ /dev/null @@ -1,93 +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 org.mvplugins.multiverse.core.event; - -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -/** - * This event is thrown when a portal is touched. - */ -public class MVPlayerTouchedPortalEvent extends Event implements Cancellable { - private Player p; - private Location l; - private boolean isCancelled; - private boolean canUse = true; - - public MVPlayerTouchedPortalEvent(Player p, Location l) { - this.p = p; - this.l = l; - } - - private static final HandlerList HANDLERS = new HandlerList(); - - /** - * {@inheritDoc} - */ - @Override - public HandlerList getHandlers() { - return HANDLERS; - } - - /** - * Gets the handler list. This is required by the event system. - * @return A list of HANDLERS. - */ - public static HandlerList getHandlerList() { - return HANDLERS; - } - - /** - * Gets the {@link Location} of the portal-block that was touched. - * @return The {@link Location} of the portal-block that was touched. - */ - public Location getBlockTouched() { - return this.l; - } - - /** - * Gets the {@link Player} that's touching the portal. - * @return The {@link Player} that's touching the portal. - */ - public Player getPlayer() { - return this.p; - } - - /** - * Gets whether or not the player in this event can use this portal. - * - * @return True if the player can use this portal. - */ - public boolean canUseThisPortal() { - return this.canUse; - } - - /** - * Sets whether or not the player in this event can use this portal. - *

- * Setting this to false will cause the player to bounce back! - * - * @param canUse Whether or not the user can go through this portal. - */ - public void setCanUseThisPortal(boolean canUse) { - this.canUse = canUse; - } - - @Override - public boolean isCancelled() { - return this.isCancelled; - } - - @Override - public void setCancelled(boolean b) { - this.isCancelled = b; - } -} diff --git a/src/main/java/org/mvplugins/multiverse/core/event/MVRespawnEvent.java b/src/main/java/org/mvplugins/multiverse/core/event/MVRespawnEvent.java index 5190122d3..ffc51f225 100644 --- a/src/main/java/org/mvplugins/multiverse/core/event/MVRespawnEvent.java +++ b/src/main/java/org/mvplugins/multiverse/core/event/MVRespawnEvent.java @@ -15,11 +15,12 @@ /** * Called when a player is respawning. */ +// todo: remove or update its usage. The respawnMethod is always "compatibility" for some reason +@Deprecated public class MVRespawnEvent extends Event { - private Player player; + private final Player player; + private final String respawnMethod; private Location location; - private String respawnMethod; - public MVRespawnEvent(Location spawningAt, Player p, String respawnMethod) { this.player = p; diff --git a/src/main/java/org/mvplugins/multiverse/core/event/MVTeleportEvent.java b/src/main/java/org/mvplugins/multiverse/core/event/MVTeleportDestinationEvent.java similarity index 76% rename from src/main/java/org/mvplugins/multiverse/core/event/MVTeleportEvent.java rename to src/main/java/org/mvplugins/multiverse/core/event/MVTeleportDestinationEvent.java index 196ddb590..46a6c2727 100644 --- a/src/main/java/org/mvplugins/multiverse/core/event/MVTeleportEvent.java +++ b/src/main/java/org/mvplugins/multiverse/core/event/MVTeleportDestinationEvent.java @@ -9,6 +9,7 @@ import org.bukkit.Location; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -18,20 +19,18 @@ import org.mvplugins.multiverse.core.teleportation.AsyncSafetyTeleporter; /** - * Event that gets called when a player use the /mvtp command. + * Event that gets called when a player teleports to a {@link DestinationInstance} with {@link AsyncSafetyTeleporter}. */ -public class MVTeleportEvent extends Event implements Cancellable { - private Player teleportee; - private CommandSender teleporter; - private DestinationInstance dest; - private boolean useSafeTeleport; +public class MVTeleportDestinationEvent extends Event implements Cancellable { + private final Entity teleportee; + private final CommandSender teleporter; + private final DestinationInstance dest; private boolean isCancelled; - public MVTeleportEvent(DestinationInstance dest, Player teleportee, CommandSender teleporter, boolean safeTeleport) { + public MVTeleportDestinationEvent(DestinationInstance dest, Entity teleportee, CommandSender teleporter) { this.teleportee = teleportee; this.teleporter = teleporter; this.dest = dest; - this.useSafeTeleport = safeTeleport; } private static final HandlerList HANDLERS = new HandlerList(); @@ -57,7 +56,7 @@ public static HandlerList getHandlerList() { * * @return The player who will be teleported by this event. */ - public Player getTeleportee() { + public Entity getTeleportee() { return this.teleportee; } @@ -88,14 +87,6 @@ public CommandSender getTeleporter() { return this.dest; } - /** - * Looks if this {@link MVTeleportEvent} is using the {@link AsyncSafetyTeleporter}. - * @return True if this {@link MVTeleportEvent} is using the {@link AsyncSafetyTeleporter}. - */ - public boolean isUsingSafeTTeleporter() { - return useSafeTeleport; - } - @Override public boolean isCancelled() { return this.isCancelled; diff --git a/src/main/java/org/mvplugins/multiverse/core/event/MVWorldDeleteEvent.java b/src/main/java/org/mvplugins/multiverse/core/event/MVWorldDeleteEvent.java index 0438d84aa..56610c479 100644 --- a/src/main/java/org/mvplugins/multiverse/core/event/MVWorldDeleteEvent.java +++ b/src/main/java/org/mvplugins/multiverse/core/event/MVWorldDeleteEvent.java @@ -4,8 +4,8 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; -import org.mvplugins.multiverse.core.world.MultiverseWorld; /** * Called when a world is about to be deleted by Multiverse. @@ -14,14 +14,9 @@ public class MVWorldDeleteEvent extends Event implements Cancellable { private boolean cancelled = false; private final LoadedMultiverseWorld world; - private final boolean removeFromConfig; - public MVWorldDeleteEvent(LoadedMultiverseWorld world, boolean removeFromConfig) { - if (world == null) { - throw new IllegalArgumentException("world can't be null!"); - } + public MVWorldDeleteEvent(@NotNull LoadedMultiverseWorld world) { this.world = world; - this.removeFromConfig = removeFromConfig; } private static final HandlerList HANDLERS = new HandlerList(); @@ -61,19 +56,9 @@ public void setCancelled(boolean cancel) { /** * Gets the world that's about to be deleted. * - * @return That {@link MultiverseWorld}. + * @return That {@link LoadedMultiverseWorld}. */ public LoadedMultiverseWorld getWorld() { return world; } - - /** - * Is the world about to be removed from the config? - * - * @return True if yes, false if no. - */ - public boolean removeWorldFromConfig() { - return removeFromConfig; - } - } diff --git a/src/main/java/org/mvplugins/multiverse/core/event/MVWorldPropertyChangeEvent.java b/src/main/java/org/mvplugins/multiverse/core/event/MVWorldPropertyChangeEvent.java index e67dbd9b0..c6bb47188 100644 --- a/src/main/java/org/mvplugins/multiverse/core/event/MVWorldPropertyChangeEvent.java +++ b/src/main/java/org/mvplugins/multiverse/core/event/MVWorldPropertyChangeEvent.java @@ -25,6 +25,8 @@ * To get the new value, use {@link #getTheNewValue()}. To change it, use {@link #setTheNewValue(Object)}. * @param The type of the property that was set. */ +// todo: Implement or remove this +@Deprecated public class MVWorldPropertyChangeEvent extends Event implements Cancellable { private MultiverseWorld world; private CommandSender changer; diff --git a/src/main/java/org/mvplugins/multiverse/core/teleportation/AsyncSafetyTeleporter.java b/src/main/java/org/mvplugins/multiverse/core/teleportation/AsyncSafetyTeleporter.java index 9c9de783a..4cfcb7f87 100644 --- a/src/main/java/org/mvplugins/multiverse/core/teleportation/AsyncSafetyTeleporter.java +++ b/src/main/java/org/mvplugins/multiverse/core/teleportation/AsyncSafetyTeleporter.java @@ -9,12 +9,14 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jvnet.hk2.annotations.Service; import org.mvplugins.multiverse.core.api.BlockSafety; import org.mvplugins.multiverse.core.destination.DestinationInstance; +import org.mvplugins.multiverse.core.event.MVTeleportDestinationEvent; import org.mvplugins.multiverse.core.utils.result.Async; import org.mvplugins.multiverse.core.utils.result.AsyncAttempt; import org.mvplugins.multiverse.core.utils.result.Attempt; @@ -26,13 +28,16 @@ public class AsyncSafetyTeleporter { private final BlockSafety blockSafety; private final TeleportQueue teleportQueue; + private final PluginManager pluginManager; @Inject AsyncSafetyTeleporter( - BlockSafety blockSafety, - TeleportQueue teleportQueue) { + @NotNull BlockSafety blockSafety, + @NotNull TeleportQueue teleportQueue, + @NotNull PluginManager pluginManager) { this.blockSafety = blockSafety; this.teleportQueue = teleportQueue; + this.pluginManager = pluginManager; } public AsyncAttempt teleportSafely( @@ -57,6 +62,11 @@ public AsyncAttempt teleportSafely( if (destination == null) { return AsyncAttempt.failure(TeleportResult.Failure.NULL_DESTINATION); } + MVTeleportDestinationEvent event = new MVTeleportDestinationEvent(destination, teleportee, teleporter); + this.pluginManager.callEvent(event); + if (event.isCancelled()) { + return AsyncAttempt.failure(TeleportResult.Failure.EVENT_CANCELLED); + } return destination.getLocation(teleportee) .map(location -> destination.checkTeleportSafety() ? teleportSafely(teleporter, teleportee, location) @@ -105,6 +115,11 @@ public AsyncAttempt teleport( if (destination == null) { return AsyncAttempt.failure(TeleportResult.Failure.NULL_DESTINATION); } + MVTeleportDestinationEvent event = new MVTeleportDestinationEvent(destination, teleportee, teleporter); + this.pluginManager.callEvent(event); + if (event.isCancelled()) { + return AsyncAttempt.failure(TeleportResult.Failure.EVENT_CANCELLED); + } return destination.getLocation(teleportee) .map(location -> teleport(teleporter, teleportee, location)) .getOrElse(AsyncAttempt.failure(TeleportResult.Failure.NULL_LOCATION)); diff --git a/src/main/java/org/mvplugins/multiverse/core/teleportation/TeleportResult.java b/src/main/java/org/mvplugins/multiverse/core/teleportation/TeleportResult.java index 93b37ff95..ef4835996 100644 --- a/src/main/java/org/mvplugins/multiverse/core/teleportation/TeleportResult.java +++ b/src/main/java/org/mvplugins/multiverse/core/teleportation/TeleportResult.java @@ -15,5 +15,6 @@ public enum Failure implements FailureReason { TELEPORT_FAILED, TELEPORT_FAILED_EXCEPTION, PLAYER_OFFLINE, + EVENT_CANCELLED, } } diff --git a/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java b/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java index de522455c..b130d0748 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java @@ -20,13 +20,14 @@ import org.bukkit.World; import org.bukkit.WorldCreator; import org.bukkit.WorldType; -import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jvnet.hk2.annotations.Service; import org.mvplugins.multiverse.core.api.BlockSafety; import org.mvplugins.multiverse.core.api.LocationManipulation; +import org.mvplugins.multiverse.core.event.MVWorldDeleteEvent; import org.mvplugins.multiverse.core.utils.message.MessageReplacement; import org.mvplugins.multiverse.core.utils.result.Attempt; import org.mvplugins.multiverse.core.utils.result.FailureReason; @@ -75,6 +76,7 @@ public class WorldManager { private final FilesManipulator filesManipulator; private final BlockSafety blockSafety; private final LocationManipulation locationManipulation; + private final PluginManager pluginManager; @Inject WorldManager( @@ -84,7 +86,9 @@ public class WorldManager { @NotNull PlayerWorldTeleporter playerWorldActions, @NotNull FilesManipulator filesManipulator, @NotNull BlockSafety blockSafety, - @NotNull LocationManipulation locationManipulation) { + @NotNull LocationManipulation locationManipulation, + @NotNull PluginManager pluginManager) { + this.pluginManager = pluginManager; this.worldsMap = new HashMap<>(); this.loadedWorldsMap = new HashMap<>(); this.unloadTracker = new ArrayList<>(); @@ -476,6 +480,13 @@ public Attempt deleteWorld(@NotNull LoadedMultivers AtomicReference worldFolder = new AtomicReference<>(); return validateWorldToDelete(world) .peek(worldFolder::set) + .mapAttempt(() -> { + MVWorldDeleteEvent event = new MVWorldDeleteEvent(world); + pluginManager.callEvent(event); + return event.isCancelled() + ? Attempt.failure(DeleteFailureReason.EVENT_CANCELLED) + : Attempt.success(null); + }) .mapAttempt(() -> removeWorld(world).transform(DeleteFailureReason.REMOVE_FAILED)) .mapAttempt(() -> filesManipulator.deleteFolder(worldFolder.get()).fold( exception -> worldActionResult(DeleteFailureReason.FAILED_TO_DELETE_FOLDER, diff --git a/src/main/java/org/mvplugins/multiverse/core/world/reasons/DeleteFailureReason.java b/src/main/java/org/mvplugins/multiverse/core/world/reasons/DeleteFailureReason.java index 454f57de2..31ad26983 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/reasons/DeleteFailureReason.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/reasons/DeleteFailureReason.java @@ -3,6 +3,7 @@ import co.aikar.locales.MessageKey; import co.aikar.locales.MessageKeyProvider; +import org.mvplugins.multiverse.core.event.MVWorldDeleteEvent; import org.mvplugins.multiverse.core.utils.MVCorei18n; import org.mvplugins.multiverse.core.utils.result.FailureReason; @@ -33,7 +34,12 @@ public enum DeleteFailureReason implements FailureReason { /** * The world folder could not be deleted. */ - FAILED_TO_DELETE_FOLDER(MVCorei18n.DELETEWORLD_FAILEDTODELETEFOLDER); + FAILED_TO_DELETE_FOLDER(MVCorei18n.DELETEWORLD_FAILEDTODELETEFOLDER), + + /** + * The {@link MVWorldDeleteEvent} was cancelled. + */ + EVENT_CANCELLED(MVCorei18n.GENERIC_FAILURE); // todo: messaging private final MessageKeyProvider message;