Update to 1.21.3. (#2153)

* Initial update to 1.21.3.

Compiles, launches, nothing tested yet.

* Boat tag includes chest boat tag.

* Avoid Material.values call.

* Split ride checks to separate event handler.

Bypass the interact entirely and let EntityMount handle it, since we can't discriminate usage in interact.
This commit is contained in:
wizjany 2024-11-09 13:29:04 -05:00 committed by GitHub
parent 764d258ed0
commit 1a59d1eb29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 48 additions and 13 deletions

View File

@ -27,8 +27,8 @@ junit-jupiter-api.module = "org.junit.jupiter:junit-jupiter-api"
junit-jupiter-params.module = "org.junit.jupiter:junit-jupiter-params"
junit-jupiter-engine.module = "org.junit.jupiter:junit-jupiter-engine"
spigot = "org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT"
paperApi = "io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT"
spigot = "org.spigotmc:spigot-api:1.21.3-R0.1-SNAPSHOT"
paperApi = "io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT"
paperLib = "io.papermc:paperlib:1.0.8"
dummypermscompat = "com.sk89q:dummypermscompat:1.10"

View File

@ -1196,7 +1196,7 @@ private static <T extends Event & Cancellable> void handleBlockRightClick(T even
// Handle created boats
if (item != null && Materials.isBoat(item.getType())) {
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.BOAT));
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), Materials.getRelatedEntity(item.getType())));
return;
}

View File

