From a0c9fe47d0222f3b8c9bb921c64a508a3fabfb56 Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Sun, 22 Oct 2023 18:42:01 -0400 Subject: [PATCH 01/52] Bump version --- api/build.gradle | 2 +- api/src/main/java/parallelmc/parallelutils/Constants.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index 6da058fd..6765a558 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -7,7 +7,7 @@ plugins { group = 'org.parallelmc' -version = '4.2.0' +version = '4.2.1' description = 'A set of utilities and features for use on the Parallel Minecraft server' java { diff --git a/api/src/main/java/parallelmc/parallelutils/Constants.java b/api/src/main/java/parallelmc/parallelutils/Constants.java index a6bf0d7a..1678da44 100644 --- a/api/src/main/java/parallelmc/parallelutils/Constants.java +++ b/api/src/main/java/parallelmc/parallelutils/Constants.java @@ -2,7 +2,7 @@ public class Constants { - public static final Version VERSION = new Version(4, 2, 0); + public static final Version VERSION = new Version(4, 2, 1); public static final String PLUGIN_NAME = "ParallelUtils"; public static final String DEFAULT_WORLD = "world2"; } From 68fa3070a8a9dcbfa1665e18683638e312e0cdbd Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:59:18 -0500 Subject: [PATCH 02/52] Fix misc bugs in Parallel Resources and add permission to ignore requirement --- api/build.gradle | 15 ++++++++++++++- .../java/parallelmc/parallelutils/Constants.java | 2 +- .../parallelresources/ParallelResources.java | 2 +- .../modules/parallelresources/ResourceServer.java | 2 ++ .../events/ResourcePackHandle.java | 4 +++- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index dacc05ca..001ebb3c 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -7,7 +7,7 @@ plugins { group = 'org.parallelmc' -version = '4.2.0' +version = '4.2.2' description = 'A set of utilities and features for use on the Parallel Minecraft server' java { @@ -90,6 +90,11 @@ bukkit { usage = '/town' permissionMessage = 'You do not have permission' } + chestshop { + description = 'Base command for all ChestShop debug commands' + usage = '/chestshop' + permissionMessage = 'You do not have permission' + } depositexp { description = 'Deposit exp into the player\' s ender chest ' usage = '/depositexp ' @@ -462,5 +467,13 @@ bukkit { 'parallelutils.notify.antislur' { description = 'Be notified of swearing' } + 'parallelutils.chestshop.debug' { + description = 'Gives access to ChestShop debug commands' + setDefault('FALSE') + } + 'parallelutils.resources.unenforced' { + description = 'Prevents being kicked from not accepting the resource pack' + setDefault('FALSE') + } } } \ No newline at end of file diff --git a/api/src/main/java/parallelmc/parallelutils/Constants.java b/api/src/main/java/parallelmc/parallelutils/Constants.java index a6bf0d7a..9aea8786 100644 --- a/api/src/main/java/parallelmc/parallelutils/Constants.java +++ b/api/src/main/java/parallelmc/parallelutils/Constants.java @@ -2,7 +2,7 @@ public class Constants { - public static final Version VERSION = new Version(4, 2, 0); + public static final Version VERSION = new Version(4, 2, 2); public static final String PLUGIN_NAME = "ParallelUtils"; public static final String DEFAULT_WORLD = "world2"; } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java index 4d2277eb..dc045a0e 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java @@ -362,7 +362,7 @@ private List squashFiles(@NotNull List inFiles, @NotNull File resour out = new File(outDir, f.getName()); Files.copy(f.toPath(), out.toPath()); } - squashed.add(f); + squashed.add(out); } purgeDirectory(tempDir.toFile()); diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ResourceServer.java b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ResourceServer.java index dece4bf5..7401a207 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ResourceServer.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ResourceServer.java @@ -71,6 +71,8 @@ public void configure(HttpsParameters params) { } }); + server = httpsServer; + } else { server = HttpServer.create(new InetSocketAddress(port), 0); } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java index 36143659..1e780ee6 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java @@ -54,10 +54,12 @@ public void onResourcePackStatus(PlayerResourcePackStatusEvent event) { switch (status) { case DECLINED -> { + if (event.getPlayer().hasPermission("parallelutils.resources.unenforced")) return; ParallelUtils.log(Level.WARNING, "Event " + status.toString() + " occurred! Declining join"); event.getPlayer().kick(warningMessage); } case FAILED_DOWNLOAD -> { + if (event.getPlayer().hasPermission("parallelutils.resources.unenforced")) return; ParallelUtils.log(Level.WARNING, "Event " + status.toString() + " occurred! Declining join"); event.getPlayer().kick(warningMessage.append( Component.text("If you believe this was an error, please contact staff on Discord."))); @@ -80,7 +82,7 @@ public boolean applyPack(@NotNull Player player) { String resourceUrl = resources.getResourceUrl(worldName); - player.setResourcePack(resourceUrl, hash, warningMessage, true); + player.setResourcePack(resourceUrl, hash, warningMessage, !player.hasPermission("parallelutils.resources.unenforced")); return true; } From 0a235de2f9742d388b50ff1e9fb568b6d25278af Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:04:58 -0500 Subject: [PATCH 03/52] Oops --- api/build.gradle | 3 --- api/src/main/java/parallelmc/parallelutils/Constants.java | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index 6d293d65..001ebb3c 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -471,12 +471,9 @@ bukkit { description = 'Gives access to ChestShop debug commands' setDefault('FALSE') } -<<<<<<< HEAD 'parallelutils.resources.unenforced' { description = 'Prevents being kicked from not accepting the resource pack' setDefault('FALSE') } -======= ->>>>>>> main } } \ No newline at end of file diff --git a/api/src/main/java/parallelmc/parallelutils/Constants.java b/api/src/main/java/parallelmc/parallelutils/Constants.java index ff8c81e4..9aea8786 100644 --- a/api/src/main/java/parallelmc/parallelutils/Constants.java +++ b/api/src/main/java/parallelmc/parallelutils/Constants.java @@ -1,7 +1,7 @@ package parallelmc.parallelutils; public class Constants { - + public static final Version VERSION = new Version(4, 2, 2); public static final String PLUGIN_NAME = "ParallelUtils"; public static final String DEFAULT_WORLD = "world2"; From c2606c4f49356988d3099a4da5718f25b9983307 Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Sat, 25 Nov 2023 10:48:22 -0500 Subject: [PATCH 04/52] Add proxy support to ParallelResources --- .../modules/parallelresources/ParallelResources.java | 12 ++++++++++-- .../parallelresources/events/ResourcePackHandle.java | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java index dc045a0e..da0600ad 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java @@ -104,6 +104,7 @@ public void onLoad() { if (!resourcesFile.exists()) { resourcesConfig.set("domain", "resources.parallelmc.org"); resourcesConfig.set("port", 4444); + resourcesConfig.set("has_proxy", false); resourcesConfig.set("https", false); resourcesConfig.set("https_keystore", null); resourcesConfig.set("https_keystore_pass", null); @@ -117,6 +118,7 @@ public void onLoad() { // Initialize server int port = resourcesConfig.getInt("port", 4444); + boolean has_proxy = resourcesConfig.getBoolean("has_proxy", false); boolean https = resourcesConfig.getBoolean("https", false); String keystore = resourcesConfig.getString("https_keystore", null); String keystore_pass = resourcesConfig.getString("https_keystore_pass", null); @@ -125,9 +127,15 @@ public void onLoad() { server = new ResourceServer(port, https, keystore != null ? new File(resourcesDir, keystore) : null, keystore_pass); - String https_head = https ? "https://" : "http://"; + // Use HTTPS if there's a proxy + String https_head = (https|has_proxy) ? "https://" : "http://"; - base_url = https_head + domain + ":" + port + "/"; + // URL does not include port if there's a proxy + if (has_proxy) { + base_url = https_head + domain + "/"; + } else { + base_url = https_head + domain + ":" + port + "/"; + } // Try loading packsquash diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java index 1e780ee6..0c2e9fb3 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java @@ -74,14 +74,21 @@ public boolean applyPack(@NotNull Player player) { byte[] hash = resources.getHash(worldName); + ParallelUtils.log(Level.INFO, "Applying pack for world " + worldName); + if (hash == null) { ParallelUtils.log(Level.INFO, "Tried to get pack for invalid world. Defaulting to base"); worldName = "base"; hash = resources.getHash("base"); } + ParallelUtils.log(Level.INFO, "Found hash for world " + worldName); + + String resourceUrl = resources.getResourceUrl(worldName); + ParallelUtils.log(Level.INFO, "Got resource URL " + resourceUrl); + player.setResourcePack(resourceUrl, hash, warningMessage, !player.hasPermission("parallelutils.resources.unenforced")); return true; From e67751560158ac3152d16cb0a5c4651c7140e553 Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Sat, 25 Nov 2023 17:01:32 -0500 Subject: [PATCH 05/52] Prevent re-applying the pack when the previous world's pack is the same --- .../events/ResourcePackHandle.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java index 0c2e9fb3..918bf574 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java @@ -10,9 +10,11 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerResourcePackStatusEvent; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import parallelmc.parallelutils.ParallelUtils; import parallelmc.parallelutils.modules.parallelresources.ParallelResources; +import java.util.Arrays; import java.util.logging.Level; public class ResourcePackHandle implements Listener { @@ -34,7 +36,7 @@ public ResourcePackHandle(ParallelUtils puPlugin, ParallelResources resources, C public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - if (!applyPack(player)) { + if (!applyPack(player, null)) { ParallelUtils.log(Level.SEVERE, "UNABLE TO APPLY RESOURCE PACK!"); } } @@ -43,7 +45,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { public void onWorldChange(PlayerChangedWorldEvent event) { Player player = event.getPlayer(); - if (!applyPack(player)) { + if (!applyPack(player, event.getFrom())) { ParallelUtils.log(Level.SEVERE, "UNABLE TO APPLY RESOURCE PACK!"); } } @@ -67,7 +69,7 @@ public void onResourcePackStatus(PlayerResourcePackStatusEvent event) { } } - public boolean applyPack(@NotNull Player player) { + public boolean applyPack(@NotNull Player player, @Nullable World previousWorld) { World world = player.getWorld(); String worldName = world.getName(); @@ -85,6 +87,20 @@ public boolean applyPack(@NotNull Player player) { ParallelUtils.log(Level.INFO, "Found hash for world " + worldName); + if (previousWorld != null) { + String previousName = previousWorld.getName(); + byte[] previousHash = resources.getHash(previousName); + + if (previousHash == null) { + previousHash = resources.getHash("base"); + } + + // If the packs for each world are the same, just don't even apply the pack + if (Arrays.equals(previousHash, hash)) { + return true; + } + } + String resourceUrl = resources.getResourceUrl(worldName); ParallelUtils.log(Level.INFO, "Got resource URL " + resourceUrl); From 3429d6d8ac041afa2169172c8dd3dfe8d4291015 Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Sat, 25 Nov 2023 17:13:43 -0500 Subject: [PATCH 06/52] Add async packsquash support to partially alleviate lag --- .../parallelresources/ParallelResources.java | 61 +++++++++++++++---- .../events/ResourcePackHandle.java | 8 +++ 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java index da0600ad..02e0fdd5 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java @@ -8,6 +8,8 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import parallelmc.parallelutils.Constants; @@ -63,6 +65,8 @@ public class ParallelResources extends ParallelModule { @Nullable private File packSquashConfig = null; + private boolean doneLoading = false; + private final HashMap resourceHashes = new HashMap<>(); public ParallelResources(ParallelClassLoader classLoader, List dependents) { @@ -173,6 +177,7 @@ public void onLoad() { if (!base_zip.exists()) { ParallelUtils.log(Level.WARNING, "Base zip does not exist! Will not continue"); + doneLoading = true; return; } @@ -214,7 +219,35 @@ public void onLoad() { packsTemp.add(base_temp); // Squash all the files - packs = squashFiles(packsTemp, resourcesDir, squashOut); + + + ParallelResources resources = this; + BukkitTask squashTask = new BukkitRunnable() { + @Override + public void run() { + try { + List packs = squashFiles(packsTemp, resourcesDir, squashOut); + + for (File f : packs) { + String trimmed_name = f.getName().replace(".zip", ""); + server.addResource(trimmed_name, f); + resourceHashes.put(trimmed_name, createSha1(f)); + } + + handler = new ResourcePackHandle(puPlugin, resources, warning_component); + + } catch (Exception e) { + ParallelUtils.log(Level.SEVERE, "Exception while loading ParallelResources! Quitting..."); + doneLoading = true; + return; + } + + serverThread = new Thread(server); + serverThread.start(); + doneLoading = true; + } + }.runTaskAsynchronously(puPlugin); + } else { // Just put them right in the final output directory packs = generatePacks(squashOut, base_zip, resourceMods); @@ -223,28 +256,28 @@ public void onLoad() { File base_final = new File(modOut, base_zip.getName()); Files.copy(base_zip.toPath(), base_final.toPath()); packs.add(base_final); - } - for (File f : packs) { - String trimmed_name = f.getName().replace(".zip", ""); - server.addResource(trimmed_name, f); - resourceHashes.put(trimmed_name, createSha1(f)); - } + for (File f : packs) { + String trimmed_name = f.getName().replace(".zip", ""); + server.addResource(trimmed_name, f); + resourceHashes.put(trimmed_name, createSha1(f)); + } - handler = new ResourcePackHandle(puPlugin, this, warning_component); + handler = new ResourcePackHandle(puPlugin, this, warning_component); + + serverThread = new Thread(server); + serverThread.start(); + } } catch (IOException e) { e.printStackTrace(); ParallelUtils.log(Level.SEVERE, "IOException while loading ParallelResources! Quitting..."); - return; } catch (Exception e) { e.printStackTrace(); ParallelUtils.log(Level.SEVERE, "Exception while loading ParallelResources! Quitting..."); - return; } - serverThread = new Thread(server); - serverThread.start(); + doneLoading = true; } @Override @@ -574,4 +607,8 @@ public byte[] getHash(@NotNull String world) { return resourceHashes.get(world); } + public boolean doneLoading() { + return doneLoading; + } + } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java index 918bf574..36ef99c0 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/events/ResourcePackHandle.java @@ -36,6 +36,14 @@ public ResourcePackHandle(ParallelUtils puPlugin, ParallelResources resources, C public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); + if (!resources.doneLoading()) { + if (player.hasPermission("parallelutils.resources.unenforced")) { + return; + } else { + player.kick(Component.text("Server is still starting! Please check back in a minute.")); + } + } + if (!applyPack(player, null)) { ParallelUtils.log(Level.SEVERE, "UNABLE TO APPLY RESOURCE PACK!"); } From 7a34728afead54fa995017f772a7efdb9ba84f90 Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Sat, 25 Nov 2023 17:17:44 -0500 Subject: [PATCH 07/52] Actually block joins while packsquashing --- .../modules/parallelresources/ParallelResources.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java index 02e0fdd5..9484dca6 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelresources/ParallelResources.java @@ -226,6 +226,8 @@ public void onLoad() { @Override public void run() { try { + handler = new ResourcePackHandle(puPlugin, resources, warning_component); + List packs = squashFiles(packsTemp, resourcesDir, squashOut); for (File f : packs) { @@ -234,7 +236,7 @@ public void run() { resourceHashes.put(trimmed_name, createSha1(f)); } - handler = new ResourcePackHandle(puPlugin, resources, warning_component); + } catch (Exception e) { ParallelUtils.log(Level.SEVERE, "Exception while loading ParallelResources! Quitting..."); From 90ac7fe69d8c61283b8faf001bb022b31c0901a0 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Sat, 23 Dec 2023 16:01:48 -0500 Subject: [PATCH 08/52] Add crafting and dyeing support for custom hats that are dyeable, add the new type of ParallelHat to be returned upon player death --- .../bitsandbobs/minimodules/SpecialItems.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java index 071b3b59..259363dc 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java @@ -47,9 +47,10 @@ public void onPlayerDeath(PlayerDeathEvent event) { if (item.getType() == Material.PAPER || item.getType() == Material.LEATHER_HORSE_ARMOR) { // TODO: Try to change this code to use item.getItemMeta().getPersistentDataContainer() // TODO: Make this 2-part check not jank - hopefully transition entirely to persistentdatacontainer - NamespacedKey hatKey = new NamespacedKey(plugin, "CustomHat"); + NamespacedKey hatKeyOld = new NamespacedKey(plugin, "CustomHat"); + NamespacedKey hatKey = new NamespacedKey(plugin, "ParallelHat"); PersistentDataContainer container = item.getItemMeta().getPersistentDataContainer(); - if (container.has(hatKey, PersistentDataType.INTEGER)) { + if (container.has(hatKeyOld, PersistentDataType.INTEGER) || container.has(hatKey, PersistentDataType.STRING)) { preventedDrops.add(item); continue; } @@ -112,11 +113,20 @@ public void onPlayerCraft(PrepareItemCraftEvent event) { if (itemMeta == null) { // itemMeta could be null, so we have to check this continue; } - NamespacedKey hatKey = new NamespacedKey(plugin, "CustomHat"); + NamespacedKey hatKeyOld = new NamespacedKey(plugin, "CustomHat"); + NamespacedKey hatKey = new NamespacedKey(plugin, "ParallelHat"); + NamespacedKey dyeableKey = new NamespacedKey(plugin, "Dyeable"); NamespacedKey modifyKey = new NamespacedKey(plugin, "NoModify"); PersistentDataContainer container = itemMeta.getPersistentDataContainer(); - if (container.has(hatKey, PersistentDataType.INTEGER) || container.has(modifyKey, PersistentDataType.INTEGER)) { - ingredients.setResult(null); // Sets the crafting output to null if a CustomHat tag is found + // skip this item if it has the dyeableKey + if (container.has(dyeableKey, PersistentDataType.INTEGER)) { + continue; + } + // otherwise, if it's a hat or has the NoModify key, cancel the recipe + if (container.has(hatKeyOld, PersistentDataType.INTEGER) + || container.has(hatKey, PersistentDataType.STRING) + || container.has(modifyKey, PersistentDataType.INTEGER)) { + ingredients.setResult(null); break; } // Now we have to use NMS if the item doesn't have a PersistentDataContainer @@ -143,10 +153,19 @@ public void onArmorCauldronDye(PlayerInteractEvent event) { if (item.getType() == Material.LEATHER_HORSE_ARMOR) { ItemMeta itemMeta = item.getItemMeta(); if (itemMeta != null) { // itemMeta could be null, so we have to check this - NamespacedKey hatKey = new NamespacedKey(plugin, "CustomHat"); + NamespacedKey hatKeyOld = new NamespacedKey(plugin, "CustomHat"); + NamespacedKey hatKey = new NamespacedKey(plugin, "ParallelHat"); + NamespacedKey dyeableKey = new NamespacedKey(plugin, "Dyeable"); NamespacedKey modifyKey = new NamespacedKey(plugin, "NoModify"); PersistentDataContainer container = itemMeta.getPersistentDataContainer(); - if (container.has(hatKey, PersistentDataType.INTEGER) || container.has(modifyKey, PersistentDataType.INTEGER)) { + // skip this item if it has the dyeableKey + if (container.has(dyeableKey, PersistentDataType.INTEGER)) { + return; + } + // otherwise, if it's a hat or has the NoModify key, cancel the recipe + if (container.has(hatKeyOld, PersistentDataType.INTEGER) + || container.has(hatKey, PersistentDataType.STRING) + || container.has(modifyKey, PersistentDataType.INTEGER)) { event.setCancelled(true); return; } From 4bc497d6c503491a8a5a6e0d1adfffb418ea9f3f Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Sat, 23 Dec 2023 22:31:21 -0500 Subject: [PATCH 09/52] Update ParallelItems --- .../main/java/parallelmc/parallelutils/modules/parallelitems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems b/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems index 6b0c59ac..9ed2fb11 160000 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems @@ -1 +1 @@ -Subproject commit 6b0c59ac6486e7653aea1ffe7629f378ecc17d23 +Subproject commit 9ed2fb119044f3c16deb32d203e5bc7d940ef74b From 2a1fedf3c197ded77729d0cbb9223970d06b9116 Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Sat, 10 Feb 2024 10:59:06 -0500 Subject: [PATCH 10/52] Update to 1.20.4 --- api/build.gradle | 6 +-- .../parallelutils/commands/Commands.java | 2 +- build.gradle | 6 +-- modules/build.gradle | 6 +-- .../minimodules/KeepSpecialItems.java | 2 +- .../bitsandbobs/minimodules/SpecialItems.java | 2 +- .../handlers/impl/CharmParticleHandler.java | 2 +- .../PlayerJoinContainerListenerOverwrite.java | 6 +-- .../modules/charms/util/EnchantGlow.java | 37 ++++++++++++++----- .../parallelutils/modules/custommobs | 2 +- .../parallelutils/modules/parallelitems | 2 +- 11 files changed, 46 insertions(+), 27 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index 001ebb3c..d31fb6f9 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -7,7 +7,7 @@ plugins { group = 'org.parallelmc' -version = '4.2.2' +version = '4.3.0' description = 'A set of utilities and features for use on the Parallel Minecraft server' java { @@ -22,11 +22,11 @@ processResources.filteringCharset = "UTF-8" dependencies { implementation 'org.jetbrains:annotations:24.0.1' testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2' - implementation 'net.dv8tion:JDA:5.0.0-beta.10' + implementation 'net.dv8tion:JDA:5.0.0-beta.20' compileOnly 'me.clip:placeholderapi:2.11.3' compileOnly fileTree('libs') { include '*.jar' } compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.8' - implementation 'mysql:mysql-connector-java:8.0.33' + implementation 'com.mysql:mysql-connector-j:8.3.0' compileOnly 'com.comphenix.protocol:ProtocolLib:5.0.0' compileOnly 'dev.esophose:playerparticles:8.4' implementation 'org.reflections:reflections:0.10.2' diff --git a/api/src/main/java/parallelmc/parallelutils/commands/Commands.java b/api/src/main/java/parallelmc/parallelutils/commands/Commands.java index d1feadec..bdadec61 100644 --- a/api/src/main/java/parallelmc/parallelutils/commands/Commands.java +++ b/api/src/main/java/parallelmc/parallelutils/commands/Commands.java @@ -5,7 +5,7 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.command.*; -import org.bukkit.craftbukkit.v1_20_R1.command.ServerCommandSender; +import org.bukkit.craftbukkit.v1_20_R3.command.ServerCommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/build.gradle b/build.gradle index 498c0d63..3909ad5a 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } dependencies { - paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.1-R0.1-SNAPSHOT") + paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.4-R0.1-SNAPSHOT") } @@ -40,9 +40,9 @@ allprojects { } dependencies { - paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.1-R0.1-SNAPSHOT") + paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.4-R0.1-SNAPSHOT") - compileOnly "io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT" + compileOnly "io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT" compileOnly 'net.luckperms:api:5.4' compileOnly 'dev.esophose:playerparticles:8.4' compileOnly "com.github.MilkBowl:VaultAPI:1.7" diff --git a/modules/build.gradle b/modules/build.gradle index 33d6254d..33bd4b4c 100644 --- a/modules/build.gradle +++ b/modules/build.gradle @@ -19,14 +19,14 @@ dependencies { compileOnly 'org.jetbrains:annotations:24.0.1' testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2' - compileOnly 'net.dv8tion:JDA:5.0.0-beta.10' + compileOnly 'net.dv8tion:JDA:5.0.0-beta.20' compileOnly 'me.clip:placeholderapi:2.11.3' compileOnly fileTree('libs') { include '*.jar' } compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.8' - compileOnly 'mysql:mysql-connector-java:8.0.33' + compileOnly 'com.mysql:mysql-connector-j:8.3.0' compileOnly 'com.comphenix.protocol:ProtocolLib:5.0.0' compileOnly 'dev.esophose:playerparticles:8.4' - compileOnly "io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT" + compileOnly "io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT" } def names = [] diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/KeepSpecialItems.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/KeepSpecialItems.java index b81a7c78..595aa411 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/KeepSpecialItems.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/KeepSpecialItems.java @@ -2,7 +2,7 @@ import net.minecraft.nbt.CompoundTag; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java index 259363dc..3b0a3d62 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java @@ -4,7 +4,7 @@ import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java b/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java index 650c383d..712d6324 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java @@ -4,7 +4,7 @@ import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/charms/listeners/PlayerJoinContainerListenerOverwrite.java b/modules/src/main/java/parallelmc/parallelutils/modules/charms/listeners/PlayerJoinContainerListenerOverwrite.java index db205e48..26da9cec 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/charms/listeners/PlayerJoinContainerListenerOverwrite.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/charms/listeners/PlayerJoinContainerListenerOverwrite.java @@ -5,7 +5,7 @@ import net.minecraft.world.inventory.*; import net.minecraft.world.item.ItemStack; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -26,9 +26,9 @@ public PlayerJoinContainerListenerOverwrite() { Field field; Field field1; try { - field = ServerPlayer.class.getDeclaredField("cW"); + field = ServerPlayer.class.getDeclaredField("dc"); field.setAccessible(true); - field1 = ServerPlayer.class.getDeclaredField("cX"); + field1 = ServerPlayer.class.getDeclaredField("dd"); field1.setAccessible(true); } catch (NoSuchFieldException e) { e.printStackTrace(); diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java b/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java index 09306767..d8a8bb4e 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java @@ -3,6 +3,7 @@ import io.papermc.paper.enchantments.EnchantmentRarity; import net.kyori.adventure.text.Component; import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.EntityCategory; @@ -15,8 +16,11 @@ import java.util.Set; public class EnchantGlow extends Enchantment { + + private final NamespacedKey key; + public EnchantGlow(@NotNull NamespacedKey key) { - super(key); + this.key = key; } @Override @@ -74,6 +78,16 @@ public boolean isDiscoverable() { return false; } + @Override + public int getMinModifiedCost(int level) { + return 0; + } + + @Override + public int getMaxModifiedCost(int level) { + return 0; + } + @Override public @NotNull EnchantmentRarity getRarity() { return EnchantmentRarity.COMMON; @@ -97,19 +111,24 @@ public float getDamageIncrease(int level, @NotNull EntityCategory entityCategory public static EnchantGlow instance = null; public static void registerFakeGlow(ParallelUtils puPlugin) { - try { - Field f = Enchantment.class.getDeclaredField("acceptingNew"); - f.setAccessible(true); - f.set(null, true); - } catch (Exception e) { - e.printStackTrace(); - } +// try { +// Field f = Enchantment.class.getDeclaredField("acceptingNew"); +// f.setAccessible(true); +// f.set(null, true); +// } catch (Exception e) { +// e.printStackTrace(); +// } try { instance = new EnchantGlow(new NamespacedKey(puPlugin, "glow")); - Enchantment.registerEnchantment(instance); + } catch (Exception e) { e.printStackTrace(); } } + + @Override + public @NotNull NamespacedKey getKey() { + return key; + } } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/custommobs b/modules/src/main/java/parallelmc/parallelutils/modules/custommobs index ab8a8e4c..cc9233ba 160000 --- a/modules/src/main/java/parallelmc/parallelutils/modules/custommobs +++ b/modules/src/main/java/parallelmc/parallelutils/modules/custommobs @@ -1 +1 @@ -Subproject commit ab8a8e4cb50468704b049bd7a1503b1cf3d54037 +Subproject commit cc9233ba51ea098fd5ae6093133bc8ed8f615f24 diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems b/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems index 9ed2fb11..b339f1d5 160000 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems @@ -1 +1 @@ -Subproject commit 9ed2fb119044f3c16deb32d203e5bc7d940ef74b +Subproject commit b339f1d5785d048866b132284fb8f66aed5cb61f From b59be855c2e4770db36bbd0a6a85e5ccec286407 Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:03:33 -0500 Subject: [PATCH 11/52] Update EntityDamageEvent signature --- .../modules/parallelflags/session/CustomArmorHealth.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelflags/session/CustomArmorHealth.java b/modules/src/main/java/parallelmc/parallelutils/modules/parallelflags/session/CustomArmorHealth.java index 38d6e3ca..6068db8d 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelflags/session/CustomArmorHealth.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelflags/session/CustomArmorHealth.java @@ -9,6 +9,8 @@ import com.sk89q.worldguard.session.handler.Handler; import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; +import org.bukkit.damage.DamageSource; +import org.bukkit.damage.DamageType; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; @@ -157,7 +159,7 @@ public void tick(LocalPlayer player, ApplicableRegionSet set) { } EntityDamageEvent event = new EntityDamageEvent(bukkitPlayer.getPlayer(), - EntityDamageEvent.DamageCause.CUSTOM, damageAmount); + EntityDamageEvent.DamageCause.CUSTOM, DamageSource.builder(DamageType.GENERIC).build(),damageAmount); bukkitPlayer.getPlayer().setLastDamageCause(event); bukkitPlayer.getPlayer().damage(player.getMaxHealth()); @@ -179,7 +181,7 @@ public void tick(LocalPlayer player, ApplicableRegionSet set) { } EntityDamageEvent event = new EntityDamageEvent(bukkitPlayer.getPlayer(), - EntityDamageEvent.DamageCause.CUSTOM, damageAmount); + EntityDamageEvent.DamageCause.CUSTOM, DamageSource.builder(DamageType.GENERIC).build(), damageAmount); bukkitPlayer.getPlayer().setLastDamageCause(event); } From e14850ec919294c3797ea2c8a7ad116213993782 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Tue, 13 Feb 2024 23:02:52 -0500 Subject: [PATCH 12/52] Initial sweethearts code --- .../modules/bitsandbobs/BitsAndBobs.java | 1 + .../bitsandbobs/minimodules/Sweethearts.java | 149 ++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java index 90029bbb..c8a96e82 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java @@ -62,6 +62,7 @@ public void onEnable() { manager.registerEvents(new OnPvp(), plugin); manager.registerEvents(new ShardLotto(), plugin); manager.registerEvents(new ChickenFeatherDrops(), plugin); + manager.registerEvents(new Sweethearts(), plugin); if (config.getBoolean("disable-ender-chests", false)) { manager.registerEvents(new DisableEnderChest(), plugin); diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java new file mode 100644 index 00000000..4ca75729 --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java @@ -0,0 +1,149 @@ +package parallelmc.parallelutils.modules.bitsandbobs.minimodules; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.*; +import org.bukkit.attribute.Attribute; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityResurrectEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import parallelmc.parallelutils.Constants; +import parallelmc.parallelutils.ParallelUtils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.UUID; +import java.util.logging.Level; + +public class Sweethearts implements Listener { + + private final HashMap healthDonors = new HashMap<>(); + private BukkitTask runnable = null; + private final Plugin plugin; + + public Sweethearts() { + PluginManager manager = Bukkit.getPluginManager(); + plugin = manager.getPlugin(Constants.PLUGIN_NAME); + if (plugin == null) { + ParallelUtils.log(Level.SEVERE, "Unable to enable Sweethearts. Plugin " + Constants.PLUGIN_NAME + + " does not exist!"); + } + } + + @EventHandler + public void onPlayerShift(PlayerToggleSneakEvent event) { + Player donor = event.getPlayer(); + if (event.isSneaking()) { + runnable = new BukkitRunnable() { + @Override + public void run() { + // If the donor is sneaking but not holding a poppy, return + if (!(donor.getInventory().getItemInMainHand().getType().equals(Material.POPPY) || + donor.getInventory().getItemInOffHand().getType().equals(Material.POPPY))) { + return; + } + // Get a list of all players in a 3-block radius (ty Paper for the epic function) + Location donorLocation = donor.getLocation(); + Collection nearbyPlayersCollection = + donor.getWorld().getNearbyEntitiesByType(Player.class, donorLocation, 3); + ArrayList nearbyPlayers = new ArrayList<>(nearbyPlayersCollection); + // Check if there are more players than just the donor themselves within a 3-block radius + if (!(nearbyPlayers.size() > 1)) { + return; + } + + // Iterate over all players within the radius and find the closest player + UUID donorUUID = donor.getUniqueId(); + double smallestDistance = Double.MAX_VALUE; + Player recipient = null; + Location recipientLocation = null; + + for (Player player : nearbyPlayers) { + if (!(player.getUniqueId().equals(donorUUID))) { + Location playerLocation = player.getLocation(); + double distance = donorLocation.distanceSquared(playerLocation); // using distance squared to avoid expensive square roots + if (distance < smallestDistance) { + smallestDistance = distance; + recipient = player; + recipientLocation = player.getLocation(); + } + } + } + + // Check if recipient needs to be healed + double recipientHealth = recipient.getHealth(); + double recipientMaxHealth = recipient.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); + if (!(recipientHealth < recipientMaxHealth)) { + return; + } + + // Add donor and recipient to healthDonor list + // The remove function does a check to see if the donor's in the list + healthDonors.remove(donorUUID); + healthDonors.put(donorUUID, recipient.getUniqueId()); + + // Give 1 health from donor to recipient + donor.damage(1); + recipient.setHealth(recipientHealth + 1); + + // Spawn particles (idk why picking the function with the right parameters is so finicky) + World world = donorLocation.getWorld(); + world.spawnParticle(Particle.DAMAGE_INDICATOR, donorLocation.getX(), donorLocation.getY() + 2, + donorLocation.getZ(), 5, 0, 0, 0, 0.255, null); + world.spawnParticle(Particle.HEART, recipientLocation.getX(), recipientLocation.getY() + 2, + recipientLocation.getZ(), 2, 0.2, 0.2, 0.2, 1, null); + } + }.runTaskTimer(plugin, 16L, 16L); + + } else { + // if the runnable is running for the player, stop it + if (!runnable.isCancelled()) { + runnable.cancel(); + } + // Remove donor from the donor list + healthDonors.remove(donor.getUniqueId()); + } + } + + @EventHandler + public void onPlayerDeath(PlayerDeathEvent event) { + Player donor = event.getPlayer(); + UUID donorUUID = donor.getUniqueId(); + // Check if the player was a donor, and if so, remove the player from the healthDonor list and + // add a custom death message + if (healthDonors.containsKey(donorUUID)) { + if (!runnable.isCancelled()) { // may be redundant because dying unshifts the player, but it's here just in case + runnable.cancel(); + } else { + ParallelUtils.log(Level.WARNING, "Player " + donor.getName() + + " was listed as a healthDonor but they weren't actively donating health. Something is wrong!"); + } + + // Build and send the death message text component + UUID recipientUUID = healthDonors.get(donorUUID); + Player recipient = Bukkit.getPlayer(recipientUUID); + final TextComponent deathMessage = Component.text(donor.getName() + " was shot through the heart and " + + recipient.getName() + " was to blame") + .color(NamedTextColor.WHITE); + event.deathMessage(deathMessage); + + healthDonors.remove(donorUUID); + + // todo: give advancement and entityresurrectevent + } + } + + public void onTotemUse(EntityResurrectEvent event) { + + } + +} From 8c88911037f3351a8888dc0b0fa0616d2df9ef5a Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Wed, 14 Feb 2024 14:24:08 -0500 Subject: [PATCH 13/52] Sweethearts updates --- .../bitsandbobs/minimodules/Sweethearts.java | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java index 4ca75729..38af23b4 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java @@ -27,7 +27,8 @@ public class Sweethearts implements Listener { private final HashMap healthDonors = new HashMap<>(); - private BukkitTask runnable = null; + private final HashMap shiftingRunnables = new HashMap<>(); + // private BukkitTask runnable = null; private final Plugin plugin; public Sweethearts() { @@ -43,7 +44,7 @@ public Sweethearts() { public void onPlayerShift(PlayerToggleSneakEvent event) { Player donor = event.getPlayer(); if (event.isSneaking()) { - runnable = new BukkitRunnable() { + BukkitTask runnable = new BukkitRunnable() { @Override public void run() { // If the donor is sneaking but not holding a poppy, return @@ -92,8 +93,13 @@ public void run() { healthDonors.put(donorUUID, recipient.getUniqueId()); // Give 1 health from donor to recipient + // If the recipient needs less than one heart, give them that donor.damage(1); - recipient.setHealth(recipientHealth + 1); + if (recipientHealth + 1 > recipientMaxHealth) { + recipient.setHealth(recipientMaxHealth); + } else { + recipient.setHealth(recipientHealth + 1); + } // Spawn particles (idk why picking the function with the right parameters is so finicky) World world = donorLocation.getWorld(); @@ -104,13 +110,20 @@ public void run() { } }.runTaskTimer(plugin, 16L, 16L); + int taskID = runnable.getTaskId(); + shiftingRunnables.put(donor.getUniqueId(),taskID); } else { - // if the runnable is running for the player, stop it - if (!runnable.isCancelled()) { - runnable.cancel(); + // Check if donor health is greater than 0 to prevent clashes with the PlayerDeathEvent listener + if (donor.getHealth() > 0) { + // if the runnable is running for the player, stop it + if (shiftingRunnables.containsKey(donor.getUniqueId())) { + int taskID = shiftingRunnables.get(donor.getUniqueId()); + Bukkit.getScheduler().cancelTask(taskID); + shiftingRunnables.remove(donor.getUniqueId()); + } + // Remove donor from the donor list + healthDonors.remove(donor.getUniqueId()); } - // Remove donor from the donor list - healthDonors.remove(donor.getUniqueId()); } } @@ -121,8 +134,11 @@ public void onPlayerDeath(PlayerDeathEvent event) { // Check if the player was a donor, and if so, remove the player from the healthDonor list and // add a custom death message if (healthDonors.containsKey(donorUUID)) { - if (!runnable.isCancelled()) { // may be redundant because dying unshifts the player, but it's here just in case - runnable.cancel(); + if (shiftingRunnables.containsKey(donorUUID)) { // may be redundant because dying unshifts the player, but it's here just in case + int taskID = shiftingRunnables.get(donorUUID); + Bukkit.getScheduler().cancelTask(taskID); + shiftingRunnables.remove(donorUUID); + } } else { ParallelUtils.log(Level.WARNING, "Player " + donor.getName() + " was listed as a healthDonor but they weren't actively donating health. Something is wrong!"); @@ -139,7 +155,7 @@ public void onPlayerDeath(PlayerDeathEvent event) { healthDonors.remove(donorUUID); // todo: give advancement and entityresurrectevent - } + } public void onTotemUse(EntityResurrectEvent event) { From 9d1a946fafd2720a7f4319e26899374b5f117239 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Thu, 15 Feb 2024 02:15:31 -0500 Subject: [PATCH 14/52] Sweethearts updates --- .../bitsandbobs/minimodules/Sweethearts.java | 59 ++++++++++++++----- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java index 38af23b4..42b2daa8 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java @@ -4,7 +4,10 @@ import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.*; +import org.bukkit.advancement.Advancement; +import org.bukkit.advancement.AdvancementProgress; import org.bukkit.attribute.Attribute; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -87,9 +90,7 @@ public void run() { return; } - // Add donor and recipient to healthDonor list - // The remove function does a check to see if the donor's in the list - healthDonors.remove(donorUUID); + // Add donor and recipient to healthDonor list - key gets overridden if it's already in there healthDonors.put(donorUUID, recipient.getUniqueId()); // Give 1 health from donor to recipient @@ -116,13 +117,14 @@ public void run() { // Check if donor health is greater than 0 to prevent clashes with the PlayerDeathEvent listener if (donor.getHealth() > 0) { // if the runnable is running for the player, stop it - if (shiftingRunnables.containsKey(donor.getUniqueId())) { - int taskID = shiftingRunnables.get(donor.getUniqueId()); + UUID donorUUID = donor.getUniqueId(); + if (shiftingRunnables.containsKey(donorUUID)) { + int taskID = shiftingRunnables.get(donorUUID); Bukkit.getScheduler().cancelTask(taskID); - shiftingRunnables.remove(donor.getUniqueId()); + shiftingRunnables.remove(donorUUID); } // Remove donor from the donor list - healthDonors.remove(donor.getUniqueId()); + healthDonors.remove(donorUUID); } } } @@ -131,35 +133,60 @@ public void run() { public void onPlayerDeath(PlayerDeathEvent event) { Player donor = event.getPlayer(); UUID donorUUID = donor.getUniqueId(); - // Check if the player was a donor, and if so, remove the player from the healthDonor list and + // Check if the player was a donor, and if so, remove the player from the healthDonor map and // add a custom death message if (healthDonors.containsKey(donorUUID)) { - if (shiftingRunnables.containsKey(donorUUID)) { // may be redundant because dying unshifts the player, but it's here just in case + // Remove the player from the shiftingRunnables map if they were shifting upon death + if (shiftingRunnables.containsKey(donorUUID)) { int taskID = shiftingRunnables.get(donorUUID); Bukkit.getScheduler().cancelTask(taskID); shiftingRunnables.remove(donorUUID); } - } else { - ParallelUtils.log(Level.WARNING, "Player " + donor.getName() + - " was listed as a healthDonor but they weren't actively donating health. Something is wrong!"); - } // Build and send the death message text component UUID recipientUUID = healthDonors.get(donorUUID); Player recipient = Bukkit.getPlayer(recipientUUID); final TextComponent deathMessage = Component.text(donor.getName() + " was shot through the heart and " + - recipient.getName() + " was to blame") + recipient.getName() + " was to blame") .color(NamedTextColor.WHITE); event.deathMessage(deathMessage); + // Remove the player from the healthDonor map healthDonors.remove(donorUUID); - // todo: give advancement and entityresurrectevent - + // Award advancement + awardAdvancement(donor); + } } + @EventHandler public void onTotemUse(EntityResurrectEvent event) { + // Check if entity is being resurrected by a totem - if the event isn't cancelled, then they have a totem + if (!event.isCancelled()) { + Entity entity = event.getEntity(); + // Check if entity is a player + if (entity instanceof Player) { + Player donor = (Player) entity; + // Check if entity is an active donor - if so, award the advancement + UUID donorUUID = donor.getUniqueId(); + if (healthDonors.containsKey(donorUUID)) { + awardAdvancement(donor); + } + } + } + } + public void awardAdvancement(Player donor) { + Advancement a = Bukkit.getAdvancement(new NamespacedKey(NamespacedKey.MINECRAFT, + "platy:exploration/flower_health_transfer_death")); + if (a != null) { + AdvancementProgress avp = donor.getAdvancementProgress(a); + if (!avp.isDone()) { + for (String criteria : avp.getRemainingCriteria()) { + avp.awardCriteria(criteria); + } + } + } } } From e052d6ab68973f0cf28be29e07b484e2dcf762a2 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Thu, 15 Feb 2024 23:07:14 -0500 Subject: [PATCH 15/52] Sweethearts fix --- .../bitsandbobs/minimodules/Sweethearts.java | 144 ++++++++---------- 1 file changed, 64 insertions(+), 80 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java index 42b2daa8..a221f16e 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java @@ -13,11 +13,8 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityResurrectEvent; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.scheduler.BukkitTask; import parallelmc.parallelutils.Constants; import parallelmc.parallelutils.ParallelUtils; @@ -36,95 +33,83 @@ public class Sweethearts implements Listener { public Sweethearts() { PluginManager manager = Bukkit.getPluginManager(); - plugin = manager.getPlugin(Constants.PLUGIN_NAME); + Plugin plugin = manager.getPlugin(Constants.PLUGIN_NAME); if (plugin == null) { ParallelUtils.log(Level.SEVERE, "Unable to enable Sweethearts. Plugin " + Constants.PLUGIN_NAME + " does not exist!"); } } - @EventHandler - public void onPlayerShift(PlayerToggleSneakEvent event) { - Player donor = event.getPlayer(); - if (event.isSneaking()) { - BukkitTask runnable = new BukkitRunnable() { - @Override - public void run() { - // If the donor is sneaking but not holding a poppy, return - if (!(donor.getInventory().getItemInMainHand().getType().equals(Material.POPPY) || + public void checkForDonors() { + for (Player donor : Bukkit.getOnlinePlayers()) { + UUID donorUUID = donor.getUniqueId(); + if (donor.isSneaking()) { + // If the donor is sneaking but not holding a poppy, return + if (!(donor.getInventory().getItemInMainHand().getType().equals(Material.POPPY) || donor.getInventory().getItemInOffHand().getType().equals(Material.POPPY))) { - return; - } - // Get a list of all players in a 3-block radius (ty Paper for the epic function) - Location donorLocation = donor.getLocation(); - Collection nearbyPlayersCollection = - donor.getWorld().getNearbyEntitiesByType(Player.class, donorLocation, 3); - ArrayList nearbyPlayers = new ArrayList<>(nearbyPlayersCollection); - // Check if there are more players than just the donor themselves within a 3-block radius - if (!(nearbyPlayers.size() > 1)) { - return; - } + return; + } + // Get a list of all players in a 3-block radius (ty Paper for the epic function) + Location donorLocation = donor.getLocation(); + Collection nearbyPlayersCollection = + donor.getWorld().getNearbyEntitiesByType(Player.class, donorLocation, 3); + ArrayList nearbyPlayers = new ArrayList<>(nearbyPlayersCollection); + // Check if there are more players than just the donor themselves within a 3-block radius + if (!(nearbyPlayers.size() > 1)) { + return; + } - // Iterate over all players within the radius and find the closest player - UUID donorUUID = donor.getUniqueId(); - double smallestDistance = Double.MAX_VALUE; - Player recipient = null; - Location recipientLocation = null; - - for (Player player : nearbyPlayers) { - if (!(player.getUniqueId().equals(donorUUID))) { - Location playerLocation = player.getLocation(); - double distance = donorLocation.distanceSquared(playerLocation); // using distance squared to avoid expensive square roots - if (distance < smallestDistance) { - smallestDistance = distance; - recipient = player; - recipientLocation = player.getLocation(); - } + // Iterate over all players within the radius and find the closest player + double smallestDistance = Double.MAX_VALUE; + Player recipient = null; + Location recipientLocation = null; + + for (Player player : nearbyPlayers) { + if (!(player.getUniqueId().equals(donorUUID))) { + Location playerLocation = player.getLocation(); + double distance = donorLocation.distanceSquared(playerLocation); // using distance squared to avoid expensive square roots + if (distance < smallestDistance) { + smallestDistance = distance; + recipient = player; + recipientLocation = player.getLocation(); } } + } - // Check if recipient needs to be healed - double recipientHealth = recipient.getHealth(); - double recipientMaxHealth = recipient.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); - if (!(recipientHealth < recipientMaxHealth)) { - return; - } - - // Add donor and recipient to healthDonor list - key gets overridden if it's already in there - healthDonors.put(donorUUID, recipient.getUniqueId()); + // Check if recipient needs to be healed + double recipientHealth = recipient.getHealth(); + double recipientMaxHealth = recipient.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); + if (!(recipientHealth < recipientMaxHealth)) { + return; + } - // Give 1 health from donor to recipient - // If the recipient needs less than one heart, give them that - donor.damage(1); - if (recipientHealth + 1 > recipientMaxHealth) { - recipient.setHealth(recipientMaxHealth); - } else { - recipient.setHealth(recipientHealth + 1); - } + // Add donor and recipient to healthDonor list - key gets overridden if it's already in there + healthDonors.put(donorUUID, recipient.getUniqueId()); - // Spawn particles (idk why picking the function with the right parameters is so finicky) - World world = donorLocation.getWorld(); - world.spawnParticle(Particle.DAMAGE_INDICATOR, donorLocation.getX(), donorLocation.getY() + 2, - donorLocation.getZ(), 5, 0, 0, 0, 0.255, null); - world.spawnParticle(Particle.HEART, recipientLocation.getX(), recipientLocation.getY() + 2, - recipientLocation.getZ(), 2, 0.2, 0.2, 0.2, 1, null); + // Give 1 health from donor to recipient + // If the recipient needs less than one heart, give them that + donor.damage(1); + if (recipientHealth + 1 > recipientMaxHealth) { + recipient.setHealth(recipientMaxHealth); + } else { + recipient.setHealth(recipientHealth + 1); } - }.runTaskTimer(plugin, 16L, 16L); - - int taskID = runnable.getTaskId(); - shiftingRunnables.put(donor.getUniqueId(),taskID); - } else { - // Check if donor health is greater than 0 to prevent clashes with the PlayerDeathEvent listener - if (donor.getHealth() > 0) { - // if the runnable is running for the player, stop it - UUID donorUUID = donor.getUniqueId(); - if (shiftingRunnables.containsKey(donorUUID)) { - int taskID = shiftingRunnables.get(donorUUID); - Bukkit.getScheduler().cancelTask(taskID); - shiftingRunnables.remove(donorUUID); + + // Spawn particles (idk why picking the function with the right parameters is so finicky) + World world = donorLocation.getWorld(); + world.spawnParticle(Particle.DAMAGE_INDICATOR, donorLocation.getX(), donorLocation.getY() + 2, + donorLocation.getZ(), 5, 0, 0, 0, 0.255, null); + world.spawnParticle(Particle.HEART, recipientLocation.getX(), recipientLocation.getY() + 2, + recipientLocation.getZ(), 2, 0.2, 0.2, 0.2, 1, null); + } + else { + if (healthDonors.containsKey(donorUUID)) { + // Check if health > 0 to prevent clashing with the death event + if (donor.getHealth() > 0) { + // Remove donor from the donor list + healthDonors.remove(donorUUID); + } } - // Remove donor from the donor list - healthDonors.remove(donorUUID); } } } @@ -177,8 +162,8 @@ public void onTotemUse(EntityResurrectEvent event) { } public void awardAdvancement(Player donor) { - Advancement a = Bukkit.getAdvancement(new NamespacedKey(NamespacedKey.MINECRAFT, - "platy:exploration/flower_health_transfer_death")); + Advancement a = Bukkit.getAdvancement(new NamespacedKey("platy", + "exploration/flower_health_transfer_death")); if (a != null) { AdvancementProgress avp = donor.getAdvancementProgress(a); if (!avp.isDone()) { @@ -188,5 +173,4 @@ public void awardAdvancement(Player donor) { } } } - } From 57d6b5a9893e75903c9ddcf0715644e405331c36 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Thu, 15 Feb 2024 23:07:30 -0500 Subject: [PATCH 16/52] Sweethearts fix --- .../bitsandbobs/minimodules/Sweethearts.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java index a221f16e..c255fb1e 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java @@ -27,9 +27,6 @@ public class Sweethearts implements Listener { private final HashMap healthDonors = new HashMap<>(); - private final HashMap shiftingRunnables = new HashMap<>(); - // private BukkitTask runnable = null; - private final Plugin plugin; public Sweethearts() { PluginManager manager = Bukkit.getPluginManager(); @@ -37,7 +34,13 @@ public Sweethearts() { if (plugin == null) { ParallelUtils.log(Level.SEVERE, "Unable to enable Sweethearts. Plugin " + Constants.PLUGIN_NAME + " does not exist!"); + return; } + + // had some weird issues when checking for sneaking in an event + // so using a runnable seems to be the play + + plugin.getServer().getScheduler().runTaskTimer(plugin, this::checkForDonors, 0L, 16L); } public void checkForDonors() { @@ -121,13 +124,6 @@ public void onPlayerDeath(PlayerDeathEvent event) { // Check if the player was a donor, and if so, remove the player from the healthDonor map and // add a custom death message if (healthDonors.containsKey(donorUUID)) { - // Remove the player from the shiftingRunnables map if they were shifting upon death - if (shiftingRunnables.containsKey(donorUUID)) { - int taskID = shiftingRunnables.get(donorUUID); - Bukkit.getScheduler().cancelTask(taskID); - shiftingRunnables.remove(donorUUID); - } - // Build and send the death message text component UUID recipientUUID = healthDonors.get(donorUUID); Player recipient = Bukkit.getPlayer(recipientUUID); @@ -150,8 +146,7 @@ public void onTotemUse(EntityResurrectEvent event) { if (!event.isCancelled()) { Entity entity = event.getEntity(); // Check if entity is a player - if (entity instanceof Player) { - Player donor = (Player) entity; + if (entity instanceof Player donor) { // Check if entity is an active donor - if so, award the advancement UUID donorUUID = donor.getUniqueId(); if (healthDonors.containsKey(donorUUID)) { From d7ee0d05d4ae8a03b0fd9be90b426243f08cde19 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Thu, 15 Feb 2024 23:09:15 -0500 Subject: [PATCH 17/52] Sweethearts fix --- .../modules/bitsandbobs/minimodules/Sweethearts.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java index c255fb1e..2d420101 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java @@ -129,7 +129,7 @@ public void onPlayerDeath(PlayerDeathEvent event) { Player recipient = Bukkit.getPlayer(recipientUUID); final TextComponent deathMessage = Component.text(donor.getName() + " was shot through the heart and " + recipient.getName() + " was to blame") - .color(NamedTextColor.WHITE); + .color(NamedTextColor.WHITE); event.deathMessage(deathMessage); // Remove the player from the healthDonor map From e12547d1828d13f01ae458725c1b5e98daf327a1 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Mon, 19 Feb 2024 01:57:04 -0500 Subject: [PATCH 18/52] Add calling bell mechanic --- .../parallelmc/parallelutils/Constants.java | 4 + api/src/main/resources/config.yml | 3 +- .../modules/bitsandbobs/BitsAndBobs.java | 3 + .../bitsandbobs/minimodules/CallingBell.java | 151 ++++++++++++++++++ 4 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/CallingBell.java diff --git a/api/src/main/java/parallelmc/parallelutils/Constants.java b/api/src/main/java/parallelmc/parallelutils/Constants.java index 9aea8786..c3898b97 100644 --- a/api/src/main/java/parallelmc/parallelutils/Constants.java +++ b/api/src/main/java/parallelmc/parallelutils/Constants.java @@ -1,8 +1,12 @@ package parallelmc.parallelutils; +import java.util.ArrayList; + public class Constants { public static final Version VERSION = new Version(4, 2, 2); public static final String PLUGIN_NAME = "ParallelUtils"; public static final String DEFAULT_WORLD = "world2"; + + public static final String[] OVERWORLD_TYPE_WORLDS = {"world", "world2", "world_skyteaser"}; } diff --git a/api/src/main/resources/config.yml b/api/src/main/resources/config.yml index 0b115ee1..f18d5129 100644 --- a/api/src/main/resources/config.yml +++ b/api/src/main/resources/config.yml @@ -76,4 +76,5 @@ announcements: # Bits and Bobs disable-ender-chests: false -prevent-spawner-mining: false \ No newline at end of file +prevent-spawner-mining: false +enable-calling-bell: true \ No newline at end of file diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java index 90029bbb..57062501 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java @@ -70,6 +70,9 @@ public void onEnable() { if (config.getBoolean("prevent-spawner-mining", false)) { manager.registerEvents(new PreventSpawnerMining(), plugin); } + if (config.getBoolean("enable-calling-bell", true)) { + manager.registerEvents(new CallingBell(), plugin); + } } @Override diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/CallingBell.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/CallingBell.java new file mode 100644 index 00000000..442e8167 --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/CallingBell.java @@ -0,0 +1,151 @@ +package parallelmc.parallelutils.modules.bitsandbobs.minimodules; + +import org.bukkit.*; +import org.bukkit.advancement.Advancement; +import org.bukkit.advancement.AdvancementProgress; +import org.bukkit.block.Block; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; +import parallelmc.parallelutils.Constants; +import parallelmc.parallelutils.ParallelUtils; + +import java.util.*; +import java.util.logging.Level; + +public class CallingBell implements Listener { + + private static final HashMap> traderSummoners = new HashMap<>(); + private static final String[] OVERWORLD_TYPE_WORLDS = Constants.OVERWORLD_TYPE_WORLDS; + private static final int DAY_CHECK_INTERVAL = 1200; + + public CallingBell() { + PluginManager manager = Bukkit.getPluginManager(); + Plugin plugin = manager.getPlugin(Constants.PLUGIN_NAME); + if (plugin == null) { + ParallelUtils.log(Level.SEVERE, "Unable to enable CallingBell. Plugin " + Constants.PLUGIN_NAME + + " does not exist!"); + return; + } + + // If this minute-long timer is too long, we can reduce it + plugin.getServer().getScheduler().runTaskTimer(plugin, this::dailyListReset, 0L, DAY_CHECK_INTERVAL); + } + + @EventHandler + public void onPlayerRightClickBell(PlayerInteractEvent event) { + // Check if player clicked a bell holding an emerald + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + if (block == null) { + return; + } + + if (!event.getClickedBlock().getType().equals(Material.BELL)) { + return; + } + + PlayerInventory inventory = player.getInventory(); + if (!inventory.getItemInMainHand().getType().equals(Material.EMERALD) && + !inventory.getItemInOffHand().getType().equals(Material.EMERALD)) { + return; + } + + // Check if player right-clicked + if (!event.getAction().isRightClick()) { + return; + } + + // Check if player is in an overworld-type world + Location bellLocation = block.getLocation(); + World world = bellLocation.getWorld(); + if (!Arrays.asList(OVERWORLD_TYPE_WORLDS).contains(world.getName())) { + return; + } + + // Check if player hasn't summoned the villager yet in this world + // If they haven't, remove emerald and summon trader + // If they have, add them and their world into (or back into) the hashmap + UUID playerUUID = player.getUniqueId(); + ArrayList worldsOnCooldown = new ArrayList<>(); + if (traderSummoners.containsKey(playerUUID)) { + worldsOnCooldown = traderSummoners.get(playerUUID); + if (worldsOnCooldown.contains(world)) { + return; + } + } + worldsOnCooldown.add(world); + traderSummoners.put(playerUUID, worldsOnCooldown); + + inventory.remove(new ItemStack(Material.EMERALD, 1)); + + // This is done to center the spawning trader on the bell - it also overwrites the original location + bellLocation.add(0.5, 1, 0.5); + world.spawnEntity(bellLocation, EntityType.WANDERING_TRADER); + + // Add particles and sound + world.spawnParticle(Particle.VILLAGER_HAPPY,bellLocation.getX(), bellLocation.getY() + 0.5, + bellLocation.getZ(), 5, 0.3, 0.3, 0.3); + world.spawnParticle(Particle.SMOKE_LARGE, bellLocation.getX(), bellLocation.getY() + 1, + bellLocation.getZ(), 10, 0.25, 0.5, 0.25, 0); + world.playSound(bellLocation, Sound.ENTITY_WANDERING_TRADER_REAPPEARED, SoundCategory.NEUTRAL, + 1, 1); + + // Check/give advancement + awardAdvancement(player); + + } + + public void dailyListReset() { + ArrayList worldsToReset = new ArrayList<>(); + // Check each world + for (String worldString : OVERWORLD_TYPE_WORLDS) { + // Check if world is null + World world = Bukkit.getWorld(worldString); + if (world == null) { + ParallelUtils.log(Level.WARNING, "World " + worldString + + " is registered as an overworld-type world but the world is not loaded!"); + continue; + } + + // Perform day check on the world - if it's a new day within the interval, add the world to the + // worldsToReset list + long worldTime = world.getTime(); + if (worldTime >= 0 && worldTime < DAY_CHECK_INTERVAL) { + worldsToReset.add(world); + } + } + + // For each traderSummoners entry, remove all reset worlds from each player's worldsOnCooldown list + // If there are no worlds left in the list after that, remove the player from the traderSummoners hashmap + for (Map.Entry> entry : traderSummoners.entrySet()) { + UUID playerUUID = entry.getKey(); + ArrayList worldsOnCooldown = entry.getValue(); + worldsOnCooldown.removeAll(worldsToReset); + if (worldsOnCooldown.isEmpty()) { + traderSummoners.remove(playerUUID); + } else { + traderSummoners.put(playerUUID, worldsOnCooldown); + } + } + } + + public void awardAdvancement(Player player) { + Advancement a = Bukkit.getAdvancement(new NamespacedKey("platy", + "village/calling_bell")); + if (a != null) { + AdvancementProgress avp = player.getAdvancementProgress(a); + if (!avp.isDone()) { + for (String criteria : avp.getRemainingCriteria()) { + avp.awardCriteria(criteria); + } + } + } + } +} From 3d7e96ca860f31fea94a74c762158ad4a1bd58d2 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Mon, 19 Feb 2024 02:00:02 -0500 Subject: [PATCH 19/52] Added sweethearts config toggle, changed advancement name --- api/src/main/resources/config.yml | 3 ++- .../parallelutils/modules/bitsandbobs/BitsAndBobs.java | 5 ++++- .../modules/bitsandbobs/minimodules/Sweethearts.java | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/api/src/main/resources/config.yml b/api/src/main/resources/config.yml index 0b115ee1..22ebea00 100644 --- a/api/src/main/resources/config.yml +++ b/api/src/main/resources/config.yml @@ -76,4 +76,5 @@ announcements: # Bits and Bobs disable-ender-chests: false -prevent-spawner-mining: false \ No newline at end of file +prevent-spawner-mining: false +enable-sweethearts: true \ No newline at end of file diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java index c8a96e82..2e2323fa 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java @@ -62,7 +62,6 @@ public void onEnable() { manager.registerEvents(new OnPvp(), plugin); manager.registerEvents(new ShardLotto(), plugin); manager.registerEvents(new ChickenFeatherDrops(), plugin); - manager.registerEvents(new Sweethearts(), plugin); if (config.getBoolean("disable-ender-chests", false)) { manager.registerEvents(new DisableEnderChest(), plugin); @@ -71,6 +70,10 @@ public void onEnable() { if (config.getBoolean("prevent-spawner-mining", false)) { manager.registerEvents(new PreventSpawnerMining(), plugin); } + + if (config.getBoolean("enable-sweethearts", true)) { + manager.registerEvents(new Sweethearts(), plugin); + } } @Override diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java index 2d420101..b293d512 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Sweethearts.java @@ -158,7 +158,7 @@ public void onTotemUse(EntityResurrectEvent event) { public void awardAdvancement(Player donor) { Advancement a = Bukkit.getAdvancement(new NamespacedKey("platy", - "exploration/flower_health_transfer_death")); + "forestry/sweethearts_death")); if (a != null) { AdvancementProgress avp = donor.getAdvancementProgress(a); if (!avp.isDone()) { From 6c1688f83bee23f8edd3b81def67eee334bb10fb Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Tue, 20 Feb 2024 21:29:25 -0500 Subject: [PATCH 20/52] Consolidated Gamemode 4 license info for various Bits & Bobs Modules --- .../parallelutils/modules/beehiveinspector/README.md | 2 -- .../modules/{beehiveinspector => bitsandbobs}/LICENSE.md | 0 .../parallelutils/modules/bitsandbobs/README.md | 8 ++++++++ 3 files changed, 8 insertions(+), 2 deletions(-) delete mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/beehiveinspector/README.md rename modules/src/main/java/parallelmc/parallelutils/modules/{beehiveinspector => bitsandbobs}/LICENSE.md (100%) create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/README.md diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/beehiveinspector/README.md b/modules/src/main/java/parallelmc/parallelutils/modules/beehiveinspector/README.md deleted file mode 100644 index 0fb63c94..00000000 --- a/modules/src/main/java/parallelmc/parallelutils/modules/beehiveinspector/README.md +++ /dev/null @@ -1,2 +0,0 @@ -This is a plugin version of a datapack module made by Gamemode4. For licensing of this module, please refer to the included license file. -https://github.com/Gamemode4Dev/GM4_Datapacks \ No newline at end of file diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/beehiveinspector/LICENSE.md b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/LICENSE.md similarity index 100% rename from modules/src/main/java/parallelmc/parallelutils/modules/beehiveinspector/LICENSE.md rename to modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/LICENSE.md diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/README.md b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/README.md new file mode 100644 index 00000000..e6a04d8d --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/README.md @@ -0,0 +1,8 @@ +The following Bits & Bobs modules are plugin versions of datapack modules made by Gamemode 4: + +- Beehive Inspector +- Calling Bell +- SweetHearts + +For licensing of these modules, please refer to the included license file. +https://github.com/Gamemode4Dev/GM4_Datapacks \ No newline at end of file From f796e6e5f88780f4958c052e221330c21870eea5 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Mon, 8 Apr 2024 20:17:49 -0400 Subject: [PATCH 21/52] Add bandaid fix for enchantment errors --- .../parallelutils/modules/charms/util/EnchantGlow.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java b/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java index d8a8bb4e..6948034d 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java @@ -131,4 +131,10 @@ public static void registerFakeGlow(ParallelUtils puPlugin) { public @NotNull NamespacedKey getKey() { return key; } + + // TODO: get rid of this shit lol + @Override + public @NotNull String getTranslationKey() { + return null; + } } From 194634378eb7ab959743f28b17c1796562a7e755 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Mon, 15 Apr 2024 14:54:32 -0400 Subject: [PATCH 22/52] Add ziprails --- .../modules/bitsandbobs/BitsAndBobs.java | 5 +- .../bitsandbobs/minimodules/Ziprails.java | 104 ++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Ziprails.java diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java index 90029bbb..52bb3455 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java @@ -14,7 +14,6 @@ import parallelmc.parallelutils.modules.bitsandbobs.minimodules.togglepvp.TogglePvpCommand; import parallelmc.parallelutils.modules.bitsandbobs.minimodules.togglepvp.TogglePvpManager; -import java.net.URLClassLoader; import java.util.List; import java.util.logging.Level; @@ -70,6 +69,10 @@ public void onEnable() { if (config.getBoolean("prevent-spawner-mining", false)) { manager.registerEvents(new PreventSpawnerMining(), plugin); } + + if (config.getBoolean("enable-ziprails", true)) { + manager.registerEvents(new Ziprails(), plugin); + } } @Override diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Ziprails.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Ziprails.java new file mode 100644 index 00000000..127c5a30 --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/Ziprails.java @@ -0,0 +1,104 @@ +package parallelmc.parallelutils.modules.bitsandbobs.minimodules; + +import org.bukkit.*; +import org.bukkit.block.data.Attachable; +import org.bukkit.entity.Minecart; +import org.bukkit.event.Listener; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; +import org.bukkit.util.Vector; +import parallelmc.parallelutils.Constants; +import parallelmc.parallelutils.ParallelUtils; + +import java.util.logging.Level; + +public class Ziprails implements Listener { + + private static final double MINECART_DEFAULT_MAX_SPEED = 0.4d; + NamespacedKey key; + + public Ziprails() { + PluginManager manager = Bukkit.getPluginManager(); + Plugin plugin = manager.getPlugin(Constants.PLUGIN_NAME); + if (plugin == null) { + ParallelUtils.log(Level.SEVERE, "Unable to enable Ziprails. Plugin " + Constants.PLUGIN_NAME + + " does not exist!"); + return; + } + + key = new NamespacedKey(plugin, "isZipping"); + + plugin.getServer().getScheduler().runTaskTimer(plugin, this::checkForZiprails, 0L, 4L); + } + + public void checkForZiprails() { + for (World world : Bukkit.getWorlds()) { + // Should only be returning a list of loaded minecarts + for (Minecart minecart : world.getEntitiesByClass(Minecart.class)) { + // Check if minecart is moving + Vector cartVelocity = minecart.getVelocity(); + if (cartVelocity.isZero()) { + continue; + } + + Location cartLocation = minecart.getLocation(); + // Check if minecart is on ziprail + Location blockAboveCart = cartLocation.clone().add(0, 1, 0); + Material blockMaterial = world.getBlockAt(blockAboveCart).getType(); + if (blockMaterial == Material.TRIPWIRE || blockMaterial == Material.TRIPWIRE_HOOK) { + Attachable blockdata = (Attachable) world.getBlockAt(blockAboveCart).getBlockData(); + // Cases for when the block above the minecart is an attachable ziprail + if (blockdata.isAttached()) { + // If the minecart isn't zipping, link it to the ziprail + if (!isZipping(minecart)) { + linkMinecart(minecart, cartLocation); + } + setMaxXZVelocity(minecart, cartVelocity); + } + } else { + if (isZipping(minecart)) { + unlinkMinecart(minecart); + } + } + } + } + } + + public boolean isZipping(Minecart minecart) { + return minecart.getPersistentDataContainer().has(key, PersistentDataType.INTEGER); + } + + public void linkMinecart(Minecart minecart, Location cartLocation) { + minecart.setGravity(false); + + // Makes sure that all ziprail cars are at the same y level + Location newCartLocation = cartLocation.clone(); + newCartLocation.setY(Math.floor(cartLocation.getY() + 0.36250001192093)); // this is the y value GM4 uses lol + minecart.teleport(newCartLocation); + + minecart.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, 1); + minecart.getWorld().playSound(cartLocation, Sound.ENTITY_ITEM_FRAME_PLACE, SoundCategory.NEUTRAL, 1, 1); + } + + public void unlinkMinecart(Minecart minecart) { + minecart.setGravity(true); + minecart.getPersistentDataContainer().remove(key); + } + + public void setMaxXZVelocity(Minecart minecart, Vector cartVelocity) { + // A normalized vector is used here to make sure the cart remains going the right way along the x or z axis + Vector normalized = cartVelocity.normalize(); + + if (cartVelocity.getX() != 0) { + cartVelocity.setX(normalized.getX() * MINECART_DEFAULT_MAX_SPEED); + cartVelocity.setZ(0); + } + if (cartVelocity.getZ() != 0) { + cartVelocity.setZ(normalized.getZ() * MINECART_DEFAULT_MAX_SPEED); + cartVelocity.setX(0); + } + + minecart.setVelocity(cartVelocity); + } +} \ No newline at end of file From 1a5947c27c30fad4bdca649f4b522a708709047a Mon Sep 17 00:00:00 2001 From: Ethan Date: Thu, 18 Apr 2024 00:22:50 -0400 Subject: [PATCH 23/52] early proof of concept --- build.gradle | 2 +- .../paralleltutorial/ParallelTutorial.java | 222 +++++++++--------- .../commands/ParallelReloadTutorials.java | 2 +- 3 files changed, 119 insertions(+), 107 deletions(-) diff --git a/build.gradle b/build.gradle index 3909ad5a..546477f7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ plugins { id 'java' id 'com.github.johnrengelman.shadow' version '8.1.1' - id("io.papermc.paperweight.userdev") version "1.5.5" + id("io.papermc.paperweight.userdev") version "1.5.12" id "xyz.jpenilla.run-paper" version "2.1.0" id 'net.minecrell.plugin-yml.bukkit' version '0.6.0' } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/ParallelTutorial.java b/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/ParallelTutorial.java index 4557de8e..f65137ea 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/ParallelTutorial.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/ParallelTutorial.java @@ -18,6 +18,7 @@ import org.bukkit.scheduler.BukkitTask; import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; +import org.checkerframework.checker.units.qual.A; import org.jetbrains.annotations.NotNull; import parallelmc.parallelutils.Constants; import parallelmc.parallelutils.ParallelClassLoader; @@ -51,7 +52,7 @@ public class ParallelTutorial extends ParallelModule { // mostly for use in server crashes/shutdown public HashMap runningTutorials = new HashMap<>(); - public HashMap armorStands = new HashMap<>(); + public HashMap displayEntities = new HashMap<>(); public HashMap startPoints = new HashMap<>(); @@ -243,11 +244,11 @@ public void run() { if (debug) ParallelChat.sendParallelMessageTo(player, "Debug mode enabled! Please open console to view debug output."); startPoints.put(player, player.getLocation()); loop = new BukkitRunnable() { - ArmorStand stand; + Display display; @Override public void run() { - if (stand != null && player.getLocation().distanceSquared(stand.getLocation()) > 256) { - Bukkit.getScheduler().runTask(puPlugin, () -> player.teleport(stand.getLocation())); + if (display != null && player.getLocation().distanceSquared(display.getLocation()) > 256) { + Bukkit.getScheduler().runTask(puPlugin, () -> player.teleport(display.getLocation())); } // only run the next instruction if the current one is finished if (instructionFinished) { @@ -257,25 +258,69 @@ public void run() { case "START" -> { Bukkit.getScheduler().runTask(puPlugin, () -> { Location start = new Location(world, Double.parseDouble(i.args()[0]), Double.parseDouble(i.args()[1]), Double.parseDouble(i.args()[2])); - stand = (ArmorStand)world.spawnEntity(start, EntityType.ARMOR_STAND, CreatureSpawnEvent.SpawnReason.COMMAND); - stand.setGravity(false); - stand.setVisible(false); - stand.setBasePlate(false); - stand.setInvulnerable(true); - stand.setHeadPose(EulerAngle.ZERO); + display = (Display)world.spawnEntity(start, EntityType.ITEM_DISPLAY, CreatureSpawnEvent.SpawnReason.COMMAND); + display.setRotation(0, 0); player.setGameMode(GameMode.SPECTATOR); player.setFlySpeed(0F); - // force player to spectate the armor stand + // force player to spectate the display // the player's actual model will be stuck back at the start - forceSpectate(player, stand.getEntityId()); - armorStands.put(player, stand); + forceSpectate(player, display.getEntityId()); + displayEntities.put(player, display); instructionFinished = true; }); } case "MOVE" -> { - final Location a = stand.getLocation(); + final Location a = display.getLocation(); final Location b = new Location(world, Double.parseDouble(i.args()[0]), Double.parseDouble(i.args()[1]), Double.parseDouble(i.args()[2])); - final float duration = Float.parseFloat(i.args()[3]) * 20f; + final int secs = Integer.parseInt(i.args()[3]); + final ArrayList nodes = new ArrayList<>(); + for (float l = 0; l < secs; l += 1f) { + float t = l / secs; + Location point = new Location(world, + a.getX() + (b.getX() - a.getX()) * t, + a.getY() + (b.getY() - a.getY()) * t, + a.getZ() + (b.getZ() - a.getZ()) * t); + lookAt(point, lookAt); + nodes.add(point); + } + lookAt(b, lookAt); + nodes.add(b); + + display.teleport(nodes.get(0)); + display.setTeleportDuration(20); + new BukkitRunnable() { + int index = 1; + @Override + public void run() { + display.teleport(nodes.get(index)); + index++; + if (index >= nodes.size()) { + display.setTeleportDuration(0); + instructionFinished = true; + this.cancel(); + } + } + }.runTaskTimer(puPlugin, 1L, 19L); + /*final float duration = Float.parseFloat(i.args()[3]) * 20f; + // if looking at a block, calculate the starting and end rotations and lerp between the two + float yA = 0f, yB = 0f, pA = 0f, pB = 0f; + if (lookAt != null) { + if (isBlock) { + Vector start = lookAt(a, lookAt); + Vector end = lookAt(b, lookAt); + yA = (float)start.getX(); + yB = (float)end.getX(); + pA = (float)start.getY(); + pB = (float)end.getY(); + } + } + display.set + + // make the compiler happy + float yawA = yA; + float yawB = yB; + float pitchA = pA; + float pitchB = pB; new BukkitRunnable() { float steps = 0f; @Override @@ -283,17 +328,15 @@ public void run() { if (steps == duration) { if (lookAt != null) { if (isBlock) { - Vector look = lookAt(stand, lookAt); - if (debug) ParallelUtils.log(Level.WARNING, "Calculated look vector: " + look.getX() + " " + look.getY()); - b.setYaw((float) look.getX()); - b.setPitch((float) look.getY()); + b.setYaw(yawB); + b.setPitch(pitchA); } else { b.setYaw((float) lookAt.getX()); b.setPitch((float) lookAt.getY()); } } - stand.teleport(b); + display.teleport(b); instructionFinished = true; this.cancel(); } @@ -309,21 +352,19 @@ else if (t > 1F) a.getZ() + (b.getZ() - a.getZ()) * t); if (lookAt != null) { if (isBlock) { - Vector look = lookAt(stand, lookAt); - if (debug) ParallelUtils.log(Level.WARNING, "Calculated look vector: " + look.getX() + " " + look.getY()); - point.setYaw((float) look.getX()); - point.setPitch((float)look.getY()); + point.setYaw(rotLerp(yawA, yawB, t)); + point.setPitch(rotLerp(pitchA, pitchB, t)); } else { point.setYaw((float) lookAt.getX()); point.setPitch((float) lookAt.getY()); } } - stand.teleport(point); + display.teleport(point); steps++; } } - }.runTaskTimer(puPlugin, 1L, 1L); + }.runTaskTimer(puPlugin, 1L, 1L); */ } case "TELEPORT" -> { final Location newPoint = new Location(world, Double.parseDouble(i.args()[0]), Double.parseDouble(i.args()[1]), Double.parseDouble(i.args()[2])); @@ -334,21 +375,18 @@ public void run() { if(player.teleport(newPoint)) { if (lookAt != null) { if (isBlock) { - Vector look = lookAt(stand, lookAt); - if (debug) ParallelUtils.log(Level.WARNING, "Calculated look vector: " + look.getX() + " " + look.getY()); - newPoint.setYaw((float) look.getX()); - newPoint.setPitch((float) look.getY()); + lookAt(newPoint, lookAt); } else { newPoint.setYaw((float) lookAt.getX()); newPoint.setPitch((float) lookAt.getY()); } } - if (stand.teleport(newPoint)) { - forceSpectate(player, stand.getEntityId()); + if (display.teleport(newPoint)) { + forceSpectate(player, display.getEntityId()); if (debug) { - ParallelUtils.log(Level.WARNING, "Armor Stand teleported!"); - ParallelUtils.log(Level.WARNING, "Armor Stand looking at: " + stand.getLocation().getYaw() + " " + stand.getLocation().getPitch()); + ParallelUtils.log(Level.WARNING, "Display teleported!"); + ParallelUtils.log(Level.WARNING, "Display looking at: " + display.getLocation().getYaw() + " " + display.getLocation().getPitch()); ParallelUtils.log(Level.WARNING, "Should be looking at: " + lookAt.getX() + " " + lookAt.getY()); } instructionFinished = true; @@ -403,7 +441,7 @@ public void run() { public void endTutorialFor(Player player, boolean debug) { Location endPoint = startPoints.get(player); - ArmorStand stand = armorStands.get(player); + Display display = displayEntities.get(player); if (debug) ParallelUtils.log(Level.WARNING, "Ending tutorial..."); new BukkitRunnable() { @Override @@ -414,11 +452,11 @@ public void run() { if (debug) ParallelUtils.log(Level.WARNING, "Player teleported!"); // making the player spectate themselves brings them back to the start forceSpectate(player, player.getEntityId()); - if (debug) ParallelUtils.log(Level.WARNING, "armorStands HashMap " + (stand != null ? "DOES" : "DOES NOT") + " contain the player before deletion."); - if (stand != null) { - if (debug) ParallelUtils.log(Level.WARNING, "Armor stand marked for removal"); - stand.remove(); - armorStands.remove(player); + if (debug) ParallelUtils.log(Level.WARNING, "displayEntities HashMap " + (display != null ? "DOES" : "DOES NOT") + " contain the player before deletion."); + if (display != null) { + if (debug) ParallelUtils.log(Level.WARNING, "Display marked for removal"); + display.remove(); + displayEntities.remove(player); } player.setGameMode(GameMode.SURVIVAL); player.setFlySpeed(0.1F); @@ -429,14 +467,14 @@ public void run() { } }.runTaskTimer(puPlugin, 0L, 2L); if (debug) { - ParallelUtils.log(Level.WARNING, "Checking status of armor stand in a few ticks..."); + ParallelUtils.log(Level.WARNING, "Checking status of display in a few ticks..."); new BukkitRunnable() { @Override public void run() { - if (stand.isDead() && !stand.isValid()) - ParallelUtils.log(Level.WARNING, "Armor Stand removed successfully!"); + if (display.isDead() && !display.isValid()) + ParallelUtils.log(Level.WARNING, "Display removed successfully!"); else - ParallelUtils.log(Level.WARNING, "Armor Stand was NOT removed!"); + ParallelUtils.log(Level.WARNING, "Display was NOT removed!"); } }.runTaskLater(puPlugin, 10L); } @@ -445,16 +483,16 @@ public void run() { /* Since we can't start runnables during shutdown we have to do this This may still result in Player moved too quickly errors, testing is needed - This will also be unable to check if the armor stand is truly despawned + This will also be unable to check if the display is truly despawned */ public void handleShutdown(Player player) { Location endPoint = startPoints.get(player); - ArmorStand stand = armorStands.get(player); + Display display = displayEntities.get(player); player.teleport(endPoint); forceSpectate(player, player.getEntityId()); - if (stand != null) { - stand.remove(); - armorStands.remove(player); + if (display != null) { + display.remove(); + displayEntities.remove(player); } player.setGameMode(GameMode.SURVIVAL); player.setFlySpeed(0.1F); @@ -464,23 +502,23 @@ public void handleShutdown(Player player) { public void handleDisconnectedPlayer(Player player, boolean debug) { if (debug) ParallelUtils.log(Level.WARNING, "Ending tutorial..."); - ArmorStand stand = armorStands.get(player); - if (debug) ParallelUtils.log(Level.WARNING, "armorStands HashMap " + (stand != null ? "DOES" : "DOES NOT") + " contain the player before deletion."); - if (stand != null) { - if (debug) ParallelUtils.log(Level.WARNING, "Armor stand marked for removal"); - stand.remove(); - armorStands.remove(player); + Display display = displayEntities.get(player); + if (debug) ParallelUtils.log(Level.WARNING, "displayEntities HashMap " + (display != null ? "DOES" : "DOES NOT") + " contain the player before deletion."); + if (display != null) { + if (debug) ParallelUtils.log(Level.WARNING, "Display stand marked for removal"); + display.remove(); + displayEntities.remove(player); } runningTutorials.remove(player); if (debug) { - ParallelUtils.log(Level.WARNING, "Checking status of armor stand in a few ticks..."); + ParallelUtils.log(Level.WARNING, "Checking status of display stand in a few ticks..."); new BukkitRunnable() { @Override public void run() { - if (stand.isDead() && !stand.isValid()) - ParallelUtils.log(Level.WARNING, "Armor Stand removed successfully!"); + if (display.isDead() && !display.isValid()) + ParallelUtils.log(Level.WARNING, "Display Stand removed successfully!"); else - ParallelUtils.log(Level.WARNING, "Armor Stand was NOT removed!"); + ParallelUtils.log(Level.WARNING, "Display Stand was NOT removed!"); } }.runTaskLater(puPlugin, 10L); } @@ -513,58 +551,32 @@ private void forceSpectate(Player player, int entityId) { } } - private Vector lookAt(ArmorStand stand, Vector block) { - Vector eyes = stand.getEyeLocation().toVector(); - double d = block.getX() - eyes.getX(); - double e = block.getY() - eyes.getY(); - double f = block.getZ() - eyes.getZ(); + private void lookAt(Location loc, Vector block) { + double d = block.getX() - loc.getX(); + double e = block.getY() - loc.getY(); + double f = block.getZ() - loc.getZ(); double g = Math.sqrt(d * d + f * f); - return new Vector(Mth.wrapDegrees((float)(Mth.atan2(f, d) * 57.2957763671875) - 90.0F), Mth.wrapDegrees((float)(-(Mth.atan2(e, g) * 57.2957763671875))), 0); + Vector result = new Vector(Mth.wrapDegrees((float)(Mth.atan2(f, d) * 57.2957763671875) - 90.0F), Mth.wrapDegrees((float)(-(Mth.atan2(e, g) * 57.2957763671875))), 0); + loc.setYaw((float)result.getX()); + loc.setPitch((float)result.getY()); } - private Vector faceBlock(ArmorStand stand, Vector block) { - Vector eyes = stand.getEyeLocation().toVector(); - Vector blockPos = new Vector(block.getX(), block.getY(), block.getZ()); - double diffX = blockPos.getX() - eyes.getX(); - double diffY = blockPos.getY() - eyes.getY(); - double diffZ = blockPos.getZ() - eyes.getZ(); - - double diffXZ = Math.sqrt(diffX * diffX + diffZ * diffZ); - - float yaw = (float)Math.toDegrees(Math.atan2(diffZ, diffX)) - 90F; - float pitch = (float)-Math.toDegrees(Math.atan2(diffY, diffXZ)); - float prevYaw = stand.getLocation().getYaw(); - float prevPitch = stand.getLocation().getPitch(); - // use a rotational lerp to prevent snapping - return new Vector(rotLerp(prevYaw, yaw, 30f), rotLerp(prevPitch, pitch, 30f), 0); - } - private float rotLerp(float pSourceAngle, float pTargetAngle, float pMaximumChange) + private float rotLerp(float source, float target, float t) { - float f = Mth.wrapDegrees(pTargetAngle - pSourceAngle); - - if (f > pMaximumChange) - { - f = pMaximumChange; - } - - if (f < -pMaximumChange) - { - f = -pMaximumChange; - } - - float f1 = pSourceAngle + f; - - if (f1 < 0.0F) - { - f1 += 360.0F; + source += 180f; + target += 180f; + float diff = Math.abs(target - source); + if (diff > 180f) { + if (target > source) + source += 360f; + else + target += 360f; } - else if (f1 > 360.0F) - { - f1 -= 360.0F; - } - - return f1; + float interp = source + (target - source) * t; + if (interp >= 0f && interp <= 360f) + return interp - 180f; + return interp % 360f - 180f; } } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/commands/ParallelReloadTutorials.java b/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/commands/ParallelReloadTutorials.java index 8920a219..6e9f1fc2 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/commands/ParallelReloadTutorials.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/commands/ParallelReloadTutorials.java @@ -15,7 +15,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command return true; } } - if (ParallelTutorial.get().runningTutorials.size() > 0) { + if (!ParallelTutorial.get().runningTutorials.isEmpty()) { commandSender.sendMessage("Cannot reload tutorials while there are players in a tutorial!"); return true; } From dd8ac69bb795f7976ca0e5bbb52203867a671795 Mon Sep 17 00:00:00 2001 From: Ethan Date: Fri, 19 Apr 2024 00:23:42 -0400 Subject: [PATCH 24/52] fix last point not getting teleported to --- .../paralleltutorial/ParallelTutorial.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/ParallelTutorial.java b/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/ParallelTutorial.java index f65137ea..7543aab8 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/ParallelTutorial.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/ParallelTutorial.java @@ -272,10 +272,10 @@ public void run() { case "MOVE" -> { final Location a = display.getLocation(); final Location b = new Location(world, Double.parseDouble(i.args()[0]), Double.parseDouble(i.args()[1]), Double.parseDouble(i.args()[2])); - final int secs = Integer.parseInt(i.args()[3]); + final int steps = Integer.parseInt(i.args()[3]); final ArrayList nodes = new ArrayList<>(); - for (float l = 0; l < secs; l += 1f) { - float t = l / secs; + for (float l = 0; l < steps; l += 1f) { + float t = l / steps; Location point = new Location(world, a.getX() + (b.getX() - a.getX()) * t, a.getY() + (b.getY() - a.getY()) * t, @@ -285,20 +285,24 @@ public void run() { } lookAt(b, lookAt); nodes.add(b); + ParallelUtils.log(Level.WARNING, "" + nodes.size()); display.teleport(nodes.get(0)); - display.setTeleportDuration(20); + ParallelUtils.log(Level.WARNING, "Teleporting to " + nodes.get(0)); + display.setTeleportDuration(19); new BukkitRunnable() { int index = 1; @Override public void run() { - display.teleport(nodes.get(index)); - index++; if (index >= nodes.size()) { display.setTeleportDuration(0); instructionFinished = true; this.cancel(); + return; } + display.teleport(nodes.get(index)); + ParallelUtils.log(Level.WARNING, "Teleporting to " + nodes.get(index)); + index++; } }.runTaskTimer(puPlugin, 1L, 19L); /*final float duration = Float.parseFloat(i.args()[3]) * 20f; From 7a9e3cb699c214f29d3d9e4a2e70fd0025645ddc Mon Sep 17 00:00:00 2001 From: Ethan Date: Fri, 19 Apr 2024 18:47:46 -0400 Subject: [PATCH 25/52] readd ROTATE functionality --- .../paralleltutorial/ParallelTutorial.java | 84 ++++--------------- 1 file changed, 15 insertions(+), 69 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/ParallelTutorial.java b/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/ParallelTutorial.java index 7543aab8..e4be51df 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/ParallelTutorial.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/paralleltutorial/ParallelTutorial.java @@ -280,15 +280,25 @@ public void run() { a.getX() + (b.getX() - a.getX()) * t, a.getY() + (b.getY() - a.getY()) * t, a.getZ() + (b.getZ() - a.getZ()) * t); - lookAt(point, lookAt); + if (isBlock) { + lookAt(point, lookAt); + } + else { + point.setYaw((float)lookAt.getX()); + point.setPitch((float)lookAt.getY()); + } nodes.add(point); } - lookAt(b, lookAt); + if (isBlock) + lookAt(b, lookAt); + else { + b.setYaw((float)lookAt.getX()); + b.setPitch((float)lookAt.getY()); + } nodes.add(b); - ParallelUtils.log(Level.WARNING, "" + nodes.size()); display.teleport(nodes.get(0)); - ParallelUtils.log(Level.WARNING, "Teleporting to " + nodes.get(0)); + if (debug) ParallelUtils.log(Level.WARNING, "Teleporting to " + nodes.get(0)); display.setTeleportDuration(19); new BukkitRunnable() { int index = 1; @@ -301,74 +311,10 @@ public void run() { return; } display.teleport(nodes.get(index)); - ParallelUtils.log(Level.WARNING, "Teleporting to " + nodes.get(index)); + if (debug) ParallelUtils.log(Level.WARNING, "Teleporting to " + nodes.get(index)); index++; } }.runTaskTimer(puPlugin, 1L, 19L); - /*final float duration = Float.parseFloat(i.args()[3]) * 20f; - // if looking at a block, calculate the starting and end rotations and lerp between the two - float yA = 0f, yB = 0f, pA = 0f, pB = 0f; - if (lookAt != null) { - if (isBlock) { - Vector start = lookAt(a, lookAt); - Vector end = lookAt(b, lookAt); - yA = (float)start.getX(); - yB = (float)end.getX(); - pA = (float)start.getY(); - pB = (float)end.getY(); - } - } - display.set - - // make the compiler happy - float yawA = yA; - float yawB = yB; - float pitchA = pA; - float pitchB = pB; - new BukkitRunnable() { - float steps = 0f; - @Override - public void run() { - if (steps == duration) { - if (lookAt != null) { - if (isBlock) { - b.setYaw(yawB); - b.setPitch(pitchA); - } - else { - b.setYaw((float) lookAt.getX()); - b.setPitch((float) lookAt.getY()); - } - } - display.teleport(b); - instructionFinished = true; - this.cancel(); - } - else { - float t = steps / duration; - if (t < 0f) - t = 0f; - else if (t > 1F) - t = 1f; - Location point = new Location(world, - a.getX() + (b.getX() - a.getX()) * t, - a.getY() + (b.getY() - a.getY()) * t, - a.getZ() + (b.getZ() - a.getZ()) * t); - if (lookAt != null) { - if (isBlock) { - point.setYaw(rotLerp(yawA, yawB, t)); - point.setPitch(rotLerp(pitchA, pitchB, t)); - } - else { - point.setYaw((float) lookAt.getX()); - point.setPitch((float) lookAt.getY()); - } - } - display.teleport(point); - steps++; - } - } - }.runTaskTimer(puPlugin, 1L, 1L); */ } case "TELEPORT" -> { final Location newPoint = new Location(world, Double.parseDouble(i.args()[0]), Double.parseDouble(i.args()[1]), Double.parseDouble(i.args()[2])); From e31ede34ade306e487e6b7125417a3e3e53628e7 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Sat, 4 May 2024 01:00:38 -0400 Subject: [PATCH 26/52] Initial dependency version bumps --- api/build.gradle | 8 ++++---- build.gradle | 12 ++++++------ modules/build.gradle | 10 +++++----- settings.gradle | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index d31fb6f9..9fb19794 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -23,12 +23,12 @@ dependencies { implementation 'org.jetbrains:annotations:24.0.1' testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2' implementation 'net.dv8tion:JDA:5.0.0-beta.20' - compileOnly 'me.clip:placeholderapi:2.11.3' + compileOnly 'me.clip:placeholderapi:2.11.5' compileOnly fileTree('libs') { include '*.jar' } - compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.8' + compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.9' implementation 'com.mysql:mysql-connector-j:8.3.0' - compileOnly 'com.comphenix.protocol:ProtocolLib:5.0.0' - compileOnly 'dev.esophose:playerparticles:8.4' + compileOnly 'com.comphenix.protocol:ProtocolLib:5.2.0' + compileOnly 'dev.esophose:playerparticles:8.5' implementation 'org.reflections:reflections:0.10.2' } diff --git a/build.gradle b/build.gradle index 546477f7..54a6df4c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,13 @@ plugins { id 'java' id 'com.github.johnrengelman.shadow' version '8.1.1' - id("io.papermc.paperweight.userdev") version "1.5.12" + id("io.papermc.paperweight.userdev") version "1.6.3" id "xyz.jpenilla.run-paper" version "2.1.0" id 'net.minecrell.plugin-yml.bukkit' version '0.6.0' } dependencies { - paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.4-R0.1-SNAPSHOT") + paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.6-R0.1-SNAPSHOT") } @@ -26,7 +26,7 @@ allprojects { repositories { mavenCentral() - maven { url = "https://papermc.io/repo/repository/maven-public/" } + maven { url = "https://repo.papermc.io/repository/maven-public/" } maven { url = 'https://oss.sonatype.org/content/repositories/snapshots/' } maven { url = "https://maven.enginehub.org/repo/" } maven { url = 'https://repo.md-5.net/content/groups/public/' } @@ -40,11 +40,11 @@ allprojects { } dependencies { - paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.4-R0.1-SNAPSHOT") + paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.6-R0.1-SNAPSHOT") - compileOnly "io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT" + compileOnly "io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT" compileOnly 'net.luckperms:api:5.4' - compileOnly 'dev.esophose:playerparticles:8.4' + compileOnly 'dev.esophose:playerparticles:8.5' compileOnly "com.github.MilkBowl:VaultAPI:1.7" } } \ No newline at end of file diff --git a/modules/build.gradle b/modules/build.gradle index 33bd4b4c..8ae2158b 100644 --- a/modules/build.gradle +++ b/modules/build.gradle @@ -20,13 +20,13 @@ dependencies { compileOnly 'org.jetbrains:annotations:24.0.1' testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2' compileOnly 'net.dv8tion:JDA:5.0.0-beta.20' - compileOnly 'me.clip:placeholderapi:2.11.3' + compileOnly 'me.clip:placeholderapi:2.11.5' compileOnly fileTree('libs') { include '*.jar' } - compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.8' + compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.9' compileOnly 'com.mysql:mysql-connector-j:8.3.0' - compileOnly 'com.comphenix.protocol:ProtocolLib:5.0.0' - compileOnly 'dev.esophose:playerparticles:8.4' - compileOnly "io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT" + compileOnly 'com.comphenix.protocol:ProtocolLib:5.2.0' + compileOnly 'dev.esophose:playerparticles:8.5' + compileOnly "io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT" } def names = [] diff --git a/settings.gradle b/settings.gradle index 59907575..7bb50d64 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,7 +1,7 @@ pluginManagement { repositories { gradlePluginPortal() - maven { url = "https://papermc.io/repo/repository/maven-public/" } + maven { url = "https://repo.papermc.io/repository/maven-public/" } } } From 94d4229ba5da0a421217082ed2a14fdd5f4381a5 Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Sat, 4 May 2024 10:45:57 -0400 Subject: [PATCH 27/52] Update to 1.20.6 --- api/build.gradle | 17 ++++++++++++----- .../parallelmc/parallelutils/Constants.java | 2 +- .../parallelmc/parallelutils/ParallelUtils.java | 4 ++-- .../parallelutils/commands/Commands.java | 6 +++--- build.gradle | 17 ++++++++--------- gradle/wrapper/gradle-wrapper.properties | 2 +- modules/build.gradle | 4 ++-- .../minimodules/KeepSpecialItems.java | 2 +- .../bitsandbobs/minimodules/SpecialItems.java | 2 +- .../handlers/impl/CharmParticleHandler.java | 2 +- .../PlayerJoinContainerListenerOverwrite.java | 2 +- .../parallelmc/parallelutils/modules/custommobs | 2 +- .../parallelutils/modules/parallelitems | 2 +- 13 files changed, 35 insertions(+), 29 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index 9fb19794..a394754b 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -7,19 +7,26 @@ plugins { group = 'org.parallelmc' -version = '4.3.0' +version = '4.4.0' description = 'A set of utilities and features for use on the Parallel Minecraft server' java { - toolchain.languageVersion.set(JavaLanguageVersion.of(17)) + toolchain.languageVersion.set(JavaLanguageVersion.of(21)) } compileJava.options.encoding = "UTF-8" compileTestJava.options.encoding = "UTF-8" processResources.filteringCharset = "UTF-8" +repositories { + mavenCentral() + maven { url = "https://repo.papermc.io/repository/maven-public/" } +} dependencies { + //compileOnly 'io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT' + paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.6-R0.1-SNAPSHOT") + implementation 'org.jetbrains:annotations:24.0.1' testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2' implementation 'net.dv8tion:JDA:5.0.0-beta.20' @@ -27,7 +34,7 @@ dependencies { compileOnly fileTree('libs') { include '*.jar' } compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.9' implementation 'com.mysql:mysql-connector-j:8.3.0' - compileOnly 'com.comphenix.protocol:ProtocolLib:5.2.0' + compileOnly 'com.comphenix.protocol:ProtocolLib:5.1.0' compileOnly 'dev.esophose:playerparticles:8.5' implementation 'org.reflections:reflections:0.10.2' } @@ -49,7 +56,7 @@ tasks { compileJava { // Set the release flag. This configures what version bytecode the compiler will emit, as well as what JDK APIs are usable. // See https://openjdk.java.net/jeps/247 for more information. - options.release.set(17) + options.release.set(21) } shadowJar { @@ -67,7 +74,7 @@ bukkit { main = 'parallelmc.parallelutils.ParallelUtils' - apiVersion = '1.20' + apiVersion = '1.20.5' depend = ['PlaceholderAPI', 'ProtocolLib'] softDepend = ['Multiverse-Core', 'FractalForest', 'WorldGuard', 'VoteParty', 'PlayerParticles', 'ProNouns'] diff --git a/api/src/main/java/parallelmc/parallelutils/Constants.java b/api/src/main/java/parallelmc/parallelutils/Constants.java index c3898b97..ec72b3c4 100644 --- a/api/src/main/java/parallelmc/parallelutils/Constants.java +++ b/api/src/main/java/parallelmc/parallelutils/Constants.java @@ -4,7 +4,7 @@ public class Constants { - public static final Version VERSION = new Version(4, 2, 2); + public static final Version VERSION = new Version(4, 4, 0); public static final String PLUGIN_NAME = "ParallelUtils"; public static final String DEFAULT_WORLD = "world2"; diff --git a/api/src/main/java/parallelmc/parallelutils/ParallelUtils.java b/api/src/main/java/parallelmc/parallelutils/ParallelUtils.java index 774304f5..0c888d3b 100644 --- a/api/src/main/java/parallelmc/parallelutils/ParallelUtils.java +++ b/api/src/main/java/parallelmc/parallelutils/ParallelUtils.java @@ -77,8 +77,8 @@ public void onEnable() { config = this.getConfig(); config.options().copyDefaults(true); - config.options().parseComments(true); - config.options().setHeader(List.of(HEADER)); + //config.options().parseComments(true); + config.options().header(HEADER); // Read config this.saveDefaultConfig(); diff --git a/api/src/main/java/parallelmc/parallelutils/commands/Commands.java b/api/src/main/java/parallelmc/parallelutils/commands/Commands.java index bdadec61..0ac3d7fc 100644 --- a/api/src/main/java/parallelmc/parallelutils/commands/Commands.java +++ b/api/src/main/java/parallelmc/parallelutils/commands/Commands.java @@ -5,7 +5,7 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.command.*; -import org.bukkit.craftbukkit.v1_20_R3.command.ServerCommandSender; +import org.bukkit.craftbukkit.command.ServerCommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -220,9 +220,9 @@ public static Location convertLocation(CommandSender sender, String sx, String s */ public static List getTargetedBlockTabHelper(@NotNull Player player, int depth) { ArrayList list = new ArrayList<>(); - Block targetedBlock = player.getTargetBlockExact(5); + Block targetedBlock = player.getTargetBlock(null,5); - if (targetedBlock != null && targetedBlock.isSolid()) { + if (targetedBlock != null && !targetedBlock.isEmpty()) { // Autofill targeted coords if (depth >= 1) { list.add(String.format("%d", targetedBlock.getZ())); diff --git a/build.gradle b/build.gradle index 54a6df4c..74e896c4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,17 @@ plugins { id 'java' id 'com.github.johnrengelman.shadow' version '8.1.1' - id("io.papermc.paperweight.userdev") version "1.6.3" - id "xyz.jpenilla.run-paper" version "2.1.0" + id "io.papermc.paperweight.userdev" version "1.7.0" + id "xyz.jpenilla.run-paper" version "2.3.0" id 'net.minecrell.plugin-yml.bukkit' version '0.6.0' } -dependencies { - paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.6-R0.1-SNAPSHOT") +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(21)) } - -java { - toolchain.languageVersion.set(JavaLanguageVersion.of(17)) +dependencies { + paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.6-R0.1-SNAPSHOT") } compileJava.options.encoding = "UTF-8" @@ -36,13 +35,13 @@ allprojects { maven { url = 'https://repo.codemc.org/repository/maven-public/' } maven { url = 'https://repo.rosewooddev.io/repository/public/' } maven { url = 'https://jitpack.io' } - } dependencies { paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.6-R0.1-SNAPSHOT") + //paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT") - compileOnly "io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT" + //compileOnly "io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT" compileOnly 'net.luckperms:api:5.4' compileOnly 'dev.esophose:playerparticles:8.5' compileOnly "com.github.MilkBowl:VaultAPI:1.7" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fae08049..48c0a02c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/modules/build.gradle b/modules/build.gradle index 8ae2158b..d509230d 100644 --- a/modules/build.gradle +++ b/modules/build.gradle @@ -6,7 +6,7 @@ group = 'org.parallelmc' java { - toolchain.languageVersion.set(JavaLanguageVersion.of(17)) + toolchain.languageVersion.set(JavaLanguageVersion.of(21)) } compileJava.options.encoding = "UTF-8" @@ -24,7 +24,7 @@ dependencies { compileOnly fileTree('libs') { include '*.jar' } compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.9' compileOnly 'com.mysql:mysql-connector-j:8.3.0' - compileOnly 'com.comphenix.protocol:ProtocolLib:5.2.0' + compileOnly 'com.comphenix.protocol:ProtocolLib:5.1.0' compileOnly 'dev.esophose:playerparticles:8.5' compileOnly "io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT" } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/KeepSpecialItems.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/KeepSpecialItems.java index 595aa411..6c865d88 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/KeepSpecialItems.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/KeepSpecialItems.java @@ -2,7 +2,7 @@ import net.minecraft.nbt.CompoundTag; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java index 3b0a3d62..b07bec28 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java @@ -4,7 +4,7 @@ import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java b/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java index 712d6324..1b16469d 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java @@ -4,7 +4,7 @@ import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData; +import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/charms/listeners/PlayerJoinContainerListenerOverwrite.java b/modules/src/main/java/parallelmc/parallelutils/modules/charms/listeners/PlayerJoinContainerListenerOverwrite.java index 26da9cec..7aa9e018 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/charms/listeners/PlayerJoinContainerListenerOverwrite.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/charms/listeners/PlayerJoinContainerListenerOverwrite.java @@ -5,7 +5,7 @@ import net.minecraft.world.inventory.*; import net.minecraft.world.item.ItemStack; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/custommobs b/modules/src/main/java/parallelmc/parallelutils/modules/custommobs index cc9233ba..79b286ff 160000 --- a/modules/src/main/java/parallelmc/parallelutils/modules/custommobs +++ b/modules/src/main/java/parallelmc/parallelutils/modules/custommobs @@ -1 +1 @@ -Subproject commit cc9233ba51ea098fd5ae6093133bc8ed8f615f24 +Subproject commit 79b286ff835e62eb337d4e99a610d6bc88f85d7c diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems b/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems index b339f1d5..1bd9508c 160000 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems @@ -1 +1 @@ -Subproject commit b339f1d5785d048866b132284fb8f66aed5cb61f +Subproject commit 1bd9508cf4321d55b43008a4643dd51cb6beaa12 From 9ef55260f214ad6f06ef8b6a696b429f4ee4a4c0 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Sat, 4 May 2024 18:53:20 -0400 Subject: [PATCH 28/52] Fix old 1.13 Bukkit library getting in the way --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 74e896c4..72ea511d 100644 --- a/build.gradle +++ b/build.gradle @@ -44,6 +44,6 @@ allprojects { //compileOnly "io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT" compileOnly 'net.luckperms:api:5.4' compileOnly 'dev.esophose:playerparticles:8.5' - compileOnly "com.github.MilkBowl:VaultAPI:1.7" + compileOnly "com.github.MilkBowl:VaultAPI:1.7.1" } } \ No newline at end of file From 40ebcbb08ca15598f7a556a93e9f3e51ed8d5d8f Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Sun, 5 May 2024 00:38:02 -0400 Subject: [PATCH 29/52] Enum changes --- .../modules/bitsandbobs/minimodules/CallingBell.java | 4 ++-- .../modules/charms/handlers/impl/CharmParticleHandler.java | 4 ++-- .../modules/sunkentreasure/events/TreasureChecker.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/CallingBell.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/CallingBell.java index 442e8167..4c50f0f6 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/CallingBell.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/CallingBell.java @@ -90,9 +90,9 @@ public void onPlayerRightClickBell(PlayerInteractEvent event) { world.spawnEntity(bellLocation, EntityType.WANDERING_TRADER); // Add particles and sound - world.spawnParticle(Particle.VILLAGER_HAPPY,bellLocation.getX(), bellLocation.getY() + 0.5, + world.spawnParticle(Particle.HAPPY_VILLAGER,bellLocation.getX(), bellLocation.getY() + 0.5, bellLocation.getZ(), 5, 0.3, 0.3, 0.3); - world.spawnParticle(Particle.SMOKE_LARGE, bellLocation.getX(), bellLocation.getY() + 1, + world.spawnParticle(Particle.LARGE_SMOKE, bellLocation.getX(), bellLocation.getY() + 1, bellLocation.getZ(), 10, 0.25, 0.5, 0.25, 0); world.playSound(bellLocation, Sound.ENTITY_WANDERING_TRADER_REAPPEARED, SoundCategory.NEUTRAL, 1, 1); diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java b/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java index 1b16469d..b32cd4e9 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java @@ -134,7 +134,7 @@ public BukkitRunnable getRunnable(Player player, ItemStack item, CharmOptions op // Data switch (particle) { - case ITEM_CRACK, BLOCK_CRACK, BLOCK_DUST, FALLING_DUST, BLOCK_MARKER -> { + case ITEM, BLOCK, DUST, FALLING_DUST, BLOCK_MARKER -> { // Takes Material as input EncapsulatedType dataMatType = settingsMap.get("dataMaterial"); @@ -147,7 +147,7 @@ public BukkitRunnable getRunnable(Player player, ItemStack item, CharmOptions op try { Material material = Material.valueOf(dataMat); - if (particle == Particle.ITEM_CRACK) { + if (particle == Particle.ITEM) { if (material.isItem()) { ItemStack itemStack = new ItemStack(material); diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/sunkentreasure/events/TreasureChecker.java b/modules/src/main/java/parallelmc/parallelutils/modules/sunkentreasure/events/TreasureChecker.java index 02bb503b..5786df44 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/sunkentreasure/events/TreasureChecker.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/sunkentreasure/events/TreasureChecker.java @@ -49,7 +49,7 @@ public void onBreakBlock(BlockBreakEvent event) { ItemStack heldItem = player.getInventory().getItemInMainHand(); Map enchantments = heldItem.getEnchantments(); - Integer enchantVal = enchantments.get(Enchantment.LOOT_BONUS_BLOCKS); + Integer enchantVal = enchantments.get(Enchantment.FORTUNE); ParallelUtils.log(Level.INFO, "" + enchantVal); From a998eb87fca495d99ff3f70580653f28f0cf72df Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Tue, 7 May 2024 01:30:25 -0400 Subject: [PATCH 30/52] NBT fixes + remove Material checks for special items death checks + delete unused KeepSpecialItems class --- .../minimodules/KeepSpecialItems.java | 81 ------------------- .../bitsandbobs/minimodules/SpecialItems.java | 67 ++++++--------- 2 files changed, 26 insertions(+), 122 deletions(-) delete mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/KeepSpecialItems.java diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/KeepSpecialItems.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/KeepSpecialItems.java deleted file mode 100644 index 6c865d88..00000000 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/KeepSpecialItems.java +++ /dev/null @@ -1,81 +0,0 @@ -package parallelmc.parallelutils.modules.bitsandbobs.minimodules; - -import net.minecraft.nbt.CompoundTag; -import org.bukkit.Material; -import org.bukkit.craftbukkit.inventory.CraftItemStack; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.inventory.ItemStack; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.UUID; - - -public class KeepSpecialItems implements Listener { - - private final HashMap> specialItemsLogger = new HashMap<>(); - - private final String[] SPECIAL_ITEMS = {"CustomHat", "CustomTrophy"}; - - @EventHandler(priority = EventPriority.HIGHEST) - public void onPlayerDeath(PlayerDeathEvent event) { - // Creates an empty list for all items to be prevented from dropping - ArrayList preventedDrops = new ArrayList<>(); - - for (ItemStack item : event.getDrops()) { - // TODO: This probably doesn't need to be dependent on item type. Just checking the tag is a bit more futureproof - if (item.getType() == Material.PAPER) { - // TODO: Try to change this code to use item.getItemMeta().getPersistentDataContainer() - net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); // does this even work lol - // Grabs the NMS items compound and checks if it's null - CompoundTag compound = (nmsItem.hasTag()) ? nmsItem.getTag() : new CompoundTag(); - - if (compound == null) continue; - - if (compound.contains("CustomHat")) { - preventedDrops.add(item); - } - } else if (item.getType() == Material.PLAYER_HEAD) { - net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); // does this even work lol - // Grabs the NMS items compound and checks if it's null - CompoundTag compound = (nmsItem.hasTag()) ? nmsItem.getTag() : new CompoundTag(); - - if (compound == null) continue; - - if (compound.contains("CustomTrophy")) { - preventedDrops.add(item); - } - } - } - // If the list of special drops has items in it, add a new player entry to the logger hashmap and remove the - // dropped items - if (!preventedDrops.isEmpty()) { - // Gets the UUID of the player - UUID uuid = event.getEntity().getUniqueId(); - specialItemsLogger.put(uuid, preventedDrops); - - // Removes each special item from the original list of dropped items - for (ItemStack item : preventedDrops) { - event.getDrops().remove(item); - } - } - } - - @EventHandler - public void onPlayerRespawn(PlayerRespawnEvent event) { - // If the special items hashmap contains the player, then give them their special items back and remove them - // from the hashmap - if (specialItemsLogger.containsKey(event.getPlayer().getUniqueId())) { - ArrayList items = specialItemsLogger.get(event.getPlayer().getUniqueId()); - for (ItemStack item : items) { - event.getPlayer().getInventory().addItem(item); - } - // Removes the player from the hashmap - specialItemsLogger.remove(event.getPlayer().getUniqueId()); - } - } -} diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java index b07bec28..37aeac8f 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/SpecialItems.java @@ -1,6 +1,7 @@ package parallelmc.parallelutils.modules.bitsandbobs.minimodules; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.component.CustomData; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -36,54 +37,40 @@ public class SpecialItems implements Listener { private final String[] SPECIAL_ITEMS = {"CustomHat", "CustomTrophy"}; + @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerDeath(PlayerDeathEvent event) { // Creates an empty list for all items to be prevented from dropping ArrayList preventedDrops = new ArrayList<>(); for (ItemStack item : event.getDrops()) { - // TODO: This probably doesn't need to be dependent on item type. Just checking the tag is a bit more futureproof - // TODO: The leather horse armor add is a band-aid because I'm lazy, will fix later - if (item.getType() == Material.PAPER || item.getType() == Material.LEATHER_HORSE_ARMOR) { - // TODO: Try to change this code to use item.getItemMeta().getPersistentDataContainer() - // TODO: Make this 2-part check not jank - hopefully transition entirely to persistentdatacontainer - NamespacedKey hatKeyOld = new NamespacedKey(plugin, "CustomHat"); - NamespacedKey hatKey = new NamespacedKey(plugin, "ParallelHat"); - PersistentDataContainer container = item.getItemMeta().getPersistentDataContainer(); - if (container.has(hatKeyOld, PersistentDataType.INTEGER) || container.has(hatKey, PersistentDataType.STRING)) { - preventedDrops.add(item); - continue; - } - - net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); // does this even work lol - // Grabs the NMS items compound and checks if it's null - CompoundTag compound = (nmsItem.hasTag()) ? nmsItem.getTag() : new CompoundTag(); - - if (compound == null) continue; - - if (compound.contains("CustomHat")) { - preventedDrops.add(item); - } - } else if (item.getType() == Material.PLAYER_HEAD) { - net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); // does this even work lol - // Grabs the NMS items compound and checks if it's null - CompoundTag compound = (nmsItem.hasTag()) ? nmsItem.getTag() : new CompoundTag(); + // TODO: The NMS check down below won't be needed anymore if we start making every hat and trophy through PU + NamespacedKey hatKeyOld = new NamespacedKey(plugin, "CustomHat"); + NamespacedKey hatKey = new NamespacedKey(plugin, "ParallelHat"); + PersistentDataContainer container = item.getItemMeta().getPersistentDataContainer(); + if (container.has(hatKeyOld, PersistentDataType.INTEGER) || container.has(hatKey, PersistentDataType.STRING)) { + preventedDrops.add(item); + continue; + } - if (compound == null) continue; + net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); // does this even work lol + // Grabs the custom data component (returns an empty component if it's null) + CustomData customData = nmsItem.getComponents().getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY); - if (compound.contains("CustomTrophy")) { - preventedDrops.add(item); - } + if (customData.contains("CustomHat") || customData.contains("CustomTrophy")) { + preventedDrops.add(item); } + } + // If the list of special drops has items in it, add a new player entry to the logger hashmap and remove the - // dropped items + // items from dropping upon death if (!preventedDrops.isEmpty()) { // Gets the UUID of the player UUID uuid = event.getEntity().getUniqueId(); specialItemsLogger.put(uuid, preventedDrops); - // Removes each special item from the original list of dropped items + // Removes each special item from dropping upon death for (ItemStack item : preventedDrops) { event.getDrops().remove(item); } @@ -131,11 +118,10 @@ public void onPlayerCraft(PrepareItemCraftEvent event) { } // Now we have to use NMS if the item doesn't have a PersistentDataContainer net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); // does this even work lol - // Grabs the NMS items compound and checks if it's null - CompoundTag compound = (nmsItem.hasTag()) ? nmsItem.getTag() : new CompoundTag(); - if (compound == null) continue; + // Grabs the custom data component (returns an empty component if it's null) + CustomData customData = nmsItem.getComponents().getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY); - if (compound.contains("CustomHat")) { + if (customData.contains("CustomHat")) { ingredients.setResult(null); break; } @@ -172,11 +158,10 @@ public void onArmorCauldronDye(PlayerInteractEvent event) { // Now we have to use NMS if the item doesn't have a PersistentDataContainer net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); // does this even work lol - // Grabs the NMS items compound and checks if it's null - CompoundTag compound = (nmsItem.hasTag()) ? nmsItem.getTag() : new CompoundTag(); - if (compound == null) return; + // Grabs the custom data component (returns an empty component if it's null) + CustomData customData = nmsItem.getComponents().getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY); - if (compound.contains("CustomHat")) { + if (customData.contains("CustomHat")) { event.setCancelled(true); } } From 722fc30deff89e097a072ac5d7835533a73f4cb0 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Tue, 7 May 2024 15:05:45 -0400 Subject: [PATCH 31/52] Correctly change both BLOCK_CRACK and BLOCK_DUST to BLOCK --- .../modules/charms/handlers/impl/CharmParticleHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java b/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java index b32cd4e9..bc11fe32 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java @@ -134,7 +134,7 @@ public BukkitRunnable getRunnable(Player player, ItemStack item, CharmOptions op // Data switch (particle) { - case ITEM, BLOCK, DUST, FALLING_DUST, BLOCK_MARKER -> { + case ITEM, BLOCK, FALLING_DUST, BLOCK_MARKER -> { // Takes Material as input EncapsulatedType dataMatType = settingsMap.get("dataMaterial"); From 89a2e7afa524b75e676a4713ea5a9367dcadff76 Mon Sep 17 00:00:00 2001 From: Ethan Date: Thu, 9 May 2024 19:54:34 -0400 Subject: [PATCH 32/52] add missing method --- .../modules/charms/util/EnchantGlow.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java b/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java index 6948034d..30bd63e4 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java @@ -1,18 +1,18 @@ package parallelmc.parallelutils.modules.charms.util; import io.papermc.paper.enchantments.EnchantmentRarity; +import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import org.bukkit.NamespacedKey; -import org.bukkit.Registry; import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.EntityCategory; +import org.bukkit.entity.EntityType; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import parallelmc.parallelutils.ParallelUtils; -import java.lang.reflect.Field; import java.util.Set; public class EnchantGlow extends Enchantment { @@ -40,7 +40,7 @@ public int getStartLevel() { @Override public @NotNull EnchantmentTarget getItemTarget() { - return EnchantmentTarget.ALL; + return null; } @Override @@ -90,11 +90,16 @@ public int getMaxModifiedCost(int level) { @Override public @NotNull EnchantmentRarity getRarity() { - return EnchantmentRarity.COMMON; + return null; } @Override - public float getDamageIncrease(int level, @NotNull EntityCategory entityCategory) { + public float getDamageIncrease(int i, @NotNull EntityCategory entityCategory) { + return 0; + } + + @Override + public float getDamageIncrease(int i, @NotNull EntityType entityType) { return 0; } @@ -132,7 +137,11 @@ public static void registerFakeGlow(ParallelUtils puPlugin) { return key; } - // TODO: get rid of this shit lol + @Override + public @NotNull Key key() { + return super.key(); + } + @Override public @NotNull String getTranslationKey() { return null; From 7a473af7e7d1f3830086fd7a50362311dbf69e40 Mon Sep 17 00:00:00 2001 From: Ethan Date: Sat, 11 May 2024 23:08:34 -0400 Subject: [PATCH 33/52] proof of concept --- api/build.gradle | 4 + build.gradle | 2 +- .../handlers/impl/CharmParticleHandler.java | 3 +- .../modules/parallelchat/ParallelChat.java | 10 ++ .../parallelutils/modules/points/Config.java | 19 +++ .../parallelutils/modules/points/Points.java | 123 ++++++++++++++++++ .../modules/points/commands/ViewPoints.java | 20 +++ .../points/events/OnAdvancementDone.java | 28 ++++ 8 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/points/Config.java create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/points/commands/ViewPoints.java create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java diff --git a/api/build.gradle b/api/build.gradle index a394754b..be97b225 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -286,6 +286,10 @@ bukkit { description = 'Opens Maggies Shop' usage = '/openmaggieshop (player)' } + points { + description = "View your advancement points" + usage = "/points" + } } permissions { diff --git a/build.gradle b/build.gradle index 72ea511d..32221654 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ plugins { id 'java' id 'com.github.johnrengelman.shadow' version '8.1.1' - id "io.papermc.paperweight.userdev" version "1.7.0" + id "io.papermc.paperweight.userdev" version "1.7.1" id "xyz.jpenilla.run-paper" version "2.3.0" id 'net.minecrell.plugin-yml.bukkit' version '0.6.0' } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java b/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java index bc11fe32..f684f9c1 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java @@ -163,7 +163,8 @@ public BukkitRunnable getRunnable(Player player, ItemStack item, CharmOptions op if (dataBlockDataType.getType() == Types.STRING) { String blockData = (String) dataBlockDataType.getVal(); - BlockData data = CraftBlockData.newData(material, blockData); + // suck my nutsack paper + BlockData data = CraftBlockData.newData(material.asBlockType(), blockData); builder.data(data); } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelchat/ParallelChat.java b/modules/src/main/java/parallelmc/parallelutils/modules/parallelchat/ParallelChat.java index 326b7e63..6bff785c 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelchat/ParallelChat.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelchat/ParallelChat.java @@ -389,6 +389,16 @@ public static void sendParallelMessageTo(Player player, Component message) { Component text = MiniMessage.miniMessage().deserialize("[P] ").append(message); player.sendMessage(text); } + + /** + * Sends a chat message to a player with the ParallelUtils prefix after waiting a specified number of ticks + * @param player The player to send the message to + * @param wait The number of ticks to wait until sending the message + * @param message The component to send + */ + public static void sendDelayedParallelMessageTo(Player player, long wait, String message) { + Bukkit.getScheduler().runTaskLater(Instance.puPlugin, () -> sendParallelMessageTo(player, message), wait); + } /** * Sends a chat message to a player diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/Config.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/Config.java new file mode 100644 index 00000000..b9c2d8ea --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/Config.java @@ -0,0 +1,19 @@ +package parallelmc.parallelutils.modules.points; + +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Config implements parallelmc.parallelutils.Config { + @Override + public @NotNull List getHardDepends() { + return List.of("ParallelChat"); + } + + @Override + public @NotNull List getSoftDepends() { + return new ArrayList<>(); + } +} diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java new file mode 100644 index 00000000..83b653fa --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java @@ -0,0 +1,123 @@ +package parallelmc.parallelutils.modules.points; + +import org.bukkit.Bukkit; +import org.bukkit.NamespacedKey; +import org.bukkit.advancement.Advancement; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; +import org.jetbrains.annotations.NotNull; +import parallelmc.parallelutils.Constants; +import parallelmc.parallelutils.ParallelClassLoader; +import parallelmc.parallelutils.ParallelModule; +import parallelmc.parallelutils.ParallelUtils; +import parallelmc.parallelutils.modules.points.commands.ViewPoints; +import parallelmc.parallelutils.modules.points.events.OnAdvancementDone; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; +import java.util.logging.Level; + +public class Points extends ParallelModule { + public Points(ParallelClassLoader classLoader, List dependents) { super(classLoader, dependents); } + + private final HashMap advancementMap = new HashMap<>(); + + private final HashMap playerPoints = new HashMap<>(); + + private static Points Instance; + + private ParallelUtils puPlugin; + + @Override + public void onLoad() { } + + @Override + public void onEnable() { + PluginManager manager = Bukkit.getPluginManager(); + Plugin plugin = manager.getPlugin(Constants.PLUGIN_NAME); + + if (plugin == null) { + ParallelUtils.log(Level.SEVERE, "Unable to enable Points. Plugin " + Constants.PLUGIN_NAME + " does not exist!"); + return; + } + + puPlugin = (ParallelUtils) plugin; + + if (!puPlugin.registerModule(this)) { + ParallelUtils.log(Level.SEVERE, "Unable to register module Points! Module may already be registered. Quitting..."); + } + + manager.registerEvents(new OnAdvancementDone(), puPlugin); + + puPlugin.getCommand("points").setExecutor(new ViewPoints()); + + loadAdvancements(); + + Instance = this; + } + + @Override + public void onDisable() { } + + @Override + public void onUnload() { } + + @Override + public @NotNull String getName() { return "Points"; } + + public int getPointsForAdvancement(Advancement advancement) { + return advancementMap.getOrDefault(advancement.getKey().asString(), -1); + } + + public void awardPoints(Player player, int amount) { + playerPoints.put(player.getUniqueId(), getPlayerPoints(player) + amount); + } + + public int getPlayerPoints(Player player) { + return playerPoints.getOrDefault(player.getUniqueId(), 0); + } + + private void loadAdvancements() { + File file = new File(puPlugin.getDataFolder(), "points.yml"); + FileConfiguration pointsConfig = new YamlConfiguration(); + try { + if (file.createNewFile()) { + ParallelUtils.log(Level.WARNING, "points.yml does not exist. Creating..."); + } + pointsConfig.load(file); + } + catch (IOException e) { + ParallelUtils.log(Level.SEVERE, "Failed to create or read points.yml\n" + e); + return; + } catch (Exception e) { + ParallelUtils.log(Level.SEVERE, "Failed to load points.yml\n" + e); + return; + } + for (String key : pointsConfig.getKeys(true)) { + if (pointsConfig.isConfigurationSection(key)) + continue; + int value = pointsConfig.getInt(key); + String[] split = key.split("\\."); + if (split.length != 2) { + ParallelUtils.log(Level.WARNING, "Invalid advancement key: " + key); + continue; + } + Advancement advancement = Bukkit.getAdvancement(new NamespacedKey(split[0], split[1])); + if (advancement == null) { + ParallelUtils.log(Level.WARNING, "Unknown advancement: " + key); + continue; + } + advancementMap.put(advancement.getKey().asString(), value); + } + ParallelUtils.log(Level.WARNING, "Loaded " + advancementMap.size() + " advancement points."); + } + + public static Points get() { return Instance; } + +} diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/ViewPoints.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/ViewPoints.java new file mode 100644 index 00000000..898c4157 --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/ViewPoints.java @@ -0,0 +1,20 @@ +package parallelmc.parallelutils.modules.points.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import parallelmc.parallelutils.modules.parallelchat.ParallelChat; +import parallelmc.parallelutils.modules.points.Points; + +public class ViewPoints implements CommandExecutor { + @Override + public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (commandSender instanceof Player player) { + int points = Points.get().getPlayerPoints(player); + ParallelChat.sendParallelMessageTo(player, "You currently have " + points + " advancement points!"); + } + return true; + } +} diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java new file mode 100644 index 00000000..b671c0ad --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/events/OnAdvancementDone.java @@ -0,0 +1,28 @@ +package parallelmc.parallelutils.modules.points.events; + +import org.bukkit.advancement.Advancement; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerAdvancementDoneEvent; +import parallelmc.parallelutils.ParallelUtils; +import parallelmc.parallelutils.modules.parallelchat.ParallelChat; +import parallelmc.parallelutils.modules.points.Points; + +import java.util.logging.Level; + +public class OnAdvancementDone implements Listener { + @EventHandler + public void onAdvancementDone(PlayerAdvancementDoneEvent event) { + Advancement advancement = event.getAdvancement(); + Player player = event.getPlayer(); + int points = Points.get().getPointsForAdvancement(advancement); + if (points == -1) { + ParallelUtils.log(Level.WARNING, "Advancement " + advancement.getKey().asString() + " has no associated point value! Skipping..."); + return; + } + Points.get().awardPoints(player, points); + // wait 1 tick to send the message so it shows after the advancement + ParallelChat.sendDelayedParallelMessageTo(player, 1, "You've received " + points + " advancement points!"); + } +} From 46ac8e93ea4079e09ff5d2029083986bee2537d0 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Sun, 12 May 2024 00:30:42 -0400 Subject: [PATCH 34/52] ty Paper --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 72ea511d..32221654 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ plugins { id 'java' id 'com.github.johnrengelman.shadow' version '8.1.1' - id "io.papermc.paperweight.userdev" version "1.7.0" + id "io.papermc.paperweight.userdev" version "1.7.1" id "xyz.jpenilla.run-paper" version "2.3.0" id 'net.minecrell.plugin-yml.bukkit' version '0.6.0' } From 9e747df44463cfae0b58c00933f6242205f4fb9b Mon Sep 17 00:00:00 2001 From: Ethan Date: Sun, 12 May 2024 22:43:34 -0400 Subject: [PATCH 35/52] implement recalculatepoints dev command --- api/build.gradle | 10 ++ .../parallelutils/modules/points/Points.java | 116 +++++++++++++++++- .../points/commands/RecalculatePoints.java | 38 ++++++ 3 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/points/commands/RecalculatePoints.java diff --git a/api/build.gradle b/api/build.gradle index be97b225..668f6e6f 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -290,6 +290,12 @@ bukkit { description = "View your advancement points" usage = "/points" } + recalculatepoints { + description = "Recalculates advancement points for all players" + usage = "/recalculatepoints" + permissionMessage = "You do not have permission." + permission = "parallelutils.recalculatepoints" + } } permissions { @@ -486,5 +492,9 @@ bukkit { description = 'Prevents being kicked from not accepting the resource pack' setDefault('FALSE') } + 'parallelutils.recalculatepoints' { + description = 'Gives access to the /recalculatepoints dev command' + setDefault('FALSE') + } } } \ No newline at end of file diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java index 83b653fa..9a1c2f30 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java @@ -2,6 +2,8 @@ import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; +import org.bukkit.OfflinePlayer; +import org.bukkit.Warning; import org.bukkit.advancement.Advancement; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -9,17 +11,26 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.jetbrains.annotations.NotNull; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; import parallelmc.parallelutils.Constants; import parallelmc.parallelutils.ParallelClassLoader; import parallelmc.parallelutils.ParallelModule; import parallelmc.parallelutils.ParallelUtils; +import parallelmc.parallelutils.modules.points.commands.RecalculatePoints; import parallelmc.parallelutils.modules.points.commands.ViewPoints; import parallelmc.parallelutils.modules.points.events.OnAdvancementDone; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; import java.util.logging.Level; @@ -56,14 +67,19 @@ public void onEnable() { manager.registerEvents(new OnAdvancementDone(), puPlugin); puPlugin.getCommand("points").setExecutor(new ViewPoints()); + puPlugin.getCommand("recalculatepoints").setExecutor(new RecalculatePoints(puPlugin)); loadAdvancements(); + loadPlayerPoints(); + Instance = this; } @Override - public void onDisable() { } + public void onDisable() { + savePlayerPoints(); + } @Override public void onUnload() { } @@ -118,6 +134,104 @@ private void loadAdvancements() { ParallelUtils.log(Level.WARNING, "Loaded " + advancementMap.size() + " advancement points."); } + private void loadPlayerPoints() { + Path path = Path.of(puPlugin.getDataFolder().getAbsolutePath() + "/player_points.json"); + if (!path.toFile().exists()) { + ParallelUtils.log(Level.WARNING, "Points JSON file does not exist, skipping loading."); + return; + } + String data; + try { + data = Files.readString(path); + JSONParser parser = new JSONParser(); + JSONArray arr = (JSONArray)parser.parse(data); + for (Object o : arr) { + JSONObject json = (JSONObject) o; + UUID uuid = UUID.fromString((String)json.get("uuid")); + int points = ((Long)json.get("points")).intValue(); + playerPoints.put(uuid, points); + } + ParallelUtils.log(Level.INFO, "Loaded " + playerPoints.size() + " player points entries."); + } catch (IOException | NullPointerException e) { + ParallelUtils.log(Level.SEVERE, "Failed to load player points!\n" + e.getMessage()); + } catch (ParseException e) { + ParallelUtils.log(Level.SEVERE, "Failed to parse player points data!\n" + e.getMessage()); + } + } + + @SuppressWarnings("unchecked") + private void savePlayerPoints() { + Path path = Path.of(puPlugin.getDataFolder().getAbsolutePath() + "/player_points.json"); + JSONArray json = new JSONArray(); + for (Map.Entry e : playerPoints.entrySet()) { + JSONObject entry = new JSONObject(); + entry.put("uuid", e.getKey()); + entry.put("points", e.getValue()); + json.add(entry); + } + try { + Files.writeString(path, json.toJSONString()); + ParallelUtils.log(Level.INFO, "Saved " + playerPoints.size() + " player points entries."); + } catch (IOException e) { + ParallelUtils.log(Level.SEVERE, "Failed to save player points entries!\n" + e.getMessage()); + } + } + + public int recalculatePlayerPoints() { + playerPoints.clear(); + Path path = Path.of(puPlugin.getServer().getWorldContainer().getAbsolutePath() + "/advancements"); + File[] files = path.toFile().listFiles(); + if (files == null) { + ParallelUtils.log(Level.SEVERE, "Failed to get files from advancements folder!"); + return -1; + } + for (File file : files) { + // this is horrible practice but its pretty safe to assume nothing in here will have more than 1 period + String[] split = file.getName().split("\\."); + // check it anyway + if (split.length != 2) { + ParallelUtils.log(Level.SEVERE, "A file has more than one period...somehow. Skipping!"); + continue; + } + UUID uuid; + try { + uuid = UUID.fromString(split[0]); + } catch (IllegalArgumentException e) { + ParallelUtils.log(Level.WARNING, split[0] + " failed to parse into a UUID. Skipping!"); + continue; + } + + String data; + try { + data = Files.readString(file.toPath()); + JSONParser parser = new JSONParser(); + JSONObject obj = (JSONObject) parser.parse(data); + + for (Object o : obj.entrySet()) { + // gee, who put this here + @SuppressWarnings("unchecked") + Map.Entry entry = (Map.Entry) o; + + String advancement = entry.getKey(); + JSONObject value = entry.getValue(); + + int points = advancementMap.getOrDefault(advancement, -1); + + if (points > -1) { + if ((Boolean)value.get("done")) { + playerPoints.put(uuid, playerPoints.getOrDefault(uuid, 0) + points); + } + } + } + } catch (IOException | NullPointerException e) { + ParallelUtils.log(Level.SEVERE, "Failed to load file " + file.getName() + "!\n" + e.getMessage()); + } catch (ParseException e) { + ParallelUtils.log(Level.SEVERE, "Failed to parse " + file.getName() + "!\n" + e.getMessage()); + } + } + return playerPoints.size(); + } + public static Points get() { return Instance; } } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/RecalculatePoints.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/RecalculatePoints.java new file mode 100644 index 00000000..eb135e19 --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/RecalculatePoints.java @@ -0,0 +1,38 @@ +package parallelmc.parallelutils.modules.points.commands; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import parallelmc.parallelutils.ParallelUtils; +import parallelmc.parallelutils.modules.points.Points; + +public class RecalculatePoints implements CommandExecutor { + private final ParallelUtils puPlugin; + + public RecalculatePoints(ParallelUtils puPlugin) { + this.puPlugin = puPlugin; + } + @Override + public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (commandSender.isOp() || commandSender instanceof ConsoleCommandSender + || (commandSender instanceof Player player && player.hasPermission("parallelutils.recalculatepoints"))) { + commandSender.sendMessage("Recalculating advancement points for all players, this might take a while..."); + Bukkit.getScheduler().runTaskAsynchronously(puPlugin, () -> { + long start = System.currentTimeMillis(); + int result = Points.get().recalculatePlayerPoints(); + long end = System.currentTimeMillis(); + if (result == -1) { + commandSender.sendMessage("Failed to recalculate, see the console for any errors."); + } + else { + commandSender.sendMessage("Recalculated advancement points for " + result + " players in " + (end - start) + "ms"); + } + }); + } + return true; + } +} From 5d33ad91ce136b7822a98677925a8c68db2fdafb Mon Sep 17 00:00:00 2001 From: Ethan Date: Sun, 12 May 2024 23:31:56 -0400 Subject: [PATCH 36/52] bugfixing --- api/build.gradle | 1 - .../parallelutils/modules/points/Points.java | 16 ++++++++-- .../points/commands/RecalculatePoints.java | 31 ++++++++++--------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index 668f6e6f..041c18be 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -494,7 +494,6 @@ bukkit { } 'parallelutils.recalculatepoints' { description = 'Gives access to the /recalculatepoints dev command' - setDefault('FALSE') } } } \ No newline at end of file diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java index 9a1c2f30..3936364a 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java @@ -165,7 +165,7 @@ private void savePlayerPoints() { JSONArray json = new JSONArray(); for (Map.Entry e : playerPoints.entrySet()) { JSONObject entry = new JSONObject(); - entry.put("uuid", e.getKey()); + entry.put("uuid", e.getKey().toString()); entry.put("points", e.getValue()); json.add(entry); } @@ -179,7 +179,15 @@ private void savePlayerPoints() { public int recalculatePlayerPoints() { playerPoints.clear(); - Path path = Path.of(puPlugin.getServer().getWorldContainer().getAbsolutePath() + "/advancements"); + Path path; + try { + //path = Path.of(puPlugin.getServer().getWorldContainer().getCanonicalPath(), "world", "advancements"); + path = Path.of(puPlugin.getServer().getWorldContainer().getCanonicalPath(), Constants.DEFAULT_WORLD, "advancements"); + ParallelUtils.log(Level.INFO, "Using path: " + path); + } catch (IOException e) { + ParallelUtils.log(Level.SEVERE, "Failed to find path to advancements folder! \n" + e.getMessage()); + return -1; + } File[] files = path.toFile().listFiles(); if (files == null) { ParallelUtils.log(Level.SEVERE, "Failed to get files from advancements folder!"); @@ -213,6 +221,10 @@ public int recalculatePlayerPoints() { Map.Entry entry = (Map.Entry) o; String advancement = entry.getKey(); + // every advancement json file has the DataVersion at the very bottom + // so treat this as the "terminator" of sorts + if (advancement.equals("DataVersion")) + break; JSONObject value = entry.getValue(); int points = advancementMap.getOrDefault(advancement, -1); diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/RecalculatePoints.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/RecalculatePoints.java index eb135e19..ee8afff5 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/RecalculatePoints.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/RecalculatePoints.java @@ -4,7 +4,6 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import parallelmc.parallelutils.ParallelUtils; @@ -18,21 +17,23 @@ public RecalculatePoints(ParallelUtils puPlugin) { } @Override public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (commandSender.isOp() || commandSender instanceof ConsoleCommandSender - || (commandSender instanceof Player player && player.hasPermission("parallelutils.recalculatepoints"))) { - commandSender.sendMessage("Recalculating advancement points for all players, this might take a while..."); - Bukkit.getScheduler().runTaskAsynchronously(puPlugin, () -> { - long start = System.currentTimeMillis(); - int result = Points.get().recalculatePlayerPoints(); - long end = System.currentTimeMillis(); - if (result == -1) { - commandSender.sendMessage("Failed to recalculate, see the console for any errors."); - } - else { - commandSender.sendMessage("Recalculated advancement points for " + result + " players in " + (end - start) + "ms"); - } - }); + if (commandSender instanceof Player player) { + if (!player.hasPermission("parallelutils.recalculatepoints")) { + return true; + } } + commandSender.sendMessage("Recalculating advancement points for all players, this might take a while..."); + Bukkit.getScheduler().runTaskAsynchronously(puPlugin, () -> { + long start = System.currentTimeMillis(); + int result = Points.get().recalculatePlayerPoints(); + long end = System.currentTimeMillis(); + if (result == -1) { + commandSender.sendMessage("Failed to recalculate, see the console for any errors."); + } + else { + commandSender.sendMessage("Recalculated advancement points for " + result + " players in " + (end - start) + "ms"); + } + }); return true; } } From 2a05adb1a6b770f8213d0f42f42033597e3ee4b8 Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Sun, 19 May 2024 17:06:04 -0400 Subject: [PATCH 37/52] Update mapping of plugin --- api/build.gradle | 7 +++++-- build.gradle | 4 ++++ modules/build.gradle | 43 +++++++++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index a394754b..db68d98e 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -1,4 +1,5 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import io.papermc.paperweight.userdev.ReobfArtifactConfiguration plugins { id 'net.minecrell.plugin-yml.bukkit' @@ -14,6 +15,8 @@ java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) } +paperweight.reobfArtifactConfiguration = ReobfArtifactConfiguration.getMOJANG_PRODUCTION() + compileJava.options.encoding = "UTF-8" compileTestJava.options.encoding = "UTF-8" processResources.filteringCharset = "UTF-8" @@ -46,11 +49,11 @@ artifacts { tasks { assemble { - dependsOn(reobfJar) + //dependsOn(reobfJar) } build { - dependsOn(reobfJar) + //dependsOn(reobfJar) } compileJava { diff --git a/build.gradle b/build.gradle index 32221654..12f67125 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ +import io.papermc.paperweight.userdev.ReobfArtifactConfiguration + plugins { id 'java' id 'com.github.johnrengelman.shadow' version '8.1.1' @@ -10,6 +12,8 @@ java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) } +paperweight.reobfArtifactConfiguration = ReobfArtifactConfiguration.getMOJANG_PRODUCTION() + dependencies { paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.6-R0.1-SNAPSHOT") } diff --git a/modules/build.gradle b/modules/build.gradle index d509230d..e41a1c29 100644 --- a/modules/build.gradle +++ b/modules/build.gradle @@ -1,6 +1,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import io.papermc.paperweight.tasks.RemapJar +import io.papermc.paperweight.userdev.ReobfArtifactConfiguration group = 'org.parallelmc' @@ -9,6 +10,8 @@ java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) } +paperweight.reobfArtifactConfiguration = ReobfArtifactConfiguration.getMOJANG_PRODUCTION() + compileJava.options.encoding = "UTF-8" compileTestJava.options.encoding = "UTF-8" processResources.filteringCharset = "UTF-8" @@ -74,23 +77,23 @@ names.each { mod -> // Figure out how to exclude META-INF } } - -names.each { mod -> - task "reobf-${mod}" (type: RemapJar) { - dependsOn "shadow-${mod}" - group = "ReobfMod" - description = "Remap the compiled module jar to Spigot's obfuscated runtime names" - - fromNamespace = reobfJar.fromNamespace - toNamespace = reobfJar.toNamespace - mappingsFile = reobfJar.mappingsFile - remapClasspath.from(reobfJar.remapClasspath.getFrom()) - remapper.from(reobfJar.project.configurations.named("remapper")) - remapperArgs = reobfJar.remapperArgs - - - inputJar.set(new File("$buildDir/libs/modules-shadow-${mod}.jar")) - //outputJar.set(new File("$buildDir/libs/${mod}-${project.version}.jar")) - outputJar.set(new File("$buildDir/libs/${mod}.jar")) - } -} \ No newline at end of file +// +//names.each { mod -> +// task "reobf-${mod}" (type: RemapJar) { +// dependsOn "shadow-${mod}" +// group = "ReobfMod" +// description = "Remap the compiled module jar to Spigot's obfuscated runtime names" +// +// fromNamespace = reobfJar.fromNamespace +// toNamespace = reobfJar.toNamespace +// mappingsFile = reobfJar.mappingsFile +// remapClasspath.from(reobfJar.remapClasspath.getFrom()) +// remapper.from(reobfJar.project.configurations.named("remapper")) +// remapperArgs = reobfJar.remapperArgs +// +// +// inputJar.set(new File("$buildDir/libs/modules-shadow-${mod}.jar")) +// //outputJar.set(new File("$buildDir/libs/${mod}-${project.version}.jar")) +// outputJar.set(new File("$buildDir/libs/${mod}.jar")) +// } +//} \ No newline at end of file From 0b9db8147d76c6b5a3e162a549a5700221f4c0f0 Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Sun, 19 May 2024 17:08:32 -0400 Subject: [PATCH 38/52] Update to 1.20.6 --- .../modules/charms/handlers/impl/CharmParticleHandler.java | 2 +- .../src/main/java/parallelmc/parallelutils/modules/custommobs | 2 +- .../main/java/parallelmc/parallelutils/modules/parallelitems | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java b/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java index bc11fe32..a6850b0f 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/charms/handlers/impl/CharmParticleHandler.java @@ -163,7 +163,7 @@ public BukkitRunnable getRunnable(Player player, ItemStack item, CharmOptions op if (dataBlockDataType.getType() == Types.STRING) { String blockData = (String) dataBlockDataType.getVal(); - BlockData data = CraftBlockData.newData(material, blockData); + BlockData data = material.createBlockData(blockData); builder.data(data); } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/custommobs b/modules/src/main/java/parallelmc/parallelutils/modules/custommobs index 79b286ff..90899a0c 160000 --- a/modules/src/main/java/parallelmc/parallelutils/modules/custommobs +++ b/modules/src/main/java/parallelmc/parallelutils/modules/custommobs @@ -1 +1 @@ -Subproject commit 79b286ff835e62eb337d4e99a610d6bc88f85d7c +Subproject commit 90899a0ceae66ccf790c720846ab7243cb8e28fa diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems b/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems index 1bd9508c..3c262720 160000 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems @@ -1 +1 @@ -Subproject commit 1bd9508cf4321d55b43008a4643dd51cb6beaa12 +Subproject commit 3c262720e8823654f4d07f4911625a8d3c4d6180 From 709ffac08278739adcb35e44fa5bec80dbba3ffc Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Sun, 19 May 2024 17:13:03 -0400 Subject: [PATCH 39/52] Update shadow config --- modules/build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/build.gradle b/modules/build.gradle index e41a1c29..65686c4a 100644 --- a/modules/build.gradle +++ b/modules/build.gradle @@ -66,7 +66,8 @@ names.each { mod -> def name = (String) "${mod}" exList.remove(name) - archiveClassifier.set("shadow-${mod}") + archiveBaseName.set("") + archiveClassifier.set("${mod}") from sourceSets.main.output From 4fcb2200c3aa8e4104a53d877c94880af5311240 Mon Sep 17 00:00:00 2001 From: Ethan Date: Tue, 21 May 2024 20:58:58 -0400 Subject: [PATCH 40/52] skeleton of points gui --- api/build.gradle | 16 +-- .../parallelutils/modules/points/Points.java | 20 ++-- .../modules/points/RedeemableItem.java | 42 ++++++++ .../points/commands/OpenPointsRedemption.java | 27 +++++ .../points/gui/PointsRedeemInventory.java | 99 +++++++++++++++++++ 5 files changed, 191 insertions(+), 13 deletions(-) create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/points/RedeemableItem.java create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/points/commands/OpenPointsRedemption.java create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/points/gui/PointsRedeemInventory.java diff --git a/api/build.gradle b/api/build.gradle index 041c18be..88b162c4 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -287,14 +287,18 @@ bukkit { usage = '/openmaggieshop (player)' } points { - description = "View your advancement points" - usage = "/points" + description = 'View your advancement points' + usage = '/points' } recalculatepoints { - description = "Recalculates advancement points for all players" - usage = "/recalculatepoints" - permissionMessage = "You do not have permission." - permission = "parallelutils.recalculatepoints" + description = 'Recalculates advancement points for all players' + usage = '/recalculatepoints' + permissionMessage = 'You do not have permission.' + permission = 'parallelutils.recalculatepoints' + } + openpointsredemption { + description = 'Opens the point redemption shop for a player' + usage = '/openpointsredemption (player)' } } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java index 3936364a..9c8a8640 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java @@ -2,8 +2,6 @@ import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; -import org.bukkit.OfflinePlayer; -import org.bukkit.Warning; import org.bukkit.advancement.Advancement; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -13,25 +11,24 @@ import org.jetbrains.annotations.NotNull; import org.json.simple.JSONArray; import org.json.simple.JSONObject; -import org.json.simple.JSONValue; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import parallelmc.parallelutils.Constants; import parallelmc.parallelutils.ParallelClassLoader; import parallelmc.parallelutils.ParallelModule; import parallelmc.parallelutils.ParallelUtils; +import parallelmc.parallelutils.modules.points.commands.OpenPointsRedemption; import parallelmc.parallelutils.modules.points.commands.RecalculatePoints; import parallelmc.parallelutils.modules.points.commands.ViewPoints; import parallelmc.parallelutils.modules.points.events.OnAdvancementDone; +import parallelmc.parallelutils.modules.points.gui.PointsRedeemInventory; +import parallelmc.parallelutils.util.GUIManager; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.logging.Level; public class Points extends ParallelModule { @@ -41,6 +38,8 @@ public class Points extends ParallelModule { private final HashMap playerPoints = new HashMap<>(); + private final List redeemableItems = new ArrayList<>(); + private static Points Instance; private ParallelUtils puPlugin; @@ -68,6 +67,7 @@ public void onEnable() { puPlugin.getCommand("points").setExecutor(new ViewPoints()); puPlugin.getCommand("recalculatepoints").setExecutor(new RecalculatePoints(puPlugin)); + puPlugin.getCommand("openpointsredemption").setExecutor(new OpenPointsRedemption()); loadAdvancements(); @@ -99,6 +99,12 @@ public int getPlayerPoints(Player player) { return playerPoints.getOrDefault(player.getUniqueId(), 0); } + public List getRedeemableItems() { return redeemableItems; } + + public void openPointsRedemptionFor(Player player) { + GUIManager.get().openInventoryForPlayer(player, new PointsRedeemInventory()); + } + private void loadAdvancements() { File file = new File(puPlugin.getDataFolder(), "points.yml"); FileConfiguration pointsConfig = new YamlConfiguration(); diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/RedeemableItem.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/RedeemableItem.java new file mode 100644 index 00000000..8d48073e --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/RedeemableItem.java @@ -0,0 +1,42 @@ +package parallelmc.parallelutils.modules.points; + +import org.bukkit.Material; + +import java.util.List; + +// an item that can be redeemed for advancement points +public class RedeemableItem { + private final Material material; + + private final int modelData; + + private final int requiredPoints; + + private final List commands; + + public RedeemableItem(Material material, int requiredPoints, List commands) { + this.material = material; + this.modelData = -1; + this.requiredPoints = requiredPoints; + this.commands = commands; + } + + public RedeemableItem(Material material, int requiredPoints, int modelData, List commands) { + this.material = material; + this.modelData = modelData; + this.requiredPoints = requiredPoints; + this.commands = commands; + } + + public Material getMaterial() { + return material; + } + + public int getModelData() { + return modelData; + } + + public int getRequiredPoints() { return requiredPoints; } + + public List getCommands() { return commands; } +} diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/OpenPointsRedemption.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/OpenPointsRedemption.java new file mode 100644 index 00000000..efa8e571 --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/commands/OpenPointsRedemption.java @@ -0,0 +1,27 @@ +package parallelmc.parallelutils.modules.points.commands; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import parallelmc.parallelutils.modules.points.Points; + +public class OpenPointsRedemption implements CommandExecutor { + @Override + public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (commandSender.isOp() || commandSender instanceof ConsoleCommandSender) { + if (args.length == 0) + return false; + Player player = Bukkit.getPlayer(args[0]); + if (player == null) { + commandSender.sendMessage("Could not find player " + args[0]); + return true; + } + Points.get().openPointsRedemptionFor(player); + } + return true; + } +} diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/gui/PointsRedeemInventory.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/gui/PointsRedeemInventory.java new file mode 100644 index 00000000..6b0664eb --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/gui/PointsRedeemInventory.java @@ -0,0 +1,99 @@ +package parallelmc.parallelutils.modules.points.gui; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.SkullMeta; +import parallelmc.parallelutils.modules.parallelchat.ParallelChat; +import parallelmc.parallelutils.modules.points.Points; +import parallelmc.parallelutils.modules.points.RedeemableItem; +import parallelmc.parallelutils.util.GUIInventory; + +import java.util.ArrayList; +import java.util.List; + +public class PointsRedeemInventory extends GUIInventory { + + private static List redeemableItems = new ArrayList<>(); + + public PointsRedeemInventory() { + super(54, Component.text("Advancement Points Redemption", NamedTextColor.GOLD, TextDecoration.BOLD)); + + ItemStack exit = new ItemStack(Material.BARRIER); + ItemMeta meta = exit.getItemMeta(); + meta.displayName(Component.text("Exit GUI", NamedTextColor.RED).decoration(TextDecoration.ITALIC, false)); + exit.setItemMeta(meta); + + inventory.setItem(49, exit); + } + + + @Override + public void onOpen(Player player) { + redeemableItems = Points.get().getRedeemableItems(); + int playerPoints = Points.get().getPlayerPoints(player); + ItemStack head = new ItemStack(Material.PLAYER_HEAD); + SkullMeta skull = (SkullMeta)head.getItemMeta(); + skull.displayName(Component.text(player.getName(), NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false)); + skull.setPlayerProfile(player.getPlayerProfile()); + skull.lore(List.of(Component.text("Advancement Points: ", NamedTextColor.GOLD).decoration(TextDecoration.ITALIC, false) + .append(Component.text(playerPoints, NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false)))); + head.setItemMeta(skull); + inventory.setItem(4, head); + + List items = Points.get().getRedeemableItems(); + int slot = 9; + for (RedeemableItem item : items) { + ItemStack i = new ItemStack(item.getMaterial()); + ItemMeta meta = i.getItemMeta(); + if (item.getModelData() != -1) { + meta.setCustomModelData(item.getModelData()); + } + meta.displayName(i.displayName().color(NamedTextColor.YELLOW).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); + List lore = List.of( + Component.empty(), + Component.text("Required Points: ", NamedTextColor.GOLD).decoration(TextDecoration.ITALIC, false) + .append(Component.text(item.getRequiredPoints(), playerPoints >= item.getRequiredPoints() ? NamedTextColor.GREEN : NamedTextColor.RED)) + + ); + meta.lore(lore); + i.setItemMeta(meta); + inventory.setItem(slot, i); + slot++; + } + } + + @Override + public void onSlotClicked(Player player, int slotNum, ItemStack itemClicked) { + if (slotNum > 8 && slotNum < 45) { + // yes this looks very stupid I know + if (player.hasPermission("parallelutils.points.slot" + slotNum)) { + player.playSound(player.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1, 1); + player.closeInventory(); + ParallelChat.sendParallelMessageTo(player, "You have already redeemed that item!"); + return; + } + if (player.getInventory().firstEmpty() == -1) { + player.playSound(player.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1, 1); + player.closeInventory(); + ParallelChat.sendParallelMessageTo(player, "Your inventory is too full!"); + return; + } + player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1); + player.closeInventory(); + ParallelChat.sendParallelMessageTo(player, Component.text("Successfully redeemed the ", NamedTextColor.GREEN).append(itemClicked.displayName())); + for (String s : redeemableItems.get(slotNum - 9).getCommands()) { + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), s); + } + } + if (slotNum == 49) { + player.closeInventory(); + } + } +} From b60af51cd0bcf7960681030f117f6d6a688e502b Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Fri, 24 May 2024 12:53:00 -0400 Subject: [PATCH 41/52] Bump plugin versions --- api/build.gradle | 8 ++++---- build.gradle | 4 ++-- modules/build.gradle | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index db68d98e..fe9bd903 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -32,12 +32,12 @@ dependencies { implementation 'org.jetbrains:annotations:24.0.1' testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2' - implementation 'net.dv8tion:JDA:5.0.0-beta.20' - compileOnly 'me.clip:placeholderapi:2.11.5' + implementation 'net.dv8tion:JDA:5.0.0-beta.24' + compileOnly 'me.clip:placeholderapi:2.11.6' compileOnly fileTree('libs') { include '*.jar' } - compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.9' + compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.10' implementation 'com.mysql:mysql-connector-j:8.3.0' - compileOnly 'com.comphenix.protocol:ProtocolLib:5.1.0' + compileOnly 'com.comphenix.protocol:ProtocolLib:5.2.0-SNAPSHOT' compileOnly 'dev.esophose:playerparticles:8.5' implementation 'org.reflections:reflections:0.10.2' } diff --git a/build.gradle b/build.gradle index 12f67125..6b56527e 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ import io.papermc.paperweight.userdev.ReobfArtifactConfiguration plugins { id 'java' - id 'com.github.johnrengelman.shadow' version '8.1.1' + id 'io.github.goooler.shadow' version '8.1.7' id "io.papermc.paperweight.userdev" version "1.7.1" id "xyz.jpenilla.run-paper" version "2.3.0" id 'net.minecrell.plugin-yml.bukkit' version '0.6.0' @@ -24,7 +24,7 @@ processResources.filteringCharset = "UTF-8" allprojects { apply plugin: 'java' - apply plugin: 'com.github.johnrengelman.shadow' + apply plugin: 'io.github.goooler.shadow' apply plugin: "io.papermc.paperweight.userdev" repositories { diff --git a/modules/build.gradle b/modules/build.gradle index 65686c4a..ebd33b37 100644 --- a/modules/build.gradle +++ b/modules/build.gradle @@ -22,12 +22,12 @@ dependencies { compileOnly 'org.jetbrains:annotations:24.0.1' testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2' - compileOnly 'net.dv8tion:JDA:5.0.0-beta.20' - compileOnly 'me.clip:placeholderapi:2.11.5' + compileOnly 'net.dv8tion:JDA:5.0.0-beta.24' + compileOnly 'me.clip:placeholderapi:2.11.6' compileOnly fileTree('libs') { include '*.jar' } - compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.9' + compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.10' compileOnly 'com.mysql:mysql-connector-j:8.3.0' - compileOnly 'com.comphenix.protocol:ProtocolLib:5.1.0' + compileOnly 'com.comphenix.protocol:ProtocolLib:5.2.0-SNAPSHOT' compileOnly 'dev.esophose:playerparticles:8.5' compileOnly "io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT" } From f79fd14d71b801467a88aa1b1f5d321d46a984b1 Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Fri, 24 May 2024 13:08:22 -0400 Subject: [PATCH 42/52] Fix reflection errors --- .../listeners/PlayerJoinContainerListenerOverwrite.java | 4 ++-- .../src/main/java/parallelmc/parallelutils/modules/custommobs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/charms/listeners/PlayerJoinContainerListenerOverwrite.java b/modules/src/main/java/parallelmc/parallelutils/modules/charms/listeners/PlayerJoinContainerListenerOverwrite.java index 7aa9e018..f3de7410 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/charms/listeners/PlayerJoinContainerListenerOverwrite.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/charms/listeners/PlayerJoinContainerListenerOverwrite.java @@ -26,9 +26,9 @@ public PlayerJoinContainerListenerOverwrite() { Field field; Field field1; try { - field = ServerPlayer.class.getDeclaredField("dc"); + field = ServerPlayer.class.getDeclaredField("containerSynchronizer"); field.setAccessible(true); - field1 = ServerPlayer.class.getDeclaredField("dd"); + field1 = ServerPlayer.class.getDeclaredField("containerListener"); field1.setAccessible(true); } catch (NoSuchFieldException e) { e.printStackTrace(); diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/custommobs b/modules/src/main/java/parallelmc/parallelutils/modules/custommobs index 90899a0c..fb1ae501 160000 --- a/modules/src/main/java/parallelmc/parallelutils/modules/custommobs +++ b/modules/src/main/java/parallelmc/parallelutils/modules/custommobs @@ -1 +1 @@ -Subproject commit 90899a0ceae66ccf790c720846ab7243cb8e28fa +Subproject commit fb1ae5019ccfedd48b583c824471a7d17568bf07 From 31207620db4368d3baf1c1f0c887a2b2050cc122 Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Fri, 24 May 2024 13:39:46 -0400 Subject: [PATCH 43/52] Bump parallelitems --- .../main/java/parallelmc/parallelutils/modules/parallelitems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems b/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems index 3c262720..5a272dd8 160000 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems @@ -1 +1 @@ -Subproject commit 3c262720e8823654f4d07f4911625a8d3c4d6180 +Subproject commit 5a272dd85c53769a3895983db61e8c6959bcf346 From 0ee7db325d14811c33e82da40e2d5ff1b0e738ac Mon Sep 17 00:00:00 2001 From: EBro912 Date: Sat, 25 May 2024 01:11:18 -0400 Subject: [PATCH 44/52] points config loading --- .../parallelutils/modules/points/Points.java | 27 +++++++++++++++++++ .../modules/points/RedeemableItem.java | 10 +++++-- .../points/gui/PointsRedeemInventory.java | 11 ++++---- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java index 9c8a8640..4c014230 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java @@ -250,6 +250,33 @@ public int recalculatePlayerPoints() { return playerPoints.size(); } + public void loadItems() { + File itemFile = new File(puPlugin.getDataFolder(), "points_items.yml"); + FileConfiguration itemConfig = new YamlConfiguration; + try { + if (itemFile.createNewFile()) { + ParallelUtils.log(Level.WARNING, "points_items.yml does not exist! Creating..."); + } + itemConfig.load(itemFile); + } catch (IOException e) { + ParallelUtils.log(Level.SEVERE, "Failed to create or read points_items.yml\n" + e); + return false; + } catch (Exception e) { + ParallelUtils.log(Level.SEVERE, "Failed to load points_items.yml\n" + e); + return false; + } + for (String key : itemConfig.getKeys(false)) { + String id = itemConfig.getString(key + ".id"); + Material material = Material.valueOf(itemConfig.getString(key + ".material")); + int modelData = itemConfig.getInt(key + ".modeldata"); + int cost = itemConfig.getInt(key + ".cost"); + String permission = itemConfig.getString(key + ".permission"); + List commands = (List)itemConfig.getList(key + ".commands"); + redeemableItems.add(new RedeemableItem(material, cost, permission, modelData, commands)); + } + ParallelUtils.log(Level.WARNING, "Loaded " + redeemableItems.size() + " redeemable items."); + } + public static Points get() { return Instance; } } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/RedeemableItem.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/RedeemableItem.java index 8d48073e..0636883c 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/RedeemableItem.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/RedeemableItem.java @@ -12,19 +12,23 @@ public class RedeemableItem { private final int requiredPoints; + private final String permission; + private final List commands; - public RedeemableItem(Material material, int requiredPoints, List commands) { + public RedeemableItem(Material material, int requiredPoints, string permission, List commands) { this.material = material; this.modelData = -1; this.requiredPoints = requiredPoints; + this.permission = permission; this.commands = commands; } - public RedeemableItem(Material material, int requiredPoints, int modelData, List commands) { + public RedeemableItem(Material material, int requiredPoints, string permission, int modelData, List commands) { this.material = material; this.modelData = modelData; this.requiredPoints = requiredPoints; + this.permission = permission; this.commands = commands; } @@ -38,5 +42,7 @@ public int getModelData() { public int getRequiredPoints() { return requiredPoints; } + public string getPermission() { return permission; } + public List getCommands() { return commands; } } diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/gui/PointsRedeemInventory.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/gui/PointsRedeemInventory.java index 6b0664eb..ba5522d5 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/gui/PointsRedeemInventory.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/gui/PointsRedeemInventory.java @@ -23,14 +23,14 @@ public class PointsRedeemInventory extends GUIInventory { private static List redeemableItems = new ArrayList<>(); public PointsRedeemInventory() { - super(54, Component.text("Advancement Points Redemption", NamedTextColor.GOLD, TextDecoration.BOLD)); + super(45, Component.text("Advancement Points Redemption", NamedTextColor.GOLD, TextDecoration.BOLD)); ItemStack exit = new ItemStack(Material.BARRIER); ItemMeta meta = exit.getItemMeta(); meta.displayName(Component.text("Exit GUI", NamedTextColor.RED).decoration(TextDecoration.ITALIC, false)); exit.setItemMeta(meta); - inventory.setItem(49, exit); + inventory.setItem(40, exit); } @@ -71,9 +71,10 @@ public void onOpen(Player player) { @Override public void onSlotClicked(Player player, int slotNum, ItemStack itemClicked) { - if (slotNum > 8 && slotNum < 45) { + if (slotNum > 8 && slotNum < 36) { + RedeemableItem clicked = redeemableItems.get(slotNum - 9); // yes this looks very stupid I know - if (player.hasPermission("parallelutils.points.slot" + slotNum)) { + if (player.hasPermission(clicked.getPermission())) { player.playSound(player.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1, 1); player.closeInventory(); ParallelChat.sendParallelMessageTo(player, "You have already redeemed that item!"); @@ -89,7 +90,7 @@ public void onSlotClicked(Player player, int slotNum, ItemStack itemClicked) { player.closeInventory(); ParallelChat.sendParallelMessageTo(player, Component.text("Successfully redeemed the ", NamedTextColor.GREEN).append(itemClicked.displayName())); for (String s : redeemableItems.get(slotNum - 9).getCommands()) { - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), s); + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), s.replace("%player%", player.getName())); } } if (slotNum == 49) { From 17dce39bf1fe21c457249816fc94cfd1062c99f4 Mon Sep 17 00:00:00 2001 From: EBro912 Date: Sat, 25 May 2024 01:12:45 -0400 Subject: [PATCH 45/52] missing function call --- .../java/parallelmc/parallelutils/modules/points/Points.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java index 4c014230..9952c612 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java @@ -70,7 +70,7 @@ public void onEnable() { puPlugin.getCommand("openpointsredemption").setExecutor(new OpenPointsRedemption()); loadAdvancements(); - + loadItems(); loadPlayerPoints(); Instance = this; From ffdead66f4b4712d40934a996b61318924b383ec Mon Sep 17 00:00:00 2001 From: EBro912 Date: Sat, 25 May 2024 01:13:23 -0400 Subject: [PATCH 46/52] remove unused field --- .../java/parallelmc/parallelutils/modules/points/Points.java | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java index 9952c612..d0a824a1 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java @@ -266,7 +266,6 @@ public void loadItems() { return false; } for (String key : itemConfig.getKeys(false)) { - String id = itemConfig.getString(key + ".id"); Material material = Material.valueOf(itemConfig.getString(key + ".material")); int modelData = itemConfig.getInt(key + ".modeldata"); int cost = itemConfig.getInt(key + ".cost"); From d818efab38c44f6d4d3ec283d29cb413f022dafb Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Sat, 25 May 2024 13:02:52 -0400 Subject: [PATCH 47/52] small fixes --- .../parallelmc/parallelutils/modules/points/Points.java | 7 ++++--- .../parallelutils/modules/points/RedeemableItem.java | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java index d0a824a1..d26fd443 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/Points.java @@ -1,6 +1,7 @@ package parallelmc.parallelutils.modules.points; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.advancement.Advancement; import org.bukkit.configuration.file.FileConfiguration; @@ -252,7 +253,7 @@ public int recalculatePlayerPoints() { public void loadItems() { File itemFile = new File(puPlugin.getDataFolder(), "points_items.yml"); - FileConfiguration itemConfig = new YamlConfiguration; + FileConfiguration itemConfig = new YamlConfiguration(); try { if (itemFile.createNewFile()) { ParallelUtils.log(Level.WARNING, "points_items.yml does not exist! Creating..."); @@ -260,10 +261,10 @@ public void loadItems() { itemConfig.load(itemFile); } catch (IOException e) { ParallelUtils.log(Level.SEVERE, "Failed to create or read points_items.yml\n" + e); - return false; + // return false; } catch (Exception e) { ParallelUtils.log(Level.SEVERE, "Failed to load points_items.yml\n" + e); - return false; + // return false; } for (String key : itemConfig.getKeys(false)) { Material material = Material.valueOf(itemConfig.getString(key + ".material")); diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/points/RedeemableItem.java b/modules/src/main/java/parallelmc/parallelutils/modules/points/RedeemableItem.java index 0636883c..c42cb4b2 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/points/RedeemableItem.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/points/RedeemableItem.java @@ -16,7 +16,7 @@ public class RedeemableItem { private final List commands; - public RedeemableItem(Material material, int requiredPoints, string permission, List commands) { + public RedeemableItem(Material material, int requiredPoints, String permission, List commands) { this.material = material; this.modelData = -1; this.requiredPoints = requiredPoints; @@ -24,7 +24,7 @@ public RedeemableItem(Material material, int requiredPoints, string permission, this.commands = commands; } - public RedeemableItem(Material material, int requiredPoints, string permission, int modelData, List commands) { + public RedeemableItem(Material material, int requiredPoints, String permission, int modelData, List commands) { this.material = material; this.modelData = modelData; this.requiredPoints = requiredPoints; @@ -42,7 +42,7 @@ public int getModelData() { public int getRequiredPoints() { return requiredPoints; } - public string getPermission() { return permission; } + public String getPermission() { return permission; } public List getCommands() { return commands; } } From 64418631ab611699ebccc28f92c341e24e54b247 Mon Sep 17 00:00:00 2001 From: UnknownSilicon <14339279+UnknownSilicon@users.noreply.github.com> Date: Sat, 25 May 2024 16:01:17 -0400 Subject: [PATCH 48/52] Update parallelitems --- .../main/java/parallelmc/parallelutils/modules/parallelitems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems b/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems index 5a272dd8..14288534 160000 --- a/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems +++ b/modules/src/main/java/parallelmc/parallelutils/modules/parallelitems @@ -1 +1 @@ -Subproject commit 5a272dd85c53769a3895983db61e8c6959bcf346 +Subproject commit 14288534ae0b3c0e2a4d20dadf01eba46eea1297 From a226441c97966c32cb5abe3d3ee7ee8bf053cd72 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Sun, 11 Aug 2024 01:17:07 -0400 Subject: [PATCH 49/52] Shiba Inu size modification code --- .../modules/bitsandbobs/BitsAndBobs.java | 1 + .../bitsandbobs/minimodules/EntityTweaks.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/EntityTweaks.java diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java index 56b26788..01b54521 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java @@ -61,6 +61,7 @@ public void onEnable() { manager.registerEvents(new OnPvp(), plugin); manager.registerEvents(new ShardLotto(), plugin); manager.registerEvents(new ChickenFeatherDrops(), plugin); + manager.registerEvents(new EntityTweaks(), plugin); if (config.getBoolean("disable-ender-chests", false)) { manager.registerEvents(new DisableEnderChest(), plugin); diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/EntityTweaks.java b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/EntityTweaks.java new file mode 100644 index 00000000..0fe3eb53 --- /dev/null +++ b/modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/minimodules/EntityTweaks.java @@ -0,0 +1,26 @@ +package parallelmc.parallelutils.modules.bitsandbobs.minimodules; + +import org.bukkit.NamespacedKey; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeInstance; +import org.bukkit.entity.Wolf; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.CreatureSpawnEvent; + +public class EntityTweaks implements Listener { + + @EventHandler + public void onShibaInuSpawn(CreatureSpawnEvent event) { + if (event.getEntity() instanceof Wolf wolf) { + // Check if the wolf is a shiba inu variant + if (wolf.getVariant().getKey().equals(NamespacedKey.fromString("parallel:shiba_inu"))) { + // Set scale to 0.8 + AttributeInstance scale = wolf.getAttribute(Attribute.GENERIC_SCALE); + if (scale != null) { + scale.setBaseValue(0.8D); + } + } + } + } +} From 447590782da303079c589234ed11cdb88dcf3ef5 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Sun, 11 Aug 2024 01:36:39 -0400 Subject: [PATCH 50/52] Initial 1.21.1 updates --- api/build.gradle | 6 +++--- build.gradle | 6 +++--- modules/build.gradle | 6 +++--- .../modules/charms/util/EnchantGlow.java | 11 +++++++++++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index 29abd160..25d7c86d 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -28,7 +28,7 @@ repositories { dependencies { //compileOnly 'io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT' - paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.6-R0.1-SNAPSHOT") + paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.21.1-R0.1-SNAPSHOT") implementation 'org.jetbrains:annotations:24.0.1' testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2' @@ -37,8 +37,8 @@ dependencies { compileOnly fileTree('libs') { include '*.jar' } compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.10' implementation 'com.mysql:mysql-connector-j:8.3.0' - compileOnly 'com.comphenix.protocol:ProtocolLib:5.2.0-SNAPSHOT' - compileOnly 'dev.esophose:playerparticles:8.5' + compileOnly 'com.comphenix.protocol:ProtocolLib:5.3.0-SNAPSHOT' + compileOnly 'dev.esophose:playerparticles:8.6' implementation 'org.reflections:reflections:0.10.2' } diff --git a/build.gradle b/build.gradle index 6b56527e..40ca693a 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ java { paperweight.reobfArtifactConfiguration = ReobfArtifactConfiguration.getMOJANG_PRODUCTION() dependencies { - paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.6-R0.1-SNAPSHOT") + paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.21.1-R0.1-SNAPSHOT") } compileJava.options.encoding = "UTF-8" @@ -42,12 +42,12 @@ allprojects { } dependencies { - paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.6-R0.1-SNAPSHOT") + paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.21.1-R0.1-SNAPSHOT") //paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT") //compileOnly "io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT" compileOnly 'net.luckperms:api:5.4' - compileOnly 'dev.esophose:playerparticles:8.5' + compileOnly 'dev.esophose:playerparticles:8.6' compileOnly "com.github.MilkBowl:VaultAPI:1.7.1" } } \ No newline at end of file diff --git a/modules/build.gradle b/modules/build.gradle index ebd33b37..d784677e 100644 --- a/modules/build.gradle +++ b/modules/build.gradle @@ -27,9 +27,9 @@ dependencies { compileOnly fileTree('libs') { include '*.jar' } compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.10' compileOnly 'com.mysql:mysql-connector-j:8.3.0' - compileOnly 'com.comphenix.protocol:ProtocolLib:5.2.0-SNAPSHOT' - compileOnly 'dev.esophose:playerparticles:8.5' - compileOnly "io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT" + compileOnly 'com.comphenix.protocol:ProtocolLib:5.3.0-SNAPSHOT' + compileOnly 'dev.esophose:playerparticles:8.6' + compileOnly "io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT" } def names = [] diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java b/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java index 30bd63e4..25d0961e 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java @@ -9,6 +9,7 @@ import org.bukkit.entity.EntityCategory; import org.bukkit.entity.EntityType; import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import parallelmc.parallelutils.ParallelUtils; @@ -88,6 +89,11 @@ public int getMaxModifiedCost(int level) { return 0; } + @Override + public int getAnvilCost() { + return 0; + } + @Override public @NotNull EnchantmentRarity getRarity() { return null; @@ -108,6 +114,11 @@ public float getDamageIncrease(int i, @NotNull EntityType entityType) { return Set.of(); } + @Override + public @NotNull Set getActiveSlotGroups() { + return Set.of(); + } + @Override public @NotNull String translationKey() { return ""; From 7ac42adf849cb7a0688e96d69417507162f5e09e Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Sat, 26 Oct 2024 15:54:21 -0400 Subject: [PATCH 51/52] Fix ProtocolLib not building --- api/build.gradle | 2 +- modules/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index 25d7c86d..2cd2d84e 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -37,7 +37,7 @@ dependencies { compileOnly fileTree('libs') { include '*.jar' } compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.10' implementation 'com.mysql:mysql-connector-j:8.3.0' - compileOnly 'com.comphenix.protocol:ProtocolLib:5.3.0-SNAPSHOT' + compileOnly 'com.comphenix.protocol:ProtocolLib:5.3.0' compileOnly 'dev.esophose:playerparticles:8.6' implementation 'org.reflections:reflections:0.10.2' } diff --git a/modules/build.gradle b/modules/build.gradle index d784677e..e9b72011 100644 --- a/modules/build.gradle +++ b/modules/build.gradle @@ -27,7 +27,7 @@ dependencies { compileOnly fileTree('libs') { include '*.jar' } compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.10' compileOnly 'com.mysql:mysql-connector-j:8.3.0' - compileOnly 'com.comphenix.protocol:ProtocolLib:5.3.0-SNAPSHOT' + compileOnly 'com.comphenix.protocol:ProtocolLib:5.3.0' compileOnly 'dev.esophose:playerparticles:8.6' compileOnly "io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT" } From d6deb9022bf0e9d9335c2971a4b16fe24f90a073 Mon Sep 17 00:00:00 2001 From: Diamondback88 <23108617+Diamondback88@users.noreply.github.com> Date: Sat, 26 Oct 2024 16:28:47 -0400 Subject: [PATCH 52/52] Enchantment temp fixes, this has to be permanently fixed soon --- .../modules/charms/util/EnchantGlow.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java b/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java index 25d0961e..c787c15e 100644 --- a/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java +++ b/modules/src/main/java/parallelmc/parallelutils/modules/charms/util/EnchantGlow.java @@ -1,6 +1,7 @@ package parallelmc.parallelutils.modules.charms.util; import io.papermc.paper.enchantments.EnchantmentRarity; +import io.papermc.paper.registry.set.RegistryKeySet; import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import org.bukkit.NamespacedKey; @@ -11,7 +12,9 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ItemType; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import parallelmc.parallelutils.ParallelUtils; import java.util.Set; @@ -119,6 +122,31 @@ public float getDamageIncrease(int i, @NotNull EntityType entityType) { return Set.of(); } + @Override + public @NotNull Component description() { + return null; + } + + @Override + public @NotNull RegistryKeySet getSupportedItems() { + return null; + } + + @Override + public @Nullable RegistryKeySet getPrimaryItems() { + return null; + } + + @Override + public int getWeight() { + return 0; + } + + @Override + public @NotNull RegistryKeySet getExclusiveWith() { + return null; + } + @Override public @NotNull String translationKey() { return "";