From 368195bed229e2dc7ab4d6ba6617a7563b47dd13 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 7 Oct 2022 20:21:41 +0200 Subject: [PATCH 1/9] Fix crashdetector on unclean shutdown --- SpigotCore_Main/src/de/steamwar/core/Core.java | 1 - 1 file changed, 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index ad70625..2fd4296 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -142,7 +142,6 @@ public class Core extends JavaPlugin{ @Override public void onDisable() { TinyProtocol.instance.close(); - crashDetector.stop(); errorHandler.unregister(); if(!standalone) { Statement.close(); From 297791ec60a65d86ad268bb0fe56f00214d3e8ce Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 8 Oct 2022 13:07:53 +0200 Subject: [PATCH 2/9] Fix crash logging --- SpigotCore_Main/src/de/steamwar/core/Core.java | 2 +- SpigotCore_Main/src/de/steamwar/core/CrashDetector.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index 2fd4296..5a68722 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -143,7 +143,7 @@ public class Core extends JavaPlugin{ public void onDisable() { TinyProtocol.instance.close(); errorHandler.unregister(); - if(!standalone) { + if(!standalone && crashDetector.onMainThread()) { Statement.close(); } } diff --git a/SpigotCore_Main/src/de/steamwar/core/CrashDetector.java b/SpigotCore_Main/src/de/steamwar/core/CrashDetector.java index 1320c2c..8d50dd3 100644 --- a/SpigotCore_Main/src/de/steamwar/core/CrashDetector.java +++ b/SpigotCore_Main/src/de/steamwar/core/CrashDetector.java @@ -20,6 +20,7 @@ package de.steamwar.core; import de.steamwar.sql.SWException; +import de.steamwar.sql.Statement; import org.bukkit.Bukkit; import java.util.Arrays; @@ -47,6 +48,10 @@ public class CrashDetector { watchdog.interrupt(); } + public boolean onMainThread() { + return Thread.currentThread() == mainThread; + } + private void run() { while (run) { long curTime = System.currentTimeMillis(); @@ -58,6 +63,7 @@ public class CrashDetector { if(Core.getInstance().isEnabled()) { Core.getInstance().onDisable(); } + Statement.close(); //System.exit(0); Does freeze, potential freezing issues: ConsoleRestoreHook, ApplicationShutdownHooks or DeleteOnExitHook Runtime.getRuntime().halt(0); } From c554d79fecf8c724537ab5bb801f828bad18a10c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 9 Oct 2022 14:44:35 +0200 Subject: [PATCH 3/9] Fix crash logging --- SpigotCore_Main/src/de/steamwar/core/CrashDetector.java | 1 + SpigotCore_Main/src/de/steamwar/sql/SWException.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/core/CrashDetector.java b/SpigotCore_Main/src/de/steamwar/core/CrashDetector.java index 8d50dd3..b4f612e 100644 --- a/SpigotCore_Main/src/de/steamwar/core/CrashDetector.java +++ b/SpigotCore_Main/src/de/steamwar/core/CrashDetector.java @@ -53,6 +53,7 @@ public class CrashDetector { } private void run() { + SWException.init(); while (run) { long curTime = System.currentTimeMillis(); if(curTime - TIMEOUT > lastTick.get()) { diff --git a/SpigotCore_Main/src/de/steamwar/sql/SWException.java b/SpigotCore_Main/src/de/steamwar/sql/SWException.java index 0622a89..c370744 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SWException.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SWException.java @@ -32,6 +32,10 @@ public class SWException { private static final String cwd = System.getProperty("user.dir"); private static final String server = new File(cwd).getName(); + public static void init() { + //force class loading + } + public static void log(String message, String stacktrace){ StringBuilder msgBuilder = new StringBuilder(message).append("\nPlayers: "); for(Player player : Bukkit.getOnlinePlayers()) From 26973bb840f7d2fb5b574a4d48cf5bba5d8d72c9 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 20 Oct 2022 20:11:12 +0200 Subject: [PATCH 4/9] Fix Rank 2 in Rank 1 Fight --- .../src/de/steamwar/inventory/SchematicSelector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index 0f6ba59..4620643 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -387,7 +387,7 @@ public class SchematicSelector { nodes.removeIf(node -> !node.isDir()); } if(target.target == Target.SCHEMATIC_TYPE) { - nodes.removeIf(node -> node.isDir() || !node.getSchemtype().equals(target.type)); + nodes.removeIf(node -> node.isDir() || !node.getSchemtype().equals(target.type) || node.getRank() > target.rank); } return nodes; } From 7ce6668de4c3ccf871b9a5287ee714121a1c6967 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 27 Oct 2022 12:58:16 +0200 Subject: [PATCH 5/9] Add AnvilInv LeftClick and SchematicSelector AnvilInv returns --- SpigotCore_Main/src/SpigotCore.properties | 1 + SpigotCore_Main/src/SpigotCore_de.properties | 1 + .../src/de/steamwar/inventory/SWAnvilInv.java | 4 +++ .../steamwar/inventory/SchematicSelector.java | 25 ++++++++++++++++--- .../SchematicSelectorInjectable.java | 7 ++++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/SpigotCore_Main/src/SpigotCore.properties b/SpigotCore_Main/src/SpigotCore.properties index 450de5a..388f441 100644 --- a/SpigotCore_Main/src/SpigotCore.properties +++ b/SpigotCore_Main/src/SpigotCore.properties @@ -42,6 +42,7 @@ SCHEM_SELECTOR_SORTING_UPDATE=Last update SCHEM_SELECTOR_SORTING_DIRECTION=§e{0} §7order SCHEM_SELECTOR_SORTING_ASC=Ascending SCHEM_SELECTOR_SORTING_DSC=Descending +SCHEM_SELECTOR_CLICK_BACK=§7Click to go back SCHEM_SELECTOR_ITEM_NAME=§e{0} SCHEM_SELECTOR_ITEM_NAME_FILTER=§7{0} diff --git a/SpigotCore_Main/src/SpigotCore_de.properties b/SpigotCore_Main/src/SpigotCore_de.properties index b5e089a..1279d36 100644 --- a/SpigotCore_Main/src/SpigotCore_de.properties +++ b/SpigotCore_Main/src/SpigotCore_de.properties @@ -42,6 +42,7 @@ SCHEM_SELECTOR_SORTING_UPDATE=Letztes Update SCHEM_SELECTOR_SORTING_DIRECTION=§7Richtung: §e{0} SCHEM_SELECTOR_SORTING_ASC=Aufsteigend SCHEM_SELECTOR_SORTING_DSC=Absteigend +SCHEM_SELECTOR_CLICK_BACK=§7Klicke hier, um zurückzugehen SCHEM_SELECTOR_CREATE_DIR_TITLE=Ordner erstellen diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWAnvilInv.java b/SpigotCore_Main/src/de/steamwar/inventory/SWAnvilInv.java index 8244390..733fae9 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SWAnvilInv.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SWAnvilInv.java @@ -66,6 +66,10 @@ public class SWAnvilInv { this.callback = callback; } + public void addLeftCallback(Runnable callback) { + builder.onLeftInputClick(p -> callback.run()); + } + public void addCloseCallback(Runnable callback) { builder.onClose(p -> callback.run()); } diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index 4620643..6582d12 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -25,11 +25,13 @@ import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; import lombok.*; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import java.text.MessageFormat; import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; public class SchematicSelector { @@ -249,9 +251,23 @@ public class SchematicSelector { return new SWListInv.SWListEntry<>(item, node); } + private void addLeftCloseAction(SWAnvilInv inv, Runnable runnable) { + AtomicBoolean wasLeft = new AtomicBoolean(false); + inv.addCloseCallback(() -> { + if(injectable.onAnvilInvCloseAction(this) == SchematicSelectorInjectable.AnvilInvCloseAction.REOPEN && !wasLeft.get()) { + player.closeInventory(); + Bukkit.getScheduler().runTaskLater(Core.getInstance(), runnable, 1); + } + }); + inv.addLeftCallback(() -> { + wasLeft.set(true); + runnable.run(); + }); + } + private void createFolderIn(SchematicNode parent) { SWAnvilInv inv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_CREATE_DIR_TITLE", player)); - inv.setItem(Material.CHEST); + inv.setItem(Material.CHEST, Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_CLICK_BACK", player)), false); inv.setCallback(s -> { if(!SchematicNode.invalidSchemName(new String[] {s})) { if(injectable.onFolderCreate(this, s)) { @@ -262,6 +278,7 @@ public class SchematicSelector { } player.closeInventory(); }); + addLeftCloseAction(inv, this::reOpen); inv.open(); } @@ -273,11 +290,12 @@ public class SchematicSelector { openFilter(); } else { SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_NAME", player)); - swAnvilInv.setItem(Material.NAME_TAG); + swAnvilInv.setItem(Material.NAME_TAG, Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_CLICK_BACK", player)), false); swAnvilInv.setCallback(s -> { filter.setName(s); openFilter(); }); + addLeftCloseAction(swAnvilInv, this::openFilter); swAnvilInv.open(); } }; @@ -293,13 +311,14 @@ public class SchematicSelector { openFilter(); } else { SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_OWNER", player)); - swAnvilInv.setItem(SWItem.getMaterial("SKULL_ITEM"), (byte) 3); + swAnvilInv.setItem(SWItem.getMaterial("SKULL_ITEM"), (byte) 3, Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_CLICK_BACK", player)), false); swAnvilInv.setCallback(s -> { if(SteamwarUser.get(s) != null) { filter.setOwner(SteamwarUser.get(s).getId()); } openFilter(); }); + addLeftCloseAction(swAnvilInv, this::openFilter); swAnvilInv.open(); } }; diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java index 29bd658..235dda4 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelectorInjectable.java @@ -45,8 +45,15 @@ public interface SchematicSelectorInjectable { default void onSelectorOpen(SchematicSelector selector, OpenFrom from) {} + default AnvilInvCloseAction onAnvilInvCloseAction(SchematicSelector selector) {return AnvilInvCloseAction.CLOSE;} + enum OpenFrom { FRESH, REOPEN } + + enum AnvilInvCloseAction { + CLOSE, + REOPEN + } } From 2f668dbf556da708102e9c8ccb24be8c91a4cd9e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 27 Oct 2022 13:05:04 +0200 Subject: [PATCH 6/9] Remove Unused and obsolet SWActionListInv.java --- .../de/steamwar/inventory/SWActionBar.java | 31 -------- .../steamwar/inventory/SWActionListInv.java | 73 ------------------- 2 files changed, 104 deletions(-) delete mode 100644 SpigotCore_Main/src/de/steamwar/inventory/SWActionBar.java delete mode 100644 SpigotCore_Main/src/de/steamwar/inventory/SWActionListInv.java diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWActionBar.java b/SpigotCore_Main/src/de/steamwar/inventory/SWActionBar.java deleted file mode 100644 index c824347..0000000 --- a/SpigotCore_Main/src/de/steamwar/inventory/SWActionBar.java +++ /dev/null @@ -1,31 +0,0 @@ -package de.steamwar.inventory; - -public class SWActionBar { - - public enum Slot { - ZERO(0), - ONE(1), - TWO(2), - THREE(3), - FOUR(4), - FIVE(5), - SIX(6); - - private int index; - - Slot(int index) { - this.index = index; - } - - int getIndex() { - return index; - } - } - - SWItem[] actionBar = new SWItem[7]; - - public void setItem(Slot slot, SWItem item) { - actionBar[slot.getIndex()] = item; - } - -} diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWActionListInv.java b/SpigotCore_Main/src/de/steamwar/inventory/SWActionListInv.java deleted file mode 100644 index 68ef71c..0000000 --- a/SpigotCore_Main/src/de/steamwar/inventory/SWActionListInv.java +++ /dev/null @@ -1,73 +0,0 @@ -package de.steamwar.inventory; - -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; - -import java.util.List; - -public class SWActionListInv extends SWInventory { - - private SWListInv.ListCallback callback; - private List> elements; - private SWActionBar actionBar = null; - private int page; - - public SWActionListInv(Player p, String t, List> l, SWListInv.ListCallback c){ - super(p, 54, t); - callback = c; - elements = l; - page = 0; - } - - public void setActionBar(SWActionBar actionBar) { - this.actionBar = actionBar; - } - - @Override - public void open(){ - inventory.clear(); - setCallback(-999, (ClickType click) -> player.closeInventory()); - if (page != 0) { - setItem(0, SWItem.getDye(10), (byte) 10, "§eSeite zurück", (ClickType click) -> { - page--; - open(); - }); - } else { - setItem(0, SWItem.getDye(8), (byte) 8, "§7Seite zurück", (ClickType click) -> {}); - } - if (page < elements.size() / 45) { - setItem(8, SWItem.getDye(10), (byte) 10, "§eSeite vor", (ClickType click) -> { - page++; - open(); - }); - } else { - setItem(8, SWItem.getDye(8), (byte) 8, "§7Seite vor", (ClickType click) -> {}); - } - - if (actionBar != null) { - for (int i = 0; i < 7; i++) { - setItem(i + 1, actionBar.actionBar[i]); - } - } - - int ipageLimit = elements.size() - page*45; - if(ipageLimit > 45 && elements.size() > 45){ - ipageLimit = 45; - } - int i = page*45; - for(int ipage=0; ipage < ipageLimit; ipage++ ){ - SWItem e = elements.get(i).getItem(); - - final int pos = i; - setItem(ipage + 9, e); - setCallback(ipage, (ClickType click) -> callback.clicked(click, elements.get(pos).getObject())); - i++; - } - super.open(); - } - - public void setCallback(SWListInv.ListCallback c){ - callback = c; - } - -} From 45d7f271530a255bdf2c87482ec26de0886a92c7 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 28 Oct 2022 11:29:24 +0200 Subject: [PATCH 7/9] Add interfaces added by commondb for seamless transition --- .../src/de/steamwar/sql/Replay.java | 65 ++++++++++++ .../src/de/steamwar/sql/SchematicData.java | 98 +++++++++++++++++++ .../src/de/steamwar/sql/SchematicNode.java | 4 + 3 files changed, 167 insertions(+) create mode 100644 SpigotCore_Main/src/de/steamwar/sql/Replay.java create mode 100644 SpigotCore_Main/src/de/steamwar/sql/SchematicData.java diff --git a/SpigotCore_Main/src/de/steamwar/sql/Replay.java b/SpigotCore_Main/src/de/steamwar/sql/Replay.java new file mode 100644 index 0000000..c3bc96f --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/sql/Replay.java @@ -0,0 +1,65 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.sql; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.sql.SQLException; + +@AllArgsConstructor +public class Replay { + + private static final Statement get = new Statement("SELECT Replay FROM Replay WHERE FightID = ?"); + private static final Statement insert = new Statement("INSERT INTO Replay (FightID, Replay) VALUES (?, ?)"); + + public static Replay get(int fightID) { + return get.select(rs -> { + rs.next(); + + File file; + try { + file = File.createTempFile("replay", "replay"); + file.deleteOnExit(); + Files.copy(rs.getBinaryStream("Replay"), file.toPath()); + } catch (IOException e) { + throw new SQLException(e); + } + return new Replay(fightID, file); + }, fightID); + } + + public static void save(int fightID, File file) { + try { + insert.update(fightID, new FileInputStream(file)); + } catch (FileNotFoundException e) { + throw new SecurityException("Could not save replay", e); + } + } + + private final int fightID; + @Getter + private final File replay; +} \ No newline at end of file diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java new file mode 100644 index 0000000..5887887 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java @@ -0,0 +1,98 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.sql; + +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import de.steamwar.core.Core; +import de.steamwar.core.WorldEditWrapper; +import org.bukkit.entity.Player; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.sql.Blob; +import java.util.zip.GZIPInputStream; + +public class SchematicData { + + public static Clipboard clipboardFromStream(InputStream is, boolean schemFormat) { + try { + return WorldEditWrapper.impl.getClipboard(is, schemFormat); + } catch (IOException e) { + throw new SecurityException("Could not read schem", e); + } + } + + private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?"); + private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?"); + + private final SchematicNode node; + + public SchematicData(SchematicNode node) { + this.node = node; + if(node.isDir()) + throw new SecurityException("Node is Directory"); + } + + public InputStream schemData() throws IOException { + try { + return selSchemData.select(rs -> { + rs.next(); + Blob schemData = rs.getBlob("NodeData"); + if(schemData == null) { + throw new SecurityException("SchemData is null"); + } + try { + return new GZIPInputStream(schemData.getBinaryStream()); + } catch (IOException e) { + throw new SecurityException("SchemData is wrong", e); + } + }, node.getId()); + } catch (Exception e) { + throw new IOException(e); + } + } + + public Clipboard load() throws IOException, NoClipboardException { + return WorldEditWrapper.impl.getClipboard(schemData(), node.getSchemFormat()); + } + + public void loadToPlayer(Player player) throws IOException, NoClipboardException { + WorldEditWrapper.impl.setPlayerClipboard(player, schemData(), node.getSchemFormat()); + } + + public void saveFromPlayer(Player player) throws IOException, NoClipboardException { + saveFromPlayer(player, Core.getVersion() > 12); + } + + public void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException { + saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player, newFormat), newFormat); + } + + @Deprecated + public void saveFromBytes(byte[] bytes, boolean newFormat) { + saveFromStream(new ByteArrayInputStream(bytes), newFormat); + } + + public void saveFromStream(InputStream blob, boolean newFormat) { + updateDatabase.update(blob, newFormat, node.getId()); + node.setNodeFormat(newFormat); + } +} diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java index cadf8fd..157f9db 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicNode.java @@ -310,6 +310,10 @@ public class SchematicNode { return schemFormat; } + public void setNodeFormat(boolean format) { + schemFormat = format; + } + public int getRank() { if(isDir) throw new SecurityException("Node is Directory"); From 7726948a06927759b235d5c8c50c1771b282b316 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 28 Oct 2022 21:16:21 +0200 Subject: [PATCH 8/9] Add Custom Callbacks for SWListInv --- SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java b/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java index 9116443..0f9f3c0 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java @@ -55,8 +55,10 @@ public class SWListInv extends SWInventory { public void open(){ opened = true; inventory.clear(); - callbacks.clear(); - setCallback(-999, (ClickType click) -> player.closeInventory()); + callbacks.keySet().stream().filter(i -> i < 0).forEach(callbacks::remove); + if(!callbacks.containsKey(-999)) { + setCallback(-999, (ClickType click) -> player.closeInventory()); + } if (sizeBiggerMax()) { if (page != 0) { From b7e057e7757dc3b1e9f92b76654fe89425cf6ef4 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 28 Oct 2022 21:24:38 +0200 Subject: [PATCH 9/9] Fix --- SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java b/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java index 0f9f3c0..28c92fc 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java @@ -28,6 +28,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import java.util.*; +import java.util.stream.Collectors; public class SWListInv extends SWInventory { @@ -55,7 +56,7 @@ public class SWListInv extends SWInventory { public void open(){ opened = true; inventory.clear(); - callbacks.keySet().stream().filter(i -> i < 0).forEach(callbacks::remove); + callbacks.keySet().stream().filter(i -> i >= 0).collect(Collectors.toList()).forEach(callbacks::remove); if(!callbacks.containsKey(-999)) { setCallback(-999, (ClickType click) -> player.closeInventory()); }