-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Re-added deprecated old Menu stuff (Just so VanillaShop won't break)
* Added customizable cancellation feature to Synchronous & Asynchronous task builders.
- Loading branch information
Showing
10 changed files
with
323 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/com/github/sanctum/labyrinth/gui/GuiLibrary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.github.sanctum.labyrinth.gui; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* @deprecated Fully replaced by new functional menu building tools. | ||
* Companion class to all menus. This is needed to pass information across the entire | ||
* menu system no matter how many inventories are opened or closed. | ||
* | ||
* Each player has one of these objects, and only one. | ||
*/ | ||
@Deprecated | ||
public class GuiLibrary { | ||
private final Player viewer; | ||
private final UUID viewerID; | ||
private String data; | ||
private String data2; | ||
|
||
public GuiLibrary(Player p) { | ||
this.viewer = p; | ||
this.viewerID = p.getUniqueId(); | ||
} | ||
|
||
public Player getViewer() { return viewer; } | ||
|
||
public UUID getUUID() { | ||
return viewerID; | ||
} | ||
|
||
public void setData(String data) { | ||
this.data = data; | ||
} | ||
|
||
public String getData() { | ||
return data; | ||
} | ||
|
||
public void setData2(String data2) { | ||
this.data2 = data2; | ||
} | ||
|
||
public String getData2() { | ||
return data2; | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
src/main/java/com/github/sanctum/labyrinth/gui/Menu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package com.github.sanctum.labyrinth.gui; | ||
|
||
import com.github.sanctum.labyrinth.Labyrinth; | ||
import com.github.sanctum.labyrinth.formatting.string.ColoredString; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Material; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import org.bukkit.event.inventory.InventoryType; | ||
import org.bukkit.inventory.Inventory; | ||
import org.bukkit.inventory.InventoryHolder; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
import org.bukkit.persistence.PersistentDataType; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @deprecated Fully replaced by {@link com.github.sanctum.labyrinth.gui.menuman.Menu} | ||
*/ | ||
@Deprecated | ||
public abstract class Menu implements InventoryHolder { | ||
|
||
/* | ||
* Defines the behavior and attributes of all menus in our plugin | ||
*/ | ||
|
||
// Protected values that can be accessed in the menus | ||
protected GuiLibrary guiLibrary; | ||
protected Inventory inventory; | ||
protected boolean isNew = Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.15") || Bukkit.getVersion().contains("1.14") || Bukkit.getVersion().contains("1.13"); | ||
protected ItemStack FILLER_GLASS = makeItem(isNew ? Material.getMaterial("BLACK_STAINED_GLASS_PANE") : Material.getMaterial("STAINED_GLASS_PANE"), " "); | ||
protected ItemStack FILLER_GLASS_LIGHT = makeItem(isNew ? Material.LIGHT_BLUE_STAINED_GLASS_PANE : Material.getMaterial("STAINED_GLASS_PANE"), | ||
new ColoredString("&7&oOther items will appear here.", ColoredString.ColorType.MC).toString()); | ||
|
||
// Constructor for Menu. Pass in a gui so that | ||
// we have information on who's menu this is and | ||
// what info is to be transfered | ||
public Menu(GuiLibrary guiLibrary) { | ||
this.guiLibrary = guiLibrary; | ||
} | ||
|
||
// let each menu decide their name | ||
public abstract String getMenuName(); | ||
|
||
// let each menu decide their slot amount | ||
public abstract int getSlots(); | ||
|
||
// let each menu decide how the items in the menu will be handled when clicked | ||
public abstract void handleMenu(InventoryClickEvent e); | ||
|
||
// let each menu decide what items are to be placed in the inventory menu | ||
public abstract void setMenuItems(); | ||
|
||
// When called, an inventory is created and opened for the player | ||
public void open() { | ||
// The owner of the inventory created is the Menu itself, | ||
// so we are able to reverse engineer the Menu object from the | ||
// inventoryHolder in the MenuListener class when handling clicks | ||
inventory = Bukkit.createInventory(this, getSlots(), getMenuName()); | ||
|
||
// grab all the items specified to be used for this menu and add to inventory | ||
this.setMenuItems(); | ||
|
||
// open the inventory for the player | ||
guiLibrary.getViewer().openInventory(inventory); | ||
} | ||
|
||
public void start() { | ||
// The owner of the inventory created is the Menu itself, | ||
// so we are able to reverse engineer the Menu object from the | ||
// inventoryHolder in the MenuListener class when handling clicks | ||
inventory = Bukkit.createInventory(this, InventoryType.ANVIL, getMenuName()); | ||
|
||
// grab all the items specified to be used for this menu and add to inventory | ||
this.setMenuItems(); | ||
|
||
// open the inventory for the player | ||
guiLibrary.getViewer().openInventory(inventory); | ||
} | ||
|
||
|
||
// Overridden method from the InventoryHolder interface | ||
@Override | ||
public Inventory getInventory() { | ||
return inventory; | ||
} | ||
|
||
// Helpful utility method to fill all remaining slots with "filler glass" | ||
public void setFillerGlass() { | ||
for (int i = 0; i < getSlots(); i++) { | ||
if (inventory.getItem(i) == null) { | ||
inventory.setItem(i, FILLER_GLASS); | ||
} | ||
} | ||
} | ||
|
||
protected List<String> color(String... text) { | ||
ArrayList<String> convert = new ArrayList<>(); | ||
for (String t : text) { | ||
convert.add(new ColoredString(t, ColoredString.ColorType.MC).toString()); | ||
} | ||
return convert; | ||
} | ||
|
||
public ItemStack makeItem(Material material, String displayName, String... lore) { | ||
|
||
ItemStack item = new ItemStack(material); | ||
ItemMeta itemMeta = item.getItemMeta(); | ||
assert itemMeta != null; | ||
itemMeta.setDisplayName(new ColoredString(displayName, ColoredString.ColorType.MC).toString()); | ||
|
||
itemMeta.setLore(color(lore)); | ||
item.setItemMeta(itemMeta); | ||
|
||
return item; | ||
} | ||
|
||
public ItemStack makePersistentItem(Material material, String displayName, String key, String data, String... lore) { | ||
|
||
ItemStack item = new ItemStack(material); | ||
ItemMeta itemMeta = item.getItemMeta(); | ||
assert itemMeta != null; | ||
itemMeta.setDisplayName(new ColoredString(displayName, ColoredString.ColorType.MC).toString()); | ||
itemMeta.getPersistentDataContainer().set(new NamespacedKey(Labyrinth.getInstance(), key), PersistentDataType.STRING, data); | ||
itemMeta.setLore(color(lore)); | ||
item.setItemMeta(itemMeta); | ||
|
||
return item; | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/com/github/sanctum/labyrinth/gui/Pagination.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.github.sanctum.labyrinth.gui; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.Material; | ||
|
||
/** | ||
* @deprecated Fully replaced by functional paginaton builder. {@link com.github.sanctum.labyrinth.gui.builder.PaginatedBuilder} | ||
*/ | ||
@Deprecated | ||
public abstract class Pagination extends Menu { | ||
|
||
// Keep track of what page the menu is on | ||
protected int page = 0; | ||
// 28 is max items because with the border set below, | ||
// 28 empty slots are remaining. | ||
protected int maxItemsPerPage = 28; | ||
// the index represents the index of the slot | ||
// that the loop is on | ||
protected int index = 0; | ||
|
||
public Pagination(GuiLibrary guiLibrary) { | ||
super(guiLibrary); | ||
} | ||
|
||
// Set the border and menu buttons for the menu | ||
public void addMenuBorder() { | ||
inventory.setItem(48, makeItem(isNew ? Material.DARK_OAK_BUTTON : Material.getMaterial("WOODEN_BUTTON"), ChatColor.GREEN + "Left")); | ||
|
||
inventory.setItem(49, makeItem(Material.BARRIER, ChatColor.DARK_RED + "Close")); | ||
|
||
inventory.setItem(50, makeItem(isNew ? Material.DARK_OAK_BUTTON : Material.getMaterial("WOODEN_BUTTON"), ChatColor.GREEN + "Right")); | ||
|
||
for (int i = 0; i < 10; i++) { | ||
if (inventory.getItem(i) == null) { | ||
inventory.setItem(i, super.FILLER_GLASS); | ||
} | ||
} | ||
|
||
inventory.setItem(17, super.FILLER_GLASS); | ||
inventory.setItem(18, super.FILLER_GLASS); | ||
inventory.setItem(26, super.FILLER_GLASS); | ||
inventory.setItem(27, super.FILLER_GLASS); | ||
inventory.setItem(35, super.FILLER_GLASS); | ||
inventory.setItem(36, super.FILLER_GLASS); | ||
|
||
for (int i = 44; i < 54; i++) { | ||
if (inventory.getItem(i) == null) { | ||
inventory.setItem(i, super.FILLER_GLASS); | ||
} | ||
} | ||
} | ||
|
||
public void setFillerGlass() { | ||
for (int i = 0; i < getSlots(); i++) { | ||
if (inventory.getItem(i) == null) { | ||
inventory.setItem(i, super.FILLER_GLASS); | ||
} | ||
} | ||
} | ||
|
||
public void setFillerGlassLight() { | ||
for (int i = 0; i < getSlots(); i++) { | ||
if (inventory.getItem(i) == null) { | ||
inventory.setItem(i, super.FILLER_GLASS_LIGHT); | ||
} | ||
} | ||
} | ||
|
||
public int getMaxItemsPerPage() { | ||
return maxItemsPerPage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/github/sanctum/labyrinth/task/ScheduledTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.github.sanctum.labyrinth.task; | ||
|
||
import org.bukkit.scheduler.BukkitRunnable; | ||
|
||
public class ScheduledTask { | ||
|
||
protected final BukkitRunnable runnable; | ||
|
||
protected ScheduledTask(BukkitRunnable runnable) { | ||
this.runnable = runnable; | ||
} | ||
|
||
public synchronized void cancel() { | ||
this.runnable.cancel(); | ||
} | ||
|
||
public synchronized boolean isCancelled() { | ||
return this.runnable.isCancelled(); | ||
} | ||
|
||
public synchronized int getId() { | ||
return this.runnable.getTaskId(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.