Various code simplification/fixes and a lot of typo/grammar fixes (may brake some stuff)

This commit is contained in:
2023-06-20 00:15:46 +02:00
parent c984b63cee
commit 5edd8cdfec
151 changed files with 909 additions and 983 deletions

View File

@@ -24,36 +24,36 @@ import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.paper.util.BukkitEvent;
/**
* Managed a « lobby » type hotbar menu/inventory. It represents items in the player inventory on which you can right click on it.
* Managed a "lobby" type hot bar menu/inventory. It represents items in the
* player inventory on which you can right-click on it.
* The player can't move or drop these items.
*
*/
public class GUIHotBar implements Listener {
private final Map<ItemStack, BiConsumer<PlayerInventory, ItemStack>> itemsAndSetters = new HashMap<>();
private final Map<ItemStack, Consumer<Player>> itemsAndRunnables = new HashMap<>();
private final Map<ItemStack, Consumer<Player>> itemsAndClickListeners = new HashMap<>();
private final int defltSlot;
private final int defaultSlot;
private final List<Player> currentPlayers = new ArrayList<>();
public GUIHotBar(int defaultSlot) {
defltSlot = Math.max(0, Math.min(8, defaultSlot));
this.defaultSlot = Math.max(0, Math.min(8, defaultSlot));
BukkitEvent.register(this);
}
/**
* Add the item to this hotbar menu. if there is already players hooked to this hotbar, the item will be directly added to
* Add the item to this hot bar menu. if there is already players hooked to this hot bar, the item will be directly added to
* their inventories.
* @param i the item stack
* @param setter code executed to put the item in the inventory. Additionally check for permission before doing the addition.
* @param run the Runnable to run when the user right click on the item in the hotbar.
* @param setter code executed to put the item in the inventory. Additionally, check for permission before doing the addition.
* @param run the Runnable to run when the user right-click on the item in the hot bar.
*/
public GUIHotBar addItem(ItemStack i, BiConsumer<PlayerInventory, ItemStack> setter, Consumer<Player> run) {
itemsAndSetters.put(i, setter);
itemsAndRunnables.put(i, run);
itemsAndClickListeners.put(i, run);
for (Player p : currentPlayers)
addItemToPlayer(p, i);
@@ -62,9 +62,9 @@ public class GUIHotBar implements Listener {
}
/**
* Add the hotbar elements to this player.
* Add the hot bar elements to this player.
*
* The players is automatically removed when they quit. You can remove it before by calling {@link #removePlayer(Player)}.
* The player is automatically removed when they quit. You can remove it before by calling {@link #removePlayer(Player)}.
*/
public void addPlayer(Player p) {
if (!currentPlayers.contains(p))
@@ -74,11 +74,11 @@ public class GUIHotBar implements Listener {
addItemToPlayer(p, is);
}
p.getInventory().setHeldItemSlot(defltSlot);
p.getInventory().setHeldItemSlot(defaultSlot);
}
/**
* Detach this player from this hotbar manager and removes the managed items from the players inventory.
* Detach this player from this hot bar manager and removes the managed items from the players inventory.
*/
public void removePlayer(Player p) {
if (!currentPlayers.contains(p))
@@ -110,9 +110,9 @@ public class GUIHotBar implements Listener {
public void addItemToPlayer(Player p, ItemStack is) {
if (!itemsAndSetters.containsKey(is))
throw new IllegalArgumentException("The provided ItemStack is not registered in this HotbarMenu");
throw new IllegalArgumentException("The provided ItemStack is not registered in this GUIHotBar");
if (!currentPlayers.contains(p))
throw new IllegalArgumentException("The provided Player is not registered in this HotbarMenu");
throw new IllegalArgumentException("The provided Player is not registered in this GUIHotBar");
itemsAndSetters.get(is).accept(p.getInventory(), is.clone());
}
@@ -153,10 +153,10 @@ public class GUIHotBar implements Listener {
Player p = event.getPlayer();
for (ItemStack is : itemsAndRunnables.keySet()) {
for (ItemStack is : itemsAndClickListeners.keySet()) {
if (item.isSimilar(is)) {
try {
itemsAndRunnables.get(is).accept(p);
itemsAndClickListeners.get(is).accept(p);
} catch (Exception e) {
Log.severe(e);
}
@@ -181,7 +181,7 @@ public class GUIHotBar implements Listener {
for (ItemStack is : itemsAndSetters.keySet()) {
if (item != null && item.isSimilar(is)) {
try {
itemsAndRunnables.get(is).accept((Player) inv.getHolder());
itemsAndClickListeners.get(is).accept((Player) inv.getHolder());
} catch (Exception e) {
Log.severe(e);
}

View File

@@ -31,7 +31,7 @@ public class GUIInventory implements Listener {
/**
* Used as parameter of {@link #buildButton(ItemStack, Integer, ComponentLike, List, Map)} to indicate that a button should
* shine like an enchanted object, without showing enchant informations in the hover text.
* shine like an enchanted object, without showing enchant information in the hover text.
*/
public static final Map<Enchantment, Integer> FAKE_ENCHANT = ImmutableMap.of(Enchantment.DURABILITY, 1);
@@ -44,7 +44,7 @@ public class GUIInventory implements Listener {
/**
* Create a new inventory based GUI.
* @param p the player for which to create the GUI.
* @param nbLines the number of invotory lines for the interface.
* @param nbLines the number of inventory lines for the interface.
* @param title the title of the GUI (title of the inventory)
* @param closeEventAction the action to perform when the player closes the GUI inventory
*/
@@ -73,7 +73,7 @@ public class GUIInventory implements Listener {
* @param p the slot index.
* @param iStack the item to put in the slot.
* @param clickEventActions the action to perform when the user clicks that button. The event passed as a parameter
* is already cancelled. It is possible to uncancel it if needed.
* is already cancelled. It is possible to un-cancel it if needed.
*/
public void setButtonIfEmpty(int p, ItemStack iStack, Consumer<InventoryClickEvent> clickEventActions) {
if (inv.getItem(p) == null)
@@ -85,7 +85,7 @@ public class GUIInventory implements Listener {
* @param p the slot index.
* @param iStack the item to put in the slot.
* @param clickEventActions the action to perform when the user clicks that button. The event passed as a parameter
* is already cancelled. It is possible to uncancel it if needed.
* is already cancelled. It is possible to un-cancel it if needed.
*/
public void setButton(int p, ItemStack iStack, Consumer<InventoryClickEvent> clickEventActions) {
inv.setItem(p, iStack);
@@ -96,7 +96,7 @@ public class GUIInventory implements Listener {
* Update/replace the action to perform for a specific slot.
* @param p the slot index.
* @param clickEventActions the action to perform when the user clicks that button. The event passed as a parameter
* is already cancelled. It is possible to uncancel it if needed.
* is already cancelled. It is possible to un-cancel it if needed.
*/
public void changeClickEventAction(int p, Consumer<InventoryClickEvent> clickEventActions) {
onClickEvents.put(p, clickEventActions);
@@ -122,7 +122,7 @@ public class GUIInventory implements Listener {
/**
* Force this GUI to be closes, without the intervention of the player.
* The bukkit API will call the {@link InventoryCloseEvent}, trigerring eventual actions associated with this event.
* The bukkit API will call the {@link InventoryCloseEvent}, triggering eventual actions associated with this event.
*/
public void forceClose() {
if (!isOpened) return;