Gotta debug NBT gui
This commit is contained in:
@@ -17,30 +17,23 @@ public class NBTStorage implements JsonSerializable<NBTStorage> {
|
||||
|
||||
public Map<String, String> caughtItems = new HashMap<>();
|
||||
|
||||
public static ItemStack toItem(String data) {
|
||||
try {
|
||||
byte[] bytes = Base64.getDecoder().decode(data);
|
||||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
|
||||
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
|
||||
ItemStack item = (ItemStack) objectInputStream.readObject();
|
||||
objectInputStream.close();
|
||||
return item;
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
Sentinel.getInstance().getLogger().warning("Could not deserialize ItemStack: " + e.getMessage());
|
||||
return null;
|
||||
public static ItemStack toItem(String serializedString) {
|
||||
if (serializedString.equals("null")) return null;
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(serializedString);
|
||||
String mapString = new String(decodedBytes);
|
||||
// Remove the curly braces and split by commas to get key-value pairs
|
||||
String[] keyValuePairs = mapString.substring(1, mapString.length() - 1).split(", ");
|
||||
Map<String, Object> deserializedMap = new HashMap<>();
|
||||
for (String pair : keyValuePairs) {
|
||||
String[] keyValue = pair.split("=");
|
||||
deserializedMap.put(keyValue[0], keyValue[1]);
|
||||
}
|
||||
ItemStack item = ItemStack.deserialize(deserializedMap);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static String toB64(ItemStack item) {
|
||||
try {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
|
||||
objectOutputStream.writeObject(item);
|
||||
objectOutputStream.close();
|
||||
return Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
Sentinel.getInstance().getLogger().warning("Could not serialize ItemStack: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String toB64(ItemStack itemStack) {
|
||||
Map<String, Object> serializedMap = itemStack.serialize();
|
||||
return Base64.getEncoder().encodeToString(serializedMap.toString().getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class ChatEvent implements CustomListener {
|
||||
UrlFilterGUI.updater.invokeCallbacks(e);
|
||||
ProfanityFilterGUI.updater.invokeCallbacks(e);
|
||||
SpamFilterGUI.updater.invokeCallbacks(e);
|
||||
NewWhitelistGUI.
|
||||
NewWhitelistGUI.updater.invokeCallbacks(e);
|
||||
DangerousCommand.updater.invokeCallbacks(e);
|
||||
LoggedCommand.updater.invokeCallbacks(e);
|
||||
SpecificCommand.updater.invokeCallbacks(e);
|
||||
|
||||
@@ -23,6 +23,8 @@ public abstract class PaginatedGUI<T> {
|
||||
protected static final Map<UUID, Set<String>> activeFilters = new HashMap<>();
|
||||
protected static final Map<UUID, FilterOperator> chosenOperator = new HashMap<>();
|
||||
|
||||
protected abstract CustomGui backGUI();
|
||||
|
||||
public CustomGui createGUI(Player p) {
|
||||
ServerUtils.verbose("Creating GUI for player: %s", p.getName());
|
||||
int page = currentPages.compute(p.getUniqueId(), (k, v) -> realizePage(p, v == null ? 0 : v));
|
||||
@@ -40,10 +42,10 @@ public abstract class PaginatedGUI<T> {
|
||||
protected abstract String getTitle(Player p);
|
||||
|
||||
protected void setupPage(Player p, Inventory inv) {
|
||||
ServerUtils.verbose("Setting up page for player: %s", p.getName());
|
||||
ServerUtils.verbose(1,"Setting up page for player: %s", p.getName());
|
||||
int page = currentPages.compute(p.getUniqueId(), (k, v) -> realizePage(p, v == null ? 0 : v));
|
||||
List<T> filtered = filterEntries(p, chosenOperator.computeIfAbsent(p.getUniqueId(), v -> FilterOperator.AND));
|
||||
ServerUtils.verbose("Current page: %d, Total entries: %d", page, filtered.size());
|
||||
ServerUtils.verbose(1,"Current page: %d, Total entries: %d", page, filtered.size());
|
||||
|
||||
// Clear previous items
|
||||
for (int i = 0; i < ITEMS_PER_PAGE; i++) {
|
||||
@@ -67,7 +69,7 @@ public abstract class PaginatedGUI<T> {
|
||||
protected abstract ItemStack createDisplayItem(T item);
|
||||
|
||||
protected void openFilterMenu(Player p) {
|
||||
ServerUtils.verbose("Creating filter menu for %s", p);
|
||||
ServerUtils.verbose(1,"Creating filter menu for %s", p);
|
||||
Set<String> filters = activeFilters.computeIfAbsent(p.getUniqueId(), k -> new HashSet<>());
|
||||
|
||||
CustomGui.GuiBuilder filterGui = CustomGui.create()
|
||||
@@ -101,6 +103,10 @@ public abstract class PaginatedGUI<T> {
|
||||
|
||||
protected void changePage(Player p, int direction) {
|
||||
int current = currentPages.getOrDefault(p.getUniqueId(), 0);
|
||||
if (current + direction < 0) {
|
||||
p.openInventory(backGUI().getInventory());
|
||||
return;
|
||||
}
|
||||
int newPage = realizePage(p, current + direction);
|
||||
currentPages.put(p.getUniqueId(), newPage);
|
||||
p.openInventory(createGUI(p).getInventory());
|
||||
@@ -114,6 +120,9 @@ public abstract class PaginatedGUI<T> {
|
||||
}
|
||||
|
||||
private ItemStack createNavigationItem(String direction, int pageTo) {
|
||||
if (pageTo < 0) {
|
||||
return Items.BACK;
|
||||
}
|
||||
return new ItemBuilder()
|
||||
.material(Material.ARROW)
|
||||
.name(Text.color("&b" + direction + "&7 Page"))
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.github.itzispyder.pdk.plugin.gui.CustomGui;
|
||||
import io.github.itzispyder.pdk.utils.misc.Pair;
|
||||
import me.trouper.sentinel.Sentinel;
|
||||
import me.trouper.sentinel.data.storage.NBTStorage;
|
||||
import me.trouper.sentinel.server.gui.MainGUI;
|
||||
import me.trouper.sentinel.server.gui.PaginatedGUI;
|
||||
import me.trouper.sentinel.utils.ServerUtils;
|
||||
import me.trouper.sentinel.utils.Text;
|
||||
@@ -25,6 +26,11 @@ public class NBTGui extends PaginatedGUI<Map.Entry<String,String>> {
|
||||
this.nbtStorage = Sentinel.getInstance().getDirector().io.nbtStorage;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CustomGui backGUI() {
|
||||
return new MainGUI().home;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTitle(Player p) {
|
||||
return Text.color("&6&lItem Ownership &7(" + getFilterCount(p) + " items)");
|
||||
|
||||
@@ -32,6 +32,11 @@ public class NewWhitelistGUI extends PaginatedGUI<CommandBlockHolder> {
|
||||
|
||||
private static final Map<UUID, String> chosenPlayer = new HashMap<>();
|
||||
|
||||
@Override
|
||||
protected CustomGui backGUI() {
|
||||
return new MainGUI().home;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTitle(Player p) {
|
||||
return Text.color("&6&lCommand Blocks &7(" + getFilterCount(p) + " filters)");
|
||||
@@ -94,9 +99,26 @@ public class NewWhitelistGUI extends PaginatedGUI<CommandBlockHolder> {
|
||||
e -> {
|
||||
if (e.isLeftClick()) toggleFilter(p, "USER");
|
||||
else if (e.isRightClick()) {
|
||||
|
||||
queuePlayer(p,(cfg,value)->{
|
||||
chosenPlayer.put(p.getUniqueId(),value.getAll().toString());
|
||||
},chosenPlayer.getOrDefault(p.getUniqueId(),"null"));
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
public static ConfigUpdater<AsyncChatEvent, ViolationConfig> updater = new ConfigUpdater<>(Sentinel.getInstance().getDirector().io.violationConfig);
|
||||
protected void queuePlayer(Player player, BiConsumer<ViolationConfig, Args> action, String currentValue) {
|
||||
MainGUI.awaitingCallback.add(player.getUniqueId());
|
||||
player.closeInventory();
|
||||
updater.queuePlayer(player, 20*60, (e)->{
|
||||
e.setCancelled(true);
|
||||
return LegacyComponentSerializer.legacySection().serialize(e.message());
|
||||
}, (cfg, newValue) -> {
|
||||
action.accept(cfg,new Args(newValue.split("\\s+")));
|
||||
player.sendMessage(Text.prefix("Value updated successfully"));
|
||||
openFilterMenu(player);
|
||||
});
|
||||
player.sendMessage(Component.text(Text.prefix("Enter the new value in chat. The value is currently set to &b%s&7. (Click to insert)".formatted(currentValue))).clickEvent(ClickEvent.suggestCommand(currentValue)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user