Compare commits

...
13 changed files with 52 additions and 79 deletions

No files matched your search

@@ -1063,7 +1063,7 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
/**
* Returns true if this entity can breathe underwater and will not take
* suffocation damage when its air supply reaches zero.
* drowning damage when its air supply reaches zero.
*
* @return <code>true</code> if the entity can breathe underwater
*/
@@ -86,7 +86,6 @@ public abstract class Event {
* <li>The handlers for this event may block for any length of time.
* <li>Some implementations may selectively declare a specific event use
* as asynchronous. This behavior should be clearly defined.
* <li>Asynchronous calls are not calculated in the plugin timing system.
* </ul>
*
* @return {@code false} by default, {@code true} if the event fires asynchronously
@@ -61,7 +61,6 @@ public final class SimplePluginManager implements PluginManager {
public final Map<Boolean, Map<Permissible, Boolean>> defSubs = new HashMap<Boolean, Map<Permissible, Boolean>>();
public PluginManager paperPluginManager;
// Paper end
private boolean useTimings = false;
public SimplePluginManager(@NotNull Server instance, @NotNull SimpleCommandMap commandMap) {
server = instance;
@@ -720,12 +719,7 @@ public final class SimplePluginManager implements PluginManager {
throw new IllegalPluginAccessException("Plugin attempted to register " + event + " while not enabled");
}
executor = new co.aikar.timings.TimedEventExecutor(executor, plugin, null, event); // Paper
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));
}
@NotNull
@@ -9,7 +9,9 @@ import org.jetbrains.annotations.Nullable;
/**
* Extends RegisteredListener to include timing information
* @deprecated This class was part of Timings v1 and has gone unused for over a decade, timings will be removed in the future.
*/
@Deprecated(forRemoval = true)
public class TimedRegisteredListener extends RegisteredListener {
private int count;
private long totalTime;
@@ -290,7 +290,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
try {
@@ -304,7 +304,7 @@ public final class JavaPluginLoader implements PluginLoader {
throw new EventException(t);
}
}
}, plugin, method, eventClass); // Paper
};
eventSet.add(new RegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled()));
}
return ret;
@@ -1,56 +0,0 @@
package org.bukkit.plugin;
import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import org.bukkit.event.Event;
import org.bukkit.event.EventException;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.junit.jupiter.api.Test;
public class TimedRegisteredListenerTest {
@Test
public void testEventClass() throws EventException {
Listener listener = new Listener() {};
EventExecutor executor = new EventExecutor() {
@Override
public void execute(Listener listener, Event event) {}
};
BukkitTestPlugin plugin = new BukkitTestPlugin("Test");
PlayerInteractEvent interactEvent = new PlayerInteractEvent(null, null, null, null, null);
PlayerMoveEvent moveEvent = new PlayerMoveEvent(null, null, null);
BlockBreakEvent breakEvent = new BlockBreakEvent(null, null);
TimedRegisteredListener trl = new TimedRegisteredListener(listener, executor, EventPriority.NORMAL, plugin, false);
// Ensure that the correct event type is reported for a single event
trl.callEvent(interactEvent);
assertThat(trl.getEventClass(), is((Object) PlayerInteractEvent.class));
// Ensure that no superclass is used in lieu of the actual event, after two identical event types
trl.callEvent(interactEvent);
assertThat(trl.getEventClass(), is((Object) PlayerInteractEvent.class));
// Ensure that the closest superclass of the two events is chosen
trl.callEvent(moveEvent);
assertThat(trl.getEventClass(), is((Object) PlayerEvent.class));
// As above, so below
trl.callEvent(breakEvent);
assertThat(trl.getEventClass(), is((Object) Event.class));
// In the name of being thorough, check that it never travels down the hierarchy again.
trl.callEvent(breakEvent);
assertThat(trl.getEventClass(), is((Object) Event.class));
trl = new TimedRegisteredListener(listener, executor, EventPriority.NORMAL, plugin, false);
trl.callEvent(breakEvent);
assertThat(trl.getEventClass(), is((Object) BlockBreakEvent.class));
// Test moving up the class hierarchy by more than one class at a time
trl.callEvent(moveEvent);
assertThat(trl.getEventClass(), is((Object) Event.class));
}
}
@@ -0,0 +1,20 @@
--- a/net/minecraft/network/protocol/game/ServerboundDebugSubscriptionRequestPacket.java
+++ b/net/minecraft/network/protocol/game/ServerboundDebugSubscriptionRequestPacket.java
@@ -11,10 +_,13 @@
import net.minecraft.util.debug.DebugSubscription;
public record ServerboundDebugSubscriptionRequestPacket(Set<DebugSubscription<?>> subscriptions) implements Packet<ServerGamePacketListener> {
- private static final StreamCodec<RegistryFriendlyByteBuf, Set<DebugSubscription<?>>> SET_STREAM_CODEC = ByteBufCodecs.registry(
- Registries.DEBUG_SUBSCRIPTION
- )
- .apply(ByteBufCodecs.collection(ReferenceOpenHashSet::new));
+ // Paper start - Limit max size of subscription codec
+ private static final StreamCodec<RegistryFriendlyByteBuf, Set<DebugSubscription<?>>> SET_STREAM_CODEC = ByteBufCodecs.collection(
+ ReferenceOpenHashSet::new,
+ ByteBufCodecs.registry(Registries.DEBUG_SUBSCRIPTION),
+ 64
+ );
+ // Paper end - Limit max size of subscription codec
public static final StreamCodec<RegistryFriendlyByteBuf, ServerboundDebugSubscriptionRequestPacket> STREAM_CODEC = SET_STREAM_CODEC.map(
ServerboundDebugSubscriptionRequestPacket::new, ServerboundDebugSubscriptionRequestPacket::subscriptions
);
@@ -573,7 +573,7 @@
}
protected GlobalPos selectLevelLoadFocusPos() {
@@ -639,19 +_,49 @@
@@ -639,19 +_,50 @@
this.stopServer();
}
@@ -620,6 +620,7 @@
this.playerList.saveAll();
- this.playerList.removeAll();
+ this.playerList.removeAll(this.isRestarting); // Paper
+ this.getConnection().handleAllDisconnections(); // Paper
+ try { Thread.sleep(100); } catch (InterruptedException ex) {} // CraftBukkit - SPIGOT-625 - give server at least a chance to send packets
}
@@ -135,3 +135,20 @@
iterator.remove();
connection.handleDisconnection();
}
@@ -168,6 +_,16 @@
}
}
}
+ // Paper start
+ public void handleAllDisconnections() {
+ synchronized (this.connections) {
+ for (Connection connection : this.connections) {
+ connection.channel.close().awaitUninterruptibly();
+ connection.handleDisconnection();
+ }
+ }
+ }
+ // Paper end
public MinecraftServer getServer() {
return this.server;
@@ -13,18 +13,15 @@
.map(BundleContents::new, contents -> contents.items);
private static final Fraction BUNDLE_IN_BUNDLE_WEIGHT = Fraction.getFraction(1, 16);
private static final int NO_STACK_INDEX = -1;
@@ -38,6 +_,11 @@
@@ -38,7 +_,7 @@
private final Supplier<DataResult<Fraction>> weight;
private BundleContents(final List<ItemStackTemplate> items, final int selectedItem) {
+ // Paper start - limit size
+ if (items.size() > 256) {
+ throw new IllegalArgumentException("Too many items");
+ }
+ // Paper end - limit size
this.items = items;
- this.items = items;
+ this.items = items.size() > 256 ? items.subList(0, 256) : items; // Paper - limit size
this.selectedItem = selectedItem;
this.weight = Suppliers.memoize(() -> computeContentWeight(this.items));
}
@@ -80,6 +_,13 @@
return !itemToAdd.isEmpty() && itemToAdd.getItem().canFitInsideContainerItems();
}
@@ -15,7 +15,7 @@
+ // Paper start - limit size
+ public ChargedProjectiles {
+ if (items.size() > 64) {
+ throw new IllegalArgumentException("Too many items");
+ items = items.subList(0, 64);
+ }
+ }
+ // Paper end - limit size
@@ -19,7 +19,7 @@ public record PaperItemContainerContents(
@Override
public List<ItemStack> contents() {
return MCUtil.transformUnmodifiable(this.impl.items, optional -> optional.map(CraftItemStack::asBukkitCopy).orElse(null));
return MCUtil.transformUnmodifiable(this.impl.items, optional -> optional.map(CraftItemStack::asBukkitCopy).orElse(ItemStack.empty()));
}
static final class BuilderImpl implements ItemContainerContents.Builder {
@@ -95,7 +95,6 @@ class PaperEventManager {
throw new IllegalPluginAccessException("Plugin attempted to register " + event + " while not enabled");
}
executor = new TimedEventExecutor(executor, plugin, null, event);
this.getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
}
@@ -182,7 +181,7 @@ class PaperEventManager {
}
}
EventExecutor executor = new TimedEventExecutor(EventExecutor.create(method, eventClass), plugin, method, eventClass);
EventExecutor executor = EventExecutor.create(method, eventClass);
eventSet.add(new RegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled()));
}
return ret;