mirror of
https://github.com/CivMC/Civ.git
synced 2026-07-18 00:20:44 +00:00
add anvil titles and fix inconsistencies
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package net.civmc.kitpvp.anvil;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
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;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
@@ -15,17 +17,31 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AnvilGui implements Listener {
|
||||
private final Map<Player, Component> names = new HashMap<>();
|
||||
private final Map<Player, Inventory> anvils = new HashMap<>();
|
||||
private final Map<Player, AnvilGuiListener> listeners = new HashMap<>();
|
||||
|
||||
public void open(Player player, AnvilGuiListener listener) {
|
||||
public void open(Player player, Component name, AnvilGuiListener listener) {
|
||||
names.put(player, name);
|
||||
InventoryView view = player.openAnvil(null, true);
|
||||
if (view == null) {
|
||||
names.remove(player);
|
||||
return;
|
||||
}
|
||||
anvils.put(player, view.getTopInventory());
|
||||
listeners.put(player, listener);
|
||||
|
||||
view.getTopInventory().setItem(0, new ItemStack(Material.WRITABLE_BOOK));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void on(InventoryOpenEvent event) {
|
||||
Component title = names.remove(event.getPlayer());
|
||||
if (title != null) {
|
||||
event.titleOverride(title);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void on(PlayerQuitEvent event) {
|
||||
Inventory inventory = anvils.remove(event.getPlayer());
|
||||
|
||||
@@ -106,7 +106,7 @@ public class EditKitGui {
|
||||
protected void clicked(@NotNull Player clicker) {
|
||||
inventory.setOnClose(null);
|
||||
player.closeInventory();
|
||||
anvilGui.open(player, new AnvilGuiListener() {
|
||||
anvilGui.open(player, Component.text("Kit name"), new AnvilGuiListener() {
|
||||
@Override
|
||||
public void onClose() {
|
||||
JavaPlugin plugin = JavaPlugin.getProvidingPlugin(KitPvpPlugin.class);
|
||||
|
||||
@@ -69,7 +69,7 @@ public class KitListGui {
|
||||
|
||||
clicker.closeInventory();
|
||||
clicker.sendMessage(Component.text("Enter kit name to create", NamedTextColor.GOLD));
|
||||
anvilGui.open(player, new AnvilGuiListener() {
|
||||
anvilGui.open(player, Component.text("Kit name"), new AnvilGuiListener() {
|
||||
@Override
|
||||
public void onClose() {
|
||||
JavaPlugin plugin = JavaPlugin.getProvidingPlugin(KitPvpPlugin.class);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class CountSelectionGui extends ItemSelectionGui {
|
||||
protected void clicked(@NotNull Player clicker) {
|
||||
inventory.setOnClose(null);
|
||||
clicker.closeInventory();
|
||||
anvilGui.open(clicker, new AnvilGuiListener() {
|
||||
anvilGui.open(clicker, Component.text("Amount"), new AnvilGuiListener() {
|
||||
@Override
|
||||
public void onClose() {
|
||||
JavaPlugin plugin = JavaPlugin.getProvidingPlugin(KitPvpPlugin.class);
|
||||
@@ -53,7 +53,6 @@ public class CountSelectionGui extends ItemSelectionGui {
|
||||
num = Integer.parseInt(name);
|
||||
if (num < 1 || num > kitItem.getMaxStackSize()) {
|
||||
clicker.sendMessage(Component.text("Must be between 1 and " + kitItem.getMaxStackSize(), NamedTextColor.RED));
|
||||
open();
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
@@ -117,7 +117,7 @@ public class EnchantmentGui extends ItemSelectionGui {
|
||||
protected void clicked(@NotNull Player clicker) {
|
||||
inventory.setOnClose(null);
|
||||
clicker.closeInventory();
|
||||
anvilGui.open(clicker, new AnvilGuiListener() {
|
||||
anvilGui.open(clicker, Component.text("Durability"), new AnvilGuiListener() {
|
||||
@Override
|
||||
public void onClose() {
|
||||
JavaPlugin plugin = JavaPlugin.getProvidingPlugin(KitPvpPlugin.class);
|
||||
|
||||
Reference in New Issue
Block a user