Tried to fix the GUI

This commit is contained in:
TheTrouper
2024-02-29 15:52:41 -06:00
parent 23fc9025ba
commit 093b8f250d
6 changed files with 125 additions and 375 deletions

View File

@@ -39,6 +39,13 @@ public class UltraDupeCommand implements CustomCommand {
default -> DupeBansCommand.handleListBans(p);
}
}
case "debug" -> {
switch (args.get(1).toString()) {
case "bans" -> {
populateBannedMaterials();
}
}
}
case "toggle" -> {
switch (args.get(1).toString()) {
case "debug" -> {
@@ -143,4 +150,19 @@ private void handleItemEdit(Player p, Args args) {
}
}
}
private static void populateBannedMaterials() {
int numberOfMaterials = 100;
for (int i = 0; i < numberOfMaterials; i++) {
Material randomMaterial = getRandomMaterial();
UltraDupe.dupeBanStorage.bannedMaterials.add(randomMaterial);
}
}
private static Material getRandomMaterial() {
Material[] materials = Material.values();
int randomIndex = (int) (Math.random() * materials.length);
return materials[randomIndex];
}
}

View File

@@ -5,9 +5,12 @@ import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import io.github.itzispyder.pdk.utils.misc.SoundPlayer;
import me.trouper.ultradupe.UltraDupe;
import me.trouper.ultradupe.server.util.ServerUtils;
import me.trouper.ultradupe.server.util.Text;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
@@ -36,45 +39,53 @@ public class DupeBanGUI extends CustomGui implements Global {
.size(54)
.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(45, GuiItems.BACK_ARROW, event -> {
event.getWhoClicked().sendMessage(Text.prefix("You clicked back on %s".formatted(event.getClickedInventory())));
decrementPage(event.getClickedInventory());
})
.define(53, GuiItems.NEXT_ARROW, event -> {
event.getWhoClicked().sendMessage(Text.prefix("You clicked next on %s".formatted(event.getClickedInventory())));
incrementPage(event.getClickedInventory());
})
.define(49, GuiItems.INFO_ICON, event -> {})
.build();
private static void handleMainClick(InventoryClickEvent e) {
Player who = (Player) e.getWhoClicked();
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();
if (!isInGUI.contains(e.getWhoClicked().getUniqueId())) {
deny.play(who);
e.getWhoClicked().setHealth(0);
return;
}
int where = e.getSlot();
ItemStack what = e.getClickedInventory().getItem(where);
ItemStack with = e.getCursor();
ItemStack current = e.getCurrentItem();
if (!with.isEmpty()) {
//who.sendMessage(Text.prefix("You clicked %s with %s at %s").formatted(current,with,where));
allow.play(who);
UltraDupe.dupeBanStorage.bannedMaterials.add(with.getType());
who.sendMessage(Text.prefix("You have &cadded&7 the material &e%s&7 from the dupe bans.".formatted(Text.cleanName(with.getType().toString()))));
who.closeInventory();
refreshGUI(who);
isInGUI.add(who.getUniqueId());
UltraDupe.dupeBanStorage.save();
return;
}
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;
}
@@ -90,10 +101,52 @@ public class DupeBanGUI extends CustomGui implements Global {
}
}
public static void incrementPage(Inventory inv) {
ItemStack info = inv.getItem(49);
int pageNumber = info.getItemMeta().getCustomModelData() + 1;
ServerUtils.verbose("Incrementing to Page: %s".formatted(pageNumber));
inv.getItem(49).getItemMeta().setCustomModelData(pageNumber);
info.getItemMeta().lore().set(3, Component.text(g.color("&7Page &9%s&7/&b%s".formatted(pageNumber,getMaxPages()))));
updatePage(inv);
}
public static void decrementPage(Inventory inv) {
ItemStack info = inv.getItem(49);
int pageNumber = info.getItemMeta().getCustomModelData() - 1;
ServerUtils.verbose("Decrementing to Page: %s".formatted(pageNumber));
inv.getItem(49).getItemMeta().setCustomModelData(pageNumber);
info.getItemMeta().lore().set(3, Component.text(g.color("&7Page &9%s&7/&b%s".formatted(pageNumber,getMaxPages()))));
updatePage(inv);
}
public static void updatePage(Inventory inv) {
ItemStack info = inv.getItem(49);
int pageNumber = info.getItemMeta().getCustomModelData();
ServerUtils.verbose("Updating Page: %s".formatted(pageNumber));
inv.getItem(49).getItemMeta().setCustomModelData(pageNumber);
info.getItemMeta().lore().set(3, Component.text(g.color("&7Page &9%s&7/&b%s".formatted(pageNumber,getMaxPages()))));
setupPage(inv,pageNumber);
}
private static void handleDefine(Inventory inv) {
setupPage(inv,1);
}
private static void setupPage(Inventory inv, int pageNumber) {
int pageSize = 46;
int startIndex = (pageNumber - 1) * pageSize;
int endIndex = Math.min(startIndex + pageSize, UltraDupe.dupeBanStorage.bannedMaterials.size());
int pointer = 0;
for (Material bannedMaterial : UltraDupe.dupeBanStorage.bannedMaterials) {
if (pointer > 44) return;
for (int i = startIndex; i < endIndex; i++) {
Material bannedMaterial = UltraDupe.dupeBanStorage.bannedMaterials.get(i);
inv.setItem(pointer, ItemBuilder.create()
.material(bannedMaterial)
.lore("")
@@ -101,12 +154,25 @@ public class DupeBanGUI extends CustomGui implements Global {
.build());
pointer++;
}
for (int i = 45; i < 53; i++) {
inv.setItem(i,GuiItems.BLANK);
}
ItemStack info = GuiItems.INFO_ICON;
info.getItemMeta().lore().set(3, Component.text(g.color("&7Page &9%s&7/&b%s".formatted(pageNumber,getMaxPages()))));
info.getItemMeta().setCustomModelData(pageNumber);
inv.setItem(45,GuiItems.BACK_ARROW);
inv.setItem(49,info);
inv.setItem(53,GuiItems.NEXT_ARROW);
}
private static int getMaxPages() {
int pageSize = 46;
int totalMaterials = UltraDupe.dupeBanStorage.bannedMaterials.size();
return (int) Math.ceil((double) totalMaterials / pageSize);
}
}

View File

@@ -10,22 +10,25 @@ public class GuiItems implements Global {
public static final ItemStack NEXT_ARROW = ItemBuilder.create()
.material(Material.ARROW)
.name(g.color("Next Page"))
.name(g.color("&bNext Page &7➔"))
.build();
public static final ItemStack BACK_ARROW = ItemBuilder.create()
.material(Material.ARROW)
.name(g.color("Previous Page"))
.name(g.color("&7\uD83E\uDC78 &bPrevious 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"))
.name(g.color("&b&lInfo"))
.lore(g.color("&3➥ &7(Drag-n-drop) &fAdds the item"))
.lore(g.color("&3➥ &7(Left-Click) &fRemoves the item"))
.lore(g.color(""))
.lore(g.color("Page 1/1"))
.customModelData(1)
.build();
public static final ItemStack BLANK = ItemBuilder.create()
.material(Material.LIGHT_GRAY_STAINED_GLASS_PANE)
.name("")
.name(g.color("&7"))
.build();
}

View File

@@ -1,263 +0,0 @@
/**
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
*
* I made this cuz Bukkit API sounds management is trash.
* by ImproperIssues
*/
package me.trouper.ultradupe.server.sound;
import me.trouper.ultradupe.UltraDupe;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class SoundPlayer {
private Location location;
private Sound sound;
private float volume;
private float pitch;
/**
* Constructs a new sound, this aims to add more methods to
* the Bukkit APIs Sound class, as they don't have many
* methods to use.
*
* @param location Location
* @param sound Sound
* @param volume float
* @param pitch float
*/
public SoundPlayer(Location location, Sound sound, float volume, float pitch) {
this.location = location;
this.sound = sound;
this.pitch = pitch;
this.volume = volume;
}
/**
* Plays a sound to a player but at the store location
*
* @param player Player
*/
public void play(Player player) {
player.playSound(this.location,this.sound,this.volume,this.pitch);
}
/**
* Plays a sound to a player but at the player's location
*
* @param player Player
*/
public void playAt(Player player) {
player.playSound(player.getLocation(),this.sound,this.volume,this.pitch);
}
/**
* Plays the sound to all players within a distance, but at the stored location.
*
* @param distance double
*/
public void playWithin(double distance) {
for (Player p : Bukkit.getOnlinePlayers()) {
if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) {
p.playSound(this.location,this.sound,this.volume,this.pitch);
}
}
}
/**
* Plays the sound to all players within a distance, but at the players' location.
*
* @param distance double
*/
public void playWithinAt(double distance) {
for (Player p : Bukkit.getOnlinePlayers()) {
if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) {
p.playSound(p.getLocation(),this.sound,this.volume,this.pitch);
}
}
}
/**
* Plays the sound to all players on the server, but at the stored location.
*/
public void playAll() {
for (Player p : Bukkit.getOnlinePlayers()) p.playSound(this.location,this.sound,this.volume,this.pitch);
}
/**
* Plays the sound to all players on the server, but at the players' location.
*/
public void playAllAt() {
for (Player p : Bukkit.getOnlinePlayers()) p.playSound(p.getLocation(),this.sound,this.volume,this.pitch);
}
/**
* Repeats a sound to a player, but at the stored location.
*
* @param player Player
* @param times int
* @param tickDelay int
*/
public void repeat(Player player, int times, int tickDelay) {
new BukkitRunnable() {
int i = 0;
@Override
public void run() {
if (i < times) {
play(player);
i ++;
} else {
this.cancel();
}
}
}.runTaskTimer(UltraDupe.getInstance(),0,tickDelay);
}
/**
* Repeats a sound to a player, but at the player's location.
*
* @param player Player
* @param times int
* @param tickDelay int
*/
public void repeatAt(Player player, int times, int tickDelay) {
new BukkitRunnable() {
int i = 0;
@Override
public void run() {
if (i < times) {
playAt(player);
i ++;
} else {
this.cancel();
}
}
}.runTaskTimer(UltraDupe.getInstance(),0,tickDelay);
}
/**
* Repeats a sound to all players on the server, but at the stored location.
*
* @param times int
* @param tickDelay int
*/
public void repeatAll(int times, int tickDelay) {
new BukkitRunnable() {
int i = 0;
@Override
public void run() {
if (i < times) {
playAll();
i ++;
} else {
this.cancel();
}
}
}.runTaskTimer(UltraDupe.getInstance(),0,tickDelay);
}
/**
* Repeats a sound to all players on the server, but at the players' location.
*
* @param times int
* @param tickDelay int
*/
public void repeatAllAt(int times, int tickDelay) {
new BukkitRunnable() {
int i = 0;
@Override
public void run() {
if (i < times) {
playAllAt();
i ++;
} else {
this.cancel();
}
}
}.runTaskTimer(UltraDupe.getInstance(),0,tickDelay);
}
/**
* Repeats a sound to all players within a radius, but at the stored location.
*
* @param radius double
* @param times int
* @param tickDelay int
*/
public void repeatAll(double radius,int times, int tickDelay) {
new BukkitRunnable() {
int i = 0;
@Override
public void run() {
if (i < times) {
playWithin(radius);
i ++;
} else {
this.cancel();
}
}
}.runTaskTimer(UltraDupe.getInstance(),0,tickDelay);
}
/**
* Repeats a sound to all players within a radius, but at the players' location.
*
* @param distance double
* @param times int
* @param tickDelay int
*/
public void repeatAllAt(double distance, int times, int tickDelay) {
new BukkitRunnable() {
int i = 0;
@Override
public void run() {
if (i < times) {
playWithinAt(distance);
i ++;
} else {
this.cancel();
}
}
}.runTaskTimer(UltraDupe.getInstance(),0,tickDelay);
}
public Sound getSound() {
return sound;
}
public float getPitch() {
return pitch;
}
public float getVolume() {
return volume;
}
public Location getLocation() {
return location;
}
public void setPitch(float pitch) {
this.pitch = pitch;
}
public void setVolume(float volume) {
this.volume = volume;
}
public void setSound(Sound sound) {
this.sound = sound;
}
public void setLocation(Location location) {
this.location = location;
}
}

View File

@@ -5,7 +5,7 @@ import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
public class CipherUtils {
private static final String secretKey = "GG8T885O4Yd/86OMVFdL0w=="; // 16, 24, or 32 bytes
private static final String secretKey = "aYN8iuz1kMHU2af8iMv7UY0HTmiqr2yqserThqQQufNO8E9jBMFdgAbo5deLVM7B"; // 16, 24, or 32 bytes
private static final String algorithm = "AES";
public static String encrypt(String strToEncrypt) {
try {

View File

@@ -1,78 +0,0 @@
package me.trouper.ultradupe.server.util;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
/**
* Randomize items from a list
* @param <T> list of?
*/
public class Randomizer<T> {
public static long generateID() {
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String formattedDate = dateFormat.format(now);
long id = Long.parseLong(formattedDate);
return id;
}
private final List<T> array;
/**
* From array list
* @param array list
*/
public Randomizer(List<T> array) {
this.array = array;
}
/**
* From set
* @param array set
*/
public Randomizer(Set<T> array) {
this.array = new ArrayList<>(array);
}
/**
* From array
* @param array array
*/
public Randomizer(T[] array) {
this.array = List.of(array);
}
/**
* Pick random from the array
* @return random of list of?
*/
public T pickRand() {
return array.get(rand(array.size() - 1));
}
/**
* Generates a random integer from 1 to (max)
* @param max max value
* @return random
*/
public static int rand(int max) {
if (max <= 0) throw new IllegalArgumentException("max cannot be less than 1!");
return (int) Math.ceil(Math.random() * max);
}
/**
* Generates a random integer from (min) to (max)
* @param min min value
* @param max max value
* @return random
*/
public static int rand(int min, int max) {
if (max <= 0 || min <= 0) throw new IllegalArgumentException("max or min cannot be less than 1!");
if (max <= min) throw new IllegalArgumentException("max cannot be less than or equal to min!");
return min + (int) Math.floor(Math.random() * (max - min + 1));
}
}