mirror of
https://github.com/songoda/EpicAnchors.git
synced 2024-11-23 02:25:23 +01:00
Redid GUI system which fixes flickering.
This commit is contained in:
parent
cef93681cc
commit
ffa4f86167
@ -11,9 +11,7 @@ import com.songoda.epicanchors.api.utils.ProtectionPluginHook;
|
||||
import com.songoda.epicanchors.command.CommandManager;
|
||||
import com.songoda.epicanchors.listeners.BlockListeners;
|
||||
import com.songoda.epicanchors.listeners.InteractListeners;
|
||||
import com.songoda.epicanchors.listeners.InventoryListeners;
|
||||
import com.songoda.epicanchors.handlers.AnchorHandler;
|
||||
import com.songoda.epicanchors.handlers.MenuHandler;
|
||||
import com.songoda.epicanchors.hooks.*;
|
||||
import com.songoda.epicanchors.utils.ConfigWrapper;
|
||||
import com.songoda.epicanchors.utils.Methods;
|
||||
@ -25,7 +23,6 @@ import com.songoda.update.SongodaUpdate;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -54,7 +51,6 @@ public class EpicAnchorsPlugin extends JavaPlugin implements EpicAnchors {
|
||||
|
||||
private SettingsManager settingsManager;
|
||||
private EAnchorManager anchorManager;
|
||||
private MenuHandler menuHandler;
|
||||
|
||||
private CommandManager commandManager;
|
||||
|
||||
@ -92,7 +88,6 @@ public class EpicAnchorsPlugin extends JavaPlugin implements EpicAnchors {
|
||||
dataFile.createNewFile("Loading Data File", "EpicAnchors Data File");
|
||||
|
||||
this.references = new References();
|
||||
this.menuHandler = new MenuHandler(this);
|
||||
this.anchorManager = new EAnchorManager();
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
@ -108,7 +103,6 @@ public class EpicAnchorsPlugin extends JavaPlugin implements EpicAnchors {
|
||||
// Event registration
|
||||
pluginManager.registerEvents(new BlockListeners(this), this);
|
||||
pluginManager.registerEvents(new InteractListeners(this), this);
|
||||
pluginManager.registerEvents(new InventoryListeners(this), this);
|
||||
|
||||
// Register default hooks
|
||||
if (pluginManager.isPluginEnabled("ASkyBlock")) this.register(HookASkyBlock::new);
|
||||
@ -265,10 +259,6 @@ public class EpicAnchorsPlugin extends JavaPlugin implements EpicAnchors {
|
||||
return settingsManager;
|
||||
}
|
||||
|
||||
public MenuHandler getMenuHandler() {
|
||||
return menuHandler;
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.epicanchors.anchor;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
||||
import com.songoda.epicanchors.gui.GUIOverview;
|
||||
import com.songoda.epicanchors.utils.Methods;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.*;
|
||||
@ -26,72 +27,7 @@ public class EAnchor implements Anchor {
|
||||
}
|
||||
|
||||
public void overview(Player player) {
|
||||
EpicAnchorsPlugin instance = EpicAnchorsPlugin.getInstance();
|
||||
|
||||
String timeRemaining = Methods.makeReadable((long) (ticksLeft / 20) * 1000) + " remaining.";
|
||||
|
||||
Inventory inventory = Bukkit.createInventory(null, 27, Methods.formatText(instance.getLocale().getMessage("interface.anchor.title")));
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
inventory.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
inventory.setItem(0, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(1, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(2, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(6, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(7, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(8, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(9, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(10, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(16, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(17, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(18, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(19, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(20, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(24, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(25, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
ItemStack itemXP = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.XP Icon")), 1);
|
||||
ItemMeta itemmetaXP = itemXP.getItemMeta();
|
||||
itemmetaXP.setDisplayName(instance.getLocale().getMessage("interface.button.addtimewithxp"));
|
||||
ArrayList<String> loreXP = new ArrayList<>();
|
||||
loreXP.add(instance.getLocale().getMessage("interface.button.addtimewithxplore", Integer.toString(instance.getConfig().getInt("Main.XP Cost"))));
|
||||
itemmetaXP.setLore(loreXP);
|
||||
itemXP.setItemMeta(itemmetaXP);
|
||||
|
||||
ItemStack itemECO = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Economy Icon")), 1);
|
||||
ItemMeta itemmetaECO = itemECO.getItemMeta();
|
||||
itemmetaECO.setDisplayName(instance.getLocale().getMessage("interface.button.addtimewitheconomy"));
|
||||
ArrayList<String> loreECO = new ArrayList<>();
|
||||
loreECO.add(instance.getLocale().getMessage("interface.button.addtimewitheconomylore", Methods.formatEconomy(instance.getConfig().getInt("Main.Economy Cost"))));
|
||||
itemmetaECO.setLore(loreECO);
|
||||
itemECO.setItemMeta(itemmetaECO);
|
||||
|
||||
ItemStack item = instance.makeAnchorItem(ticksLeft);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Methods.formatText(instance.getLocale().getMessage("interface.anchor.smalltitle")));
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
lore.add(Methods.formatText("&7" + timeRemaining));
|
||||
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inventory.setItem(13, item);
|
||||
|
||||
|
||||
if (instance.getConfig().getBoolean("Main.Add Time With Economy")) {
|
||||
inventory.setItem(11, itemECO);
|
||||
}
|
||||
|
||||
if (instance.getConfig().getBoolean("Main.Add Time With XP")) {
|
||||
inventory.setItem(15, itemXP);
|
||||
}
|
||||
|
||||
player.openInventory(inventory);
|
||||
EpicAnchorsPlugin.getInstance().getMenuHandler().addPlayer(player, location);
|
||||
new GUIOverview(EpicAnchorsPlugin.getInstance(), this, player);
|
||||
}
|
||||
|
||||
public void addTime(String type, Player player) {
|
||||
|
@ -0,0 +1,117 @@
|
||||
package com.songoda.epicanchors.gui;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.anchor.EAnchor;
|
||||
import com.songoda.epicanchors.utils.Methods;
|
||||
import com.songoda.epicspawners.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GUIOverview extends AbstractGUI {
|
||||
|
||||
private final EpicAnchorsPlugin plugin;
|
||||
private final EAnchor anchor;
|
||||
|
||||
private int task;
|
||||
|
||||
public GUIOverview(EpicAnchorsPlugin plugin, EAnchor anchor, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.anchor = anchor;
|
||||
|
||||
|
||||
init(Methods.formatText(plugin.getLocale().getMessage("interface.anchor.title")), 27);
|
||||
runTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
String timeRemaining = Methods.makeReadable((long) (anchor.getTicksLeft() / 20) * 1000) + " remaining.";
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
inventory.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
inventory.setItem(0, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(1, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(2, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(6, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(7, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(8, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(9, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(10, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(16, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(17, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(18, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(19, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(20, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(24, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(25, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
ItemStack itemXP = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.XP Icon")), 1);
|
||||
ItemMeta itemmetaXP = itemXP.getItemMeta();
|
||||
itemmetaXP.setDisplayName(plugin.getLocale().getMessage("interface.button.addtimewithxp"));
|
||||
ArrayList<String> loreXP = new ArrayList<>();
|
||||
loreXP.add(plugin.getLocale().getMessage("interface.button.addtimewithxplore", Integer.toString(plugin.getConfig().getInt("Main.XP Cost"))));
|
||||
itemmetaXP.setLore(loreXP);
|
||||
itemXP.setItemMeta(itemmetaXP);
|
||||
|
||||
ItemStack itemECO = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Economy Icon")), 1);
|
||||
ItemMeta itemmetaECO = itemECO.getItemMeta();
|
||||
itemmetaECO.setDisplayName(plugin.getLocale().getMessage("interface.button.addtimewitheconomy"));
|
||||
ArrayList<String> loreECO = new ArrayList<>();
|
||||
loreECO.add(plugin.getLocale().getMessage("interface.button.addtimewitheconomylore", Methods.formatEconomy(plugin.getConfig().getInt("Main.Economy Cost"))));
|
||||
itemmetaECO.setLore(loreECO);
|
||||
itemECO.setItemMeta(itemmetaECO);
|
||||
|
||||
ItemStack item = plugin.makeAnchorItem(anchor.getTicksLeft());
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Methods.formatText(plugin.getLocale().getMessage("interface.anchor.smalltitle")));
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
lore.add(Methods.formatText("&7" + timeRemaining));
|
||||
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inventory.setItem(13, item);
|
||||
|
||||
|
||||
if (plugin.getConfig().getBoolean("Main.Add Time With Economy")) {
|
||||
inventory.setItem(11, itemECO);
|
||||
}
|
||||
|
||||
if (plugin.getConfig().getBoolean("Main.Add Time With XP")) {
|
||||
inventory.setItem(15, itemXP);
|
||||
}
|
||||
}
|
||||
|
||||
private void runTask() {
|
||||
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::constructGUI, 5L, 5L);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
registerClickable(11, ((player, inventory, cursor, slot, type) -> {
|
||||
if (plugin.getConfig().getBoolean("Main.Add Time With Economy"))
|
||||
anchor.addTime("ECO", player);
|
||||
}));
|
||||
|
||||
registerClickable(15, ((player, inventory, cursor, slot, type) -> {
|
||||
if (plugin.getConfig().getBoolean("Main.Add Time With XP"))
|
||||
anchor.addTime("XP", player);
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
registerOnClose(((player1, inventory1) -> Bukkit.getScheduler().cancelTask(task)));
|
||||
}
|
||||
}
|
@ -95,8 +95,6 @@ public class AnchorHandler {
|
||||
if (anchor.getLocation().getBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Anchor Block Material")))
|
||||
continue;
|
||||
|
||||
instance.getMenuHandler().updateMenu();
|
||||
|
||||
Chunk chunk = location.getChunk();
|
||||
chunk.load();
|
||||
|
||||
@ -129,7 +127,6 @@ public class AnchorHandler {
|
||||
location.getWorld().playSound(location, instance.isServerVersionAtLeast(ServerVersion.V1_13)
|
||||
? Sound.ENTITY_GENERIC_EXPLODE : Sound.valueOf("EXLODE"), 10, 10);
|
||||
location.getBlock().setType(Material.AIR);
|
||||
instance.getMenuHandler().removeAnchor(location);
|
||||
chunk.unload();
|
||||
}
|
||||
|
||||
|
@ -1,56 +0,0 @@
|
||||
package com.songoda.epicanchors.handlers;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.anchor.EAnchor;
|
||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MenuHandler {
|
||||
|
||||
private Map<UUID, Location> playersInMenu = new HashMap<>();
|
||||
|
||||
private EpicAnchorsPlugin instance;
|
||||
|
||||
public MenuHandler(EpicAnchorsPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void updateMenu() {
|
||||
if (playersInMenu.size() == 0) return;
|
||||
for (Map.Entry<UUID, Location> entry : playersInMenu.entrySet()) {
|
||||
Player player = Bukkit.getPlayer(entry.getKey());
|
||||
((EAnchor)instance.getAnchorManager().getAnchor(entry.getValue())).overview(player);
|
||||
}
|
||||
}
|
||||
|
||||
public Anchor getAnchor(Player player) {
|
||||
return instance.getAnchorManager().getAnchor(playersInMenu.get(player.getUniqueId()));
|
||||
}
|
||||
|
||||
public void addPlayer(Player player, Location location) {
|
||||
playersInMenu.put(player.getUniqueId(), location);
|
||||
}
|
||||
|
||||
public void removePlayer(Player player) {
|
||||
playersInMenu.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean isPlayerInMenu(Player player) {
|
||||
return playersInMenu.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void removeAnchor(Location location) {
|
||||
for (Map.Entry<UUID, Location> entry : playersInMenu.entrySet()) {
|
||||
if (entry.getValue() != location) return;
|
||||
Player player = Bukkit.getPlayer(entry.getKey());
|
||||
playersInMenu.remove(player.getUniqueId());
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package com.songoda.epicanchors.listeners;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.anchor.EAnchor;
|
||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
public class InventoryListeners implements Listener {
|
||||
|
||||
EpicAnchorsPlugin instance;
|
||||
|
||||
public InventoryListeners(EpicAnchorsPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler()
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (event.getRawSlot() >= event.getView().getTopInventory().getSize()) return;
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (!instance.getMenuHandler().isPlayerInMenu(player)) return;
|
||||
|
||||
Anchor anchor = instance.getMenuHandler().getAnchor(player);
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (event.getSlot() == 15 && instance.getConfig().getBoolean("Main.Add Time With XP")) {
|
||||
if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
|
||||
((EAnchor) anchor).addTime("XP", player);
|
||||
}
|
||||
} else if (event.getSlot() == 11 && instance.getConfig().getBoolean("Main.Add Time With Economy")) {
|
||||
if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
|
||||
((EAnchor) anchor).addTime("ECO", player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler()
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
instance.getMenuHandler().removePlayer((Player) event.getPlayer());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user