Improved Admin GUI and fixed bugs

This commit is contained in:
PlasmaFX 2019-02-17 11:17:13 -05:00
parent 365ffeaf05
commit 5fb8b29510
14 changed files with 173 additions and 27 deletions

View File

@ -4,7 +4,7 @@ stages:
variables:
name: "EpicBuckets"
path: "/builds/Songoda/epicbuckets"
version: "1.5.1"
version: "1.5.2"
build:
stage: build

View File

@ -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;

View File

@ -177,10 +177,15 @@ public class ConfigManager {
epicBuckets.getConfig().getConfigurationSection("COST-FOR-INFINITE-USE").getKeys(false)
.forEach(bucket -> {
HashMap<ItemStack, Double> 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);
}
}

View File

@ -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;
}

View File

@ -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<Genbucket> activeGensInOneList() {
List<Genbucket> gens = new ArrayList<>();
activeGens.forEach((uuid, genbuckets) -> gens.addAll(genbuckets));

View File

@ -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;

View File

@ -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();

View File

@ -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());

View File

@ -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();

View File

@ -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());

View File

@ -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<UUID, List<Genbucket>> 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<UUID, List<Genbucket>> userGens = epicBuckets.getGenbucketManager().getActiveGens();
List<Genbucket> 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;
}
}

View File

@ -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()))) {

View File

@ -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

View File

@ -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: