Gotta debug NBT gui
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -17,30 +17,23 @@ public class NBTStorage implements JsonSerializable<NBTStorage> {
|
|||||||
|
|
||||||
public Map<String, String> caughtItems = new HashMap<>();
|
public Map<String, String> caughtItems = new HashMap<>();
|
||||||
|
|
||||||
public static ItemStack toItem(String data) {
|
public static ItemStack toItem(String serializedString) {
|
||||||
try {
|
if (serializedString.equals("null")) return null;
|
||||||
byte[] bytes = Base64.getDecoder().decode(data);
|
byte[] decodedBytes = Base64.getDecoder().decode(serializedString);
|
||||||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
|
String mapString = new String(decodedBytes);
|
||||||
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
|
// Remove the curly braces and split by commas to get key-value pairs
|
||||||
ItemStack item = (ItemStack) objectInputStream.readObject();
|
String[] keyValuePairs = mapString.substring(1, mapString.length() - 1).split(", ");
|
||||||
objectInputStream.close();
|
Map<String, Object> deserializedMap = new HashMap<>();
|
||||||
return item;
|
for (String pair : keyValuePairs) {
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
String[] keyValue = pair.split("=");
|
||||||
Sentinel.getInstance().getLogger().warning("Could not deserialize ItemStack: " + e.getMessage());
|
deserializedMap.put(keyValue[0], keyValue[1]);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
ItemStack item = ItemStack.deserialize(deserializedMap);
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String toB64(ItemStack item) {
|
public static String toB64(ItemStack itemStack) {
|
||||||
try {
|
Map<String, Object> serializedMap = itemStack.serialize();
|
||||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
return Base64.getEncoder().encodeToString(serializedMap.toString().getBytes());
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class ChatEvent implements CustomListener {
|
|||||||
UrlFilterGUI.updater.invokeCallbacks(e);
|
UrlFilterGUI.updater.invokeCallbacks(e);
|
||||||
ProfanityFilterGUI.updater.invokeCallbacks(e);
|
ProfanityFilterGUI.updater.invokeCallbacks(e);
|
||||||
SpamFilterGUI.updater.invokeCallbacks(e);
|
SpamFilterGUI.updater.invokeCallbacks(e);
|
||||||
NewWhitelistGUI.
|
NewWhitelistGUI.updater.invokeCallbacks(e);
|
||||||
DangerousCommand.updater.invokeCallbacks(e);
|
DangerousCommand.updater.invokeCallbacks(e);
|
||||||
LoggedCommand.updater.invokeCallbacks(e);
|
LoggedCommand.updater.invokeCallbacks(e);
|
||||||
SpecificCommand.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, Set<String>> activeFilters = new HashMap<>();
|
||||||
protected static final Map<UUID, FilterOperator> chosenOperator = new HashMap<>();
|
protected static final Map<UUID, FilterOperator> chosenOperator = new HashMap<>();
|
||||||
|
|
||||||
|
protected abstract CustomGui backGUI();
|
||||||
|
|
||||||
public CustomGui createGUI(Player p) {
|
public CustomGui createGUI(Player p) {
|
||||||
ServerUtils.verbose("Creating GUI for player: %s", p.getName());
|
ServerUtils.verbose("Creating GUI for player: %s", p.getName());
|
||||||
int page = currentPages.compute(p.getUniqueId(), (k, v) -> realizePage(p, v == null ? 0 : v));
|
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 abstract String getTitle(Player p);
|
||||||
|
|
||||||
protected void setupPage(Player p, Inventory inv) {
|
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));
|
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));
|
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
|
// Clear previous items
|
||||||
for (int i = 0; i < ITEMS_PER_PAGE; i++) {
|
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 abstract ItemStack createDisplayItem(T item);
|
||||||
|
|
||||||
protected void openFilterMenu(Player p) {
|
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<>());
|
Set<String> filters = activeFilters.computeIfAbsent(p.getUniqueId(), k -> new HashSet<>());
|
||||||
|
|
||||||
CustomGui.GuiBuilder filterGui = CustomGui.create()
|
CustomGui.GuiBuilder filterGui = CustomGui.create()
|
||||||
@@ -101,6 +103,10 @@ public abstract class PaginatedGUI<T> {
|
|||||||
|
|
||||||
protected void changePage(Player p, int direction) {
|
protected void changePage(Player p, int direction) {
|
||||||
int current = currentPages.getOrDefault(p.getUniqueId(), 0);
|
int current = currentPages.getOrDefault(p.getUniqueId(), 0);
|
||||||
|
if (current + direction < 0) {
|
||||||
|
p.openInventory(backGUI().getInventory());
|
||||||
|
return;
|
||||||
|
}
|
||||||
int newPage = realizePage(p, current + direction);
|
int newPage = realizePage(p, current + direction);
|
||||||
currentPages.put(p.getUniqueId(), newPage);
|
currentPages.put(p.getUniqueId(), newPage);
|
||||||
p.openInventory(createGUI(p).getInventory());
|
p.openInventory(createGUI(p).getInventory());
|
||||||
@@ -114,6 +120,9 @@ public abstract class PaginatedGUI<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack createNavigationItem(String direction, int pageTo) {
|
private ItemStack createNavigationItem(String direction, int pageTo) {
|
||||||
|
if (pageTo < 0) {
|
||||||
|
return Items.BACK;
|
||||||
|
}
|
||||||
return new ItemBuilder()
|
return new ItemBuilder()
|
||||||
.material(Material.ARROW)
|
.material(Material.ARROW)
|
||||||
.name(Text.color("&b" + direction + "&7 Page"))
|
.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 io.github.itzispyder.pdk.utils.misc.Pair;
|
||||||
import me.trouper.sentinel.Sentinel;
|
import me.trouper.sentinel.Sentinel;
|
||||||
import me.trouper.sentinel.data.storage.NBTStorage;
|
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.server.gui.PaginatedGUI;
|
||||||
import me.trouper.sentinel.utils.ServerUtils;
|
import me.trouper.sentinel.utils.ServerUtils;
|
||||||
import me.trouper.sentinel.utils.Text;
|
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;
|
this.nbtStorage = Sentinel.getInstance().getDirector().io.nbtStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CustomGui backGUI() {
|
||||||
|
return new MainGUI().home;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getTitle(Player p) {
|
protected String getTitle(Player p) {
|
||||||
return Text.color("&6&lItem Ownership &7(" + getFilterCount(p) + " items)");
|
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<>();
|
private static final Map<UUID, String> chosenPlayer = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CustomGui backGUI() {
|
||||||
|
return new MainGUI().home;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getTitle(Player p) {
|
protected String getTitle(Player p) {
|
||||||
return Text.color("&6&lCommand Blocks &7(" + getFilterCount(p) + " filters)");
|
return Text.color("&6&lCommand Blocks &7(" + getFilterCount(p) + " filters)");
|
||||||
@@ -94,9 +99,26 @@ public class NewWhitelistGUI extends PaginatedGUI<CommandBlockHolder> {
|
|||||||
e -> {
|
e -> {
|
||||||
if (e.isLeftClick()) toggleFilter(p, "USER");
|
if (e.isLeftClick()) toggleFilter(p, "USER");
|
||||||
else if (e.isRightClick()) {
|
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
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user