Mirror von
https://github.com/TheSilentPro/HeadDB.git
synchronisiert 2024-12-26 19:02:39 +01:00
Local Heads and minor fixes/changes
Dieser Commit ist enthalten in:
Ursprung
af6e7e67ec
Commit
b82c72b4cd
5
pom.xml
5
pom.xml
@ -6,17 +6,19 @@
|
||||
|
||||
<groupId>tsp.headdb</groupId>
|
||||
<artifactId>HeadDB</artifactId>
|
||||
<version>1.2</version>
|
||||
<version>1.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HeadDB</name>
|
||||
<description>Head Database</description>
|
||||
|
||||
<repositories>
|
||||
<!-- Paper Repo -->
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
<!-- Mojang Repo -->
|
||||
<repository>
|
||||
<id>mojang-repo</id>
|
||||
<url>https://libraries.minecraft.net/</url>
|
||||
@ -36,6 +38,7 @@
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<!-- Mojang Auth Lib -->
|
||||
<dependency>
|
||||
<groupId>com.mojang</groupId>
|
||||
<artifactId>authlib</artifactId>
|
||||
|
@ -1,9 +1,9 @@
|
||||
package tsp.headdb;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import tsp.headdb.api.HeadAPI;
|
||||
import tsp.headdb.command.Command_headdb;
|
||||
import tsp.headdb.database.HeadDatabase;
|
||||
import tsp.headdb.listener.JoinListener;
|
||||
import tsp.headdb.listener.PagedPaneListener;
|
||||
import tsp.headdb.listener.MenuListener;
|
||||
import tsp.headdb.util.Config;
|
||||
@ -32,6 +32,7 @@ public class HeadDB extends JavaPlugin {
|
||||
Log.debug("Registering listeners...");
|
||||
new PagedPaneListener(this);
|
||||
new MenuListener(this);
|
||||
new JoinListener(this);
|
||||
|
||||
Log.debug("Registering commands...");
|
||||
getCommand("headdb").setExecutor(new Command_headdb());
|
||||
|
@ -26,11 +26,10 @@ public class Head {
|
||||
Validate.notNull(name, "name must not be null!");
|
||||
Validate.notNull(uuid, "uuid must not be null!");
|
||||
Validate.notNull(value, "value must not be null!");
|
||||
Validate.notNull(category, "category must not be null!");
|
||||
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
meta.setDisplayName(Utils.colorize(category.getColor() + name));
|
||||
meta.setDisplayName(Utils.colorize(category != null ? category.getColor() + name : "&8" + name));
|
||||
// set skull owner
|
||||
GameProfile profile = new GameProfile(uuid, name);
|
||||
profile.getProperties().put("textures", new Property("textures", value));
|
||||
|
@ -1,5 +1,7 @@
|
||||
package tsp.headdb.api;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import tsp.headdb.HeadDB;
|
||||
import tsp.headdb.database.Category;
|
||||
@ -84,6 +86,19 @@ public class HeadAPI {
|
||||
return heads;
|
||||
}
|
||||
|
||||
public static List<LocalHead> getLocalHeads() {
|
||||
List<LocalHead> heads = new ArrayList<>();
|
||||
for (String key : HeadDB.getPlayerdata().getKeys(false)) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(key));
|
||||
heads.add(new LocalHead.Builder()
|
||||
.withUUID(player.getUniqueId())
|
||||
.withName(player.getName())
|
||||
.build());
|
||||
}
|
||||
|
||||
return heads;
|
||||
}
|
||||
|
||||
public static void updateDatabase() {
|
||||
HeadDatabase.update();
|
||||
}
|
||||
|
77
src/main/java/tsp/headdb/api/LocalHead.java
Normale Datei
77
src/main/java/tsp/headdb/api/LocalHead.java
Normale Datei
@ -0,0 +1,77 @@
|
||||
package tsp.headdb.api;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import tsp.headdb.util.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LocalHead {
|
||||
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
Validate.notNull(uuid, "uuid must not be null!");
|
||||
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
meta.setOwningPlayer(Bukkit.getOfflinePlayer(uuid));
|
||||
meta.setDisplayName(Utils.colorize("&8" + name));
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(Utils.colorize("&aUUID: " + uuid.toString()));
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public LocalHead(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
|
||||
public Builder withUUID(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocalHead build() {
|
||||
LocalHead head = new LocalHead(uuid);
|
||||
head.setName(name);
|
||||
return head;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
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;
|
||||
@ -9,6 +8,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import tsp.headdb.api.Head;
|
||||
import tsp.headdb.api.HeadAPI;
|
||||
import tsp.headdb.api.LocalHead;
|
||||
import tsp.headdb.database.Category;
|
||||
import tsp.headdb.util.Utils;
|
||||
import tsp.headdb.util.XMaterial;
|
||||
@ -18,8 +18,34 @@ import java.util.List;
|
||||
|
||||
public class InventoryUtils {
|
||||
|
||||
public static void openLocalMenu(Player player) {
|
||||
PagedPane pane = new PagedPane(4, 6, Utils.colorize("&c&lHeadDB &8- &aLocal Heads"));
|
||||
|
||||
List<LocalHead> heads = HeadAPI.getLocalHeads();
|
||||
for (LocalHead localHead : heads) {
|
||||
pane.addButton(new Button(localHead.getItemStack(), e -> {
|
||||
if (e.getClick() == ClickType.SHIFT_LEFT) {
|
||||
ItemStack item = localHead.getItemStack();
|
||||
item.setAmount(64);
|
||||
player.getInventory().addItem(item);
|
||||
return;
|
||||
}
|
||||
if (e.getClick() == ClickType.LEFT) {
|
||||
player.getInventory().addItem(localHead.getItemStack());
|
||||
return;
|
||||
}
|
||||
if (e.getClick() == ClickType.RIGHT) {
|
||||
player.closeInventory();
|
||||
Utils.sendMessage(player, "&cLocal heads can not be added to favorites!");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
pane.open(player);
|
||||
}
|
||||
|
||||
public static void openFavoritesMenu(Player player) {
|
||||
PagedPane pane = new PagedPane(4, 6, Utils.colorize("&c&lHeadDB - &eFavorites: " + player.getName()));
|
||||
PagedPane pane = new PagedPane(4, 6, Utils.colorize("&c&lHeadDB &8- &eFavorites: " + player.getName()));
|
||||
|
||||
List<Head> heads = HeadAPI.getFavoriteHeads(player.getUniqueId());
|
||||
for (Head head : heads) {
|
||||
@ -45,7 +71,7 @@ public class InventoryUtils {
|
||||
}
|
||||
|
||||
public static void openSearchDatabase(Player player, String search) {
|
||||
PagedPane pane = new PagedPane(4, 6, Utils.colorize("&c&lHeadDB - &eSearch: " + search));
|
||||
PagedPane pane = new PagedPane(4, 6, Utils.colorize("&c&lHeadDB &8- &eSearch: " + search));
|
||||
|
||||
List<Head> heads = HeadAPI.getHeadsByName(search);
|
||||
for (Head head : heads) {
|
||||
@ -70,7 +96,7 @@ public class InventoryUtils {
|
||||
}
|
||||
|
||||
public static void openCategoryDatabase(Player player, Category category) {
|
||||
PagedPane pane = new PagedPane(4, 6, Utils.colorize("&c&lHeadDB - &e" + category.getName()));
|
||||
PagedPane pane = new PagedPane(4, 6, Utils.colorize("&c&lHeadDB &8- &e" + category.getName()));
|
||||
|
||||
List<Head> heads = HeadAPI.getHeads(category);
|
||||
for (Head head : heads) {
|
||||
@ -109,11 +135,19 @@ 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);
|
||||
inventory.setItem(37, buildButton(
|
||||
XMaterial.BOOK.parseItem(),
|
||||
"&eFavorites",
|
||||
"",
|
||||
"&8Click to view your favorites")
|
||||
);
|
||||
|
||||
inventory.setItem(43, buildButton(
|
||||
XMaterial.COMPASS.parseItem(),
|
||||
"&aLocal",
|
||||
"",
|
||||
"&8Heads from any players that have logged on the server"
|
||||
));
|
||||
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
@ -140,4 +174,20 @@ public class InventoryUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static ItemStack buildButton(ItemStack item, String name, String... lore) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Utils.colorize(name));
|
||||
List<String> list = meta.getLore();
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
|
||||
for (String line : lore) {
|
||||
list.add(Utils.colorize(line));
|
||||
}
|
||||
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
||||
|
19
src/main/java/tsp/headdb/listener/JoinListener.java
Normale Datei
19
src/main/java/tsp/headdb/listener/JoinListener.java
Normale Datei
@ -0,0 +1,19 @@
|
||||
package tsp.headdb.listener;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import tsp.headdb.HeadDB;
|
||||
|
||||
public class JoinListener implements Listener {
|
||||
|
||||
public JoinListener(HeadDB plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
HeadDB.getPlayerdata().set(e.getPlayer().getUniqueId().toString() + ".username", e.getPlayer().getName());
|
||||
}
|
||||
|
||||
}
|
@ -44,6 +44,16 @@ public class MenuListener implements Listener {
|
||||
InventoryUtils.openFavoritesMenu(player);
|
||||
return;
|
||||
}
|
||||
if (name.equalsIgnoreCase("local")) {
|
||||
if (!player.hasPermission("headdb.local")) {
|
||||
Utils.sendMessage(player, "&cYou do not have permission to view local heads!");
|
||||
player.closeInventory();
|
||||
return;
|
||||
}
|
||||
InventoryUtils.openLocalMenu(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Category category = Category.getByName(name);
|
||||
|
||||
if (category != null) {
|
||||
|
@ -2,7 +2,7 @@ name: HeadDB
|
||||
description: Head Database
|
||||
|
||||
main: tsp.headdb.HeadDB
|
||||
version: 1.2
|
||||
version: 1.3
|
||||
api-version: 1.16
|
||||
author: Silent
|
||||
|
||||
@ -20,6 +20,7 @@ permissions:
|
||||
headdb.search: true
|
||||
headdb.give: true
|
||||
headdb.favorites: true
|
||||
headdb.local: true
|
||||
headdb.open:
|
||||
default: op
|
||||
headdb.search:
|
||||
@ -27,4 +28,6 @@ permissions:
|
||||
headdb.give:
|
||||
default: op
|
||||
headdb.favorites:
|
||||
default: op
|
||||
headdb.local:
|
||||
default: op
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren