mirror of
https://github.com/trainerlord/WorldSystem.git
synced 2024-11-30 13:03:23 +01:00
GUI complete rewritten. Added changelog at autoupdater
This commit is contained in:
parent
c0e2ff98ed
commit
1726bb60ef
@ -1,5 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/de/butzlabben/inventory/OrcItem.java=Cp1252
|
||||
encoding//src/de/butzlabben/world/WorldSystem.java=UTF-8
|
||||
encoding//src/de/butzlabben/world/command/WSCommand.java=UTF-8
|
||||
encoding//src/de/butzlabben/world/config/GuiConfig.java=Cp1252
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: WorldSystem
|
||||
version: 2.3.0
|
||||
version: 2.3.1
|
||||
author: Butzlabben
|
||||
main: de.butzlabben.world.WorldSystem
|
||||
|
||||
|
@ -21,10 +21,26 @@ options:
|
||||
material: ORANGE_DYE
|
||||
display: '&6Coming soon...'
|
||||
|
||||
# How the back item should look like
|
||||
back:
|
||||
material: BARRIER
|
||||
display: '&cBack'
|
||||
|
||||
# WorldoptionsGUI
|
||||
world:
|
||||
# What the title of the Inv should be
|
||||
title: 'World Options'
|
||||
|
||||
# Rows
|
||||
rows: 2
|
||||
rows: 3
|
||||
|
||||
# Where the back item should be
|
||||
back:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 3
|
||||
col: 5
|
||||
|
||||
# Reset button
|
||||
reset:
|
||||
# If feature should be enabled or not
|
||||
@ -61,40 +77,61 @@ options:
|
||||
material: TNT
|
||||
display: '&eToggle TNT-Explosion'
|
||||
|
||||
players:
|
||||
back:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 3
|
||||
col: 5
|
||||
|
||||
skull_item:
|
||||
material: PLAYER_HEAD
|
||||
players:
|
||||
title: 'Players added to this world'
|
||||
|
||||
back:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 6
|
||||
col: 6
|
||||
|
||||
rows: 6
|
||||
|
||||
nextpage:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 6
|
||||
col: 9
|
||||
col: 8
|
||||
material: PAPER
|
||||
display: '&eNext Page'
|
||||
pagebefore:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 6
|
||||
col: 1
|
||||
col: 2
|
||||
material: PAPER
|
||||
display: '&ePage before'
|
||||
currentpage:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 6
|
||||
col: 5
|
||||
col: 4
|
||||
material: SUNFLOWER
|
||||
display: '&eCurrent page: &a%page'
|
||||
player_list_to_row: 4
|
||||
|
||||
playerhead:
|
||||
material: PLAYER_HEAD
|
||||
display: '&e%player'
|
||||
|
||||
# PlayerGUI for managing one player on a world
|
||||
player:
|
||||
rows: 2
|
||||
title: 'Player options for %player'
|
||||
|
||||
back:
|
||||
slot:
|
||||
enabled: true
|
||||
row: 3
|
||||
col: 5
|
||||
|
||||
rows: 3
|
||||
|
||||
build:
|
||||
enabled: true
|
||||
slot:
|
||||
@ -202,18 +239,27 @@ options:
|
||||
|
||||
# WorldsystemGUI
|
||||
worldsystem:
|
||||
title: 'WorldSystem'
|
||||
|
||||
rows: 1
|
||||
|
||||
back:
|
||||
slot:
|
||||
enabled: true
|
||||
row: 1
|
||||
col: 5
|
||||
|
||||
playeroptions:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 1
|
||||
col: 4
|
||||
col: 1
|
||||
material: LEATHER_HELMET
|
||||
display: '&ePlayer Options'
|
||||
worldoptions:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 1
|
||||
col: 6
|
||||
col: 9
|
||||
material: GRASS_BLOCK
|
||||
display: '&eWorld Options'
|
@ -53,10 +53,10 @@ public class AutoUpdater implements Listener {
|
||||
String v = plugin.getDescription().getVersion();
|
||||
if (!ui.getVersion().equals(plugin.getDescription().getVersion())) {
|
||||
|
||||
if (!ui.isSilent())
|
||||
if (!ui.isSilent()) {
|
||||
Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "Found new version. Current: " + v
|
||||
+ ", Available: " + ui.getVersion());
|
||||
|
||||
}
|
||||
// Get jar file
|
||||
Method getFileMethod = null;
|
||||
try {
|
||||
@ -90,9 +90,11 @@ public class AutoUpdater implements Listener {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
p.sendMessage(
|
||||
PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm");
|
||||
p.sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates");
|
||||
}
|
||||
Bukkit.getConsoleSender().sendMessage(
|
||||
PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm");
|
||||
Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates");
|
||||
}
|
||||
} else {
|
||||
confirmNeed = false;
|
||||
@ -104,6 +106,7 @@ public class AutoUpdater implements Listener {
|
||||
if (e.getPlayer().hasPermission("ws.confirm")) {
|
||||
e.getPlayer().sendMessage(
|
||||
PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm");
|
||||
e.getPlayer().sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates");
|
||||
}
|
||||
}
|
||||
|
||||
|
12
WorldSystem/src/de/butzlabben/inventory/CostumInv.java
Normal file
12
WorldSystem/src/de/butzlabben/inventory/CostumInv.java
Normal file
@ -0,0 +1,12 @@
|
||||
package de.butzlabben.inventory;
|
||||
|
||||
/**
|
||||
* @author Butzlabben
|
||||
* @since 28.06.2018
|
||||
*/
|
||||
public class CostumInv extends OrcInventory{
|
||||
|
||||
public CostumInv(String title, int rows) {
|
||||
super(title, rows);
|
||||
}
|
||||
}
|
@ -6,43 +6,31 @@ import java.util.Objects;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import de.butzlabben.world.WorldSystem;
|
||||
import de.butzlabben.world.wrapper.WorldPlayer;
|
||||
public abstract class OrcInventory {
|
||||
|
||||
public abstract class OrcInventory implements Listener {
|
||||
|
||||
private String title;
|
||||
protected String title;
|
||||
private int rows;
|
||||
private InventoryType type;
|
||||
private final boolean isStatic;
|
||||
|
||||
private HashMap<Integer, OrcItem> items = new HashMap<>();
|
||||
protected HashMap<Integer, OrcItem> items = new HashMap<>();
|
||||
|
||||
public OrcInventory(String title, boolean isStatic) {
|
||||
this.isStatic = isStatic;
|
||||
public OrcInventory(String title) {
|
||||
Objects.requireNonNull(title, "title cannot be null");
|
||||
this.title = title;
|
||||
Bukkit.getPluginManager().registerEvents(this, JavaPlugin.getPlugin(WorldSystem.class));
|
||||
}
|
||||
|
||||
public OrcInventory(String title, int rows, boolean isStatic) {
|
||||
this(title, isStatic);
|
||||
public OrcInventory(String title, int rows) {
|
||||
this(title);
|
||||
if (rows <= 0 || rows > 6)
|
||||
throw new IllegalArgumentException("rows cannot be smaller than 1 or bigger than 6");
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
public OrcInventory(String title, InventoryType type, boolean isStatic) {
|
||||
this(title, isStatic);
|
||||
public OrcInventory(String title, InventoryType type) {
|
||||
this(title);
|
||||
if (type == null || type == InventoryType.CHEST) {
|
||||
this.type = null;
|
||||
rows = 3;
|
||||
@ -75,9 +63,12 @@ public abstract class OrcInventory implements Listener {
|
||||
return getInventory(p, title);
|
||||
}
|
||||
|
||||
public void redraw(Player p) {
|
||||
p.closeInventory();
|
||||
p.openInventory(getInventory(p));
|
||||
}
|
||||
|
||||
public Inventory getInventory(Player p, String title) {
|
||||
if (canOpen(p) == false)
|
||||
return null;
|
||||
Inventory inv;
|
||||
int size;
|
||||
if (type == null) {
|
||||
@ -87,16 +78,17 @@ public abstract class OrcInventory implements Listener {
|
||||
inv = Bukkit.createInventory(null, type, title);
|
||||
size = type.getDefaultSize();
|
||||
}
|
||||
WorldPlayer wp = new WorldPlayer(p);
|
||||
|
||||
for (Entry<Integer, OrcItem> entry : items.entrySet()) {
|
||||
if (entry.getKey() >= 0 && entry.getKey() < size) {
|
||||
inv.setItem(entry.getKey(), entry.getValue().getItemStack(p, wp));
|
||||
inv.setItem(entry.getKey(), entry.getValue().getItemStack(p));
|
||||
} else {
|
||||
System.err.println("[WorldSystem] There is a problem with a configured Item!");
|
||||
System.err.println("There is a problem with a configured Item!");
|
||||
}
|
||||
}
|
||||
|
||||
OrcListener.getInstance().register(p.getUniqueId(), this);
|
||||
|
||||
return inv;
|
||||
}
|
||||
|
||||
@ -107,28 +99,4 @@ public abstract class OrcInventory implements Listener {
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void on(InventoryClickEvent e) {
|
||||
if (e.getClickedInventory() != null && e.getClickedInventory().getTitle().equals(title)) {
|
||||
e.setCancelled(true);
|
||||
OrcItem item = items.get(e.getSlot());
|
||||
if (item != null)
|
||||
item.onClick((Player) e.getWhoClicked(), this);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void on(InventoryCloseEvent e) {
|
||||
if (e.getInventory() != null && e.getInventory().getTitle().equals(title) && !isStatic) {
|
||||
unregister();
|
||||
}
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
public abstract boolean canOpen(Player p);
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.Objects;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
@ -14,12 +15,17 @@ import de.butzlabben.world.wrapper.WorldPlayer;
|
||||
|
||||
public class OrcItem {
|
||||
|
||||
public static OrcItem enabled, disabled, coming_soon, error = new OrcItem(Material.BARRIER, null,
|
||||
public static OrcItem enabled, disabled, coming_soon, back, error = new OrcItem(Material.BARRIER, null,
|
||||
"§cERROR: Item is wrong configured!", "§cPath in config: see Displayname");
|
||||
|
||||
private ItemStack is;
|
||||
private OrcClickListener listener;
|
||||
private DependListener depend;
|
||||
private Runnable callback;
|
||||
|
||||
public void setCallback(Runnable r) {
|
||||
callback = r;
|
||||
}
|
||||
|
||||
public OrcItem(Material mat, String display, String... lore) {
|
||||
setItemStack(mat, display, lore);
|
||||
@ -30,50 +36,36 @@ public class OrcItem {
|
||||
}
|
||||
|
||||
public OrcItem(Material mat, String display, List<String> lore) {
|
||||
setItemStack(mat, display, lore);
|
||||
setItemStack(mat, (byte) 0, display, lore);
|
||||
}
|
||||
|
||||
// public OrcItem(int id, byte data, String display, List<String> lore) {
|
||||
// setItemStack(id, data, display, lore);
|
||||
// }
|
||||
|
||||
// @SuppressWarnings("deprecation")
|
||||
// public OrcItem setItemStack(int id, byte data, String display, List<String> lore) {
|
||||
// is = new ItemStack(id, 1, data);
|
||||
// ItemMeta meta = is.getItemMeta();
|
||||
// if (meta != null) {
|
||||
// meta.setDisplayName(display);
|
||||
// meta.setLore(lore);
|
||||
// is.setItemMeta(meta);
|
||||
// }
|
||||
// return this;
|
||||
// }
|
||||
|
||||
// public OrcItem(int id, byte data, String display, String... lore) {
|
||||
// setItemStack(id, data, display, lore);
|
||||
// }
|
||||
|
||||
// public OrcItem setItemStack(int id, byte data, String display, String[] lore) {
|
||||
// return setItemStack(id, data, display, Arrays.asList(lore));
|
||||
// }
|
||||
public OrcItem(Material mat) {
|
||||
this(new ItemStack(mat));
|
||||
}
|
||||
|
||||
public OrcItem(Material material, byte data, String display, ArrayList<String> lore) {
|
||||
is = new ItemStack(material, 1, data);
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
meta.setDisplayName(display);
|
||||
meta.setLore(lore);
|
||||
is.setItemMeta(meta);
|
||||
setItemStack(material, data, display, lore);
|
||||
}
|
||||
|
||||
public OrcItem setItemStack(Material mat, String display, List<String> lore) {
|
||||
is = new ItemStack(mat);
|
||||
public OrcItem setItemStack(Material mat, byte data, String display, List<String> lore) {
|
||||
is = new ItemStack(mat, 1 , data);
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
meta.setDisplayName(display);
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
is.setItemMeta(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(Player p) {
|
||||
if (p != null && depend != null) {
|
||||
ItemStack is = depend.getItemStack(p, new WorldPlayer(p));
|
||||
if (is != null)
|
||||
return is;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(Player p, WorldPlayer wp) {
|
||||
if (p != null && depend != null) {
|
||||
ItemStack is = depend.getItemStack(p, wp);
|
||||
@ -83,14 +75,21 @@ public class OrcItem {
|
||||
return is;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return is;
|
||||
}
|
||||
|
||||
public OrcItem setOnClick(OrcClickListener listener) {
|
||||
this.listener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OrcItem onClick(Player p, OrcInventory inv) {
|
||||
if (listener != null)
|
||||
if (listener != null) {
|
||||
listener.onClick(p, inv, this);
|
||||
}
|
||||
if (callback != null)
|
||||
callback.run();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -118,11 +117,14 @@ public class OrcItem {
|
||||
public OrcItem setItemStack(ItemStack is) {
|
||||
Objects.requireNonNull(is, "ItemStack cannot be null");
|
||||
this.is = is;
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
is.setItemMeta(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public OrcItem setItemStack(Material mat, String display, String... lore) {
|
||||
return setItemStack(mat, display, Arrays.asList(lore));
|
||||
return setItemStack(mat, (byte) 0, display, Arrays.asList(lore));
|
||||
}
|
||||
|
||||
public OrcItem setDepend(DependListener listener) {
|
||||
|
55
WorldSystem/src/de/butzlabben/inventory/OrcListener.java
Normal file
55
WorldSystem/src/de/butzlabben/inventory/OrcListener.java
Normal file
@ -0,0 +1,55 @@
|
||||
package de.butzlabben.inventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
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 de.butzlabben.world.WorldSystem;
|
||||
|
||||
/**
|
||||
* @author Butzlabben
|
||||
* @since 10.06.2018
|
||||
*/
|
||||
public class OrcListener implements Listener {
|
||||
|
||||
private static OrcListener instance;
|
||||
|
||||
private HashMap<UUID, OrcInventory> invs = new HashMap<>();
|
||||
|
||||
public static synchronized OrcListener getInstance() {
|
||||
if (instance == null)
|
||||
instance = new OrcListener();
|
||||
return instance;
|
||||
}
|
||||
|
||||
private OrcListener() {
|
||||
Bukkit.getPluginManager().registerEvents(this, WorldSystem.getInstance());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void on(InventoryClickEvent e) {
|
||||
if (e.getClickedInventory() != null && invs.containsKey(e.getWhoClicked().getUniqueId())) {
|
||||
e.setCancelled(true);
|
||||
OrcItem item = invs.get(e.getWhoClicked().getUniqueId()).items.get(e.getSlot());
|
||||
if (item != null)
|
||||
item.onClick((Player) e.getWhoClicked(), invs.get(e.getWhoClicked().getUniqueId()));
|
||||
}
|
||||
}
|
||||
|
||||
public void register(UUID uuid, OrcInventory inv) {
|
||||
invs.put(uuid, inv);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void on(InventoryCloseEvent e) {
|
||||
if (e.getInventory() != null && invs.containsKey(e.getPlayer().getUniqueId())) {
|
||||
invs.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package de.butzlabben.inventory;
|
||||
|
||||
/**
|
||||
* @author Butzlabben
|
||||
* @since 20.04.2018
|
||||
*/
|
||||
public interface PageClickListener {
|
||||
|
||||
public int getPageAfter();
|
||||
public int getPageBefore();
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package de.butzlabben.inventory.pages;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import de.butzlabben.inventory.OrcInventory;
|
||||
import de.butzlabben.inventory.OrcItem;
|
||||
import de.butzlabben.world.config.GuiConfig;
|
||||
|
||||
/**
|
||||
* @author Butzlabben
|
||||
* @since 20.05.2018
|
||||
*/
|
||||
public class InventoryPage extends OrcInventory {
|
||||
|
||||
InventoryPage next, before = null;
|
||||
|
||||
public InventoryPage(String title, int page, int pages) {
|
||||
super(title, 6);
|
||||
|
||||
YamlConfiguration cfg = GuiConfig.getConfig();
|
||||
String path = "options.players.currentpage";
|
||||
|
||||
OrcItem oi = new OrcItem(GuiConfig.getMaterial(cfg, path), GuiConfig.getData(cfg, path),
|
||||
GuiConfig.getDisplay(cfg, path).replaceAll("%page", "" + page), GuiConfig.getLore(cfg, path));
|
||||
addItem(GuiConfig.getSlot(path), oi);
|
||||
|
||||
path = "options.players.pagebefore";
|
||||
oi = GuiConfig.getItem(path);
|
||||
oi.setOnClick((p, inv, item) -> {
|
||||
p.closeInventory();
|
||||
p.openInventory(this.before.getInventory(p));
|
||||
});
|
||||
addItem(GuiConfig.getSlot(path), oi);
|
||||
|
||||
path = "options.players.nextpage";
|
||||
oi = GuiConfig.getItem(path);
|
||||
oi.setOnClick((p, inv, item) -> {
|
||||
p.closeInventory();
|
||||
p.openInventory(this.next.getInventory(p));
|
||||
});
|
||||
addItem(GuiConfig.getSlot(path), oi);
|
||||
}
|
||||
|
||||
private int i = 0;
|
||||
|
||||
@Override
|
||||
public Inventory getInventory(Player p) {
|
||||
return super.getInventory(p);
|
||||
}
|
||||
|
||||
public void addItem(OrcItem item) {
|
||||
if (i > 36) {
|
||||
System.err.println("More items than allowed in page view");
|
||||
return;
|
||||
}
|
||||
addItem(i, item);
|
||||
i++;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void on(InventoryClickEvent e) {
|
||||
if (e.getClickedInventory() != null && e.getClickedInventory().getTitle() != null
|
||||
&& e.getClickedInventory().getTitle().equals(title)) {
|
||||
e.setCancelled(true);
|
||||
OrcItem item = items.get(e.getSlot());
|
||||
if (item != null)
|
||||
item.onClick((Player) e.getWhoClicked(), this);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package de.butzlabben.inventory.pages;
|
||||
|
||||
import de.butzlabben.inventory.OrcItem;
|
||||
|
||||
/**
|
||||
* @author Butzlabben
|
||||
* @since 21.05.2018
|
||||
*/
|
||||
public interface ItemConverter<T> {
|
||||
|
||||
public OrcItem convert(T element);
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package de.butzlabben.inventory.pages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.butzlabben.inventory.OrcItem;
|
||||
|
||||
/**
|
||||
* @author Butzlabben
|
||||
* @since 21.05.2018
|
||||
*/
|
||||
public class PageGUICreator<T> {
|
||||
|
||||
private final int elementsPerPage;
|
||||
private List<InventoryPage> invpages;
|
||||
|
||||
public void create(String title, Collection<T> elements, ItemConverter<T> converter) {
|
||||
List<OrcItem> items = elements.stream().map(r -> converter.convert(r)).collect(Collectors.toList());
|
||||
if (items == null || items.size() == 0)
|
||||
return;
|
||||
|
||||
int pages = (int) (Math.ceil((double) (items.size() / (double) elementsPerPage) < 1 ? 1 : Math.ceil((double) items.size() / (double) elementsPerPage)));
|
||||
|
||||
invpages = new ArrayList<>(pages);
|
||||
|
||||
for (int i = 1; i < pages + 1; i++) {
|
||||
int start = i == 1 ? 0 : elementsPerPage * (i - 1);
|
||||
int end = items.size() < elementsPerPage * i ? items.size() : elementsPerPage * i;
|
||||
List<OrcItem> page = items.subList(start, end);
|
||||
|
||||
InventoryPage invpage = new InventoryPage(title, i, pages);
|
||||
page.forEach(invpage::addItem);
|
||||
invpages.add(invpage);
|
||||
}
|
||||
|
||||
for (int i = 0; i < invpages.size(); i++) {
|
||||
|
||||
int beforeIndex = i == 0 ? invpages.size() - 1 : i - 1;
|
||||
int nextIndex = i == invpages.size() - 1 ? 0 : i + 1;
|
||||
|
||||
invpages.get(i).before = invpages.get(beforeIndex);
|
||||
invpages.get(i).next = invpages.get(nextIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public void show(Player p) {
|
||||
p.openInventory(invpages.get(0).getInventory(p));
|
||||
}
|
||||
|
||||
public PageGUICreator() {
|
||||
this(4 * 9);
|
||||
}
|
||||
|
||||
public List<InventoryPage> getInvPages() {
|
||||
return invpages;
|
||||
}
|
||||
|
||||
public PageGUICreator(int elementsPerPage) {
|
||||
this.elementsPerPage = elementsPerPage;
|
||||
}
|
||||
}
|
@ -40,6 +40,7 @@ public class GameProfileBuilder {
|
||||
.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create();
|
||||
private static HashMap<UUID, CachedProfile> cache = new HashMap<>();
|
||||
private static long cacheTime = -1L;
|
||||
private static Object sync = new Object();
|
||||
|
||||
public static GameProfile fetch(UUID uuid) throws IOException {
|
||||
return fetch(uuid, false);
|
||||
@ -49,10 +50,14 @@ public class GameProfileBuilder {
|
||||
if ((!forceNew) && (cache.containsKey(uuid)) && (((CachedProfile) cache.get(uuid)).isValid())) {
|
||||
return ((CachedProfile) cache.get(uuid)).profile;
|
||||
}
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(
|
||||
|
||||
HttpURLConnection connection;
|
||||
synchronized (sync) {
|
||||
connection = (HttpURLConnection) new URL(
|
||||
String.format("https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false",
|
||||
new Object[] { UUIDTypeAdapter.fromUUID(uuid) })).openConnection();
|
||||
connection.setReadTimeout(5000);
|
||||
}
|
||||
if (connection.getResponseCode() == 200) {
|
||||
String json = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
|
||||
|
||||
|
@ -13,7 +13,6 @@ import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import de.butzlabben.autoupdater.AutoUpdater;
|
||||
import de.butzlabben.inventory.OrcInventory;
|
||||
import de.butzlabben.world.command.WSAddmemberCommand;
|
||||
import de.butzlabben.world.command.WSCommand;
|
||||
import de.butzlabben.world.command.WSConfirmCommand;
|
||||
@ -37,9 +36,6 @@ import de.butzlabben.world.config.MessageConfig;
|
||||
import de.butzlabben.world.config.PluginConfig;
|
||||
import de.butzlabben.world.config.SettingsConfig;
|
||||
import de.butzlabben.world.gui.GuiCommand;
|
||||
import de.butzlabben.world.gui.PlayerOptionsGUI;
|
||||
import de.butzlabben.world.gui.WorldOptionsGUI;
|
||||
import de.butzlabben.world.gui.WorldSystemGUI;
|
||||
import de.butzlabben.world.listener.BlockListener;
|
||||
import de.butzlabben.world.listener.CommandListener;
|
||||
import de.butzlabben.world.listener.PlayerDeathListener;
|
||||
@ -59,7 +55,6 @@ public class WorldSystem extends JavaPlugin {
|
||||
public static HashMap<Player, World> deathLocations = new HashMap<>();
|
||||
|
||||
final private String version = this.getDescription().getVersion();
|
||||
public static OrcInventory mainGUI;
|
||||
|
||||
public static CreatorAdapter creator;
|
||||
|
||||
@ -126,8 +121,6 @@ public class WorldSystem extends JavaPlugin {
|
||||
|
||||
getCommand("ws gui").setExecutor(new GuiCommand());
|
||||
|
||||
mainGUI = new WorldSystemGUI();
|
||||
|
||||
System.setProperty("bstats.relocatecheck", "false");
|
||||
Metrics m = new Metrics(this);
|
||||
m.addCustomChart(new Metrics.SingleLineChart("worlds", Entry::entrys));
|
||||
@ -167,9 +160,7 @@ public class WorldSystem extends JavaPlugin {
|
||||
sw.directUnload(w);
|
||||
}
|
||||
}
|
||||
mainGUI.unregister();
|
||||
PlayerOptionsGUI.instance.unregister();
|
||||
WorldOptionsGUI.instance.unregister();
|
||||
|
||||
Bukkit.getConsoleSender()
|
||||
.sendMessage(PluginConfig.getPrefix() + "Succesfully disabled WorldSystem v" + version);
|
||||
}
|
||||
@ -222,7 +213,7 @@ public class WorldSystem extends JavaPlugin {
|
||||
return JavaPlugin.getPlugin(WorldSystem.class);
|
||||
}
|
||||
|
||||
public static boolean isIs1_13() {
|
||||
public static boolean is1_13() {
|
||||
return is1_13;
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class GuiConfig {
|
||||
if (file.exists() == false) {
|
||||
try {
|
||||
String guiFileResource;
|
||||
if (WorldSystem.isIs1_13()) {
|
||||
if (WorldSystem.is1_13()) {
|
||||
guiFileResource = "1_13_gui.yml";
|
||||
} else {
|
||||
guiFileResource = "old_gui.yml";
|
||||
@ -48,6 +48,7 @@ public class GuiConfig {
|
||||
OrcItem.enabled = getEnabled();
|
||||
OrcItem.disabled = getDisabled();
|
||||
OrcItem.coming_soon = getComingSoon();
|
||||
OrcItem.back = getBack();
|
||||
}
|
||||
|
||||
public static YamlConfiguration getConfig() {
|
||||
@ -95,6 +96,10 @@ public class GuiConfig {
|
||||
return (byte) cfg.getInt(path + ".data", 0);
|
||||
}
|
||||
|
||||
public static String getTitle(FileConfiguration cfg, String path) {
|
||||
return cfg.getString(path + ".title");
|
||||
}
|
||||
|
||||
public static Material getMaterial(FileConfiguration cfg, String path) {
|
||||
try {
|
||||
return Material.valueOf(cfg.getString(path + ".material").toUpperCase());
|
||||
@ -129,7 +134,11 @@ public class GuiConfig {
|
||||
return getItem("options.coming_soon");
|
||||
}
|
||||
|
||||
private static OrcItem getBack() {
|
||||
return getItem("options.back");
|
||||
}
|
||||
|
||||
public static Material getSkullItem() {
|
||||
return getMaterial(getConfig(), "options.players.skull_item");
|
||||
return getMaterial(getConfig(), "options.players.playerhead");
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.butzlabben.world.WorldSystem;
|
||||
import de.butzlabben.world.config.MessageConfig;
|
||||
import de.butzlabben.world.wrapper.WorldPlayer;
|
||||
|
||||
@ -18,7 +17,7 @@ public class GuiCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
WorldPlayer wp = new WorldPlayer((Player) sender);
|
||||
if(!wp.isOnSystemWorld()) {
|
||||
if (!wp.isOnSystemWorld()) {
|
||||
sender.sendMessage(MessageConfig.getNotOnWorld());
|
||||
return true;
|
||||
}
|
||||
@ -26,7 +25,7 @@ public class GuiCommand implements CommandExecutor {
|
||||
sender.sendMessage(MessageConfig.getNoPermission());
|
||||
return true;
|
||||
}
|
||||
((Player) sender).openInventory(WorldSystem.mainGUI.getInventory((Player) sender));
|
||||
((Player) sender).openInventory(new WorldSystemGUI().getInventory((Player) sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
package de.butzlabben.world.gui;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import de.butzlabben.inventory.DependListener;
|
||||
import de.butzlabben.inventory.OrcInventory;
|
||||
@ -19,26 +18,28 @@ import de.butzlabben.world.wrapper.WorldPlayer;
|
||||
|
||||
public class PlayerOptionsGUI extends OrcInventory {
|
||||
|
||||
public static PlayerOptionsGUI instance;
|
||||
|
||||
private final static String path = "options.player.";
|
||||
|
||||
public final static HashMap<UUID, String> data = new HashMap<>();
|
||||
|
||||
public PlayerOptionsGUI() {
|
||||
super("Player Options", GuiConfig.getRows("options.player"), true);
|
||||
loadItem("build", "/ws togglebuild %data", new BuildStatus());
|
||||
loadItem("gamemode", "/ws togglegm %data", new GamemodeStatus());
|
||||
loadItem("teleport", "/ws toggletp %data", new TeleportStatus());
|
||||
public PlayerOptionsGUI(Player loader, String otherPlayer, UUID other) {
|
||||
super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.player").replace("%player", otherPlayer), GuiConfig.getRows("options.player"));
|
||||
WorldPlayer wp = new WorldPlayer(Bukkit.getOfflinePlayer(other), loader.getWorld().getName());
|
||||
loadItem("build", "/ws togglebuild " + otherPlayer, new BuildStatus(wp));
|
||||
loadItem("gamemode", "/ws togglegm " + otherPlayer, new GamemodeStatus(wp));
|
||||
loadItem("teleport", "/ws toggletp " + otherPlayer, new TeleportStatus(wp));
|
||||
loadItem("time");
|
||||
loadItem("addmember");
|
||||
loadItem("delmember");
|
||||
loadItem("worldborder");
|
||||
loadItem("setpermissions");
|
||||
loadItem("administrateworld");
|
||||
if (instance != null)
|
||||
instance.unregister();
|
||||
instance = this;
|
||||
|
||||
if (GuiConfig.isEnabled(path + "back")) {
|
||||
OrcItem back = OrcItem.back.clone();
|
||||
back.setOnClick((p, inv, i) -> {
|
||||
p.closeInventory();
|
||||
PlayersPageGUI.openGUI(p);
|
||||
});
|
||||
addItem(GuiConfig.getSlot(path + "back"), back);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadItem(String subpath, String message, DependListener depend) {
|
||||
@ -67,23 +68,4 @@ public class PlayerOptionsGUI extends OrcInventory {
|
||||
public void loadItem(String subpath) {
|
||||
loadItem(subpath, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory(Player p, String title) {
|
||||
if (data.containsKey(p.getUniqueId()))
|
||||
return super.getInventory(p, title.replaceAll("%data", data.get(p.getUniqueId())));
|
||||
return super.getInventory(p, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory(Player p) {
|
||||
if (data.containsKey(p.getUniqueId()))
|
||||
return super.getInventory(p, getTitle().replaceAll("%data", data.get(p.getUniqueId())));
|
||||
return super.getInventory(p, getTitle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOpen(Player p) {
|
||||
return new WorldPlayer(p).isOwnerofWorld();
|
||||
}
|
||||
}
|
||||
|
@ -1,70 +0,0 @@
|
||||
package de.butzlabben.world.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.butzlabben.world.config.GuiConfig;
|
||||
import de.butzlabben.world.config.WorldConfig;
|
||||
import de.butzlabben.world.wrapper.SystemWorld;
|
||||
|
||||
/**
|
||||
* @author Butzlabben
|
||||
* @since 20.04.2018
|
||||
*/
|
||||
public class PlayersGUIManager {
|
||||
|
||||
private static final int headsPerInv = GuiConfig.getConfig().getInt("options.players.player_list_to_row") * 9;
|
||||
|
||||
private PlayersGUIManager() {
|
||||
}
|
||||
|
||||
public static PlayersPageGUI getFirstPage(Player p) {
|
||||
return getPage(p, 1);
|
||||
}
|
||||
|
||||
public static PlayersPageGUI getPage(Player p, int page) {
|
||||
String worldname = p.getWorld().getName();
|
||||
SystemWorld sw = SystemWorld.getSystemWorld(worldname);
|
||||
if (sw != null) {
|
||||
HashMap<UUID, String> members = WorldConfig.getWorldConfig(worldname).getMembersWithNames();
|
||||
if (members == null || members.size() == 0)
|
||||
return null;
|
||||
int pages = Math.round(members.size() / headsPerInv) < 1 ? 1 : Math.round(members.size() / headsPerInv);
|
||||
if (page > pages)
|
||||
return null;
|
||||
return getPage(p, page, pages);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PlayersPageGUI getPage(Player p, int page, int pages) {
|
||||
String worldname = p.getWorld().getName();
|
||||
SystemWorld sw = SystemWorld.getSystemWorld(worldname);
|
||||
if (sw != null) {
|
||||
HashMap<UUID, String> members = WorldConfig.getWorldConfig(worldname).getMembersWithNames();
|
||||
if (members == null || members.size() == 0)
|
||||
return null;
|
||||
|
||||
|
||||
|
||||
int startPos = pages == 1 ? 0 : headsPerInv * (page - 1);
|
||||
int length = pages == 1 ? members.size() : headsPerInv;
|
||||
|
||||
ArrayList<UUID> list = new ArrayList<>(members.keySet());
|
||||
HashMap<UUID, String> uuids = new HashMap<>();
|
||||
for (int i = startPos; i < startPos + length; i++) {
|
||||
uuids.put(list.get(i), members.get(list.get(i)));
|
||||
}
|
||||
|
||||
int pageBefore = page == 1 ? pages : page - 1;
|
||||
int nextPage = pages == page ? 1 : page + 1;
|
||||
|
||||
PlayersPageGUI ppg = new PlayersPageGUI(page, p.getUniqueId(), uuids, nextPage, pageBefore);
|
||||
return ppg;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,125 +1,91 @@
|
||||
package de.butzlabben.world.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import de.butzlabben.inventory.OrcClickListener;
|
||||
import de.butzlabben.inventory.OrcInventory;
|
||||
import de.butzlabben.inventory.OrcItem;
|
||||
import de.butzlabben.inventory.pages.PageGUICreator;
|
||||
import de.butzlabben.world.config.GuiConfig;
|
||||
import de.butzlabben.world.wrapper.WorldPlayer;
|
||||
import de.butzlabben.world.config.MessageConfig;
|
||||
import de.butzlabben.world.config.WorldConfig;
|
||||
|
||||
/**
|
||||
* @author Butzlabben
|
||||
* @since 20.04.2018
|
||||
*/
|
||||
public class PlayersPageGUI extends OrcInventory {
|
||||
|
||||
private final static String path = "options.players.";
|
||||
private static HashMap<UUID, Pair<Integer, Integer>> pages = new HashMap<>();
|
||||
public class PlayersPageGUI {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public PlayersPageGUI(int page, UUID ex, HashMap<UUID, String> players, int next, int before) {
|
||||
super("Players added to this world", GuiConfig.getRows("options.players"), false);
|
||||
pages.put(ex, Pair.of(next, before));
|
||||
public static void openGUI(Player p) {
|
||||
WorldConfig config = WorldConfig.getWorldConfig(p.getWorld().getName());
|
||||
|
||||
loadItem("nextpage", (p, inv, orcitem) -> {
|
||||
p.closeInventory();
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
p.closeInventory();
|
||||
HashMap<UUID, String> members = config.getMembersWithNames();
|
||||
|
||||
inv.unregister();
|
||||
int nextPage = pages.get(p.getUniqueId()).getLeft();
|
||||
pages.remove(p.getUniqueId());
|
||||
|
||||
p.openInventory(PlayersGUIManager.getPage(p, nextPage).getInventory(p));
|
||||
if (members.size() == 0) {
|
||||
p.sendMessage(MessageConfig.getNoMemberAdded());
|
||||
return;
|
||||
}
|
||||
}.run();
|
||||
|
||||
PageGUICreator<Entry<UUID, String>> creator = new PageGUICreator<>(GuiConfig.getRows("options.players"));
|
||||
|
||||
creator.create(GuiConfig.getTitle(GuiConfig.getConfig(), "options.players"), members.entrySet(), (entry) -> {
|
||||
String name = entry.getValue();
|
||||
OrcItem oi = new OrcItem(GuiConfig.getSkullItem(), GuiConfig
|
||||
.getDisplay(GuiConfig.getConfig(), "options.players.playerhead").replaceAll("%player", name));
|
||||
SkullMeta sm = (SkullMeta) oi.getItemStack().getItemMeta();
|
||||
sm.setOwner(name);
|
||||
oi.getItemStack().setItemMeta(sm);
|
||||
oi.setOnClick((player, inv, item) -> {
|
||||
player.closeInventory();
|
||||
PlayerOptionsGUI gui = new PlayerOptionsGUI(player, name, entry.getKey());
|
||||
player.openInventory(gui.getInventory(p));
|
||||
});
|
||||
return oi;
|
||||
});
|
||||
|
||||
loadItem("pagebefore", (p, inv, orcitem) -> {
|
||||
p.closeInventory();
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
p.closeInventory();
|
||||
int pageBefore = pages.get(p.getUniqueId()).getRight();
|
||||
pages.remove(p.getUniqueId());
|
||||
inv.unregister();
|
||||
p.openInventory(PlayersGUIManager.getPage(p, pageBefore).getInventory(p));
|
||||
}
|
||||
}.run();
|
||||
if (GuiConfig.isEnabled("options.players.back")) {
|
||||
OrcItem back = OrcItem.back.clone();
|
||||
back.setOnClick((player, inv, i) -> {
|
||||
player.closeInventory();
|
||||
player.openInventory(new WorldSystemGUI().getInventory(p));
|
||||
});
|
||||
|
||||
String subpath = "currentpage";
|
||||
String path = PlayersPageGUI.path + subpath;
|
||||
YamlConfiguration cfg = GuiConfig.getConfig();
|
||||
OrcItem oi = null;
|
||||
try {
|
||||
oi = new OrcItem(GuiConfig.getMaterial(cfg, path), GuiConfig.getData(cfg, path),
|
||||
GuiConfig.getDisplay(cfg, path).replaceAll("%page", "" + page), GuiConfig.getLore(cfg, path));
|
||||
} catch (Exception e) {
|
||||
creator.getInvPages().forEach((oi) -> {oi.addItem(GuiConfig.getSlot("options.players.back"), back);});
|
||||
}
|
||||
try {
|
||||
oi = new OrcItem(GuiConfig.getMaterial(cfg, path),
|
||||
GuiConfig.getDisplay(cfg, path).replaceAll("%page", "" + page), GuiConfig.getLore(cfg, path));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
addItem(GuiConfig.getSlot(path), oi);
|
||||
|
||||
// Load players
|
||||
int i = 0;
|
||||
for (UUID uuid : players.keySet()) {
|
||||
String name = players.get(uuid);
|
||||
Material skullItem = GuiConfig.getSkullItem();
|
||||
ItemStack is = new ItemStack(skullItem, 1, (short) 3);
|
||||
creator.show(p);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void preloadPlayers(WorldConfig config) {
|
||||
new Thread(() -> {
|
||||
int headsPerInv = GuiConfig.getRows("options.players") * 9;
|
||||
HashMap<UUID, String> members = config.getMembersWithNames();
|
||||
if (members == null || members.size() == 0)
|
||||
return;
|
||||
int pages = Math.round(members.size() / headsPerInv) < 1 ? 1 : Math.round(members.size() / headsPerInv);
|
||||
for (int page = 0; page < pages; page++) {
|
||||
int startPos = pages == 1 ? 0 : headsPerInv * (page - 1);
|
||||
int length = pages == 1 ? members.size() : headsPerInv;
|
||||
|
||||
ArrayList<UUID> list = new ArrayList<>(members.keySet());
|
||||
|
||||
Inventory inv = Bukkit.createInventory(null, headsPerInv);
|
||||
for (int i = startPos; i < startPos + length; i++) {
|
||||
String name = members.get(list.get(i));
|
||||
ItemStack is = new ItemStack(GuiConfig.getSkullItem(), 1, (short) 3);
|
||||
SkullMeta sm = (SkullMeta) is.getItemMeta();
|
||||
sm.setOwner(name);
|
||||
sm.setDisplayName(
|
||||
GuiConfig.getDisplay(cfg, PlayersPageGUI.path + "playerhead").replaceAll("%player", name));
|
||||
is.setItemMeta(sm);
|
||||
OrcItem item = new OrcItem(is);
|
||||
item.setOnClick((p, inv, orcitem) -> {
|
||||
p.closeInventory();
|
||||
PlayerOptionsGUI.data.put(ex, name);
|
||||
pages.remove(p.getUniqueId());
|
||||
p.openInventory(PlayerOptionsGUI.instance.getInventory(p));
|
||||
});
|
||||
addItem(i, item);
|
||||
i++;
|
||||
|
||||
inv.addItem(is);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadItem(String subpath, OrcClickListener depend) {
|
||||
if (GuiConfig.isEnabled(path + subpath) == false)
|
||||
return;
|
||||
OrcItem item = GuiConfig.getItem(path + subpath);
|
||||
if (item != null) {
|
||||
|
||||
item.setOnClick(depend);
|
||||
|
||||
addItem(GuiConfig.getSlot(path + subpath), item);
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
public void loadItem(String subpath) {
|
||||
loadItem(subpath, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOpen(Player p) {
|
||||
return new WorldPlayer(p).isOwnerofWorld();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,18 +21,16 @@ public class WorldOptionsGUI extends OrcInventory {
|
||||
private final static String path = "options.world.";
|
||||
|
||||
public final static HashMap<UUID, String> data = new HashMap<>();
|
||||
public static WorldOptionsGUI instance;
|
||||
|
||||
public WorldOptionsGUI() {
|
||||
super("World Options", GuiConfig.getRows("options.world"), true);
|
||||
if (instance != null)
|
||||
return;
|
||||
super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.world"), GuiConfig.getRows("options.world"));
|
||||
|
||||
loadItem("fire", "/ws fire", true, new FireStatus());
|
||||
loadItem("tnt", "/ws tnt", true, new TntStatus());
|
||||
|
||||
if (GuiConfig.isEnabled(path + "reset") == false)
|
||||
return;
|
||||
|
||||
OrcItem item = GuiConfig.getItem(path + "reset");
|
||||
if (item != null) {
|
||||
item.setOnClick((p, inv, i) -> {
|
||||
@ -42,7 +40,14 @@ public class WorldOptionsGUI extends OrcInventory {
|
||||
addItem(GuiConfig.getSlot(path + "reset"), item);
|
||||
}
|
||||
|
||||
instance = this;
|
||||
if (GuiConfig.isEnabled(path + "back")) {
|
||||
OrcItem back = OrcItem.back.clone();
|
||||
back.setOnClick((p, inv, i) -> {
|
||||
p.closeInventory();
|
||||
p.openInventory(new WorldSystemGUI().getInventory(p));
|
||||
});
|
||||
addItem(GuiConfig.getSlot(path + "back"), back);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadItem(String subpath, String message, boolean state, DependListener depend) {
|
||||
@ -88,7 +93,6 @@ public class WorldOptionsGUI extends OrcInventory {
|
||||
return super.getInventory(p, getTitle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOpen(Player p) {
|
||||
return new WorldPlayer(p).isOwnerofWorld();
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package de.butzlabben.world.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import de.butzlabben.inventory.OrcClickListener;
|
||||
import de.butzlabben.inventory.OrcInventory;
|
||||
import de.butzlabben.inventory.OrcItem;
|
||||
import de.butzlabben.world.config.GuiConfig;
|
||||
import de.butzlabben.world.config.MessageConfig;
|
||||
import de.butzlabben.world.config.WorldConfig;
|
||||
import de.butzlabben.world.gui.clicklistener.InventoryOpenClickListener;
|
||||
|
||||
public class WorldSystemGUI extends OrcInventory {
|
||||
@ -14,19 +15,29 @@ public class WorldSystemGUI extends OrcInventory {
|
||||
private final static String path = "worldsystem.";
|
||||
|
||||
public WorldSystemGUI() {
|
||||
super("WorldSystem", GuiConfig.getRows("worldsystem"), true);
|
||||
new WorldOptionsGUI();
|
||||
new PlayerOptionsGUI();
|
||||
|
||||
super(GuiConfig.getTitle(GuiConfig.getConfig(), "worldsystem"), GuiConfig.getRows("worldsystem"));
|
||||
|
||||
loadItem("playeroptions", (p, inv, item) -> {
|
||||
p.closeInventory();
|
||||
PlayersPageGUI ppg = PlayersGUIManager.getFirstPage(p);
|
||||
if (ppg != null)
|
||||
p.openInventory(ppg.getInventory(p));
|
||||
else
|
||||
p.sendMessage(MessageConfig.getNoMemberAdded());
|
||||
PlayersPageGUI.openGUI(p);
|
||||
});
|
||||
loadItem("worldoptions", new InventoryOpenClickListener(WorldOptionsGUI.instance));
|
||||
|
||||
loadItem("worldoptions", new InventoryOpenClickListener(new WorldOptionsGUI()));
|
||||
|
||||
if (GuiConfig.isEnabled(path + "back")) {
|
||||
OrcItem back = OrcItem.back.clone();
|
||||
back.setOnClick((p, inv, item) -> {
|
||||
p.closeInventory();
|
||||
});
|
||||
addItem(GuiConfig.getSlot(path + "back"), back);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory(Player player) {
|
||||
PlayersPageGUI.preloadPlayers(WorldConfig.getWorldConfig(player.getWorld().getName()));
|
||||
return super.getInventory(player);
|
||||
}
|
||||
|
||||
public void loadItem(String subpath, OrcClickListener listener) {
|
||||
@ -43,9 +54,7 @@ public class WorldSystemGUI extends OrcInventory {
|
||||
loadItem(subpath, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOpen(Player p) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import org.bukkit.entity.Player;
|
||||
import de.butzlabben.inventory.OrcClickListener;
|
||||
import de.butzlabben.inventory.OrcInventory;
|
||||
import de.butzlabben.inventory.OrcItem;
|
||||
import de.butzlabben.world.gui.PlayerOptionsGUI;
|
||||
|
||||
public class CommandExecutorClickListener implements OrcClickListener {
|
||||
|
||||
@ -19,8 +18,7 @@ public class CommandExecutorClickListener implements OrcClickListener {
|
||||
public void onClick(Player p, OrcInventory inv, OrcItem item) {
|
||||
p.closeInventory();
|
||||
String msg = message;
|
||||
if(PlayerOptionsGUI.data.containsKey(p.getUniqueId()))
|
||||
msg = message.replaceAll("%data", PlayerOptionsGUI.data.get(p.getUniqueId()));
|
||||
p.chat(msg);
|
||||
inv.redraw(p);
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ public class InventoryOpenClickListener implements OrcClickListener {
|
||||
|
||||
@Override
|
||||
public void onClick(Player p, OrcInventory inv, OrcItem item) {
|
||||
if (open == null) {
|
||||
p.closeInventory();
|
||||
if (open == null) {
|
||||
return;
|
||||
}
|
||||
Inventory to = open.getInventory(p);
|
||||
|
@ -1,20 +1,22 @@
|
||||
package de.butzlabben.world.gui.playeroption;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import de.butzlabben.inventory.DependListener;
|
||||
import de.butzlabben.inventory.OrcItem;
|
||||
import de.butzlabben.world.gui.PlayerOptionsGUI;
|
||||
import de.butzlabben.world.wrapper.WorldPlayer;
|
||||
|
||||
public class BuildStatus implements DependListener {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private final WorldPlayer wp;
|
||||
|
||||
public BuildStatus(WorldPlayer wp) {
|
||||
this.wp = wp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack(Player p, WorldPlayer wp) {
|
||||
wp = new WorldPlayer(Bukkit.getOfflinePlayer(PlayerOptionsGUI.data.get(p.getUniqueId())), p.getWorld().getName());
|
||||
return wp.canBuild() ? OrcItem.enabled.getItemStack(p, wp) : null;
|
||||
public ItemStack getItemStack(Player p, WorldPlayer player) {
|
||||
return wp.canBuild() ? OrcItem.enabled.getItemStack(p, wp) : OrcItem.disabled.getItemStack(p, wp);
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,22 @@
|
||||
package de.butzlabben.world.gui.playeroption;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import de.butzlabben.inventory.DependListener;
|
||||
import de.butzlabben.inventory.OrcItem;
|
||||
import de.butzlabben.world.gui.PlayerOptionsGUI;
|
||||
import de.butzlabben.world.wrapper.WorldPlayer;
|
||||
|
||||
public class GamemodeStatus implements DependListener {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private final WorldPlayer wp;
|
||||
|
||||
public GamemodeStatus(WorldPlayer wp) {
|
||||
this.wp = wp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack(Player p, WorldPlayer wp) {
|
||||
wp = new WorldPlayer(Bukkit.getOfflinePlayer(PlayerOptionsGUI.data.get(p.getUniqueId())), p.getWorld().getName());
|
||||
return wp.canChangeGamemode() ? OrcItem.enabled.getItemStack(p, wp) : null;
|
||||
public ItemStack getItemStack(Player p, WorldPlayer player) {
|
||||
return wp.canChangeGamemode() ? OrcItem.enabled.getItemStack(p, wp) : OrcItem.disabled.getItemStack(p, wp);
|
||||
}
|
||||
}
|
@ -1,20 +1,22 @@
|
||||
package de.butzlabben.world.gui.playeroption;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import de.butzlabben.inventory.DependListener;
|
||||
import de.butzlabben.inventory.OrcItem;
|
||||
import de.butzlabben.world.gui.PlayerOptionsGUI;
|
||||
import de.butzlabben.world.wrapper.WorldPlayer;
|
||||
|
||||
public class TeleportStatus implements DependListener {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private final WorldPlayer wp;
|
||||
|
||||
public TeleportStatus(WorldPlayer wp) {
|
||||
this.wp = wp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack(Player p, WorldPlayer wp) {
|
||||
wp = new WorldPlayer(Bukkit.getOfflinePlayer(PlayerOptionsGUI.data.get(p.getUniqueId())), p.getWorld().getName());
|
||||
return wp.canTeleport() ? OrcItem.enabled.getItemStack(p, wp) : null;
|
||||
public ItemStack getItemStack(Player p, WorldPlayer player) {
|
||||
return wp.canTeleport() ? OrcItem.enabled.getItemStack(p, wp) : OrcItem.disabled.getItemStack(p, wp);
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ public class FireStatus implements DependListener {
|
||||
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
|
||||
boolean b = cfg.getBoolean("Settings.Fire");
|
||||
if (b)
|
||||
return OrcItem.enabled.getItemStack(p, wp);
|
||||
return OrcItem.enabled.getItemStack(p);
|
||||
|
||||
return null;
|
||||
// TODO wenn enabled, dann return OrcItem.enabled.getItemStack(p, wp);
|
||||
|
@ -25,7 +25,7 @@ public class TntStatus implements DependListener {
|
||||
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
|
||||
boolean b = cfg.getBoolean("Settings.TNTDamage");
|
||||
if (b)
|
||||
return OrcItem.enabled.getItemStack(p, wp);
|
||||
return OrcItem.enabled.getItemStack(p);
|
||||
|
||||
return null;
|
||||
// TODO wenn enabled, dann return OrcItem.enabled.getItemStack(p, wp);
|
||||
|
@ -25,10 +25,26 @@ options:
|
||||
data: 14
|
||||
display: '&6Coming soon...'
|
||||
|
||||
# How the back item should look like
|
||||
back:
|
||||
material: BARRIER
|
||||
display: '&cBack'
|
||||
|
||||
# WorldoptionsGUI
|
||||
world:
|
||||
# What the title of the Inv should be
|
||||
title: 'World Options'
|
||||
|
||||
# Rows
|
||||
rows: 2
|
||||
rows: 3
|
||||
|
||||
# Where the back item should be
|
||||
back:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 3
|
||||
col: 5
|
||||
|
||||
# Reset button
|
||||
reset:
|
||||
# If feature should be enabled or not
|
||||
@ -66,38 +82,54 @@ options:
|
||||
display: '&eToggle TNT-Explosion'
|
||||
|
||||
players:
|
||||
skull_item:
|
||||
material: SKULL_ITEM
|
||||
title: 'Players added to this world'
|
||||
|
||||
back:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 6
|
||||
col: 6
|
||||
|
||||
rows: 6
|
||||
|
||||
nextpage:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 6
|
||||
col: 9
|
||||
col: 8
|
||||
material: PAPER
|
||||
display: '&eNext Page'
|
||||
pagebefore:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 6
|
||||
col: 1
|
||||
col: 2
|
||||
material: PAPER
|
||||
display: '&ePage before'
|
||||
currentpage:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 6
|
||||
col: 5
|
||||
col: 4
|
||||
material: DOUBLE_PLANT
|
||||
display: '&eCurrent page: &a%page'
|
||||
player_list_to_row: 4
|
||||
playerhead:
|
||||
material: SKULL_ITEM
|
||||
display: '&e%player'
|
||||
|
||||
# PlayerGUI for managing one player on a world
|
||||
player:
|
||||
rows: 2
|
||||
title: 'Player options for %player'
|
||||
|
||||
back:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 3
|
||||
col: 5
|
||||
|
||||
rows: 3
|
||||
|
||||
build:
|
||||
enabled: true
|
||||
slot:
|
||||
@ -205,18 +237,27 @@ options:
|
||||
|
||||
# WorldsystemGUI
|
||||
worldsystem:
|
||||
title: 'WorldSystem'
|
||||
|
||||
rows: 1
|
||||
|
||||
back:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 1
|
||||
col: 5
|
||||
|
||||
playeroptions:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 1
|
||||
col: 4
|
||||
col: 1
|
||||
material: LEATHER_HELMET
|
||||
display: '&ePlayer Options'
|
||||
worldoptions:
|
||||
enabled: true
|
||||
slot:
|
||||
row: 1
|
||||
col: 6
|
||||
col: 9
|
||||
material: GRASS
|
||||
display: '&eWorld Options'
|
@ -1,5 +1,5 @@
|
||||
name: WorldSystem
|
||||
version: 2.3.0
|
||||
version: 2.3.1
|
||||
author: Butzlabben
|
||||
main: de.butzlabben.world.WorldSystem
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user