Skip to content

Commit

Permalink
Readd bukkit TimedRegisteredListener to keep plugin compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Dec 31, 2023
1 parent 6dfd0e6 commit 3f0845c
Showing 1 changed file with 10 additions and 126 deletions.
136 changes: 10 additions & 126 deletions patches/api/0004-Remove-Timings.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2972,7 +2972,7 @@ index e43d0e0a2c5edfcc82a677b6c4db9314006c9bf4..68fafa73d2e8d832acc7ce4759147774
server.getPluginManager().callEvent(new com.destroystokyo.paper.event.server.ServerExceptionEvent(new com.destroystokyo.paper.exception.ServerCommandException(ex, target, sender, args))); // Paper
throw new CommandException(msg, ex);
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
index 899d67fa782fac639fe7fb096e05c551d75bd647..cb01547706de416dd41879bf479d93fa0e7e23c9 100644
index 899d67fa782fac639fe7fb096e05c551d75bd647..4e93f49d1c54f3b061be456c0b8f11aa58f5a3af 100644
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
@@ -60,7 +60,6 @@ public final class SimplePluginManager implements PluginManager {
Expand All @@ -2991,8 +2991,9 @@ index 899d67fa782fac639fe7fb096e05c551d75bd647..cb01547706de416dd41879bf479d93fa
- if (false) { // Spigot - RL handles useTimings check now // Paper
- getEventListeners(event).register(new TimedRegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
- } else {
getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
- getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
- }
+ getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
}

@NotNull
Expand All @@ -3015,115 +3016,8 @@ index 899d67fa782fac639fe7fb096e05c551d75bd647..cb01547706de416dd41879bf479d93fa
}

// Paper start
diff --git a/src/main/java/org/bukkit/plugin/TimedRegisteredListener.java b/src/main/java/org/bukkit/plugin/TimedRegisteredListener.java
deleted file mode 100644
index 1d76e30b82ca56bb4cf3b9a33f5a129ab829e3f0..0000000000000000000000000000000000000000
--- a/src/main/java/org/bukkit/plugin/TimedRegisteredListener.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package org.bukkit.plugin;
-
-import org.bukkit.event.Event;
-import org.bukkit.event.EventException;
-import org.bukkit.event.EventPriority;
-import org.bukkit.event.Listener;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Extends RegisteredListener to include timing information
- */
-public class TimedRegisteredListener extends RegisteredListener {
- private int count;
- private long totalTime;
- private Class<? extends Event> eventClass;
- private boolean multiple = false;
-
- public TimedRegisteredListener(@NotNull final Listener pluginListener, @NotNull final EventExecutor eventExecutor, @NotNull final EventPriority eventPriority, @NotNull final Plugin registeredPlugin, final boolean listenCancelled) {
- super(pluginListener, eventExecutor, eventPriority, registeredPlugin, listenCancelled);
- }
-
- @Override
- public void callEvent(@NotNull Event event) throws EventException {
- if (event.isAsynchronous()) {
- super.callEvent(event);
- return;
- }
- count++;
- Class<? extends Event> newEventClass = event.getClass();
- if (this.eventClass == null) {
- this.eventClass = newEventClass;
- } else if (!this.eventClass.equals(newEventClass)) {
- multiple = true;
- this.eventClass = getCommonSuperclass(newEventClass, this.eventClass).asSubclass(Event.class);
- }
- long start = System.nanoTime();
- super.callEvent(event);
- totalTime += System.nanoTime() - start;
- }
-
- @NotNull
- private static Class<?> getCommonSuperclass(@NotNull Class<?> class1, @NotNull Class<?> class2) {
- while (!class1.isAssignableFrom(class2)) {
- class1 = class1.getSuperclass();
- }
- return class1;
- }
-
- /**
- * Resets the call count and total time for this listener
- */
- public void reset() {
- count = 0;
- totalTime = 0;
- }
-
- /**
- * Gets the total times this listener has been called
- *
- * @return Times this listener has been called
- */
- public int getCount() {
- return count;
- }
-
- /**
- * Gets the total time calls to this listener have taken
- *
- * @return Total time for all calls of this listener
- */
- public long getTotalTime() {
- return totalTime;
- }
-
- /**
- * Gets the class of the events this listener handled. If it handled
- * multiple classes of event, the closest shared superclass will be
- * returned, such that for any event this listener has handled,
- * <code>this.getEventClass().isAssignableFrom(event.getClass())</code>
- * and no class <code>this.getEventClass().isAssignableFrom(clazz)
- * {@literal && this.getEventClass() != clazz &&}
- * event.getClass().isAssignableFrom(clazz)</code> for all handled events.
- *
- * @return the event class handled by this RegisteredListener
- */
- @Nullable
- public Class<? extends Event> getEventClass() {
- return eventClass;
- }
-
- /**
- * Gets whether this listener has handled multiple events, such that for
- * some two events, <code>eventA.getClass() != eventB.getClass()</code>.
- *
- * @return true if this listener has handled multiple events
- */
- public boolean hasMultiple() {
- return multiple;
- }
-}
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
index f7266e3991d991e7d7b38752ed472bc9cfa5f43c..d0b97df06a3fb5b05592f1d8204358e8f6e4d459 100644
index f7266e3991d991e7d7b38752ed472bc9cfa5f43c..74e4abd3766d905280da0a53ce7e4d98e90e7690 100644
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
@@ -39,11 +39,9 @@ import org.bukkit.plugin.PluginDescriptionFile;
Expand All @@ -3138,37 +3032,27 @@ index f7266e3991d991e7d7b38752ed472bc9cfa5f43c..d0b97df06a3fb5b05592f1d8204358e8
import org.yaml.snakeyaml.error.YAMLException;

/**
@@ -239,7 +237,6 @@ public final class JavaPluginLoader implements PluginLoader {
Preconditions.checkArgument(plugin != null, "Plugin can not be null");
Preconditions.checkArgument(listener != null, "Listener can not be null");

- boolean useTimings = server.getPluginManager().useTimings();
Map<Class<? extends Event>, Set<RegisteredListener>> ret = new HashMap<Class<? extends Event>, Set<RegisteredListener>>();
Set<Method> methods;
try {
@@ -300,9 +297,9 @@ public final class JavaPluginLoader implements PluginLoader {
@@ -300,7 +298,7 @@ public final class JavaPluginLoader implements PluginLoader {
}
}

- EventExecutor executor = new co.aikar.timings.TimedEventExecutor(new EventExecutor() { // Paper
+ EventExecutor executor = new EventExecutor() {
@Override
- public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException { // Paper
+ public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException {
public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException { // Paper
try {
if (!eventClass.isAssignableFrom(event.getClass())) {
return;
@@ -314,12 +311,8 @@ public final class JavaPluginLoader implements PluginLoader {
@@ -314,12 +312,8 @@ public final class JavaPluginLoader implements PluginLoader {
throw new EventException(t);
}
}
- }, plugin, method, eventClass); // Paper
- if (false) { // Spigot - RL handles useTimings check now
- eventSet.add(new TimedRegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled()));
- } else {
+ };
eventSet.add(new RegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled()));
- eventSet.add(new RegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled()));
- }
+ };
+ eventSet.add(new RegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled()));
}
return ret;
}
Expand Down

0 comments on commit 3f0845c

Please sign in to comment.