Get credits GUI to function properly
This commit is contained in:
parent
28ec395978
commit
4acb0baa7a
8 changed files with 129 additions and 29 deletions
|
@ -16,7 +16,7 @@ static def getTime() {
|
|||
}
|
||||
|
||||
// Set version to version property if supplied
|
||||
String shortVersion = "v1.0"
|
||||
String shortVersion = "1.0"
|
||||
if (hasProperty('ver')) {
|
||||
if (ver.charAt(0) == "v") {
|
||||
shortVersion = ver.substring(1).toUpperCase()
|
||||
|
|
|
@ -9,13 +9,11 @@ import java.util.Map;
|
|||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import dev.zontreck.ase.guis.ChestGUI;
|
||||
import dev.zontreck.ase.utils.TPACaches;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -23,7 +21,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
|||
|
||||
public class AriasServerEssentials extends JavaPlugin implements Listener {
|
||||
private static JavaPlugin plugin;
|
||||
private static Map<String, SavedData> cachedPlayerData = new HashMap<>();
|
||||
protected static Map<String, SavedData> cachedPlayerData = new HashMap<>();
|
||||
private static List<TPACaches> cacheTPA = new ArrayList<>();
|
||||
public static boolean disabled = false;
|
||||
|
||||
|
@ -42,6 +40,9 @@ public class AriasServerEssentials extends JavaPlugin implements Listener {
|
|||
if (disabled)
|
||||
task.cancel();
|
||||
}, 0, 20);
|
||||
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvents(new EventsHandler(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,21 +67,6 @@ public class AriasServerEssentials extends JavaPlugin implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public static void onPlayerJoin(PlayerJoinEvent ev) {
|
||||
getPlayerData(ev.getPlayer().getUniqueId().toString()); // Pre-cache it
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public static void onPlayerLeave(PlayerQuitEvent ev) {
|
||||
// Save the player's data and remove from object cache
|
||||
String id = ev.getPlayer().getUniqueId().toString();
|
||||
SavedData data = getPlayerData(id);
|
||||
data.save(id);
|
||||
|
||||
cachedPlayerData.remove(id);
|
||||
}
|
||||
|
||||
public static void onTick() {
|
||||
for (TPACaches cache : cacheTPA) {
|
||||
cache.tick();
|
||||
|
@ -97,6 +83,8 @@ public class AriasServerEssentials extends JavaPlugin implements Listener {
|
|||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
ChestGUI.onTick();
|
||||
}
|
||||
|
||||
public static boolean hasTPARequest(Player from) {
|
||||
|
|
44
src/main/java/dev/zontreck/ase/EventsHandler.java
Normal file
44
src/main/java/dev/zontreck/ase/EventsHandler.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
package dev.zontreck.ase;
|
||||
|
||||
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.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import dev.zontreck.ase.guis.ChestGUI;
|
||||
import dev.zontreck.ase.guis.PrimitiveItem;
|
||||
|
||||
public class EventsHandler implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public static void onPlayerJoin(PlayerJoinEvent ev) {
|
||||
AriasServerEssentials.getPlayerData(ev.getPlayer().getUniqueId().toString()); // Pre-cache it
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public static void onPlayerLeave(PlayerQuitEvent ev) {
|
||||
// Save the player's data and remove from object cache
|
||||
String id = ev.getPlayer().getUniqueId().toString();
|
||||
SavedData data = AriasServerEssentials.getPlayerData(id);
|
||||
data.save(id);
|
||||
|
||||
AriasServerEssentials.cachedPlayerData.remove(id);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public static void onPlayerInteractGUI(InventoryClickEvent ice) {
|
||||
// Get the player who clicked
|
||||
Player player = (Player) ice.getWhoClicked();
|
||||
// Check if the current inventory is a valid ChestGUI
|
||||
ChestGUI gui = ChestGUI.getGUIForPlayer(player);
|
||||
if (gui != null) {
|
||||
|
||||
// Check if clicked item is a GUI button
|
||||
if (PrimitiveItem.isGUIButton(ice.getCurrentItem())) {
|
||||
ice.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package dev.zontreck.ase.guis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -8,6 +10,7 @@ import org.bukkit.inventory.Inventory;
|
|||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import dev.zontreck.ase.AriasServerEssentials;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class ChestGUI {
|
||||
|
@ -19,10 +22,14 @@ public class ChestGUI {
|
|||
}
|
||||
|
||||
public static void checkValidity() {
|
||||
for (int i = 0; i < GUI_LIST.size(); i++) {
|
||||
ChestGUI gui = GUI_LIST.get(i);
|
||||
Iterator<ChestGUI> it = GUI_LIST.iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
ChestGUI gui = it.next();
|
||||
if (!gui.valid()) {
|
||||
GUI_LIST.remove(gui);
|
||||
|
||||
AriasServerEssentials.getSelf().getLogger().info("A gui has been invalidated, removing from caches");
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,12 +40,18 @@ public class ChestGUI {
|
|||
return gui;
|
||||
}
|
||||
}
|
||||
|
||||
AriasServerEssentials.getSelf().getLogger().info("No such GUI, returning null");
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void onTick() {
|
||||
checkValidity();
|
||||
}
|
||||
// END STATIC REGISTRY
|
||||
|
||||
public String guiTitle;
|
||||
public List<ItemStack> buttons;
|
||||
public List<ItemStack> buttons = new ArrayList<>();
|
||||
public int totalSize;
|
||||
public Player player;
|
||||
public boolean closed = false;
|
||||
|
@ -58,6 +71,10 @@ public class ChestGUI {
|
|||
}
|
||||
}
|
||||
|
||||
public void add(PrimitiveItem item) {
|
||||
buttons.add(item.generate());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method presents the GUI to the player, using the defined layout above.
|
||||
*/
|
||||
|
|
|
@ -4,16 +4,30 @@ import org.bukkit.Material;
|
|||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
public class CreditsGui {
|
||||
public static void openGUI(Player player) {
|
||||
// First step, construct the layout
|
||||
ChestGUI gui = new ChestGUI("Credits", 9 * 4);
|
||||
gui.fill(9, new PrimitiveItem(Material.BLACK_STAINED_GLASS_PANE, Component.text(""), true,
|
||||
Component.text().build()));
|
||||
ChestGUI gui = new ChestGUI("Credits", 9 * 3);
|
||||
PrimitiveItem StainedGlass = new PrimitiveItem(Material.BLACK_STAINED_GLASS_PANE, Component.text(""), true,
|
||||
Component.text().build());
|
||||
|
||||
PrimitiveItem zontreckHead = new PrimitiveItem(Material.PLAYER_HEAD,
|
||||
Component.text("Aria", NamedTextColor.DARK_RED), true,
|
||||
Component.text("Username: zontreck", NamedTextColor.DARK_PURPLE),
|
||||
Component.text("Creator of ASE", NamedTextColor.DARK_PURPLE));
|
||||
zontreckHead.skull("zontreck");
|
||||
|
||||
gui.fill(9, StainedGlass);
|
||||
gui.add(StainedGlass);
|
||||
gui.add(zontreckHead);
|
||||
|
||||
gui.fill(9 - 2, StainedGlass);
|
||||
gui.fill(9, StainedGlass);
|
||||
|
||||
// Second step, present to the player
|
||||
|
||||
gui.setPlayer(player);
|
||||
gui.doPresentation();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,12 @@ package dev.zontreck.ase.guis;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
|
@ -22,6 +24,8 @@ public class PrimitiveItem {
|
|||
public Component name;
|
||||
public Component[] itemLore;
|
||||
public boolean isGUIButton;
|
||||
public boolean isSkull = false;
|
||||
public String skullOwner = "";
|
||||
|
||||
public PrimitiveItem(Material type, Component name, boolean isGUIButton, Component... lore) {
|
||||
itemType = type;
|
||||
|
@ -57,6 +61,12 @@ public class PrimitiveItem {
|
|||
true);
|
||||
}
|
||||
|
||||
if (isSkull) {
|
||||
SkullMeta skullMeta = (SkullMeta) meta;
|
||||
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(skullOwner));
|
||||
meta = skullMeta;
|
||||
}
|
||||
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
@ -74,4 +84,10 @@ public class PrimitiveItem {
|
|||
PersistentDataType.BOOLEAN);
|
||||
}
|
||||
|
||||
public void skull(String string) {
|
||||
isSkull = true;
|
||||
skullOwner = string;
|
||||
itemType = Material.PLAYER_HEAD;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,6 +36,9 @@ commands:
|
|||
shareitem:
|
||||
description: Shares the item in your hand with everyone in chat
|
||||
usage: "- /shareitem -"
|
||||
asecredits:
|
||||
description: Displays the plugin's credits
|
||||
usage: "- /asecredits -"
|
||||
permissions:
|
||||
ase.commands.*:
|
||||
description: Allow all commands
|
||||
|
@ -51,6 +54,7 @@ permissions:
|
|||
ase.commands.tpacancel: true
|
||||
ase.commands.tpahere: true
|
||||
ase.commands.shareitem: true
|
||||
ase.commands.asecredits: true
|
||||
ase.commands.home:
|
||||
description: Allows usage of the /home command
|
||||
default: true
|
||||
|
@ -81,3 +85,6 @@ permissions:
|
|||
ase.commands.shareitem:
|
||||
description: Allow /shareitem
|
||||
default: true
|
||||
ase.commands.asecredits:
|
||||
description: Allow /asecredits
|
||||
default: true
|
||||
|
|
|
@ -32,6 +32,12 @@ commands:
|
|||
tpahere:
|
||||
description: Request a player to teleport to you
|
||||
usage: "- /tpahere [player] -"
|
||||
shareitem:
|
||||
description: Shares the item in your hand with everyone in chat
|
||||
usage: "- /shareitem -"
|
||||
asecredits:
|
||||
description: Displays the plugin's credits
|
||||
usage: "- /asecredits -"
|
||||
permissions:
|
||||
ase.commands.*:
|
||||
description: Allow all commands
|
||||
|
@ -46,6 +52,8 @@ permissions:
|
|||
ase.commands.tpdeny: true
|
||||
ase.commands.tpacancel: true
|
||||
ase.commands.tpahere: true
|
||||
ase.commands.shareitem: true
|
||||
ase.commands.asecredits: true
|
||||
ase.commands.home:
|
||||
description: Allows usage of the /home command
|
||||
default: true
|
||||
|
@ -73,3 +81,9 @@ permissions:
|
|||
ase.commands.tpahere:
|
||||
description: Allow usage of /tpahere
|
||||
default: true
|
||||
ase.commands.shareitem:
|
||||
description: Allow /shareitem
|
||||
default: true
|
||||
ase.commands.asecredits:
|
||||
description: Allow /asecredits
|
||||
default: true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue