diff --git a/pom.xml b/pom.xml
index afb785b..9733dd3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
com.mcmiddleearth
MCME-Architect
- 2.9.14
+ 2.9.15
jar
UTF-8
diff --git a/src/main/java/com/mcmiddleearth/architect/ArchitectPlugin.java b/src/main/java/com/mcmiddleearth/architect/ArchitectPlugin.java
index 088a337..49f2804 100644
--- a/src/main/java/com/mcmiddleearth/architect/ArchitectPlugin.java
+++ b/src/main/java/com/mcmiddleearth/architect/ArchitectPlugin.java
@@ -32,6 +32,7 @@
import com.mcmiddleearth.architect.specialBlockHandling.command.GetCommand;
import com.mcmiddleearth.architect.specialBlockHandling.command.InvCommand;
import com.mcmiddleearth.architect.specialBlockHandling.command.SwitchStickCommand;
+import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.CustomInventoryEditor;
import com.mcmiddleearth.architect.specialBlockHandling.data.*;
import com.mcmiddleearth.architect.specialBlockHandling.itemBlock.ItemBlockCommand;
import com.mcmiddleearth.architect.specialBlockHandling.itemBlock.ItemBlockListener;
@@ -146,7 +147,8 @@ public void onEnable() {
setCommandExecutor("switchstick", new SwitchStickCommand());
//setCommandExecutor("speed", new SpeedCommand());
// setCommandExecutor("newafkk", new NewAfkCommand());
-
+
+ CustomInventoryEditor.init(this);
rpSwitchTask = new RPSwitchTask().runTaskTimer(this, 500, 20);
ItemBlockManager.startEntityGlowTask();
diff --git a/src/main/java/com/mcmiddleearth/architect/Permission.java b/src/main/java/com/mcmiddleearth/architect/Permission.java
index cb45f9c..ae9640c 100644
--- a/src/main/java/com/mcmiddleearth/architect/Permission.java
+++ b/src/main/java/com/mcmiddleearth/architect/Permission.java
@@ -63,6 +63,7 @@ public enum Permission {
INV_COMMAND ("architect.inventory"),
INV_OTHER ("architect.inventory.other"),
INV_SAVE ("architect.inventory.save"),
+ INV_EDIT ("architect.inventory.edit"),
INV_RELOAD_COMMAND ("architect.inventory.reload"),
INVENTORY_OPEN ("architect.inventory.open"),
NO_PHYSICS_LIST ("architect.noPhysicsList.view"),
diff --git a/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpManager.java b/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpManager.java
index 28ac4bb..41162b1 100644
--- a/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpManager.java
+++ b/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpManager.java
@@ -29,6 +29,7 @@
import com.mcmiddleearth.connect.log.Log;
import com.mcmiddleearth.util.DevUtil;
import com.mcmiddleearth.util.ResourceUtil;
+import com.viaversion.viaversion.api.Via;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
@@ -213,6 +214,9 @@ private static ConfigurationSection getConfigSection(String rp, Player player) {
RpPlayerData data;
if (player != null) {
data = getPlayerData(player);
+ if(data.getProtocolVersion()==0) {
+ data.setProtocolVersion(Via.getAPI().getPlayerProtocolVersion(player.getUniqueId()).getVersion());
+ }
} else {
data = new RpPlayerData();
}
@@ -344,6 +348,7 @@ public static boolean setRp(String rpName, Player player, boolean force) {
RpPlayerData data = getPlayerData(player);
if(url!=null && data!=null && !url.equals("") && (force || !url.equals(data.getCurrentRpUrl()))) {
data.setCurrentRpUrl(url);
+//Logger.getGlobal().info("Sending to "+player.getName()+"("+getPlayerData(player).getProtocolVersion()+") RP: "+url);
player.setResourcePack(url, getSHA(rpName, player));
savePlayerData(player);
return true;
diff --git a/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpPluginMessageListener.java b/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpPluginMessageListener.java
index 2082a4c..af6abd2 100644
--- a/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpPluginMessageListener.java
+++ b/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpPluginMessageListener.java
@@ -16,8 +16,8 @@ public class RpPluginMessageListener implements PluginMessageListener {
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, byte[] bytes) {
//Logger.getGlobal().info("Sodium client detected: "+player.getName());
-Logger.getGlobal().info("Received message from player " + player.getName() + " on channel "
- + channel + " with data " + Arrays.toString(bytes));
+//Logger.getGlobal().info("Received message from player " + player.getName() + " on channel "
+// + channel + " with data " + Arrays.toString(bytes));
try (var dataStream = new DataInputStream(new ByteArrayInputStream(bytes))) {
int stringLength = readVarInt(dataStream);
String jsonString = new String(dataStream.readNBytes(stringLength));
diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java
index 4d9431a..b2d2749 100644
--- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java
+++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java
@@ -22,9 +22,13 @@
*/
import com.mcmiddleearth.architect.ArchitectPlugin;
+import com.mcmiddleearth.architect.Permission;
+import com.mcmiddleearth.architect.serverResoucePack.RpManager;
+import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.CustomInventoryEditor;
import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialBlockInventoryData;
import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialHeadInventoryData;
import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialItemInventoryData;
+import com.mcmiddleearth.architect.specialBlockHandling.specialBlocks.SpecialBlock;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -339,6 +343,28 @@ void onCategoryChange(final InventoryClickEvent event) {
}
}
}
+
+ @EventHandler(priority = EventPriority.HIGHEST)
+ void onInventoryEdit(final InventoryClickEvent event) {
+ if (openInventories.containsKey(event.getInventory())) { //.getTitle.equals(name)) {
+ if (event.getWhoClicked() instanceof Player player
+ && player.hasPermission(Permission.INV_EDIT.getPermissionNode())
+ && event.getRawSlot() >= CATEGORY_SLOTS
+ && event.getRawSlot() < event.getInventory().getSize()
+ && event.isRightClick()
+ && event.isShiftClick()) {//items.size()/9+1)*9
+ CustomInventoryState state = openInventories.get(event.getInventory());
+ String category = state.categoryNames[state.currentCategory];
+ String rpName = RpManager.getCurrentRpName(state.getPlayer());
+ event.getInventory().close();
+ if(event.getCurrentItem() == null) {
+ CustomInventoryEditor.addBlock(player, rpName, category, state, event.getRawSlot());
+ } else {
+ CustomInventoryEditor.editBlock(player, category, state, event.getRawSlot(), event.getCurrentItem());
+ }
+ }
+ }
+ }
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
void onClose(final InventoryCloseEvent event) {
diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCategory.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCategory.java
index cbcc511..f8c2897 100644
--- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCategory.java
+++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCategory.java
@@ -21,6 +21,7 @@
import org.bukkit.inventory.ItemStack;
import java.util.*;
+import java.util.logging.Logger;
/**
*
@@ -85,7 +86,10 @@ public boolean isVisible(Player player) {
}
public ItemStack getItem(String id) {
- return items.stream().filter(item -> SpecialBlockInventoryData.getSpecialBlockId(item).equals(id)).findAny().orElse(null);
+ return items.stream().filter(item -> {
+ String blockId = SpecialBlockInventoryData.getSpecialBlockId(item);
+ return blockId != null && blockId.equals(id);
+ }).findAny().orElse(null);
}
public boolean isPublic() {
diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCollectionState.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCollectionState.java
index ed75f94..d9ccd54 100644
--- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCollectionState.java
+++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCollectionState.java
@@ -28,6 +28,7 @@
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
+import java.util.logging.Logger;
/**
*
@@ -212,4 +213,8 @@ public boolean isDirectGet() {
public void setDirectGet(boolean directGet) {
this.directGet = directGet;
}
+
+ public SpecialBlock getBaseBlock() {
+ return baseBlock;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryState.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryState.java
index fb7ecc3..262d6f2 100644
--- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryState.java
+++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryState.java
@@ -281,4 +281,8 @@ public static ItemStack newPagingItem(Material material, int cmd, String display
}
public abstract boolean usesSubcategories();
+
+ public Player getPlayer() {
+ return player;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/SearchInventory.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/SearchInventory.java
index 8992aa3..048fa89 100644
--- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/SearchInventory.java
+++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/SearchInventory.java
@@ -222,7 +222,14 @@ public boolean isEmpty() {
public ItemStack getItem(String id) {
//Logger.getGlobal().info("search getItem: "+id);
- return items.stream().filter(item -> item.getItemMeta().getLore().get(1).equals(id)).findFirst().orElse(null);
+ return items.stream().filter(item -> {
+ if(item.hasItemMeta() && item.getItemMeta().hasLore()) {
+ return item.getItemMeta().getLore().get(1).equals(id);
+// } else {
+// Logger.getGlobal().warning("Invalid item in search inventory: "+item);
+ }
+ return false;
+ }).findFirst().orElse(null);
}
public Set getRecipeKeys() {
diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/CustomInventoryEditor.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/CustomInventoryEditor.java
new file mode 100644
index 0000000..4ffecdb
--- /dev/null
+++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/CustomInventoryEditor.java
@@ -0,0 +1,235 @@
+package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor;
+
+import com.mcmiddleearth.architect.PluginData;
+import com.mcmiddleearth.architect.specialBlockHandling.customInventories.CustomInventory;
+import com.mcmiddleearth.architect.specialBlockHandling.customInventories.CustomInventoryCollectionState;
+import com.mcmiddleearth.architect.specialBlockHandling.customInventories.CustomInventoryState;
+import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.BlockIdPrompt;
+import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit.EditPrompt;
+import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialBlockInventoryData;
+import com.mcmiddleearth.architect.specialBlockHandling.specialBlocks.SpecialBlock;
+import org.bukkit.ChatColor;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.InvalidConfigurationException;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.conversations.*;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.plugin.Plugin;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+public class CustomInventoryEditor {
+
+ private static ConversationFactory addBlockConversationFactory;
+ private static ConversationFactory editBlockConversationFactory;
+
+ public static void init(Plugin plugin) {
+ Map