Mirror von
https://github.com/TheSilentPro/HeadDB.git
synchronisiert 2024-12-27 11:20:05 +01:00
Added favorites menu
Dieser Commit ist enthalten in:
Ursprung
ddf0e10c19
Commit
abc90629ea
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>tsp.headdb</groupId>
|
||||
<artifactId>HeadDB</artifactId>
|
||||
<version>1.1</version>
|
||||
<version>1.2</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HeadDB</name>
|
||||
|
@ -15,6 +15,7 @@ public class HeadDB extends JavaPlugin {
|
||||
|
||||
private static HeadDB instance;
|
||||
private static Config config;
|
||||
private static Config playerdata;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@ -22,6 +23,8 @@ public class HeadDB extends JavaPlugin {
|
||||
Log.info("Loading HeadDB - " + getDescription().getVersion());
|
||||
saveDefaultConfig();
|
||||
config = new Config("plugins/HeadDB/config.yml");
|
||||
playerdata = new Config("plugins/HeadDB/playerdata.yml");
|
||||
playerdata.create();
|
||||
|
||||
Log.debug("Starting metrics...");
|
||||
new Metrics(this, Utils.METRICS_ID);
|
||||
@ -43,6 +46,10 @@ public class HeadDB extends JavaPlugin {
|
||||
return config;
|
||||
}
|
||||
|
||||
public static Config getPlayerdata() {
|
||||
return playerdata;
|
||||
}
|
||||
|
||||
public static HeadDB getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import tsp.headdb.util.Log;
|
||||
import tsp.headdb.util.Utils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Head {
|
||||
@ -29,7 +29,6 @@ public class Head {
|
||||
Validate.notNull(category, "category must not be null!");
|
||||
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
if (item != null) {
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
meta.setDisplayName(Utils.colorize(category.getColor() + name));
|
||||
// set skull owner
|
||||
@ -44,9 +43,11 @@ public class Head {
|
||||
Log.error("Could not set skull owner for " + uuid.toString() + " | Stack Trace:");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
meta.setLore(Collections.singletonList(Utils.colorize("&cID: " + id)));
|
||||
meta.setLore(Arrays.asList(
|
||||
Utils.colorize("&cID: " + id),
|
||||
Utils.colorize("&8Right-Click to add/remove from favorites.")
|
||||
));
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package tsp.headdb.api;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import tsp.headdb.HeadDB;
|
||||
import tsp.headdb.database.Category;
|
||||
import tsp.headdb.database.HeadDatabase;
|
||||
import tsp.headdb.inventory.InventoryUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -50,6 +52,38 @@ public class HeadAPI {
|
||||
return HeadDatabase.getHeads();
|
||||
}
|
||||
|
||||
public static void addFavoriteHead(UUID uuid, int id) {
|
||||
List<Integer> favs = HeadDB.getPlayerdata().getIntList(uuid.toString() + ".favorites");
|
||||
if (!favs.contains(id)) {
|
||||
favs.add(id);
|
||||
}
|
||||
HeadDB.getPlayerdata().set(uuid.toString() + ".favorites", favs);
|
||||
HeadDB.getPlayerdata().save();
|
||||
}
|
||||
|
||||
public static void removeFavoriteHead(UUID uuid, int id) {
|
||||
List<Integer> favs = HeadDB.getPlayerdata().getIntList(uuid.toString() + ".favorites");
|
||||
for (int i = 0; i < favs.size(); i++) {
|
||||
if (favs.get(i) == id) {
|
||||
favs.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
HeadDB.getPlayerdata().set(uuid.toString() + ".favorites", favs);
|
||||
HeadDB.getPlayerdata().save();
|
||||
}
|
||||
|
||||
public static List<Head> getFavoriteHeads(UUID uuid) {
|
||||
List<Head> heads = new ArrayList<>();
|
||||
List<Integer> ids = HeadDB.getPlayerdata().getIntList(uuid.toString() + ".favorites");
|
||||
for (int id : ids) {
|
||||
Head head = getHeadByID(id);
|
||||
heads.add(head);
|
||||
}
|
||||
|
||||
return heads;
|
||||
}
|
||||
|
||||
public static void updateDatabase() {
|
||||
HeadDatabase.update();
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package tsp.headdb.inventory;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -17,6 +18,32 @@ import java.util.List;
|
||||
|
||||
public class InventoryUtils {
|
||||
|
||||
public static void openFavoritesMenu(Player player) {
|
||||
PagedPane pane = new PagedPane(4, 6, Utils.colorize("&c&lHeadDB - &eFavorites: " + player.getName()));
|
||||
|
||||
List<Head> heads = HeadAPI.getFavoriteHeads(player.getUniqueId());
|
||||
for (Head head : heads) {
|
||||
pane.addButton(new Button(head.getItemStack(), e -> {
|
||||
if (e.getClick() == ClickType.SHIFT_LEFT) {
|
||||
ItemStack item = head.getItemStack();
|
||||
item.setAmount(64);
|
||||
player.getInventory().addItem(item);
|
||||
return;
|
||||
}
|
||||
if (e.getClick() == ClickType.LEFT) {
|
||||
player.getInventory().addItem(head.getItemStack());
|
||||
}
|
||||
if (e.getClick() == ClickType.RIGHT) {
|
||||
HeadAPI.removeFavoriteHead(player.getUniqueId(), head.getId());
|
||||
openFavoritesMenu(player);
|
||||
Utils.sendMessage(player, "Removed &e" + head.getName() + " &8from favorites.");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
pane.open(player);
|
||||
}
|
||||
|
||||
public static void openSearchDatabase(Player player, String search) {
|
||||
PagedPane pane = new PagedPane(4, 6, Utils.colorize("&c&lHeadDB - &eSearch: " + search));
|
||||
|
||||
@ -29,7 +56,13 @@ public class InventoryUtils {
|
||||
player.getInventory().addItem(item);
|
||||
return;
|
||||
}
|
||||
if (e.getClick() == ClickType.LEFT) {
|
||||
player.getInventory().addItem(head.getItemStack());
|
||||
}
|
||||
if (e.getClick() == ClickType.RIGHT) {
|
||||
HeadAPI.addFavoriteHead(player.getUniqueId(), head.getId());
|
||||
Utils.sendMessage(player, "Added &e" + head.getName() + " &8to favorites.");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@ -48,7 +81,13 @@ public class InventoryUtils {
|
||||
player.getInventory().addItem(item);
|
||||
return;
|
||||
}
|
||||
if (e.getClick() == ClickType.LEFT) {
|
||||
player.getInventory().addItem(head.getItemStack());
|
||||
}
|
||||
if (e.getClick() == ClickType.RIGHT) {
|
||||
HeadAPI.addFavoriteHead(player.getUniqueId(), head.getId());
|
||||
Utils.sendMessage(player, "Added &e" + head.getName() + " &8to favorites.");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@ -56,7 +95,7 @@ public class InventoryUtils {
|
||||
}
|
||||
|
||||
public static void openDatabase(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, Utils.colorize("&c&lHeadDB"));
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, Utils.colorize("&c&lHeadDB &8(" + HeadAPI.getHeads().size() + ")"));
|
||||
|
||||
fillBorder(inventory, XMaterial.BLACK_STAINED_GLASS_PANE.parseItem());
|
||||
for (Category category : Category.getCategories()) {
|
||||
@ -70,6 +109,12 @@ public class InventoryUtils {
|
||||
inventory.addItem(item);
|
||||
}
|
||||
|
||||
ItemStack fav = XMaterial.BOOK.parseItem();
|
||||
ItemMeta meta = fav.getItemMeta();
|
||||
meta.setDisplayName(Utils.colorize("&eFavorites"));
|
||||
fav.setItemMeta(meta);
|
||||
inventory.setItem(37, fav);
|
||||
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ public class MenuListener implements Listener {
|
||||
if (!(e.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) e.getWhoClicked();
|
||||
if (e.getView().getTitle().startsWith(Utils.colorize("&c&lHeadDB"))) {
|
||||
e.setCancelled(true);
|
||||
Inventory inventory = e.getClickedInventory();
|
||||
@ -34,11 +35,19 @@ public class MenuListener implements Listener {
|
||||
|
||||
if (item != null && item.getType() != XMaterial.AIR.parseMaterial()) {
|
||||
String name = ChatColor.stripColor(item.getItemMeta().getDisplayName().toLowerCase());
|
||||
if (name.equalsIgnoreCase("favorites")) {
|
||||
if (!player.hasPermission("headdb.favorites")) {
|
||||
Utils.sendMessage(player, "&cYou do not have permission for favorites!");
|
||||
player.closeInventory();
|
||||
return;
|
||||
}
|
||||
InventoryUtils.openFavoritesMenu(player);
|
||||
return;
|
||||
}
|
||||
Category category = Category.getByName(name);
|
||||
|
||||
if (category != null) {
|
||||
InventoryUtils.openCategoryDatabase((Player) e.getWhoClicked(), category);
|
||||
|
||||
InventoryUtils.openCategoryDatabase(player, category);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,10 @@ public class Config {
|
||||
return config.getInt(path);
|
||||
}
|
||||
|
||||
public List<Integer> getIntList(String path) {
|
||||
return config.getIntegerList(path);
|
||||
}
|
||||
|
||||
public long getLong(String path) {
|
||||
return config.getLong(path);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package tsp.headdb.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import tsp.headdb.HeadDB;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
@ -34,6 +35,9 @@ public class Log {
|
||||
}
|
||||
|
||||
public static void log(LogLevel level, String message) {
|
||||
if (level == LogLevel.DEBUG && !HeadDB.getCfg().getBoolean("debug")) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getConsoleSender().sendMessage(Utils.colorize("&7[&9&l" + name + "&7] " + level.getColor() + "[" + level.name() + "]: " + message));
|
||||
}
|
||||
|
||||
|
@ -2,4 +2,4 @@
|
||||
refresh: 3600
|
||||
|
||||
# Debug Mode
|
||||
debug: true
|
||||
debug: false
|
@ -2,7 +2,7 @@ name: HeadDB
|
||||
description: Head Database
|
||||
|
||||
main: tsp.headdb.HeadDB
|
||||
version: 1.1
|
||||
version: 1.2
|
||||
api-version: 1.16
|
||||
author: Silent
|
||||
|
||||
@ -19,9 +19,12 @@ permissions:
|
||||
headdb.open: true
|
||||
headdb.search: true
|
||||
headdb.give: true
|
||||
headdb.favorites: true
|
||||
headdb.open:
|
||||
default: op
|
||||
headdb.search:
|
||||
default: op
|
||||
headdb.give:
|
||||
default: op
|
||||
headdb.favorites:
|
||||
default: op
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren