From 5fb8b29510673d29fb6e91c6171048d9e69ac513 Mon Sep 17 00:00:00 2001 From: PlasmaFX Date: Sun, 17 Feb 2019 11:17:13 -0500 Subject: [PATCH] Improved Admin GUI and fixed bugs --- .gitlab-ci.yml | 2 +- .../epicbuckets/command/CommandManager.java | 1 - .../epicbuckets/file/ConfigManager.java | 9 +- .../epicbuckets/genbucket/Genbucket.java | 10 ++ .../genbucket/GenbucketManager.java | 11 ++ .../epicbuckets/genbucket/GenbucketType.java | 4 + .../genbucket/types/Horizontal.java | 4 + .../epicbuckets/genbucket/types/Infused.java | 4 + .../genbucket/types/PsuedoVertical.java | 4 + .../epicbuckets/genbucket/types/Vertical.java | 4 + .../com/songoda/epicbuckets/gui/GUIPanel.java | 133 +++++++++++++++--- .../listeners/GenbucketPlaceListener.java | 2 +- .../src/main/resources/en_US.lang | 10 +- .../src/main/resources/plugin.yml | 2 +- 14 files changed, 173 insertions(+), 27 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eea8c0b..49c717e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "EpicBuckets" path: "/builds/Songoda/epicbuckets" - version: "1.5.1" + version: "1.5.2" build: stage: build diff --git a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/command/CommandManager.java b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/command/CommandManager.java index 646716d..57b1739 100644 --- a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/command/CommandManager.java +++ b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/command/CommandManager.java @@ -8,7 +8,6 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import java.util.ArrayList; import java.util.Collections; diff --git a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/file/ConfigManager.java b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/file/ConfigManager.java index 0ec5a40..7db8699 100644 --- a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/file/ConfigManager.java +++ b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/file/ConfigManager.java @@ -177,10 +177,15 @@ public class ConfigManager { epicBuckets.getConfig().getConfigurationSection("COST-FOR-INFINITE-USE").getKeys(false) .forEach(bucket -> { + HashMap chargingCostsPerItem = new HashMap<>(); + epicBuckets.getConfig().getConfigurationSection("COST-FOR-INFINITE-USE." + bucket).getKeys(false) - .forEach(item -> chargingCostsPerItem.put(XMaterial.valueOf(item).parseItem(), epicBuckets.getConfig().getDouble("COST-FOR-INFINITE-USE." + bucket + "." + item))); + .forEach(item -> chargingCostsPerItem.put(XMaterial.valueOf(item).parseItem(), + epicBuckets.getConfig().getDouble("COST-FOR-INFINITE-USE." + bucket + "." + item))); + infiniteUseCost.put(GenbucketType.valueOf(bucket), chargingCostsPerItem); + }); setCooldown(epicBuckets.getConfig().getInt("GENBUCKET-DELAY")); @@ -447,7 +452,7 @@ public class ConfigManager { public double getInfiniteUseCostForGenbucketType(GenbucketType genbucketType, ItemStack item) { for (ItemStack itemStack : infiniteUseCost.get(genbucketType).keySet()) { - if (itemStack.getType() == item.getType() && itemStack.getData() == item.getData()) { + if (itemStack.getType().equals(item.getType()) && itemStack.getData().equals(item.getData())) { return infiniteUseCost.get(genbucketType).get(itemStack); } } diff --git a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/Genbucket.java b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/Genbucket.java index b205186..5c1e8ff 100644 --- a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/Genbucket.java +++ b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/Genbucket.java @@ -137,21 +137,31 @@ public abstract class Genbucket { } protected boolean spongeInRange(Block block) { + if (!epicBuckets.getConfigManager().isSpongeCheck()) return false; + int radius = (epicBuckets.getConfigManager().getSpongeRadius() - 1) / 2; + for (int x = -radius; x <= radius; x++) { for (int z = -radius; z <= radius; z++) { if (block.getRelative(x, 0, z).getType() == XMaterial.SPONGE.parseMaterial()) return true; } } + return false; } protected boolean placeGen(Block block) { + if (!epicBuckets.getConfigManager().getIgnoredMaterials().contains(XMaterial.requestXMaterial(block.getType().name(), block.getData()))) return false; + + if (!epicBuckets.canBuild(owner, block.getLocation())) return false; + if (spongeInRange(block)) return false; + block.setType(getGenItem().getType()); + return true; } diff --git a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/GenbucketManager.java b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/GenbucketManager.java index 5967079..2d7036e 100644 --- a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/GenbucketManager.java +++ b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/GenbucketManager.java @@ -41,6 +41,17 @@ public class GenbucketManager { admins.add(player); } + public boolean isGenbucketActive(UUID genbucketUUID) { + for (UUID uuid : activeGens.keySet()) + for (Genbucket bucket : activeGens.get(uuid)) if (bucket.getGenUUID().equals(genbucketUUID)) return true; + return false; + } + + public void deactiveAll() { + for (UUID uuid : activeGens.keySet()) + for (Genbucket genbucket : activeGens.get(uuid)) unregisterGenbucketForPlayer(genbucket.getOwner(), genbucket.getGenUUID()); + } + public List activeGensInOneList() { List gens = new ArrayList<>(); activeGens.forEach((uuid, genbuckets) -> gens.addAll(genbuckets)); diff --git a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/GenbucketType.java b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/GenbucketType.java index 24076e3..6cfe19f 100644 --- a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/GenbucketType.java +++ b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/GenbucketType.java @@ -13,6 +13,10 @@ public enum GenbucketType { this.name = name; } + public String formatName() { + return name.toUpperCase().charAt(0) + name.toLowerCase().substring(1); + } + @Override public String toString() { return name; diff --git a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/Horizontal.java b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/Horizontal.java index cd7a21f..be137c6 100644 --- a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/Horizontal.java +++ b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/Horizontal.java @@ -22,6 +22,10 @@ public class Horizontal extends Genbucket { BukkitRunnable runnable = new BukkitRunnable() { @Override public void run() { + if (!epicBuckets.getGenbucketManager().isGenbucketActive(getGenUUID())) { + cancel(); + return; + } if (blocksPlaced >= epicBuckets.getConfigManager().getMaxHorizontalLength() || !placeGen(getNextBlock())) { epicBuckets.getGenbucketManager().unregisterGenbucketForPlayer(getOwner(), getGenUUID()); cancel(); diff --git a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/Infused.java b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/Infused.java index be84682..0a0b990 100644 --- a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/Infused.java +++ b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/Infused.java @@ -24,6 +24,10 @@ public class Infused extends Genbucket { BukkitRunnable runnable = new BukkitRunnable() { @Override public void run() { + if (!epicBuckets.getGenbucketManager().isGenbucketActive(getGenUUID())) { + cancel(); + return; + } // if (isGravityGen()) { // if (!side1 && !side2) { // epicBuckets.getGenbucketManager().unregisterGenbucketForPlayer(getOwner(), getGenUUID()); diff --git a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/PsuedoVertical.java b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/PsuedoVertical.java index 9419aca..83d8d94 100644 --- a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/PsuedoVertical.java +++ b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/PsuedoVertical.java @@ -22,6 +22,10 @@ public class PsuedoVertical extends Genbucket { BukkitRunnable runnable = new BukkitRunnable() { @Override public void run() { + if (!epicBuckets.getGenbucketManager().isGenbucketActive(getGenUUID())) { + cancel(); + return; + } if (isBelowVoid(blocksUp) || blocksUp >= epicBuckets.getConfigManager().getMaxVerticalHeight()) { epicBuckets.getGenbucketManager().unregisterGenbucketForPlayer(getOwner(), getGenUUID()); cancel(); diff --git a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/Vertical.java b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/Vertical.java index 7353130..b74d7f7 100644 --- a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/Vertical.java +++ b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/genbucket/types/Vertical.java @@ -22,6 +22,10 @@ public class Vertical extends Genbucket { BukkitRunnable runnable = new BukkitRunnable() { @Override public void run() { + if (!epicBuckets.getGenbucketManager().isGenbucketActive(getGenUUID())) { + cancel(); + return; + } if (isGravityGen()) { if (!gravityGen(blocksPlaced)) { epicBuckets.getGenbucketManager().unregisterGenbucketForPlayer(getOwner(), getGenUUID()); diff --git a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/gui/GUIPanel.java b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/gui/GUIPanel.java index a15e452..f71ea28 100644 --- a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/gui/GUIPanel.java +++ b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/gui/GUIPanel.java @@ -7,45 +7,73 @@ import com.songoda.epicbuckets.utils.XMaterial; import com.songoda.epicbuckets.utils.gui.AbstractGUI; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; -import java.util.*; +import java.util.UUID; +import java.util.List; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Arrays; public class GUIPanel extends AbstractGUI { private EpicBuckets epicBuckets; - private int size = 54; + private int page = 0; public GUIPanel(Player player) { super(player); this.epicBuckets = EpicBuckets.getInstance(); - init(ChatUtil.colorString(EpicBuckets.getInstance().getLocale().getMessage("interface.admin.panel.title")), size); + init(ChatUtil.colorString(EpicBuckets.getInstance().getLocale().getMessage("interface.admin.panel.title")), 36); } @Override protected void constructGUI() { - HashMap> gens = epicBuckets.getGenbucketManager().getActiveGens(); - int place = 0; - for (UUID uuid : gens.keySet()) { - if (gens.get(uuid).size() < 1 && place != size) continue; - for (Genbucket genbucket : gens.get(uuid)) { - ItemStack skull = new ItemStack(XMaterial.PLAYER_HEAD.parseMaterial(), 1, (short) 3); - SkullMeta meta = (SkullMeta) (skull.getItemMeta() != null ? skull.getItemMeta() : Bukkit.getItemFactory().getItemMeta(skull.getType())); - meta.setOwner(genbucket.getOwner().getName()); - meta.setDisplayName(ChatUtil.colorString(epicBuckets.getLocale().getMessage("interface.admin.panel.player").replace("%player%", genbucket.getOwner().getName()))); - meta.setLore(ChatUtil.colorList(new ArrayList<>(Arrays.asList(epicBuckets.getLocale().getMessage("interface.admin.panel.type").replace("%genbucket%", genbucket.getGenbucketType().name.toLowerCase()), EpicBuckets.getInstance().getLocale().getMessage("interface.admin.panel.location").replace("%location%", ChatUtil.getCoordinatesFromLocation(genbucket.getClickedLocation())), "", EpicBuckets.getInstance().getLocale().getMessage("interface.admin.panel.teleport"))))); - skull.setItemMeta(meta); - inventory.setItem(place, skull); - registerClickable(place, ((player1, inventory1, cursor, slot, type) -> - player.teleport(genbucket.getPlayerLocation() - ))); - place++; - } + inventory.clear(); + resetClickables(); + + HashMap> userGens = epicBuckets.getGenbucketManager().getActiveGens(); + List genbuckets = new ArrayList<>(); + + userGens.forEach((uuid, gens) -> genbuckets.addAll(gens)); + + int pageStart = 27 * page; + + if (genbuckets.size() < pageStart) { + if (page > 0) page--; + constructGUI(); + return; } + + // Registers extra buttons like next, deactivate-all, ect. + registerExtraButtons(); + + int slot = 0; + for (int i = pageStart; i < pageStart + 27; i++, slot++) { + if (i > genbuckets.size() - 1) break; + + Genbucket bucket = genbuckets.get(i); + + inventory.setItem(slot, createGenbucketItem(bucket)); + registerClickable(slot, (player, inventory, cursor, clickedSlot, type) -> { + if (type == ClickType.LEFT) { + player.teleport(bucket.getPlayerLocation()); + player.sendMessage(ChatUtil.colorString(epicBuckets.getLocale().getMessage("interface.admin.panel.teleported") + .replace("%location%", ChatUtil.getCoordinatesFromLocation(bucket.getClickedLocation())))); + } else if (type == ClickType.RIGHT) { + epicBuckets.getGenbucketManager().unregisterGenbucketForPlayer(bucket.getOwner(), bucket.getGenUUID()); + player.sendMessage(ChatUtil.colorString(epicBuckets.getLocale().getMessage("interface.admin.panel.deleted") + .replace("%location%", ChatUtil.getCoordinatesFromLocation(bucket.getClickedLocation())))); + } + }); + + } + } @Override @@ -56,4 +84,69 @@ public class GUIPanel extends AbstractGUI { protected void registerOnCloses() { } + + private void registerExtraButtons() { + + if (page > 0) { + inventory.setItem(27, createItem(XMaterial.ARROW.parseItem(), epicBuckets.getLocale().getMessage("interface.admin.panel.previous"))); + registerClickable(27, (player, inventory, cursor, slot, type) -> { + page--; + constructGUI(); + player.updateInventory(); + }); + } + + ItemStack deactiveButton = createItem(XMaterial.RED_WOOL.parseItem(), epicBuckets.getLocale().getMessage("interface.admin.panel.deactivateall")); + ItemStack pageButton = createItem(XMaterial.SIGN.parseItem(), epicBuckets.getLocale().getMessage("interface.admin.panel.page").replace("%page%", String.valueOf(page + 1))); + ItemStack nextButton = createItem(XMaterial.ARROW.parseItem(), epicBuckets.getLocale().getMessage("interface.admin.panel.next")); + + inventory.setItem(30, deactiveButton); + inventory.setItem(32, pageButton); + inventory.setItem(35, nextButton); + + // Deactivate-All Button Clickable + registerClickable(30, (player, inventory, cursor, slot, type) -> { + epicBuckets.getGenbucketManager().deactiveAll(); + constructGUI(); + player.updateInventory(); + player.sendMessage(ChatUtil.colorString(epicBuckets.getLocale().getMessage("interface.admin.panel.deactivedall"))); + }); + + // Next Button Clickable + registerClickable(35, (player, inventory, cursor, slot, type) -> { + page++; + constructGUI(); + player.updateInventory(); + }); + + } + + private ItemStack createItem(ItemStack itemStack, String title) { + + ItemStack item = new ItemStack(itemStack.getType(), 1, itemStack.getDurability()); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(ChatUtil.colorString(title)); + item.setItemMeta(meta); + + return item; + + } + + private ItemStack createGenbucketItem(Genbucket genbucket) { + + ItemStack skull = new ItemStack(XMaterial.PLAYER_HEAD.parseMaterial(), 1, (short) 3); + SkullMeta meta = (SkullMeta) (skull.getItemMeta() != null ? skull.getItemMeta() : Bukkit.getItemFactory().getItemMeta(skull.getType())); + meta.setOwner(genbucket.getOwner().getName()); + meta.setDisplayName(ChatUtil.colorString(epicBuckets.getLocale().getMessage("interface.admin.panel.player").replace("%player%", genbucket.getOwner().getName()))); + meta.setLore(ChatUtil.colorList(new ArrayList<>(Arrays.asList(epicBuckets.getLocale().getMessage("interface.admin.panel.type").replace("%genbucket%", genbucket.getGenbucketType().name.toLowerCase()), + EpicBuckets.getInstance().getLocale().getMessage("interface.admin.panel.location").replace("%location%", ChatUtil.getCoordinatesFromLocation(genbucket.getClickedLocation())), + "", + EpicBuckets.getInstance().getLocale().getMessage("interface.admin.panel.teleport"), + EpicBuckets.getInstance().getLocale().getMessage("interface.admin.panel.delete"))))); + skull.setItemMeta(meta); + + return skull; + + } + } diff --git a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/listeners/GenbucketPlaceListener.java b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/listeners/GenbucketPlaceListener.java index 42a4f1e..00e948a 100644 --- a/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/listeners/GenbucketPlaceListener.java +++ b/EpicBuckets-Plugin/src/main/java/com/songoda/epicbuckets/listeners/GenbucketPlaceListener.java @@ -88,7 +88,7 @@ public class GenbucketPlaceListener implements Listener { instance.getConfigManager().updateCooldown(e.getPlayer()); if (!genbucket.calculateBlockFace()) { - e.getPlayer().sendMessage(instance.getLocale().getMessage("event.genbucket.placedwrong").replace("%genbucket%", genbucket.getGenbucketType().name.toUpperCase() + " genbucket")); + e.getPlayer().sendMessage(instance.getLocale().getMessage("event.genbucket.placedwrong").replace("%genbucket%", genbucket.getGenbucketType().formatName() + " Genbucket")); return; } if (genbucket.getGenbucketType() == GenbucketType.PSUEDO && !instance.getConfigManager().getPsuedoMaterials().contains(XMaterial.requestXMaterial(e.getClickedBlock().getType().name(), e.getClickedBlock().getData()))) { diff --git a/EpicBuckets-Plugin/src/main/resources/en_US.lang b/EpicBuckets-Plugin/src/main/resources/en_US.lang index 454d7ca..374f65b 100644 --- a/EpicBuckets-Plugin/src/main/resources/en_US.lang +++ b/EpicBuckets-Plugin/src/main/resources/en_US.lang @@ -15,7 +15,15 @@ interface.admin.panel.title = "Active Genbuckets" interface.admin.panel.player = "&a%player%" interface.admin.panel.type = "&7Type: &f%genbucket%" interface.admin.panel.location = "&7Location: &f%location%" -interface.admin.panel.teleport = "&f&oClick to teleport" +interface.admin.panel.teleport = "&f&oLeft Click to teleport" +interface.admin.panel.delete = "&f&oRight Click to delete" +interface.admin.panel.teleported = "&7Teleported to bucket at &e%location%" +interface.admin.panel.deleted = "&cDeleted &7bucket at &e%location%" +interface.admin.panel.previous = "&cPrevious" +interface.admin.panel.next = "&aNext" +interface.admin.panel.deactivateall = "&cDeactive All" +interface.admin.panel.page = "&bPage &8#&e%page%" +interface.admin.panel.deactivedall = "&cDeactivated &7all active genbuckets." #Event Messages diff --git a/EpicBuckets-Plugin/src/main/resources/plugin.yml b/EpicBuckets-Plugin/src/main/resources/plugin.yml index 4f7ed7d..988f4bb 100644 --- a/EpicBuckets-Plugin/src/main/resources/plugin.yml +++ b/EpicBuckets-Plugin/src/main/resources/plugin.yml @@ -3,7 +3,7 @@ version: maven-version-number description: Generate walls fast and efficient with beautiful guis! author: Songoda main: com.songoda.epicbuckets.EpicBuckets -softdepend: [WorldGuard, WorldEdit, Factions, MassiveCore, GriefPrevention] +softdepend: [WorldGuard, WorldEdit, Factions, MassiveCore, GriefPrevention, FactionsFramework] depend: [Vault] commands: EpicBuckets: