mirror of
https://github.com/songoda/EpicBuckets.git
synced 2024-11-13 05:45:16 +01:00
Added an Active Genbuckets Panel
This commit is contained in:
parent
f1d0399e3a
commit
e966fb519d
6
pom.xml
6
pom.xml
@ -89,6 +89,12 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>fr.minuskube.inv</groupId>
|
||||
<artifactId>smart-invs</artifactId>
|
||||
<version>1.2.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>co.aikar</groupId>
|
||||
<artifactId>acf-paper</artifactId>
|
||||
|
@ -8,14 +8,15 @@ import com.songoda.epicbuckets.listener.GenbucketPlaceListener;
|
||||
import com.songoda.epicbuckets.shop.ShopManager;
|
||||
import com.songoda.epicbuckets.util.ChatUtil;
|
||||
import com.songoda.epicbuckets.util.Debugger;
|
||||
import fr.minuskube.inv.InventoryManager;
|
||||
import me.lucko.helper.plugin.ExtendedJavaPlugin;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class EpicBuckets extends JavaPlugin {
|
||||
public class EpicBuckets extends ExtendedJavaPlugin {
|
||||
|
||||
private static EpicBuckets instance;
|
||||
private static CommandSender console = Bukkit.getConsoleSender();
|
||||
@ -26,13 +27,14 @@ public class EpicBuckets extends JavaPlugin {
|
||||
private GenbucketManager genbucketManager;
|
||||
private Economy econ;
|
||||
private PaperCommandManager commandManager;
|
||||
private InventoryManager inventoryManager;
|
||||
|
||||
private Locale locale;
|
||||
|
||||
public static EpicBuckets getInstance() { return instance; }
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
protected void enable() {
|
||||
console.sendMessage(ChatUtil.colorString("&a============================="));
|
||||
console.sendMessage(ChatUtil.colorString("&7EpicBuckets " + this.getDescription().getVersion() + " by &5Songoda <3!"));
|
||||
console.sendMessage(ChatUtil.colorString("&7Action: &aEnabling&7..."));
|
||||
@ -53,6 +55,9 @@ public class EpicBuckets extends JavaPlugin {
|
||||
genbucketManager = new GenbucketManager();
|
||||
commandManager = new PaperCommandManager(this);
|
||||
|
||||
inventoryManager = new InventoryManager(this);
|
||||
inventoryManager.init();
|
||||
|
||||
commandManager.registerCommand(new CommandGenbucket());
|
||||
|
||||
getServer().getPluginManager().registerEvents(new GenbucketPlaceListener(), this);
|
||||
@ -63,7 +68,7 @@ public class EpicBuckets extends JavaPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
protected void disable() {
|
||||
console.sendMessage(ChatUtil.colorString("&a============================="));
|
||||
console.sendMessage(ChatUtil.colorString("&7EpicBuckets " + this.getDescription().getVersion() + " by &5Songoda <3!"));
|
||||
console.sendMessage(ChatUtil.colorString("&7Action: &cDisabling&7..."));
|
||||
@ -116,6 +121,10 @@ public class EpicBuckets extends JavaPlugin {
|
||||
return genbucketManager;
|
||||
}
|
||||
|
||||
public InventoryManager getInventoryManager() {
|
||||
return inventoryManager;
|
||||
}
|
||||
|
||||
public Economy getEcon() {
|
||||
return econ;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import com.songoda.epicbuckets.EpicBuckets;
|
||||
import com.songoda.epicbuckets.gui.GUIMain;
|
||||
import com.songoda.epicbuckets.gui.GUIPanel;
|
||||
import com.songoda.epicbuckets.util.ChatUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -41,9 +42,17 @@ public class CommandGenbucket extends BaseCommand {
|
||||
player.sendMessage(ChatUtil.colorPrefix(epicBuckets.getLocale().getMessage("command.reload.success")));
|
||||
}
|
||||
|
||||
@Subcommand("admin toggle")
|
||||
@Description("Toggles your admin status to receive genbucket placement notifications")
|
||||
public void admin(Player player) {
|
||||
if (!permCheck(player, "genbucket.admin") || !permCheck(player, "genbucket.admin.toggle")) return;
|
||||
epicBuckets.getGenbucketManager().toggleAdmin(player);
|
||||
}
|
||||
|
||||
@Subcommand("admin panel")
|
||||
public void panel(Player player) {
|
||||
if (!permCheck(player, "genbucket.admin") || !permCheck(player, "genbucket.admin.panel")) return;
|
||||
GUIPanel.PANEL.open(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.songoda.epicbuckets.genbucket;
|
||||
import com.songoda.epicbuckets.EpicBuckets;
|
||||
import com.songoda.epicbuckets.shop.SubShop;
|
||||
import com.songoda.epicbuckets.util.XMaterial;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -20,6 +21,7 @@ public abstract class Genbucket {
|
||||
private Block currentBlock;
|
||||
private SubShop subShop;
|
||||
private UUID genUUID;
|
||||
private Location playerLocation;
|
||||
|
||||
public Genbucket(GenbucketType genbucketType, Block clickedBlock, BlockFace blockFace, SubShop s, Player owner) {
|
||||
epicBuckets = EpicBuckets.getInstance();
|
||||
@ -30,6 +32,7 @@ public abstract class Genbucket {
|
||||
this.clickedBlock = clickedBlock;
|
||||
this.currentBlock = clickedBlock;
|
||||
this.subShop = s;
|
||||
this.playerLocation = owner.getLocation();
|
||||
}
|
||||
|
||||
public abstract void generate();
|
||||
@ -38,6 +41,14 @@ public abstract class Genbucket {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public Location getPlayerLocation() {
|
||||
return playerLocation;
|
||||
}
|
||||
|
||||
public Location getClickedLocation() {
|
||||
return clickedBlock.getLocation();
|
||||
}
|
||||
|
||||
public UUID getGenUUID() {
|
||||
return genUUID;
|
||||
}
|
||||
|
@ -31,10 +31,11 @@ public class GenbucketManager {
|
||||
public void toggleAdmin(Player player) {
|
||||
if (admins.contains(player)) {
|
||||
removeAdmin(player);
|
||||
player.sendMessage(ChatUtil.colorPrefix(epicBuckets.getLocale().getMessage("command.admin.toggle").replace("%mode%", "&cdisabled")));
|
||||
return;
|
||||
}
|
||||
addAdmin(player);
|
||||
player.sendMessage(ChatUtil.colorPrefix(epicBuckets.getLocale().getMessage("command.admin.toggle").replace("%mode%", ((admins.contains(player)) ? "&aenabled" : "&cdisabled"))));
|
||||
player.sendMessage(ChatUtil.colorPrefix(epicBuckets.getLocale().getMessage("command.admin.toggle").replace("%mode%", "&aenabled")));
|
||||
}
|
||||
|
||||
private void removeAdmin(Player player) {
|
||||
@ -45,6 +46,20 @@ public class GenbucketManager {
|
||||
admins.add(player);
|
||||
}
|
||||
|
||||
public List<Genbucket> activeGensInOneList() {
|
||||
List<Genbucket> gens = new ArrayList<>();
|
||||
activeGens.forEach((uuid, genbuckets) -> gens.addAll(genbuckets));
|
||||
return gens;
|
||||
}
|
||||
|
||||
public int getTotalActiveGenbuckets(HashMap<UUID, List<Genbucket>> gens) {
|
||||
int total = 0;
|
||||
for (UUID uuid : gens.keySet()) {
|
||||
total += gens.get(uuid).size();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public void unregisterGenbucketForPlayer(Player owner, UUID genUUID) {
|
||||
List<Genbucket> genbuckets = activeGens.get(owner.getUniqueId());
|
||||
List<Genbucket> newGenbuckets = new ArrayList<>();
|
||||
@ -88,4 +103,7 @@ public class GenbucketManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
public HashMap<UUID, List<Genbucket>> getActiveGens() {
|
||||
return activeGens;
|
||||
}
|
||||
}
|
||||
|
67
src/main/java/com/songoda/epicbuckets/gui/GUIPanel.java
Normal file
67
src/main/java/com/songoda/epicbuckets/gui/GUIPanel.java
Normal file
@ -0,0 +1,67 @@
|
||||
package com.songoda.epicbuckets.gui;
|
||||
|
||||
import com.songoda.epicbuckets.EpicBuckets;
|
||||
import com.songoda.epicbuckets.genbucket.Genbucket;
|
||||
import com.songoda.epicbuckets.util.ChatUtil;
|
||||
import com.songoda.epicbuckets.util.XMaterial;
|
||||
import fr.minuskube.inv.ClickableItem;
|
||||
import fr.minuskube.inv.SmartInventory;
|
||||
import fr.minuskube.inv.content.InventoryContents;
|
||||
import fr.minuskube.inv.content.InventoryProvider;
|
||||
import fr.minuskube.inv.content.Pagination;
|
||||
import fr.minuskube.inv.content.SlotIterator;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.SkullType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class GUIPanel implements InventoryProvider {
|
||||
|
||||
private EpicBuckets epicBuckets = EpicBuckets.getInstance();
|
||||
|
||||
public static final SmartInventory PANEL = SmartInventory.builder()
|
||||
.id("GUIPanel")
|
||||
.provider(new GUIPanel())
|
||||
.size(6, 9)
|
||||
.title("Active Genbuckets")
|
||||
.manager(EpicBuckets.getInstance().getInventoryManager())
|
||||
.build();
|
||||
|
||||
|
||||
@Override
|
||||
public void init(Player player, InventoryContents inventoryContents) {
|
||||
HashMap<UUID, List<Genbucket>> gens = epicBuckets.getGenbucketManager().getActiveGens();
|
||||
List<ClickableItem> itemList = new ArrayList<>();
|
||||
|
||||
Pagination pagination = inventoryContents.pagination();
|
||||
|
||||
for (UUID uuid : gens.keySet()) {
|
||||
if (gens.get(uuid).size() < 1) continue;
|
||||
for (Genbucket genbucket : gens.get(uuid)) {
|
||||
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
|
||||
SkullMeta meta = (SkullMeta) skull.getItemMeta();
|
||||
meta.setOwner(genbucket.getOwner().getName());
|
||||
meta.setDisplayName(ChatUtil.colorString("&a" + genbucket.getOwner().getName()));
|
||||
meta.setLore(ChatUtil.colorList(new ArrayList<>(Arrays.asList("&7Type: &f" + genbucket.getGenbucketType().name.toLowerCase(), "&7Location: &f" + ChatUtil.getCoordinatesFromLocation(genbucket.getClickedLocation()), "", "&f&oClick to teleport"))));
|
||||
skull.setItemMeta(meta);
|
||||
itemList.add(ClickableItem.of(skull, e -> player.teleport(genbucket.getPlayerLocation())));
|
||||
}
|
||||
}
|
||||
|
||||
pagination.setItems(itemList.toArray(new ClickableItem[1]));
|
||||
pagination.setItemsPerPage(7);
|
||||
pagination.addToIterator(inventoryContents.newIterator(SlotIterator.Type.HORIZONTAL, 1, 1));
|
||||
|
||||
inventoryContents.set(5, 3, ClickableItem.of(new ItemStack(Material.ARROW),
|
||||
e -> PANEL.open(player, pagination.previous().getPage())));
|
||||
inventoryContents.set(5, 5, ClickableItem.of(new ItemStack(Material.ARROW),
|
||||
e -> PANEL.open(player, pagination.next().getPage())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Player player, InventoryContents inventoryContents) {
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user