mirror of
https://github.com/IHasName/CustomHeads.git
synced 2025-02-17 19:21:28 +01:00
Small Fix
Added better Vault Error Description Reverted Player Caching Change
This commit is contained in:
parent
3faa8e26ff
commit
fe5306e1d4
@ -249,7 +249,9 @@ public class CustomHeads extends JavaPlugin {
|
||||
instance = this;
|
||||
pluginLogger = instance.getLogger();
|
||||
if(DEV_BUILD) {
|
||||
getServer().getConsoleSender().sendMessage("[CustomHeads]\n§e=============================================================================================\nThis is a Dev Version of the Plugin! Please update update as soon as a new Version gets released\n=============================================================================================");
|
||||
String txt = " This is a Dev Version of the Plugin! Please update update as soon as a public Version gets released ";
|
||||
String line = Utils.repeatString("=", txt.length());
|
||||
getServer().getConsoleSender().sendMessage("[CustomHeads]\n§e"+ line + "\n" + txt + "\n" + line);
|
||||
}
|
||||
|
||||
bukkitVersion = Bukkit.getVersion().substring(Bukkit.getVersion().lastIndexOf("("));
|
||||
|
@ -95,13 +95,15 @@ public class CategoryManager {
|
||||
Permission categoryAllHeadsPermission = new Permission(category.getPermission() + ".all_heads");
|
||||
|
||||
// Add Permissions from the Categories dynamically
|
||||
pluginManager.addPermission(categoryBasePermission);
|
||||
pluginManager.addPermission(categoryAllHeadsPermission);
|
||||
|
||||
// Add the Category Permissions as Parent from the View Category Permission
|
||||
categoryBasePermission.addParent(viewCategoryWildcard, true);
|
||||
categoryBasePermission.addParent(categoryAllHeadsPermission, true);
|
||||
categoryAllHeadsPermission.addParent(viewCategoryWildcard, true);
|
||||
if (pluginManager.getPermission(categoryBasePermission.getName()) == null) {
|
||||
pluginManager.addPermission(categoryBasePermission);
|
||||
categoryBasePermission.addParent(viewCategoryWildcard, true);
|
||||
categoryBasePermission.addParent(categoryAllHeadsPermission, true);
|
||||
}
|
||||
if (pluginManager.getPermission(categoryAllHeadsPermission.getName()) == null) {
|
||||
pluginManager.addPermission(categoryAllHeadsPermission);
|
||||
categoryAllHeadsPermission.addParent(viewCategoryWildcard, true);
|
||||
}
|
||||
|
||||
categoriesLoaded++;
|
||||
if (category.hasSubCategories()) {
|
||||
|
@ -14,7 +14,7 @@ public interface EconomyHandler {
|
||||
|
||||
/**
|
||||
* Whether the Plugin/Handler is currently able to handle incoming Economy Requests
|
||||
* Example: {@link de.likewhat.customheads.economy.handlers.Vault}
|
||||
* Example: {@link de.likewhat.customheads.economy.handlers.VaultHandler}
|
||||
* @return true/false
|
||||
*/
|
||||
boolean isValid();
|
||||
|
@ -5,7 +5,7 @@ import de.likewhat.customheads.api.CustomHeadsPlayer;
|
||||
import de.likewhat.customheads.category.Category;
|
||||
import de.likewhat.customheads.category.CustomHead;
|
||||
import de.likewhat.customheads.economy.errors.InvalidEconomyHandlerException;
|
||||
import de.likewhat.customheads.economy.handlers.Vault;
|
||||
import de.likewhat.customheads.economy.handlers.VaultHandler;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -28,7 +28,7 @@ public class EconomyManager {
|
||||
|
||||
public EconomyManager() throws InvalidEconomyHandlerException {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
|
||||
registerAndSetActiveHandler(new Vault());
|
||||
registerAndSetActiveHandler(new VaultHandler());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.likewhat.customheads.economy.handlers;
|
||||
|
||||
import de.likewhat.customheads.CustomHeads;
|
||||
import de.likewhat.customheads.economy.EconomyCallback;
|
||||
import de.likewhat.customheads.economy.EconomyHandler;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
@ -8,13 +9,15 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
public class Vault implements EconomyHandler {
|
||||
public class VaultHandler implements EconomyHandler {
|
||||
|
||||
private Economy economyPlugin;
|
||||
|
||||
public Vault() {
|
||||
public VaultHandler() {
|
||||
RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (economyProvider != null) {
|
||||
if (economyProvider == null) {
|
||||
CustomHeads.getPluginLogger().warning("Vault Economy Service not found. Do you have a supported Economy Plugin installed?");
|
||||
} else {
|
||||
economyPlugin = economyProvider.getProvider();
|
||||
}
|
||||
}
|
@ -44,8 +44,8 @@ public class PlayerWrapper implements CustomHeadsPlayer {
|
||||
this.player = player;
|
||||
try {
|
||||
JsonObject dataRoot = CustomHeads.getPlayerDataFile().getJson().getAsJsonObject();
|
||||
searchHistory = new SearchHistory(player);
|
||||
getHistory = new GetHistory(player);
|
||||
this.searchHistory = new SearchHistory(player);
|
||||
this.getHistory = new GetHistory(player);
|
||||
|
||||
if (dataRoot.has(player.getUniqueId().toString())) {
|
||||
JsonObject uuidObject = dataRoot.getAsJsonObject(player.getUniqueId().toString());
|
||||
@ -57,13 +57,13 @@ public class PlayerWrapper implements CustomHeadsPlayer {
|
||||
} else {
|
||||
editor.setOwner(textureValue);
|
||||
}
|
||||
savedHeads.add(editor.getItem());
|
||||
this.savedHeads.add(editor.getItem());
|
||||
});
|
||||
|
||||
if (uuidObject.has("unlockedCategories")) {
|
||||
List<Category> categories = new ArrayList<>();
|
||||
uuidObject.getAsJsonArray("unlockedCategories").forEach(categoryId -> categories.add(CustomHeads.getCategoryManager().getCategory(categoryId.getAsString())));
|
||||
unlockedCategories = categories;
|
||||
this.unlockedCategories = categories;
|
||||
}
|
||||
|
||||
if (uuidObject.has("unlockedHeads")) {
|
||||
@ -72,7 +72,7 @@ public class PlayerWrapper implements CustomHeadsPlayer {
|
||||
String[] idParts = headId.getAsString().split(":");
|
||||
heads.add(CustomHeads.getApi().getHead(CustomHeads.getCategoryManager().getCategory(idParts[0]), Integer.parseInt(idParts[1])));
|
||||
});
|
||||
unlockedHeads = heads;
|
||||
this.unlockedHeads = heads;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -82,7 +82,11 @@ public class PlayerWrapper implements CustomHeadsPlayer {
|
||||
}
|
||||
|
||||
static CustomHeadsPlayer wrapPlayer(Player player) {
|
||||
return WRAPPED_PLAYERS_CACHE.getOrDefault(player.getUniqueId(), new PlayerWrapper(player));
|
||||
if (WRAPPED_PLAYERS_CACHE.containsKey(player.getUniqueId())) {
|
||||
return WRAPPED_PLAYERS_CACHE.get(player.getUniqueId());
|
||||
} else {
|
||||
return new PlayerWrapper(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearCache() {
|
||||
@ -139,7 +143,7 @@ public class PlayerWrapper implements CustomHeadsPlayer {
|
||||
}
|
||||
|
||||
public List<Category> getUnlockedCategories(boolean ignorePermission) {
|
||||
return CustomHeads.getCategoryManager().getCategoryList().stream().filter(category -> (!ignorePermission && (Utils.hasPermission(player, category.getPermission()) || Utils.hasPermission(player, category.getPermission() + ".allheads"))) || unlockedCategories.contains(category)).collect(Collectors.toList());
|
||||
return CustomHeads.getCategoryManager().getCategoryList().stream().filter(category -> (!ignorePermission && (Utils.hasPermission(this.player, category.getPermission()) || Utils.hasPermission(this.player, category.getPermission() + ".allheads"))) || this.unlockedCategories.contains(category)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Player unwrap() {
|
||||
@ -147,39 +151,29 @@ public class PlayerWrapper implements CustomHeadsPlayer {
|
||||
}
|
||||
|
||||
public boolean unlockCategory(Category category) {
|
||||
if (unlockedCategories.contains(category)) {
|
||||
if (this.unlockedCategories.contains(category)) {
|
||||
return false;
|
||||
} else {
|
||||
unlockedCategories.add(category);
|
||||
this.unlockedCategories.add(category);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean lockCategory(Category category) {
|
||||
if (unlockedCategories.contains(category)) {
|
||||
unlockedCategories.remove(category);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return unlockedCategories.remove(category);
|
||||
}
|
||||
|
||||
public boolean unlockHead(Category category, int id) {
|
||||
if (unlockedHeads.contains(CustomHeads.getApi().getHead(category, id))) {
|
||||
if (this.unlockedHeads.contains(CustomHeads.getApi().getHead(category, id))) {
|
||||
return false;
|
||||
} else {
|
||||
unlockedHeads.add(CustomHeads.getApi().getHead(category, id));
|
||||
this.unlockedHeads.add(CustomHeads.getApi().getHead(category, id));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean lockHead(Category category, int id) {
|
||||
if (unlockedHeads.contains(CustomHeads.getApi().getHead(category, id))) {
|
||||
unlockedHeads.remove(CustomHeads.getApi().getHead(category, id));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return this.unlockedHeads.remove(CustomHeads.getApi().getHead(category, id));
|
||||
}
|
||||
|
||||
public boolean saveHead(String name, String texture) {
|
||||
@ -192,7 +186,7 @@ public class PlayerWrapper implements CustomHeadsPlayer {
|
||||
} else {
|
||||
editor.setOwner(texture);
|
||||
}
|
||||
savedHeads.add(editor.getItem());
|
||||
this.savedHeads.add(editor.getItem());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -201,17 +195,17 @@ public class PlayerWrapper implements CustomHeadsPlayer {
|
||||
if (!hasHead(name)) {
|
||||
return false;
|
||||
} else {
|
||||
savedHeads.remove(getHead(name));
|
||||
this.savedHeads.remove(getHead(name));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getHead(String name) {
|
||||
return savedHeads.stream().filter(itemStack -> Utils.toConfigString(itemStack.getItemMeta().getDisplayName()).equals(name)).iterator().next();
|
||||
return this.savedHeads.stream().filter(itemStack -> Utils.toConfigString(itemStack.getItemMeta().getDisplayName()).equals(name)).iterator().next();
|
||||
}
|
||||
|
||||
public boolean hasHead(String name) {
|
||||
return savedHeads.stream().filter(itemStack -> Utils.toConfigString(itemStack.getItemMeta().getDisplayName()).equals(name)).iterator().hasNext();
|
||||
return this.savedHeads.stream().filter(itemStack -> Utils.toConfigString(itemStack.getItemMeta().getDisplayName()).equals(name)).iterator().hasNext();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -380,12 +380,14 @@ public class Utils {
|
||||
if (baseCategory.isSubCategory()) {
|
||||
SubCategory subCategory = baseCategory.getAsSubCategory();
|
||||
if (!customHeadsPlayer.getUnlockedCategories(CustomHeads.hasEconomy() && !CustomHeads.keepCategoryPermissions()).contains(subCategory.getOriginCategory())) {
|
||||
CustomHeads.getPluginLogger().info("Player doesn't have this Sub-Category unlocked ("+subCategory.getName()+") Permissions ignored? " + (CustomHeads.hasEconomy() && !CustomHeads.keepCategoryPermissions()));
|
||||
return;
|
||||
}
|
||||
categoryHeads = subCategory.getHeads();
|
||||
} else {
|
||||
Category category = baseCategory.getAsCategory();
|
||||
if (!customHeadsPlayer.getUnlockedCategories(CustomHeads.hasEconomy() && !CustomHeads.keepCategoryPermissions()).contains(category)) {
|
||||
CustomHeads.getPluginLogger().info("Player doesn't have this Category unlocked ("+category.getName()+") Permissions ignored? " + (CustomHeads.hasEconomy() && !CustomHeads.keepCategoryPermissions()));
|
||||
return;
|
||||
}
|
||||
if (category.hasSubCategories()) {
|
||||
@ -745,6 +747,14 @@ public class Utils {
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String repeatString(String string, int n) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < n; i++) {
|
||||
result.append(string);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static int clamp(int min, int value, int max) {
|
||||
return Math.max(Math.min(value, min), max);
|
||||
}
|
||||
|
@ -45,6 +45,11 @@
|
||||
# Categories to the Cursor otherwise it will be added #
|
||||
# to your Inventory like /give #
|
||||
# --------------------------------------------------- #
|
||||
# replaceHelmet: Whether or not to replace the Helmet #
|
||||
# When Shift-Right clicking a Head #
|
||||
# When false the Helmet will be returned into the #
|
||||
# Inventory #
|
||||
# --------------------------------------------------- #
|
||||
# disabledCategories: A List of Categories which will #
|
||||
# be ignored by the Plugin #
|
||||
# --------------------------------------------------- #
|
||||
@ -82,6 +87,7 @@ update-notifications:
|
||||
onJoin: true
|
||||
console: true
|
||||
grabHeadToCursor: true
|
||||
replaceHelmet: false
|
||||
disabledCategories: []
|
||||
langFile: none
|
||||
reducedDebug: true
|
Loading…
Reference in New Issue
Block a user