@ -61,6 +61,7 @@
import org.bukkit.event.Event;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityMountEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerTakeLecternBookEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
@ -413,13 +414,13 @@ public void onUseEntity(UseEntityEvent event) {
/* Paintings, item frames, etc. */
} else if (Entities.isConsideredBuildingIfUsed(entity)
// weird case since sneak+interact is chest access and not ride
|| type == EntityType.CHEST_BOAT && event.getOriginalEvent() instanceof InventoryOpenEvent) {
|| event.getOriginalEvent() instanceof InventoryOpenEvent) {
if ((type == EntityType.ITEM_FRAME || type == EntityType.GLOW_ITEM_FRAME)
&& event.getCause().getFirstPlayer() != null
&& ((ItemFrame) entity).getItem().getType() != Material.AIR) {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.ITEM_FRAME_ROTATE));
what = "change that";
} else if (Entities.isMinecart(type) || type == EntityType.CHEST_BOAT) {
} else if (event.getOriginalEvent() instanceof InventoryOpenEvent) {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.CHEST_ACCESS));
what = "open that";
} else {
@ -428,9 +429,10 @@ public void onUseEntity(UseEntityEvent event) {
}
/* Ridden on use */
} else if (Entities.isRiddenOnUse(entity)) {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.RIDE, Flags.INTERACT));
// this is bypassed here as it's handled by the entity mount listener below
// bukkit actually gives three events in this case - in order: PlayerInteractAtEntity, VehicleEnter, EntityMount
canUse = true;
what = "ride that";
/* Everything else */
} else {
canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.INTERACT));
@ -519,6 +521,27 @@ public void onDamageEntity(DamageEntityEvent event) {
}
}
@EventHandler
public void onEntityMount(EntityMountEvent event) {
Entity vehicle = event.getMount();
if (!isRegionSupportEnabled(vehicle.getWorld())) return; // Region support disabled
if (!(event.getEntity() instanceof Player player)) {
return;
}
Cause cause = Cause.create(player);
if (isWhitelisted(cause, vehicle.getWorld(), false)) {
return;
}
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
Location location = vehicle.getLocation();
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
if (!query.testBuild(BukkitAdapter.adapt(location), localPlayer, Flags.RIDE, Flags.INTERACT)) {
event.setCancelled(true);
DelegateEvent dummy = new UseEntityEvent(event, cause, vehicle);
tellErrorMessage(dummy, cause, vehicle.getLocation(), "ride that");
}
}
@EventHandler(ignoreCancelled = true)
public void onVehicleExit(VehicleExitEvent event) {
Entity vehicle = event.getVehicle();

View File

@ -122,8 +122,11 @@ public static boolean isVehicle(EntityType type) {
* @return true if the type is a Boat type
*/
public static boolean isBoat(EntityType type) {
return switch(type) {
case BOAT, CHEST_BOAT -> true;
return switch (type) {
case OAK_BOAT, DARK_OAK_BOAT, SPRUCE_BOAT, ACACIA_BOAT, CHERRY_BOAT, JUNGLE_BOAT, MANGROVE_BOAT,
BIRCH_BOAT, PALE_OAK_BOAT, BAMBOO_RAFT, OAK_CHEST_BOAT, DARK_OAK_CHEST_BOAT, SPRUCE_CHEST_BOAT,
ACACIA_CHEST_BOAT, CHERRY_CHEST_BOAT, JUNGLE_CHEST_BOAT, MANGROVE_CHEST_BOAT, BIRCH_CHEST_BOAT,
PALE_OAK_CHEST_BOAT, BAMBOO_CHEST_RAFT -> true;
default -> false;
};
}

View File

@ -23,6 +23,7 @@
import com.google.common.collect.HashBiMap;
import com.sk89q.worldguard.protection.flags.Flags;
import org.bukkit.Material;
import org.bukkit.Registry;
import org.bukkit.Tag;
import org.bukkit.entity.EntityType;
import org.bukkit.potion.PotionEffect;
@ -69,7 +70,6 @@ private static void putMaterialTag(Tag<Material> tag, Integer value) {
ENTITY_ITEMS.put(EntityType.TNT, Material.TNT);
ENTITY_ITEMS.put(EntityType.FIREWORK_ROCKET, Material.FIREWORK_ROCKET);
ENTITY_ITEMS.put(EntityType.COMMAND_BLOCK_MINECART, Material.COMMAND_BLOCK_MINECART);
ENTITY_ITEMS.put(EntityType.BOAT, Material.OAK_BOAT);
ENTITY_ITEMS.put(EntityType.MINECART, Material.MINECART);
ENTITY_ITEMS.put(EntityType.CHEST_MINECART, Material.CHEST_MINECART);
ENTITY_ITEMS.put(EntityType.FURNACE_MINECART, Material.FURNACE_MINECART);
@ -80,6 +80,15 @@ private static void putMaterialTag(Tag<Material> tag, Integer value) {
ENTITY_ITEMS.put(EntityType.ARMOR_STAND, Material.ARMOR_STAND);
ENTITY_ITEMS.put(EntityType.END_CRYSTAL, Material.END_CRYSTAL);
for (String wood : new String[]{"OAK", "SPRUCE", "BIRCH", "JUNGLE", "ACACIA", "DARK_OAK", "MANGROVE", "CHERRY", "PALE_OAK"}) {
String regular = wood + "_BOAT";
String chest = wood + "_CHEST_BOAT";
ENTITY_ITEMS.put(EntityType.valueOf(regular), Material.getMaterial(regular));
ENTITY_ITEMS.put(EntityType.valueOf(chest), Material.getMaterial(chest));
}
ENTITY_ITEMS.put(EntityType.BAMBOO_RAFT, Material.BAMBOO_RAFT);
ENTITY_ITEMS.put(EntityType.BAMBOO_CHEST_RAFT, Material.BAMBOO_CHEST_RAFT);
// preset some tags to a default value, override some of them:
putMaterialTag(Tag.DOORS, MODIFIED_ON_RIGHT);
putMaterialTag(Tag.TRAPDOORS, MODIFIED_ON_RIGHT);
@ -877,6 +886,7 @@ private static void putMaterialTag(Tag<Material> tag, Integer value) {
putMaterialTag(Tag.SHULKER_BOXES, MODIFIED_ON_RIGHT);
putMaterialTag(Tag.ITEMS_BOATS, 0);
putMaterialTag(Tag.ITEMS_CHEST_BOATS, 0);
putMaterialTag(Tag.BANNERS, 0);
putMaterialTag(Tag.SLABS, 0);
putMaterialTag(Tag.PLANKS, 0);
@ -925,8 +935,7 @@ private static void putMaterialTag(Tag<Material> tag, Integer value) {
});
// Check for missing items/blocks
for (Material material : Material.values()) {
if (material.isLegacy()) continue;
Registry.MATERIAL.stream().forEach(material -> {
// Add spawn eggs
if (isSpawnEgg(material)) {
MATERIAL_FLAGS.put(material, 0);
@ -937,7 +946,7 @@ private static void putMaterialTag(Tag<Material> tag, Integer value) {
if (!MATERIAL_FLAGS.containsKey(material)) {
logger.fine("Missing material definition for " + (material.isBlock() ? "block " : "item ") + material.name());
}
}
});
// DAMAGE_EFFECTS.add(PotionEffectType.SPEED);
DAMAGE_EFFECTS.add(PotionEffectType.SLOWNESS);