From dcd6967828d445498b2b5c7f4e79558e815a67d2 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Thu, 29 Dec 2022 11:28:17 +0100 Subject: [PATCH 01/22] GitHub Actions: Adds Spigot 1.19.3 to the setup-action to compile it --- .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 48f826c7..01227363 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, 1.18.2, 1.19, 1.19.2 + versions: 1.18, 1.18.2, 1.19, 1.19.2, 1.19.3 remapped: true # Build project From 17fb03f0730767f39391d44f5bb813e911b3a37d Mon Sep 17 00:00:00 2001 From: ceze88 Date: Thu, 29 Dec 2022 11:50:51 +0100 Subject: [PATCH 02/22] Fix pre stacking items --- .../core/lootables/loot/DropUtils.java | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 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 4e8e7b72..3f26cd21 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,5 +1,6 @@ package com.songoda.core.lootables.loot; +import com.bgsoftware.wildstacker.api.objects.StackedItem; import com.songoda.core.SongodaCore; import com.songoda.ultimatestacker.UltimateStacker; import com.songoda.ultimatestacker.settings.Settings; @@ -69,30 +70,25 @@ public class DropUtils { private static void dropItems(List items, EntityDeathEvent event) { if (SongodaCore.isRegistered("UltimateStacker")) { List stacks = new ArrayList<>(); + int maxSize = Settings.MAX_STACK_ITEMS.getInt(); for (ItemStack item : items) { - if (stacks.isEmpty()) { + StackedItem stack = stacks.stream().filter(stackedItem -> stackedItem.getItem().getType() == item.getType()).findFirst().orElse(null); + if (stack == null) { stacks.add(new StackedItem(item, item.getAmount())); continue; } - 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(); - 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())); - } + int newAmount = stack.getAmount() + item.getAmount(); + while (newAmount > maxSize) { + newAmount -= maxSize; + stacks.add(new StackedItem(item, maxSize)); } + stack.setamount(newAmount); } - for (StackedItem stack : stacks) { - UltimateStacker.spawnStackedItem(stack.getItem(), stack.getAmount(), event.getEntity().getLocation()); - } + Bukkit.getScheduler().runTask(UltimateStacker.getInstance(), () -> { + for (StackedItem stack : stacks) { + UltimateStacker.spawnStackedItem(stack.getItem(), stack.getAmount(), event.getEntity().getLocation()); + } + }); return; } for (ItemStack item : items) { @@ -101,21 +97,24 @@ public class DropUtils { } private static void runCommands(LivingEntity entity, List commands) { - for (String command : commands) { - if (entity.getKiller() != null) { - command = command.replace("%player%", entity.getKiller().getName()); - } + Bukkit.getScheduler().runTask(SongodaCore.getHijackedPlugin(), () -> { + for (String command : commands) { + if (entity.getKiller() != null) { + command = command.replace("%player%", entity.getKiller().getName()); + } - if (!command.contains("%player%")) { - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + if (!command.contains("%player%")) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + } } - } + }); + } private static class StackedItem { private final ItemStack item; - private final int amount; + private int amount; public StackedItem(ItemStack item, int amount) { this.item = item; @@ -133,5 +132,9 @@ public class DropUtils { public int getAmount() { return amount; } + + public void setamount(int amount) { + this.amount = amount; + } } } From 8ad3bc8ba663f19836349f3432bad846d72349ed Mon Sep 17 00:00:00 2001 From: ceze88 Date: Thu, 29 Dec 2022 11:51:23 +0100 Subject: [PATCH 03/22] Why spihot api wasn't there? --- NMS/NMS-v1_18_R1/pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NMS/NMS-v1_18_R1/pom.xml b/NMS/NMS-v1_18_R1/pom.xml index 274dae3b..64be7009 100644 --- a/NMS/NMS-v1_18_R1/pom.xml +++ b/NMS/NMS-v1_18_R1/pom.xml @@ -26,12 +26,20 @@ 17 17 + + 1.18-R0.1-SNAPSHOT SongodaCore-NMS-v1_18_R1 jar + + org.spigotmc + spigot-api + ${nms.ver} + provided + org.spigotmc spigot From 7ac9b7b28377fd0971d6a9941b2448d37308835c Mon Sep 17 00:00:00 2001 From: ceze88 Date: Thu, 29 Dec 2022 11:52:12 +0100 Subject: [PATCH 04/22] Remove UUID when deserialising NBT --- .../java/com/songoda/core/nms/v1_19_R2/nbt/NBTEntityImpl.java | 1 + 1 file changed, 1 insertion(+) 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 index cd76b620..d5db1d35 100644 --- 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 @@ -25,6 +25,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Optional> optionalEntity = EntityType.byString(entityType); if (optionalEntity.isPresent()) { From f38296e4b186b95bebbe63d09349db2371c0277e Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Thu, 29 Dec 2022 12:24:05 +0100 Subject: [PATCH 05/22] GitHub Actions: Adds Spigot 1.18 + 1.19.3 to SonarCloud --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 366d17cb..e8c2d392 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, 1.19.2 + versions: 1.18, 1.18.2, 1.19, 1.19.2, 1.19.3 remapped: true - name: Analyze project From 8f95056e31caaa6ebcd6916335f8f6b91162e92c Mon Sep 17 00:00:00 2001 From: ceze88 Date: Thu, 29 Dec 2022 13:49:04 +0100 Subject: [PATCH 06/22] A little database utility --- .../com/songoda/core/database/DataManagerAbstract.java | 9 +++++++++ .../com/songoda/core/database/DatabaseConnector.java | 2 ++ .../java/com/songoda/core/database/DatabaseType.java | 8 ++++++++ .../java/com/songoda/core/database/MariaDBConnector.java | 5 +++++ .../java/com/songoda/core/database/MySQLConnector.java | 5 +++++ .../java/com/songoda/core/database/SQLiteConnector.java | 5 +++++ 6 files changed, 34 insertions(+) create mode 100644 Core/src/main/java/com/songoda/core/database/DatabaseType.java diff --git a/Core/src/main/java/com/songoda/core/database/DataManagerAbstract.java b/Core/src/main/java/com/songoda/core/database/DataManagerAbstract.java index c6fcf188..78435c7d 100644 --- a/Core/src/main/java/com/songoda/core/database/DataManagerAbstract.java +++ b/Core/src/main/java/com/songoda/core/database/DataManagerAbstract.java @@ -21,6 +21,7 @@ import java.util.function.Consumer; public class DataManagerAbstract { protected final DatabaseConnector databaseConnector; protected final Plugin plugin; + protected final DatabaseType type; protected final ExecutorService asyncPool = Executors.newSingleThreadExecutor(); @@ -30,6 +31,7 @@ public class DataManagerAbstract { public DataManagerAbstract(DatabaseConnector databaseConnector, Plugin plugin) { this.databaseConnector = databaseConnector; this.plugin = plugin; + this.type = databaseConnector.getType(); } /** @@ -196,4 +198,11 @@ public class DataManagerAbstract { }); }); } + + public String getSyntax(String string, DatabaseType type) { + if (this.type == type) { + return string; + } + return ""; + } } diff --git a/Core/src/main/java/com/songoda/core/database/DatabaseConnector.java b/Core/src/main/java/com/songoda/core/database/DatabaseConnector.java index 7d0c0ff2..2be85c25 100644 --- a/Core/src/main/java/com/songoda/core/database/DatabaseConnector.java +++ b/Core/src/main/java/com/songoda/core/database/DatabaseConnector.java @@ -31,4 +31,6 @@ public interface DatabaseConnector { } Connection getConnection(); + + DatabaseType getType(); } diff --git a/Core/src/main/java/com/songoda/core/database/DatabaseType.java b/Core/src/main/java/com/songoda/core/database/DatabaseType.java new file mode 100644 index 00000000..e7ac08d6 --- /dev/null +++ b/Core/src/main/java/com/songoda/core/database/DatabaseType.java @@ -0,0 +1,8 @@ +package com.songoda.core.database; + +public enum DatabaseType { + + MARIADB, + MYSQL, + SQLITE +} diff --git a/Core/src/main/java/com/songoda/core/database/MariaDBConnector.java b/Core/src/main/java/com/songoda/core/database/MariaDBConnector.java index 061191df..7a507a5c 100644 --- a/Core/src/main/java/com/songoda/core/database/MariaDBConnector.java +++ b/Core/src/main/java/com/songoda/core/database/MariaDBConnector.java @@ -62,4 +62,9 @@ public class MariaDBConnector implements DatabaseConnector { } return null; } + + @Override + public DatabaseType getType() { + return DatabaseType.MARIADB; + } } diff --git a/Core/src/main/java/com/songoda/core/database/MySQLConnector.java b/Core/src/main/java/com/songoda/core/database/MySQLConnector.java index 1b2fe4c1..910c8836 100644 --- a/Core/src/main/java/com/songoda/core/database/MySQLConnector.java +++ b/Core/src/main/java/com/songoda/core/database/MySQLConnector.java @@ -61,4 +61,9 @@ public class MySQLConnector implements DatabaseConnector { } return null; } + + @Override + public DatabaseType getType() { + return DatabaseType.MYSQL; + } } 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 7ffbbf22..6882e2c5 100644 --- a/Core/src/main/java/com/songoda/core/database/SQLiteConnector.java +++ b/Core/src/main/java/com/songoda/core/database/SQLiteConnector.java @@ -65,4 +65,9 @@ public class SQLiteConnector implements DatabaseConnector { } return this.connection; } + + @Override + public DatabaseType getType() { + return DatabaseType.SQLITE; + } } From a554934bfa9aa478628b5c30e11666a2590492d3 Mon Sep 17 00:00:00 2001 From: ceze88 Date: Thu, 29 Dec 2022 13:49:34 +0100 Subject: [PATCH 07/22] Remove deprecated constructor --- .../main/java/com/songoda/core/core/SongodaCoreDiagCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/main/java/com/songoda/core/core/SongodaCoreDiagCommand.java b/Core/src/main/java/com/songoda/core/core/SongodaCoreDiagCommand.java index 28ed2644..04c2a94b 100644 --- a/Core/src/main/java/com/songoda/core/core/SongodaCoreDiagCommand.java +++ b/Core/src/main/java/com/songoda/core/core/SongodaCoreDiagCommand.java @@ -20,7 +20,7 @@ public class SongodaCoreDiagCommand extends AbstractCommand { private Field tpsField; public SongodaCoreDiagCommand() { - super(false, "diag"); + super(CommandType.CONSOLE_OK, "diag"); try { serverInstance = ClassMapping.MINECRAFT_SERVER.getClazz().getMethod("getServer").invoke(null); From ea10cc2e3f8c332b66c95bf5998210f36257ee59 Mon Sep 17 00:00:00 2001 From: ceze88 Date: Thu, 29 Dec 2022 17:26:23 +0100 Subject: [PATCH 08/22] Don't override uuid --- .../java/com/songoda/core/nms/v1_10_R1/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_11_R1/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_12_R1/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_13_R1/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_13_R2/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_14_R1/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_16_R1/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_16_R2/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_16_R3/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_17_R1/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_18_R1/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_18_R2/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_19_R1/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_19_R1v2/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_8_R1/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_8_R2/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_8_R3/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_9_R1/nbt/NBTEntityImpl.java | 1 + .../java/com/songoda/core/nms/v1_9_R2/nbt/NBTEntityImpl.java | 1 + 19 files changed, 19 insertions(+) diff --git a/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTEntityImpl.java index 101ea777..9290ec04 100644 --- a/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTEntityImpl.java @@ -21,6 +21,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14 ((CraftWorld) location.getWorld()).getHandle(), diff --git a/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTEntityImpl.java index 59dce207..081e56e6 100644 --- a/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTEntityImpl.java @@ -22,6 +22,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14 ((CraftWorld) location.getWorld()).getHandle(), diff --git a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTEntityImpl.java index 45aa80f4..16b499f7 100644 --- a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTEntityImpl.java @@ -22,6 +22,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14 ((CraftWorld) location.getWorld()).getHandle(), diff --git a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTEntityImpl.java index ded0cccb..c5794391 100644 --- a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTEntityImpl.java @@ -24,6 +24,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Optional> optionalEntity = Optional.ofNullable(EntityTypes.a(entityType)); // Changed since 1.13.2 if (optionalEntity.isPresent()) { diff --git a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTEntityImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTEntityImpl.java index 58192c92..d43c78eb 100644 --- a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTEntityImpl.java @@ -24,6 +24,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Optional> optionalEntity = Optional.ofNullable(EntityTypes.a(entityType)); // Changed since 1.13.2 if (optionalEntity.isPresent()) { diff --git a/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTEntityImpl.java index 8a272a67..d1e42d56 100644 --- a/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTEntityImpl.java @@ -24,6 +24,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Optional> optionalEntity = EntityTypes.a(entityType); if (optionalEntity.isPresent()) { diff --git a/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTEntityImpl.java index 2c29f250..6e88a4a2 100644 --- a/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTEntityImpl.java @@ -24,6 +24,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Optional> optionalEntity = EntityTypes.a(entityType); if (optionalEntity.isPresent()) { diff --git a/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTEntityImpl.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTEntityImpl.java index 504b3ec5..1258ef25 100644 --- a/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTEntityImpl.java @@ -24,6 +24,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Optional> optionalEntity = EntityTypes.a(entityType); if (optionalEntity.isPresent()) { diff --git a/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTEntityImpl.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTEntityImpl.java index de9202e4..d3383570 100644 --- a/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTEntityImpl.java @@ -24,6 +24,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Optional> optionalEntity = EntityTypes.a(entityType); if (optionalEntity.isPresent()) { diff --git a/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTEntityImpl.java index 1ec46246..797e5fe8 100644 --- a/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTEntityImpl.java @@ -24,6 +24,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Optional> optionalEntity = EntityTypes.a(entityType); if (optionalEntity.isPresent()) { diff --git a/NMS/NMS-v1_18_R1/src/main/java/com/songoda/core/nms/v1_18_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_18_R1/src/main/java/com/songoda/core/nms/v1_18_R1/nbt/NBTEntityImpl.java index c8d7faee..7666db2d 100644 --- a/NMS/NMS-v1_18_R1/src/main/java/com/songoda/core/nms/v1_18_R1/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_18_R1/src/main/java/com/songoda/core/nms/v1_18_R1/nbt/NBTEntityImpl.java @@ -24,6 +24,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Optional> optionalEntity = EntityTypes.a(entityType); if (optionalEntity.isPresent()) { diff --git a/NMS/NMS-v1_18_R2/src/main/java/com/songoda/core/nms/v1_18_R2/nbt/NBTEntityImpl.java b/NMS/NMS-v1_18_R2/src/main/java/com/songoda/core/nms/v1_18_R2/nbt/NBTEntityImpl.java index cbbca061..797149fa 100644 --- a/NMS/NMS-v1_18_R2/src/main/java/com/songoda/core/nms/v1_18_R2/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_18_R2/src/main/java/com/songoda/core/nms/v1_18_R2/nbt/NBTEntityImpl.java @@ -24,6 +24,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Optional> optionalEntity = EntityType.byString(entityType); if (optionalEntity.isPresent()) { diff --git a/NMS/NMS-v1_19_R1/src/main/java/com/songoda/core/nms/v1_19_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_19_R1/src/main/java/com/songoda/core/nms/v1_19_R1/nbt/NBTEntityImpl.java index 3c768325..04fe3939 100644 --- a/NMS/NMS-v1_19_R1/src/main/java/com/songoda/core/nms/v1_19_R1/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_19_R1/src/main/java/com/songoda/core/nms/v1_19_R1/nbt/NBTEntityImpl.java @@ -24,6 +24,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Optional> optionalEntity = EntityType.byString(entityType); if (optionalEntity.isPresent()) { 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 index cdc9c36b..cb9a39e4 100644 --- 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 @@ -24,6 +24,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Optional> optionalEntity = EntityType.byString(entityType); if (optionalEntity.isPresent()) { diff --git a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTEntityImpl.java index d793ef3e..b2e4f094 100644 --- a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTEntityImpl.java @@ -35,6 +35,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); try { Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14 diff --git a/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTEntityImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTEntityImpl.java index 6114833b..87417d09 100644 --- a/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTEntityImpl.java @@ -35,6 +35,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); try { Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14 diff --git a/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTEntityImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTEntityImpl.java index 29d726f7..31cbb092 100644 --- a/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTEntityImpl.java @@ -36,6 +36,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); try { Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14 diff --git a/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTEntityImpl.java index f5341176..956b901f 100644 --- a/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTEntityImpl.java @@ -21,6 +21,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14 ((CraftWorld) location.getWorld()).getHandle(), diff --git a/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTEntityImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTEntityImpl.java index 5c705453..d626b22d 100644 --- a/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTEntityImpl.java @@ -21,6 +21,7 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { @Override public org.bukkit.entity.Entity spawn(Location location) { String entityType = getNBTObject("entity_type").asString(); + getKeys().remove("UUID"); Entity spawned = ItemMonsterEgg.spawnCreature( // Changed since 1.14 ((CraftWorld) location.getWorld()).getHandle(), From 842841cd749c45ad9f5f2e62e3aab8dc2dce8e5c Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Fri, 30 Dec 2022 20:09:01 +0100 Subject: [PATCH 09/22] Fixes NMS for Spigot 1.19.0 / 1.19.1 / 1.19.2 detection Purpur-Spigot and plain Spigot do not end with `.0`. Not sure if Paper does or Spigot 1.19.1 does? I just added the plain `1.19` check. This is not an issue in the Core v3 branch as the check is more stable there. --- Core/src/main/java/com/songoda/core/nms/NmsManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 63568efe..24c4939e 100644 --- a/Core/src/main/java/com/songoda/core/nms/NmsManager.java +++ b/Core/src/main/java/com/songoda/core/nms/NmsManager.java @@ -129,7 +129,7 @@ public class NmsManager { world = new com.songoda.core.nms.v1_18_R2.world.WorldCoreImpl(); break; case "v1_19_R1": - if (bukkitVersion.endsWith(".0")) { + if (bukkitVersion.endsWith(".0") || bukkitVersion.equals("1.19")) { 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(); From bd187c7512f94c9ea001424fac3e462bf069be42 Mon Sep 17 00:00:00 2001 From: ceze88 Date: Sat, 31 Dec 2022 20:42:03 +0100 Subject: [PATCH 10/22] Fix max stack size for drops --- .../java/com/songoda/core/lootables/loot/DropUtils.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 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 3f26cd21..40f00351 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 @@ -6,9 +6,12 @@ import com.songoda.ultimatestacker.UltimateStacker; import com.songoda.ultimatestacker.settings.Settings; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.loot.LootTable; import java.util.ArrayList; import java.util.List; @@ -70,7 +73,7 @@ public class DropUtils { private static void dropItems(List items, EntityDeathEvent event) { if (SongodaCore.isRegistered("UltimateStacker")) { List stacks = new ArrayList<>(); - int maxSize = Settings.MAX_STACK_ITEMS.getInt(); + int maxSize = Settings.MAX_STACK_ITEMS.getInt()-64; for (ItemStack item : items) { StackedItem stack = stacks.stream().filter(stackedItem -> stackedItem.getItem().getType() == item.getType()).findFirst().orElse(null); if (stack == null) { @@ -91,9 +94,7 @@ public class DropUtils { }); return; } - for (ItemStack item : items) { - event.getDrops().add(item); - } + event.getDrops().addAll(items); } private static void runCommands(LivingEntity entity, List commands) { From 10aac8c10fa464ca41caab1db033394676c029fc Mon Sep 17 00:00:00 2001 From: ceze88 Date: Mon, 2 Jan 2023 13:39:54 +0100 Subject: [PATCH 11/22] License system --- .../java/com/songoda/core/SongodaCore.java | 97 ++++++++++++++++++- .../core/core/SongodaCoreIPCommand.java | 75 ++++++++++++++ .../core/SongodaCoreSetAPIKeyCommand.java | 55 +++++++++++ 3 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 Core/src/main/java/com/songoda/core/core/SongodaCoreIPCommand.java create mode 100644 Core/src/main/java/com/songoda/core/core/SongodaCoreSetAPIKeyCommand.java diff --git a/Core/src/main/java/com/songoda/core/SongodaCore.java b/Core/src/main/java/com/songoda/core/SongodaCore.java index 96fc0e26..6c080d4d 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCore.java +++ b/Core/src/main/java/com/songoda/core/SongodaCore.java @@ -8,6 +8,8 @@ import com.songoda.core.core.PluginInfo; import com.songoda.core.core.PluginInfoModule; import com.songoda.core.core.SongodaCoreCommand; import com.songoda.core.core.SongodaCoreDiagCommand; +import com.songoda.core.core.SongodaCoreIPCommand; +import com.songoda.core.core.SongodaCoreSetAPIKeyCommand; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -24,13 +26,20 @@ import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -67,6 +76,7 @@ public class SongodaCore { private CommandManager commandManager; private EventListener loginListener; private ShadedEventListener shadingListener; + private static String apiKey; public static boolean hasShading() { // sneaky hack to check the package name since maven tries to re-shade all references to the package string @@ -172,7 +182,7 @@ public class SongodaCore { private void init() { shadingListener = new ShadedEventListener(); commandManager.registerCommandDynamically(new SongodaCoreCommand()) - .addSubCommand(new SongodaCoreDiagCommand()); + .addSubCommands(new SongodaCoreDiagCommand(), new SongodaCoreIPCommand(), new SongodaCoreSetAPIKeyCommand()); Bukkit.getPluginManager().registerEvents(loginListener, piggybackedPlugin); Bukkit.getPluginManager().registerEvents(shadingListener, piggybackedPlugin); @@ -188,6 +198,82 @@ public class SongodaCore { 20 * 60 * 2)); } + private boolean checkAPIKey() { + String currentDir = System.getProperty("user.dir"); + File tokenFile = new File(currentDir).getParentFile().toPath().resolve(".songoda-marketplace.key").toFile(); + if (!tokenFile.exists()) { + return false; + } + + try (BufferedReader reader = new BufferedReader(new FileReader(tokenFile))) { + String token = reader.readLine(); + if (token == null || token.isEmpty()) { + return false; + } + token = token; + return true; + } catch (IOException ex) { + return false; + } + } + + public static void setAPIKey(String token) { + token = token; + //Save token to file + String currentDir = System.getProperty("user.dir"); + File tokenFile = new File(currentDir).getParentFile().toPath().resolve(".songoda-marketplace.key").toFile(); + try (BufferedWriter writer = new BufferedWriter(new FileWriter(tokenFile))) { + writer.write(token); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public String getAPIKey() { + return apiKey; + } + + public static boolean hasAPIKey() { + return apiKey != null; + } + + private boolean checkPluginAccess(int id, String name) { + //No need to check Ultimate series since they are all free + if (name.toLowerCase().startsWith("ultimate")) { + return true; + } + if (!hasAPIKey()) { + return false; + } + try { + URL url = new URL("https://marketplace.songoda.com/api/v2/products/license/validate"); + HttpURLConnection con = (HttpURLConnection)url.openConnection(); + con.setRequestMethod("POST"); + con.setRequestProperty("Content-Type", "application/json"); + con.setRequestProperty("Accept", "application/json"); + con.setDoOutput(true); + String jsonInputString = "{\"product_id\":" + id + ",\"license\":\"" + apiKey + "\"}"; + try(OutputStream os = con.getOutputStream()) { + byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); + os.write(input, 0, input.length); + } + + try(BufferedReader br = new BufferedReader( + new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { + StringBuilder response = new StringBuilder(); + String responseLine = null; + while ((responseLine = br.readLine()) != null) { + response.append(responseLine.trim()); + } + return response.toString().contains("true"); + } + + } catch (Exception e) { + logger.log(Level.WARNING, "Error checking plugin access for " + name); + } + return true; + } + /** * Used to yield this core to a newer core */ @@ -210,6 +296,15 @@ public class SongodaCore { private ArrayList tasks = new ArrayList<>(); private void register(JavaPlugin plugin, int pluginID, String icon, String libraryVersion) { + if(!checkPluginAccess(pluginID, plugin.getName())) { + plugin.getServer().getPluginManager().disablePlugin(plugin); + if (hasAPIKey()) { + logger.log(Level.WARNING, "You do not have access to " + plugin.getName() + " on this server. Please check your license key."); + } else { + logger.log(Level.WARNING, "You do not have access to " + plugin.getName() + " on this server. Please set your license key."); + } + return; + } logger.info(getPrefix() + "Hooked " + plugin.getName() + "."); PluginInfo info = new PluginInfo(plugin, pluginID, icon, libraryVersion); diff --git a/Core/src/main/java/com/songoda/core/core/SongodaCoreIPCommand.java b/Core/src/main/java/com/songoda/core/core/SongodaCoreIPCommand.java new file mode 100644 index 00000000..bcf4824a --- /dev/null +++ b/Core/src/main/java/com/songoda/core/core/SongodaCoreIPCommand.java @@ -0,0 +1,75 @@ +package com.songoda.core.core; + +import com.songoda.core.commands.AbstractCommand; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.impl.client.HttpClients; +import org.bukkit.command.CommandSender; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.List; + +public class SongodaCoreIPCommand extends AbstractCommand { + + public SongodaCoreIPCommand() { + super(CommandType.CONSOLE_OK, "myip"); + } + + @Override + protected ReturnType runCommand(CommandSender sender, String... args) { + try { + HttpClient httpclient = HttpClients.createDefault(); + HttpPost httppost = new HttpPost("https://marketplace.songoda.com/api/v2/products/license/ip"); + + HttpResponse response = httpclient.execute(httppost); + HttpEntity entity = response.getEntity(); + + if (entity != null) { + try (InputStream inputStream = entity.getContent()) { + //Read json and get ip key value + JSONParser parser = new JSONParser(); + JSONObject json = (JSONObject) parser.parse(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); + String ip = (String) json.get("ip"); + sender.sendMessage(""); + sender.sendMessage("IP Information"); + sender.sendMessage(""); + sender.sendMessage("Public IP: " + ip); + sender.sendMessage(""); + return ReturnType.SUCCESS; + } catch (Exception ignored) {} + } + + } catch (Exception ignored) {} + + sender.sendMessage("Error: Could not get IP information."); + return ReturnType.SUCCESS; + } + + @Override + protected List onTab(CommandSender sender, String... args) { + return null; + } + + @Override + public String getPermissionNode() { + return "songoda.admin"; + } + + @Override + public String getSyntax() { + return "/songoda myip"; + } + + @Override + public String getDescription() { + return "Displays your public IP address."; + } +} diff --git a/Core/src/main/java/com/songoda/core/core/SongodaCoreSetAPIKeyCommand.java b/Core/src/main/java/com/songoda/core/core/SongodaCoreSetAPIKeyCommand.java new file mode 100644 index 00000000..897077f8 --- /dev/null +++ b/Core/src/main/java/com/songoda/core/core/SongodaCoreSetAPIKeyCommand.java @@ -0,0 +1,55 @@ +package com.songoda.core.core; + +import com.songoda.core.SongodaCore; +import com.songoda.core.commands.AbstractCommand; +import org.bukkit.command.CommandSender; + +import java.util.List; +import java.util.UUID; + +public class SongodaCoreSetAPIKeyCommand extends AbstractCommand { + + public SongodaCoreSetAPIKeyCommand() { + super(CommandType.CONSOLE_OK, "key"); + } + + @Override + protected ReturnType runCommand(CommandSender sender, String... args) { + if (args.length == 0) { + sender.sendMessage("Please provide an API key."); + return ReturnType.FAILURE; + } + + String key = args[0]; + + //Let's check if the key is in the correct format + UUID uuid = UUID.fromString(key); + if (uuid.version() != 4) { + sender.sendMessage("The API key you provided is not in the correct format."); + return ReturnType.FAILURE; + } + SongodaCore.setAPIKey(key); + sender.sendMessage("API key set."); + return ReturnType.SUCCESS; + } + + @Override + protected List onTab(CommandSender sender, String... args) { + return null; + } + + @Override + public String getPermissionNode() { + return "songodacore.admin"; + } + + @Override + public String getSyntax() { + return "/songodacore key "; + } + + @Override + public String getDescription() { + return "Sets the stored API key."; + } +} From 336c5c49f3fd88330f0d1f02ff4fa3604d1aaf45 Mon Sep 17 00:00:00 2001 From: ceze88 Date: Mon, 2 Jan 2023 13:39:54 +0100 Subject: [PATCH 12/22] Revert "License system" This reverts commit 10aac8c10fa464ca41caab1db033394676c029fc. --- .../java/com/songoda/core/SongodaCore.java | 97 +------------------ .../core/core/SongodaCoreIPCommand.java | 75 -------------- .../core/SongodaCoreSetAPIKeyCommand.java | 55 ----------- 3 files changed, 1 insertion(+), 226 deletions(-) delete mode 100644 Core/src/main/java/com/songoda/core/core/SongodaCoreIPCommand.java delete mode 100644 Core/src/main/java/com/songoda/core/core/SongodaCoreSetAPIKeyCommand.java diff --git a/Core/src/main/java/com/songoda/core/SongodaCore.java b/Core/src/main/java/com/songoda/core/SongodaCore.java index 6c080d4d..96fc0e26 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCore.java +++ b/Core/src/main/java/com/songoda/core/SongodaCore.java @@ -8,8 +8,6 @@ import com.songoda.core.core.PluginInfo; import com.songoda.core.core.PluginInfoModule; import com.songoda.core.core.SongodaCoreCommand; import com.songoda.core.core.SongodaCoreDiagCommand; -import com.songoda.core.core.SongodaCoreIPCommand; -import com.songoda.core.core.SongodaCoreSetAPIKeyCommand; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -26,20 +24,13 @@ import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.OutputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.URL; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -76,7 +67,6 @@ public class SongodaCore { private CommandManager commandManager; private EventListener loginListener; private ShadedEventListener shadingListener; - private static String apiKey; public static boolean hasShading() { // sneaky hack to check the package name since maven tries to re-shade all references to the package string @@ -182,7 +172,7 @@ public class SongodaCore { private void init() { shadingListener = new ShadedEventListener(); commandManager.registerCommandDynamically(new SongodaCoreCommand()) - .addSubCommands(new SongodaCoreDiagCommand(), new SongodaCoreIPCommand(), new SongodaCoreSetAPIKeyCommand()); + .addSubCommand(new SongodaCoreDiagCommand()); Bukkit.getPluginManager().registerEvents(loginListener, piggybackedPlugin); Bukkit.getPluginManager().registerEvents(shadingListener, piggybackedPlugin); @@ -198,82 +188,6 @@ public class SongodaCore { 20 * 60 * 2)); } - private boolean checkAPIKey() { - String currentDir = System.getProperty("user.dir"); - File tokenFile = new File(currentDir).getParentFile().toPath().resolve(".songoda-marketplace.key").toFile(); - if (!tokenFile.exists()) { - return false; - } - - try (BufferedReader reader = new BufferedReader(new FileReader(tokenFile))) { - String token = reader.readLine(); - if (token == null || token.isEmpty()) { - return false; - } - token = token; - return true; - } catch (IOException ex) { - return false; - } - } - - public static void setAPIKey(String token) { - token = token; - //Save token to file - String currentDir = System.getProperty("user.dir"); - File tokenFile = new File(currentDir).getParentFile().toPath().resolve(".songoda-marketplace.key").toFile(); - try (BufferedWriter writer = new BufferedWriter(new FileWriter(tokenFile))) { - writer.write(token); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - public String getAPIKey() { - return apiKey; - } - - public static boolean hasAPIKey() { - return apiKey != null; - } - - private boolean checkPluginAccess(int id, String name) { - //No need to check Ultimate series since they are all free - if (name.toLowerCase().startsWith("ultimate")) { - return true; - } - if (!hasAPIKey()) { - return false; - } - try { - URL url = new URL("https://marketplace.songoda.com/api/v2/products/license/validate"); - HttpURLConnection con = (HttpURLConnection)url.openConnection(); - con.setRequestMethod("POST"); - con.setRequestProperty("Content-Type", "application/json"); - con.setRequestProperty("Accept", "application/json"); - con.setDoOutput(true); - String jsonInputString = "{\"product_id\":" + id + ",\"license\":\"" + apiKey + "\"}"; - try(OutputStream os = con.getOutputStream()) { - byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); - os.write(input, 0, input.length); - } - - try(BufferedReader br = new BufferedReader( - new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { - StringBuilder response = new StringBuilder(); - String responseLine = null; - while ((responseLine = br.readLine()) != null) { - response.append(responseLine.trim()); - } - return response.toString().contains("true"); - } - - } catch (Exception e) { - logger.log(Level.WARNING, "Error checking plugin access for " + name); - } - return true; - } - /** * Used to yield this core to a newer core */ @@ -296,15 +210,6 @@ public class SongodaCore { private ArrayList tasks = new ArrayList<>(); private void register(JavaPlugin plugin, int pluginID, String icon, String libraryVersion) { - if(!checkPluginAccess(pluginID, plugin.getName())) { - plugin.getServer().getPluginManager().disablePlugin(plugin); - if (hasAPIKey()) { - logger.log(Level.WARNING, "You do not have access to " + plugin.getName() + " on this server. Please check your license key."); - } else { - logger.log(Level.WARNING, "You do not have access to " + plugin.getName() + " on this server. Please set your license key."); - } - return; - } logger.info(getPrefix() + "Hooked " + plugin.getName() + "."); PluginInfo info = new PluginInfo(plugin, pluginID, icon, libraryVersion); diff --git a/Core/src/main/java/com/songoda/core/core/SongodaCoreIPCommand.java b/Core/src/main/java/com/songoda/core/core/SongodaCoreIPCommand.java deleted file mode 100644 index bcf4824a..00000000 --- a/Core/src/main/java/com/songoda/core/core/SongodaCoreIPCommand.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.songoda.core.core; - -import com.songoda.core.commands.AbstractCommand; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.impl.client.HttpClients; -import org.bukkit.command.CommandSender; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; - -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.List; - -public class SongodaCoreIPCommand extends AbstractCommand { - - public SongodaCoreIPCommand() { - super(CommandType.CONSOLE_OK, "myip"); - } - - @Override - protected ReturnType runCommand(CommandSender sender, String... args) { - try { - HttpClient httpclient = HttpClients.createDefault(); - HttpPost httppost = new HttpPost("https://marketplace.songoda.com/api/v2/products/license/ip"); - - HttpResponse response = httpclient.execute(httppost); - HttpEntity entity = response.getEntity(); - - if (entity != null) { - try (InputStream inputStream = entity.getContent()) { - //Read json and get ip key value - JSONParser parser = new JSONParser(); - JSONObject json = (JSONObject) parser.parse(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); - String ip = (String) json.get("ip"); - sender.sendMessage(""); - sender.sendMessage("IP Information"); - sender.sendMessage(""); - sender.sendMessage("Public IP: " + ip); - sender.sendMessage(""); - return ReturnType.SUCCESS; - } catch (Exception ignored) {} - } - - } catch (Exception ignored) {} - - sender.sendMessage("Error: Could not get IP information."); - return ReturnType.SUCCESS; - } - - @Override - protected List onTab(CommandSender sender, String... args) { - return null; - } - - @Override - public String getPermissionNode() { - return "songoda.admin"; - } - - @Override - public String getSyntax() { - return "/songoda myip"; - } - - @Override - public String getDescription() { - return "Displays your public IP address."; - } -} diff --git a/Core/src/main/java/com/songoda/core/core/SongodaCoreSetAPIKeyCommand.java b/Core/src/main/java/com/songoda/core/core/SongodaCoreSetAPIKeyCommand.java deleted file mode 100644 index 897077f8..00000000 --- a/Core/src/main/java/com/songoda/core/core/SongodaCoreSetAPIKeyCommand.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.songoda.core.core; - -import com.songoda.core.SongodaCore; -import com.songoda.core.commands.AbstractCommand; -import org.bukkit.command.CommandSender; - -import java.util.List; -import java.util.UUID; - -public class SongodaCoreSetAPIKeyCommand extends AbstractCommand { - - public SongodaCoreSetAPIKeyCommand() { - super(CommandType.CONSOLE_OK, "key"); - } - - @Override - protected ReturnType runCommand(CommandSender sender, String... args) { - if (args.length == 0) { - sender.sendMessage("Please provide an API key."); - return ReturnType.FAILURE; - } - - String key = args[0]; - - //Let's check if the key is in the correct format - UUID uuid = UUID.fromString(key); - if (uuid.version() != 4) { - sender.sendMessage("The API key you provided is not in the correct format."); - return ReturnType.FAILURE; - } - SongodaCore.setAPIKey(key); - sender.sendMessage("API key set."); - return ReturnType.SUCCESS; - } - - @Override - protected List onTab(CommandSender sender, String... args) { - return null; - } - - @Override - public String getPermissionNode() { - return "songodacore.admin"; - } - - @Override - public String getSyntax() { - return "/songodacore key "; - } - - @Override - public String getDescription() { - return "Sets the stored API key."; - } -} From ad6b52ca4a7f16f7ad9b2284dcc0adc5417b0e87 Mon Sep 17 00:00:00 2001 From: ceze88 Date: Wed, 11 Jan 2023 21:41:04 +0100 Subject: [PATCH 13/22] Add license stuff --- .../java/com/songoda/core/SongodaCore.java | 4 +- .../java/com/songoda/core/SongodaPlugin.java | 19 +++ .../core/core/SongodaCoreIPCommand.java | 73 ++++++++++++ .../core/core/SongodaCoreUUIDCommand.java | 55 +++++++++ .../com/songoda/core/utils/SongodaAuth.java | 109 ++++++++++++++++++ 5 files changed, 259 insertions(+), 1 deletion(-) create mode 100644 Core/src/main/java/com/songoda/core/core/SongodaCoreIPCommand.java create mode 100644 Core/src/main/java/com/songoda/core/core/SongodaCoreUUIDCommand.java create mode 100644 Core/src/main/java/com/songoda/core/utils/SongodaAuth.java diff --git a/Core/src/main/java/com/songoda/core/SongodaCore.java b/Core/src/main/java/com/songoda/core/SongodaCore.java index 96fc0e26..41464bb5 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCore.java +++ b/Core/src/main/java/com/songoda/core/SongodaCore.java @@ -8,6 +8,8 @@ import com.songoda.core.core.PluginInfo; import com.songoda.core.core.PluginInfoModule; import com.songoda.core.core.SongodaCoreCommand; import com.songoda.core.core.SongodaCoreDiagCommand; +import com.songoda.core.core.SongodaCoreIPCommand; +import com.songoda.core.core.SongodaCoreUUIDCommand; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -172,7 +174,7 @@ public class SongodaCore { private void init() { shadingListener = new ShadedEventListener(); commandManager.registerCommandDynamically(new SongodaCoreCommand()) - .addSubCommand(new SongodaCoreDiagCommand()); + .addSubCommands(new SongodaCoreDiagCommand(), new SongodaCoreIPCommand(), new SongodaCoreUUIDCommand()); Bukkit.getPluginManager().registerEvents(loginListener, piggybackedPlugin); Bukkit.getPluginManager().registerEvents(shadingListener, piggybackedPlugin); diff --git a/Core/src/main/java/com/songoda/core/SongodaPlugin.java b/Core/src/main/java/com/songoda/core/SongodaPlugin.java index 8b700be9..22541d15 100644 --- a/Core/src/main/java/com/songoda/core/SongodaPlugin.java +++ b/Core/src/main/java/com/songoda/core/SongodaPlugin.java @@ -4,6 +4,7 @@ import com.songoda.core.configuration.Config; import com.songoda.core.database.DataManagerAbstract; import com.songoda.core.locale.Locale; import com.songoda.core.utils.Metrics; +import com.songoda.core.utils.SongodaAuth; import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -90,6 +91,24 @@ public abstract class SongodaPlugin extends JavaPlugin { return; } + //Check plugin access, don't load plugin if user don't have access + if (!SongodaAuth.isAuthorized(true)) { + Thread thread = new Thread(() -> { + console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + console.sendMessage(ChatColor.RED + "You do not have access to this plugin."); + console.sendMessage(ChatColor.YELLOW + "Please purchase a license at https://sngda.to/marketplace"); + console.sendMessage(ChatColor.YELLOW + "or set up your license at https://sngda.to/licenses"); + console.sendMessage(ChatColor.YELLOW + "License setup steps:"); + console.sendMessage(ChatColor.YELLOW + "Visit the link mentioned above and click the 'Create License button'"); + console.sendMessage(ChatColor.YELLOW + "Copy the following ip and uuid and click create."); + console.sendMessage(ChatColor.YELLOW + "IP: " + SongodaAuth.getIP()); + console.sendMessage(ChatColor.YELLOW + "UUID: " + SongodaAuth.getUUID()); + console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + }); + thread.start(); + return; + } + console.sendMessage(" "); // blank line to separate chatter console.sendMessage(ChatColor.GREEN + "============================="); console.sendMessage(String.format("%s%s %s by %sSongoda <3!", ChatColor.GRAY, diff --git a/Core/src/main/java/com/songoda/core/core/SongodaCoreIPCommand.java b/Core/src/main/java/com/songoda/core/core/SongodaCoreIPCommand.java new file mode 100644 index 00000000..6f0e8a8c --- /dev/null +++ b/Core/src/main/java/com/songoda/core/core/SongodaCoreIPCommand.java @@ -0,0 +1,73 @@ +package com.songoda.core.core; + +import com.songoda.core.commands.AbstractCommand; +import com.songoda.core.utils.SongodaAuth; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.impl.client.HttpClients; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.List; + +public class SongodaCoreIPCommand extends AbstractCommand { + + public SongodaCoreIPCommand() { + super(CommandType.CONSOLE_OK, "myip"); + } + + @Override + protected ReturnType runCommand(CommandSender sender, String... args) { + Thread thread = new Thread(() -> { + String ip = SongodaAuth.getIP(); + sender.sendMessage(""); + sender.sendMessage("IP Information"); + sender.sendMessage(""); + if (sender instanceof Player) { + TextComponent component = new TextComponent("Your public IP is: " + ip); + component.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, ip)); + component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[]{new TextComponent("Click to copy")})); + sender.spigot().sendMessage(component); + } else { + sender.sendMessage("Your public IP is: " + ip); + } + sender.sendMessage(""); + }); + thread.start(); + + return ReturnType.SUCCESS; + } + + @Override + protected List onTab(CommandSender sender, String... args) { + return null; + } + + @Override + public String getPermissionNode() { + return "songoda.admin"; + } + + @Override + public String getSyntax() { + return "/songoda myip"; + } + + @Override + public String getDescription() { + return "Displays your public IP address."; + } +} diff --git a/Core/src/main/java/com/songoda/core/core/SongodaCoreUUIDCommand.java b/Core/src/main/java/com/songoda/core/core/SongodaCoreUUIDCommand.java new file mode 100644 index 00000000..0bcb10c6 --- /dev/null +++ b/Core/src/main/java/com/songoda/core/core/SongodaCoreUUIDCommand.java @@ -0,0 +1,55 @@ +package com.songoda.core.core; + +import com.songoda.core.commands.AbstractCommand; +import com.songoda.core.utils.SongodaAuth; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.UUID; + +public class SongodaCoreUUIDCommand extends AbstractCommand { + + public SongodaCoreUUIDCommand() { + super(CommandType.CONSOLE_OK, "uuid"); + } + + @Override + protected ReturnType runCommand(CommandSender sender, String... args) { + sender.sendMessage(""); + if (sender instanceof Player) { + TextComponent component = new TextComponent("Your server UUID is: " + SongodaAuth.getUUID()); + component.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, SongodaAuth.getUUID().toString())); + component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[]{new TextComponent("Click to copy")})); + sender.spigot().sendMessage(component); + } else { + sender.sendMessage("Your server UUID is: " + SongodaAuth.getUUID()); + } + sender.sendMessage(""); + return ReturnType.SUCCESS; + } + + @Override + protected List onTab(CommandSender sender, String... args) { + return null; + } + + @Override + public String getPermissionNode() { + return "songodacore.admin"; + } + + @Override + public String getSyntax() { + return "/songodacore uuid"; + } + + @Override + public String getDescription() { + return "Returns your server's uuid"; + } +} diff --git a/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java b/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java new file mode 100644 index 00000000..48f7280e --- /dev/null +++ b/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java @@ -0,0 +1,109 @@ +package com.songoda.core.utils; + +import com.songoda.core.commands.AbstractCommand; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.impl.client.HttpClients; +import org.bukkit.Bukkit; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.math.BigInteger; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.security.MessageDigest; +import java.util.Properties; +import java.util.UUID; + +public class SongodaAuth { + + public static boolean isAuthorized(boolean allowOffline) { + UUID uuid = getUUID(); + try { + URL url = new URL("https://marketplace.songoda.com/api/v2/products/license/validate"); + HttpURLConnection con = (HttpURLConnection)url.openConnection(); + con.setRequestMethod("POST"); + con.setRequestProperty("Content-Type", "application/json"); + con.setRequestProperty("Accept", "application/json"); + con.setDoOutput(true); + String jsonInputString = "{\"product_id\":" + "%%__PLUGIN__%%" + ",\"license\":\"" + uuid + "\",\"user_id\":\"%%__USER__%%\"}"; + try(OutputStream os = con.getOutputStream()) { + byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); + os.write(input, 0, input.length); + } + + try(BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { + StringBuilder response = new StringBuilder(); + String responseLine = null; + while ((responseLine = br.readLine()) != null) { + response.append(responseLine.trim()); + } + JSONObject jsonObject = (JSONObject) new JSONParser().parse(response.toString()); + if (jsonObject.get("error") != null) { + //Got an error, return false and print error + Bukkit.getLogger().warning("Error validating license: " + jsonObject.get("error")); + return false; + } else { + return (boolean) jsonObject.get("valid"); + } + } + } catch (Exception e) { + return allowOffline; + } + } + + public static UUID getUUID() { + File serverProperties = new File(Bukkit.getWorldContainer(),"server.properties"); + Properties prop = new Properties(); + try { + prop.load(new FileReader(serverProperties)); + String uuid = prop.getProperty("uuid"); + if (uuid == null || uuid.isEmpty()) { + UUID newUUID = UUID.randomUUID(); + prop.setProperty("uuid", newUUID.toString()); + prop.store(new FileWriter(serverProperties), null); + return newUUID; + } else { + return UUID.fromString(uuid); + } + } catch (Exception ex) { + throw new RuntimeException("Could not fetch UUID from server.properties", ex); + } + } + + public static String getIP() { + try { + URL url = new URL("https://marketplace.songoda.com/api/v2/products/license/ip"); + HttpURLConnection con = (HttpURLConnection)url.openConnection(); + con.setRequestMethod("GET"); + con.setRequestProperty("Accept", "application/json"); + con.setDoOutput(true); + try(BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { + StringBuilder response = new StringBuilder(); + String responseLine = null; + while ((responseLine = br.readLine()) != null) { + response.append(responseLine.trim()); + } + JSONParser parser = new JSONParser(); + JSONObject jsonObject = (JSONObject) parser.parse(response.toString()); + return jsonObject.get("ip").toString(); + } + } catch (Exception ex) { + throw new RuntimeException("Could not fetch IP address", ex); + } + } +} From c29c4a5b0933a7adba189e455228a64fe83165f3 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Wed, 11 Jan 2023 21:50:20 +0100 Subject: [PATCH 14/22] Release v2.6.18-DEV --- 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 4447adce..cbb26261 100644 --- a/Compatibility/pom.xml +++ b/Compatibility/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17 + 2.6.18-DEV ../pom.xml diff --git a/Core/pom.xml b/Core/pom.xml index f909dd13..2fc3f046 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17 + 2.6.18-DEV ../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 41464bb5..0c3892ef 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCore.java +++ b/Core/src/main/java/com/songoda/core/SongodaCore.java @@ -55,7 +55,7 @@ public class SongodaCore { /** * @since coreRevision 6 */ - private final static String coreVersion = "2.6.17"; + private final static String coreVersion = "2.6.18-DEV"; /** * This is specific to the website api diff --git a/NMS/NMS-API/pom.xml b/NMS/NMS-API/pom.xml index 8c07f06f..e49dce48 100644 --- a/NMS/NMS-API/pom.xml +++ b/NMS/NMS-API/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.17 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_10_R1/pom.xml b/NMS/NMS-v1_10_R1/pom.xml index ede38c0e..7f8a647b 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_11_R1/pom.xml b/NMS/NMS-v1_11_R1/pom.xml index 128ae780..57d75726 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_12_R1/pom.xml b/NMS/NMS-v1_12_R1/pom.xml index 699710e1..3e98d060 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_13_R1/pom.xml b/NMS/NMS-v1_13_R1/pom.xml index c409b5ad..df641546 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_13_R2/pom.xml b/NMS/NMS-v1_13_R2/pom.xml index fdc9d617..f5bd0ef4 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_14_R1/pom.xml b/NMS/NMS-v1_14_R1/pom.xml index 042c5d36..48cd1728 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_15_R1/pom.xml b/NMS/NMS-v1_15_R1/pom.xml index b05e785e..054797f4 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_16_R1/pom.xml b/NMS/NMS-v1_16_R1/pom.xml index 27ea1136..ef4c9f32 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_16_R2/pom.xml b/NMS/NMS-v1_16_R2/pom.xml index 37c5c42b..06ad15f3 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_16_R3/pom.xml b/NMS/NMS-v1_16_R3/pom.xml index 1e348f75..e70b3efe 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_17_R1/pom.xml b/NMS/NMS-v1_17_R1/pom.xml index 20cc46d7..dbf3488f 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_18_R1/pom.xml b/NMS/NMS-v1_18_R1/pom.xml index 64be7009..2f09c37a 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_18_R2/pom.xml b/NMS/NMS-v1_18_R2/pom.xml index c9795004..547bc227 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_19_R1/pom.xml b/NMS/NMS-v1_19_R1/pom.xml index b4178b84..2c98eeb2 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_19_R1v2/pom.xml b/NMS/NMS-v1_19_R1v2/pom.xml index 47de9855..616d5989 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_19_R2/pom.xml b/NMS/NMS-v1_19_R2/pom.xml index 09a72a6a..2bd44ff9 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_8_R1/pom.xml b/NMS/NMS-v1_8_R1/pom.xml index 1826f481..208aa079 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_8_R2/pom.xml b/NMS/NMS-v1_8_R2/pom.xml index f57ef13f..1de47781 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_8_R3/pom.xml b/NMS/NMS-v1_8_R3/pom.xml index cd8c3980..37ecf894 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_9_R1/pom.xml b/NMS/NMS-v1_9_R1/pom.xml index 9a101be7..a8d33474 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 + 2.6.18-DEV ../../pom.xml diff --git a/NMS/NMS-v1_9_R2/pom.xml b/NMS/NMS-v1_9_R2/pom.xml index c9b86983..0026c7ed 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 + 2.6.18-DEV ../../pom.xml diff --git a/pom.xml b/pom.xml index c2e7b6e9..b898364a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.songoda SongodaCore-Modules - 2.6.17 + 2.6.18-DEV pom From 7c02457108d724899ff0653308f7b0238d79e9bc Mon Sep 17 00:00:00 2001 From: ceze88 Date: Sun, 15 Jan 2023 12:23:56 +0100 Subject: [PATCH 15/22] Ignore self compiled plugins --- .../main/java/com/songoda/core/SongodaPlugin.java | 1 + .../java/com/songoda/core/utils/SongodaAuth.java | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/SongodaPlugin.java b/Core/src/main/java/com/songoda/core/SongodaPlugin.java index 22541d15..2dbf598f 100644 --- a/Core/src/main/java/com/songoda/core/SongodaPlugin.java +++ b/Core/src/main/java/com/songoda/core/SongodaPlugin.java @@ -106,6 +106,7 @@ public abstract class SongodaPlugin extends JavaPlugin { console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); }); thread.start(); + emergencyStop(); return; } diff --git a/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java b/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java index 48f7280e..e486d097 100644 --- a/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java +++ b/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java @@ -32,6 +32,13 @@ import java.util.UUID; public class SongodaAuth { public static boolean isAuthorized(boolean allowOffline) { + String productId = "%%__PLUGIN__%%"; + try { + Integer.parseInt(productId); + } catch (NumberFormatException e) { + //Self compiled, return true + return true; + } UUID uuid = getUUID(); try { URL url = new URL("https://marketplace.songoda.com/api/v2/products/license/validate"); @@ -40,7 +47,7 @@ public class SongodaAuth { con.setRequestProperty("Content-Type", "application/json"); con.setRequestProperty("Accept", "application/json"); con.setDoOutput(true); - String jsonInputString = "{\"product_id\":" + "%%__PLUGIN__%%" + ",\"license\":\"" + uuid + "\",\"user_id\":\"%%__USER__%%\"}"; + String jsonInputString = "{\"product_id\":" + productId + ",\"license\":\"" + uuid + "\",\"user_id\":\"%%__USER__%%\"}"; try(OutputStream os = con.getOutputStream()) { byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); @@ -67,7 +74,7 @@ public class SongodaAuth { } public static UUID getUUID() { - File serverProperties = new File(Bukkit.getWorldContainer(),"server.properties"); + File serverProperties = new File(new File("."),"server.properties"); Properties prop = new Properties(); try { prop.load(new FileReader(serverProperties)); @@ -81,7 +88,7 @@ public class SongodaAuth { return UUID.fromString(uuid); } } catch (Exception ex) { - throw new RuntimeException("Could not fetch UUID from server.properties", ex); + throw new RuntimeException("Could not fetch UUID for server", ex); } } From 386ff209a7cfc74d2aeb40863c2f41f835387abe Mon Sep 17 00:00:00 2001 From: ceze88 Date: Wed, 25 Jan 2023 16:02:44 +0100 Subject: [PATCH 16/22] Release v2.6.18 --- 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 cbb26261..9dbba0e2 100644 --- a/Compatibility/pom.xml +++ b/Compatibility/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.18-DEV + 2.6.18 ../pom.xml diff --git a/Core/pom.xml b/Core/pom.xml index 2fc3f046..857c5316 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.18-DEV + 2.6.18 ../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 0c3892ef..5d76a5f9 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCore.java +++ b/Core/src/main/java/com/songoda/core/SongodaCore.java @@ -55,7 +55,7 @@ public class SongodaCore { /** * @since coreRevision 6 */ - private final static String coreVersion = "2.6.18-DEV"; + private final static String coreVersion = "2.6.18"; /** * This is specific to the website api diff --git a/NMS/NMS-API/pom.xml b/NMS/NMS-API/pom.xml index e49dce48..9f837d2a 100644 --- a/NMS/NMS-API/pom.xml +++ b/NMS/NMS-API/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.6.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_10_R1/pom.xml b/NMS/NMS-v1_10_R1/pom.xml index 7f8a647b..236fb363 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_11_R1/pom.xml b/NMS/NMS-v1_11_R1/pom.xml index 57d75726..f59cc539 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_12_R1/pom.xml b/NMS/NMS-v1_12_R1/pom.xml index 3e98d060..fcc3fa2c 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_13_R1/pom.xml b/NMS/NMS-v1_13_R1/pom.xml index df641546..c933b9e4 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_13_R2/pom.xml b/NMS/NMS-v1_13_R2/pom.xml index f5bd0ef4..52d6a1f0 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_14_R1/pom.xml b/NMS/NMS-v1_14_R1/pom.xml index 48cd1728..2263f18a 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_15_R1/pom.xml b/NMS/NMS-v1_15_R1/pom.xml index 054797f4..5a7e4774 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_16_R1/pom.xml b/NMS/NMS-v1_16_R1/pom.xml index ef4c9f32..a94664ea 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_16_R2/pom.xml b/NMS/NMS-v1_16_R2/pom.xml index 06ad15f3..99b7080b 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_16_R3/pom.xml b/NMS/NMS-v1_16_R3/pom.xml index e70b3efe..3108af55 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_17_R1/pom.xml b/NMS/NMS-v1_17_R1/pom.xml index dbf3488f..74182a43 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_18_R1/pom.xml b/NMS/NMS-v1_18_R1/pom.xml index 2f09c37a..c2523f17 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_18_R2/pom.xml b/NMS/NMS-v1_18_R2/pom.xml index 547bc227..521397c0 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_19_R1/pom.xml b/NMS/NMS-v1_19_R1/pom.xml index 2c98eeb2..f67d44b6 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_19_R1v2/pom.xml b/NMS/NMS-v1_19_R1v2/pom.xml index 616d5989..f86f796c 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_19_R2/pom.xml b/NMS/NMS-v1_19_R2/pom.xml index 2bd44ff9..5f72ec24 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_8_R1/pom.xml b/NMS/NMS-v1_8_R1/pom.xml index 208aa079..923e9bde 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_8_R2/pom.xml b/NMS/NMS-v1_8_R2/pom.xml index 1de47781..4e4778c0 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_8_R3/pom.xml b/NMS/NMS-v1_8_R3/pom.xml index 37ecf894..e3783b2d 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_9_R1/pom.xml b/NMS/NMS-v1_9_R1/pom.xml index a8d33474..b79c0b28 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/NMS/NMS-v1_9_R2/pom.xml b/NMS/NMS-v1_9_R2/pom.xml index 0026c7ed..eb1e3117 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.18-DEV + 2.6.18 ../../pom.xml diff --git a/pom.xml b/pom.xml index b898364a..5a4f40a9 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.songoda SongodaCore-Modules - 2.6.18-DEV + 2.6.18 pom From ca13e8b26ec10b5b528ee50bb4677cc7d5a91413 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Sat, 4 Mar 2023 12:36:20 +0100 Subject: [PATCH 17/22] Prints 'missing-license' message in the console as one long message This prevents fragmentation of the idividual lines. `#getIP()` can take a couple of seconds and because it is executed outside of the main-thread, other message can be printed bevore the IP address and UUID are ready to be printed. --- .../java/com/songoda/core/SongodaPlugin.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/SongodaPlugin.java b/Core/src/main/java/com/songoda/core/SongodaPlugin.java index 2dbf598f..92bae005 100644 --- a/Core/src/main/java/com/songoda/core/SongodaPlugin.java +++ b/Core/src/main/java/com/songoda/core/SongodaPlugin.java @@ -85,27 +85,28 @@ public abstract class SongodaPlugin extends JavaPlugin { @Override public final void onEnable() { - if (emergencyStop) { + if (this.emergencyStop) { setEnabled(false); return; } - //Check plugin access, don't load plugin if user don't have access + // Check plugin access, don't load plugin if user don't have access if (!SongodaAuth.isAuthorized(true)) { - Thread thread = new Thread(() -> { - console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); - console.sendMessage(ChatColor.RED + "You do not have access to this plugin."); - console.sendMessage(ChatColor.YELLOW + "Please purchase a license at https://sngda.to/marketplace"); - console.sendMessage(ChatColor.YELLOW + "or set up your license at https://sngda.to/licenses"); - console.sendMessage(ChatColor.YELLOW + "License setup steps:"); - console.sendMessage(ChatColor.YELLOW + "Visit the link mentioned above and click the 'Create License button'"); - console.sendMessage(ChatColor.YELLOW + "Copy the following ip and uuid and click create."); - console.sendMessage(ChatColor.YELLOW + "IP: " + SongodaAuth.getIP()); - console.sendMessage(ChatColor.YELLOW + "UUID: " + SongodaAuth.getUUID()); - console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); - }); - thread.start(); + new Thread(() -> { + String message = ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + ChatColor.RED + "You do not have access to this plugin.\n" + + ChatColor.YELLOW + "Please purchase a license at https://sngda.to/marketplace\n" + + ChatColor.YELLOW + "or set up your license at https://sngda.to/licenses\n" + + ChatColor.YELLOW + "License setup steps:\n" + + ChatColor.YELLOW + "Visit the link mentioned above and click the 'Create License button'\n" + + ChatColor.YELLOW + "Copy the following ip and uuid and click create.\n" + + ChatColor.YELLOW + "IP: " + SongodaAuth.getIP() + "\n" + + ChatColor.YELLOW + "UUID: " + SongodaAuth.getUUID() + "\n" + + ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; + this.console.sendMessage(message); + }).start(); + emergencyStop(); return; } From d9586cfe86875d99c9aa1329c22c012aa6ffed09 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Sat, 4 Mar 2023 12:38:33 +0100 Subject: [PATCH 18/22] Slightly changes wording of 'missing-license' message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + small refactoring – Putting the *expesive* method calls outside the string into variables to easier see them, when trying to understand the code and the need for its own thread for just printing some messages to the console. --- .../java/com/songoda/core/SongodaPlugin.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/SongodaPlugin.java b/Core/src/main/java/com/songoda/core/SongodaPlugin.java index 92bae005..bd542f34 100644 --- a/Core/src/main/java/com/songoda/core/SongodaPlugin.java +++ b/Core/src/main/java/com/songoda/core/SongodaPlugin.java @@ -93,16 +93,22 @@ public abstract class SongodaPlugin extends JavaPlugin { // Check plugin access, don't load plugin if user don't have access if (!SongodaAuth.isAuthorized(true)) { + String pluginName = getDescription().getName(); + new Thread(() -> { - String message = ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + - ChatColor.RED + "You do not have access to this plugin.\n" + + String externalIP = SongodaAuth.getIP(); + String serverUuid = SongodaAuth.getUUID().toString(); + + String message = "\n" + + ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + ChatColor.RED + "You do not have access to the " + pluginName + " plugin.\n" + ChatColor.YELLOW + "Please purchase a license at https://sngda.to/marketplace\n" + ChatColor.YELLOW + "or set up your license at https://sngda.to/licenses\n" + ChatColor.YELLOW + "License setup steps:\n" + - ChatColor.YELLOW + "Visit the link mentioned above and click the 'Create License button'\n" + - ChatColor.YELLOW + "Copy the following ip and uuid and click create.\n" + - ChatColor.YELLOW + "IP: " + SongodaAuth.getIP() + "\n" + - ChatColor.YELLOW + "UUID: " + SongodaAuth.getUUID() + "\n" + + ChatColor.YELLOW + "Visit the link mentioned above and click the 'Create License' button.\n" + + ChatColor.YELLOW + "Copy the following IP address and UUID and click create.\n" + + ChatColor.YELLOW + "IP: " + externalIP + "\n" + + ChatColor.YELLOW + "UUID: " + serverUuid + "\n" + ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; this.console.sendMessage(message); }).start(); From 6145021ecbe87bb64150585b57806ac987dd34e0 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Sat, 4 Mar 2023 12:47:53 +0100 Subject: [PATCH 19/22] Remove unused imports in SongodaAuth and apply code formatting --- .../com/songoda/core/utils/SongodaAuth.java | 39 +++++++------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java b/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java index e486d097..a913aa38 100644 --- a/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java +++ b/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java @@ -1,64 +1,52 @@ package com.songoda.core.utils; -import com.songoda.core.commands.AbstractCommand; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.impl.client.HttpClients; import org.bukkit.Bukkit; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import java.io.BufferedReader; -import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; -import java.math.BigInteger; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.security.MessageDigest; import java.util.Properties; import java.util.UUID; public class SongodaAuth { - public static boolean isAuthorized(boolean allowOffline) { String productId = "%%__PLUGIN__%%"; try { Integer.parseInt(productId); } catch (NumberFormatException e) { - //Self compiled, return true + // Self compiled return true; } + UUID uuid = getUUID(); try { URL url = new URL("https://marketplace.songoda.com/api/v2/products/license/validate"); - HttpURLConnection con = (HttpURLConnection)url.openConnection(); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/json"); con.setRequestProperty("Accept", "application/json"); con.setDoOutput(true); String jsonInputString = "{\"product_id\":" + productId + ",\"license\":\"" + uuid + "\",\"user_id\":\"%%__USER__%%\"}"; - try(OutputStream os = con.getOutputStream()) { + try (OutputStream os = con.getOutputStream()) { byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); } - try(BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { + try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { StringBuilder response = new StringBuilder(); - String responseLine = null; + String responseLine; while ((responseLine = br.readLine()) != null) { response.append(responseLine.trim()); } + JSONObject jsonObject = (JSONObject) new JSONParser().parse(response.toString()); if (jsonObject.get("error") != null) { //Got an error, return false and print error @@ -74,7 +62,7 @@ public class SongodaAuth { } public static UUID getUUID() { - File serverProperties = new File(new File("."),"server.properties"); + File serverProperties = new File(new File("."), "server.properties"); Properties prop = new Properties(); try { prop.load(new FileReader(serverProperties)); @@ -95,18 +83,19 @@ public class SongodaAuth { public static String getIP() { try { URL url = new URL("https://marketplace.songoda.com/api/v2/products/license/ip"); - HttpURLConnection con = (HttpURLConnection)url.openConnection(); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("Accept", "application/json"); con.setDoOutput(true); - try(BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { + + try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { StringBuilder response = new StringBuilder(); - String responseLine = null; + String responseLine; while ((responseLine = br.readLine()) != null) { response.append(responseLine.trim()); } - JSONParser parser = new JSONParser(); - JSONObject jsonObject = (JSONObject) parser.parse(response.toString()); + + JSONObject jsonObject = (JSONObject) new JSONParser().parse(response.toString()); return jsonObject.get("ip").toString(); } } catch (Exception ex) { From 5199043a4baa6a461664fb41d83cd560a3a860ba Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Sat, 4 Mar 2023 13:08:16 +0100 Subject: [PATCH 20/22] Minor code refractoring on SongodaAuth Just trying to make it a bit more readable and easier to understand at a glance. --- .../com/songoda/core/utils/SongodaAuth.java | 94 ++++++++++--------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java b/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java index a913aa38..adfed7a0 100644 --- a/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java +++ b/Core/src/main/java/com/songoda/core/utils/SongodaAuth.java @@ -3,11 +3,13 @@ package com.songoda.core.utils; import org.bukkit.Bukkit; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; +import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; @@ -19,14 +21,11 @@ import java.util.UUID; public class SongodaAuth { public static boolean isAuthorized(boolean allowOffline) { String productId = "%%__PLUGIN__%%"; - try { - Integer.parseInt(productId); - } catch (NumberFormatException e) { - // Self compiled + if (isPluginSelfCompiled(productId)) { return true; } - UUID uuid = getUUID(); + UUID serverUuid = getUUID(); try { URL url = new URL("https://marketplace.songoda.com/api/v2/products/license/validate"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); @@ -34,49 +33,42 @@ public class SongodaAuth { con.setRequestProperty("Content-Type", "application/json"); con.setRequestProperty("Accept", "application/json"); con.setDoOutput(true); - String jsonInputString = "{\"product_id\":" + productId + ",\"license\":\"" + uuid + "\",\"user_id\":\"%%__USER__%%\"}"; + + String requestBodyJson = "{\"product_id\":" + productId + ",\"license\":\"" + serverUuid + "\",\"user_id\":\"%%__USER__%%\"}"; try (OutputStream os = con.getOutputStream()) { - byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); - os.write(input, 0, input.length); + byte[] requestBody = requestBodyJson.getBytes(StandardCharsets.UTF_8); + os.write(requestBody, 0, requestBody.length); } - try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { - StringBuilder response = new StringBuilder(); - String responseLine; - while ((responseLine = br.readLine()) != null) { - response.append(responseLine.trim()); - } - - JSONObject jsonObject = (JSONObject) new JSONParser().parse(response.toString()); - if (jsonObject.get("error") != null) { - //Got an error, return false and print error - Bukkit.getLogger().warning("Error validating license: " + jsonObject.get("error")); - return false; - } else { - return (boolean) jsonObject.get("valid"); - } + JSONObject jsonResponse = readHttpResponseJson(con); + if (jsonResponse.containsKey("error")) { + Bukkit.getLogger().warning("Error validating license: " + jsonResponse.get("error")); + return false; } - } catch (Exception e) { + + return (boolean) jsonResponse.get("valid"); + } catch (Exception ex) { return allowOffline; } } public static UUID getUUID() { - File serverProperties = new File(new File("."), "server.properties"); - Properties prop = new Properties(); + File serverProperties = new File("./server.properties"); try { + Properties prop = new Properties(); prop.load(new FileReader(serverProperties)); + String uuid = prop.getProperty("uuid"); - if (uuid == null || uuid.isEmpty()) { - UUID newUUID = UUID.randomUUID(); - prop.setProperty("uuid", newUUID.toString()); - prop.store(new FileWriter(serverProperties), null); - return newUUID; - } else { + if (uuid != null && !uuid.isEmpty()) { return UUID.fromString(uuid); } + + UUID newUUID = UUID.randomUUID(); + prop.setProperty("uuid", newUUID.toString()); + prop.store(new FileWriter(serverProperties), null); + return newUUID; } catch (Exception ex) { - throw new RuntimeException("Could not fetch UUID for server", ex); + throw new RuntimeException("Could not determine UUID for server", ex); } } @@ -86,20 +78,34 @@ public class SongodaAuth { HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("Accept", "application/json"); - con.setDoOutput(true); - try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { - StringBuilder response = new StringBuilder(); - String responseLine; - while ((responseLine = br.readLine()) != null) { - response.append(responseLine.trim()); - } - - JSONObject jsonObject = (JSONObject) new JSONParser().parse(response.toString()); - return jsonObject.get("ip").toString(); - } + JSONObject jsonResponse = readHttpResponseJson(con); + return jsonResponse.get("ip").toString(); } catch (Exception ex) { throw new RuntimeException("Could not fetch IP address", ex); } } + + private static JSONObject readHttpResponseJson(HttpURLConnection con) throws IOException, ParseException { + try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { + StringBuilder response = new StringBuilder(); + + String responseLine; + while ((responseLine = br.readLine()) != null) { + response.append(responseLine.trim()); + } + + return (JSONObject) new JSONParser().parse(response.toString()); + } + } + + private static boolean isPluginSelfCompiled(String productId) { + try { + Integer.parseInt(productId); + return false; + } catch (NumberFormatException ignore) { + } + + return true; + } } From a79677d261542c4cecbd856743f37a12f9a8b1e2 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Thu, 9 Mar 2023 15:53:21 +0100 Subject: [PATCH 21/22] Updates Lands-ProtectionHook to use v6 of the API The API changed and we are 2 major versions behind This drops support for outdated version of *Lands* and re-adds support for the latest version. --- Core/pom.xml | 4 ++-- .../hooks/protection/LandsProtection.java | 22 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Core/pom.xml b/Core/pom.xml index 857c5316..94b4ea12 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -376,9 +376,9 @@ - me.angeschossen + com.github.Angeschossen LandsAPI - 4.12.20 + 6.28.11 provided diff --git a/Core/src/main/java/com/songoda/core/hooks/protection/LandsProtection.java b/Core/src/main/java/com/songoda/core/hooks/protection/LandsProtection.java index cf73e7a6..0112e587 100644 --- a/Core/src/main/java/com/songoda/core/hooks/protection/LandsProtection.java +++ b/Core/src/main/java/com/songoda/core/hooks/protection/LandsProtection.java @@ -1,8 +1,9 @@ package com.songoda.core.hooks.protection; -import me.angeschossen.lands.api.integration.LandsIntegration; +import me.angeschossen.lands.api.LandsIntegration; +import me.angeschossen.lands.api.flags.type.Flags; +import me.angeschossen.lands.api.flags.type.RoleFlag; import me.angeschossen.lands.api.land.Area; -import me.angeschossen.lands.api.role.enums.RoleSetting; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -13,32 +14,31 @@ public class LandsProtection extends Protection { public LandsProtection(Plugin plugin) { super(plugin); - this.landsIntegration = new LandsIntegration(plugin); + this.landsIntegration = LandsIntegration.of(plugin); } @Override public boolean canPlace(Player player, Location location) { - return hasPerms(player, location, RoleSetting.BLOCK_PLACE); + return hasPerms(player, location, Flags.BLOCK_PLACE); } @Override public boolean canBreak(Player player, Location location) { - return hasPerms(player, location, RoleSetting.BLOCK_BREAK); + return hasPerms(player, location, Flags.BLOCK_BREAK); } @Override public boolean canInteract(Player player, Location location) { - return hasPerms(player, location, RoleSetting.INTERACT_CONTAINER); + return hasPerms(player, location, Flags.INTERACT_CONTAINER); } - private boolean hasPerms(Player player, Location location, RoleSetting roleSetting) { - Area area = landsIntegration.getAreaByLoc(location); - + private boolean hasPerms(Player player, Location location, RoleFlag roleFlag) { + Area area = this.landsIntegration.getArea(location); if (area == null) { return true; } - return area.canSetting(player, roleSetting, false); + return area.getRole(player.getUniqueId()).hasFlag(roleFlag); } @Override @@ -48,6 +48,6 @@ public class LandsProtection extends Protection { @Override public boolean isEnabled() { - return landsIntegration != null; + return this.landsIntegration != null; } } From 52f6c42266b12a876830cd581b6d2e4d2f436ba7 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Thu, 16 Mar 2023 09:44:22 +0100 Subject: [PATCH 22/22] Adds NMS Module v1_19_R3 for Spigot 1.19.4 compatibility --- .github/workflows/maven.yml | 2 +- .github/workflows/sonarcloud.yml | 2 +- Core/pom.xml | 6 + NMS/NMS-v1_19_R3/pom.xml | 105 +++++++++ .../core/nms/v1_19_R3/anvil/AnvilCore.java | 21 ++ .../v1_19_R3/anvil/AnvilInventoryCustom.java | 22 ++ .../core/nms/v1_19_R3/anvil/AnvilView.java | 216 ++++++++++++++++++ .../nms/v1_19_R3/entity/NMSPlayerImpl.java | 13 ++ .../nms/v1_19_R3/nbt/NBTCompoundImpl.java | 208 +++++++++++++++++ .../core/nms/v1_19_R3/nbt/NBTCoreImpl.java | 38 +++ .../core/nms/v1_19_R3/nbt/NBTEntityImpl.java | 67 ++++++ .../core/nms/v1_19_R3/nbt/NBTItemImpl.java | 24 ++ .../core/nms/v1_19_R3/nbt/NBTObjectImpl.java | 72 ++++++ .../nms/v1_19_R3/world/SItemStackImpl.java | 39 ++++ .../core/nms/v1_19_R3/world/SSpawnerImpl.java | 132 +++++++++++ .../core/nms/v1_19_R3/world/SWorldImpl.java | 38 +++ .../nms/v1_19_R3/world/WorldCoreImpl.java | 93 ++++++++ .../world/spawner/BBaseSpawnerImpl.java | 213 +++++++++++++++++ pom.xml | 1 + 19 files changed, 1310 insertions(+), 2 deletions(-) create mode 100644 NMS/NMS-v1_19_R3/pom.xml create mode 100644 NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/anvil/AnvilCore.java create mode 100644 NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/anvil/AnvilInventoryCustom.java create mode 100644 NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/anvil/AnvilView.java create mode 100644 NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/entity/NMSPlayerImpl.java create mode 100644 NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTCompoundImpl.java create mode 100644 NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTCoreImpl.java create mode 100644 NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTEntityImpl.java create mode 100644 NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTItemImpl.java create mode 100644 NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTObjectImpl.java create mode 100644 NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/SItemStackImpl.java create mode 100644 NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/SSpawnerImpl.java create mode 100644 NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/SWorldImpl.java create mode 100644 NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/WorldCoreImpl.java create mode 100644 NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/spawner/BBaseSpawnerImpl.java diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 01227363..5fbb013a 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, 1.18.2, 1.19, 1.19.2, 1.19.3 + versions: 1.18, 1.18.2, 1.19, 1.19.2, 1.19.3, 1.19.4 remapped: true # Build project diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index e8c2d392..cb6ede4e 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, 1.18.2, 1.19, 1.19.2, 1.19.3 + versions: 1.18, 1.18.2, 1.19, 1.19.2, 1.19.3, 1.19.4 remapped: true - name: Analyze project diff --git a/Core/pom.xml b/Core/pom.xml index 94b4ea12..187bafc5 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -267,6 +267,12 @@ ${project.version} compile + + ${project.groupId} + SongodaCore-NMS-v1_19_R3 + ${project.version} + compile + diff --git a/NMS/NMS-v1_19_R3/pom.xml b/NMS/NMS-v1_19_R3/pom.xml new file mode 100644 index 00000000..85a007c2 --- /dev/null +++ b/NMS/NMS-v1_19_R3/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.18 + ../../pom.xml + + + + 17 + 17 + + 1.19.4-R0.1-SNAPSHOT + + + SongodaCore-NMS-v1_19_R3 + 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_R3/src/main/java/com/songoda/core/nms/v1_19_R3/anvil/AnvilCore.java b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/anvil/AnvilCore.java new file mode 100644 index 00000000..ceb3674f --- /dev/null +++ b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/anvil/AnvilCore.java @@ -0,0 +1,21 @@ +package com.songoda.core.nms.v1_19_R3.anvil; + +import com.songoda.core.nms.anvil.CustomAnvil; +import net.minecraft.server.level.ServerPlayer; +import org.bukkit.craftbukkit.v1_19_R3.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_R3/src/main/java/com/songoda/core/nms/v1_19_R3/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/anvil/AnvilInventoryCustom.java new file mode 100644 index 00000000..a24d9583 --- /dev/null +++ b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/anvil/AnvilInventoryCustom.java @@ -0,0 +1,22 @@ +package com.songoda.core.nms.v1_19_R3.anvil; + +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AnvilMenu; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_19_R3.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_R3/src/main/java/com/songoda/core/nms/v1_19_R3/anvil/AnvilView.java b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/anvil/AnvilView.java new file mode 100644 index 00000000..ad944620 --- /dev/null +++ b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/anvil/AnvilView.java @@ -0,0 +1,216 @@ +package com.songoda.core.nms.v1_19_R3.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_R3.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(this.customTitle != null ? this.customTitle : "", this.customTitle != null ? this.customTitle : "", new Object[0]))); + 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(this.customTitle != null ? this.customTitle : "", this.customTitle != null ? this.customTitle : "", new Object[0]))); + } 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(this.customTitle != null ? this.customTitle : "", this.customTitle != null ? this.customTitle : "", new Object[0])))); + + // 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_R3/src/main/java/com/songoda/core/nms/v1_19_R3/entity/NMSPlayerImpl.java b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/entity/NMSPlayerImpl.java new file mode 100644 index 00000000..4f457b36 --- /dev/null +++ b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/entity/NMSPlayerImpl.java @@ -0,0 +1,13 @@ +package com.songoda.core.nms.v1_19_R3.entity; + +import com.songoda.core.nms.entity.NMSPlayer; +import net.minecraft.network.protocol.Packet; +import org.bukkit.craftbukkit.v1_19_R3.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_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTCompoundImpl.java new file mode 100644 index 00000000..f0c3b52e --- /dev/null +++ b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTCompoundImpl.java @@ -0,0 +1,208 @@ +package com.songoda.core.nms.v1_19_R3.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_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTCoreImpl.java b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTCoreImpl.java new file mode 100644 index 00000000..f18fe100 --- /dev/null +++ b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTCoreImpl.java @@ -0,0 +1,38 @@ +package com.songoda.core.nms.v1_19_R3.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_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_19_R3.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_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTEntityImpl.java b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTEntityImpl.java new file mode 100644 index 00000000..8b38113a --- /dev/null +++ b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTEntityImpl.java @@ -0,0 +1,67 @@ +package com.songoda.core.nms.v1_19_R3.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_R3.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(); + getKeys().remove("UUID"); + + 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_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTItemImpl.java b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTItemImpl.java new file mode 100644 index 00000000..bdffd1fd --- /dev/null +++ b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTItemImpl.java @@ -0,0 +1,24 @@ +package com.songoda.core.nms.v1_19_R3.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_R3.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_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTObjectImpl.java b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTObjectImpl.java new file mode 100644 index 00000000..1f3cb708 --- /dev/null +++ b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/nbt/NBTObjectImpl.java @@ -0,0 +1,72 @@ +package com.songoda.core.nms.v1_19_R3.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_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/SItemStackImpl.java b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/SItemStackImpl.java new file mode 100644 index 00000000..5aafa871 --- /dev/null +++ b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/SItemStackImpl.java @@ -0,0 +1,39 @@ +package com.songoda.core.nms.v1_19_R3.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_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R3.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_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/SSpawnerImpl.java b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/SSpawnerImpl.java new file mode 100644 index 00000000..7dd731fa --- /dev/null +++ b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/SSpawnerImpl.java @@ -0,0 +1,132 @@ +package com.songoda.core.nms.v1_19_R3.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_R3.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_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/SWorldImpl.java b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/SWorldImpl.java new file mode 100644 index 00000000..4b1a54f8 --- /dev/null +++ b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/SWorldImpl.java @@ -0,0 +1,38 @@ +package com.songoda.core.nms.v1_19_R3.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_R3.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_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/WorldCoreImpl.java b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/WorldCoreImpl.java new file mode 100644 index 00000000..f47905a9 --- /dev/null +++ b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/WorldCoreImpl.java @@ -0,0 +1,93 @@ +package com.songoda.core.nms.v1_19_R3.world; + +import com.songoda.core.nms.ReflectionUtils; +import com.songoda.core.nms.v1_19_R3.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_R3.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_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/spawner/BBaseSpawnerImpl.java new file mode 100644 index 00000000..570b2c4a --- /dev/null +++ b/NMS/NMS-v1_19_R3/src/main/java/com/songoda/core/nms/v1_19_R3/world/spawner/BBaseSpawnerImpl.java @@ -0,0 +1,213 @@ +package com.songoda.core.nms.v1_19_R3.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_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R3.block.CraftCreatureSpawner; +import org.bukkit.craftbukkit.v1_19_R3.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 worldserver = getWorld(); + BlockPos blockposition = getBlockPosition(); + + if (this.spawner.spawnDelay == -1) { + this.delay(worldserver, blockposition); + } + + if (this.spawner.spawnDelay > 0) { + --this.spawner.spawnDelay; + } else { + boolean flag = false; + RandomSource randomsource = worldserver.getRandom(); + SpawnData mobspawnerdata = (SpawnData) this.getOrCreateNextSpawnDataMethod.invoke(this.spawner, worldserver, randomsource, blockposition); + int i = 0; + + while (true) { + if (i >= this.spawner.spawnCount) { + if (flag) { + this.delay(worldserver, blockposition); + } + break; + } + + CompoundTag nbttagcompound = mobspawnerdata.getEntityToSpawn(); + Optional> optional = EntityType.by(nbttagcompound); + if (optional.isEmpty()) { + this.delay(worldserver, blockposition); + return; + } + + ListTag nbttaglist = nbttagcompound.getList("Pos", 6); + int j = nbttaglist.size(); + double d0 = j >= 1 ? nbttaglist.getDouble(0) : (double) blockposition.getX() + (randomsource.nextDouble() - randomsource.nextDouble()) * (double) this.spawner.spawnRange + 0.5; + double d1 = j >= 2 ? nbttaglist.getDouble(1) : (double) (blockposition.getY() + randomsource.nextInt(3) - 1); + double d2 = j >= 3 ? nbttaglist.getDouble(2) : (double) blockposition.getZ() + (randomsource.nextDouble() - randomsource.nextDouble()) * (double) this.spawner.spawnRange + 0.5; + if (worldserver.noCollision(optional.get().getAABB(d0, d1, d2))) { + label128: + { + BlockPos blockposition1 = BlockPos.containing(d0, d1, d2); + if (mobspawnerdata.getCustomSpawnRules().isPresent()) { + if (!optional.get().getCategory().isFriendly() && worldserver.getDifficulty() == Difficulty.PEACEFUL) { + break label128; + } + + SpawnData.CustomSpawnRules mobspawnerdata_a = mobspawnerdata.getCustomSpawnRules().get(); + if (!mobspawnerdata_a.blockLightLimit().isValueInRange(worldserver.getBrightness(LightLayer.BLOCK, blockposition1)) || !mobspawnerdata_a.skyLightLimit().isValueInRange(worldserver.getBrightness(LightLayer.SKY, blockposition1))) { + break label128; + } + } else if (!SpawnPlacements.checkSpawnRules((EntityType) optional.get(), worldserver, MobSpawnType.SPAWNER, blockposition1, worldserver.getRandom())) { + break label128; + } + + Entity entity = EntityType.loadEntityRecursive(nbttagcompound, worldserver, (entity1) -> { + entity1.moveTo(d0, d1, d2, entity1.getYRot(), entity1.getXRot()); + return entity1; + }); + if (entity == null) { + this.delay(worldserver, blockposition); + return; + } + + int k = worldserver.getEntitiesOfClass(entity.getClass(), (new AABB(blockposition.getX(), blockposition.getY(), blockposition.getZ(), blockposition.getX() + 1, blockposition.getY() + 1, blockposition.getZ() + 1)).inflate(this.spawner.spawnRange)).size(); + if (k >= this.spawner.maxNearbyEntities) { + this.delay(worldserver, blockposition); + 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(worldserver, MobSpawnType.SPAWNER) || !entityinsentient.checkSpawnObstruction(worldserver)) { + break label128; + } + + if (mobspawnerdata.getEntityToSpawn().size() == 1 && mobspawnerdata.getEntityToSpawn().contains("id", 8)) { + ((Mob) entity).finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.SPAWNER, null, null); + } + + if (entityinsentient.level.spigotConfig.nerfSpawnerMobs) { + entityinsentient.aware = false; + } + } + + if (CraftEventFactory.callSpawnerSpawnEvent(entity, blockposition).isCancelled()) { + Entity vehicle = entity.getVehicle(); + if (vehicle != null) { + vehicle.discard(); + } + + for (Entity passenger : entity.getIndirectPassengers()) { + passenger.discard(); + } + } else { + if (!worldserver.tryAddFreshEntityWithPassengers(entity, CreatureSpawnEvent.SpawnReason.SPAWNER)) { + this.delay(worldserver, blockposition); + return; + } + + worldserver.levelEvent(2004, blockposition, 0); + worldserver.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 5a4f40a9..3097a971 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,7 @@ NMS/NMS-v1_19_R1 NMS/NMS-v1_19_R1v2 NMS/NMS-v1_19_R2 + NMS/NMS-v1_19_R3