Mirror von
https://github.com/TheSilentPro/HeadDB.git
synchronisiert 2024-12-27 11:20:05 +01:00
internal changes and update command
Dieser Commit ist enthalten in:
Ursprung
47f4f5b2b1
Commit
9c3a45502a
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>tsp.headdb</groupId>
|
<groupId>tsp.headdb</groupId>
|
||||||
<artifactId>HeadDB</artifactId>
|
<artifactId>HeadDB</artifactId>
|
||||||
<version>2.4.1</version>
|
<version>2.4.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HeadDB</name>
|
<name>HeadDB</name>
|
||||||
|
@ -46,10 +46,11 @@ public class Head {
|
|||||||
profileField = meta.getClass().getDeclaredField("profile");
|
profileField = meta.getClass().getDeclaredField("profile");
|
||||||
profileField.setAccessible(true);
|
profileField.setAccessible(true);
|
||||||
profileField.set(meta, profile);
|
profileField.set(meta, profile);
|
||||||
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
|
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
|
||||||
Log.error("Could not set skull owner for " + uuid.toString() + " | Stack Trace:");
|
Log.error("Could not set skull owner for " + uuid.toString() + " | Stack Trace:");
|
||||||
e1.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
meta.setLore(Arrays.asList(
|
meta.setLore(Arrays.asList(
|
||||||
Utils.colorize("&cID: " + id),
|
Utils.colorize("&cID: " + id),
|
||||||
Utils.colorize("&e" + buildTagLore(tags)),
|
Utils.colorize("&e" + buildTagLore(tags)),
|
||||||
|
@ -21,6 +21,7 @@ public class LocalHead extends Head {
|
|||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ItemStack getItemStack() {
|
public ItemStack getItemStack() {
|
||||||
Validate.notNull(uuid, "uuid must not be null!");
|
Validate.notNull(uuid, "uuid must not be null!");
|
||||||
|
|
||||||
@ -36,10 +37,12 @@ public class LocalHead extends Head {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public UUID getUniqueId() {
|
public UUID getUniqueId() {
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -64,11 +67,13 @@ public class LocalHead extends Head {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public LocalHead withUniqueId(UUID uuid) {
|
public LocalHead withUniqueId(UUID uuid) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public LocalHead withName(String name) {
|
public LocalHead withName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return this;
|
return this;
|
||||||
|
@ -9,9 +9,10 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import tsp.headdb.HeadDB;
|
import tsp.headdb.HeadDB;
|
||||||
import tsp.headdb.api.Head;
|
import tsp.headdb.api.Head;
|
||||||
import tsp.headdb.api.HeadAPI;
|
import tsp.headdb.api.HeadAPI;
|
||||||
import tsp.headdb.inventory.InventoryUtils;
|
|
||||||
import tsp.headdb.util.Utils;
|
import tsp.headdb.util.Utils;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class Command_headdb implements CommandExecutor {
|
public class Command_headdb implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -127,6 +128,33 @@ public class Command_headdb implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sub.equalsIgnoreCase("update") || sub.equalsIgnoreCase("u")) {
|
||||||
|
if (!sender.hasPermission("headdb.update")) {
|
||||||
|
Utils.sendMessage(sender, "&cNo permission!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils.sendMessage(sender, "Updating...");
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
boolean result = HeadAPI.getDatabase().update();
|
||||||
|
if (result) {
|
||||||
|
Utils.sendMessage(sender, "&aDone! Took: " + TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - start) + " seconds");
|
||||||
|
} else {
|
||||||
|
Utils.sendMessage(sender, "&cFailed! Check console for errors.");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sub.equalsIgnoreCase("updateasync") || sub.equalsIgnoreCase("ua")) {
|
||||||
|
if (!sender.hasPermission("headdb.update")) {
|
||||||
|
Utils.sendMessage(sender, "&cNo permission!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils.sendMessage(sender, "Updating...");
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(HeadDB.getInstance(), () -> HeadAPI.getDatabase().update());
|
||||||
|
}
|
||||||
|
|
||||||
Utils.sendMessage(sender, " ");
|
Utils.sendMessage(sender, " ");
|
||||||
Utils.sendMessage(sender, "&c&lHeadDB &c- &5Commands");
|
Utils.sendMessage(sender, "&c&lHeadDB &c- &5Commands");
|
||||||
Utils.sendMessage(sender, "&7&oParameters:&c command &9(aliases)&c arguments... &7- Description");
|
Utils.sendMessage(sender, "&7&oParameters:&c command &9(aliases)&c arguments... &7- Description");
|
||||||
@ -134,6 +162,8 @@ public class Command_headdb implements CommandExecutor {
|
|||||||
Utils.sendMessage(sender, " > &c/hdb info &9(i) &7- Plugin Information");
|
Utils.sendMessage(sender, " > &c/hdb info &9(i) &7- Plugin Information");
|
||||||
Utils.sendMessage(sender, " > &c/hdb search &9(s) &c<name> &7- Search for heads matching a name");
|
Utils.sendMessage(sender, " > &c/hdb search &9(s) &c<name> &7- Search for heads matching a name");
|
||||||
Utils.sendMessage(sender, " > &c/hdb tagsearch &9(ts) &c<tag> &7- Search for heads matching a tag");
|
Utils.sendMessage(sender, " > &c/hdb tagsearch &9(ts) &c<tag> &7- Search for heads matching a tag");
|
||||||
|
Utils.sendMessage(sender, " > &c/hdb update &9(u) &7- Forcefully update the database");
|
||||||
|
Utils.sendMessage(sender, " > &c/hdb updateasync &9(ua) &7- Forcefully update the database ASYNCHRONOUSLY");
|
||||||
Utils.sendMessage(sender, " > &c/hdb give &9(g) &c<id> <player> &6[amount] &7- Give player a head");
|
Utils.sendMessage(sender, " > &c/hdb give &9(g) &c<id> <player> &6[amount] &7- Give player a head");
|
||||||
Utils.sendMessage(sender, " ");
|
Utils.sendMessage(sender, " ");
|
||||||
return true;
|
return true;
|
||||||
|
@ -5,12 +5,11 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import tsp.headdb.api.Head;
|
import tsp.headdb.api.Head;
|
||||||
import tsp.headdb.api.HeadAPI;
|
import tsp.headdb.api.HeadAPI;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public enum Category {
|
public enum Category {
|
||||||
|
|
||||||
ALPHABET("alphabet", ChatColor.YELLOW, 20),
|
ALPHABET("alphabet", ChatColor.YELLOW, 20),
|
||||||
ANIMALS("animals", ChatColor.DARK_AQUA, 21),
|
ANIMALS("animals", ChatColor.DARK_AQUA, 21),
|
||||||
BLOCKS("blocks", ChatColor.DARK_GRAY, 22),
|
BLOCKS("blocks", ChatColor.DARK_GRAY, 22),
|
||||||
@ -26,6 +25,7 @@ public enum Category {
|
|||||||
private final ChatColor color;
|
private final ChatColor color;
|
||||||
private final int location;
|
private final int location;
|
||||||
private final Map<Category, Head> item = new HashMap<>();
|
private final Map<Category, Head> item = new HashMap<>();
|
||||||
|
private static final Category[] values = values();
|
||||||
|
|
||||||
Category(String name, ChatColor color, int location) {
|
Category(String name, ChatColor color, int location) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -55,8 +55,8 @@ public enum Category {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Category getByName(String name) {
|
public static Category getByName(String name) {
|
||||||
for (Category category : Category.values()) {
|
for (Category category : values) {
|
||||||
if (category.getName().equals(name)) {
|
if (category.getName().equalsIgnoreCase(name)) {
|
||||||
return category;
|
return category;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,8 +64,8 @@ public enum Category {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Category> getCategories() {
|
public static Category[] getValues() {
|
||||||
return Arrays.asList(Category.values());
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,18 @@ import org.json.simple.parser.JSONParser;
|
|||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
import tsp.headdb.api.Head;
|
import tsp.headdb.api.Head;
|
||||||
import tsp.headdb.util.Log;
|
import tsp.headdb.util.Log;
|
||||||
import tsp.headdb.util.Utils;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@ -139,7 +143,7 @@ public class HeadDatabase {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public Map<Category, List<Head>> getHeadsNoCache() {
|
public Map<Category, List<Head>> getHeadsNoCache() {
|
||||||
Map<Category, List<Head>> result = new HashMap<>();
|
Map<Category, List<Head>> result = new HashMap<>();
|
||||||
List<Category> categories = Category.getCategories();
|
Category[] categories = Category.getValues();
|
||||||
|
|
||||||
int id = 1;
|
int id = 1;
|
||||||
for (Category category : categories) {
|
for (Category category : categories) {
|
||||||
@ -162,12 +166,14 @@ public class HeadDatabase {
|
|||||||
JSONArray array = (JSONArray) parser.parse(response.toString());
|
JSONArray array = (JSONArray) parser.parse(response.toString());
|
||||||
for (Object o : array) {
|
for (Object o : array) {
|
||||||
JSONObject obj = (JSONObject) o;
|
JSONObject obj = (JSONObject) o;
|
||||||
String uuid = obj.get("uuid").toString();
|
UUID uuid = UUID.fromString(obj.get("uuid").toString());
|
||||||
Log.debug(!Utils.isValid(uuid) + "Invalid UUID: " + uuid);
|
if (uuid.toString().length() != 36) {
|
||||||
|
uuid = UUID.randomUUID();
|
||||||
|
}
|
||||||
|
|
||||||
Head head = new Head(id)
|
Head head = new Head(id)
|
||||||
.withName(obj.get("name").toString())
|
.withName(obj.get("name").toString())
|
||||||
.withUniqueId(Utils.isValid(uuid) ? UUID.fromString(uuid) : UUID.randomUUID())
|
.withUniqueId(uuid)
|
||||||
.withValue(obj.get("value").toString())
|
.withValue(obj.get("value").toString())
|
||||||
.withTags(obj.get("tags") != null ? obj.get("tags").toString() : "None")
|
.withTags(obj.get("tags") != null ? obj.get("tags").toString() : "None")
|
||||||
.withCategory(category);
|
.withCategory(category);
|
||||||
@ -204,9 +210,7 @@ public class HeadDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
HEADS.clear();
|
HEADS.clear();
|
||||||
for (Map.Entry<Category, List<Head>> entry : heads.entrySet()) {
|
HEADS.putAll(heads);
|
||||||
HEADS.put(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,12 @@ import org.bukkit.event.HandlerList;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import tsp.headdb.api.Head;
|
import tsp.headdb.api.Head;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event is called when a player purchases a {@link Head}
|
||||||
|
*
|
||||||
|
* @author TheSilentPro
|
||||||
|
* @see tsp.headdb.inventory.InventoryUtils#purchaseHead(Player, Head, int, String, String)
|
||||||
|
*/
|
||||||
public class PlayerHeadPurchaseEvent extends Event implements Cancellable {
|
public class PlayerHeadPurchaseEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
private final HandlerList handlerList = new HandlerList();
|
private final HandlerList handlerList = new HandlerList();
|
||||||
|
@ -195,7 +195,7 @@ public class InventoryUtils {
|
|||||||
public static void openDatabase(Player player) {
|
public static void openDatabase(Player player) {
|
||||||
Inventory inventory = Bukkit.createInventory(null, 54, Utils.colorize("&c&lHeadDB &8(" + HeadAPI.getHeads().size() + ")"));
|
Inventory inventory = Bukkit.createInventory(null, 54, Utils.colorize("&c&lHeadDB &8(" + HeadAPI.getHeads().size() + ")"));
|
||||||
|
|
||||||
for (Category category : Category.getCategories()) {
|
for (Category category : Category.getValues()) {
|
||||||
ItemStack item = getUIItem(category.getName(), category.getItem());
|
ItemStack item = getUIItem(category.getName(), category.getItem());
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
meta.setDisplayName(Utils.colorize(category.getColor() + "&l" + category.getName().toUpperCase()));
|
meta.setDisplayName(Utils.colorize(category.getColor() + "&l" + category.getName().toUpperCase()));
|
||||||
@ -304,14 +304,6 @@ public class InventoryUtils {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void purchaseItem(Player player, ItemStack item, int amount, String category, String description) {
|
|
||||||
if (!processPayment(player, amount, category, description)) return;
|
|
||||||
|
|
||||||
item.setAmount(amount);
|
|
||||||
player.getInventory().addItem(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void purchaseHead(Player player, Head head, int amount, String category, String description) {
|
public static void purchaseHead(Player player, Head head, int amount, String category, String description) {
|
||||||
if (!processPayment(player, amount, category, description)) return;
|
if (!processPayment(player, amount, category, description)) return;
|
||||||
PlayerHeadPurchaseEvent event = new PlayerHeadPurchaseEvent(player, head, getCategoryCost(player, category));
|
PlayerHeadPurchaseEvent event = new PlayerHeadPurchaseEvent(player, head, getCategoryCost(player, category));
|
||||||
|
@ -14,7 +14,6 @@ import tsp.headdb.HeadDB;
|
|||||||
import tsp.headdb.api.HeadAPI;
|
import tsp.headdb.api.HeadAPI;
|
||||||
import tsp.headdb.database.Category;
|
import tsp.headdb.database.Category;
|
||||||
import tsp.headdb.inventory.InventoryUtils;
|
import tsp.headdb.inventory.InventoryUtils;
|
||||||
import tsp.headdb.util.Log;
|
|
||||||
import tsp.headdb.util.Utils;
|
import tsp.headdb.util.Utils;
|
||||||
|
|
||||||
public class MenuListener implements Listener {
|
public class MenuListener implements Listener {
|
||||||
|
@ -3,18 +3,8 @@ package tsp.headdb.util;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
public static final Pattern UUID_PATTERN = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
|
|
||||||
|
|
||||||
public static boolean isValid(String uuid) {
|
|
||||||
Matcher matcher = UUID_PATTERN.matcher(uuid);
|
|
||||||
return matcher.find();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendMessage(CommandSender sender, String message) {
|
public static void sendMessage(CommandSender sender, String message) {
|
||||||
sender.sendMessage(colorize(message));
|
sender.sendMessage(colorize(message));
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren