From 216ae7c95be08b841b32fde3d6f1a89bc860c17c Mon Sep 17 00:00:00 2001 From: anon8281 Date: Sun, 25 Jun 2023 19:29:43 +0300 Subject: [PATCH 01/11] Folia support --- pom.xml | 24 ++++-- src/com/dre/brewery/BCauldron.java | 4 +- src/com/dre/brewery/BDistiller.java | 11 +-- src/com/dre/brewery/BPlayer.java | 17 +++-- src/com/dre/brewery/BSealer.java | 5 +- src/com/dre/brewery/Barrel.java | 4 +- src/com/dre/brewery/P.java | 74 +++++++++---------- src/com/dre/brewery/filedata/BData.java | 4 +- src/com/dre/brewery/filedata/DataSave.java | 6 +- src/com/dre/brewery/filedata/ReadOldData.java | 4 +- .../brewery/listeners/InventoryListener.java | 4 +- .../dre/brewery/listeners/PlayerListener.java | 2 +- .../dre/brewery/listeners/WorldListener.java | 2 +- src/com/dre/brewery/utility/SQLSync.java | 8 +- 14 files changed, 89 insertions(+), 80 deletions(-) diff --git a/pom.xml b/pom.xml index 3fdc8c1e..9b185965 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.1 + 3.5.0 package @@ -58,6 +58,7 @@ org.bstats:* + com.github.Anon8281:* @@ -65,6 +66,10 @@ org.bstats com.dre.brewery.integration.bstats + + com.github.Anon8281.universalScheduler + com.dre.brewery.integration.universalScheduler + @@ -127,11 +132,11 @@ chestshop-repo https://repo.minebench.de/ - - - CodeMC - https://repo.codemc.org/repository/maven-public - + + + CodeMC + https://repo.codemc.org/repository/maven-public + MMOPlugins @@ -142,7 +147,6 @@ Lichtspiele https://nexus.lichtspiele.org/repository/releases/ - @@ -320,5 +324,11 @@ 16.0.2 compile + + com.github.Anon8281 + UniversalScheduler + 0.1.3 + compile + diff --git a/src/com/dre/brewery/BCauldron.java b/src/com/dre/brewery/BCauldron.java index c9907c11..71a4d4ef 100644 --- a/src/com/dre/brewery/BCauldron.java +++ b/src/com/dre/brewery/BCauldron.java @@ -441,7 +441,7 @@ public static void clickCauldron(PlayerInteractEvent event) { if (event.getHand() == EquipmentSlot.HAND) { final UUID id = player.getUniqueId(); plInteracted.add(id); - P.p.getServer().getScheduler().runTask(P.p, () -> plInteracted.remove(id)); + P.getScheduler().runTask(() -> plInteracted.remove(id)); } else if (event.getHand() == EquipmentSlot.OFF_HAND) { if (!plInteracted.remove(player.getUniqueId())) { item = player.getInventory().getItemInMainHand(); @@ -563,7 +563,7 @@ public static void save(ConfigurationSection config, ConfigurationSection oldDat // bukkit bug not updating the inventory while executing event, have to // schedule the give public static void giveItem(final Player player, final ItemStack item) { - P.p.getServer().getScheduler().runTaskLater(P.p, () -> player.getInventory().addItem(item), 1L); + P.getScheduler().runTaskLater(() -> player.getInventory().addItem(item), 1L); } } diff --git a/src/com/dre/brewery/BDistiller.java b/src/com/dre/brewery/BDistiller.java index bdafa878..0596be54 100644 --- a/src/com/dre/brewery/BDistiller.java +++ b/src/com/dre/brewery/BDistiller.java @@ -1,6 +1,8 @@ package com.dre.brewery; import com.dre.brewery.lore.BrewLore; +import com.github.Anon8281.universalScheduler.UniversalRunnable; +import com.github.Anon8281.universalScheduler.scheduling.tasks.MyScheduledTask; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; @@ -10,7 +12,6 @@ import org.bukkit.inventory.BrewerInventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.scheduler.BukkitRunnable; import java.util.HashMap; import java.util.Map; @@ -29,7 +30,7 @@ public class BDistiller { private static final int DISTILLTIME = 400; private static Map trackedDistillers = new HashMap<>(); - private int taskId; + private MyScheduledTask task; private int runTime = -1; private int brewTime = -1; private Block standBlock; @@ -41,11 +42,11 @@ public BDistiller(Block standBlock, int fuel) { } public void cancelDistill() { - Bukkit.getScheduler().cancelTask(taskId); // cancel prior + task.cancel(); } public void start() { - taskId = new DistillRunnable().runTaskTimer(P.p, 2L, 1L).getTaskId(); + task = new DistillRunnable().runTaskTimer(P.p, 2L, 1L); } public static void distillerClick(InventoryClickEvent event) { @@ -167,7 +168,7 @@ public static void showAlc(BrewerInventory inv, Brew[] contents) { } } - public class DistillRunnable extends BukkitRunnable { + public class DistillRunnable extends UniversalRunnable { private Brew[] contents = null; @Override diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index 47074438..8b0cd8bb 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -9,6 +9,7 @@ import com.dre.brewery.recipe.BEffect; import com.dre.brewery.utility.BUtil; import com.dre.brewery.utility.PermissionUtil; +import com.github.Anon8281.universalScheduler.scheduling.tasks.MyScheduledTask; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Location; @@ -32,7 +33,7 @@ public class BPlayer { private static Map players = new HashMap<>();// Players uuid and BPlayer private static Map pTasks = new HashMap<>();// Player and count - private static int taskId; + private static MyScheduledTask task; private static Random pukeRand; private final String uuid; @@ -218,8 +219,8 @@ public void showDrunkeness(Player player) { try { // It this returns false, then the Action Bar is not supported. Do not repeat the message as it was sent into chat if (sendDrunkenessMessage(player)) { - P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> sendDrunkenessMessage(player), 40); - P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> sendDrunkenessMessage(player), 80); + P.getScheduler().runTaskLater(() -> sendDrunkenessMessage(player), 40); + P.getScheduler().runTaskLater(() -> sendDrunkenessMessage(player), 80); } } catch (Exception e) { e.printStackTrace(); @@ -303,7 +304,7 @@ public boolean sendDrunkenessMessage(Player player) { b.append("ยง7]"); final String text = b.toString(); if (hangover && P.use1_11) { - P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> player.sendTitle("", text, 30, 100, 90), 160); + P.getScheduler().runTaskLater(() -> player.sendTitle("", text, 30, 100, 90), 160); return false; } try { @@ -321,7 +322,7 @@ public void drinkCap(Player player) { drunkeness = 100; syncToSQL(false); if (BConfig.overdrinkKick && !player.hasPermission("brewery.bypass.overdrink")) { - P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> passOut(player), 1); + P.getScheduler().runTaskLater(() -> passOut(player), 1); } else { addPuke(player, 60 + (int) (Math.random() * 60.0)); P.p.msg(player, P.p.languageReader.get("Player_CantDrink")); @@ -467,7 +468,7 @@ public void join(final Player player) { return; } // delayed login event as the player is not fully accessible pre login - P.p.getServer().getScheduler().runTaskLater(P.p, () -> login(player), 1L); + P.getScheduler().runTaskLater(() -> login(player), 1L); } // he may be having a hangover @@ -573,7 +574,7 @@ public static void addPuke(Player player, int count) { BUtil.reapplyPotionEffect(player, PotionEffectType.HUNGER.createEffect(80, 4), true); if (pTasks.isEmpty()) { - taskId = P.p.getServer().getScheduler().scheduleSyncRepeatingTask(P.p, BPlayer::pukeTask, 1L, 1L); + task = P.getScheduler().runTaskTimer(P.p, BPlayer::pukeTask, 1L, 1L); } pTasks.put(player, event.getCount()); } @@ -594,7 +595,7 @@ public static void pukeTask() { } } if (pTasks.isEmpty()) { - P.p.getServer().getScheduler().cancelTask(taskId); + task.cancel(); } } diff --git a/src/com/dre/brewery/BSealer.java b/src/com/dre/brewery/BSealer.java index 7ab15f9f..c12ad14a 100644 --- a/src/com/dre/brewery/BSealer.java +++ b/src/com/dre/brewery/BSealer.java @@ -1,5 +1,6 @@ package com.dre.brewery; +import com.github.Anon8281.universalScheduler.scheduling.tasks.MyScheduledTask; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.Sound; @@ -30,7 +31,7 @@ public class BSealer implements InventoryHolder { private final Player player; private short[] slotTime = new short[9]; private ItemStack[] contents = null; - private BukkitTask task; + private MyScheduledTask task; public BSealer(Player player) { this.player = player; @@ -56,7 +57,7 @@ public BSealer(Player player) { public void clickInv() { contents = null; if (task == null) { - task = P.p.getServer().getScheduler().runTaskTimer(P.p, this::itemChecking, 1, 1); + task = P.getScheduler().runTaskTimer(P.p, this::itemChecking, 1, 1); } } diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index 0c880f1d..86298d05 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -10,6 +10,7 @@ import com.dre.brewery.utility.BUtil; import com.dre.brewery.utility.BoundingBox; import com.dre.brewery.utility.LegacyUtil; +import com.github.Anon8281.universalScheduler.UniversalRunnable; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; @@ -24,7 +25,6 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -551,7 +551,7 @@ public static void save(ConfigurationSection config, ConfigurationSection oldDat } } - public static class BarrelCheck extends BukkitRunnable { + public static class BarrelCheck extends UniversalRunnable { @Override public void run() { boolean repeat = true; diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 6037361e..3c8caab2 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -1,34 +1,27 @@ /** - * - * Brewery Minecraft-Plugin for an alternate Brewing Process - * Copyright (C) 2021 Milan Albrecht - * - * This file is part of Brewery. - * - * Brewery is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Brewery is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Brewery. If not, see . - * + * Brewery Minecraft-Plugin for an alternate Brewing Process + * Copyright (C) 2021 Milan Albrecht + *

