mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
Added ServerResourcesReloadedEvent
This commit is contained in:
parent
da4545f227
commit
d2e5086e43
2 changed files with 146 additions and 0 deletions
60
Spigot-API-Patches/Added-ServerResourcesReloadedEvent.patch
Normal file
60
Spigot-API-Patches/Added-ServerResourcesReloadedEvent.patch
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||||
|
Date: Wed, 2 Dec 2020 20:04:16 -0800
|
||||||
|
Subject: [PATCH] Added ServerResourcesReloadedEvent
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/io/papermc/paper/event/server/ServerResourcesReloadedEvent.java b/src/main/java/io/papermc/paper/event/server/ServerResourcesReloadedEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/io/papermc/paper/event/server/ServerResourcesReloadedEvent.java
|
||||||
|
@@ -0,0 +0,0 @@
|
||||||
|
+package io.papermc.paper.event.server;
|
||||||
|
+
|
||||||
|
+import org.bukkit.event.HandlerList;
|
||||||
|
+import org.bukkit.event.server.ServerEvent;
|
||||||
|
+import org.jetbrains.annotations.NotNull;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * Called when resources such as datapacks are reloaded (e.g. /minecraft:reload)
|
||||||
|
+ * <p>
|
||||||
|
+ * Intended for use to re-register custom recipes, advancements that may be lost during a reload like this.
|
||||||
|
+ * </p>
|
||||||
|
+ */
|
||||||
|
+public class ServerResourcesReloadedEvent extends ServerEvent {
|
||||||
|
+
|
||||||
|
+ public static final HandlerList HANDLER_LIST = new HandlerList();
|
||||||
|
+
|
||||||
|
+ private final Cause cause;
|
||||||
|
+
|
||||||
|
+ public ServerResourcesReloadedEvent(@NotNull Cause cause) {
|
||||||
|
+ this.cause = cause;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Gets the cause of the resource reload.
|
||||||
|
+ *
|
||||||
|
+ * @return the reload cause
|
||||||
|
+ */
|
||||||
|
+ @NotNull
|
||||||
|
+ public Cause getCause() {
|
||||||
|
+ return cause;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ public static HandlerList getHandlerList() {
|
||||||
|
+ return HANDLER_LIST;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ @Override
|
||||||
|
+ public HandlerList getHandlers() {
|
||||||
|
+ return HANDLER_LIST;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public enum Cause {
|
||||||
|
+ COMMAND,
|
||||||
|
+ PLUGIN,
|
||||||
|
+ }
|
||||||
|
+}
|
|
@ -0,0 +1,86 @@
|
||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||||
|
Date: Wed, 2 Dec 2020 20:04:01 -0800
|
||||||
|
Subject: [PATCH] Added ServerResourcesReloadedEvent
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/net/minecraft/server/CommandReload.java b/src/main/java/net/minecraft/server/CommandReload.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/net/minecraft/server/CommandReload.java
|
||||||
|
+++ b/src/main/java/net/minecraft/server/CommandReload.java
|
||||||
|
@@ -0,0 +0,0 @@ import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
+import io.papermc.paper.event.server.ServerResourcesReloadedEvent; // Paper
|
||||||
|
|
||||||
|
public class CommandReload {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
|
public static void a(Collection<String> collection, CommandListenerWrapper commandlistenerwrapper) {
|
||||||
|
- commandlistenerwrapper.getServer().a(collection).exceptionally((throwable) -> {
|
||||||
|
+ commandlistenerwrapper.getServer().reloadServerResources(collection, ServerResourcesReloadedEvent.Cause.COMMAND).exceptionally((throwable) -> { // Paper
|
||||||
|
CommandReload.LOGGER.warn("Failed to execute reload", throwable);
|
||||||
|
commandlistenerwrapper.sendFailureMessage(new ChatMessage("commands.reload.failure"));
|
||||||
|
return null;
|
||||||
|
@@ -0,0 +0,0 @@ public class CommandReload {
|
||||||
|
SaveData savedata = minecraftserver.getSaveData();
|
||||||
|
Collection<String> collection = resourcepackrepository.d();
|
||||||
|
Collection<String> collection1 = a(resourcepackrepository, savedata, collection);
|
||||||
|
- minecraftserver.a(collection1);
|
||||||
|
+ minecraftserver.reloadServerResources(collection1, ServerResourcesReloadedEvent.Cause.PLUGIN); // Paper
|
||||||
|
}
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||||
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||||
|
@@ -0,0 +0,0 @@ package net.minecraft.server;
|
||||||
|
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
-import co.aikar.timings.Timings;
|
||||||
|
-import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
|
||||||
|
-import com.google.common.base.Stopwatch;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
@@ -0,0 +0,0 @@ import org.apache.logging.log4j.Logger;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
// import jline.console.ConsoleReader; // Paper
|
||||||
|
import joptsimple.OptionSet;
|
||||||
|
-import org.bukkit.Bukkit;
|
||||||
|
-import org.bukkit.craftbukkit.CraftServer;
|
||||||
|
-import org.bukkit.craftbukkit.Main;
|
||||||
|
import org.bukkit.event.server.ServerLoadEvent;
|
||||||
|
// CraftBukkit end
|
||||||
|
import co.aikar.timings.MinecraftTimings; // Paper
|
||||||
|
import io.papermc.paper.util.PaperJvmChecker; // Paper
|
||||||
|
+import io.papermc.paper.event.server.ServerResourcesReloadedEvent; // Paper
|
||||||
|
import org.spigotmc.SlackActivityAccountant; // Spigot
|
||||||
|
|
||||||
|
public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTask> implements IMojangStatistics, ICommandListener, AutoCloseable {
|
||||||
|
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
||||||
|
return this.customFunctionData;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ // Paper start - add cause
|
||||||
|
+ @Deprecated
|
||||||
|
public CompletableFuture<Void> a(Collection<String> collection) {
|
||||||
|
+ return this.reloadServerResources(collection, ServerResourcesReloadedEvent.Cause.PLUGIN);
|
||||||
|
+ }
|
||||||
|
+ public CompletableFuture<Void> reloadServerResources(Collection<String> collection, ServerResourcesReloadedEvent.Cause cause) {
|
||||||
|
+ // Paper end
|
||||||
|
CompletableFuture<Void> completablefuture = CompletableFuture.supplyAsync(() -> {
|
||||||
|
Stream<String> stream = collection.stream(); // CraftBukkit - decompile error
|
||||||
|
ResourcePackRepository resourcepackrepository = this.resourcePackRepository;
|
||||||
|
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
||||||
|
this.resourcePackRepository.a(collection);
|
||||||
|
this.saveData.a(a(this.resourcePackRepository));
|
||||||
|
datapackresources.i();
|
||||||
|
+ new ServerResourcesReloadedEvent(cause).callEvent(); // Paper
|
||||||
|
if (Thread.currentThread() != this.serverThread) return; // Paper
|
||||||
|
//this.getPlayerList().savePlayers(); // Paper - we don't need to do this
|
||||||
|
this.getPlayerList().reload();
|
Loading…
Reference in a new issue