add open events

This commit is contained in:
jascotty2 2019-08-27 08:27:28 -05:00
parent b41ce17710
commit f0a2d47b58
4 changed files with 98 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package com.songoda.core.gui;
import com.songoda.core.gui.methods.Clickable;
import com.songoda.core.gui.methods.Closable;
import com.songoda.core.gui.methods.Droppable;
import com.songoda.core.gui.methods.Openable;
import com.songoda.core.gui.methods.Pagable;
import com.songoda.core.gui.methods.SimpleClickable;
import java.util.HashMap;
@ -529,6 +530,11 @@ public class DoubleGUI extends GUI {
return (DoubleGUI) super.setButton(row, col, item, type, action);
}
@Override
public DoubleGUI setOnOpen(Openable action) {
return (DoubleGUI) super.setOnOpen(action);
}
@Override
public DoubleGUI setOnClose(Closable action) {
return (DoubleGUI) super.setOnClose(action);

View File

@ -4,6 +4,7 @@ import com.songoda.core.gui.methods.Pagable;
import com.songoda.core.gui.methods.Clickable;
import com.songoda.core.gui.methods.Droppable;
import com.songoda.core.gui.methods.Closable;
import com.songoda.core.gui.methods.Openable;
import com.songoda.core.gui.methods.SimpleClickable;
import java.util.Collections;
import java.util.HashMap;
@ -46,10 +47,15 @@ public class GUI {
protected static ItemStack AIR = new ItemStack(Material.AIR);
protected boolean open = false;
protected Openable opener = null;
protected Closable closer = null;
protected Droppable dropper = null;
protected Pagable pager = null;
public GUI() {
this.rows = 3;
}
public GUI(GUIType type) {
this.type = type;
switch (type) {
@ -402,6 +408,11 @@ public class GUI {
}
}
public GUI setOnOpen(Openable action) {
opener = action;
return this;
}
public GUI setOnClose(Closable action) {
closer = action;
return this;
@ -559,6 +570,9 @@ public class GUI {
public void onOpen(Player player) {
open = true;
if (opener != null) {
opener.onOpen(player, this);
}
}
public void onClose(GUIManager manager, Player player) {

View File

@ -2,7 +2,9 @@ package com.songoda.core.gui;
import com.songoda.core.compatibility.LegacyMaterials;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@ -22,12 +24,37 @@ public class GuiUtils {
return glass;
}
public static ItemStack getBorderItem(ItemStack item) {
ItemMeta glassmeta = item.getItemMeta();
glassmeta.setDisplayName(ChatColor.BLACK.toString());
item.setItemMeta(glassmeta);
return item;
}
public static ItemStack getBorderItem(Material mat) {
ItemStack item = new ItemStack(mat);
ItemMeta glassmeta = item.getItemMeta();
glassmeta.setDisplayName(ChatColor.BLACK.toString());
item.setItemMeta(glassmeta);
return item;
}
public static ItemStack getBorderItem(LegacyMaterials mat) {
ItemStack item = mat.getItem();
ItemMeta glassmeta = item.getItemMeta();
glassmeta.setDisplayName(ChatColor.BLACK.toString());
item.setItemMeta(glassmeta);
return item;
}
public static ItemStack createButtonItem(Material mat, String title, String... lore) {
ItemStack item = new ItemStack(mat);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(Arrays.asList(lore.length == 1 ? lore[0].split("\n") : lore));
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
return item;
@ -39,6 +66,8 @@ public class GuiUtils {
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(Arrays.asList(lore.length == 1 ? lore[0].split("\n") : lore));
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
return item;
@ -56,4 +85,43 @@ public class GuiUtils {
item.setItemMeta(meta);
return item;
}
public static ItemStack createButtonItem(Material mat, String title, List<String> lore) {
ItemStack item = new ItemStack(mat);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(lore.size() == 1 ? Arrays.asList(lore.get(0).split("\n")) : lore);
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
return item;
}
public static ItemStack createButtonItem(LegacyMaterials mat, String title, List<String> lore) {
ItemStack item = mat.getItem();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(lore.size() == 1 ? Arrays.asList(lore.get(0).split("\n")) : lore);
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
return item;
}
public static ItemStack createButtonItem(ItemStack from, String title, List<String> lore) {
ItemStack item = from.clone();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(lore.size() == 1 ? Arrays.asList(lore.get(0).split("\n")) : lore);
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
return item;
}
}

View File

@ -0,0 +1,9 @@
package com.songoda.core.gui.methods;
import com.songoda.core.gui.GUI;
import org.bukkit.entity.Player;
public interface Openable {
void onOpen(Player player, GUI gui);
}