mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-12-26 02:17:40 +01:00
add open events
This commit is contained in:
parent
b41ce17710
commit
f0a2d47b58
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
@ -13,7 +15,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
* @author jascotty2
|
||||
*/
|
||||
public class GuiUtils {
|
||||
|
||||
|
||||
public static ItemStack getBorderGlassItem() {
|
||||
ItemStack glass = LegacyMaterials.LIGHT_BLUE_STAINED_GLASS_PANE.getItem();
|
||||
ItemMeta glassmeta = glass.getItemMeta();
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
9
src/main/java/com/songoda/core/gui/methods/Openable.java
Normal file
9
src/main/java/com/songoda/core/gui/methods/Openable.java
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user