Skip to content

Commit

Permalink
PreLoadEvent uses desc
Browse files Browse the repository at this point in the history
  • Loading branch information
404Setup committed Oct 6, 2024
1 parent 7181b8d commit 50ba482
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.PluginDescriptionFile;
import org.jetbrains.annotations.NotNull;

import java.nio.file.Path;

public class PreLoadPluginEvent extends Event implements Cancellable {
private static final HandlerList HANDLERS_LIST = new HandlerList();
private final @NotNull Path pluginPath;
private final @NotNull String pluginName;
private final @NotNull PluginDescriptionFile desc;
private boolean isCancelled;

public PreLoadPluginEvent(@NotNull Path pluginPath, @NotNull String pluginName) {
public PreLoadPluginEvent(@NotNull Path pluginPath, @NotNull PluginDescriptionFile desc) {
this.pluginPath = pluginPath;
this.pluginName = pluginName;
this.desc = desc;
this.isCancelled = false;
}

public static HandlerList getHandlerList() {
return HANDLERS_LIST;
}

@Override
public boolean isCancelled() {
return isCancelled;
Expand All @@ -34,15 +39,11 @@ public void setCancelled(boolean cancelled) {
return HANDLERS_LIST;
}

public static HandlerList getHandlerList() {
return HANDLERS_LIST;
}

public @NotNull Path getPluginPath() {
return pluginPath;
}

public @NotNull String getPluginName() {
return pluginName;
public @NotNull PluginDescriptionFile getDesc() {
return desc;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -359,19 +359,29 @@ public String load(String name) {
return PlugMan.getInstance().getMessageFormatter().format("load.plugin-directory");

File pluginFile = new File(pluginDir, name + ".jar");
PluginDescriptionFile description = null;

if (!pluginFile.isFile()) for (File f : pluginDir.listFiles())
if (f.getName().endsWith(".jar")) try {
PluginDescriptionFile desc = PlugMan.getInstance().getPluginLoader().getPluginDescription(f);
if (desc.getName().equalsIgnoreCase(name)) {
pluginFile = f;
description = desc;
break;
}
} catch (InvalidDescriptionException e) {
return PlugMan.getInstance().getMessageFormatter().format("load.cannot-find");
}

PreLoadPluginEvent preloadEvent = new PreLoadPluginEvent(pluginFile.toPath(), name);
if (description == null) {
try {
description = PlugMan.getInstance().getPluginLoader().getPluginDescription(pluginFile);
} catch (InvalidDescriptionException e) {
return PlugMan.getInstance().getMessageFormatter().format("load.cannot-find");
}
}

PreLoadPluginEvent preloadEvent = new PreLoadPluginEvent(pluginFile.toPath(), description);
Bukkit.getPluginManager().callEvent(preloadEvent);
if (preloadEvent.isCancelled())
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.rylinaux.plugman.api.event.PreUnloadPluginEvent;
import com.rylinaux.plugman.util.BukkitCommandWrapUseless;
import com.rylinaux.plugman.util.StringUtil;
import com.tcoded.folialib.FoliaLib;
import io.papermc.paper.plugin.configuration.PluginMeta;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
Expand Down Expand Up @@ -376,20 +377,30 @@ public String load(String name) {
return PlugMan.getInstance().getMessageFormatter().format("load.plugin-directory");

File pluginFile = new File(pluginDir, name + ".jar");
PluginDescriptionFile description = null;

if (!pluginFile.isFile())
for (File f : pluginDir.listFiles())
if (f.getName().endsWith(".jar")) try {
PluginDescriptionFile desc = this.getPluginDescription(f);
if (desc.getName().equalsIgnoreCase(name)) {
pluginFile = f;
description = desc;
break;
}
} catch (InvalidDescriptionException e) {
return PlugMan.getInstance().getMessageFormatter().format("load.cannot-find");
}

PreLoadPluginEvent preloadEvent = new PreLoadPluginEvent(pluginFile.toPath(), name);
if (description == null) {
try {
description = this.getPluginDescription(pluginFile);
} catch (InvalidDescriptionException e) {
return PlugMan.getInstance().getMessageFormatter().format("load.cannot-find");
}
}

PreLoadPluginEvent preloadEvent = new PreLoadPluginEvent(pluginFile.toPath(), description);
Bukkit.getPluginManager().callEvent(preloadEvent);
if (preloadEvent.isCancelled())
return null;
Expand Down Expand Up @@ -433,7 +444,7 @@ public String load(String name) {
Plugin finalTarget = target;

if (this.isFolia()) {
com.tcoded.folialib.FoliaLib foliaLib = new com.tcoded.folialib.FoliaLib(PlugMan.getInstance());
FoliaLib foliaLib = new FoliaLib(PlugMan.getInstance());

foliaLib.getImpl().runLater(() -> {
this.loadCommands(finalTarget);
Expand Down

0 comments on commit 50ba482

Please sign in to comment.