diff --git a/SpigotCore_10/src/de/steamwar/inventory/SWInventory_10.java b/SpigotCore_10/src/de/steamwar/inventory/SWInventory_10.java
deleted file mode 100644
index 14dd049..0000000
--- a/SpigotCore_10/src/de/steamwar/inventory/SWInventory_10.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.inventory;
-
-import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryCustom;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.Inventory;
-
-class SWInventory_10 {
- private SWInventory_10(){}
-
- static Inventory get(Player player, int size, String title){
- return new CraftInventoryCustom(player, size, title);
- }
-}
diff --git a/SpigotCore_12/src/de/steamwar/inventory/SWInventory_12.java b/SpigotCore_12/src/de/steamwar/inventory/SWInventory_12.java
deleted file mode 100644
index bd8461f..0000000
--- a/SpigotCore_12/src/de/steamwar/inventory/SWInventory_12.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.inventory;
-
-import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryCustom;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.Inventory;
-
-class SWInventory_12 {
- private SWInventory_12(){}
-
- static Inventory get(Player player, int size, String title){
- return new CraftInventoryCustom(player, size, title);
- }
-}
diff --git a/SpigotCore_14/src/de/steamwar/inventory/SWInventory_14.java b/SpigotCore_14/src/de/steamwar/inventory/SWInventory_14.java
deleted file mode 100644
index 4d6d5b1..0000000
--- a/SpigotCore_14/src/de/steamwar/inventory/SWInventory_14.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.inventory;
-
-import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryCustom;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.Inventory;
-
-class SWInventory_14 {
- private SWInventory_14() {}
-
- static Inventory get(Player player, int size, String title){
- return new CraftInventoryCustom(player, size, title);
- }
-}
diff --git a/SpigotCore_15/src/de/steamwar/inventory/SWInventory_15.java b/SpigotCore_15/src/de/steamwar/inventory/SWInventory_15.java
deleted file mode 100644
index 788dcc1..0000000
--- a/SpigotCore_15/src/de/steamwar/inventory/SWInventory_15.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.inventory;
-
-import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCustom;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.Inventory;
-
-class SWInventory_15 {
- private SWInventory_15() {}
-
- static Inventory get(Player player, int size, String title){
- return new CraftInventoryCustom(player, size, title);
- }
-}
diff --git a/SpigotCore_8/src/de/steamwar/inventory/SWInventory_8.java b/SpigotCore_8/src/de/steamwar/inventory/SWInventory_8.java
deleted file mode 100644
index 7311b6d..0000000
--- a/SpigotCore_8/src/de/steamwar/inventory/SWInventory_8.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.inventory;
-
-import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCustom;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.Inventory;
-
-class SWInventory_8 {
- private SWInventory_8(){}
-
- static Inventory get(Player player, int size, String title){
- return new CraftInventoryCustom(player, size, title);
- }
-}
diff --git a/SpigotCore_9/src/de/steamwar/inventory/SWInventory_9.java b/SpigotCore_9/src/de/steamwar/inventory/SWInventory_9.java
deleted file mode 100644
index 549a22f..0000000
--- a/SpigotCore_9/src/de/steamwar/inventory/SWInventory_9.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- This file is a part of the SteamWar software.
-
- Copyright (C) 2020 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.inventory;
-
-import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftInventoryCustom;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.Inventory;
-
-class SWInventory_9 {
- private SWInventory_9(){}
-
- static Inventory get(Player player, int size, String title){
- return new CraftInventoryCustom(player, size, title);
- }
-}
diff --git a/SpigotCore_Main/pom.xml b/SpigotCore_Main/pom.xml
index 424f825..0d23f6f 100644
--- a/SpigotCore_Main/pom.xml
+++ b/SpigotCore_Main/pom.xml
@@ -14,6 +14,13 @@
${project.basedir}/..
+
+
+ codemc-snapshots
+ https://repo.codemc.io/repository/maven-snapshots/
+
+
+
SpigotCore_Main
2.0
jar
@@ -69,6 +76,12 @@
system
${main.basedir}/lib/ProtocolLib.jar
+
+ net.wesjd
+ anvilgui
+ 1.4.0-SNAPSHOT
+ compile
+
steamwar
SpigotCore_API
diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWAnvilInv.java b/SpigotCore_Main/src/de/steamwar/inventory/SWAnvilInv.java
new file mode 100644
index 0000000..582538f
--- /dev/null
+++ b/SpigotCore_Main/src/de/steamwar/inventory/SWAnvilInv.java
@@ -0,0 +1,84 @@
+/*
+ This file is a part of the SteamWar software.
+
+ Copyright (C) 2020 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.inventory;
+
+import de.steamwar.core.Core;
+import net.wesjd.anvilgui.AnvilGUI;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SWAnvilInv {
+
+ private final AnvilGUI.Builder builder;
+ private final Player player;
+
+ private Response callback;
+
+ public SWAnvilInv(Player p, String t){
+ builder = new AnvilGUI.Builder().plugin(Core.getInstance()).title(t).text("»").onComplete(this::onResult);
+ player = p;
+ }
+
+ public void setItem(Material m){
+ setItem(m, new ArrayList<>(), false);
+ }
+
+ public void setItem(Material m, byte meta){
+ setItem(m, meta, new ArrayList<>(), false);
+ }
+
+ public void setItem(Material m, List lore, boolean e){
+ setItem(m, (byte)0, lore, e);
+ }
+
+ public void setItem(Material m, byte meta, List lore, boolean e){
+ builder.itemLeft(new SWItem(m, meta, "»", lore, e, null).getItemStack());
+ }
+
+ public void setCallback(Response callback){
+ this.callback = callback;
+ }
+
+ public void addCloseCallback(Runnable callback){
+ builder.onClose(p -> callback.run());
+ }
+
+ public void open(){
+ builder.open(player);
+ }
+
+ private AnvilGUI.Response onResult(Player player, String s) {
+ if(s.startsWith("»"))
+ s = s.substring(1);
+ callback.onResult(s);
+ return AnvilGUI.Response.close();
+ }
+
+ public void onClose(Player player) {
+ player.sendMessage("Closing");
+ }
+
+ public static interface Response{
+ void onResult(String s);
+ }
+}
diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java b/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java
index 1208056..470853f 100644
--- a/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java
+++ b/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java
@@ -36,32 +36,14 @@ import java.util.Map;
public class SWInventory implements Listener {
- Player player;
- private Map callbacks;
- Inventory inventory;
+ final Player player;
+ private final Map callbacks = new HashMap<>();
+ final Inventory inventory;
+
public SWInventory(Player p, int size, String t){
- callbacks = new HashMap<>();
player = p;
- switch(Core.getVersion()){
- case 8:
- inventory = SWInventory_8.get(p, size, t);
- break;
- case 9:
- inventory = SWInventory_9.get(p, size, t);
- break;
- case 10:
- inventory = SWInventory_10.get(p, size, t);
- break;
- case 14:
- inventory = SWInventory_14.get(p, size, t);
- break;
- case 15:
- inventory = SWInventory_15.get(p, size, t);
- break;
- default:
- inventory = SWInventory_12.get(p, size, t);
- }
+ inventory = Bukkit.createInventory(p, size, t);
}
public SWInventory(Player p, int size, String t, Map items){
@@ -106,7 +88,7 @@ public class SWInventory implements Listener {
}
@EventHandler
- public void onInventoryClick(InventoryClickEvent e){
+ private void onInventoryClick(InventoryClickEvent e){
if(!player.equals(e.getWhoClicked()))
return;
@@ -116,7 +98,7 @@ public class SWInventory implements Listener {
}
@EventHandler
- public void onInventoryClose(InventoryCloseEvent e){
+ private void onInventoryClose(InventoryCloseEvent e){
if(!player.equals(e.getPlayer()))
return;
diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java b/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java
index 8e3a06f..d6e92ff 100644
--- a/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java
+++ b/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java
@@ -103,10 +103,18 @@ public class SWItem {
this(material, (byte)0, name, new ArrayList<>(), false, null);
}
+ public SWItem(Material material, String name, InvCallback c){
+ this(material, (byte)0, name, new ArrayList<>(), false, c);
+ }
+
public SWItem(Material material, byte meta, String name){
this(material, meta, name, new ArrayList<>(), false, null);
}
+ public SWItem(Material material, byte meta, String name, InvCallback c){
+ this(material, meta, name, new ArrayList<>(), false, c);
+ }
+
public SWItem(Material material, String name, List lore, boolean enchanted, InvCallback c) {
this(material, (byte)0, name, lore, enchanted, c);
}
diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java b/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java
index 891ad9d..dfb748c 100644
--- a/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java
+++ b/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java
@@ -30,21 +30,29 @@ import java.util.*;
public class SWListInv extends SWInventory {
+ private final List> elements;
+
+ private final Map customItems = new HashMap<>();
private ListCallback callback;
- private List> elements;
private int page;
+ private boolean opened = false;
public SWListInv(Player p, String t, List> l, ListCallback c){
- super(p, (l.size()>45) ? 54 : (l.size() + 9-l.size()%9), t);
+ this(p, t, true, l, c);
+ }
+
+ public SWListInv(Player p, String t, boolean dynamicSize, List> l, ListCallback c){
+ super(p, dynamicSize ? dynamicSize(l.size()) : 54, t);
callback = c;
elements = l;
page = 0;
+ setCallback(-999, (ClickType click) -> player.closeInventory());
}
@Override
public void open(){
+ opened = true;
inventory.clear();
- setCallback(-999, (ClickType click) -> player.closeInventory());
if(elements.size() > 54){
if(page != 0)
setItem(45, SWItem.getDye(10), (byte)10, "§eSeite zurück", (ClickType click) -> {
@@ -75,17 +83,23 @@ public class SWListInv extends SWInventory {
setCallback(ipage, (ClickType click) -> callback.clicked(click, elements.get(pos).getObject()));
i++;
}
+
+ for(Map.Entry customItem : customItems.entrySet())
+ setItem(customItem.getKey(), customItem.getValue());
super.open();
}
+ @Override
+ public void setItem(int pos, SWItem item){
+ super.setItem(pos, item);
+ if(!opened)
+ customItems.put(pos, item);
+ }
+
public void setCallback(ListCallback c){
callback = c;
}
- public interface ListCallback{
- void clicked(ClickType click, T element);
- }
-
public static List> createPlayerList(UUID without){
List> onlinePlayers = new ArrayList<>();
for(Player player : Bukkit.getOnlinePlayers()){
@@ -118,6 +132,14 @@ public class SWListInv extends SWInventory {
return schemList;
}
+ private static int dynamicSize(int size){
+ return (size>45) ? 54 : (size + 9-size%9);
+ }
+
+ public interface ListCallback{
+ void clicked(ClickType click, T element);
+ }
+
public static class SWListEntry{
final SWItem item;
final T object;