Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface ActionButton {
* @return a new ActionButton instance
*/
@Contract(value = "_, _, _, _ -> new", pure = true)
static ActionButton create(final Component label, final @Nullable Component tooltip, final int width, final @Nullable DialogAction action) {
static ActionButton create(final Component label, final @Nullable Component tooltip, final @Range(from = 1, to = 1024) int width, final @Nullable DialogAction action) {
return builder(label).tooltip(tooltip).width(width).action(action).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.List;

/**
* Event fired when a dispenser shears a nearby sheep.
* Event fired when a dispenser shears a nearby entity.
*/
public class BlockShearEntityEvent extends BlockEvent implements Cancellable {

Expand Down Expand Up @@ -43,9 +43,9 @@ public Entity getEntity() {
}

/**
* Gets the item used to shear this sheep.
* Gets the item used to shear this entity.
*
* @return the item used to shear this sheep.
* @return the item used to shear this entity.
*/
@NotNull
public ItemStack getTool() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/net/minecraft/world/item/LeadItem.java
+++ b/net/minecraft/world/item/LeadItem.java
@@ -26,24 +_,46 @@
@@ -26,25 +_,38 @@
if (blockState.is(BlockTags.FENCES)) {
Player player = context.getPlayer();
if (!level.isClientSide && player != null) {
Expand All @@ -18,9 +18,7 @@
List<Leashable> list = Leashable.leashableInArea(level, Vec3.atCenterOf(pos), leashable1 -> leashable1.getLeashHolder() == player);
boolean flag = false;

- for (Leashable leashable : list) {
+ for (java.util.Iterator<Leashable> iterator = list.iterator(); iterator.hasNext();) { // Paper - use iterator to remove
+ Leashable leashable = iterator.next(); // Paper - use iterator to remove
for (Leashable leashable : list) {
if (leashFenceKnotEntity == null) {
- leashFenceKnotEntity = LeashFenceKnotEntity.getOrCreateKnot(level, pos);
+ // CraftBukkit start - fire HangingPlaceEvent
Expand All @@ -32,25 +30,19 @@
+ level.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ leashFenceKnotEntity.discard(null); // CraftBukkit - add Bukkit remove cause
+ leashFenceKnotEntity.discard(null);
+ return InteractionResult.PASS;
+ }
+ }
+ // CraftBukkit end
leashFenceKnotEntity.playPlacementSound();
}

+ // CraftBukkit start
+ if (leashable instanceof net.minecraft.world.entity.Entity leashed) {
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(leashed, leashFenceKnotEntity, player, interactionHand).isCancelled()) {
+ iterator.remove();
+ continue;
+ }
+ }
+ // CraftBukkit end
if (leashable.canHaveALeashAttachedTo(leashFenceKnotEntity)) {
- if (leashable.canHaveALeashAttachedTo(leashFenceKnotEntity)) {
+ if (leashable.canHaveALeashAttachedTo(leashFenceKnotEntity) && org.bukkit.craftbukkit.event.CraftEventFactory.handlePlayerLeashEntityEvent(leashable, leashFenceKnotEntity, player, interactionHand)) { // Paper - leash event
leashable.setLeashedTo(leashFenceKnotEntity, true);
flag = true;
}
@@ -54,7 +_,18 @@
level.gameEvent(GameEvent.BLOCK_ATTACH, pos, GameEvent.Context.of(player));
return InteractionResult.SUCCESS_SERVER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import com.mojang.datafixers.util.Either;
import io.papermc.paper.adventure.PaperAdventure;
import io.papermc.paper.connection.HorriblePlayerLoginEventHack;
import io.papermc.paper.connection.PlayerConnection;
import io.papermc.paper.event.connection.PlayerConnectionValidateLoginEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
Expand All @@ -14,16 +18,11 @@
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import io.papermc.paper.adventure.PaperAdventure;
import io.papermc.paper.connection.HorriblePlayerLoginEventHack;
import io.papermc.paper.connection.PlayerConnection;
import io.papermc.paper.event.connection.PlayerConnectionValidateLoginEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ServerboundContainerClosePacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -1544,8 +1543,8 @@ public static boolean handlePlayerUnleashEntityEvent(
}

public static boolean handlePlayerLeashEntityEvent(Leashable leashed, Entity leashHolder, net.minecraft.world.entity.player.Player player, InteractionHand hand) {
if (!(leashed instanceof final Entity leashedEntity)) return false;
return callPlayerLeashEntityEvent(leashedEntity, leashHolder, player, hand).callEvent();
if (!(leashed instanceof final Entity leashedEntity)) return true;
return !callPlayerLeashEntityEvent(leashedEntity, leashHolder, player, hand).isCancelled();
}

public static @Nullable PlayerLeashEntityEvent callPlayerLeashEntityEvent(Leashable leashed, Entity leashHolder, net.minecraft.world.entity.player.Player player, InteractionHand hand) {
Expand Down
Loading