+ * This file is part of Brewery. + *

+ * Brewery is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * Brewery is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with Brewery. If not, see . */ - package com.dre.brewery; -import com.dre.brewery.filedata.BConfig; -import com.dre.brewery.filedata.BData; -import com.dre.brewery.filedata.DataSave; -import com.dre.brewery.filedata.LanguageReader; -import com.dre.brewery.filedata.UpdateChecker; +import com.dre.brewery.filedata.*; import com.dre.brewery.integration.ChestShopListener; import com.dre.brewery.integration.IntegrationListener; import com.dre.brewery.integration.ShopKeepersListener; @@ -40,6 +33,8 @@ import com.dre.brewery.utility.BUtil; import com.dre.brewery.utility.LegacyUtil; import com.dre.brewery.utility.Stats; +import com.github.Anon8281.universalScheduler.UniversalScheduler; +import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -51,7 +46,6 @@ import java.sql.SQLException; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import java.util.function.Function; @@ -65,6 +59,8 @@ public class P extends JavaPlugin { public static boolean use1_13; public static boolean use1_14; + private static TaskScheduler scheduler; + // Listeners public BlockListener blockListener; public PlayerListener playerListener; @@ -86,6 +82,7 @@ public class P extends JavaPlugin { @Override public void onEnable() { p = this; + scheduler = UniversalScheduler.getScheduler(p); // Version check String v = Bukkit.getBukkitVersion(); @@ -167,17 +164,17 @@ public void onEnable() { } // Heartbeat - p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 650, 1200); - p.getServer().getScheduler().runTaskTimer(p, new DrunkRunnable(), 120, 120); + P.getScheduler().runTaskTimer(new BreweryRunnable(), 650, 1200); + P.getScheduler().runTaskTimer(new DrunkRunnable(), 120, 120); if (use1_9) { - p.getServer().getScheduler().runTaskTimer(p, new CauldronParticles(), 1, 1); + P.getScheduler().runTaskTimer(new CauldronParticles(), 1, 1); } // Disable Update Check for older mc versions if (use1_14 && BConfig.updateCheck) { try { - p.getServer().getScheduler().runTaskLaterAsynchronously(p, new UpdateChecker(), 135); + P.getScheduler().runTaskLaterAsynchronously(new UpdateChecker(), 135); } catch (Exception e) { e.printStackTrace(); } @@ -193,7 +190,7 @@ public void onDisable() { HandlerList.unregisterAll(this); // Stop shedulers - getServer().getScheduler().cancelTasks(this); + getScheduler().cancelTasks(this); if (p == null) { return; @@ -309,6 +306,10 @@ public static P getInstance() { return p; } + public static TaskScheduler getScheduler() { + return scheduler; + } + // Utility public void msg(CommandSender sender, String msg) { @@ -387,13 +388,8 @@ public class BreweryRunnable implements Runnable { public void run() { long t1 = System.nanoTime(); BConfig.reloader = null; - Iterator iter = BCauldron.bcauldrons.values().iterator(); - while (iter.hasNext()) { - // runs every min to update cooking time - if (!iter.next().onUpdate()) { - iter.remove(); - } - } + // runs every min to update cooking time + BCauldron.bcauldrons.values().removeIf(bCauldron -> !bCauldron.onUpdate()); long t2 = System.nanoTime(); Barrel.onUpdate();// runs every min to check and update ageing time long t3 = System.nanoTime(); @@ -411,7 +407,7 @@ public void run() { " | t2: " + (t3 - t2) / 1000000.0 + "ms" + " | t3: " + (t4 - t3) / 1000000.0 + "ms" + " | t4: " + (t5 - t4) / 1000000.0 + "ms" + - " | t5: " + (t6 - t5) / 1000000.0 + "ms" ); + " | t5: " + (t6 - t5) / 1000000.0 + "ms"); } } diff --git a/src/com/dre/brewery/filedata/BData.java b/src/com/dre/brewery/filedata/BData.java index d9b544dc..8e68fa44 100644 --- a/src/com/dre/brewery/filedata/BData.java +++ b/src/com/dre/brewery/filedata/BData.java @@ -181,7 +181,7 @@ public static void readData() { final List worlds = P.p.getServer().getWorlds(); if (BConfig.loadDataAsync) { - P.p.getServer().getScheduler().runTaskAsynchronously(P.p, () -> lwDataTask(worlds)); + P.getScheduler().runTaskAsynchronously(() -> lwDataTask(worlds)); } else { lwDataTask(worlds); } @@ -422,7 +422,7 @@ public static void loadWorldData(String uuid, World world) { } // Merge Loaded Data in Main Thread - P.p.getServer().getScheduler().runTask(P.p, () -> { + P.getScheduler().runTask(() -> { if (P.p.getServer().getWorld(world.getUID()) == null) { return; } diff --git a/src/com/dre/brewery/filedata/DataSave.java b/src/com/dre/brewery/filedata/DataSave.java index eaa69ed2..90532961 100644 --- a/src/com/dre/brewery/filedata/DataSave.java +++ b/src/com/dre/brewery/filedata/DataSave.java @@ -3,17 +3,17 @@ import com.dre.brewery.*; import com.dre.brewery.utility.BUtil; +import com.github.Anon8281.universalScheduler.UniversalRunnable; import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.scheduler.BukkitRunnable; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; -public class DataSave extends BukkitRunnable { +public class DataSave extends UniversalRunnable { public static int lastBackup = 0; public static int lastSave = 1; @@ -129,7 +129,7 @@ public void run() { P.p.debugLog("saving: " + ((System.nanoTime() - saveTime) / 1000000.0) + "ms"); if (P.p.isEnabled()) { - P.p.getServer().getScheduler().runTaskAsynchronously(P.p, new WriteData(data, worldData)); + P.getScheduler().runTaskAsynchronously(new WriteData(data, worldData)); } else { new WriteData(data, worldData).run(); } diff --git a/src/com/dre/brewery/filedata/ReadOldData.java b/src/com/dre/brewery/filedata/ReadOldData.java index 6db007a6..a0b2c67a 100644 --- a/src/com/dre/brewery/filedata/ReadOldData.java +++ b/src/com/dre/brewery/filedata/ReadOldData.java @@ -3,13 +3,13 @@ import java.io.File; +import com.github.Anon8281.universalScheduler.UniversalRunnable; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.scheduler.BukkitRunnable; import com.dre.brewery.P; -public class ReadOldData extends BukkitRunnable { +public class ReadOldData extends UniversalRunnable { public FileConfiguration data; public boolean done = false; diff --git a/src/com/dre/brewery/listeners/InventoryListener.java b/src/com/dre/brewery/listeners/InventoryListener.java index 676ff194..c22068f1 100644 --- a/src/com/dre/brewery/listeners/InventoryListener.java +++ b/src/com/dre/brewery/listeners/InventoryListener.java @@ -164,7 +164,7 @@ public void onInventoryClick(InventoryClickEvent event) { case MOVE_TO_OTHER_INVENTORY: case HOTBAR_SWAP: // Fix a Graphical glitch of item still showing colors until clicking it - P.p.getServer().getScheduler().runTask(P.p, () -> ((Player) event.getWhoClicked()).updateInventory()); + P.getScheduler().runTask(() -> ((Player) event.getWhoClicked()).updateInventory()); } } } @@ -238,7 +238,7 @@ public void onInventoryOpen(InventoryOpenEvent event) { if (!opening) { opening = true; Barrel finalBarrel = x; - P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> {finalBarrel.remove(null, null); opening = false;}, 100); + P.getScheduler().scheduleSyncDelayedTask(() -> {finalBarrel.remove(null, null); opening = false;}, 100); }*/ // Check for MC Barrel diff --git a/src/com/dre/brewery/listeners/PlayerListener.java b/src/com/dre/brewery/listeners/PlayerListener.java index 9e3a9489..451900b7 100644 --- a/src/com/dre/brewery/listeners/PlayerListener.java +++ b/src/com/dre/brewery/listeners/PlayerListener.java @@ -142,7 +142,7 @@ public void onPlayerInteract(PlayerInteractEvent event) { } if (useSlot != -1) { inv.setHeldItemSlot(useSlot); - P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> player.getInventory().setHeldItemSlot(held), 2); + P.getScheduler().runTaskLater(() -> player.getInventory().setHeldItemSlot(held), 2); } } diff --git a/src/com/dre/brewery/listeners/WorldListener.java b/src/com/dre/brewery/listeners/WorldListener.java index 1455b2cb..c96f0573 100644 --- a/src/com/dre/brewery/listeners/WorldListener.java +++ b/src/com/dre/brewery/listeners/WorldListener.java @@ -21,7 +21,7 @@ public class WorldListener implements Listener { public void onWorldLoad(WorldLoadEvent event) { final World world = event.getWorld(); if (BConfig.loadDataAsync) { - P.p.getServer().getScheduler().runTaskAsynchronously(P.p, () -> lwDataTask(world)); + P.getScheduler().runTaskAsynchronously(() -> lwDataTask(world)); } else { lwDataTask(world); } diff --git a/src/com/dre/brewery/utility/SQLSync.java b/src/com/dre/brewery/utility/SQLSync.java index 3087b01c..afad50ac 100644 --- a/src/com/dre/brewery/utility/SQLSync.java +++ b/src/com/dre/brewery/utility/SQLSync.java @@ -80,7 +80,7 @@ public void fetchPlayerLoginData(final UUID uuid) { if (statement.execute("SELECT * FROM Brewery_Z_BPlayers WHERE uuid = '" + uuid.toString() + "';")) { final ResultSet result = statement.getResultSet(); if (result.next()) { - P.p.getServer().getScheduler().runTask(P.p, () -> { + P.getScheduler().runTask(() -> { try { new BPlayer(uuid.toString(), result.getInt("quality"), result.getInt("drunkeness"), result.getInt("offlineDrunk")); } catch (SQLException e) { @@ -90,7 +90,7 @@ public void fetchPlayerLoginData(final UUID uuid) { return; } } - P.p.getServer().getScheduler().runTask(P.p, () -> BPlayer.sqlRemoved(uuid)); + P.getScheduler().runTask(() -> BPlayer.sqlRemoved(uuid)); } catch (Exception e) { e.printStackTrace(); } @@ -99,7 +99,7 @@ public void fetchPlayerLoginData(final UUID uuid) { private void initAsyncTask() { if (sqlTaskRunning) return; sqlTaskRunning = true; - P.p.getServer().getScheduler().runTaskAsynchronously(P.p, new SQLSaver()); + P.getScheduler().runTaskAsynchronously(new SQLSaver()); } @@ -230,7 +230,7 @@ public void run() { if (storedOfflineDrunk != d.offlineDrunk) { // The player is not offlineDrunk anymore, // Someone else is changing the mysql data - P.p.getServer().getScheduler().runTask(P.p, () -> BPlayer.sqlRemoved(d.uuid)); + P.getScheduler().runTask(() -> BPlayer.sqlRemoved(d.uuid)); continue; } } From ed4034835ec28bdea66324411165e02eeaa4b545 Mon Sep 17 00:00:00 2001 From: Sevastjan <80479533+Anon8281@users.noreply.github.com> Date: Sun, 25 Jun 2023 21:42:43 +0300 Subject: [PATCH 02/11] Update plugin.yml --- resources/plugin.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/plugin.yml b/resources/plugin.yml index 96cf9b36..d8590944 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -3,6 +3,7 @@ version: 3.1.1 main: com.dre.brewery.P softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault, ChestShop, Shopkeepers, Towny, BlockLocker, Slimefun] authors: [Milan Albrecht, Frank Baumann, ProgrammerDan, Daniel Saukel] +folia-supported: true api-version: 1.13 commands: brewery: From 38fb1542367f02169349d936c86d683a0ffe414d Mon Sep 17 00:00:00 2001 From: ewof Date: Tue, 4 Jul 2023 02:10:34 -0400 Subject: [PATCH 03/11] fix a lot of reading world async errors, which fixes reading worlddata.yml and cauldron particles --- src/com/dre/brewery/BCauldron.java | 4 ++- src/com/dre/brewery/Barrel.java | 34 ++++++++++++++----------- src/com/dre/brewery/P.java | 11 +++++++- src/com/dre/brewery/filedata/BData.java | 34 +++++++++++++++---------- 4 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/com/dre/brewery/BCauldron.java b/src/com/dre/brewery/BCauldron.java index 71a4d4ef..ddb49516 100644 --- a/src/com/dre/brewery/BCauldron.java +++ b/src/com/dre/brewery/BCauldron.java @@ -372,7 +372,9 @@ public static void processCookEffects() { for (BCauldron cauldron : bcauldrons.values()) { if (particleRandom.nextFloat() < chance) { - cauldron.cookEffect(); + P.getScheduler().runTask(cauldron.block.getLocation(), () -> { + cauldron.cookEffect(); + }); } } } diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index 86298d05..d4a31b20 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -11,6 +11,8 @@ import com.dre.brewery.utility.BoundingBox; import com.dre.brewery.utility.LegacyUtil; import com.github.Anon8281.universalScheduler.UniversalRunnable; + +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; @@ -359,6 +361,7 @@ public static boolean create(Block sign, Player player) { BarrelCreateEvent createEvent = new BarrelCreateEvent(barrel, player); P.p.getServer().getPluginManager().callEvent(createEvent); if (!createEvent.isCancelled()) { + Bukkit.getLogger().info("CCC"); barrels.add(0, barrel); return true; } @@ -559,21 +562,22 @@ public void run() { if (check < barrels.size()) { Barrel barrel = barrels.get(check); if (!barrel.checked) { - Block broken = barrel.body.getBrokenBlock(false); - if (broken != null) { - P.p.debugLog("Barrel at " - + broken.getWorld().getName() + "/" + broken.getX() + "/" + broken.getY() + "/" + broken.getZ() - + " has been destroyed unexpectedly, contents will drop"); - // remove the barrel if it was destroyed - barrel.remove(broken, null, true); - } else { - // Dont check this barrel again, its enough to check it once after every restart (and when randomly chosen) - // as now this is only the backup if we dont register the barrel breaking, - // for example when removing it with some world editor - barrel.checked = true; - } - repeat = false; - } + P.getScheduler().runTaskTimer(barrel.getSpigot().getLocation(), () -> { + Block broken = barrel.body.getBrokenBlock(false); + + if (broken != null) { + P.p.debugLog("Barrel at " + + broken.getWorld().getName() + "/" + broken.getX() + "/" + broken.getY() + "/" + broken.getZ() + + " has been destroyed unexpectedly, contents will drop"); + // remove the barrel if it was destroyed + barrel.remove(broken, null, true); + } else { + barrel.checked = true; + return; + } + }, 1L, 1L); + repeat = false; + }; check++; } else { check = 0; diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 3c8caab2..ece8e87f 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -45,6 +45,7 @@ import org.bukkit.plugin.java.JavaPlugin; import java.sql.SQLException; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.function.Function; @@ -389,7 +390,15 @@ public void run() { long t1 = System.nanoTime(); BConfig.reloader = null; // runs every min to update cooking time - BCauldron.bcauldrons.values().removeIf(bCauldron -> !bCauldron.onUpdate()); + Collection bCauldronsToRemove = BCauldron.bcauldrons.values(); + BCauldron.bcauldrons.values().forEach(bcauldron -> { + getScheduler().runTask(bcauldron.getBlock().getLocation(), () -> { + if (!bcauldron.onUpdate()) + bCauldronsToRemove.add(bcauldron); + }); + }); + BCauldron.bcauldrons.values().removeIf(bCaulron -> bCauldronsToRemove.contains(bCaulron)); + long t2 = System.nanoTime(); Barrel.onUpdate();// runs every min to check and update ageing time long t3 = System.nanoTime(); diff --git a/src/com/dre/brewery/filedata/BData.java b/src/com/dre/brewery/filedata/BData.java index 8e68fa44..9d1cc150 100644 --- a/src/com/dre/brewery/filedata/BData.java +++ b/src/com/dre/brewery/filedata/BData.java @@ -8,6 +8,8 @@ import com.dre.brewery.recipe.SimpleItem; import com.dre.brewery.utility.BUtil; import com.dre.brewery.utility.BoundingBox; + +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -334,6 +336,7 @@ public static void loadWorldData(String uuid, World world) { // block spigot is splitted into x/y/z String spigot = section.getString(barrel + ".spigot"); if (spigot != null) { + Bukkit.getLogger().info("LOL"); String[] splitted = spigot.split("/"); if (splitted.length == 3) { @@ -370,20 +373,23 @@ public static void loadWorldData(String uuid, World world) { } } - Barrel b; - if (invSection != null) { - b = new Barrel(block, sign, box, invSection.getValues(true), time, true); - } else { - // Barrel has no inventory - b = new Barrel(block, sign, box, null, time, true); - } - - if (b.getBody().getBounds() != null) { - initBarrels.add(b); - } else { - // The Barrel Bounds need recreating, as they were missing or corrupt - initBadBarrels.add(b); - } + final BoundingBox bbox = box; + P.getScheduler().runTask(block.getLocation(), () -> { + Barrel b; + if (invSection != null) { + b = new Barrel(block, sign, bbox, invSection.getValues(true), time, true); + } else { + // Barrel has no inventory + b = new Barrel(block, sign, bbox, null, time, true); + } + + if (b.getBody().getBounds() != null) { + initBarrels.add(b); + } else { + // The Barrel Bounds need recreating, as they were missing or corrupt + initBadBarrels.add(b); + } + }); } else { P.p.errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel); From 1e095fd21a6910cd97a71680a1325dcf0a3f7c75 Mon Sep 17 00:00:00 2001 From: ewof Date: Tue, 4 Jul 2023 02:13:09 -0400 Subject: [PATCH 04/11] remove debug prints --- src/com/dre/brewery/Barrel.java | 1 - src/com/dre/brewery/filedata/BData.java | 5 ----- 2 files changed, 6 deletions(-) diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index d4a31b20..6adc04cb 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -361,7 +361,6 @@ public static boolean create(Block sign, Player player) { BarrelCreateEvent createEvent = new BarrelCreateEvent(barrel, player); P.p.getServer().getPluginManager().callEvent(createEvent); if (!createEvent.isCancelled()) { - Bukkit.getLogger().info("CCC"); barrels.add(0, barrel); return true; } diff --git a/src/com/dre/brewery/filedata/BData.java b/src/com/dre/brewery/filedata/BData.java index 9d1cc150..65612033 100644 --- a/src/com/dre/brewery/filedata/BData.java +++ b/src/com/dre/brewery/filedata/BData.java @@ -2,14 +2,11 @@ import com.dre.brewery.*; import com.dre.brewery.lore.Base91DecoderStream; -import com.dre.brewery.recipe.CustomItem; import com.dre.brewery.recipe.Ingredient; -import com.dre.brewery.recipe.PluginItem; import com.dre.brewery.recipe.SimpleItem; import com.dre.brewery.utility.BUtil; import com.dre.brewery.utility.BoundingBox; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -24,7 +21,6 @@ import java.io.IOException; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.IntStream; public class BData { @@ -336,7 +332,6 @@ public static void loadWorldData(String uuid, World world) { // block spigot is splitted into x/y/z String spigot = section.getString(barrel + ".spigot"); if (spigot != null) { - Bukkit.getLogger().info("LOL"); String[] splitted = spigot.split("/"); if (splitted.length == 3) { From 816b95dce798ad5b8c4340ecef02b9f54fdb2309 Mon Sep 17 00:00:00 2001 From: anon8281 Date: Tue, 4 Jul 2023 13:08:15 +0300 Subject: [PATCH 05/11] Formatting fixes --- src/com/dre/brewery/BCauldron.java | 4 ++-- src/com/dre/brewery/Barrel.java | 31 ++++++++++++------------ src/com/dre/brewery/P.java | 15 ++++++------ src/com/dre/brewery/filedata/BData.java | 32 ++++++++++++------------- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/com/dre/brewery/BCauldron.java b/src/com/dre/brewery/BCauldron.java index ddb49516..b57a1a1d 100644 --- a/src/com/dre/brewery/BCauldron.java +++ b/src/com/dre/brewery/BCauldron.java @@ -373,8 +373,8 @@ public static void processCookEffects() { for (BCauldron cauldron : bcauldrons.values()) { if (particleRandom.nextFloat() < chance) { P.getScheduler().runTask(cauldron.block.getLocation(), () -> { - cauldron.cookEffect(); - }); + cauldron.cookEffect(); + }); } } } diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index 6adc04cb..7f3ae2da 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -562,21 +562,22 @@ public void run() { Barrel barrel = barrels.get(check); if (!barrel.checked) { P.getScheduler().runTaskTimer(barrel.getSpigot().getLocation(), () -> { - Block broken = barrel.body.getBrokenBlock(false); - - if (broken != null) { - P.p.debugLog("Barrel at " - + broken.getWorld().getName() + "/" + broken.getX() + "/" + broken.getY() + "/" + broken.getZ() - + " has been destroyed unexpectedly, contents will drop"); - // remove the barrel if it was destroyed - barrel.remove(broken, null, true); - } else { - barrel.checked = true; - return; - } - }, 1L, 1L); - repeat = false; - }; + Block broken = barrel.body.getBrokenBlock(false); + + if (broken != null) { + P.p.debugLog("Barrel at " + + broken.getWorld().getName() + "/" + broken.getX() + "/" + broken.getY() + "/" + broken.getZ() + + " has been destroyed unexpectedly, contents will drop"); + // remove the barrel if it was destroyed + barrel.remove(broken, null, true); + } else { + barrel.checked = true; + return; + } + }, 1L, 1L); + repeat = false; + } + ; check++; } else { check = 0; diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index ece8e87f..24263299 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -390,14 +390,13 @@ public void run() { long t1 = System.nanoTime(); BConfig.reloader = null; // runs every min to update cooking time - Collection bCauldronsToRemove = BCauldron.bcauldrons.values(); - BCauldron.bcauldrons.values().forEach(bcauldron -> { - getScheduler().runTask(bcauldron.getBlock().getLocation(), () -> { - if (!bcauldron.onUpdate()) - bCauldronsToRemove.add(bcauldron); - }); - }); - BCauldron.bcauldrons.values().removeIf(bCaulron -> bCauldronsToRemove.contains(bCaulron)); + Collection bCauldronsToRemove = BCauldron.bcauldrons.values(); + BCauldron.bcauldrons.values().forEach(bcauldron -> + getScheduler().runTask(bcauldron.getBlock().getLocation(), () -> { + if (!bcauldron.onUpdate()) + bCauldronsToRemove.add(bcauldron); + })); + BCauldron.bcauldrons.values().removeIf(bCaulron -> bCauldronsToRemove.contains(bCaulron)); long t2 = System.nanoTime(); Barrel.onUpdate();// runs every min to check and update ageing time diff --git a/src/com/dre/brewery/filedata/BData.java b/src/com/dre/brewery/filedata/BData.java index 65612033..17ab0fee 100644 --- a/src/com/dre/brewery/filedata/BData.java +++ b/src/com/dre/brewery/filedata/BData.java @@ -368,23 +368,23 @@ public static void loadWorldData(String uuid, World world) { } } - final BoundingBox bbox = box; + final BoundingBox bbox = box; P.getScheduler().runTask(block.getLocation(), () -> { - Barrel b; - if (invSection != null) { - b = new Barrel(block, sign, bbox, invSection.getValues(true), time, true); - } else { - // Barrel has no inventory - b = new Barrel(block, sign, bbox, null, time, true); - } - - if (b.getBody().getBounds() != null) { - initBarrels.add(b); - } else { - // The Barrel Bounds need recreating, as they were missing or corrupt - initBadBarrels.add(b); - } - }); + Barrel b; + if (invSection != null) { + b = new Barrel(block, sign, bbox, invSection.getValues(true), time, true); + } else { + // Barrel has no inventory + b = new Barrel(block, sign, bbox, null, time, true); + } + + if (b.getBody().getBounds() != null) { + initBarrels.add(b); + } else { + // The Barrel Bounds need recreating, as they were missing or corrupt + initBadBarrels.add(b); + } + }); } else { P.p.errorLog("Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel); From f1535385233503b001f3d09cf00d0549ed95b36b Mon Sep 17 00:00:00 2001 From: anon8281 Date: Tue, 4 Jul 2023 14:46:45 +0300 Subject: [PATCH 06/11] May fix code sequence --- src/com/dre/brewery/BCauldron.java | 2 +- src/com/dre/brewery/Barrel.java | 1 - src/com/dre/brewery/P.java | 10 +++++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/com/dre/brewery/BCauldron.java b/src/com/dre/brewery/BCauldron.java index b57a1a1d..45e1afd7 100644 --- a/src/com/dre/brewery/BCauldron.java +++ b/src/com/dre/brewery/BCauldron.java @@ -27,7 +27,7 @@ public class BCauldron { public static final int PARTICLEPAUSE = 15; public static Random particleRandom = new Random(); private static Set plInteracted = new HashSet<>(); // Interact Event helper - public static Map bcauldrons = new HashMap<>(); // All active cauldrons. Mapped to their block for fast retrieve + public volatile static Map bcauldrons = new HashMap<>(); // All active cauldrons. Mapped to their block for fast retrieve private BIngredients ingredients = new BIngredients(); private final Block block; diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index 7f3ae2da..ab998838 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -577,7 +577,6 @@ public void run() { }, 1L, 1L); repeat = false; } - ; check++; } else { check = 0; diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 24263299..363bf87a 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -389,14 +389,14 @@ public class BreweryRunnable implements Runnable { public void run() { long t1 = System.nanoTime(); BConfig.reloader = null; + // runs every min to update cooking time Collection bCauldronsToRemove = BCauldron.bcauldrons.values(); - BCauldron.bcauldrons.values().forEach(bcauldron -> + bCauldronsToRemove.forEach(bcauldron -> getScheduler().runTask(bcauldron.getBlock().getLocation(), () -> { - if (!bcauldron.onUpdate()) - bCauldronsToRemove.add(bcauldron); - })); - BCauldron.bcauldrons.values().removeIf(bCaulron -> bCauldronsToRemove.contains(bCaulron)); + if (!bcauldron.onUpdate()) + BCauldron.bcauldrons.values().remove(bcauldron); + })); long t2 = System.nanoTime(); Barrel.onUpdate();// runs every min to check and update ageing time From 5e29223b202b9daecf804f5019bc14a6bf02f6dd Mon Sep 17 00:00:00 2001 From: anon8281 Date: Wed, 5 Jul 2023 05:24:26 +0300 Subject: [PATCH 07/11] NPE fix --- src/com/dre/brewery/Barrel.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index ab998838..6d3add1d 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -39,7 +39,7 @@ */ public class Barrel implements InventoryHolder { - public static List barrels = new ArrayList<>(); + public static volatile List barrels = new ArrayList<>(); private static int check = 0; // Which Barrel was last checked private final Block spigot; @@ -68,7 +68,6 @@ public Barrel(Block spigot, byte sign, BoundingBox bounds, Map i /** * Load from File *

If async: true, The Barrel Bounds will not be recreated when missing/corrupt, getBody().getBounds() will be null if it needs recreating - * */ public Barrel(Block spigot, byte sign, BoundingBox bounds, Map items, float time, boolean async) { this.spigot = spigot; @@ -92,7 +91,8 @@ public Barrel(Block spigot, byte sign, BoundingBox bounds, Map i public static void onUpdate() { for (Barrel barrel : barrels) { // Minecraft day is 20 min, so add 1/20 to the time every minute - barrel.time += (1.0 / 20.0); + if (barrel != null) + barrel.time += (1.0 / 20.0); } int numBarrels = barrels.size(); if (check == 0 && numBarrels > 0) { From c719a3f0d04acecdd6f76b01d62067425f944805 Mon Sep 17 00:00:00 2001 From: anon8281 Date: Wed, 5 Jul 2023 05:26:02 +0300 Subject: [PATCH 08/11] NPE fix (2) --- src/com/dre/brewery/Barrel.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index 6d3add1d..660d6555 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -268,7 +268,7 @@ public static Barrel get(Block block) { return null; } Material type = block.getType(); - if (LegacyUtil.isFence(type) || LegacyUtil.isSign(type) ) { + if (LegacyUtil.isFence(type) || LegacyUtil.isSign(type)) { return getBySpigot(block); } else { return getByWood(block); @@ -313,10 +313,11 @@ public static Barrel getByWood(Block wood) { if (LegacyUtil.isWoodPlanks(wood.getType()) || LegacyUtil.isWoodStairs(wood.getType())) { int i = 0; for (Barrel barrel : barrels) { - if (barrel.getSpigot().getWorld().equals(wood.getWorld()) && barrel.body.getBounds().contains(wood)) { - moveMRU(i); - return barrel; - } + if (barrel != null) + if (barrel.getSpigot().getWorld().equals(wood.getWorld()) && barrel.body.getBounds().contains(wood)) { + moveMRU(i); + return barrel; + } i++; } } @@ -377,8 +378,8 @@ public static boolean create(Block sign, Player player) { /** * Removes a barrel, throwing included potions to the ground * - * @param broken The Block that was broken - * @param breaker The Player that broke it, or null if not known + * @param broken The Block that was broken + * @param breaker The Player that broke it, or null if not known * @param dropItems If the items in the barrels inventory should drop to the ground */ public void remove(@Nullable Block broken, @Nullable Player breaker, boolean dropItems) { @@ -544,7 +545,7 @@ public static void save(ConfigurationSection config, ConfigurationSection oldDat } } // also save barrels that are not loaded - if (oldData != null){ + if (oldData != null) { for (String uuid : oldData.getKeys(false)) { if (!config.contains(uuid)) { config.set(uuid, oldData.get(uuid)); From a379b4344ed6ffefe2f6fa11f830e8f6a61a85f6 Mon Sep 17 00:00:00 2001 From: anon8281 Date: Wed, 5 Jul 2023 05:27:45 +0300 Subject: [PATCH 09/11] Fix "can't add effects to entities asynchronously" --- src/com/dre/brewery/BPlayer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index 8b0cd8bb..4b13e578 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -674,7 +674,7 @@ public void drunkEffects(Player player) { return; } for (PotionEffect effect : l) { - effect.apply(player); + P.getScheduler().runTask(player, () -> effect.apply(player)); } } From bff3f70a1bd13dfdc45c87f92cd2454341f386fb Mon Sep 17 00:00:00 2001 From: Sevastjan Date: Mon, 7 Aug 2023 14:56:23 +0300 Subject: [PATCH 10/11] Using ConcurrentHashMap for thread safety --- src/com/dre/brewery/BCauldron.java | 7 +++---- src/com/dre/brewery/BDistiller.java | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/com/dre/brewery/BCauldron.java b/src/com/dre/brewery/BCauldron.java index 45e1afd7..02868325 100644 --- a/src/com/dre/brewery/BCauldron.java +++ b/src/com/dre/brewery/BCauldron.java @@ -21,13 +21,14 @@ import org.jetbrains.annotations.Nullable; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; public class BCauldron { public static final byte EMPTY = 0, SOME = 1, FULL = 2; public static final int PARTICLEPAUSE = 15; public static Random particleRandom = new Random(); private static Set plInteracted = new HashSet<>(); // Interact Event helper - public volatile static Map bcauldrons = new HashMap<>(); // All active cauldrons. Mapped to their block for fast retrieve + public volatile static Map bcauldrons = new ConcurrentHashMap<>(); // All active cauldrons. Mapped to their block for fast retrieve private BIngredients ingredients = new BIngredients(); private final Block block; @@ -372,9 +373,7 @@ public static void processCookEffects() { for (BCauldron cauldron : bcauldrons.values()) { if (particleRandom.nextFloat() < chance) { - P.getScheduler().runTask(cauldron.block.getLocation(), () -> { - cauldron.cookEffect(); - }); + P.getScheduler().runTask(cauldron.block.getLocation(), cauldron::cookEffect); } } } diff --git a/src/com/dre/brewery/BDistiller.java b/src/com/dre/brewery/BDistiller.java index 0596be54..fb723698 100644 --- a/src/com/dre/brewery/BDistiller.java +++ b/src/com/dre/brewery/BDistiller.java @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * Updated for 1.9 to replicate the "Brewing" process for distilling. @@ -28,7 +29,7 @@ public class BDistiller { private static final int DISTILLTIME = 400; - private static Map trackedDistillers = new HashMap<>(); + private static Map trackedDistillers = new ConcurrentHashMap<>(); private MyScheduledTask task; private int runTime = -1; From 6124c369b294fdc2f90d40adc155951c5f0557e2 Mon Sep 17 00:00:00 2001 From: Sevastjan <80479533+Anon8281@users.noreply.github.com> Date: Wed, 24 Jan 2024 19:58:46 +0300 Subject: [PATCH 11/11] Fix scheduling + update Towny dependency --- pom.xml | 2 +- src/com/dre/brewery/BDistiller.java | 54 +++++++++++++++-------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index e7198ee8..050b7270 100644 --- a/pom.xml +++ b/pom.xml @@ -300,7 +300,7 @@ com.github.TownyAdvanced Towny - 0.100.0.0 + 0.100.1.0 provided diff --git a/src/com/dre/brewery/BDistiller.java b/src/com/dre/brewery/BDistiller.java index fb723698..15a3a5d7 100644 --- a/src/com/dre/brewery/BDistiller.java +++ b/src/com/dre/brewery/BDistiller.java @@ -174,38 +174,40 @@ public class DistillRunnable extends UniversalRunnable { @Override public void run() { - BlockState now = standBlock.getState(); - if (now instanceof BrewingStand) { - BrewingStand stand = (BrewingStand) now; - if (brewTime == -1) { // check at the beginning for distillables - if (!prepareForDistillables(stand)) { - return; + P.getScheduler().runTask(standBlock.getLocation(), () -> { + BlockState now = standBlock.getState(); + if (now instanceof BrewingStand) { + BrewingStand stand = (BrewingStand) now; + if (brewTime == -1) { // check at the beginning for distillables + if (!prepareForDistillables(stand)) { + return; + } } - } - brewTime--; // count down. - stand.setBrewingTime((int) ((float) brewTime / ((float) runTime / (float) DISTILLTIME)) + 1); - - if (brewTime <= 1) { // Done! - contents = getDistillContents(stand.getInventory()); // Get the contents again at the end just in case - stand.setBrewingTime(0); - stand.update(); - if (!runDistill(stand.getInventory(), contents)) { - this.cancel(); - trackedDistillers.remove(standBlock); - P.p.debugLog("All done distilling"); + brewTime--; // count down. + stand.setBrewingTime((int) ((float) brewTime / ((float) runTime / (float) DISTILLTIME)) + 1); + + if (brewTime <= 1) { // Done! + contents = getDistillContents(stand.getInventory()); // Get the contents again at the end just in case + stand.setBrewingTime(0); + stand.update(); + if (!runDistill(stand.getInventory(), contents)) { + this.cancel(); + trackedDistillers.remove(standBlock); + P.p.debugLog("All done distilling"); + } else { + brewTime = -1; // go again. + P.p.debugLog("Can distill more! Continuing."); + } } else { - brewTime = -1; // go again. - P.p.debugLog("Can distill more! Continuing."); + stand.update(); } } else { - stand.update(); + this.cancel(); + trackedDistillers.remove(standBlock); + P.p.debugLog("The block was replaced; not a brewing stand."); } - } else { - this.cancel(); - trackedDistillers.remove(standBlock); - P.p.debugLog("The block was replaced; not a brewing stand."); - } + }); } private boolean prepareForDistillables(BrewingStand stand) {