Small code changes that fixes minor bugs
This commit is contained in:
JaTiTV 2022-05-16 14:03:53 +02:00
parent a05b941aaf
commit 326dfae0e9
10 changed files with 28 additions and 31 deletions

View File

@ -6,7 +6,7 @@
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>CommandGUI_V2</artifactId> <artifactId>CommandGUI_V2</artifactId>
<version>2.7.1</version> <version>2.7.2</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>CommandGUI</name> <name>CommandGUI</name>

View File

@ -261,7 +261,7 @@ public class GUIListener implements Listener {
} }
private static void toggleUseItem(Player player, Gui gui) { private static void toggleUseItem(Player player, Gui gui) {
if (Events.useItemHashMap.get(player)) { if (Events.useItemHashMap.get(player.getName())) {
Commands.itemOff(player); Commands.itemOff(player);
} else { } else {
Commands.itemOn(player); Commands.itemOn(player);

View File

@ -4,6 +4,7 @@ import de.jatitv.commandguiv2.Spigot.Listener.UseItem_Listener.Events;
import de.jatitv.commandguiv2.Spigot.Main; import de.jatitv.commandguiv2.Spigot.Main;
import de.jatitv.commandguiv2.Spigot.system.UseItem; import de.jatitv.commandguiv2.Spigot.system.UseItem;
import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig; import de.jatitv.commandguiv2.Spigot.config.config.SelectConfig;
import de.jatitv.commandguiv2.Spigot.system.database.SelectDatabase;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -14,10 +15,10 @@ public class ItemChange {
if (SelectConfig.UseItem_InventorySlotEnforce) { if (SelectConfig.UseItem_InventorySlotEnforce) {
slot = SelectConfig.UseItem_InventorySlot; slot = SelectConfig.UseItem_InventorySlot;
} else { } else {
if (Events.useItemSlotHashMap.get(player) == null) { if (Events.useItemSlotHashMap.get(player.getName()) == null) {
slot = SelectConfig.UseItem_InventorySlot; slot = SelectConfig.UseItem_InventorySlot;
} else { } else {
slot = Events.useItemSlotHashMap.get(player); slot = Events.useItemSlotHashMap.get(player.getName());
} }
} }
@ -27,7 +28,7 @@ public class ItemChange {
UseItem.removeItem(player); UseItem.removeItem(player);
if (UseItem.protection(player, false)) return; if (UseItem.protection(player, false)) return;
if (SelectConfig.UseItem_GiveOnlyOnFirstJoin) { if (SelectConfig.UseItem_GiveOnlyOnFirstJoin) {
if (!SelectConfig.UseItem_AllowToggle || Events.useItemHashMap.get(player)) { if (!SelectConfig.UseItem_AllowToggle || Events.useItemHashMap.get(player.getName())) {
if (!player.hasPlayedBefore()) { if (!player.hasPlayedBefore()) {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
@ -53,8 +54,7 @@ public class ItemChange {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
if (player == null) return; if (!SelectConfig.UseItem_AllowToggle || Events.useItemHashMap.get(player.getName())) {
if (!SelectConfig.UseItem_AllowToggle || Events.useItemHashMap.get(player)) {
if (SelectConfig.UseItem_InventorySlotEnforce || player.getInventory().getItem(slot - 1) == null) { if (SelectConfig.UseItem_InventorySlotEnforce || player.getInventory().getItem(slot - 1) == null) {
send.debug(Main.plugin, "Give: " + player.getName()); send.debug(Main.plugin, "Give: " + player.getName());
UseItem.giveUseItem(player); UseItem.giveUseItem(player);

View File

@ -34,16 +34,13 @@ import java.util.Iterator;
public class Events implements Listener { public class Events implements Listener {
public static HashMap<Player, Boolean> useItemHashMap = new HashMap<>(); public static HashMap<String, Boolean> useItemHashMap = new HashMap<>();
public static HashMap<Player, Integer> useItemSlotHashMap = new HashMap<>(); public static HashMap<String, Integer> useItemSlotHashMap = new HashMap<>();
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent e) { public void onJoin(PlayerJoinEvent e) {
if (SelectDatabase.selectItemStatus(e.getPlayer())) { useItemHashMap.put(e.getPlayer().getName(), SelectDatabase.selectItemStatus(e.getPlayer()));
useItemHashMap.put(e.getPlayer(), true); useItemSlotHashMap.put(e.getPlayer().getName(), SelectDatabase.selectSlot(e.getPlayer()));
} else useItemHashMap.put(e.getPlayer(), false);
useItemSlotHashMap.put(e.getPlayer(), SelectDatabase.selectSlot(e.getPlayer()));
if (CGuiAPI.JoinDisable) { if (CGuiAPI.JoinDisable) {
send.debug(Main.plugin, "JoinDisable"); send.debug(Main.plugin, "JoinDisable");
@ -62,7 +59,7 @@ public class Events implements Listener {
@EventHandler @EventHandler
public void onJoin(PlayerQuitEvent e) { public void onJoin(PlayerQuitEvent e) {
useItemHashMap.remove(e.getPlayer()); useItemHashMap.remove(e.getPlayer().getName());
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)

View File

@ -124,10 +124,10 @@ public class Commands {
if (SelectConfig.UseItem_InventorySlotEnforce) { if (SelectConfig.UseItem_InventorySlotEnforce) {
slot = SelectConfig.UseItem_InventorySlot; slot = SelectConfig.UseItem_InventorySlot;
} else { } else {
if (Events.useItemSlotHashMap.get(player) == null) { if (Events.useItemSlotHashMap.get(player.getName()) == null) {
slot = SelectConfig.UseItem_InventorySlot; slot = SelectConfig.UseItem_InventorySlot;
} else { } else {
slot = Events.useItemSlotHashMap.get(player); slot = Events.useItemSlotHashMap.get(player.getName());
} }
} }
send.debug(Main.plugin, String.valueOf(slot)); send.debug(Main.plugin, String.valueOf(slot));
@ -175,8 +175,8 @@ public class Commands {
return; return;
} }
if (Events.useItemHashMap.get(player)) { if (Events.useItemHashMap.get(player.getName())) {
if (Objects.equals(Events.useItemSlotHashMap.get(player), setSlot)) { if (Objects.equals(Events.useItemSlotHashMap.get(player.getName()), setSlot)) {
player.sendMessage(SelectMessages.ItemSlotAlreadySet.replace("[slot]", setSlot.toString())); player.sendMessage(SelectMessages.ItemSlotAlreadySet.replace("[slot]", setSlot.toString()));
return; return;
} }
@ -189,9 +189,9 @@ public class Commands {
UseItem.removeItem(player); UseItem.removeItem(player);
SelectDatabase.setSlot(player, setSlot); SelectDatabase.setSlot(player, setSlot);
Events.useItemSlotHashMap.replace(player, setSlot); Events.useItemSlotHashMap.replace(player.getName(), setSlot);
if (Events.useItemHashMap.get(player)) { if (Events.useItemHashMap.get(player.getName())) {
UseItem.giveUseItem(player); UseItem.giveUseItem(player);
} }

View File

@ -95,7 +95,7 @@ public class OpenGUI {
toggleOff(function, slot.slot, player, inventory); toggleOff(function, slot.slot, player, inventory);
} }
} else if (function.toggleUseItem) { } else if (function.toggleUseItem) {
if (Events.useItemHashMap.get(player)) { if (Events.useItemHashMap.get(player.getName())) {
toggleOn(function, slot.slot, player, inventory); toggleOn(function, slot.slot, player, inventory);
} else { } else {
toggleOff(function, slot.slot, player, inventory); toggleOff(function, slot.slot, player, inventory);

View File

@ -38,17 +38,17 @@ public class Placeholder extends PlaceholderExpansion {
@Override @Override
public String onPlaceholderRequest(Player p, String params) { public String onPlaceholderRequest(Player p, String params) {
if (params.contains("useitem_boolean")) { if (params.contains("useitem_boolean")) {
return Events.useItemHashMap.get(p).toString(); return Events.useItemHashMap.get(p.getName()).toString();
} }
if (params.contains("useitem")) { if (params.contains("useitem")) {
if (Events.useItemHashMap.get(p)) { if (Events.useItemHashMap.get(p.getName())) {
return SelectConfig.placeholderTrue; return SelectConfig.placeholderTrue;
} else return SelectConfig.placeholderFalse; } else return SelectConfig.placeholderFalse;
} }
if (params.contains("slot")){ if (params.contains("slot")){
return Events.useItemSlotHashMap.get(p).toString(); return Events.useItemSlotHashMap.get(p.getName()).toString();
} }
return null; return null;

View File

@ -29,10 +29,10 @@ public class UseItem {
if (SelectConfig.UseItem_InventorySlotEnforce) { if (SelectConfig.UseItem_InventorySlotEnforce) {
slot = SelectConfig.UseItem_InventorySlot; slot = SelectConfig.UseItem_InventorySlot;
} else { } else {
if (Events.useItemSlotHashMap.get(player) == null) { if (Events.useItemSlotHashMap.get(player.getName()) == null) {
slot = SelectConfig.UseItem_InventorySlot; slot = SelectConfig.UseItem_InventorySlot;
} else { } else {
slot = Events.useItemSlotHashMap.get(player); slot = Events.useItemSlotHashMap.get(player.getName());
} }
} }
if (SelectConfig.UseItem_InventorySlot_FreeSlot) { if (SelectConfig.UseItem_InventorySlot_FreeSlot) {

View File

@ -49,7 +49,7 @@ public class SelectDatabase {
} }
public static void setItemStatusTrue(Player player) { public static void setItemStatusTrue(Player player) {
Events.useItemHashMap.replace(player, true); Events.useItemHashMap.replace(player.getName(), true);
switch (Storage) { switch (Storage) {
case MYSQL: case MYSQL:
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`) VALUES ('" + player.getUniqueId() + "', '" + player.getName() MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
@ -67,7 +67,7 @@ public class SelectDatabase {
} }
public static void setItemStatusFalse(Player player) { public static void setItemStatusFalse(Player player) {
Events.useItemHashMap.replace(player, false); Events.useItemHashMap.replace(player.getName(), false);
switch (Storage) { switch (Storage) {
case MYSQL: case MYSQL:
MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Status`) VALUES ('" + player.getUniqueId() + "', '" + player.getName() MySQL.query("INSERT INTO `gui-item` (`UUID`, `Name`, `Status`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()

View File

@ -44,11 +44,11 @@ public class CGuiAPI {
} }
public static Boolean selectPlayerItemEnable(Player player) { public static Boolean selectPlayerItemEnable(Player player) {
return Events.useItemHashMap.get(player); return Events.useItemHashMap.get(player.getName());
} }
public static Integer selectPlayerItemSlot(Player player) { public static Integer selectPlayerItemSlot(Player player) {
return Events.useItemSlotHashMap.get(player); return Events.useItemSlotHashMap.get(player.getName());
} }
public static void setPlayerItemEnable(Player player, Boolean value) { public static void setPlayerItemEnable(Player player, Boolean value) {