Worked on the GUI

This commit is contained in:
obvWolf
2024-02-28 16:58:43 -06:00
parent 352b58fb7c
commit 23fc9025ba
4 changed files with 121 additions and 39 deletions

View File

@@ -69,8 +69,23 @@ public class UltraDupeCommand implements CustomCommand {
.then(b.arg("debug","bypass"))
).then(b.arg("gui"));
}
private void handleItemEdit(Player p, Args args) {
private void handleItemEdit(Player p, Args args) {
if (!p.hasPermission("ultradupe.dupebans.edit")) {
DupeBansCommand.handleListBans(p);
return;
}
switch (args.get(2).toString()) {
case "add" -> {
ItemStack i = p.getInventory().getItemInMainHand();
i.getItemMeta().setCustomModelData(UltraDupe.dupeBanStorage.bannedModelData);
}
case "remove" -> {
ItemStack i = p.getInventory().getItemInMainHand();
i.getItemMeta().setCustomModelData(0);
}
}
}
/*private void handleItemEdit(Player p, Args args) {
if (!p.hasPermission("ultradupe.dupebans.edit")) {
DupeBansCommand.handleListBans(p);
return;
@@ -97,7 +112,7 @@ public class UltraDupeCommand implements CustomCommand {
UltraDupe.dupeBanStorage.save();
}
}
}
}*/
private void handleMaterialEdit(Player p, Args args) {
if (!p.hasPermission("ultradupe.dupebans.edit")) {

View File

@@ -6,6 +6,7 @@ import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -18,9 +19,9 @@ public class DupeBanStorage implements JsonSerializable<DupeBanStorage> {
return file;
}
public int bannedModelData = 1111;
public List<Material> bannedMaterials = Arrays.asList(
public List<Material> bannedMaterials = new ArrayList<>(Arrays.asList(
Material.ANCIENT_DEBRIS,
Material.NETHERITE_INGOT,
Material.TOTEM_OF_UNDYING
);
));
}

View File

@@ -9,49 +9,104 @@ import me.trouper.ultradupe.server.util.Text;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class DupeBanGUI implements Global {
public class DupeBanGUI extends CustomGui implements Global {
static Global g = Global.instance;
public static List<UUID> isInGUI = new ArrayList<>();
public DupeBanGUI(String title, int size, InvAction mainAction, Map<Integer, InvAction> slotActions, Map<Integer, ItemStack> slotDisplays, CreateAction createAction, CloseAction closeAction) {
super(title, size, mainAction, slotActions, slotDisplays, createAction, closeAction);
}
public static void refreshGUI(Player p) {
p.openInventory(home.getInventory());
}
public static final CustomGui home = CustomGui.create()
.title(g.color("&#5A88FF&lU&#698CFF&ll&#7890FF&lt&#8794FF&lr&#9699FF&la&#A59DFF&lD&#B4A1FF&lu&#C3A5FF&lp&#D2A9FF&le &7&l | &#D589FFD&#CB99FFu&#C2A9FFp&#B8B9FFe &#AFCAFFB&#A5DAFFa&#9CEAFFn&#96F3FBs &#93F5F2E&#91F7EAd&#8EF9E1i&#8CFBD9t&#89FDD0o&#87FFC8r"))
.title(g.color("&#5A88FF&lU&#698CFF&ll&#7890FF&lt&#8794FF&lr&#9699FF&la&#A59DFF&lD&#B4A1FF&lu&#C3A5FF&lp&#D2A9FF&le &7&l| &#D589FFD&#CB99FFu&#C2A9FFp&#B8B9FFe &#AFCAFFB&#A5DAFFa&#9CEAFFn&#96F3FBs &#93F5F2E&#91F7EAd&#8EF9E1i&#8CFBD9t&#89FDD0o&#87FFC8r"))
.size(54)
.defineMain(e -> {
e.setCancelled(true);
if (!isInGUI.contains(e.getWhoClicked().getUniqueId())) {
e.setCancelled(true);
e.getWhoClicked().setHealth(0);
return;
}
if (e.getClickedInventory().getItem(e.getSlot()).getType().equals(Material.LIGHT_GRAY_STAINED_GLASS_PANE)) {
SoundPlayer deny = new SoundPlayer(e.getWhoClicked().getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS,1,1);
deny.play((Player) e.getWhoClicked());
}
})
.onDefine(i -> {
int pointer = 0;
for (Material bannedMaterial : UltraDupe.dupeBanStorage.bannedMaterials) {
if (pointer > 44) return;
i.setItem(pointer, ItemBuilder.create()
.material(bannedMaterial)
.lore("")
.lore(Global.instance.color("&7(Light click to remove)"))
.build());
pointer++;
}
})
.define(45,GuiItems.backArrow,event-> {
event.getWhoClicked().sendMessage(Text.prefix("You clicked back"));
})
.define(53,GuiItems.nextArrow,event -> {
event.getWhoClicked().sendMessage(Text.prefix("You clicked next"));
})
.defineMain(DupeBanGUI::handleMainClick)
.onDefine(DupeBanGUI::handleDefine)
.define(45, GuiItems.BACK_ARROW, event -> event.getWhoClicked().sendMessage(Text.prefix("You clicked back")))
.define(53, GuiItems.NEXT_ARROW, event -> event.getWhoClicked().sendMessage(Text.prefix("You clicked next")))
.define(49, GuiItems.INFO_ICON, event -> {})
.build();
private static void handleMainClick(InventoryClickEvent e) {
SoundPlayer deny = new SoundPlayer(e.getWhoClicked().getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1);
SoundPlayer allow = new SoundPlayer(e.getWhoClicked().getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
e.setCancelled(true);
Player who = (Player) e.getWhoClicked();
int where = e.getSlot();
if (e.getClickedInventory().getItem(where) == null || e.getClickedInventory().getItem(where).isEmpty()) {
deny.play(who);
return;
}
ItemStack what = e.getClickedInventory().getItem(where);
if (!isInGUI.contains(e.getWhoClicked().getUniqueId())) {
e.setCancelled(true);
deny.play(who);
e.getWhoClicked().setHealth(0);
return;
}
if (!e.getCursor().isEmpty()) {
allow.play(who);
UltraDupe.dupeBanStorage.bannedMaterials.add(e.getCursor().getType());
who.sendMessage(Text.prefix("You have &cadded&7 the material &e%s&7 from the dupe bans.".formatted(Text.cleanName(what.getType().toString()))));
who.closeInventory();
refreshGUI(who);
isInGUI.add(who.getUniqueId());
UltraDupe.dupeBanStorage.save();
}
if ((e.getSlot() > 44 && e.getSlot() < 54) && what.getType().equals(Material.LIGHT_GRAY_STAINED_GLASS_PANE)) {
e.setCancelled(true);
deny.play(who);
return;
}
if (e.getSlot() > 0 && e.getSlot() < 45) {
allow.play(who);
UltraDupe.dupeBanStorage.bannedMaterials.remove(what.getType());
who.sendMessage(Text.prefix("You have &aremoved&7 the material &e%s&7 from the dupe bans.".formatted(Text.cleanName(what.getType().toString()))));
who.closeInventory();
refreshGUI(who);
isInGUI.add(who.getUniqueId());
UltraDupe.dupeBanStorage.save();
}
}
private static void handleDefine(Inventory inv) {
int pointer = 0;
for (Material bannedMaterial : UltraDupe.dupeBanStorage.bannedMaterials) {
if (pointer > 44) return;
inv.setItem(pointer, ItemBuilder.create()
.material(bannedMaterial)
.lore("")
.lore(Global.instance.color("&7(Light click to remove)"))
.build());
pointer++;
}
for (int i = 45; i < 53; i++) {
inv.setItem(i,GuiItems.BLANK);
}
}
}

View File

@@ -8,13 +8,24 @@ import org.bukkit.inventory.ItemStack;
public class GuiItems implements Global {
static Global g = Global.instance;
public static final ItemStack nextArrow = ItemBuilder.create()
public static final ItemStack NEXT_ARROW = ItemBuilder.create()
.material(Material.ARROW)
.name(g.color("Next Page"))
.build();
public static final ItemStack backArrow = ItemBuilder.create()
public static final ItemStack BACK_ARROW = ItemBuilder.create()
.material(Material.ARROW)
.name(g.color("Previous Page"))
.build();
public static final ItemStack INFO_ICON = ItemBuilder.create()
.material(Material.NAME_TAG)
.name(g.color("Info"))
.lore(g.color("Right click an item in your inventory to add it"))
.lore(g.color("Left click any item to remove it"))
.build();
public static final ItemStack BLANK = ItemBuilder.create()
.material(Material.LIGHT_GRAY_STAINED_GLASS_PANE)
.name("")
.build();
}