Local Heads and minor fixes/changes

Dieser Commit ist enthalten in:
Silent 2020-11-17 22:39:22 +01:00
Ursprung af6e7e67ec
Commit b82c72b4cd
9 geänderte Dateien mit 191 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -6,17 +6,19 @@
<groupId>tsp.headdb</groupId> <groupId>tsp.headdb</groupId>
<artifactId>HeadDB</artifactId> <artifactId>HeadDB</artifactId>
<version>1.2</version> <version>1.3</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HeadDB</name> <name>HeadDB</name>
<description>Head Database</description> <description>Head Database</description>
<repositories> <repositories>
<!-- Paper Repo -->
<repository> <repository>
<id>papermc</id> <id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url> <url>https://papermc.io/repo/repository/maven-public/</url>
</repository> </repository>
<!-- Mojang Repo -->
<repository> <repository>
<id>mojang-repo</id> <id>mojang-repo</id>
<url>https://libraries.minecraft.net/</url> <url>https://libraries.minecraft.net/</url>
@ -36,6 +38,7 @@
<artifactId>json-simple</artifactId> <artifactId>json-simple</artifactId>
<version>1.1.1</version> <version>1.1.1</version>
</dependency> </dependency>
<!-- Mojang Auth Lib -->
<dependency> <dependency>
<groupId>com.mojang</groupId> <groupId>com.mojang</groupId>
<artifactId>authlib</artifactId> <artifactId>authlib</artifactId>

Datei anzeigen

@ -1,9 +1,9 @@
package tsp.headdb; package tsp.headdb;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import tsp.headdb.api.HeadAPI;
import tsp.headdb.command.Command_headdb; import tsp.headdb.command.Command_headdb;
import tsp.headdb.database.HeadDatabase; import tsp.headdb.database.HeadDatabase;
import tsp.headdb.listener.JoinListener;
import tsp.headdb.listener.PagedPaneListener; import tsp.headdb.listener.PagedPaneListener;
import tsp.headdb.listener.MenuListener; import tsp.headdb.listener.MenuListener;
import tsp.headdb.util.Config; import tsp.headdb.util.Config;
@ -32,6 +32,7 @@ public class HeadDB extends JavaPlugin {
Log.debug("Registering listeners..."); Log.debug("Registering listeners...");
new PagedPaneListener(this); new PagedPaneListener(this);
new MenuListener(this); new MenuListener(this);
new JoinListener(this);
Log.debug("Registering commands..."); Log.debug("Registering commands...");
getCommand("headdb").setExecutor(new Command_headdb()); getCommand("headdb").setExecutor(new Command_headdb());

Datei anzeigen

@ -26,11 +26,10 @@ public class Head {
Validate.notNull(name, "name must not be null!"); Validate.notNull(name, "name must not be null!");
Validate.notNull(uuid, "uuid must not be null!"); Validate.notNull(uuid, "uuid must not be null!");
Validate.notNull(value, "value 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); ItemStack item = new ItemStack(Material.PLAYER_HEAD);
SkullMeta meta = (SkullMeta) item.getItemMeta(); 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 // set skull owner
GameProfile profile = new GameProfile(uuid, name); GameProfile profile = new GameProfile(uuid, name);
profile.getProperties().put("textures", new Property("textures", value)); profile.getProperties().put("textures", new Property("textures", value));

Datei anzeigen

@ -1,5 +1,7 @@
package tsp.headdb.api; package tsp.headdb.api;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import tsp.headdb.HeadDB; import tsp.headdb.HeadDB;
import tsp.headdb.database.Category; import tsp.headdb.database.Category;
@ -84,6 +86,19 @@ public class HeadAPI {
return heads; 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() { public static void updateDatabase() {
HeadDatabase.update(); HeadDatabase.update();
} }

Datei anzeigen

@ -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;
}
}
}

Datei anzeigen

@ -1,7 +1,6 @@
package tsp.headdb.inventory; package tsp.headdb.inventory;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
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;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
@ -9,6 +8,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import tsp.headdb.api.Head; import tsp.headdb.api.Head;
import tsp.headdb.api.HeadAPI; import tsp.headdb.api.HeadAPI;
import tsp.headdb.api.LocalHead;
import tsp.headdb.database.Category; import tsp.headdb.database.Category;
import tsp.headdb.util.Utils; import tsp.headdb.util.Utils;
import tsp.headdb.util.XMaterial; import tsp.headdb.util.XMaterial;
@ -18,8 +18,34 @@ import java.util.List;
public class InventoryUtils { 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) { 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()); List<Head> heads = HeadAPI.getFavoriteHeads(player.getUniqueId());
for (Head head : heads) { for (Head head : heads) {
@ -45,7 +71,7 @@ public class InventoryUtils {
} }
public static void openSearchDatabase(Player player, String search) { 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); List<Head> heads = HeadAPI.getHeadsByName(search);
for (Head head : heads) { for (Head head : heads) {
@ -70,7 +96,7 @@ public class InventoryUtils {
} }
public static void openCategoryDatabase(Player player, Category category) { 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); List<Head> heads = HeadAPI.getHeads(category);
for (Head head : heads) { for (Head head : heads) {
@ -109,11 +135,19 @@ public class InventoryUtils {
inventory.addItem(item); inventory.addItem(item);
} }
ItemStack fav = XMaterial.BOOK.parseItem(); inventory.setItem(37, buildButton(
ItemMeta meta = fav.getItemMeta(); XMaterial.BOOK.parseItem(),
meta.setDisplayName(Utils.colorize("&eFavorites")); "&eFavorites",
fav.setItemMeta(meta); "",
inventory.setItem(37, fav); "&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); 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;
}
} }

Datei anzeigen

@ -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());
}
}

Datei anzeigen

@ -44,6 +44,16 @@ public class MenuListener implements Listener {
InventoryUtils.openFavoritesMenu(player); InventoryUtils.openFavoritesMenu(player);
return; 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); Category category = Category.getByName(name);
if (category != null) { if (category != null) {

Datei anzeigen

@ -2,7 +2,7 @@ name: HeadDB
description: Head Database description: Head Database
main: tsp.headdb.HeadDB main: tsp.headdb.HeadDB
version: 1.2 version: 1.3
api-version: 1.16 api-version: 1.16
author: Silent author: Silent
@ -20,6 +20,7 @@ permissions:
headdb.search: true headdb.search: true
headdb.give: true headdb.give: true
headdb.favorites: true headdb.favorites: true
headdb.local: true
headdb.open: headdb.open:
default: op default: op
headdb.search: headdb.search:
@ -28,3 +29,5 @@ permissions:
default: op default: op
headdb.favorites: headdb.favorites:
default: op default: op
headdb.local:
default: op