From 9c47056b46a65a02084035ed3168a62e2db8f344 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 3 Sep 2022 01:03:27 -0400 Subject: [PATCH 01/20] Version 2.6.16-DEV - Support for 1.19.1/2 spawners. --- Compatibility/pom.xml | 2 +- Core/pom.xml | 8 +- .../java/com/songoda/core/nms/NmsManager.java | 16 +- NMS/NMS-API/pom.xml | 2 +- NMS/NMS-v1_10_R1/pom.xml | 2 +- NMS/NMS-v1_11_R1/pom.xml | 2 +- NMS/NMS-v1_12_R1/pom.xml | 2 +- NMS/NMS-v1_13_R1/pom.xml | 2 +- NMS/NMS-v1_13_R2/pom.xml | 2 +- NMS/NMS-v1_14_R1/pom.xml | 2 +- NMS/NMS-v1_15_R1/pom.xml | 2 +- NMS/NMS-v1_16_R1/pom.xml | 2 +- NMS/NMS-v1_16_R2/pom.xml | 2 +- NMS/NMS-v1_16_R3/pom.xml | 2 +- NMS/NMS-v1_17_R1/pom.xml | 2 +- NMS/NMS-v1_18_R1/pom.xml | 2 +- NMS/NMS-v1_18_R2/pom.xml | 2 +- NMS/NMS-v1_19_R1/pom.xml | 2 +- NMS/NMS-v1_19_R1v2/pom.xml | 105 +++++++++ .../core/nms/v1_19_R1v2/anvil/AnvilCore.java | 21 ++ .../anvil/AnvilInventoryCustom.java | 22 ++ .../core/nms/v1_19_R1v2/anvil/AnvilView.java | 215 ++++++++++++++++++ .../anvil/entity/NMSPlayerImpl.java | 13 ++ .../nms/v1_19_R1v2/entity/NMSPlayerImpl.java | 13 ++ .../nms/v1_19_R1v2/nbt/NBTCompoundImpl.java | 208 +++++++++++++++++ .../core/nms/v1_19_R1v2/nbt/NBTCoreImpl.java | 38 ++++ .../nms/v1_19_R1v2/nbt/NBTEntityImpl.java | 66 ++++++ .../core/nms/v1_19_R1v2/nbt/NBTItemImpl.java | 24 ++ .../nms/v1_19_R1v2/nbt/NBTObjectImpl.java | 72 ++++++ .../nms/v1_19_R1v2/world/SItemStackImpl.java | 39 ++++ .../nms/v1_19_R1v2/world/SSpawnerImpl.java | 132 +++++++++++ .../core/nms/v1_19_R1v2/world/SWorldImpl.java | 38 ++++ .../nms/v1_19_R1v2/world/WorldCoreImpl.java | 93 ++++++++ .../world/spawner/BBaseSpawnerImpl.java | 209 +++++++++++++++++ NMS/NMS-v1_8_R1/pom.xml | 2 +- NMS/NMS-v1_8_R2/pom.xml | 2 +- NMS/NMS-v1_8_R3/pom.xml | 2 +- NMS/NMS-v1_9_R1/pom.xml | 2 +- NMS/NMS-v1_9_R2/pom.xml | 2 +- pom.xml | 3 +- 40 files changed, 1350 insertions(+), 27 deletions(-) create mode 100644 NMS/NMS-v1_19_R1v2/pom.xml create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/AnvilCore.java create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/AnvilInventoryCustom.java create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/AnvilView.java create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/entity/NMSPlayerImpl.java create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/entity/NMSPlayerImpl.java create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTCompoundImpl.java create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTCoreImpl.java create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTEntityImpl.java create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTItemImpl.java create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTObjectImpl.java create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SItemStackImpl.java create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SSpawnerImpl.java create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SWorldImpl.java create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/WorldCoreImpl.java create mode 100644 NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/spawner/BBaseSpawnerImpl.java diff --git a/Compatibility/pom.xml b/Compatibility/pom.xml index b0067344..99befc33 100644 --- a/Compatibility/pom.xml +++ b/Compatibility/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../pom.xml diff --git a/Core/pom.xml b/Core/pom.xml index 36c91c7b..ed22e490 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../pom.xml @@ -243,6 +243,12 @@ ${project.version} compile + + ${project.groupId} + SongodaCore-NMS-v1_19_R1v2 + ${project.version} + compile + diff --git a/Core/src/main/java/com/songoda/core/nms/NmsManager.java b/Core/src/main/java/com/songoda/core/nms/NmsManager.java index 7bad334f..b895353a 100644 --- a/Core/src/main/java/com/songoda/core/nms/NmsManager.java +++ b/Core/src/main/java/com/songoda/core/nms/NmsManager.java @@ -12,6 +12,7 @@ import java.util.logging.Logger; public class NmsManager { private static final String serverPackagePath = Bukkit.getServer().getClass().getPackage().getName(); private static final String serverPackageVersion = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1); + private static final String bukkitVersion = Bukkit.getServer().getBukkitVersion().split("-")[0]; private static final NMSPlayer player; private static final AnvilCore anvil; private static final NBTCore nbt; @@ -128,10 +129,17 @@ public class NmsManager { world = new com.songoda.core.nms.v1_18_R2.world.WorldCoreImpl(); break; case "v1_19_R1": - player = new com.songoda.core.nms.v1_19_R1.entity.NMSPlayerImpl(); - anvil = new com.songoda.core.nms.v1_19_R1.anvil.AnvilCore(); - nbt = new com.songoda.core.nms.v1_19_R1.nbt.NBTCoreImpl(); - world = new com.songoda.core.nms.v1_19_R1.world.WorldCoreImpl(); + if (bukkitVersion.endsWith(".0")) { + player = new com.songoda.core.nms.v1_19_R1.entity.NMSPlayerImpl(); + anvil = new com.songoda.core.nms.v1_19_R1.anvil.AnvilCore(); + nbt = new com.songoda.core.nms.v1_19_R1.nbt.NBTCoreImpl(); + world = new com.songoda.core.nms.v1_19_R1.world.WorldCoreImpl(); + }else{ + player = new com.songoda.core.nms.v1_19_R1v2.entity.NMSPlayerImpl(); + anvil = new com.songoda.core.nms.v1_19_R1v2.anvil.AnvilCore(); + nbt = new com.songoda.core.nms.v1_19_R1v2.nbt.NBTCoreImpl(); + world = new com.songoda.core.nms.v1_19_R1v2.world.WorldCoreImpl(); + } break; default: Logger.getLogger(NmsManager.class.getName()).log(Level.SEVERE, "Failed to load NMS for this server version: version {0} not found", serverPackageVersion); diff --git a/NMS/NMS-API/pom.xml b/NMS/NMS-API/pom.xml index 7aafb2fe..11c0556e 100644 --- a/NMS/NMS-API/pom.xml +++ b/NMS/NMS-API/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_10_R1/pom.xml b/NMS/NMS-v1_10_R1/pom.xml index 8cc96fc4..a68d8205 100644 --- a/NMS/NMS-v1_10_R1/pom.xml +++ b/NMS/NMS-v1_10_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_11_R1/pom.xml b/NMS/NMS-v1_11_R1/pom.xml index 0fce2892..c0bd0a52 100644 --- a/NMS/NMS-v1_11_R1/pom.xml +++ b/NMS/NMS-v1_11_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_12_R1/pom.xml b/NMS/NMS-v1_12_R1/pom.xml index 8e92b9d5..a8fd7ffd 100644 --- a/NMS/NMS-v1_12_R1/pom.xml +++ b/NMS/NMS-v1_12_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_13_R1/pom.xml b/NMS/NMS-v1_13_R1/pom.xml index ad14e6d1..5d831267 100644 --- a/NMS/NMS-v1_13_R1/pom.xml +++ b/NMS/NMS-v1_13_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_13_R2/pom.xml b/NMS/NMS-v1_13_R2/pom.xml index 00f73f14..d682e5d3 100644 --- a/NMS/NMS-v1_13_R2/pom.xml +++ b/NMS/NMS-v1_13_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_14_R1/pom.xml b/NMS/NMS-v1_14_R1/pom.xml index d1368bb5..1cf11480 100644 --- a/NMS/NMS-v1_14_R1/pom.xml +++ b/NMS/NMS-v1_14_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_15_R1/pom.xml b/NMS/NMS-v1_15_R1/pom.xml index ff4ee305..cacfaaed 100644 --- a/NMS/NMS-v1_15_R1/pom.xml +++ b/NMS/NMS-v1_15_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_16_R1/pom.xml b/NMS/NMS-v1_16_R1/pom.xml index e330e617..0953a8aa 100644 --- a/NMS/NMS-v1_16_R1/pom.xml +++ b/NMS/NMS-v1_16_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_16_R2/pom.xml b/NMS/NMS-v1_16_R2/pom.xml index 0ab70aa5..c4aff7cf 100644 --- a/NMS/NMS-v1_16_R2/pom.xml +++ b/NMS/NMS-v1_16_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_16_R3/pom.xml b/NMS/NMS-v1_16_R3/pom.xml index 2c852cf0..05ea479a 100644 --- a/NMS/NMS-v1_16_R3/pom.xml +++ b/NMS/NMS-v1_16_R3/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_17_R1/pom.xml b/NMS/NMS-v1_17_R1/pom.xml index 0c23f7ce..b259bf4f 100644 --- a/NMS/NMS-v1_17_R1/pom.xml +++ b/NMS/NMS-v1_17_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_18_R1/pom.xml b/NMS/NMS-v1_18_R1/pom.xml index 22114cc5..118dd72e 100644 --- a/NMS/NMS-v1_18_R1/pom.xml +++ b/NMS/NMS-v1_18_R1/pom.xml @@ -19,7 +19,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_18_R2/pom.xml b/NMS/NMS-v1_18_R2/pom.xml index 33b870ce..7d2b8fd4 100644 --- a/NMS/NMS-v1_18_R2/pom.xml +++ b/NMS/NMS-v1_18_R2/pom.xml @@ -60,7 +60,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_19_R1/pom.xml b/NMS/NMS-v1_19_R1/pom.xml index 78f75627..b3595365 100644 --- a/NMS/NMS-v1_19_R1/pom.xml +++ b/NMS/NMS-v1_19_R1/pom.xml @@ -60,7 +60,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_19_R1v2/pom.xml b/NMS/NMS-v1_19_R1v2/pom.xml new file mode 100644 index 00000000..b03e46a2 --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/pom.xml @@ -0,0 +1,105 @@ + + + 4.0.0 + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + + ${java.release} + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + + remap-obf + package + + remap + + + + org.spigotmc:minecraft-server:${nms.ver}:txt:maps-mojang + true + org.spigotmc:spigot:${nms.ver}:jar:remapped-mojang + true + remapped-obf + + + + + remap-spigot + package + + remap + + + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${nms.ver}:csrg:maps-spigot + org.spigotmc:spigot:${nms.ver}:jar:remapped-obf + + + + + + + + + com.songoda + SongodaCore-Modules + 2.6.16-DEV + ../../pom.xml + + + + 17 + 17 + + 1.19.2-R0.1-SNAPSHOT + + + SongodaCore-NMS-v1_19_R1v2 + jar + + + + org.spigotmc + spigot-api + ${nms.ver} + provided + + + + org.spigotmc + spigot + ${nms.ver} + provided + remapped-mojang + + + + ${project.groupId} + SongodaCore-NMS-API + ${project.version} + + + + ${project.groupId} + SongodaCore-Compatibility + ${project.version} + + + diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/AnvilCore.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/AnvilCore.java new file mode 100644 index 00000000..12c2d06e --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/AnvilCore.java @@ -0,0 +1,21 @@ +package com.songoda.core.nms.v1_19_R1v2.anvil; + +import com.songoda.core.nms.anvil.CustomAnvil; +import net.minecraft.server.level.ServerPlayer; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryHolder; + +public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { + @Override + public CustomAnvil createAnvil(Player player) { + ServerPlayer p = ((CraftPlayer) player).getHandle(); + return new AnvilView(p.nextContainerCounter(), p, null); + } + + @Override + public CustomAnvil createAnvil(Player player, InventoryHolder holder) { + ServerPlayer p = ((CraftPlayer) player).getHandle(); + return new AnvilView(p.nextContainerCounter(), p, holder); + } +} diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/AnvilInventoryCustom.java new file mode 100644 index 00000000..0a207509 --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/AnvilInventoryCustom.java @@ -0,0 +1,22 @@ +package com.songoda.core.nms.v1_19_R1v2.anvil; + +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryAnvil; +import org.bukkit.inventory.InventoryHolder; + +public class AnvilInventoryCustom extends CraftInventoryAnvil { + final InventoryHolder holder; + + public AnvilInventoryCustom(InventoryHolder holder, Location location, Container inventory, Container resultInventory, AnvilMenu container) { + super(location, inventory, resultInventory, container); + + this.holder = holder; + } + + @Override + public InventoryHolder getHolder() { + return holder; + } +} diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/AnvilView.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/AnvilView.java new file mode 100644 index 00000000..d11c8a94 --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/AnvilView.java @@ -0,0 +1,215 @@ +package com.songoda.core.nms.v1_19_R1v2.anvil; + +import com.songoda.core.nms.anvil.CustomAnvil; +import com.songoda.core.nms.anvil.methods.AnvilTextChange; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.contents.TranslatableContents; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.ItemCombinerMenu; +import net.minecraft.world.inventory.MenuType; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryView; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; + +import java.lang.reflect.Field; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class AnvilView extends AnvilMenu implements CustomAnvil { + private final ServerPlayer entity; + private final Inventory inventory; + private String customTitle = "Repairing"; + private int cost = -1; + private boolean canUse = true; + private AnvilTextChange textChange; + + // used for setting custom inventory + static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result + static Field mc_ContainerAnvil_resultInventory; // full inventory + static Field mc_ContainerAnvil_bukkitEntity; + + static { + try { + mc_ContainerAnvil_repairInventory = ItemCombinerMenu.class.getDeclaredField("p"); + mc_ContainerAnvil_repairInventory.setAccessible(true); + + mc_ContainerAnvil_resultInventory = ItemCombinerMenu.class.getDeclaredField("o"); + mc_ContainerAnvil_resultInventory.setAccessible(true); + + mc_ContainerAnvil_bukkitEntity = AnvilMenu.class.getDeclaredField("bukkitEntity"); + mc_ContainerAnvil_bukkitEntity.setAccessible(true); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); + } + } + + // 1.14 also introduced a title field, also private, which can only be set once and can't be checked + static Field mc_Container_title; + + static { + try { + mc_Container_title = AbstractContainerMenu.class.getDeclaredField("title"); + mc_Container_title.setAccessible(true); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); + } + } + + public AnvilView(int id, ServerPlayer entity, InventoryHolder holder) { + super(entity.nextContainerCounter(), entity.getInventory(), ContainerLevelAccess.create(entity.level, new BlockPos(0, 0, 0))); + + this.setTitle(MutableComponent.create(new TranslatableContents(customTitle != null ? customTitle : ""))); + this.checkReachable = false; + this.entity = entity; + + if (holder != null) { + this.inventory = getBukkitView(entity, holder).getTopInventory(); + } else { + this.inventory = getBukkitView().getTopInventory(); + } + } + + public CraftInventoryView getBukkitView(Player player, InventoryHolder holder) { + try { + AnvilInventoryCustom craftInventory = new AnvilInventoryCustom(holder, + new Location(entity.level.getWorld(), 0, 0, 0), + (Container) mc_ContainerAnvil_repairInventory.get(this), + (Container) mc_ContainerAnvil_resultInventory.get(this), this); + CraftInventoryView view = new CraftInventoryView(player.getBukkitEntity(), craftInventory, this); + mc_ContainerAnvil_bukkitEntity.set(this, view); + + return view; + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); + } + + return getBukkitView(); + } + + @Override + public boolean stillValid(Player entityHuman) { + return canUse; + } + + @Override + public void broadcastFullState() { + super.broadcastFullState(); + + if (cost >= 0) { + this.setLevelCost(cost); + } + + textChange.onChange(); + } + + @Override + public void update() { + broadcastFullState(); + } + + @Override + public String getRenameText() { + return this.itemName; + } + + @Override + public void setRenameText(String text) { + this.setItemName(text); + } + + @Override + public void setOnChange(AnvilTextChange handler) { + textChange = handler; + } + + @Override + public String getCustomTitle() { + return customTitle; + } + + @Override + public void setCustomTitle(String title) { + this.customTitle = title; + + try { + mc_Container_title.set(this, MutableComponent.create(new TranslatableContents(customTitle != null ? customTitle : ""))); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex); + } + } + + @Override + public void setLevelCost(int cost) { + this.cost = cost; + } + + @Override + public int getLevelCost() { + if (cost >= 0) { + return cost; + } + + return this.getLevelCost(); + } + + @Override + public void setCanUse(boolean bool) { + this.canUse = bool; + } + + @Override + public ItemStack getLeftInput() { + return inventory.getItem(0); + } + + @Override + public ItemStack getRightInput() { + return inventory.getItem(1); + } + + @Override + public ItemStack getOutput() { + return inventory.getItem(2); + } + + @Override + public void setLeftInput(ItemStack item) { + inventory.setItem(0, item); + } + + @Override + public void setRightInput(ItemStack item) { + inventory.setItem(1, item); + } + + @Override + public void setOutput(ItemStack item) { + inventory.setItem(2, item); + } + + @Override + public Inventory getInventory() { + return inventory; + } + + @Override + public void open() { + // Send the packet + entity.connection.send(new ClientboundOpenScreenPacket(super.containerId, MenuType.ANVIL, MutableComponent.create(new TranslatableContents(customTitle != null ? customTitle : "")))); + + // Set their active container to this anvil + entity.containerMenu = this; + + // Add the slot listener + entity.initMenu(entity.containerMenu); + } +} diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/entity/NMSPlayerImpl.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/entity/NMSPlayerImpl.java new file mode 100644 index 00000000..c3ff06f0 --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/anvil/entity/NMSPlayerImpl.java @@ -0,0 +1,13 @@ +package com.songoda.core.nms.v1_19_R1v2.anvil.entity; + +import com.songoda.core.nms.entity.NMSPlayer; +import net.minecraft.network.protocol.Packet; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +public class NMSPlayerImpl implements NMSPlayer { + @Override + public void sendPacket(Player p, Object packet) { + ((CraftPlayer) p).getHandle().connection.send((Packet) packet); + } +} diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/entity/NMSPlayerImpl.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/entity/NMSPlayerImpl.java new file mode 100644 index 00000000..ce1d0de9 --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/entity/NMSPlayerImpl.java @@ -0,0 +1,13 @@ +package com.songoda.core.nms.v1_19_R1v2.entity; + +import com.songoda.core.nms.entity.NMSPlayer; +import net.minecraft.network.protocol.Packet; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +public class NMSPlayerImpl implements NMSPlayer { + @Override + public void sendPacket(Player p, Object packet) { + ((CraftPlayer) p).getHandle().connection.send((Packet) packet); + } +} diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTCompoundImpl.java new file mode 100644 index 00000000..28255a67 --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTCompoundImpl.java @@ -0,0 +1,208 @@ +package com.songoda.core.nms.v1_19_R1v2.nbt; + +import com.songoda.core.nms.nbt.NBTCompound; +import com.songoda.core.nms.nbt.NBTObject; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtIo; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.Set; +import java.util.UUID; + +public class NBTCompoundImpl implements NBTCompound { + protected CompoundTag compound; + + protected NBTCompoundImpl(CompoundTag compound) { + this.compound = compound; + } + + public NBTCompoundImpl() { + this.compound = new CompoundTag(); + } + + @Override + public NBTCompound set(String tag, String s) { + compound.putString(tag, s); + return this; + } + + @Override + public NBTCompound set(String tag, boolean b) { + compound.putBoolean(tag, b); + return this; + } + + @Override + public NBTCompound set(String tag, int i) { + compound.putInt(tag, i); + return this; + } + + @Override + public NBTCompound set(String tag, double i) { + compound.putDouble(tag, i); + return this; + } + + @Override + public NBTCompound set(String tag, long l) { + compound.putLong(tag, l); + return this; + } + + @Override + public NBTCompound set(String tag, short s) { + compound.putShort(tag, s); + return this; + } + + @Override + public NBTCompound set(String tag, byte b) { + compound.putByte(tag, b); + return this; + } + + @Override + public NBTCompound set(String tag, int[] i) { + compound.putIntArray(tag, i); + return this; + } + + @Override + public NBTCompound set(String tag, byte[] b) { + compound.putByteArray(tag, b); + return this; + } + + @Override + public NBTCompound set(String tag, UUID u) { + compound.putUUID(tag, u); + return this; + } + + @Override + public NBTCompound remove(String tag) { + compound.remove(tag); + return this; + } + + @Override + public boolean has(String tag) { + return compound.contains(tag); + } + + @Override + public NBTObject getNBTObject(String tag) { + return new NBTObjectImpl(compound, tag); + } + + @Override + public String getString(String tag) { + return getNBTObject(tag).asString(); + } + + @Override + public boolean getBoolean(String tag) { + return getNBTObject(tag).asBoolean(); + } + + @Override + public int getInt(String tag) { + return getNBTObject(tag).asInt(); + } + + @Override + public double getDouble(String tag) { + return getNBTObject(tag).asDouble(); + } + + @Override + public long getLong(String tag) { + return getNBTObject(tag).asLong(); + } + + @Override + public short getShort(String tag) { + return getNBTObject(tag).asShort(); + } + + @Override + public byte getByte(String tag) { + return getNBTObject(tag).asByte(); + } + + @Override + public int[] getIntArray(String tag) { + return getNBTObject(tag).asIntArray(); + } + + @Override + public byte[] getByteArray(String tag) { + return getNBTObject(tag).asByteArray(); + } + + @Override + public NBTCompound getCompound(String tag) { + if (has(tag)) { + return getNBTObject(tag).asCompound(); + } + + CompoundTag newCompound = new CompoundTag(); + compound.put(tag, newCompound); + return new NBTCompoundImpl(newCompound); + } + + @Override + public Set getKeys() { + return compound.getAllKeys(); + } + + @Override + public Set getKeys(String tag) { + return compound.getCompound(tag).getAllKeys(); + } + + @Override + public byte[] serialize(String... exclusions) { + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) { + addExtras(); + CompoundTag compound = this.compound.copy(); + + for (String exclusion : exclusions) { + compound.remove(exclusion); + } + + NbtIo.writeCompressed(compound, dataOutput); + + return outputStream.toByteArray(); + } catch (Exception ex) { + ex.printStackTrace(); + } + + return null; + } + + @Override + public void deSerialize(byte[] serialized) { + try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized); + ObjectInputStream dataInput = new ObjectInputStream(inputStream)) { + compound = NbtIo.readCompressed(dataInput); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + @Override + public void addExtras() { + // None + } + + @Override + public String toString() { + return compound.toString(); + } +} diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTCoreImpl.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTCoreImpl.java new file mode 100644 index 00000000..e2edefe2 --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTCoreImpl.java @@ -0,0 +1,38 @@ +package com.songoda.core.nms.v1_19_R1v2.nbt; + +import com.songoda.core.nms.nbt.NBTCore; +import com.songoda.core.nms.nbt.NBTEntity; +import com.songoda.core.nms.nbt.NBTItem; +import net.minecraft.nbt.CompoundTag; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; +import org.bukkit.entity.Entity; +import org.bukkit.inventory.ItemStack; + +public class NBTCoreImpl implements NBTCore { + @Deprecated + @Override + public NBTItem of(ItemStack item) { + return new NBTItemImpl(CraftItemStack.asNMSCopy(item)); + } + + @Deprecated + @Override + public NBTItem newItem() { + return new NBTItemImpl(null); + } + + @Override + public NBTEntity of(Entity entity) { + net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle(); + CompoundTag nbt = new CompoundTag(); + nmsEntity.saveWithoutId(nbt); + + return new NBTEntityImpl(nbt, nmsEntity); + } + + @Override + public NBTEntity newEntity() { + return new NBTEntityImpl(new CompoundTag(), null); + } +} diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTEntityImpl.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTEntityImpl.java new file mode 100644 index 00000000..cdc9c36b --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTEntityImpl.java @@ -0,0 +1,66 @@ +package com.songoda.core.nms.v1_19_R1v2.nbt; + +import com.songoda.core.nms.nbt.NBTEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobSpawnType; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; + +import java.util.Optional; + +public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { + private Entity nmsEntity; + + public NBTEntityImpl(CompoundTag entityNBT, Entity nmsEntity) { + super(entityNBT); + + this.nmsEntity = nmsEntity; + } + + @Override + public org.bukkit.entity.Entity spawn(Location location) { + String entityType = getNBTObject("entity_type").asString(); + + Optional> optionalEntity = EntityType.byString(entityType); + if (optionalEntity.isPresent()) { + assert location.getWorld() != null; + + Entity spawned = optionalEntity.get().spawn( + ((CraftWorld) location.getWorld()).getHandle(), + compound, + null, + null, + new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), + MobSpawnType.COMMAND, + true, + false + ); + + if (spawned != null) { + spawned.load(compound); + org.bukkit.entity.Entity entity = spawned.getBukkitEntity(); + entity.teleport(location); + nmsEntity = spawned; + + return entity; + } + } + + return null; + } + + @Override + public org.bukkit.entity.Entity reSpawn(Location location) { + nmsEntity.discard(); + return spawn(location); + } + + @Override + public void addExtras() { + compound.putString("entity_type", Registry.ENTITY_TYPE.getKey(nmsEntity.getType()).toString()); + } +} diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTItemImpl.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTItemImpl.java new file mode 100644 index 00000000..053dafe9 --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTItemImpl.java @@ -0,0 +1,24 @@ +package com.songoda.core.nms.v1_19_R1v2.nbt; + +import com.songoda.core.nms.nbt.NBTItem; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; + +public class NBTItemImpl extends NBTCompoundImpl implements NBTItem { + private final ItemStack nmsItem; + + public NBTItemImpl(ItemStack nmsItem) { + super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new CompoundTag()); + + this.nmsItem = nmsItem; + } + + public org.bukkit.inventory.ItemStack finish() { + if (nmsItem == null) { + return CraftItemStack.asBukkitCopy(ItemStack.of(compound)); + } + + return CraftItemStack.asBukkitCopy(nmsItem); + } +} diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTObjectImpl.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTObjectImpl.java new file mode 100644 index 00000000..b2a3856a --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTObjectImpl.java @@ -0,0 +1,72 @@ +package com.songoda.core.nms.v1_19_R1v2.nbt; + +import com.songoda.core.nms.nbt.NBTCompound; +import com.songoda.core.nms.nbt.NBTObject; +import net.minecraft.nbt.CompoundTag; + +import java.util.Set; + +public class NBTObjectImpl implements NBTObject { + private final CompoundTag compound; + private final String tag; + + public NBTObjectImpl(CompoundTag compound, String tag) { + this.compound = compound; + this.tag = tag; + } + + @Override + public String asString() { + return compound.getString(tag); + } + + @Override + public boolean asBoolean() { + return compound.getBoolean(tag); + } + + @Override + public int asInt() { + return compound.getInt(tag); + } + + @Override + public double asDouble() { + return compound.getDouble(tag); + } + + @Override + public long asLong() { + return compound.getLong(tag); + } + + @Override + public short asShort() { + return compound.getShort(tag); + } + + @Override + public byte asByte() { + return compound.getByte(tag); + } + + @Override + public int[] asIntArray() { + return compound.getIntArray(tag); + } + + @Override + public byte[] asByteArray() { + return compound.getByteArray(tag); + } + + @Override + public NBTCompound asCompound() { + return new NBTCompoundImpl(compound.getCompound(tag)); + } + + @Override + public Set getKeys() { + return compound.getAllKeys(); + } +} diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SItemStackImpl.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SItemStackImpl.java new file mode 100644 index 00000000..18422c81 --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SItemStackImpl.java @@ -0,0 +1,39 @@ +package com.songoda.core.nms.v1_19_R1v2.world; + +import com.songoda.core.nms.world.SItemStack; +import net.minecraft.core.particles.ItemParticleOption; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.phys.Vec3; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class SItemStackImpl implements SItemStack { + private final ItemStack item; + + public SItemStackImpl(ItemStack item) { + this.item = item; + } + + @Override + public void breakItem(Player player, int amount) { + ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); + + for (int i = 0; i < amount; ++i) { + Vec3 vec3d = new Vec3(((double) random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D); + vec3d = vec3d.xRot(-entityPlayer.getXRot() * 0.017453292F); + vec3d = vec3d.yRot(-entityPlayer.getYRot() * 0.017453292F); + + double d0 = (double) (-random.nextFloat()) * 0.6D - 0.3D; + + Vec3 vec3d1 = new Vec3(((double) random.nextFloat() - 0.5D) * 0.3D, d0, 0.6D); + vec3d1 = vec3d1.xRot(-entityPlayer.getXRot() * 0.017453292F); + vec3d1 = vec3d1.yRot(-entityPlayer.getYRot() * 0.017453292F); + vec3d1 = vec3d1.add(entityPlayer.getX(), entityPlayer.getEyeY(), entityPlayer.getZ()); + + entityPlayer.level.addParticle(new ItemParticleOption(ParticleTypes.ITEM, CraftItemStack.asNMSCopy(item)), vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z); + } + } +} diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SSpawnerImpl.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SSpawnerImpl.java new file mode 100644 index 00000000..ac0c837b --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SSpawnerImpl.java @@ -0,0 +1,132 @@ +package com.songoda.core.nms.v1_19_R1v2.world; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.CompatibleParticleHandler; +import com.songoda.core.nms.world.SSpawner; +import com.songoda.core.nms.world.SpawnedEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.RandomSource; +import net.minecraft.world.DifficultyInstance; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.level.SpawnData; +import org.bukkit.Location; +import org.bukkit.block.BlockFace; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.entity.CreatureSpawnEvent; + +import java.util.Optional; +import java.util.Set; + +public class SSpawnerImpl implements SSpawner { + private final Location spawnerLocation; + + public SSpawnerImpl(Location location) { + this.spawnerLocation = location; + } + + @Override + public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) { + return spawnEntity(type, "EXPLOSION_NORMAL", null, null); + } + + @Override + public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set canSpawnOn) { + SpawnData data = new SpawnData(); + CompoundTag compound = data.getEntityToSpawn(); + + String name = type.name().toLowerCase().replace("snowman", "snow_golem") + .replace("mushroom_cow", "mooshroom"); + compound.putString("id", "minecraft:" + name); + + short spawnRange = 4; + for (int i = 0; i < 50; i++) { + assert spawnerLocation.getWorld() != null; + ServerLevel world = ((CraftWorld) spawnerLocation.getWorld()).getHandle(); + + RandomSource random = world.getRandom(); + double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D; + double y = spawnerLocation.getY() + random.nextInt(3) - 1; + double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D; + + Optional optionalEntity = net.minecraft.world.entity.EntityType.create(compound, world); + if (optionalEntity.isEmpty()) continue; + + Entity entity = optionalEntity.get(); + entity.setPos(x, y, z); + + BlockPos position = entity.blockPosition(); + DifficultyInstance damageScaler = world.getCurrentDifficultyAt(position); + + if (!(entity instanceof Mob entityInsentient)) { + continue; + } + + Location spot = new Location(spawnerLocation.getWorld(), x, y, z); + + if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) { + continue; + } + + entityInsentient.finalizeSpawn(world, damageScaler, MobSpawnType.SPAWNER, null, null); + + LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity(); + + if (spawned != null && !spawned.onSpawn(craftEntity)) { + return null; + } + + if (particleType != null) { + float xx = (float) (0 + (Math.random() * 1)); + float yy = (float) (0 + (Math.random() * 2)); + float zz = (float) (0 + (Math.random() * 1)); + + CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType), spot, 5, xx, yy, zz, 0); + } + + world.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER); + + spot.setYaw(random.nextFloat() * 360.0F); + craftEntity.teleport(spot); + + return craftEntity; + } + + return null; + } + + private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set canSpawnOn) { + if (!world.noCollision(entityInsentient, entityInsentient.getBoundingBox())) { + return false; + } + + CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock()); + CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN)); + + if (spawnedIn == null || spawnedOn == null) { + return false; + } + + if (!spawnedIn.isAir() && + spawnedIn != CompatibleMaterial.WATER && + !spawnedIn.name().contains("PRESSURE") && + !spawnedIn.name().contains("SLAB")) { + return false; + } + + for (CompatibleMaterial material : canSpawnOn) { + if (material == null) continue; + + if (spawnedOn.equals(material) || material.isAir()) { + return true; + } + } + + return false; + } +} diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SWorldImpl.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SWorldImpl.java new file mode 100644 index 00000000..b4944be1 --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SWorldImpl.java @@ -0,0 +1,38 @@ +package com.songoda.core.nms.v1_19_R1v2.world; + +import com.songoda.core.nms.world.SWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.entity.LevelEntityGetter; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; +import org.bukkit.entity.LivingEntity; + +import java.util.ArrayList; +import java.util.List; + +public class SWorldImpl implements SWorld { + private final World world; + + public SWorldImpl(World world) { + this.world = world; + } + + @Override + public List getLivingEntities() { + List result = new ArrayList<>(); + + ServerLevel worldServer = ((CraftWorld) world).getHandle(); + LevelEntityGetter entities = worldServer.entityManager.getEntityGetter(); + + entities.getAll().forEach((mcEnt) -> { + org.bukkit.entity.Entity bukkitEntity = mcEnt.getBukkitEntity(); + + if (bukkitEntity instanceof LivingEntity && bukkitEntity.isValid()) { + result.add((LivingEntity) bukkitEntity); + } + }); + + return result; + } +} diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/WorldCoreImpl.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/WorldCoreImpl.java new file mode 100644 index 00000000..496fa18e --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/WorldCoreImpl.java @@ -0,0 +1,93 @@ +package com.songoda.core.nms.v1_19_R1v2.world; + +import com.songoda.core.nms.ReflectionUtils; +import com.songoda.core.nms.v1_19_R1v2.world.spawner.BBaseSpawnerImpl; +import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; +import com.songoda.core.nms.world.SSpawner; +import com.songoda.core.nms.world.SWorld; +import com.songoda.core.nms.world.WorldCore; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.level.BaseSpawner; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.chunk.LevelChunkSection; +import net.minecraft.world.level.material.FluidState; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.CreatureSpawner; +import org.bukkit.craftbukkit.v1_19_R1.CraftChunk; +import org.bukkit.inventory.ItemStack; + +public class WorldCoreImpl implements WorldCore { + @Override + public SSpawner getSpawner(CreatureSpawner spawner) { + return new SSpawnerImpl(spawner.getLocation()); + } + + @Override + public SSpawner getSpawner(Location location) { + return new SSpawnerImpl(location); + } + + @Override + public SItemStack getItemStack(ItemStack item) { + return new SItemStackImpl(item); + } + + @Override + public SWorld getWorld(World world) { + return new SWorldImpl(world); + } + + @Override + public BBaseSpawner getBaseSpawner(CreatureSpawner spawner) throws NoSuchFieldException, IllegalAccessException { + Object cTileEntity = ReflectionUtils.getFieldValue(spawner, "tileEntity"); + + return new BBaseSpawnerImpl(spawner, (BaseSpawner) ReflectionUtils.getFieldValue(cTileEntity, "a")); + } + + /** + * Method is based on {@link ServerLevel#tickChunk(LevelChunk, int)}. + */ + @Override + public void randomTickChunk(org.bukkit.Chunk bukkitChunk, int tickAmount) { + LevelChunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + ServerLevel world = chunk.q; + ProfilerFiller gameProfilerFiller = world.getProfiler(); + + ChunkPos chunkCoordIntPair = chunk.getPos(); + int j = chunkCoordIntPair.getMinBlockX(); + int k = chunkCoordIntPair.getMinBlockZ(); + + gameProfilerFiller.popPush("tickBlocks"); + if (tickAmount > 0) { + LevelChunkSection[] aChunkSection = chunk.getSections(); + + for (LevelChunkSection chunkSection : aChunkSection) { + if (chunkSection.isRandomlyTicking()) { + int j1 = chunkSection.bottomBlockY(); + + for (int k1 = 0; k1 < tickAmount; ++k1) { + BlockPos blockposition2 = world.getBlockRandomPos(j, j1, k, 15); + gameProfilerFiller.push("randomTick"); + BlockState iBlockData1 = chunkSection.getBlockState(blockposition2.getX() - j, blockposition2.getY() - j1, blockposition2.getZ() - k); + if (iBlockData1.isRandomlyTicking()) { + iBlockData1.randomTick(world, blockposition2, world.random); + } + + FluidState fluid = iBlockData1.getFluidState(); + if (fluid.isRandomlyTicking()) { + fluid.randomTick(world, blockposition2, world.random); + } + + gameProfilerFiller.pop(); + } + } + } + } + } +} diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/spawner/BBaseSpawnerImpl.java new file mode 100644 index 00000000..1bd895bf --- /dev/null +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/spawner/BBaseSpawnerImpl.java @@ -0,0 +1,209 @@ +package com.songoda.core.nms.v1_19_R1v2.world.spawner; + +import com.songoda.core.nms.world.BBaseSpawner; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.RandomSource; +import net.minecraft.world.Difficulty; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.SpawnPlacements; +import net.minecraft.world.level.BaseSpawner; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LightLayer; +import net.minecraft.world.level.SpawnData; +import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.phys.AABB; +import org.bukkit.block.CreatureSpawner; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R1.block.CraftCreatureSpawner; +import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; +import org.bukkit.event.entity.CreatureSpawnEvent; + +import java.util.Iterator; +import java.util.Optional; + +public class BBaseSpawnerImpl implements BBaseSpawner { + private final CreatureSpawner bukkitSpawner; + private final BaseSpawner spawner; + + public BBaseSpawnerImpl(CreatureSpawner bukkitSpawner, BaseSpawner spawner) { + this.bukkitSpawner = bukkitSpawner; + this.spawner = spawner; + } + + /** + * This method is based on {@link BaseSpawner#isNearPlayer(Level, BlockPos)}. + */ + @SuppressWarnings("JavadocReference") + @Override + public boolean isNearPlayer() { + BlockPos bPos = getBlockPosition(); + + return getWorld().hasNearbyAlivePlayer( + (double) bPos.getX() + 0.5, + (double) bPos.getY() + 0.5, + (double) bPos.getZ() + 0.5, + this.spawner.requiredPlayerRange + ); + } + + /** + * This method is based on {@link BaseSpawner#serverTick(ServerLevel, BlockPos)}. + */ + @Override + public void tick() { + ServerLevel world = getWorld(); + BlockPos bPos = getBlockPosition(); + + if (this.spawner.spawnDelay == -1) { + delay(world, bPos); + } + + if (this.spawner.spawnDelay > 0) { + --this.spawner.spawnDelay; + } else { + boolean flag = false; + int i = 0; + + while (true) { + if (i >= this.spawner.spawnCount) { + if (flag) { + delay(world, bPos); + } + break; + } + + CompoundTag nbtTagCompound = this.spawner.nextSpawnData.getEntityToSpawn(); + Optional> optional = EntityType.by(nbtTagCompound); + if (optional.isEmpty()) { + delay(world, bPos); + return; + } + + ListTag nbtTagList = nbtTagCompound.getList("Pos", 6); + int j = nbtTagList.size(); + RandomSource randomsource = world.getRandom(); + double d0 = j >= 1 ? nbtTagList.getDouble(0) : (double) bPos.getX() + (randomsource.nextDouble() - randomsource.nextDouble()) * (double) this.spawner.spawnRange + 0.5; + double d1 = j >= 2 ? nbtTagList.getDouble(1) : (double) (bPos.getY() + randomsource.nextInt(3) - 1); + double d2 = j >= 3 ? nbtTagList.getDouble(2) : (double) bPos.getZ() + (randomsource.nextDouble() - randomsource.nextDouble()) * (double) this.spawner.spawnRange + 0.5; + if (world.noCollision(optional.get().getAABB(d0, d1, d2))) { + label128: + { + BlockPos blockposition1 = new BlockPos(d0, d1, d2); + if (this.spawner.nextSpawnData.getCustomSpawnRules().isPresent()) { + if (!optional.get().getCategory().isFriendly() && world.getDifficulty() == Difficulty.PEACEFUL) { + break label128; + } + + SpawnData.CustomSpawnRules mobSpawnerDataA = this.spawner.nextSpawnData.getCustomSpawnRules().get(); + if (!mobSpawnerDataA.blockLightLimit().isValueInRange(world.getBrightness(LightLayer.BLOCK, blockposition1)) || + !mobSpawnerDataA.skyLightLimit().isValueInRange(world.getBrightness(LightLayer.SKY, blockposition1))) { + break label128; + } + } else if (!SpawnPlacements.checkSpawnRules((EntityType) optional.get(), world, MobSpawnType.SPAWNER, blockposition1, world.getRandom())) { + break label128; + } + + Entity entity = EntityType.loadEntityRecursive(nbtTagCompound, world, (entity1) -> { + entity1.moveTo(d0, d1, d2, entity1.getYRot(), entity1.getXRot()); + return entity1; + }); + if (entity == null) { + delay(world, bPos); + return; + } + + int k = world.getEntitiesOfClass(entity.getClass(), + new AABB(bPos.getX(), + bPos.getY(), + bPos.getZ(), + bPos.getX() + 1, + bPos.getY() + 1, + bPos.getZ() + 1).inflate(this.spawner.spawnRange) + ).size(); + if (k >= this.spawner.maxNearbyEntities) { + delay(world, bPos); + return; + } + + entity.moveTo(entity.getX(), entity.getY(), entity.getZ(), randomsource.nextFloat() * 360.0F, 0.0F); + if (entity instanceof Mob) { + Mob entityInsentient = (Mob) entity; + if (this.spawner.nextSpawnData.getCustomSpawnRules().isEmpty() && !entityInsentient.checkSpawnRules(world, MobSpawnType.SPAWNER) || !entityInsentient.checkSpawnObstruction(world)) { + break label128; + } + + if (this.spawner.nextSpawnData.getEntityToSpawn().size() == 1 && this.spawner.nextSpawnData.getEntityToSpawn().contains("id", 8)) { + ((Mob) entity).finalizeSpawn(world, world.getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.SPAWNER, null, null); + } + + if (entityInsentient.level.spigotConfig.nerfSpawnerMobs) { + entityInsentient.aware = false; + } + } + + if (CraftEventFactory.callSpawnerSpawnEvent(entity, bPos).isCancelled()) { + Entity vehicle = entity.getVehicle(); + if (vehicle != null) { + vehicle.discard(); + } + + Iterator var21 = entity.getIndirectPassengers().iterator(); + + while (var21.hasNext()) { + Entity passenger = (Entity) var21.next(); + passenger.discard(); + } + } else { + if (!world.tryAddFreshEntityWithPassengers(entity, CreatureSpawnEvent.SpawnReason.SPAWNER)) { + delay(world, bPos); + return; + } + + world.levelEvent(2004, bPos, 0); + world.gameEvent(entity, GameEvent.ENTITY_PLACE, blockposition1); + if (entity instanceof Mob) { + ((Mob) entity).spawnAnim(); + } + + flag = true; + } + } + } + + ++i; + } + } + } + + /** + * This method is based on {@link BaseSpawner#delay(Level, BlockPos)}. + */ + @SuppressWarnings("JavadocReference") + private void delay(ServerLevel world, BlockPos bPos) { + RandomSource randomsource = world.random; + if (this.spawner.maxSpawnDelay <= this.spawner.minSpawnDelay) { + this.spawner.spawnDelay = this.spawner.minSpawnDelay; + } else { + this.spawner.spawnDelay = this.spawner.minSpawnDelay + randomsource.nextInt(this.spawner.maxSpawnDelay - this.spawner.minSpawnDelay); + } + + this.spawner.spawnPotentials.getRandom(randomsource).ifPresent((weightedEntryB) -> { + this.spawner.setNextSpawnData(world, bPos, weightedEntryB.getData()); + }); + this.spawner.broadcastEvent(world, bPos, 1); + } + + private ServerLevel getWorld() { + return ((CraftWorld) this.bukkitSpawner.getWorld()).getHandle(); + } + + private BlockPos getBlockPosition() { + return ((CraftCreatureSpawner) this.bukkitSpawner).getPosition(); + } +} diff --git a/NMS/NMS-v1_8_R1/pom.xml b/NMS/NMS-v1_8_R1/pom.xml index f7c9de3f..f7b7c12b 100644 --- a/NMS/NMS-v1_8_R1/pom.xml +++ b/NMS/NMS-v1_8_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_8_R2/pom.xml b/NMS/NMS-v1_8_R2/pom.xml index d071b5cf..700bb6f2 100644 --- a/NMS/NMS-v1_8_R2/pom.xml +++ b/NMS/NMS-v1_8_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_8_R3/pom.xml b/NMS/NMS-v1_8_R3/pom.xml index e057e154..9257a5eb 100644 --- a/NMS/NMS-v1_8_R3/pom.xml +++ b/NMS/NMS-v1_8_R3/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_9_R1/pom.xml b/NMS/NMS-v1_9_R1/pom.xml index 602d360f..71888378 100644 --- a/NMS/NMS-v1_9_R1/pom.xml +++ b/NMS/NMS-v1_9_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/NMS/NMS-v1_9_R2/pom.xml b/NMS/NMS-v1_9_R2/pom.xml index 573c86a0..b8d7db27 100644 --- a/NMS/NMS-v1_9_R2/pom.xml +++ b/NMS/NMS-v1_9_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV ../../pom.xml diff --git a/pom.xml b/pom.xml index fdd7f8bf..12247748 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.songoda SongodaCore-Modules - 2.6.15-DEV + 2.6.16-DEV pom @@ -47,6 +47,7 @@ NMS/NMS-v1_18_R1 NMS/NMS-v1_18_R2 NMS/NMS-v1_19_R1 + NMS/NMS-v1_19_R1v2 From 4800d6982910e535ecf9407ffb03cb683935699c Mon Sep 17 00:00:00 2001 From: l3st4tDevelopment Date: Sat, 3 Sep 2022 03:01:17 -0400 Subject: [PATCH 02/20] Add 1.19.2 to workflow --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 8692e5b7..6d6ccbe7 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -27,7 +27,7 @@ jobs: # Build remapped Spigot versions - uses: SpraxDev/Action-SpigotMC@v4 with: - versions: 1.18.2, 1.19 + versions: 1.18.2, 1.19, 1.19.2 remapped: true # Build project From d51f72977b90eba5e787cfced882daac8f9e69e1 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Sun, 4 Sep 2022 19:24:50 +0200 Subject: [PATCH 03/20] GitHub-Actions: Force Spigot 1.19.2 recompilation The non-mapped version is currently cached and thus not getting recompiled. This is a temporary *fix* for that --- .github/workflows/maven.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 6d6ccbe7..9fcc74c2 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,6 +29,7 @@ jobs: with: versions: 1.18.2, 1.19, 1.19.2 remapped: true + forceRun: true # Build project - name: Build with Maven From e3b275b40dcf7610ede92b111f09bb141a844241 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Sun, 4 Sep 2022 19:31:58 +0200 Subject: [PATCH 04/20] Release v2.6.16 --- Compatibility/pom.xml | 2 +- Core/pom.xml | 2 +- Core/src/main/java/com/songoda/core/SongodaCore.java | 2 +- NMS/NMS-API/pom.xml | 2 +- NMS/NMS-v1_10_R1/pom.xml | 2 +- NMS/NMS-v1_11_R1/pom.xml | 2 +- NMS/NMS-v1_12_R1/pom.xml | 2 +- NMS/NMS-v1_13_R1/pom.xml | 2 +- NMS/NMS-v1_13_R2/pom.xml | 2 +- NMS/NMS-v1_14_R1/pom.xml | 2 +- NMS/NMS-v1_15_R1/pom.xml | 2 +- NMS/NMS-v1_16_R1/pom.xml | 2 +- NMS/NMS-v1_16_R2/pom.xml | 2 +- NMS/NMS-v1_16_R3/pom.xml | 2 +- NMS/NMS-v1_17_R1/pom.xml | 2 +- NMS/NMS-v1_18_R1/pom.xml | 2 +- NMS/NMS-v1_18_R2/pom.xml | 2 +- NMS/NMS-v1_19_R1/pom.xml | 2 +- NMS/NMS-v1_19_R1v2/pom.xml | 2 +- NMS/NMS-v1_8_R1/pom.xml | 2 +- NMS/NMS-v1_8_R2/pom.xml | 2 +- NMS/NMS-v1_8_R3/pom.xml | 2 +- NMS/NMS-v1_9_R1/pom.xml | 2 +- NMS/NMS-v1_9_R2/pom.xml | 2 +- pom.xml | 2 +- 25 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Compatibility/pom.xml b/Compatibility/pom.xml index 99befc33..10dff5ca 100644 --- a/Compatibility/pom.xml +++ b/Compatibility/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../pom.xml diff --git a/Core/pom.xml b/Core/pom.xml index ed22e490..81754cd5 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../pom.xml diff --git a/Core/src/main/java/com/songoda/core/SongodaCore.java b/Core/src/main/java/com/songoda/core/SongodaCore.java index 3dda7c0e..edd3421f 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCore.java +++ b/Core/src/main/java/com/songoda/core/SongodaCore.java @@ -53,7 +53,7 @@ public class SongodaCore { /** * @since coreRevision 6 */ - private final static String coreVersion = "2.6.14-DEV"; + private final static String coreVersion = "2.6.16"; /** * This is specific to the website api diff --git a/NMS/NMS-API/pom.xml b/NMS/NMS-API/pom.xml index 11c0556e..c242b25a 100644 --- a/NMS/NMS-API/pom.xml +++ b/NMS/NMS-API/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_10_R1/pom.xml b/NMS/NMS-v1_10_R1/pom.xml index a68d8205..c84341db 100644 --- a/NMS/NMS-v1_10_R1/pom.xml +++ b/NMS/NMS-v1_10_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_11_R1/pom.xml b/NMS/NMS-v1_11_R1/pom.xml index c0bd0a52..06747819 100644 --- a/NMS/NMS-v1_11_R1/pom.xml +++ b/NMS/NMS-v1_11_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_12_R1/pom.xml b/NMS/NMS-v1_12_R1/pom.xml index a8fd7ffd..dc6a06c8 100644 --- a/NMS/NMS-v1_12_R1/pom.xml +++ b/NMS/NMS-v1_12_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_13_R1/pom.xml b/NMS/NMS-v1_13_R1/pom.xml index 5d831267..cba76fb4 100644 --- a/NMS/NMS-v1_13_R1/pom.xml +++ b/NMS/NMS-v1_13_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_13_R2/pom.xml b/NMS/NMS-v1_13_R2/pom.xml index d682e5d3..f230ae59 100644 --- a/NMS/NMS-v1_13_R2/pom.xml +++ b/NMS/NMS-v1_13_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_14_R1/pom.xml b/NMS/NMS-v1_14_R1/pom.xml index 1cf11480..804e8a9a 100644 --- a/NMS/NMS-v1_14_R1/pom.xml +++ b/NMS/NMS-v1_14_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_15_R1/pom.xml b/NMS/NMS-v1_15_R1/pom.xml index cacfaaed..696b50a0 100644 --- a/NMS/NMS-v1_15_R1/pom.xml +++ b/NMS/NMS-v1_15_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_16_R1/pom.xml b/NMS/NMS-v1_16_R1/pom.xml index 0953a8aa..f101eb83 100644 --- a/NMS/NMS-v1_16_R1/pom.xml +++ b/NMS/NMS-v1_16_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_16_R2/pom.xml b/NMS/NMS-v1_16_R2/pom.xml index c4aff7cf..96bb63fa 100644 --- a/NMS/NMS-v1_16_R2/pom.xml +++ b/NMS/NMS-v1_16_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_16_R3/pom.xml b/NMS/NMS-v1_16_R3/pom.xml index 05ea479a..7069f4a6 100644 --- a/NMS/NMS-v1_16_R3/pom.xml +++ b/NMS/NMS-v1_16_R3/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_17_R1/pom.xml b/NMS/NMS-v1_17_R1/pom.xml index b259bf4f..10b7af90 100644 --- a/NMS/NMS-v1_17_R1/pom.xml +++ b/NMS/NMS-v1_17_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_18_R1/pom.xml b/NMS/NMS-v1_18_R1/pom.xml index 118dd72e..46303b82 100644 --- a/NMS/NMS-v1_18_R1/pom.xml +++ b/NMS/NMS-v1_18_R1/pom.xml @@ -19,7 +19,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_18_R2/pom.xml b/NMS/NMS-v1_18_R2/pom.xml index 7d2b8fd4..eaa8147a 100644 --- a/NMS/NMS-v1_18_R2/pom.xml +++ b/NMS/NMS-v1_18_R2/pom.xml @@ -60,7 +60,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_19_R1/pom.xml b/NMS/NMS-v1_19_R1/pom.xml index b3595365..760111c5 100644 --- a/NMS/NMS-v1_19_R1/pom.xml +++ b/NMS/NMS-v1_19_R1/pom.xml @@ -60,7 +60,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_19_R1v2/pom.xml b/NMS/NMS-v1_19_R1v2/pom.xml index b03e46a2..f4bc6f69 100644 --- a/NMS/NMS-v1_19_R1v2/pom.xml +++ b/NMS/NMS-v1_19_R1v2/pom.xml @@ -60,7 +60,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_8_R1/pom.xml b/NMS/NMS-v1_8_R1/pom.xml index f7b7c12b..c801ffed 100644 --- a/NMS/NMS-v1_8_R1/pom.xml +++ b/NMS/NMS-v1_8_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_8_R2/pom.xml b/NMS/NMS-v1_8_R2/pom.xml index 700bb6f2..e3977c88 100644 --- a/NMS/NMS-v1_8_R2/pom.xml +++ b/NMS/NMS-v1_8_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_8_R3/pom.xml b/NMS/NMS-v1_8_R3/pom.xml index 9257a5eb..4f4b8938 100644 --- a/NMS/NMS-v1_8_R3/pom.xml +++ b/NMS/NMS-v1_8_R3/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_9_R1/pom.xml b/NMS/NMS-v1_9_R1/pom.xml index 71888378..65ab22c2 100644 --- a/NMS/NMS-v1_9_R1/pom.xml +++ b/NMS/NMS-v1_9_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/NMS/NMS-v1_9_R2/pom.xml b/NMS/NMS-v1_9_R2/pom.xml index b8d7db27..cb6bea89 100644 --- a/NMS/NMS-v1_9_R2/pom.xml +++ b/NMS/NMS-v1_9_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 ../../pom.xml diff --git a/pom.xml b/pom.xml index 12247748..c7fc73b5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.songoda SongodaCore-Modules - 2.6.16-DEV + 2.6.16 pom From 954c5024a95bb9f446fb10f50c211889ebc75831 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Sun, 4 Sep 2022 19:43:28 +0200 Subject: [PATCH 05/20] Reverts 'GitHub-Actions: Force Spigot 1.19.2 recompilation' d51f72977b90eba5e787cfced882daac8f9e69e1 --- .github/workflows/maven.yml | 1 - .github/workflows/sonarcloud.yml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9fcc74c2..6d6ccbe7 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,7 +29,6 @@ jobs: with: versions: 1.18.2, 1.19, 1.19.2 remapped: true - forceRun: true # Build project - name: Build with Maven diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index e5e004ee..366d17cb 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -38,7 +38,7 @@ jobs: # Build remapped Spigot versions - uses: SpraxDev/Action-SpigotMC@v4 with: - versions: 1.18.2, 1.19 + versions: 1.18.2, 1.19, 1.19.2 remapped: true - name: Analyze project From d11b32d8ea3597b1d23f3286118eb73ca9f18705 Mon Sep 17 00:00:00 2001 From: ceze88 Date: Mon, 19 Sep 2022 20:36:38 +0200 Subject: [PATCH 06/20] Update UltimateStacker version --- Core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/pom.xml b/Core/pom.xml index 81754cd5..14751f6b 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -311,7 +311,7 @@ com.songoda UltimateStacker - 2.1.1 + 2.3.1-Dev provided From 30d070cade1a6a9241bafa4f51e266ee4db4ec1f Mon Sep 17 00:00:00 2001 From: ceze88 Date: Mon, 19 Sep 2022 20:37:34 +0200 Subject: [PATCH 07/20] Drop items stacked when UltimateStacker is present --- .../core/lootables/loot/DropUtils.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java b/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java index ebc5d03d..d0724d42 100644 --- a/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java +++ b/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java @@ -1,12 +1,18 @@ package com.songoda.core.lootables.loot; +import com.songoda.core.SongodaCore; +import com.songoda.ultimatestacker.UltimateStacker; import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; + +import static com.songoda.core.hooks.PluginHook.STACKER_ULTIMATE; public class DropUtils { public static void processStackedDrop(LivingEntity entity, List drops, EntityDeathEvent event) { @@ -63,6 +69,22 @@ public class DropUtils { } private static void dropItems(List items, EntityDeathEvent event) { + //Pre stack items + if (SongodaCore.isRegistered("UltimateStacker")) { + Map stacks = new HashMap<>(); + //Check if stacks contains the item, if so update the amount + for (ItemStack item : items) { + if (stacks.containsKey(item)) { + stacks.put(item, stacks.get(item) + item.getAmount()); + } else { + stacks.put(item, item.getAmount()); + } + } + //Spawn stacked items by UltimateStacker + for (Map.Entry entry : stacks.entrySet()) { + UltimateStacker.spawnStackedItem(entry.getKey(), entry.getValue(), event.getEntity().getLocation()); + } + } for (ItemStack item : items) { event.getDrops().add(item); } From 92c653d9beb71d7374d4b058032aa866824785bc Mon Sep 17 00:00:00 2001 From: ceze88 Date: Mon, 19 Sep 2022 21:04:52 +0200 Subject: [PATCH 08/20] Add max stack size check when pre-stack items with US --- .../core/lootables/loot/DropUtils.java | 58 +++++++++++++++---- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java b/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java index d0724d42..1eaf4ff5 100644 --- a/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java +++ b/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java @@ -2,10 +2,13 @@ package com.songoda.core.lootables.loot; import com.songoda.core.SongodaCore; import com.songoda.ultimatestacker.UltimateStacker; +import com.songoda.ultimatestacker.settings.Settings; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; import java.util.HashMap; @@ -69,21 +72,33 @@ public class DropUtils { } private static void dropItems(List items, EntityDeathEvent event) { - //Pre stack items if (SongodaCore.isRegistered("UltimateStacker")) { - Map stacks = new HashMap<>(); - //Check if stacks contains the item, if so update the amount + List stacks = new ArrayList<>(); for (ItemStack item : items) { - if (stacks.containsKey(item)) { - stacks.put(item, stacks.get(item) + item.getAmount()); - } else { - stacks.put(item, item.getAmount()); + if (stacks.isEmpty()) { + stacks.add(new StackedItem(item, item.getAmount())); + continue; + } + for (StackedItem stackedItem : stacks) { + if (stackedItem.getMaterial().equals(item.getType())) { + int newAmount = stackedItem.getAmount() + item.getAmount(); + int maxSize = Settings.MAX_STACK_ITEMS.getInt(); + while (newAmount > maxSize) { + newAmount -= maxSize; + stacks.add(new StackedItem(item, newAmount)); + } + if (newAmount > 0) { + stacks.add(new StackedItem(item, newAmount)); + } + } else { + stacks.add(new StackedItem(item, item.getAmount())); + } } } - //Spawn stacked items by UltimateStacker - for (Map.Entry entry : stacks.entrySet()) { - UltimateStacker.spawnStackedItem(entry.getKey(), entry.getValue(), event.getEntity().getLocation()); + for (StackedItem stack : stacks) { + UltimateStacker.spawnStackedItem(stack.getItem(), stack.getAmount(), event.getEntity().getLocation()); } + return; } for (ItemStack item : items) { event.getDrops().add(item); @@ -101,4 +116,27 @@ public class DropUtils { } } } + + private static class StackedItem { + + private final ItemStack item; + private final int amount; + + public StackedItem(ItemStack item, int amount) { + this.item = item; + this.amount = amount; + } + + public Material getMaterial() { + return item.getType(); + } + + public ItemStack getItem() { + return item; + } + + public int getAmount() { + return amount; + } + } } From 5f43578869349b948097821b683a58292f89d4cd Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Wed, 26 Oct 2022 21:57:39 +0200 Subject: [PATCH 09/20] Fix NoSuchFieldError on Paper-Spigot 1.19.2 for SWorld#getLivingEntities The field does not exist on Spigot (located in another class?). But `#getEntities()` does exactly what we need and Paper-Spigot still has it. SD-9374 SD-9377 SD-9392 SD-9401 --- Core/src/main/java/com/songoda/core/nms/NmsManager.java | 2 +- .../java/com/songoda/core/nms/v1_19_R1/world/SWorldImpl.java | 2 +- .../java/com/songoda/core/nms/v1_19_R1v2/world/SWorldImpl.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/nms/NmsManager.java b/Core/src/main/java/com/songoda/core/nms/NmsManager.java index b895353a..ee047a6b 100644 --- a/Core/src/main/java/com/songoda/core/nms/NmsManager.java +++ b/Core/src/main/java/com/songoda/core/nms/NmsManager.java @@ -134,7 +134,7 @@ public class NmsManager { anvil = new com.songoda.core.nms.v1_19_R1.anvil.AnvilCore(); nbt = new com.songoda.core.nms.v1_19_R1.nbt.NBTCoreImpl(); world = new com.songoda.core.nms.v1_19_R1.world.WorldCoreImpl(); - }else{ + } else { player = new com.songoda.core.nms.v1_19_R1v2.entity.NMSPlayerImpl(); anvil = new com.songoda.core.nms.v1_19_R1v2.anvil.AnvilCore(); nbt = new com.songoda.core.nms.v1_19_R1v2.nbt.NBTCoreImpl(); diff --git a/NMS/NMS-v1_19_R1/src/main/java/com/songoda/core/nms/v1_19_R1/world/SWorldImpl.java b/NMS/NMS-v1_19_R1/src/main/java/com/songoda/core/nms/v1_19_R1/world/SWorldImpl.java index 0706be94..d04a5e36 100644 --- a/NMS/NMS-v1_19_R1/src/main/java/com/songoda/core/nms/v1_19_R1/world/SWorldImpl.java +++ b/NMS/NMS-v1_19_R1/src/main/java/com/songoda/core/nms/v1_19_R1/world/SWorldImpl.java @@ -23,7 +23,7 @@ public class SWorldImpl implements SWorld { List result = new ArrayList<>(); ServerLevel worldServer = ((CraftWorld) world).getHandle(); - LevelEntityGetter entities = worldServer.entityManager.getEntityGetter(); + LevelEntityGetter entities = worldServer.getEntities(); entities.getAll().forEach((mcEnt) -> { org.bukkit.entity.Entity bukkitEntity = mcEnt.getBukkitEntity(); diff --git a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SWorldImpl.java b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SWorldImpl.java index b4944be1..7ca2e85c 100644 --- a/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SWorldImpl.java +++ b/NMS/NMS-v1_19_R1v2/src/main/java/com/songoda/core/nms/v1_19_R1v2/world/SWorldImpl.java @@ -23,7 +23,7 @@ public class SWorldImpl implements SWorld { List result = new ArrayList<>(); ServerLevel worldServer = ((CraftWorld) world).getHandle(); - LevelEntityGetter entities = worldServer.entityManager.getEntityGetter(); + LevelEntityGetter entities = worldServer.getEntities(); entities.getAll().forEach((mcEnt) -> { org.bukkit.entity.Entity bukkitEntity = mcEnt.getBukkitEntity(); From 500ac98f8471e0454acabbe7e3857ba58d41a972 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Wed, 26 Oct 2022 21:59:06 +0200 Subject: [PATCH 10/20] Release 2.6.17-SNAPSHOT --- Compatibility/pom.xml | 2 +- Core/pom.xml | 2 +- NMS/NMS-API/pom.xml | 2 +- NMS/NMS-v1_10_R1/pom.xml | 2 +- NMS/NMS-v1_11_R1/pom.xml | 2 +- NMS/NMS-v1_12_R1/pom.xml | 2 +- NMS/NMS-v1_13_R1/pom.xml | 2 +- NMS/NMS-v1_13_R2/pom.xml | 2 +- NMS/NMS-v1_14_R1/pom.xml | 2 +- NMS/NMS-v1_15_R1/pom.xml | 2 +- NMS/NMS-v1_16_R1/pom.xml | 2 +- NMS/NMS-v1_16_R2/pom.xml | 2 +- NMS/NMS-v1_16_R3/pom.xml | 2 +- NMS/NMS-v1_17_R1/pom.xml | 2 +- NMS/NMS-v1_18_R1/pom.xml | 2 +- NMS/NMS-v1_18_R2/pom.xml | 2 +- NMS/NMS-v1_19_R1/pom.xml | 2 +- NMS/NMS-v1_19_R1v2/pom.xml | 2 +- NMS/NMS-v1_8_R1/pom.xml | 2 +- NMS/NMS-v1_8_R2/pom.xml | 2 +- NMS/NMS-v1_8_R3/pom.xml | 2 +- NMS/NMS-v1_9_R1/pom.xml | 2 +- NMS/NMS-v1_9_R2/pom.xml | 2 +- pom.xml | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Compatibility/pom.xml b/Compatibility/pom.xml index 10dff5ca..af8d3107 100644 --- a/Compatibility/pom.xml +++ b/Compatibility/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../pom.xml diff --git a/Core/pom.xml b/Core/pom.xml index 14751f6b..d8c01b8e 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../pom.xml diff --git a/NMS/NMS-API/pom.xml b/NMS/NMS-API/pom.xml index c242b25a..bceeb0f4 100644 --- a/NMS/NMS-API/pom.xml +++ b/NMS/NMS-API/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_10_R1/pom.xml b/NMS/NMS-v1_10_R1/pom.xml index c84341db..451b740f 100644 --- a/NMS/NMS-v1_10_R1/pom.xml +++ b/NMS/NMS-v1_10_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_11_R1/pom.xml b/NMS/NMS-v1_11_R1/pom.xml index 06747819..f8b2a361 100644 --- a/NMS/NMS-v1_11_R1/pom.xml +++ b/NMS/NMS-v1_11_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_12_R1/pom.xml b/NMS/NMS-v1_12_R1/pom.xml index dc6a06c8..51f573fc 100644 --- a/NMS/NMS-v1_12_R1/pom.xml +++ b/NMS/NMS-v1_12_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_13_R1/pom.xml b/NMS/NMS-v1_13_R1/pom.xml index cba76fb4..3547dda3 100644 --- a/NMS/NMS-v1_13_R1/pom.xml +++ b/NMS/NMS-v1_13_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_13_R2/pom.xml b/NMS/NMS-v1_13_R2/pom.xml index f230ae59..a9e96a65 100644 --- a/NMS/NMS-v1_13_R2/pom.xml +++ b/NMS/NMS-v1_13_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_14_R1/pom.xml b/NMS/NMS-v1_14_R1/pom.xml index 804e8a9a..2b3b7c5a 100644 --- a/NMS/NMS-v1_14_R1/pom.xml +++ b/NMS/NMS-v1_14_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_15_R1/pom.xml b/NMS/NMS-v1_15_R1/pom.xml index 696b50a0..a4afd62e 100644 --- a/NMS/NMS-v1_15_R1/pom.xml +++ b/NMS/NMS-v1_15_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_16_R1/pom.xml b/NMS/NMS-v1_16_R1/pom.xml index f101eb83..800b3eb1 100644 --- a/NMS/NMS-v1_16_R1/pom.xml +++ b/NMS/NMS-v1_16_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_16_R2/pom.xml b/NMS/NMS-v1_16_R2/pom.xml index 96bb63fa..6954493c 100644 --- a/NMS/NMS-v1_16_R2/pom.xml +++ b/NMS/NMS-v1_16_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_16_R3/pom.xml b/NMS/NMS-v1_16_R3/pom.xml index 7069f4a6..56a64bdc 100644 --- a/NMS/NMS-v1_16_R3/pom.xml +++ b/NMS/NMS-v1_16_R3/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_17_R1/pom.xml b/NMS/NMS-v1_17_R1/pom.xml index 10b7af90..c02142fd 100644 --- a/NMS/NMS-v1_17_R1/pom.xml +++ b/NMS/NMS-v1_17_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_18_R1/pom.xml b/NMS/NMS-v1_18_R1/pom.xml index 46303b82..9a15e72e 100644 --- a/NMS/NMS-v1_18_R1/pom.xml +++ b/NMS/NMS-v1_18_R1/pom.xml @@ -19,7 +19,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_18_R2/pom.xml b/NMS/NMS-v1_18_R2/pom.xml index eaa8147a..1fec2de7 100644 --- a/NMS/NMS-v1_18_R2/pom.xml +++ b/NMS/NMS-v1_18_R2/pom.xml @@ -60,7 +60,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_19_R1/pom.xml b/NMS/NMS-v1_19_R1/pom.xml index 760111c5..dfff442a 100644 --- a/NMS/NMS-v1_19_R1/pom.xml +++ b/NMS/NMS-v1_19_R1/pom.xml @@ -60,7 +60,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_19_R1v2/pom.xml b/NMS/NMS-v1_19_R1v2/pom.xml index f4bc6f69..4de592fb 100644 --- a/NMS/NMS-v1_19_R1v2/pom.xml +++ b/NMS/NMS-v1_19_R1v2/pom.xml @@ -60,7 +60,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_8_R1/pom.xml b/NMS/NMS-v1_8_R1/pom.xml index c801ffed..c0670602 100644 --- a/NMS/NMS-v1_8_R1/pom.xml +++ b/NMS/NMS-v1_8_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_8_R2/pom.xml b/NMS/NMS-v1_8_R2/pom.xml index e3977c88..d8a20f1f 100644 --- a/NMS/NMS-v1_8_R2/pom.xml +++ b/NMS/NMS-v1_8_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_8_R3/pom.xml b/NMS/NMS-v1_8_R3/pom.xml index 4f4b8938..e612e1c1 100644 --- a/NMS/NMS-v1_8_R3/pom.xml +++ b/NMS/NMS-v1_8_R3/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_9_R1/pom.xml b/NMS/NMS-v1_9_R1/pom.xml index 65ab22c2..64902dd8 100644 --- a/NMS/NMS-v1_9_R1/pom.xml +++ b/NMS/NMS-v1_9_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/NMS/NMS-v1_9_R2/pom.xml b/NMS/NMS-v1_9_R2/pom.xml index cb6bea89..58539a26 100644 --- a/NMS/NMS-v1_9_R2/pom.xml +++ b/NMS/NMS-v1_9_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT ../../pom.xml diff --git a/pom.xml b/pom.xml index c7fc73b5..e4f4dbfc 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.songoda SongodaCore-Modules - 2.6.16 + 2.6.17-SNAPSHOT pom From 31fde88c334c41e7e78f607e7b6b4cad0f71a30c Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Wed, 26 Oct 2022 22:59:00 +0200 Subject: [PATCH 11/20] Fix ConcurrentModificationException in DropUtils for UltimateStacker Related to 92c653d9beb71d7374d4b058032aa866824785bc --- .../java/com/songoda/core/lootables/loot/DropUtils.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java b/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java index 1eaf4ff5..4e8e7b72 100644 --- a/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java +++ b/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java @@ -8,14 +8,9 @@ import org.bukkit.Material; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; - -import static com.songoda.core.hooks.PluginHook.STACKER_ULTIMATE; public class DropUtils { public static void processStackedDrop(LivingEntity entity, List drops, EntityDeathEvent event) { @@ -79,7 +74,7 @@ public class DropUtils { stacks.add(new StackedItem(item, item.getAmount())); continue; } - for (StackedItem stackedItem : stacks) { + for (StackedItem stackedItem : stacks.toArray(new StackedItem[0])) { if (stackedItem.getMaterial().equals(item.getType())) { int newAmount = stackedItem.getAmount() + item.getAmount(); int maxSize = Settings.MAX_STACK_ITEMS.getInt(); From e8c0e21ac2ddd7b0a0f9eac1068d1e9d0922fe70 Mon Sep 17 00:00:00 2001 From: ceze88 Date: Fri, 4 Nov 2022 12:28:20 +0100 Subject: [PATCH 12/20] Adds suppoert for PlotSquared and MariaDB for SQL --- Core/pom.xml | 36 ++++++++++ .../core/database/MariaDBConnector.java | 65 +++++++++++++++++++ .../protection/PlotSquaredProtection.java | 43 ++++++++++++ pom.xml | 10 +++ 4 files changed, 154 insertions(+) create mode 100644 Core/src/main/java/com/songoda/core/database/MariaDBConnector.java create mode 100644 Core/src/main/java/com/songoda/core/hooks/protection/PlotSquaredProtection.java diff --git a/Core/pom.xml b/Core/pom.xml index d8c01b8e..0c7df925 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -98,6 +98,18 @@ + + + + com.intellectualsites.bom + bom-1.18.x + 1.18 + import + pom + + + + org.spigotmc @@ -371,6 +383,24 @@ provided + + com.plotsquared + PlotSquared-Core + provided + + + + com.plotsquared + PlotSquared-Bukkit + provided + + + PlotSquared-Core + * + + + + com.songoda UltimateClaims @@ -437,6 +467,12 @@ 3.2.0 + + org.mariadb.jdbc + mariadb-java-client + 3.0.8 + + org.xerial sqlite-jdbc diff --git a/Core/src/main/java/com/songoda/core/database/MariaDBConnector.java b/Core/src/main/java/com/songoda/core/database/MariaDBConnector.java new file mode 100644 index 00000000..061191df --- /dev/null +++ b/Core/src/main/java/com/songoda/core/database/MariaDBConnector.java @@ -0,0 +1,65 @@ +package com.songoda.core.database; + +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import org.bukkit.plugin.Plugin; + +import java.sql.Connection; +import java.sql.SQLException; + +public class MariaDBConnector implements DatabaseConnector { + + private final Plugin plugin; + private HikariDataSource hikari; + private boolean initializedSuccessfully; + + public MariaDBConnector(Plugin plugin, String hostname, int port, String database, String username, String password, boolean useSSL, int poolSize) { + this.plugin = plugin; + + plugin.getLogger().info("connecting to " + hostname + " : " + port); + + HikariConfig config = new HikariConfig(); + config.setJdbcUrl("jdbc:mariadb://" + hostname + ":" + port + "/" + database + "?useSSL=" + useSSL); + config.setUsername(username); + config.setPassword(password); + config.setMaximumPoolSize(poolSize); + + try { + this.hikari = new HikariDataSource(config); + this.initializedSuccessfully = true; + } catch (Exception ex) { + this.initializedSuccessfully = false; + } + } + + @Override + public boolean isInitialized() { + return this.initializedSuccessfully; + } + + @Override + public void closeConnection() { + this.hikari.close(); + } + + @Deprecated + @Override + public void connect(DatabaseConnector.ConnectionCallback callback) { + try (Connection connection = this.hikari.getConnection()) { + callback.accept(connection); + } catch (SQLException ex) { + this.plugin.getLogger().severe("An error occurred executing a MySQL query: " + ex.getMessage()); + ex.printStackTrace(); + } + } + + @Override + public Connection getConnection() { + try { + return this.hikari.getConnection(); + } catch (Exception ex) { + ex.printStackTrace(); + } + return null; + } +} diff --git a/Core/src/main/java/com/songoda/core/hooks/protection/PlotSquaredProtection.java b/Core/src/main/java/com/songoda/core/hooks/protection/PlotSquaredProtection.java new file mode 100644 index 00000000..e5c23d54 --- /dev/null +++ b/Core/src/main/java/com/songoda/core/hooks/protection/PlotSquaredProtection.java @@ -0,0 +1,43 @@ +package com.songoda.core.hooks.protection; + +import com.plotsquared.core.PlotAPI; +import com.plotsquared.core.PlotSquared; +import com.plotsquared.core.plot.PlotArea; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class PlotSquaredProtection extends Protection { + + PlotSquared plotSquared; + + public PlotSquaredProtection(Plugin plugin) { + super(plugin); + plotSquared = PlotSquared.get(); + } + + @Override + public String getName() { + return "PlotSquared"; + } + + @Override + public boolean isEnabled() { + return plotSquared != null; + } + + @Override + public boolean canPlace(Player player, Location location) { + return plotSquared.getPlotAreaManager().getApplicablePlotArea(com.plotsquared.core.location.Location.at(location.getWorld().getName(), (int) location.getX(), (int) location.getY(), (int) location.getZ())).getPlots().stream().anyMatch(p -> p.isAdded(player.getUniqueId())); + } + + @Override + public boolean canBreak(Player player, Location location) { + return plotSquared.getPlotAreaManager().getApplicablePlotArea(com.plotsquared.core.location.Location.at(location.getWorld().getName(), (int) location.getX(), (int) location.getY(), (int) location.getZ())).getPlots().stream().anyMatch(p -> p.isAdded(player.getUniqueId())); + } + + @Override + public boolean canInteract(Player player, Location location) { + return plotSquared.getPlotAreaManager().getApplicablePlotArea(com.plotsquared.core.location.Location.at(location.getWorld().getName(), (int) location.getX(), (int) location.getY(), (int) location.getZ())).getPlots().stream().anyMatch(p -> p.isAdded(player.getUniqueId())); + } +} diff --git a/pom.xml b/pom.xml index e4f4dbfc..cb65e929 100644 --- a/pom.xml +++ b/pom.xml @@ -142,6 +142,16 @@ jitpack.io https://jitpack.io/ + + + enginehub-repo + https://maven.enginehub.org/repo/ + + + + papermc + https://repo.papermc.io/repository/maven-public/ + From aff3ea92f3359cbfb5b6a6adf4dc9d5f37d188ca Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Mon, 7 Nov 2022 22:19:19 +0100 Subject: [PATCH 13/20] Fix wrong coreVersion in SongodaCore class --- Core/src/main/java/com/songoda/core/SongodaCore.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/main/java/com/songoda/core/SongodaCore.java b/Core/src/main/java/com/songoda/core/SongodaCore.java index edd3421f..17b2eff0 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCore.java +++ b/Core/src/main/java/com/songoda/core/SongodaCore.java @@ -53,7 +53,7 @@ public class SongodaCore { /** * @since coreRevision 6 */ - private final static String coreVersion = "2.6.16"; + private final static String coreVersion = "2.6.17-SNAPSHOT"; /** * This is specific to the website api From 6aa9178321e6a515f554630e47b3ea79918e2597 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Mon, 7 Nov 2022 22:29:40 +0100 Subject: [PATCH 14/20] Fix `ItemUtils#applyRandomEnchants` in Minecraft 1.19 The method needs a `RandomSource` instead of a normal Java `Random`. The method reference has been updated but updating its usage has been forgotten. Sadly I do not really know where to properly get an `RandomSource` instance without instanciating it myself. --- .../core/compatibility/ClassMapping.java | 1 + .../com/songoda/core/utils/ItemUtils.java | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Compatibility/src/main/java/com/songoda/core/compatibility/ClassMapping.java b/Compatibility/src/main/java/com/songoda/core/compatibility/ClassMapping.java index 117dcc7b..4fe950f7 100644 --- a/Compatibility/src/main/java/com/songoda/core/compatibility/ClassMapping.java +++ b/Compatibility/src/main/java/com/songoda/core/compatibility/ClassMapping.java @@ -47,6 +47,7 @@ public enum ClassMapping { CRAFT_PLAYER("entity", "CraftPlayer"), CRAFT_WORLD("CraftWorld"), + SINGLE_THREADED_RANDOM_SOURCE("world.level.levelgen", "SingleThreadedRandomSource"), RANDOM_SOURCE("util", "RandomSource"), MOJANGSON_PARSER("nbt", "MojangsonParser"); diff --git a/Core/src/main/java/com/songoda/core/utils/ItemUtils.java b/Core/src/main/java/com/songoda/core/utils/ItemUtils.java index e86f389a..05ebf2c1 100644 --- a/Core/src/main/java/com/songoda/core/utils/ItemUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/ItemUtils.java @@ -35,6 +35,7 @@ import java.util.Iterator; import java.util.List; import java.util.Random; import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Stream; @@ -82,6 +83,7 @@ public class ItemUtils { } private static Method methodAsBukkitCopy, methodAsNMSCopy, methodA; + private static Object randomInstance; static { try { @@ -90,17 +92,20 @@ public class ItemUtils { Class clazzCraftItemStack = ClassMapping.CRAFT_ITEM_STACK.getClazz(); methodAsBukkitCopy = clazzCraftItemStack.getMethod("asBukkitCopy", clazzItemStack); - methodAsNMSCopy = clazzCraftItemStack.getMethod("asNMSCopy", ItemStack.class); + methodAsNMSCopy = MethodMapping.CB_ITEM_STACK__AS_NMS_COPY.getMethod(clazzCraftItemStack); if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_19)) { Class clazzRandomSource = ClassMapping.RANDOM_SOURCE.getClazz(); methodA = clazzEnchantmentManager.getMethod("a", clazzRandomSource.getMethod("c").getReturnType(), clazzItemStack, int.class, boolean.class); - }else if (ServerVersion.isServerVersion(ServerVersion.V1_8)) { + randomInstance = ClassMapping.SINGLE_THREADED_RANDOM_SOURCE.getClazz().getConstructor(long.class).newInstance(ThreadLocalRandom.current().nextLong()); + } else if (ServerVersion.isServerVersion(ServerVersion.V1_8)) { methodA = clazzEnchantmentManager.getMethod("a", Random.class, clazzItemStack, int.class); + randomInstance = new Random(); } else { methodA = clazzEnchantmentManager.getMethod("a", Random.class, clazzItemStack, int.class, boolean.class); + randomInstance = new Random(); } - } catch (NoSuchMethodException ex) { + } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } } @@ -109,10 +114,12 @@ public class ItemUtils { try { Object nmsItemStack = methodAsNMSCopy.invoke(null, item); - if (ServerVersion.isServerVersion(ServerVersion.V1_8)) { - nmsItemStack = methodA.invoke(null, new Random(), nmsItemStack, level); + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_19)) { + nmsItemStack = methodA.invoke(null, randomInstance, nmsItemStack, level, false); + } else if (ServerVersion.isServerVersion(ServerVersion.V1_8)) { + nmsItemStack = methodA.invoke(null, randomInstance, nmsItemStack, level); } else { - nmsItemStack = methodA.invoke(null, new Random(), nmsItemStack, level, false); + nmsItemStack = methodA.invoke(null, randomInstance, nmsItemStack, level, false); } item = (ItemStack) methodAsBukkitCopy.invoke(null, nmsItemStack); From d939489861d7b544948447628d04ca4606cc9735 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Sun, 25 Dec 2022 22:49:26 +0100 Subject: [PATCH 15/20] Use `1.18-R0.1-SNAPSHOT` instead of `1.18` in `NMS-v1_18_R1` module --- .github/workflows/maven.yml | 2 +- NMS/NMS-v1_18_R1/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 6d6ccbe7..48f826c7 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -27,7 +27,7 @@ jobs: # Build remapped Spigot versions - uses: SpraxDev/Action-SpigotMC@v4 with: - versions: 1.18.2, 1.19, 1.19.2 + versions: 1.18, 1.18.2, 1.19, 1.19.2 remapped: true # Build project diff --git a/NMS/NMS-v1_18_R1/pom.xml b/NMS/NMS-v1_18_R1/pom.xml index 9a15e72e..8e01cc7d 100644 --- a/NMS/NMS-v1_18_R1/pom.xml +++ b/NMS/NMS-v1_18_R1/pom.xml @@ -35,7 +35,7 @@ org.spigotmc spigot - 1.18 + 1.18-R0.1-SNAPSHOT provided From c3fb0504442dc7810e79ab9a3c2d1acfe4cd8f88 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Sun, 25 Dec 2022 22:37:06 +0100 Subject: [PATCH 16/20] Updates dependency UltimateStacker to v2.3.2 --- Core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/pom.xml b/Core/pom.xml index 0c7df925..c9ba5936 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -323,7 +323,7 @@ com.songoda UltimateStacker - 2.3.1-Dev + 2.3.2 provided From 296f82f50e1b8a9b223e78eb21427afd378000ab Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Mon, 26 Dec 2022 13:39:51 +0100 Subject: [PATCH 17/20] Restore functionality of deprecated SQLite connection acquisition If the connection is closed, no new SQLite connection is created in plugins still using the deprecated method. Introduced in 0ae9c6fcdb1d3af48f64d5fa5103d67d93eeeddc --- .../com/songoda/core/database/SQLiteConnector.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/database/SQLiteConnector.java b/Core/src/main/java/com/songoda/core/database/SQLiteConnector.java index 2a777a49..7ffbbf22 100644 --- a/Core/src/main/java/com/songoda/core/database/SQLiteConnector.java +++ b/Core/src/main/java/com/songoda/core/database/SQLiteConnector.java @@ -42,16 +42,8 @@ public class SQLiteConnector implements DatabaseConnector { @Deprecated @Override public void connect(ConnectionCallback callback) { - if (this.connection == null) { - try { - this.connection = DriverManager.getConnection(this.connectionString); - } catch (SQLException ex) { - this.plugin.getLogger().severe("An error occurred retrieving the SQLite database connection: " + ex.getMessage()); - } - } - try { - callback.accept(this.connection); + callback.accept(getConnection()); } catch (Exception ex) { this.plugin.getLogger().severe("An error occurred executing an SQLite query: " + ex.getMessage()); ex.printStackTrace(); From 64865873f944c6327f150190856782d991eeec0b Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Mon, 26 Dec 2022 13:44:25 +0100 Subject: [PATCH 18/20] Adds NMS module for Spigot 1.19.3 (v1_19_R2) support --- Core/pom.xml | 6 + .../java/com/songoda/core/nms/NmsManager.java | 6 + .../com/songoda/core/nms/world/WorldCore.java | 6 +- NMS/NMS-v1_19_R2/pom.xml | 105 +++++++++ .../core/nms/v1_19_R2/anvil/AnvilCore.java | 21 ++ .../v1_19_R2/anvil/AnvilInventoryCustom.java | 22 ++ .../core/nms/v1_19_R2/anvil/AnvilView.java | 216 ++++++++++++++++++ .../nms/v1_19_R2/entity/NMSPlayerImpl.java | 13 ++ .../nms/v1_19_R2/nbt/NBTCompoundImpl.java | 208 +++++++++++++++++ .../core/nms/v1_19_R2/nbt/NBTCoreImpl.java | 38 +++ .../core/nms/v1_19_R2/nbt/NBTEntityImpl.java | 66 ++++++ .../core/nms/v1_19_R2/nbt/NBTItemImpl.java | 24 ++ .../core/nms/v1_19_R2/nbt/NBTObjectImpl.java | 72 ++++++ .../nms/v1_19_R2/world/SItemStackImpl.java | 39 ++++ .../core/nms/v1_19_R2/world/SSpawnerImpl.java | 132 +++++++++++ .../core/nms/v1_19_R2/world/SWorldImpl.java | 38 +++ .../nms/v1_19_R2/world/WorldCoreImpl.java | 93 ++++++++ .../world/spawner/BBaseSpawnerImpl.java | 214 +++++++++++++++++ pom.xml | 1 + 19 files changed, 1317 insertions(+), 3 deletions(-) create mode 100644 NMS/NMS-v1_19_R2/pom.xml create mode 100644 NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/anvil/AnvilCore.java create mode 100644 NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/anvil/AnvilInventoryCustom.java create mode 100644 NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/anvil/AnvilView.java create mode 100644 NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/entity/NMSPlayerImpl.java create mode 100644 NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTCompoundImpl.java create mode 100644 NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTCoreImpl.java create mode 100644 NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTEntityImpl.java create mode 100644 NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTItemImpl.java create mode 100644 NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTObjectImpl.java create mode 100644 NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/SItemStackImpl.java create mode 100644 NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/SSpawnerImpl.java create mode 100644 NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/SWorldImpl.java create mode 100644 NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/WorldCoreImpl.java create mode 100644 NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/spawner/BBaseSpawnerImpl.java diff --git a/Core/pom.xml b/Core/pom.xml index c9ba5936..e039eac9 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -261,6 +261,12 @@ ${project.version} compile + + ${project.groupId} + SongodaCore-NMS-v1_19_R2 + ${project.version} + compile + diff --git a/Core/src/main/java/com/songoda/core/nms/NmsManager.java b/Core/src/main/java/com/songoda/core/nms/NmsManager.java index ee047a6b..63568efe 100644 --- a/Core/src/main/java/com/songoda/core/nms/NmsManager.java +++ b/Core/src/main/java/com/songoda/core/nms/NmsManager.java @@ -141,6 +141,12 @@ public class NmsManager { world = new com.songoda.core.nms.v1_19_R1v2.world.WorldCoreImpl(); } break; + case "v1_19_R2": + player = new com.songoda.core.nms.v1_19_R2.entity.NMSPlayerImpl(); + anvil = new com.songoda.core.nms.v1_19_R2.anvil.AnvilCore(); + nbt = new com.songoda.core.nms.v1_19_R2.nbt.NBTCoreImpl(); + world = new com.songoda.core.nms.v1_19_R2.world.WorldCoreImpl(); + break; default: Logger.getLogger(NmsManager.class.getName()).log(Level.SEVERE, "Failed to load NMS for this server version: version {0} not found", serverPackageVersion); diff --git a/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/WorldCore.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/WorldCore.java index 75da36f8..bf5256ff 100644 --- a/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/WorldCore.java +++ b/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/WorldCore.java @@ -18,7 +18,7 @@ public interface WorldCore { SWorld getWorld(World world); - BBaseSpawner getBaseSpawner(CreatureSpawner spawner) throws NoSuchFieldException, IllegalAccessException; + BBaseSpawner getBaseSpawner(CreatureSpawner spawner) throws ReflectiveOperationException; /** * Performs random ticks on a specific chunks. @@ -28,7 +28,7 @@ public interface WorldCore { * @param bukkitChunk The chunk to tick * @param tickAmount The number of blocks to tick per ChunkSection, normally referred to as randomTickSpeed */ - void randomTickChunk(Chunk bukkitChunk, int tickAmount) throws NoSuchFieldException, IllegalAccessException; + void randomTickChunk(Chunk bukkitChunk, int tickAmount) throws ReflectiveOperationException; /** * Ticks all inactive spawners in a specific chunk ignoring the minimum required players within a specific range.
@@ -37,7 +37,7 @@ public interface WorldCore { * @param chunk The chunk to tick the spawners in * @param amount The amount of ticks to execute for each spawner */ - default void tickInactiveSpawners(Chunk chunk, int amount) throws NoSuchFieldException, IllegalAccessException, InvocationTargetException { + default void tickInactiveSpawners(Chunk chunk, int amount) throws ReflectiveOperationException { if (amount <= 0) return; for (BlockState tileEntity : chunk.getTileEntities()) { diff --git a/NMS/NMS-v1_19_R2/pom.xml b/NMS/NMS-v1_19_R2/pom.xml new file mode 100644 index 00000000..e826970c --- /dev/null +++ b/NMS/NMS-v1_19_R2/pom.xml @@ -0,0 +1,105 @@ + + + 4.0.0 + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + + ${java.release} + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + + remap-obf + package + + remap + + + + org.spigotmc:minecraft-server:${nms.ver}:txt:maps-mojang + true + org.spigotmc:spigot:${nms.ver}:jar:remapped-mojang + true + remapped-obf + + + + + remap-spigot + package + + remap + + + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${nms.ver}:csrg:maps-spigot + org.spigotmc:spigot:${nms.ver}:jar:remapped-obf + + + + + + + + + com.songoda + SongodaCore-Modules + 2.6.17-SNAPSHOT + ../../pom.xml + + + + 17 + 17 + + 1.19.3-R0.1-SNAPSHOT + + + SongodaCore-NMS-v1_19_R2 + jar + + + + org.spigotmc + spigot-api + ${nms.ver} + provided + + + + org.spigotmc + spigot + ${nms.ver} + provided + remapped-mojang + + + + ${project.groupId} + SongodaCore-NMS-API + ${project.version} + + + + ${project.groupId} + SongodaCore-Compatibility + ${project.version} + + + diff --git a/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/anvil/AnvilCore.java b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/anvil/AnvilCore.java new file mode 100644 index 00000000..66ef90a6 --- /dev/null +++ b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/anvil/AnvilCore.java @@ -0,0 +1,21 @@ +package com.songoda.core.nms.v1_19_R2.anvil; + +import com.songoda.core.nms.anvil.CustomAnvil; +import net.minecraft.server.level.ServerPlayer; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryHolder; + +public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { + @Override + public CustomAnvil createAnvil(Player player) { + ServerPlayer p = ((CraftPlayer) player).getHandle(); + return new AnvilView(p.nextContainerCounter(), p, null); + } + + @Override + public CustomAnvil createAnvil(Player player, InventoryHolder holder) { + ServerPlayer p = ((CraftPlayer) player).getHandle(); + return new AnvilView(p.nextContainerCounter(), p, holder); + } +} diff --git a/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/anvil/AnvilInventoryCustom.java new file mode 100644 index 00000000..e084ad4d --- /dev/null +++ b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/anvil/AnvilInventoryCustom.java @@ -0,0 +1,22 @@ +package com.songoda.core.nms.v1_19_R2.anvil; + +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventoryAnvil; +import org.bukkit.inventory.InventoryHolder; + +public class AnvilInventoryCustom extends CraftInventoryAnvil { + final InventoryHolder holder; + + public AnvilInventoryCustom(InventoryHolder holder, Location location, Container inventory, Container resultInventory, AnvilMenu container) { + super(location, inventory, resultInventory, container); + + this.holder = holder; + } + + @Override + public InventoryHolder getHolder() { + return holder; + } +} diff --git a/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/anvil/AnvilView.java b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/anvil/AnvilView.java new file mode 100644 index 00000000..4ec10d7c --- /dev/null +++ b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/anvil/AnvilView.java @@ -0,0 +1,216 @@ +package com.songoda.core.nms.v1_19_R2.anvil; + +import com.songoda.core.nms.anvil.CustomAnvil; +import com.songoda.core.nms.anvil.methods.AnvilTextChange; +import net.md_5.bungee.api.chat.TranslatableComponent; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.contents.TranslatableContents; +import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.ItemCombinerMenu; +import net.minecraft.world.inventory.MenuType; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftInventoryView; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; + +import java.lang.reflect.Field; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class AnvilView extends AnvilMenu implements CustomAnvil { + private final ServerPlayer entity; + private final Inventory inventory; + private String customTitle = "Repairing"; + private int cost = -1; + private boolean canUse = true; + private AnvilTextChange textChange; + + // used for setting custom inventory + static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result + static Field mc_ContainerAnvil_resultInventory; // full inventory + static Field mc_ContainerAnvil_bukkitEntity; + + static { + try { + mc_ContainerAnvil_repairInventory = ItemCombinerMenu.class.getDeclaredField("p"); + mc_ContainerAnvil_repairInventory.setAccessible(true); + + mc_ContainerAnvil_resultInventory = ItemCombinerMenu.class.getDeclaredField("o"); + mc_ContainerAnvil_resultInventory.setAccessible(true); + + mc_ContainerAnvil_bukkitEntity = AnvilMenu.class.getDeclaredField("bukkitEntity"); + mc_ContainerAnvil_bukkitEntity.setAccessible(true); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); + } + } + + // 1.14 also introduced a title field, also private, which can only be set once and can't be checked + static Field mc_Container_title; + + static { + try { + mc_Container_title = AbstractContainerMenu.class.getDeclaredField("title"); + mc_Container_title.setAccessible(true); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); + } + } + + public AnvilView(int id, ServerPlayer entity, InventoryHolder holder) { + super(entity.nextContainerCounter(), entity.getInventory(), ContainerLevelAccess.create(entity.level, new BlockPos(0, 0, 0))); + + this.setTitle(MutableComponent.create(new TranslatableContents(customTitle != null ? customTitle : ""))); + this.checkReachable = false; + this.entity = entity; + + if (holder != null) { + this.inventory = getBukkitView(entity, holder).getTopInventory(); + } else { + this.inventory = getBukkitView().getTopInventory(); + } + } + + public CraftInventoryView getBukkitView(Player player, InventoryHolder holder) { + try { + AnvilInventoryCustom craftInventory = new AnvilInventoryCustom(holder, + new Location(entity.level.getWorld(), 0, 0, 0), + (Container) mc_ContainerAnvil_repairInventory.get(this), + (Container) mc_ContainerAnvil_resultInventory.get(this), this); + CraftInventoryView view = new CraftInventoryView(player.getBukkitEntity(), craftInventory, this); + mc_ContainerAnvil_bukkitEntity.set(this, view); + + return view; + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); + } + + return getBukkitView(); + } + + @Override + public boolean stillValid(Player entityHuman) { + return canUse; + } + + @Override + public void broadcastFullState() { + super.broadcastFullState(); + + if (cost >= 0) { + this.setLevelCost(cost); + } + + textChange.onChange(); + } + + @Override + public void update() { + broadcastFullState(); + } + + @Override + public String getRenameText() { + return this.itemName; + } + + @Override + public void setRenameText(String text) { + this.setItemName(text); + } + + @Override + public void setOnChange(AnvilTextChange handler) { + textChange = handler; + } + + @Override + public String getCustomTitle() { + return customTitle; + } + + @Override + public void setCustomTitle(String title) { + this.customTitle = title; + + try { + mc_Container_title.set(this, MutableComponent.create(new TranslatableContents(customTitle != null ? customTitle : ""))); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex); + } + } + + @Override + public void setLevelCost(int cost) { + this.cost = cost; + } + + @Override + public int getLevelCost() { + if (cost >= 0) { + return cost; + } + + return this.getLevelCost(); + } + + @Override + public void setCanUse(boolean bool) { + this.canUse = bool; + } + + @Override + public ItemStack getLeftInput() { + return inventory.getItem(0); + } + + @Override + public ItemStack getRightInput() { + return inventory.getItem(1); + } + + @Override + public ItemStack getOutput() { + return inventory.getItem(2); + } + + @Override + public void setLeftInput(ItemStack item) { + inventory.setItem(0, item); + } + + @Override + public void setRightInput(ItemStack item) { + inventory.setItem(1, item); + } + + @Override + public void setOutput(ItemStack item) { + inventory.setItem(2, item); + } + + @Override + public Inventory getInventory() { + return inventory; + } + + @Override + public void open() { + // Send the packet + entity.connection.send(new ClientboundOpenScreenPacket(super.containerId, MenuType.ANVIL, MutableComponent.create(new TranslatableContents(customTitle != null ? customTitle : "")))); + + // Set their active container to this anvil + entity.containerMenu = this; + + // Add the slot listener + entity.initMenu(entity.containerMenu); + } +} diff --git a/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/entity/NMSPlayerImpl.java b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/entity/NMSPlayerImpl.java new file mode 100644 index 00000000..0c4708b6 --- /dev/null +++ b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/entity/NMSPlayerImpl.java @@ -0,0 +1,13 @@ +package com.songoda.core.nms.v1_19_R2.entity; + +import com.songoda.core.nms.entity.NMSPlayer; +import net.minecraft.network.protocol.Packet; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.entity.Player; + +public class NMSPlayerImpl implements NMSPlayer { + @Override + public void sendPacket(Player p, Object packet) { + ((CraftPlayer) p).getHandle().connection.send((Packet) packet); + } +} diff --git a/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTCompoundImpl.java new file mode 100644 index 00000000..2d4d5997 --- /dev/null +++ b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTCompoundImpl.java @@ -0,0 +1,208 @@ +package com.songoda.core.nms.v1_19_R2.nbt; + +import com.songoda.core.nms.nbt.NBTCompound; +import com.songoda.core.nms.nbt.NBTObject; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtIo; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.Set; +import java.util.UUID; + +public class NBTCompoundImpl implements NBTCompound { + protected CompoundTag compound; + + protected NBTCompoundImpl(CompoundTag compound) { + this.compound = compound; + } + + public NBTCompoundImpl() { + this.compound = new CompoundTag(); + } + + @Override + public NBTCompound set(String tag, String s) { + compound.putString(tag, s); + return this; + } + + @Override + public NBTCompound set(String tag, boolean b) { + compound.putBoolean(tag, b); + return this; + } + + @Override + public NBTCompound set(String tag, int i) { + compound.putInt(tag, i); + return this; + } + + @Override + public NBTCompound set(String tag, double i) { + compound.putDouble(tag, i); + return this; + } + + @Override + public NBTCompound set(String tag, long l) { + compound.putLong(tag, l); + return this; + } + + @Override + public NBTCompound set(String tag, short s) { + compound.putShort(tag, s); + return this; + } + + @Override + public NBTCompound set(String tag, byte b) { + compound.putByte(tag, b); + return this; + } + + @Override + public NBTCompound set(String tag, int[] i) { + compound.putIntArray(tag, i); + return this; + } + + @Override + public NBTCompound set(String tag, byte[] b) { + compound.putByteArray(tag, b); + return this; + } + + @Override + public NBTCompound set(String tag, UUID u) { + compound.putUUID(tag, u); + return this; + } + + @Override + public NBTCompound remove(String tag) { + compound.remove(tag); + return this; + } + + @Override + public boolean has(String tag) { + return compound.contains(tag); + } + + @Override + public NBTObject getNBTObject(String tag) { + return new NBTObjectImpl(compound, tag); + } + + @Override + public String getString(String tag) { + return getNBTObject(tag).asString(); + } + + @Override + public boolean getBoolean(String tag) { + return getNBTObject(tag).asBoolean(); + } + + @Override + public int getInt(String tag) { + return getNBTObject(tag).asInt(); + } + + @Override + public double getDouble(String tag) { + return getNBTObject(tag).asDouble(); + } + + @Override + public long getLong(String tag) { + return getNBTObject(tag).asLong(); + } + + @Override + public short getShort(String tag) { + return getNBTObject(tag).asShort(); + } + + @Override + public byte getByte(String tag) { + return getNBTObject(tag).asByte(); + } + + @Override + public int[] getIntArray(String tag) { + return getNBTObject(tag).asIntArray(); + } + + @Override + public byte[] getByteArray(String tag) { + return getNBTObject(tag).asByteArray(); + } + + @Override + public NBTCompound getCompound(String tag) { + if (has(tag)) { + return getNBTObject(tag).asCompound(); + } + + CompoundTag newCompound = new CompoundTag(); + compound.put(tag, newCompound); + return new NBTCompoundImpl(newCompound); + } + + @Override + public Set getKeys() { + return compound.getAllKeys(); + } + + @Override + public Set getKeys(String tag) { + return compound.getCompound(tag).getAllKeys(); + } + + @Override + public byte[] serialize(String... exclusions) { + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) { + addExtras(); + CompoundTag compound = this.compound.copy(); + + for (String exclusion : exclusions) { + compound.remove(exclusion); + } + + NbtIo.writeCompressed(compound, dataOutput); + + return outputStream.toByteArray(); + } catch (Exception ex) { + ex.printStackTrace(); + } + + return null; + } + + @Override + public void deSerialize(byte[] serialized) { + try (ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized); + ObjectInputStream dataInput = new ObjectInputStream(inputStream)) { + compound = NbtIo.readCompressed(dataInput); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + @Override + public void addExtras() { + // None + } + + @Override + public String toString() { + return compound.toString(); + } +} diff --git a/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTCoreImpl.java b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTCoreImpl.java new file mode 100644 index 00000000..4f195413 --- /dev/null +++ b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTCoreImpl.java @@ -0,0 +1,38 @@ +package com.songoda.core.nms.v1_19_R2.nbt; + +import com.songoda.core.nms.nbt.NBTCore; +import com.songoda.core.nms.nbt.NBTEntity; +import com.songoda.core.nms.nbt.NBTItem; +import net.minecraft.nbt.CompoundTag; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; +import org.bukkit.entity.Entity; +import org.bukkit.inventory.ItemStack; + +public class NBTCoreImpl implements NBTCore { + @Deprecated + @Override + public NBTItem of(ItemStack item) { + return new NBTItemImpl(CraftItemStack.asNMSCopy(item)); + } + + @Deprecated + @Override + public NBTItem newItem() { + return new NBTItemImpl(null); + } + + @Override + public NBTEntity of(Entity entity) { + net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle(); + CompoundTag nbt = new CompoundTag(); + nmsEntity.saveWithoutId(nbt); + + return new NBTEntityImpl(nbt, nmsEntity); + } + + @Override + public NBTEntity newEntity() { + return new NBTEntityImpl(new CompoundTag(), null); + } +} diff --git a/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTEntityImpl.java b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTEntityImpl.java new file mode 100644 index 00000000..cd76b620 --- /dev/null +++ b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTEntityImpl.java @@ -0,0 +1,66 @@ +package com.songoda.core.nms.v1_19_R2.nbt; + +import com.songoda.core.nms.nbt.NBTEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobSpawnType; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; + +import java.util.Optional; + +public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { + private Entity nmsEntity; + + public NBTEntityImpl(CompoundTag entityNBT, Entity nmsEntity) { + super(entityNBT); + + this.nmsEntity = nmsEntity; + } + + @Override + public org.bukkit.entity.Entity spawn(Location location) { + String entityType = getNBTObject("entity_type").asString(); + + Optional> optionalEntity = EntityType.byString(entityType); + if (optionalEntity.isPresent()) { + assert location.getWorld() != null; + + Entity spawned = optionalEntity.get().spawn( + ((CraftWorld) location.getWorld()).getHandle(), + compound, + null, + new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), + MobSpawnType.COMMAND, + true, + false + ); + + if (spawned != null) { + spawned.load(compound); + org.bukkit.entity.Entity entity = spawned.getBukkitEntity(); + entity.teleport(location); + nmsEntity = spawned; + + return entity; + } + } + + return null; + } + + @Override + public org.bukkit.entity.Entity reSpawn(Location location) { + nmsEntity.discard(); + return spawn(location); + } + + @Override + public void addExtras() { + compound.putString("entity_type", BuiltInRegistries.ENTITY_TYPE.getKey(nmsEntity.getType()).toString()); + } +} diff --git a/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTItemImpl.java b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTItemImpl.java new file mode 100644 index 00000000..5ef6a7b1 --- /dev/null +++ b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTItemImpl.java @@ -0,0 +1,24 @@ +package com.songoda.core.nms.v1_19_R2.nbt; + +import com.songoda.core.nms.nbt.NBTItem; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; + +public class NBTItemImpl extends NBTCompoundImpl implements NBTItem { + private final ItemStack nmsItem; + + public NBTItemImpl(ItemStack nmsItem) { + super(nmsItem != null && nmsItem.hasTag() ? nmsItem.getTag() : new CompoundTag()); + + this.nmsItem = nmsItem; + } + + public org.bukkit.inventory.ItemStack finish() { + if (nmsItem == null) { + return CraftItemStack.asBukkitCopy(ItemStack.of(compound)); + } + + return CraftItemStack.asBukkitCopy(nmsItem); + } +} diff --git a/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTObjectImpl.java b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTObjectImpl.java new file mode 100644 index 00000000..b1e77f55 --- /dev/null +++ b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/nbt/NBTObjectImpl.java @@ -0,0 +1,72 @@ +package com.songoda.core.nms.v1_19_R2.nbt; + +import com.songoda.core.nms.nbt.NBTCompound; +import com.songoda.core.nms.nbt.NBTObject; +import net.minecraft.nbt.CompoundTag; + +import java.util.Set; + +public class NBTObjectImpl implements NBTObject { + private final CompoundTag compound; + private final String tag; + + public NBTObjectImpl(CompoundTag compound, String tag) { + this.compound = compound; + this.tag = tag; + } + + @Override + public String asString() { + return compound.getString(tag); + } + + @Override + public boolean asBoolean() { + return compound.getBoolean(tag); + } + + @Override + public int asInt() { + return compound.getInt(tag); + } + + @Override + public double asDouble() { + return compound.getDouble(tag); + } + + @Override + public long asLong() { + return compound.getLong(tag); + } + + @Override + public short asShort() { + return compound.getShort(tag); + } + + @Override + public byte asByte() { + return compound.getByte(tag); + } + + @Override + public int[] asIntArray() { + return compound.getIntArray(tag); + } + + @Override + public byte[] asByteArray() { + return compound.getByteArray(tag); + } + + @Override + public NBTCompound asCompound() { + return new NBTCompoundImpl(compound.getCompound(tag)); + } + + @Override + public Set getKeys() { + return compound.getAllKeys(); + } +} diff --git a/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/SItemStackImpl.java b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/SItemStackImpl.java new file mode 100644 index 00000000..e4e0dde4 --- /dev/null +++ b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/SItemStackImpl.java @@ -0,0 +1,39 @@ +package com.songoda.core.nms.v1_19_R2.world; + +import com.songoda.core.nms.world.SItemStack; +import net.minecraft.core.particles.ItemParticleOption; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.phys.Vec3; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class SItemStackImpl implements SItemStack { + private final ItemStack item; + + public SItemStackImpl(ItemStack item) { + this.item = item; + } + + @Override + public void breakItem(Player player, int amount) { + ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); + + for (int i = 0; i < amount; ++i) { + Vec3 vec3d = new Vec3(((double) random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D); + vec3d = vec3d.xRot(-entityPlayer.getXRot() * 0.017453292F); + vec3d = vec3d.yRot(-entityPlayer.getYRot() * 0.017453292F); + + double d0 = (double) (-random.nextFloat()) * 0.6D - 0.3D; + + Vec3 vec3d1 = new Vec3(((double) random.nextFloat() - 0.5D) * 0.3D, d0, 0.6D); + vec3d1 = vec3d1.xRot(-entityPlayer.getXRot() * 0.017453292F); + vec3d1 = vec3d1.yRot(-entityPlayer.getYRot() * 0.017453292F); + vec3d1 = vec3d1.add(entityPlayer.getX(), entityPlayer.getEyeY(), entityPlayer.getZ()); + + entityPlayer.level.addParticle(new ItemParticleOption(ParticleTypes.ITEM, CraftItemStack.asNMSCopy(item)), vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z); + } + } +} diff --git a/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/SSpawnerImpl.java b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/SSpawnerImpl.java new file mode 100644 index 00000000..a9c93bee --- /dev/null +++ b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/SSpawnerImpl.java @@ -0,0 +1,132 @@ +package com.songoda.core.nms.v1_19_R2.world; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.CompatibleParticleHandler; +import com.songoda.core.nms.world.SSpawner; +import com.songoda.core.nms.world.SpawnedEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.RandomSource; +import net.minecraft.world.DifficultyInstance; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.level.SpawnData; +import org.bukkit.Location; +import org.bukkit.block.BlockFace; +import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.entity.CreatureSpawnEvent; + +import java.util.Optional; +import java.util.Set; + +public class SSpawnerImpl implements SSpawner { + private final Location spawnerLocation; + + public SSpawnerImpl(Location location) { + this.spawnerLocation = location; + } + + @Override + public LivingEntity spawnEntity(EntityType type, Location spawnerLocation) { + return spawnEntity(type, "EXPLOSION_NORMAL", null, null); + } + + @Override + public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set canSpawnOn) { + SpawnData data = new SpawnData(); + CompoundTag compound = data.getEntityToSpawn(); + + String name = type.name().toLowerCase().replace("snowman", "snow_golem") + .replace("mushroom_cow", "mooshroom"); + compound.putString("id", "minecraft:" + name); + + short spawnRange = 4; + for (int i = 0; i < 50; i++) { + assert spawnerLocation.getWorld() != null; + ServerLevel world = ((CraftWorld) spawnerLocation.getWorld()).getHandle(); + + RandomSource random = world.getRandom(); + double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D; + double y = spawnerLocation.getY() + random.nextInt(3) - 1; + double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D; + + Optional optionalEntity = net.minecraft.world.entity.EntityType.create(compound, world); + if (optionalEntity.isEmpty()) continue; + + Entity entity = optionalEntity.get(); + entity.setPos(x, y, z); + + BlockPos position = entity.blockPosition(); + DifficultyInstance damageScaler = world.getCurrentDifficultyAt(position); + + if (!(entity instanceof Mob entityInsentient)) { + continue; + } + + Location spot = new Location(spawnerLocation.getWorld(), x, y, z); + + if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) { + continue; + } + + entityInsentient.finalizeSpawn(world, damageScaler, MobSpawnType.SPAWNER, null, null); + + LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity(); + + if (spawned != null && !spawned.onSpawn(craftEntity)) { + return null; + } + + if (particleType != null) { + float xx = (float) (0 + (Math.random() * 1)); + float yy = (float) (0 + (Math.random() * 2)); + float zz = (float) (0 + (Math.random() * 1)); + + CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.getParticle(particleType), spot, 5, xx, yy, zz, 0); + } + + world.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.SPAWNER); + + spot.setYaw(random.nextFloat() * 360.0F); + craftEntity.teleport(spot); + + return craftEntity; + } + + return null; + } + + private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set canSpawnOn) { + if (!world.noCollision(entityInsentient, entityInsentient.getBoundingBox())) { + return false; + } + + CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock()); + CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN)); + + if (spawnedIn == null || spawnedOn == null) { + return false; + } + + if (!spawnedIn.isAir() && + spawnedIn != CompatibleMaterial.WATER && + !spawnedIn.name().contains("PRESSURE") && + !spawnedIn.name().contains("SLAB")) { + return false; + } + + for (CompatibleMaterial material : canSpawnOn) { + if (material == null) continue; + + if (spawnedOn.equals(material) || material.isAir()) { + return true; + } + } + + return false; + } +} diff --git a/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/SWorldImpl.java b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/SWorldImpl.java new file mode 100644 index 00000000..9aff266a --- /dev/null +++ b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/SWorldImpl.java @@ -0,0 +1,38 @@ +package com.songoda.core.nms.v1_19_R2.world; + +import com.songoda.core.nms.world.SWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.entity.LevelEntityGetter; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; +import org.bukkit.entity.LivingEntity; + +import java.util.ArrayList; +import java.util.List; + +public class SWorldImpl implements SWorld { + private final World world; + + public SWorldImpl(World world) { + this.world = world; + } + + @Override + public List getLivingEntities() { + List result = new ArrayList<>(); + + ServerLevel worldServer = ((CraftWorld) world).getHandle(); + LevelEntityGetter entities = worldServer.getEntities(); + + entities.getAll().forEach((mcEnt) -> { + org.bukkit.entity.Entity bukkitEntity = mcEnt.getBukkitEntity(); + + if (bukkitEntity instanceof LivingEntity && bukkitEntity.isValid()) { + result.add((LivingEntity) bukkitEntity); + } + }); + + return result; + } +} diff --git a/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/WorldCoreImpl.java b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/WorldCoreImpl.java new file mode 100644 index 00000000..c616f9ff --- /dev/null +++ b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/WorldCoreImpl.java @@ -0,0 +1,93 @@ +package com.songoda.core.nms.v1_19_R2.world; + +import com.songoda.core.nms.ReflectionUtils; +import com.songoda.core.nms.v1_19_R2.world.spawner.BBaseSpawnerImpl; +import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; +import com.songoda.core.nms.world.SSpawner; +import com.songoda.core.nms.world.SWorld; +import com.songoda.core.nms.world.WorldCore; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.level.BaseSpawner; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.chunk.LevelChunkSection; +import net.minecraft.world.level.material.FluidState; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.CreatureSpawner; +import org.bukkit.craftbukkit.v1_19_R2.CraftChunk; +import org.bukkit.inventory.ItemStack; + +public class WorldCoreImpl implements WorldCore { + @Override + public SSpawner getSpawner(CreatureSpawner spawner) { + return new SSpawnerImpl(spawner.getLocation()); + } + + @Override + public SSpawner getSpawner(Location location) { + return new SSpawnerImpl(location); + } + + @Override + public SItemStack getItemStack(ItemStack item) { + return new SItemStackImpl(item); + } + + @Override + public SWorld getWorld(World world) { + return new SWorldImpl(world); + } + + @Override + public BBaseSpawner getBaseSpawner(CreatureSpawner spawner) throws NoSuchFieldException, NoSuchMethodException, IllegalAccessException { + Object cTileEntity = ReflectionUtils.getFieldValue(spawner, "tileEntity"); + + return new BBaseSpawnerImpl(spawner, (BaseSpawner) ReflectionUtils.getFieldValue(cTileEntity, "a")); + } + + /** + * Method is based on {@link ServerLevel#tickChunk(LevelChunk, int)}. + */ + @Override + public void randomTickChunk(org.bukkit.Chunk bukkitChunk, int tickAmount) { + LevelChunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + ServerLevel world = chunk.q; + ProfilerFiller gameProfilerFiller = world.getProfiler(); + + ChunkPos chunkCoordIntPair = chunk.getPos(); + int j = chunkCoordIntPair.getMinBlockX(); + int k = chunkCoordIntPair.getMinBlockZ(); + + gameProfilerFiller.popPush("tickBlocks"); + if (tickAmount > 0) { + LevelChunkSection[] aChunkSection = chunk.getSections(); + + for (LevelChunkSection chunkSection : aChunkSection) { + if (chunkSection.isRandomlyTicking()) { + int j1 = chunkSection.bottomBlockY(); + + for (int k1 = 0; k1 < tickAmount; ++k1) { + BlockPos blockposition2 = world.getBlockRandomPos(j, j1, k, 15); + gameProfilerFiller.push("randomTick"); + BlockState iBlockData1 = chunkSection.getBlockState(blockposition2.getX() - j, blockposition2.getY() - j1, blockposition2.getZ() - k); + if (iBlockData1.isRandomlyTicking()) { + iBlockData1.randomTick(world, blockposition2, world.random); + } + + FluidState fluid = iBlockData1.getFluidState(); + if (fluid.isRandomlyTicking()) { + fluid.randomTick(world, blockposition2, world.random); + } + + gameProfilerFiller.pop(); + } + } + } + } + } +} diff --git a/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/spawner/BBaseSpawnerImpl.java new file mode 100644 index 00000000..c3365c6a --- /dev/null +++ b/NMS/NMS-v1_19_R2/src/main/java/com/songoda/core/nms/v1_19_R2/world/spawner/BBaseSpawnerImpl.java @@ -0,0 +1,214 @@ +package com.songoda.core.nms.v1_19_R2.world.spawner; + +import com.songoda.core.nms.world.BBaseSpawner; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.RandomSource; +import net.minecraft.util.random.WeightedEntry; +import net.minecraft.world.Difficulty; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.SpawnPlacements; +import net.minecraft.world.level.BaseSpawner; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LightLayer; +import net.minecraft.world.level.SpawnData; +import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.phys.AABB; +import org.bukkit.block.CreatureSpawner; +import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R2.block.CraftCreatureSpawner; +import org.bukkit.craftbukkit.v1_19_R2.event.CraftEventFactory; +import org.bukkit.event.entity.CreatureSpawnEvent; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Optional; + +public class BBaseSpawnerImpl implements BBaseSpawner { + private final CreatureSpawner bukkitSpawner; + private final BaseSpawner spawner; + + private final Method setNextSpawnDataMethod; + private final Method getOrCreateNextSpawnDataMethod; + + public BBaseSpawnerImpl(CreatureSpawner bukkitSpawner, BaseSpawner spawner) throws NoSuchMethodException { + this.bukkitSpawner = bukkitSpawner; + this.spawner = spawner; + + this.setNextSpawnDataMethod = this.spawner.getClass().getDeclaredMethod("a", Level.class, BlockPos.class, SpawnData.class); + if (!this.setNextSpawnDataMethod.canAccess(this.spawner)) { + this.setNextSpawnDataMethod.setAccessible(true); + } + + this.getOrCreateNextSpawnDataMethod = this.spawner.getClass().getSuperclass().getDeclaredMethod("b", Level.class, RandomSource.class, BlockPos.class); + if (!this.getOrCreateNextSpawnDataMethod.canAccess(this.spawner)) { + this.getOrCreateNextSpawnDataMethod.setAccessible(true); + } + } + + /** + * This method is based on {@link BaseSpawner#isNearPlayer(Level, BlockPos)}. + */ + @SuppressWarnings("JavadocReference") + @Override + public boolean isNearPlayer() { + BlockPos bPos = getBlockPosition(); + return getWorld().hasNearbyAlivePlayer( + (double) bPos.getX() + 0.5, + (double) bPos.getY() + 0.5, + (double) bPos.getZ() + 0.5, + this.spawner.requiredPlayerRange + ); + } + + /** + * This method is based on {@link BaseSpawner#serverTick(ServerLevel, BlockPos)}. + */ + @Override + public void tick() throws InvocationTargetException, IllegalAccessException { + ServerLevel world = getWorld(); + BlockPos bPos = getBlockPosition(); + + if (this.spawner.spawnDelay == -1) { + this.delay(world, bPos); + } + + if (this.spawner.spawnDelay > 0) { + --this.spawner.spawnDelay; + } else { + boolean flag = false; + RandomSource randomsource = world.getRandom(); + SpawnData mobspawnerdata = (SpawnData) this.getOrCreateNextSpawnDataMethod.invoke(this.spawner, world, randomsource, bPos); + int i = 0; + + while (true) { + if (i >= this.spawner.spawnCount) { + if (flag) { + this.delay(world, bPos); + } + break; + } + + CompoundTag nbttagcompound = mobspawnerdata.getEntityToSpawn(); + Optional> optional = EntityType.by(nbttagcompound); + if (optional.isEmpty()) { + this.delay(world, bPos); + return; + } + + ListTag nbttaglist = nbttagcompound.getList("Pos", 6); + int j = nbttaglist.size(); + double d0 = j >= 1 ? nbttaglist.getDouble(0) : (double) bPos.getX() + (randomsource.nextDouble() - randomsource.nextDouble()) * (double) this.spawner.spawnRange + 0.5; + double d1 = j >= 2 ? nbttaglist.getDouble(1) : (double) (bPos.getY() + randomsource.nextInt(3) - 1); + double d2 = j >= 3 ? nbttaglist.getDouble(2) : (double) bPos.getZ() + (randomsource.nextDouble() - randomsource.nextDouble()) * (double) this.spawner.spawnRange + 0.5; + if (world.noCollision(optional.get().getAABB(d0, d1, d2))) { + label128: + { + BlockPos blockposition1 = new BlockPos(d0, d1, d2); + if (mobspawnerdata.getCustomSpawnRules().isPresent()) { + if (!optional.get().getCategory().isFriendly() && world.getDifficulty() == Difficulty.PEACEFUL) { + break label128; + } + + SpawnData.CustomSpawnRules mobspawnerdata_a = mobspawnerdata.getCustomSpawnRules().get(); + if (!mobspawnerdata_a.blockLightLimit().isValueInRange(world.getBrightness(LightLayer.BLOCK, blockposition1)) || !mobspawnerdata_a.skyLightLimit().isValueInRange(world.getBrightness(LightLayer.SKY, blockposition1))) { + break label128; + } + } else if (!SpawnPlacements.checkSpawnRules(optional.get(), world, MobSpawnType.SPAWNER, blockposition1, world.getRandom())) { + break label128; + } + + Entity entity = EntityType.loadEntityRecursive(nbttagcompound, world, (entity1) -> { + entity1.moveTo(d0, d1, d2, entity1.getYRot(), entity1.getXRot()); + return entity1; + }); + if (entity == null) { + this.delay(world, bPos); + return; + } + + int k = world.getEntitiesOfClass(entity.getClass(), (new AABB(bPos.getX(), bPos.getY(), bPos.getZ(), bPos.getX() + 1, bPos.getY() + 1, bPos.getZ() + 1)).inflate(this.spawner.spawnRange)).size(); + if (k >= this.spawner.maxNearbyEntities) { + this.delay(world, bPos); + return; + } + + entity.moveTo(entity.getX(), entity.getY(), entity.getZ(), randomsource.nextFloat() * 360.0F, 0.0F); + if (entity instanceof Mob entityinsentient) { + if (mobspawnerdata.getCustomSpawnRules().isEmpty() && !entityinsentient.checkSpawnRules(world, MobSpawnType.SPAWNER) || !entityinsentient.checkSpawnObstruction(world)) { + break label128; + } + + if (mobspawnerdata.getEntityToSpawn().size() == 1 && mobspawnerdata.getEntityToSpawn().contains("id", 8)) { + ((Mob) entity).finalizeSpawn(world, world.getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.SPAWNER, null, null); + } + + if (entityinsentient.level.spigotConfig.nerfSpawnerMobs) { + entityinsentient.aware = false; + } + } + + if (CraftEventFactory.callSpawnerSpawnEvent(entity, bPos).isCancelled()) { + Entity vehicle = entity.getVehicle(); + if (vehicle != null) { + vehicle.discard(); + } + + for (Entity passenger : entity.getIndirectPassengers()) { + passenger.discard(); + } + } else { + if (!world.tryAddFreshEntityWithPassengers(entity, CreatureSpawnEvent.SpawnReason.SPAWNER)) { + this.delay(world, bPos); + return; + } + + world.levelEvent(2004, bPos, 0); + world.gameEvent(entity, GameEvent.ENTITY_PLACE, blockposition1); + if (entity instanceof Mob) { + ((Mob) entity).spawnAnim(); + } + + flag = true; + } + } + } + + ++i; + } + } + } + + /** + * This method is based on {@link BaseSpawner#delay(Level, BlockPos)}. + */ + @SuppressWarnings("JavadocReference") + private void delay(ServerLevel world, BlockPos bPos) throws InvocationTargetException, IllegalAccessException { + RandomSource randomsource = world.random; + if (this.spawner.maxSpawnDelay <= this.spawner.minSpawnDelay) { + this.spawner.spawnDelay = this.spawner.minSpawnDelay; + } else { + this.spawner.spawnDelay = this.spawner.minSpawnDelay + randomsource.nextInt(this.spawner.maxSpawnDelay - this.spawner.minSpawnDelay); + } + + Optional> weightedEntry = this.spawner.spawnPotentials.getRandom(randomsource); + if (weightedEntry.isPresent()) { + this.setNextSpawnDataMethod.invoke(this.spawner, world, bPos, weightedEntry.get().getData()); + } + + this.spawner.broadcastEvent(world, bPos, 1); + } + + private ServerLevel getWorld() { + return ((CraftWorld) this.bukkitSpawner.getWorld()).getHandle(); + } + + private BlockPos getBlockPosition() { + return ((CraftCreatureSpawner) this.bukkitSpawner).getPosition(); + } +} diff --git a/pom.xml b/pom.xml index cb65e929..8673cba5 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,7 @@ NMS/NMS-v1_18_R2 NMS/NMS-v1_19_R1 NMS/NMS-v1_19_R1v2 + NMS/NMS-v1_19_R2 From 6d28fce312ce4687628958c99ea4b985c64b740e Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Mon, 26 Dec 2022 19:58:33 +0100 Subject: [PATCH 19/20] Updates dependency `de.tr7zw:item-nbt-api` to support Minecraft 1.19.3 --- Core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/pom.xml b/Core/pom.xml index e039eac9..e3962a37 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -128,7 +128,7 @@ de.tr7zw item-nbt-api - 2.10.0 + 2.11.1 compile From 1a911ee085416b3e3d1b46adbb3baafc3902ddd4 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Mon, 26 Dec 2022 19:59:02 +0100 Subject: [PATCH 20/20] Release v2.6.17 --- Compatibility/pom.xml | 2 +- Core/pom.xml | 2 +- Core/src/main/java/com/songoda/core/SongodaCore.java | 2 +- NMS/NMS-API/pom.xml | 2 +- NMS/NMS-v1_10_R1/pom.xml | 2 +- NMS/NMS-v1_11_R1/pom.xml | 2 +- NMS/NMS-v1_12_R1/pom.xml | 2 +- NMS/NMS-v1_13_R1/pom.xml | 2 +- NMS/NMS-v1_13_R2/pom.xml | 2 +- NMS/NMS-v1_14_R1/pom.xml | 2 +- NMS/NMS-v1_15_R1/pom.xml | 2 +- NMS/NMS-v1_16_R1/pom.xml | 2 +- NMS/NMS-v1_16_R2/pom.xml | 2 +- NMS/NMS-v1_16_R3/pom.xml | 2 +- NMS/NMS-v1_17_R1/pom.xml | 2 +- NMS/NMS-v1_18_R1/pom.xml | 2 +- NMS/NMS-v1_18_R2/pom.xml | 2 +- NMS/NMS-v1_19_R1/pom.xml | 2 +- NMS/NMS-v1_19_R1v2/pom.xml | 2 +- NMS/NMS-v1_19_R2/pom.xml | 2 +- NMS/NMS-v1_8_R1/pom.xml | 2 +- NMS/NMS-v1_8_R2/pom.xml | 2 +- NMS/NMS-v1_8_R3/pom.xml | 2 +- NMS/NMS-v1_9_R1/pom.xml | 2 +- NMS/NMS-v1_9_R2/pom.xml | 2 +- pom.xml | 2 +- 26 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Compatibility/pom.xml b/Compatibility/pom.xml index af8d3107..4447adce 100644 --- a/Compatibility/pom.xml +++ b/Compatibility/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../pom.xml diff --git a/Core/pom.xml b/Core/pom.xml index e3962a37..f909dd13 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../pom.xml diff --git a/Core/src/main/java/com/songoda/core/SongodaCore.java b/Core/src/main/java/com/songoda/core/SongodaCore.java index 17b2eff0..96fc0e26 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCore.java +++ b/Core/src/main/java/com/songoda/core/SongodaCore.java @@ -53,7 +53,7 @@ public class SongodaCore { /** * @since coreRevision 6 */ - private final static String coreVersion = "2.6.17-SNAPSHOT"; + private final static String coreVersion = "2.6.17"; /** * This is specific to the website api diff --git a/NMS/NMS-API/pom.xml b/NMS/NMS-API/pom.xml index bceeb0f4..8c07f06f 100644 --- a/NMS/NMS-API/pom.xml +++ b/NMS/NMS-API/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_10_R1/pom.xml b/NMS/NMS-v1_10_R1/pom.xml index 451b740f..ede38c0e 100644 --- a/NMS/NMS-v1_10_R1/pom.xml +++ b/NMS/NMS-v1_10_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_11_R1/pom.xml b/NMS/NMS-v1_11_R1/pom.xml index f8b2a361..128ae780 100644 --- a/NMS/NMS-v1_11_R1/pom.xml +++ b/NMS/NMS-v1_11_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_12_R1/pom.xml b/NMS/NMS-v1_12_R1/pom.xml index 51f573fc..699710e1 100644 --- a/NMS/NMS-v1_12_R1/pom.xml +++ b/NMS/NMS-v1_12_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_13_R1/pom.xml b/NMS/NMS-v1_13_R1/pom.xml index 3547dda3..c409b5ad 100644 --- a/NMS/NMS-v1_13_R1/pom.xml +++ b/NMS/NMS-v1_13_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_13_R2/pom.xml b/NMS/NMS-v1_13_R2/pom.xml index a9e96a65..fdc9d617 100644 --- a/NMS/NMS-v1_13_R2/pom.xml +++ b/NMS/NMS-v1_13_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_14_R1/pom.xml b/NMS/NMS-v1_14_R1/pom.xml index 2b3b7c5a..042c5d36 100644 --- a/NMS/NMS-v1_14_R1/pom.xml +++ b/NMS/NMS-v1_14_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_15_R1/pom.xml b/NMS/NMS-v1_15_R1/pom.xml index a4afd62e..b05e785e 100644 --- a/NMS/NMS-v1_15_R1/pom.xml +++ b/NMS/NMS-v1_15_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_16_R1/pom.xml b/NMS/NMS-v1_16_R1/pom.xml index 800b3eb1..27ea1136 100644 --- a/NMS/NMS-v1_16_R1/pom.xml +++ b/NMS/NMS-v1_16_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_16_R2/pom.xml b/NMS/NMS-v1_16_R2/pom.xml index 6954493c..37c5c42b 100644 --- a/NMS/NMS-v1_16_R2/pom.xml +++ b/NMS/NMS-v1_16_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_16_R3/pom.xml b/NMS/NMS-v1_16_R3/pom.xml index 56a64bdc..1e348f75 100644 --- a/NMS/NMS-v1_16_R3/pom.xml +++ b/NMS/NMS-v1_16_R3/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_17_R1/pom.xml b/NMS/NMS-v1_17_R1/pom.xml index c02142fd..20cc46d7 100644 --- a/NMS/NMS-v1_17_R1/pom.xml +++ b/NMS/NMS-v1_17_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_18_R1/pom.xml b/NMS/NMS-v1_18_R1/pom.xml index 8e01cc7d..274dae3b 100644 --- a/NMS/NMS-v1_18_R1/pom.xml +++ b/NMS/NMS-v1_18_R1/pom.xml @@ -19,7 +19,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_18_R2/pom.xml b/NMS/NMS-v1_18_R2/pom.xml index 1fec2de7..c9795004 100644 --- a/NMS/NMS-v1_18_R2/pom.xml +++ b/NMS/NMS-v1_18_R2/pom.xml @@ -60,7 +60,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_19_R1/pom.xml b/NMS/NMS-v1_19_R1/pom.xml index dfff442a..b4178b84 100644 --- a/NMS/NMS-v1_19_R1/pom.xml +++ b/NMS/NMS-v1_19_R1/pom.xml @@ -60,7 +60,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_19_R1v2/pom.xml b/NMS/NMS-v1_19_R1v2/pom.xml index 4de592fb..47de9855 100644 --- a/NMS/NMS-v1_19_R1v2/pom.xml +++ b/NMS/NMS-v1_19_R1v2/pom.xml @@ -60,7 +60,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_19_R2/pom.xml b/NMS/NMS-v1_19_R2/pom.xml index e826970c..09a72a6a 100644 --- a/NMS/NMS-v1_19_R2/pom.xml +++ b/NMS/NMS-v1_19_R2/pom.xml @@ -60,7 +60,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_8_R1/pom.xml b/NMS/NMS-v1_8_R1/pom.xml index c0670602..1826f481 100644 --- a/NMS/NMS-v1_8_R1/pom.xml +++ b/NMS/NMS-v1_8_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_8_R2/pom.xml b/NMS/NMS-v1_8_R2/pom.xml index d8a20f1f..f57ef13f 100644 --- a/NMS/NMS-v1_8_R2/pom.xml +++ b/NMS/NMS-v1_8_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_8_R3/pom.xml b/NMS/NMS-v1_8_R3/pom.xml index e612e1c1..cd8c3980 100644 --- a/NMS/NMS-v1_8_R3/pom.xml +++ b/NMS/NMS-v1_8_R3/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_9_R1/pom.xml b/NMS/NMS-v1_9_R1/pom.xml index 64902dd8..9a101be7 100644 --- a/NMS/NMS-v1_9_R1/pom.xml +++ b/NMS/NMS-v1_9_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/NMS/NMS-v1_9_R2/pom.xml b/NMS/NMS-v1_9_R2/pom.xml index 58539a26..c9b86983 100644 --- a/NMS/NMS-v1_9_R2/pom.xml +++ b/NMS/NMS-v1_9_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 ../../pom.xml diff --git a/pom.xml b/pom.xml index 8673cba5..c2e7b6e9 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.songoda SongodaCore-Modules - 2.6.17-SNAPSHOT + 2.6.17 pom