Confirmation Disband GUI Created

This commit is contained in:
Driftay 2020-01-19 02:55:56 -05:00
parent 57ac2c8c98
commit 417cc57aa7
7 changed files with 140 additions and 170 deletions

View File

@ -105,6 +105,9 @@ public class Conf {
//AUDIT
public static boolean useAuditSystem = true;
//GUI's
public static boolean useDisbandGUI = true;
//DISCORD
public static boolean useDiscordSystem = false;
public static String discordBotToken = "<token here>";

View File

@ -1,19 +1,19 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.*;
import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fdisband.FDisbandFrame;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.command.ConsoleCommandSender;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
public class CmdDisband extends FCommand {
@ -37,6 +37,7 @@ public class CmdDisband extends FCommand {
@Override
public void perform(CommandContext context) {
long time;
// The faction, default to your own.. but null if console sender.
Faction faction = context.argAsFaction(0, context.fPlayer == null ? null : context.faction);
if (faction == null) return;
@ -44,9 +45,7 @@ public class CmdDisband extends FCommand {
boolean isMyFaction = context.fPlayer != null && faction == context.faction;
if (!isMyFaction) {
if (!Permission.DISBAND_ANY.has(context.sender, true)) {
return;
}
if (!Permission.DISBAND_ANY.has(context.sender, true)) return;
}
@ -73,6 +72,21 @@ public class CmdDisband extends FCommand {
return;
}
boolean access = false;
if (context.fPlayer.getPlayer().hasMetadata("disband_confirm") && (time = context.fPlayer.getPlayer().getMetadata("disband_confirm").get(0).asLong()) != 0L && System.currentTimeMillis() - time <= TimeUnit.SECONDS.toMillis(3L)) {
access = true;
}
if (!access) {
if(Conf.useDisbandGUI) {
if (!disbandMap.containsKey(context.player.getUniqueId().toString())) {
new FDisbandFrame(context.faction).buildGUI(context.fPlayer);
return;
}
}
}
// check for tnt before disbanding.
if (!disbandMap.containsKey(context.player.getUniqueId().toString()) && faction.getTnt() > 0) {
context.msg(TL.COMMAND_DISBAND_CONFIRM.toString().replace("{tnt}", faction.getTnt() + ""));

View File

@ -265,7 +265,8 @@ public class FactionsBlockListener implements Listener {
@EventHandler
public void onHopperPlace(BlockPlaceEvent e) {
if (e.getItemInHand().getType() != Material.HOPPER && !FactionsPlugin.instance.getConfig().getBoolean("fvault.No-Hoppers-near-vault")) return;
if (e.getItemInHand().getType() != Material.HOPPER && !FactionsPlugin.instance.getConfig().getBoolean("fvault.No-Hoppers-near-vault"))
return;
Faction factionAt = Board.getInstance().getFactionAt(new FLocation(e.getBlockPlaced().getLocation()));
if (factionAt.isWilderness() || factionAt.getVault() == null) return;
FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer());
@ -356,12 +357,8 @@ public class FactionsBlockListener implements Listener {
return;
}
for (FPlayer fplayer : fme.getFaction().getFPlayers()) {
if (XMaterial.isVersionOrHigher(XMaterial.MinecraftVersion.VERSION_1_9)) {
fplayer.getPlayer().sendTitle(FactionsPlugin.getInstance().color(fme.getTag() + " Placed A WarBanner!"), FactionsPlugin.getInstance().color("&7use &c/f tpbanner&7 to tp to the banner!"), 10, 70, 20);
} else {
fplayer.getPlayer().sendTitle(FactionsPlugin.getInstance().color(fme.getTag() + " Placed A WarBanner!"), FactionsPlugin.getInstance().color("&7use &c/f tpbanner&7 to tp to the banner!"));
}
}
bannerCooldownMap.put(fme.getTag(), true);
FactionsBlockListener.bannerLocations.put(fme.getTag(), e.getBlockPlaced().getLocation());
int bannerCooldown = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Place-Cooldown");

View File

@ -21,14 +21,9 @@ public class ItemBuilder {
this.meta = item.getItemMeta();
}
public ItemBuilder(Material material, int amount, int durability) {
this(new ItemStack(material, amount, (short) durability));
}
public ItemBuilder(Material material, int amount) {
this(material, amount, 0);
this(new ItemStack(material, amount));
}
public ItemBuilder(Material material) {
this(material, 1);
}

View File

@ -1,151 +0,0 @@
package com.massivecraft.factions.util.serializable;
/**
* @author Driftay
*/
import com.massivecraft.factions.FactionsPlugin;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
public abstract class SaberGUI {
public static Set<String> allGUINames = new HashSet<>();
public static Map<UUID, SaberGUI> activeGUIs = new ConcurrentHashMap<>();
public SaberGUI parentGUI;
protected String title;
protected int size;
protected Player player;
protected Inventory inventory;
private Map<Integer, InventoryItem> inventoryItems;
private String owningPluginName;
private Runnable closeRunnable;
public SaberGUI(Player player, String title, int size) {
this(player, title, size, InventoryType.CHEST);
}
public SaberGUI(Player player, String title, int size, InventoryType type) {
this.inventoryItems = new HashMap<>();
this.inventory = type == InventoryType.CHEST ? Bukkit.createInventory(null, size, title) : Bukkit.createInventory(null, type, title);
this.player = player;
this.size = size;
this.title = title;
allGUINames.add(this.title);
}
public SaberGUI setParentGUI(SaberGUI parent) {
this.parentGUI = parent;
return this;
}
public void onUnknownItemClick(InventoryClickEvent event) {
}
public abstract void redraw();
public void openGUI(JavaPlugin owning) {
this.owningPluginName = owning.getName();
SaberGUI currentlyActive = activeGUIs.get(this.player.getUniqueId());
if (currentlyActive != null) {
Bukkit.getLogger().info("Closing already open menu first!");
Bukkit.getScheduler().scheduleSyncDelayedTask(owning, () -> {
currentlyActive.close();
activeGUIs.put(this.player.getUniqueId(), this);
this.redraw();
this.player.openInventory(this.inventory);
});
} else {
activeGUIs.put(this.player.getUniqueId(), this);
this.redraw();
this.player.openInventory(this.inventory);
}
}
public void setItem(int slot, InventoryItem inventoryItem) {
if (inventoryItem != null && inventoryItem.getItem() != null) {
this.inventoryItems.put(slot, inventoryItem);
this.inventory.setItem(slot, inventoryItem.getItem());
} else {
this.removeItem(slot);
}
}
public void closeWithDelay() {
this.closeWithDelay(null);
}
public void closeWithDelay(Consumer<Player> afterClose) {
Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.instance, () -> {
this.player.closeInventory();
if (afterClose != null) {
afterClose.accept(this.player);
}
}, 1L);
}
public void setItem(int slot, ItemStack item, Runnable runnable) {
this.setItem(slot, (new InventoryItem(item)).click(runnable));
}
public void onInventoryClose() {
if (this.closeRunnable != null) {
this.closeRunnable.run();
}
}
public void close() {
this.onInventoryClose();
this.player.closeInventory();
}
public void removeItem(int slot) {
this.inventory.setItem(slot, null);
this.inventoryItems.remove(slot);
}
public SaberGUI setOnClose(Runnable runnable) {
this.closeRunnable = runnable;
return this;
}
public boolean isInventory(Inventory inventory) {
return this.inventory.equals(inventory);
}
public static SaberGUI getActiveGUI(UUID uuid) { return activeGUIs.get(uuid); }
public static void removeGUI(UUID uuid) {
activeGUIs.remove(uuid);
}
public SaberGUI getParentGUI() {
return this.parentGUI;
}
public Map<Integer, InventoryItem> getInventoryItems() {
return this.inventoryItems;
}
public String getOwningPluginName() {
return this.owningPluginName;
}
public void setOwningPluginName(String owningPluginName) {
this.owningPluginName = owningPluginName;
}
public Runnable getCloseRunnable() {
return this.closeRunnable;
}
}

View File

@ -0,0 +1,89 @@
package com.massivecraft.factions.zcore.fdisband;
import com.github.stefvanschie.inventoryframework.Gui;
import com.github.stefvanschie.inventoryframework.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.XMaterial;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* Factions - Developed by Driftay.
* All rights reserved 2020.
* Creation Date: 1/18/2020
*/
public class FDisbandFrame {
private Gui gui;
public FDisbandFrame(Faction faction) {
this.gui = new Gui(FactionsPlugin.getInstance(), 1, "Confirm Disband");
}
public void buildGUI(FPlayer fPlayer) {
int i;
PaginatedPane pane = new PaginatedPane(0, 0, 9, this.gui.getRows());
List<GuiItem> GUIItems = new ArrayList<>();
ItemStack confirm = buildConfirmDummyItem(fPlayer.getFaction());
ItemStack deny = buildDenyDummyItem();
for (i = 0; i < 5; ++i) {
GUIItems.add(new GuiItem(confirm, (e) -> {
e.setCancelled(true);
fPlayer.getPlayer().setMetadata("disband_confirm", new FixedMetadataValue(FactionsPlugin.getInstance(), System.currentTimeMillis()));
fPlayer.getPlayer().closeInventory();
fPlayer.getPlayer().performCommand("f disband");
}));
}
GUIItems.set(4, new GuiItem(XMaterial.BLACK_WOOL.parseItem(), (e) -> e.setCancelled(true)));
for (i = 5; i < 10; ++i) {
GUIItems.add(new GuiItem(deny, (e) -> {
e.setCancelled(true);
fPlayer.getPlayer().closeInventory();
}));
}
pane.populateWithGuiItems(GUIItems);
gui.addPane(pane);
gui.update();
gui.show(fPlayer.getPlayer());
}
private ItemStack buildConfirmDummyItem(Faction faction) {
ConfigurationSection config = FactionsPlugin.getInstance().getConfig().getConfigurationSection("f-disband-gui.confirm-item");
ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem();
ItemMeta meta = item.getItemMeta();
if (meta != null) {
List<String> lore = new ArrayList<>();
for (String s : config.getStringList("Lore")) {
lore.add(FactionsPlugin.getInstance().color(s).replace("{faction}", faction.getTag()));
}
meta.setLore(lore);
meta.setDisplayName(FactionsPlugin.getInstance().color(Objects.requireNonNull(config.getString("Name"))));
item.setItemMeta(meta);
}
return item;
}
private ItemStack buildDenyDummyItem() {
ConfigurationSection config = FactionsPlugin.getInstance().getConfig().getConfigurationSection("f-disband-gui.deny-item");
ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem();
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setLore(FactionsPlugin.getInstance().colorList(config.getStringList("Lore")));
meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name")));
item.setItemMeta(meta);
}
return item;
}
}

View File

@ -651,6 +651,7 @@ frules:
- '&f'
- '&r &r &r &r &r &r &r &r &r &r &r &7&o(( Tip: Use &f&o/f rules add <rule>&7&o add a &c&orule&7&o ))'
- ''
############################################################
# +------------------------------------------------------+ #
# | Faction TNT Bank | #
@ -708,6 +709,7 @@ F-Shop:
Name: '&cFaction Points: &b{points}'
Lore:
- ' '
############################################################
# +------------------------------------------------------+ #
# | Faction Command Cooldowns | #
@ -730,6 +732,27 @@ fcooldowns:
Falling-Block-Fix:
enabled: true
############################################################
# +------------------------------------------------------+ #
# | Faction Disband | #
# +------------------------------------------------------+ #
############################################################
f-disband-gui:
confirm-item:
Type: LIME_STAINED_GLASS_PANE
Name: '&a&lConfirm'
Lore:
- ' '
- '&7Confirm disbanding of &a&b{faction}&7!'
deny-item:
Type: RED_STAINED_GLASS_PANE
Name: '&c&lCancel'
Lore:
- ' '
- '&7Click to cancel faction disband.'
############################################################
# +------------------------------------------------------+ #
# | Faction GracePeriod | #