Skip to content

Commit

Permalink
Merge pull request #3133 from Multiverse/ben/mv5/events
Browse files Browse the repository at this point in the history
Ben/mv5/events
  • Loading branch information
benwoo1110 authored Nov 24, 2024
2 parents 668856d + d077461 commit 470e657
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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<String, String> files = versionEvent.getDetailedVersionInfo();
final Map<String, String> files = versionEvent.getDetailedDebugInfo();

// Deal with uploading debug info
switch (servicesType) {
Expand Down Expand Up @@ -180,36 +179,36 @@ 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'
+ " - Loaded Worlds: " + worldManager.getLoadedWorlds() + '\n'
+ " - 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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Called when the Multiverse-config should be reloaded.
*/
public class MVConfigReloadEvent extends Event {
private List<String> configsLoaded;
private final List<String> configsLoaded;

public MVConfigReloadEvent(List<String> configsLoaded) {
this.configsLoaded = configsLoaded;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> detailedVersionInfo;
private final StringBuilder debugInfoBuilder;
private final Map<String, String> detailedDebugInfo;

public MVVersionEvent() {
versionInfoBuilder = new StringBuilder();
detailedVersionInfo = new HashMap<>();
public MVDumpsDebugInfoEvent() {
debugInfoBuilder = new StringBuilder();
detailedDebugInfo = new HashMap<>();
}

private static final HandlerList HANDLERS = new HandlerList();
Expand All @@ -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();
}

/**
Expand All @@ -63,16 +63,16 @@ public String getVersionInfo() {
*
* @return The immutable key value mapping of files and the contents of those files.
*/
public Map<String, String> getDetailedVersionInfo() {
return Collections.unmodifiableMap(this.detailedVersionInfo);
public Map<String, String> 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) {
Expand Down Expand Up @@ -104,16 +104,16 @@ 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);
}

/**
* Adds a file to to the detailed version-info currently saved in this event.
* @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()));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
* To get the new value, use {@link #getTheNewValue()}. To change it, use {@link #setTheNewValue(Object)}.
* @param <T> The type of the property that was set.
*/
// todo: Implement or remove this
@Deprecated
public class MVWorldPropertyChangeEvent<T> extends Event implements Cancellable {
private MultiverseWorld world;
private CommandSender changer;
Expand Down
Loading

0 comments on commit 470e657

Please sign in to comment.