Merge branch 'development' into 'master'

2.0.10

See merge request Songoda/songodaupdater!11
This commit is contained in:
Jacob Scott 2019-09-08 15:41:07 +00:00
commit 4f81d5a272
10 changed files with 200 additions and 72 deletions

View File

@ -4,7 +4,7 @@ stages:
variables: variables:
name: "SongodaCore" name: "SongodaCore"
path: "/builds/$CI_PROJECT_PATH" path: "/builds/$CI_PROJECT_PATH"
version: "2.0.7" version: "2.0.10"
build: build:
stage: build stage: build

View File

@ -3,6 +3,7 @@
<artifactId>SongodaCore</artifactId> <artifactId>SongodaCore</artifactId>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<version>maven-version-number</version> <version>maven-version-number</version>
<packaging>jar</packaging>
<build> <build>
<defaultGoal>clean install</defaultGoal> <defaultGoal>clean install</defaultGoal>
<finalName>SongodaCore-${project.version}</finalName> <finalName>SongodaCore-${project.version}</finalName>

View File

@ -46,7 +46,7 @@ public class SongodaCore {
* Whenever we make a major change to the core GUI, updater, * Whenever we make a major change to the core GUI, updater,
* or other function used by the core, increment this number * or other function used by the core, increment this number
*/ */
private final static int coreRevision = 3; private final static int coreRevision = 4;
private final static int updaterVersion = 1; private final static int updaterVersion = 1;
private final static Set<PluginInfo> registeredPlugins = new HashSet<>(); private final static Set<PluginInfo> registeredPlugins = new HashSet<>();

View File

@ -1024,10 +1024,12 @@ public enum LegacyMaterials {
static { static {
for (LegacyMaterials m : values()) { for (LegacyMaterials m : values()) {
lookupMap.put(m.name(), m); lookupMap.put(m.name(), m);
if (!m.usesCompatibility()) {
lookupMap.put(m.material + ":" + (m.data == null ? "" : m.data), m); lookupMap.put(m.material + ":" + (m.data == null ? "" : m.data), m);
} }
}
for (LegacyMaterials m : values()) { for (LegacyMaterials m : values()) {
if (!lookupMap.containsKey(m.legacy)) { if (!m.usesCompatibility() && !lookupMap.containsKey(m.legacy)) {
lookupMap.put(m.legacy, m); lookupMap.put(m.legacy, m);
} }
} }
@ -1902,6 +1904,7 @@ public enum LegacyMaterials {
case DRAGON_WALL_HEAD: case DRAGON_WALL_HEAD:
case END_GATEWAY: case END_GATEWAY:
case END_PORTAL: case END_PORTAL:
case FARMLAND:
case FIRE: // used to be able to in older versions case FIRE: // used to be able to in older versions
case FIRE_CORAL_WALL_FAN: case FIRE_CORAL_WALL_FAN:
case FROSTED_ICE: case FROSTED_ICE:

View File

@ -1,6 +1,5 @@
package com.songoda.core.core; package com.songoda.core.core;
import com.songoda.core.core.PluginInfoModule;
import com.songoda.core.locale.Locale; import com.songoda.core.locale.Locale;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@ -35,8 +34,24 @@ public class LocaleModule implements PluginInfoModule {
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"); urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
urlConnection.setRequestProperty("Accept", "*/*"); urlConnection.setRequestProperty("Accept", "*/*");
urlConnection.setInstanceFollowRedirects(true);
urlConnection.setConnectTimeout(5000); urlConnection.setConnectTimeout(5000);
// do we need to follow a redirect?
int status = urlConnection.getResponseCode();
if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM || status == HttpURLConnection.HTTP_SEE_OTHER) {
// get redirect url from "location" header field
String newUrl = urlConnection.getHeaderField("Location");
// get the cookie if needed
String cookies = urlConnection.getHeaderField("Set-Cookie");
// open the new connnection again
urlConnection = (HttpURLConnection) new URL(newUrl).openConnection();
urlConnection.setRequestProperty("Cookie", cookies);
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
urlConnection.setRequestProperty("Accept", "*/*");
urlConnection.setConnectTimeout(5000);
}
Locale.saveLocale(plugin.getJavaPlugin(), urlConnection.getInputStream(), fileName); Locale.saveLocale(plugin.getJavaPlugin(), urlConnection.getInputStream(), fileName);
urlConnection.disconnect(); urlConnection.disconnect();

View File

@ -18,7 +18,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
@ -40,7 +39,7 @@ public class Gui {
protected Inventory inventory; protected Inventory inventory;
protected String title; protected String title;
protected GuiType inventoryType = GuiType.STANDARD; protected GuiType inventoryType = GuiType.STANDARD;
protected int rows, page, pages; protected int rows, page = 1, pages = 1;
protected boolean acceptsItems = false; protected boolean acceptsItems = false;
protected boolean allowDropItems = true; protected boolean allowDropItems = true;
protected boolean allowClose = true; protected boolean allowClose = true;
@ -48,11 +47,12 @@ public class Gui {
protected final Map<Integer, ItemStack> cellItems = new HashMap<>(); protected final Map<Integer, ItemStack> cellItems = new HashMap<>();
protected final Map<Integer, Map<ClickType, Clickable>> conditionalButtons = new HashMap<>(); protected final Map<Integer, Map<ClickType, Clickable>> conditionalButtons = new HashMap<>();
protected ItemStack blankItem = GuiUtils.getBorderGlassItem(); protected ItemStack blankItem = GuiUtils.getBorderGlassItem();
protected int nextPageIndex, prevPageIndex; protected int nextPageIndex = -1, prevPageIndex = -1;
protected ItemStack nextPage, prevPage; protected ItemStack nextPage, prevPage;
protected Gui parent = null; protected Gui parent = null;
protected static ItemStack AIR = new ItemStack(Material.AIR); protected static ItemStack AIR = new ItemStack(Material.AIR);
protected GuiManager guiManager;
protected boolean open = false; protected boolean open = false;
protected Clickable defaultClicker = null; protected Clickable defaultClicker = null;
protected Openable opener = null; protected Openable opener = null;
@ -205,7 +205,21 @@ public class Gui {
@NotNull @NotNull
public Gui setTitle(String title) { public Gui setTitle(String title) {
if (title == null) title = "";
if (!title.equals(this.title)) {
this.title = title; this.title = title;
if (inventory != null) {
// update active inventory
List<Player> toUpdate = getPlayers();
boolean isAllowClose = allowClose;
exit();
Inventory oldInv = inventory;
createInventory();
inventory.setContents(oldInv.getContents());
toUpdate.forEach(player -> player.openInventory(inventory));
allowClose = isAllowClose;
}
}
return this; return this;
} }
@ -547,7 +561,7 @@ public class Gui {
public Gui setNextPage(int cell, @NotNull ItemStack item) { public Gui setNextPage(int cell, @NotNull ItemStack item) {
nextPageIndex = cell; nextPageIndex = cell;
if (page < pages) { if (page < pages) {
setButton(nextPageIndex, nextPage = item, ClickType.LEFT, (event) -> this.nextPage(event.manager)); setButton(nextPageIndex, nextPage = item, ClickType.LEFT, (event) -> this.nextPage());
} }
return this; return this;
} }
@ -556,7 +570,7 @@ public class Gui {
public Gui setNextPage(int row, int col, @NotNull ItemStack item) { public Gui setNextPage(int row, int col, @NotNull ItemStack item) {
nextPageIndex = col + row * 9; nextPageIndex = col + row * 9;
if (page < pages) { if (page < pages) {
setButton(nextPageIndex, nextPage = item, ClickType.LEFT, (event) -> this.nextPage(event.manager)); setButton(nextPageIndex, nextPage = item, ClickType.LEFT, (event) -> this.nextPage());
} }
return this; return this;
} }
@ -565,7 +579,7 @@ public class Gui {
public Gui setPrevPage(int cell, @NotNull ItemStack item) { public Gui setPrevPage(int cell, @NotNull ItemStack item) {
prevPageIndex = cell; prevPageIndex = cell;
if (page > 1) { if (page > 1) {
setButton(prevPageIndex, prevPage = item, ClickType.LEFT, (event) -> this.prevPage(event.manager)); setButton(prevPageIndex, prevPage = item, ClickType.LEFT, (event) -> this.prevPage());
} }
return this; return this;
} }
@ -574,18 +588,38 @@ public class Gui {
public Gui setPrevPage(int row, int col, @NotNull ItemStack item) { public Gui setPrevPage(int row, int col, @NotNull ItemStack item) {
prevPageIndex = col + row * 9; prevPageIndex = col + row * 9;
if (page > 1) { if (page > 1) {
setButton(prevPageIndex, prevPage = item, ClickType.LEFT, (event) -> this.prevPage(event.manager)); setButton(prevPageIndex, prevPage = item, ClickType.LEFT, (event) -> this.prevPage());
} }
return this; return this;
} }
public void nextPage(@NotNull GuiManager manager) { public void setPage(int page) {
int lastPage = page;
this.page = Math.max(1, Math.min(pages, page));
if(pager != null && this.page != lastPage) {
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
// page markers
updatePageNavigation();
}
}
public void changePage(int direction) {
int lastPage = page;
this.page = Math.max(1, Math.min(pages, page + direction));
if(pager != null && this.page != lastPage) {
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
// page markers
updatePageNavigation();
}
}
public void nextPage() {
if (page < pages) { if (page < pages) {
int lastPage = page; int lastPage = page;
++page; ++page;
// page switch events // page switch events
if (pager != null) { if (pager != null) {
pager.onPageChange(new GuiPageEvent(this, manager, lastPage, page)); pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
// page markers // page markers
updatePageNavigation(); updatePageNavigation();
@ -597,12 +631,12 @@ public class Gui {
} }
} }
public void prevPage(@NotNull GuiManager manager) { public void prevPage() {
if (page > 1) { if (page > 1) {
int lastPage = page; int lastPage = page;
--page; --page;
if (pager != null) { if (pager != null) {
pager.onPageChange(new GuiPageEvent(this, manager, lastPage, page)); pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
// page markers // page markers
updatePageNavigation(); updatePageNavigation();
@ -615,19 +649,23 @@ public class Gui {
} }
protected void updatePageNavigation() { protected void updatePageNavigation() {
if(prevPage != null) {
if (page > 1) { if (page > 1) {
this.setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage(event.manager)); this.setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage());
} else { } else {
this.setItem(prevPageIndex, null); this.setItem(prevPageIndex, null);
this.clearActions(prevPageIndex); this.clearActions(prevPageIndex);
} }
}
if(nextPage != null) {
if (pages > 1 && page != pages) { if (pages > 1 && page != pages) {
this.setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage(event.manager)); this.setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage());
} else { } else {
this.setItem(nextPageIndex, null); this.setItem(nextPageIndex, null);
this.clearActions(nextPageIndex); this.clearActions(nextPageIndex);
} }
} }
}
@NotNull @NotNull
protected Inventory getOrCreateInventory(@NotNull GuiManager manager) { protected Inventory getOrCreateInventory(@NotNull GuiManager manager) {
@ -636,19 +674,10 @@ public class Gui {
@NotNull @NotNull
protected Inventory generateInventory(@NotNull GuiManager manager) { protected Inventory generateInventory(@NotNull GuiManager manager) {
this.guiManager = manager;
final int cells = rows * 9; final int cells = rows * 9;
InventoryType t = inventoryType == null ? InventoryType.CHEST : inventoryType.type;
switch (t) {
case DISPENSER:
case HOPPER:
inventory = Bukkit.getServer().createInventory(new GuiHolder(manager, this), t,
title == null ? "" : trimTitle(ChatColor.translateAlternateColorCodes('&', title)));
break;
default:
inventory = Bukkit.getServer().createInventory(new GuiHolder(manager, this), cells,
title == null ? "" : trimTitle(ChatColor.translateAlternateColorCodes('&', title)));
}
createInventory();
for (int i = 0; i < cells; ++i) { for (int i = 0; i < cells; ++i) {
final ItemStack item = cellItems.get(i); final ItemStack item = cellItems.get(i);
inventory.setItem(i, item != null ? item : (unlockedCells.getOrDefault(i, false) ? AIR : blankItem)); inventory.setItem(i, item != null ? item : (unlockedCells.getOrDefault(i, false) ? AIR : blankItem));
@ -657,6 +686,20 @@ public class Gui {
return inventory; return inventory;
} }
protected void createInventory() {
final InventoryType t = inventoryType == null ? InventoryType.CHEST : inventoryType.type;
switch (t) {
case DISPENSER:
case HOPPER:
inventory = Bukkit.getServer().createInventory(new GuiHolder(guiManager, this), t,
title == null ? "" : trimTitle(title));
break;
default:
inventory = Bukkit.getServer().createInventory(new GuiHolder(guiManager, this), rows * 9,
title == null ? "" : trimTitle(title));
}
}
@Nullable @Nullable
public Gui getParent() { public Gui getParent() {
return parent; return parent;
@ -674,7 +717,9 @@ public class Gui {
} }
protected static String trimTitle(String title) { protected static String trimTitle(String title) {
if (title != null && title.length() > 32) { if(title == null) {
return "";
} else if (title != null && title.length() > 32) {
return title.substring(0, 31); return title.substring(0, 31);
} }
return title; return title;
@ -709,6 +754,7 @@ public class Gui {
public void onOpen(@NotNull GuiManager manager, @NotNull Player player) { public void onOpen(@NotNull GuiManager manager, @NotNull Player player) {
open = true; open = true;
guiManager = manager;
if (opener != null) { if (opener != null) {
opener.onOpen(new GuiOpenEvent(manager, this, player)); opener.onOpen(new GuiOpenEvent(manager, this, player));
} }
@ -719,11 +765,12 @@ public class Gui {
manager.showGUI(player, this); manager.showGUI(player, this);
return; return;
} }
boolean showParent = open && parent != null;
if (open && closer != null) { if (open && closer != null) {
open = inventory.getViewers().isEmpty(); open = !inventory.getViewers().isEmpty();
closer.onClose(new GuiCloseEvent(manager, this, player)); closer.onClose(new GuiCloseEvent(manager, this, player));
} }
if (parent != null) { if (showParent) {
manager.showGUI(player, parent); manager.showGUI(player, parent);
} }
} }

View File

@ -36,6 +36,7 @@ public class GuiManager {
final UUID uuid = UUID.randomUUID(); // manager tracking to fix weird bugs from lazy programming final UUID uuid = UUID.randomUUID(); // manager tracking to fix weird bugs from lazy programming
final GuiListener listener = new GuiListener(this); final GuiListener listener = new GuiListener(this);
final Map<Player, Gui> openInventories = new HashMap(); final Map<Player, Gui> openInventories = new HashMap();
private final Object lock = new Object();
private boolean initialized = false; private boolean initialized = false;
private boolean shutdown = false; private boolean shutdown = false;
@ -77,15 +78,21 @@ public class GuiManager {
} else if (!initialized) { } else if (!initialized) {
init(); init();
} }
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
Gui openInv = openInventories.get(player); Gui openInv = openInventories.get(player);
if(openInv != null) { if (openInv != null) {
openInv.open = false; openInv.open = false;
} }
Inventory inv = gui.getOrCreateInventory(this); Inventory inv = gui.getOrCreateInventory(this);
Bukkit.getScheduler().runTask(plugin, () -> {
player.openInventory(inv); player.openInventory(inv);
gui.onOpen(this, player); gui.onOpen(this, player);
synchronized(lock) {
openInventories.put(player, gui); openInventories.put(player, gui);
} }
});
});
}
public void showPopup(Player player, String message) { public void showPopup(Player player, String message) {
showPopup(player, message, LegacyMaterials.NETHER_STAR, BackgroundType.ADVENTURE); showPopup(player, message, LegacyMaterials.NETHER_STAR, BackgroundType.ADVENTURE);
@ -115,12 +122,14 @@ public class GuiManager {
* Close all active GUIs * Close all active GUIs
*/ */
public void closeAll() { public void closeAll() {
synchronized(lock) {
openInventories.entrySet().stream() openInventories.entrySet().stream()
.filter(e -> e.getKey().getOpenInventory().getTopInventory().getHolder() instanceof GuiHolder) .filter(e -> e.getKey().getOpenInventory().getTopInventory().getHolder() instanceof GuiHolder)
.collect(Collectors.toList()) // to prevent concurrency exceptions .collect(Collectors.toList()) // to prevent concurrency exceptions
.forEach(e -> e.getKey().closeInventory()); .forEach(e -> e.getKey().closeInventory());
openInventories.clear(); openInventories.clear();
} }
}
protected static class GuiListener implements Listener { protected static class GuiListener implements Listener {

View File

@ -103,6 +103,22 @@ public class GuiUtils {
return item; return item;
} }
public static ItemStack createButtonItem(LegacyMaterials mat, int amount, String title, String... lore) {
ItemStack item = mat.getItem();
item.setAmount(amount);
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(getSafeLore(lore));
} else {
meta.setLore(Collections.EMPTY_LIST);
}
item.setItemMeta(meta);
}
return item;
}
public static ItemStack createButtonItem(ItemStack from, String title, String... lore) { public static ItemStack createButtonItem(ItemStack from, String title, String... lore) {
ItemStack item = from.clone(); ItemStack item = from.clone();
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
@ -133,6 +149,22 @@ public class GuiUtils {
return item; return item;
} }
public static ItemStack createButtonItem(LegacyMaterials mat, int amount, String title, List<String> lore) {
ItemStack item = mat.getItem();
item.setAmount(amount);
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(title);
if (lore != null) {
meta.setLore(getSafeLore(lore));
} else {
meta.setLore(Collections.EMPTY_LIST);
}
}
item.setItemMeta(meta);
return item;
}
public static ItemStack createButtonItem(ItemStack from, String title, List<String> lore) { public static ItemStack createButtonItem(ItemStack from, String title, List<String> lore) {
ItemStack item = from.clone(); ItemStack item = from.clone();
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();

View File

@ -80,7 +80,7 @@ public class SimplePagedGui extends Gui {
} }
@Override @Override
public void nextPage(GuiManager manager) { public void nextPage() {
if (page < pages) { if (page < pages) {
++page; ++page;
showPage(); showPage();
@ -88,7 +88,7 @@ public class SimplePagedGui extends Gui {
} }
@Override @Override
public void prevPage(GuiManager manager) { public void prevPage() {
if (page > 1) { if (page > 1) {
--page; --page;
showPage(); showPage();
@ -111,7 +111,7 @@ public class SimplePagedGui extends Gui {
protected void updatePageNavigation() { protected void updatePageNavigation() {
if (page > 1) { if (page > 1) {
inventory.setItem(inventory.getSize() - prevPageIndex, prevPage); inventory.setItem(inventory.getSize() - prevPageIndex, prevPage);
this.setButton(-prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage(event.manager)); this.setButton(-prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage());
} else { } else {
inventory.setItem(inventory.getSize() - prevPageIndex, footerBackItem != null ? footerBackItem : blankItem); inventory.setItem(inventory.getSize() - prevPageIndex, footerBackItem != null ? footerBackItem : blankItem);
this.setItem(-prevPageIndex, null); this.setItem(-prevPageIndex, null);
@ -119,7 +119,7 @@ public class SimplePagedGui extends Gui {
} }
if (pages > 1 && page != pages) { if (pages > 1 && page != pages) {
inventory.setItem(inventory.getSize() - nextPageIndex, nextPage); inventory.setItem(inventory.getSize() - nextPageIndex, nextPage);
this.setButton(-nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage(event.manager)); this.setButton(-nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage());
} else { } else {
inventory.setItem(inventory.getSize() - nextPageIndex, footerBackItem != null ? footerBackItem : blankItem); inventory.setItem(inventory.getSize() - nextPageIndex, footerBackItem != null ? footerBackItem : blankItem);
this.setItem(-nextPageIndex, null); this.setItem(-nextPageIndex, null);
@ -129,6 +129,7 @@ public class SimplePagedGui extends Gui {
@Override @Override
protected Inventory generateInventory(GuiManager manager) { protected Inventory generateInventory(GuiManager manager) {
this.guiManager = manager;
// calculate pages here // calculate pages here
rowsPerPage = useHeader ? 4 : 5; rowsPerPage = useHeader ? 4 : 5;
maxCellSlot = (this.cellItems.isEmpty() ? 0 : this.cellItems.keySet().stream().max(Integer::compare).get()) + 1; maxCellSlot = (this.cellItems.isEmpty() ? 0 : this.cellItems.keySet().stream().max(Integer::compare).get()) + 1;
@ -137,16 +138,21 @@ public class SimplePagedGui extends Gui {
this.setRows(maxRows + (useHeader ? 1 : 0)); this.setRows(maxRows + (useHeader ? 1 : 0));
// create inventory view // create inventory view
final int cells = rows * 9; createInventory();
inventory = Bukkit.getServer().createInventory(new GuiHolder(manager, this), cells,
title == null ? "" : trimTitle(ChatColor.translateAlternateColorCodes('&', title)));
// populate and return the display inventory // populate and return the display inventory
page = 1; page = Math.min(page, pages);
update(); update();
return inventory; return inventory;
} }
@Override
protected void createInventory() {
final int cells = rows * 9;
inventory = Bukkit.getServer().createInventory(new GuiHolder(guiManager, this), cells,
title == null ? "" : trimTitle(title));
}
@Override @Override
public void update() { public void update() {
if (inventory == null) { if (inventory == null) {
@ -164,8 +170,7 @@ public class SimplePagedGui extends Gui {
if (Math.min(54, (maxRows + (useHeader ? 1 : 0)) * 9) != inventory.getSize()) { if (Math.min(54, (maxRows + (useHeader ? 1 : 0)) * 9) != inventory.getSize()) {
toUpdate = getPlayers(); toUpdate = getPlayers();
this.setRows(maxRows + (useHeader ? 1 : 0)); this.setRows(maxRows + (useHeader ? 1 : 0));
inventory = Bukkit.getServer().createInventory(inventory.getHolder(), rows * 9, createInventory();
title == null ? "" : trimTitle(ChatColor.translateAlternateColorCodes('&', title)));
} }
// populate header // populate header
@ -189,7 +194,7 @@ public class SimplePagedGui extends Gui {
if(toUpdate != null) { if(toUpdate != null) {
// whoopsie! // whoopsie!
exit(); exit();
toUpdate.forEach(player -> ((GuiHolder) inventory.getHolder()).manager.showGUI(player, this)); toUpdate.forEach(player -> guiManager.showGUI(player, this));
} }
} }

View File

@ -64,6 +64,22 @@ public final class PluginHook <T extends Class> {
} }
} }
/**
* Add a hook handler for us to use later. <br>
* NOTE: The class passed MUST extend Hook. <br>
* Permissible constructors are empty () or (org.bukkit.plugin.Plugin) <br>
* Each plugin defined must use a different handler class.
*
* @param <T>
* @param type Generic hook type for this plugin
* @param pluginName Plugin name
* @param handler Specific class that will handle this plugin, if enabled.
* @return instance of the PluginHook that was added
*/
public static <T extends Class> PluginHook addHook(T type, String pluginName, Class handler) {
return new PluginHook(type, pluginName, handler);
}
protected static Map<PluginHook, Hook> loadHooks(Class type, Plugin plugin) { protected static Map<PluginHook, Hook> loadHooks(Class type, Plugin plugin) {
Map<PluginHook, Hook> loaded = new LinkedHashMap<>(); Map<PluginHook, Hook> loaded = new LinkedHashMap<>();
PluginManager pluginManager = Bukkit.getPluginManager(); PluginManager pluginManager = Bukkit.getPluginManager();