Updated to 2.0.3 (some manual patches).

This commit is contained in:
CoderMarido 2018-08-23 20:51:59 +02:00
parent 1caf138d56
commit 02be1447fc
13 changed files with 501 additions and 471 deletions

View File

@ -8,8 +8,8 @@ Quality, performance, and support are my priorities for this resource. Purchase
Here is an example with built-in methods for developers that want to use the developers API to code other resources.
```ruby
# Check if Heads is installed and enabled.
if(Bukkit.getPluginManager().getPlugin("Heads") != null) {
Bukkit.broadcastMessage("Hooray!");
if (HeadsAPI.isEnabled()) {
Hooray();
}
# How you would get the heads in any way.

View File

@ -45,15 +45,17 @@ public class HeadNamer implements Listener {
return Heads.getMainConfig().shouldUseBlockStore() && Heads.isBlockStoreAvailable();
}
@SuppressWarnings("deprecation")
private boolean isHeadsHead(ItemStack item) {
if (!Items.isSkull(item))
return false;
SkullMeta meta = (SkullMeta) item.getItemMeta();
// This needs to be kept too since it will not work on 1.8 if changed.
return meta.hasOwner() && meta.getOwner().equals("SpigotHeadPlugin");
}
@SuppressWarnings("deprecation")
private boolean isHeadsHead(Block block) {
BlockState state = block.getState();
if (!(state instanceof Skull))
@ -61,6 +63,7 @@ public class HeadNamer implements Listener {
Skull skull = (Skull) state;
// This needs to be kept too since it will not work on 1.8 if changed.
return skull.getOwner() != null && skull.getOwner().equals("SpigotHeadPlugin");
}

View File

@ -45,10 +45,12 @@ public class LegacyIDs {
}
}
@SuppressWarnings("deprecation")
public static LegacyIDs create() {
Map<Integer, String> idToType = new HashMap<>();
for (Material type : Material.values()) {
// This need to be kept for the legacy IDS for 1.13.
idToType.put(type.getId(), type.name());
}

View File

@ -1,7 +1,28 @@
package net.sothatsit.heads;
import java.util.List;
import org.bukkit.Location;
public class LiveHead {
// TODO: Add animation heads with live (cached) texures in the next updates.
private int frames;
private List<Heads> fases;
private Location location;
public LiveHead(int frames, List<Heads> fases, Location location /*.more.*/) {
// Safety first, experimental features should not crash servers.
if (frames > 60)
frames = 60;
this.frames = frames;
this.fases = fases;
this.location = location;
}
public void renderTexure() {
int interval = frames / 20;
// Render (but I am too tired for now).
// TODO: External classes from the animation packages.
}
}

View File

@ -1,114 +1,120 @@
package net.sothatsit.heads.api;
import com.google.common.collect.ImmutableList;
import net.sothatsit.heads.Heads;
import net.sothatsit.heads.cache.CacheHead;
import net.sothatsit.heads.util.Checks;
import net.sothatsit.heads.volatilecode.TextureGetter;
import org.bukkit.inventory.ItemStack;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import org.bukkit.inventory.ItemStack;
import com.google.common.collect.ImmutableList;
import net.sothatsit.heads.Heads;
import net.sothatsit.heads.cache.CacheHead;
import net.sothatsit.heads.util.Checks;
import net.sothatsit.heads.volatilecode.TextureGetter;
public class HeadsAPI {
public static class Head {
public static class Head {
private final CacheHead head;
private final CacheHead head;
private Head(CacheHead head) {
Checks.ensureNonNull(head, "head");
private Head(CacheHead head) {
Checks.ensureNonNull(head, "head");
this.head = head;
}
this.head = head;
}
public int getId() {
return head.getId();
}
public boolean isEnabled() {
return Heads.getInstance() != null;
}
public String getName() {
return head.getName();
}
public int getId() {
return head.getId();
}
public String getCategory() {
return head.getCategory();
}
public String getName() {
return head.getName();
}
public double getCost() {
return head.getCost();
}
public String getCategory() {
return head.getCategory();
}
public ItemStack getItem() {
return head.getItemStack();
}
public double getCost() {
return head.getCost();
}
public ItemStack getItem(String displayName) {
return head.getItemStack(displayName);
}
public ItemStack getItem() {
return head.getItemStack();
}
private static Head fromCacheHead(CacheHead head) {
return (head == null ? null : new Head(head));
}
public ItemStack getItem(String displayName) {
return head.getItemStack(displayName);
}
private static Head fromNameAndTexture(String name, String texture) {
return (texture == null ? null : fromCacheHead(new CacheHead(name, "HeadsAPI", texture)));
}
private static Head fromCacheHead(CacheHead head) {
return (head == null ? null : new Head(head));
}
private static List<Head> fromCacheHeads(List<CacheHead> heads) {
ImmutableList.Builder<Head> converted = ImmutableList.builder();
private static Head fromNameAndTexture(String name, String texture) {
return (texture == null ? null : fromCacheHead(new CacheHead(name, "HeadsAPI", texture)));
}
for(CacheHead head : heads) {
converted.add(Head.fromCacheHead(head));
}
private static List<Head> fromCacheHeads(List<CacheHead> heads) {
ImmutableList.Builder<Head> converted = ImmutableList.builder();
return converted.build();
}
for (CacheHead head : heads) {
converted.add(Head.fromCacheHead(head));
}
}
return converted.build();
}
public static Head getHead(int id) {
CacheHead head = Heads.getCache().findHead(id);
}
if(head == null)
return null;
public static Head getHead(int id) {
CacheHead head = Heads.getCache().findHead(id);
return new Head(head);
}
if (head == null)
return null;
@Deprecated
public static List<Head> searchHeads(String query) {
List<CacheHead> search = Heads.getCache().searchHeads(query);
return new Head(head);
}
return Head.fromCacheHeads(search);
}
@Deprecated
public static List<Head> searchHeads(String query) {
List<CacheHead> search = Heads.getCache().searchHeads(query);
public static void searchHeads(String query, Consumer<List<Head>> onResult) {
Heads.getCache().searchHeadsAsync(query, heads -> {
onResult.accept(Head.fromCacheHeads(heads));
});
}
return Head.fromCacheHeads(search);
}
public static Set<String> getCategories() {
return Heads.getCache().getCategories();
}
public static void searchHeads(String query, Consumer<List<Head>> onResult) {
Heads.getCache().searchHeadsAsync(query, heads -> {
onResult.accept(Head.fromCacheHeads(heads));
});
}
public static List<Head> getCategoryHeads(String category) {
List<CacheHead> categoryHeads = Heads.getCache().getCategoryHeads(category);
public static Set<String> getCategories() {
return Heads.getCache().getCategories();
}
return Head.fromCacheHeads(categoryHeads);
}
public static List<Head> getCategoryHeads(String category) {
List<CacheHead> categoryHeads = Heads.getCache().getCategoryHeads(category);
public static List<Head> getAllHeads() {
List<CacheHead> heads = Heads.getCache().getHeads();
return Head.fromCacheHeads(categoryHeads);
}
return Head.fromCacheHeads(heads);
}
public static List<Head> getAllHeads() {
List<CacheHead> heads = Heads.getCache().getHeads();
public static void downloadHead(String playerName, Consumer<Head> consumer) {
TextureGetter.getTexture(playerName, (texture) -> {
consumer.accept(Head.fromNameAndTexture(playerName, texture));
});
}
return Head.fromCacheHeads(heads);
}
public static void downloadHead(String playerName, Consumer<Head> consumer) {
TextureGetter.getTexture(playerName, (texture) -> {
consumer.accept(Head.fromNameAndTexture(playerName, texture));
});
}
}

View File

@ -1,5 +1,11 @@
package net.sothatsit.heads.command.admin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import net.sothatsit.heads.Heads;
import net.sothatsit.heads.cache.CacheHead;
import net.sothatsit.heads.command.AbstractCommand;
@ -10,111 +16,105 @@ import net.sothatsit.heads.volatilecode.Items;
import net.sothatsit.heads.volatilecode.TextureGetter;
import net.sothatsit.heads.volatilecode.reflection.Version;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
public class HandCommand extends AbstractCommand {
@Override
public String getCommandLabel(MainConfig config) {
return config.getHandCommand();
}
@Override
public String getCommandLabel(MainConfig config) {
return config.getHandCommand();
}
@Override
public String getPermission() {
return "heads.hand";
}
@Override
public String getPermission() {
return "heads.hand";
}
@Override
public Lang.HelpSection getHelp() {
return Lang.Command.Hand.help();
}
@Override
public Lang.HelpSection getHelp() {
return Lang.Command.Hand.help();
}
@Override
public boolean onCommand(final CommandSender sender, Command command, String label, final String[] args) {
if (!(sender instanceof Player)) {
Lang.Command.Errors.mustBePlayer().send(sender);
return true;
}
@Override
public boolean onCommand(final CommandSender sender, Command command, String label, final String[] args) {
if (!(sender instanceof Player)) {
Lang.Command.Errors.mustBePlayer().send(sender);
return true;
}
if (args.length < 3) {
sendInvalidArgs(sender);
return true;
}
if (args.length < 3) {
sendInvalidArgs(sender);
return true;
}
StringBuilder nameBuilder = new StringBuilder();
for (int i = 2; i < args.length; i++) {
nameBuilder.append(' ');
nameBuilder.append(args[i]);
}
StringBuilder nameBuilder = new StringBuilder();
for (int i = 2; i < args.length; i++) {
nameBuilder.append(' ');
nameBuilder.append(args[i]);
}
String name = nameBuilder.toString().substring(1);
String category = args[1];
String name = nameBuilder.toString().substring(1);
String category = args[1];
if (category.length() > 32) {
Lang.Command.Hand.categoryLength(category).send(sender);
return true;
}
if (category.length() > 32) {
Lang.Command.Hand.categoryLength(category).send(sender);
return true;
}
Player player = (Player) sender;
Player player = (Player) sender;
ItemStack hand = player.getInventory().getItemInMainHand();
ItemStack hand = player.getInventory().getItemInMainHand();
if(!Items.isSkull(hand)) {
Lang.Command.Hand.notSkull().send(sender);
return true;
}
if (!Items.isSkull(hand)) {
Lang.Command.Hand.notSkull().send(sender);
return true;
}
String texture = ItemNBT.getTextureProperty(hand);
String texture = ItemNBT.getTextureProperty(hand);
if (texture == null || texture.isEmpty()) {
Lang.Command.Hand.noTextureProperty().send(sender);
if (texture == null || texture.isEmpty()) {
Lang.Command.Hand.noTextureProperty().send(sender);
if (Version.v1_8.higherThan(Version.getVersion())) {
Lang.Command.Hand.notSupported().send(sender);
return true;
}
if (Version.v1_8.higherThan(Version.getVersion())) {
Lang.Command.Hand.notSupported().send(sender);
return true;
}
SkullMeta meta = (SkullMeta) hand.getItemMeta();
SkullMeta meta = (SkullMeta) hand.getItemMeta();
final String owner = meta.getOwner();
@SuppressWarnings("deprecation")
final String owner = meta.getOwner();
if (owner == null || owner.isEmpty()) {
Lang.Command.Hand.noNameProperty().send(sender);
return true;
}
if (owner == null || owner.isEmpty()) {
Lang.Command.Hand.noNameProperty().send(sender);
return true;
}
texture = TextureGetter.getCachedTexture(owner);
texture = TextureGetter.getCachedTexture(owner);
if (texture == null || texture.isEmpty()) {
Lang.Command.Hand.fetching().send(sender);
TextureGetter.getTexture(owner, (resolvedTexture) -> {
if (resolvedTexture == null || resolvedTexture.isEmpty()) {
Lang.Command.Hand.cantFind(owner).send(sender);
return;
}
if (texture == null || texture.isEmpty()) {
Lang.Command.Hand.fetching().send(sender);
TextureGetter.getTexture(owner, (resolvedTexture) -> {
if (resolvedTexture == null || resolvedTexture.isEmpty()) {
Lang.Command.Hand.cantFind(owner).send(sender);
return;
}
add(sender, category, name, resolvedTexture);
});
return true;
}
}
add(sender, category, name, resolvedTexture);
});
return true;
}
}
add(sender, category, name, texture);
return true;
}
add(sender, category, name, texture);
return true;
}
public void add(CommandSender sender, String category, String name, String texture) {
CacheHead head = new CacheHead(name, category, texture);
Heads.getCache().addHead(head);
Heads.getInstance().saveCache();
Lang.Command.Hand.adding(name, category).send(sender);
}
public void add(CommandSender sender, String category, String name, String texture) {
CacheHead head = new CacheHead(name, category, texture);
Heads.getCache().addHead(head);
Heads.getInstance().saveCache();
Lang.Command.Hand.adding(name, category).send(sender);
}
}

View File

@ -2,6 +2,13 @@ package net.sothatsit.heads.command.user;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import net.sothatsit.heads.cache.CacheHead;
import net.sothatsit.heads.command.AbstractCommand;
import net.sothatsit.heads.config.MainConfig;
@ -10,89 +17,82 @@ import net.sothatsit.heads.volatilecode.Items;
import net.sothatsit.heads.volatilecode.TextureGetter;
import net.sothatsit.heads.volatilecode.reflection.Version;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
public class GetCommand extends AbstractCommand {
@Override
public String getCommandLabel(MainConfig config) {
return config.getGetCommand();
}
@Override
public String getCommandLabel(MainConfig config) {
return config.getGetCommand();
}
@Override
public String getPermission() {
return "heads.get";
}
@Override
public String getPermission() {
return "heads.get";
}
@Override
public Lang.HelpSection getHelp() {
return Lang.Command.Get.help();
}
@Override
public Lang.HelpSection getHelp() {
return Lang.Command.Get.help();
}
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (!(sender instanceof Player)) {
Lang.Command.Errors.mustBePlayer().send(sender);
return true;
}
if (args.length != 2) {
sendInvalidArgs(sender);
return true;
}
if (Version.v1_8.higherThan(Version.getVersion())) {
Lang.Command.Get.oldMethod().send(sender);
@SuppressWarnings("deprecation")
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (!(sender instanceof Player)) {
Lang.Command.Errors.mustBePlayer().send(sender);
return true;
}
ItemStack head = Items.createSkull().build();
SkullMeta meta = (SkullMeta) head.getItemMeta();
meta.setOwner(args[1]);
meta.setDisplayName(Lang.Command.Get.headName(args[1]).getSingle());
head.setItemMeta(meta);
Lang.Command.Get.adding(args[1]).send(sender);
((Player) sender).getInventory().addItem(head);
return true;
}
if (args.length != 2) {
sendInvalidArgs(sender);
return true;
}
String texture = TextureGetter.getCachedTexture(args[1]);
if (Version.v1_8.higherThan(Version.getVersion())) {
Lang.Command.Get.oldMethod().send(sender);
if (texture != null) {
giveHead((Player) sender, args[1], texture);
return true;
}
ItemStack head = Items.createSkull().build();
SkullMeta meta = (SkullMeta) head.getItemMeta();
Lang.Command.Get.fetching().send(sender);
meta.setOwner(args[1]);
meta.setDisplayName(Lang.Command.Get.headName(args[1]).getSingle());
final UUID uuid = ((Player) sender).getUniqueId();
final String name = args[1];
head.setItemMeta(meta);
TextureGetter.getTexture(name, (resolvedTexture) -> {
giveHead(Bukkit.getPlayer(uuid), name, resolvedTexture);
});
return true;
}
Lang.Command.Get.adding(args[1]).send(sender);
((Player) sender).getInventory().addItem(head);
return true;
}
public void giveHead(Player player, String name, String texture) {
if (player != null) {
if (texture == null || texture.isEmpty()) {
Lang.Command.Get.cantFind(name).send(player);
return;
}
String texture = TextureGetter.getCachedTexture(args[1]);
CacheHead head = new CacheHead(name, "getcommand", texture);
if (texture != null) {
giveHead((Player) sender, args[1], texture);
return true;
}
Lang.Command.Get.adding(name).send(player);
Lang.Command.Get.fetching().send(sender);
player.getInventory().addItem(head.getItemStack());
}
}
final UUID uuid = ((Player) sender).getUniqueId();
final String name = args[1];
TextureGetter.getTexture(name, (resolvedTexture) -> {
giveHead(Bukkit.getPlayer(uuid), name, resolvedTexture);
});
return true;
}
public void giveHead(Player player, String name, String texture) {
if (player != null) {
if (texture == null || texture.isEmpty()) {
Lang.Command.Get.cantFind(name).send(player);
return;
}
CacheHead head = new CacheHead(name, "getcommand", texture);
Lang.Command.Get.adding(name).send(player);
player.getInventory().addItem(head.getItemStack());
}
}
}

View File

@ -1,95 +1,94 @@
package net.sothatsit.heads.config.menu;
import net.sothatsit.heads.Heads;
import net.sothatsit.heads.config.ConfigFile;
import net.sothatsit.heads.config.FileConfigFile;
import net.sothatsit.heads.menu.CacheHeadsMenu;
import net.sothatsit.heads.menu.CategoriesMenu;
import net.sothatsit.heads.menu.HeadsMenu;
import net.sothatsit.heads.menu.ui.item.Item;
import net.sothatsit.heads.menu.ui.element.Scrollbar;
import net.sothatsit.heads.menu.ui.element.PagedBox;
import net.sothatsit.heads.util.Checks;
import java.util.concurrent.atomic.AtomicBoolean;
import net.sothatsit.heads.Heads;
import net.sothatsit.heads.config.ConfigFile;
import net.sothatsit.heads.menu.CacheHeadsMenu;
import net.sothatsit.heads.menu.CategoriesMenu;
import net.sothatsit.heads.menu.HeadsMenu;
import net.sothatsit.heads.menu.ui.element.PagedBox;
import net.sothatsit.heads.menu.ui.element.Scrollbar;
import net.sothatsit.heads.menu.ui.item.Item;
import net.sothatsit.heads.util.Checks;
public class MenuConfig {
private final ConfigFile config;
private final AtomicBoolean requiresSave;
private final ConfigFile config;
private final AtomicBoolean requiresSave;
public MenuConfig(String fileName) {
this(Heads.getVersionedConfig(fileName));
}
public MenuConfig(String fileName) {
this(Heads.getVersionedConfig(fileName));
}
public MenuConfig(ConfigFile config) {
Checks.ensureNonNull(config, "configFile");
public MenuConfig(ConfigFile config) {
Checks.ensureNonNull(config, "configFile");
this.config = config;
this.requiresSave = new AtomicBoolean(false);
}
this.config = config;
this.requiresSave = new AtomicBoolean(false);
}
public void load() {
config.copyDefaults();
config.reload();
public void load() {
config.copyDefaults();
config.reload();
requiresSave.set(false);
}
requiresSave.set(false);
}
public void saveIfChanged() {
if(!requiresSave.get())
return;
public void saveIfChanged() {
if (!requiresSave.get())
return;
config.save();
}
config.save();
}
public Scrollbar.Template loadScrollbar(String key) {
Item left = config.getOrCopyDefault(key + ".left", Scrollbar.defaultLeft, requiresSave);
Item right = config.getOrCopyDefault(key + ".right", Scrollbar.defaultRight, requiresSave);
Item noLeft = config.getOrCopyDefault(key + ".no-left", Scrollbar.defaultNoLeft, requiresSave);
Item noRight = config.getOrCopyDefault(key + ".no-right", Scrollbar.defaultNoRight, requiresSave);
Item filler = config.getOrCopyDefault(key + ".filler", Scrollbar.defaultFiller, requiresSave);
public Scrollbar.Template loadScrollbar(String key) {
Item left = config.getOrCopyDefault(key + ".left", Scrollbar.defaultLeft, requiresSave);
Item right = config.getOrCopyDefault(key + ".right", Scrollbar.defaultRight, requiresSave);
Item noLeft = config.getOrCopyDefault(key + ".no-left", Scrollbar.defaultNoLeft, requiresSave);
Item noRight = config.getOrCopyDefault(key + ".no-right", Scrollbar.defaultNoRight, requiresSave);
Item filler = config.getOrCopyDefault(key + ".filler", Scrollbar.defaultFiller, requiresSave);
return new Scrollbar.Template(left, right, noLeft, noRight, filler);
}
return new Scrollbar.Template(left, right, noLeft, noRight, filler);
}
public PagedBox.Template loadPagedBox(String key) {
Item unselected = config.getOrCopyDefault(key + ".unselected-page", PagedBox.defaultUnselected, requiresSave);
Item selected = config.getOrCopyDefault(key + ".selected-page", PagedBox.defaultSelected, requiresSave);
public PagedBox.Template loadPagedBox(String key) {
Item unselected = config.getOrCopyDefault(key + ".unselected-page", PagedBox.defaultUnselected, requiresSave);
Item selected = config.getOrCopyDefault(key + ".selected-page", PagedBox.defaultSelected, requiresSave);
Scrollbar.Template scrollbar = loadScrollbar(key + ".scrollbar");
Scrollbar.Template scrollbar = loadScrollbar(key + ".scrollbar");
return new PagedBox.Template(scrollbar, unselected, selected);
}
return new PagedBox.Template(scrollbar, unselected, selected);
}
public CategoriesMenu.Template loadCategoriesMenu(String key) {
Item category = config.getOrCopyDefault(key + ".category", CategoriesMenu.defaultCategoryItem, requiresSave);
public CategoriesMenu.Template loadCategoriesMenu(String key) {
Item category = config.getOrCopyDefault(key + ".category", CategoriesMenu.defaultCategoryItem, requiresSave);
PagedBox.Template pagedBoxTemplate = loadPagedBox(key);
PagedBox.Template pagedBoxTemplate = loadPagedBox(key);
return new CategoriesMenu.Template(pagedBoxTemplate, category);
}
return new CategoriesMenu.Template(pagedBoxTemplate, category);
}
public HeadsMenu.Template loadHeadsMenu(String key) {
Item head = config.getOrCopyDefault(key + ".head", HeadsMenu.defaultHead, requiresSave);
public HeadsMenu.Template loadHeadsMenu(String key) {
Item head = config.getOrCopyDefault(key + ".head", HeadsMenu.defaultHead, requiresSave);
PagedBox.Template pagedBoxTemplate = loadPagedBox(key);
PagedBox.Template pagedBoxTemplate = loadPagedBox(key);
return new HeadsMenu.Template(pagedBoxTemplate, head);
}
return new HeadsMenu.Template(pagedBoxTemplate, head);
}
public CacheHeadsMenu.Template loadCacheHeadsMenu(String key) {
String categoriesTitle = config.getOrCopyDefault(key + ".categories-title", CacheHeadsMenu.defaultCategoriesTitle, requiresSave);
String categoryTitle = config.getOrCopyDefault(key + ".category-title", CacheHeadsMenu.defaultCategoryTitle, requiresSave);
public CacheHeadsMenu.Template loadCacheHeadsMenu(String key) {
String categoriesTitle = config.getOrCopyDefault(key + ".categories-title", CacheHeadsMenu.defaultCategoriesTitle, requiresSave);
String categoryTitle = config.getOrCopyDefault(key + ".category-title", CacheHeadsMenu.defaultCategoryTitle, requiresSave);
Item close = config.getOrCopyDefault(key + ".close", CacheHeadsMenu.defaultClose, requiresSave);
Item back = config.getOrCopyDefault(key + ".back", CacheHeadsMenu.defaultBack, requiresSave);
Item search = config.getOrCopyDefault(key + ".search", CacheHeadsMenu.defaultSearch, requiresSave);
Item close = config.getOrCopyDefault(key + ".close", CacheHeadsMenu.defaultClose, requiresSave);
Item back = config.getOrCopyDefault(key + ".back", CacheHeadsMenu.defaultBack, requiresSave);
Item search = config.getOrCopyDefault(key + ".search", CacheHeadsMenu.defaultSearch, requiresSave);
CategoriesMenu.Template categoriesTemplate = loadCategoriesMenu(key + ".categories");
HeadsMenu.Template headsTemplate = loadHeadsMenu(key + ".heads");
CategoriesMenu.Template categoriesTemplate = loadCategoriesMenu(key + ".categories");
HeadsMenu.Template headsTemplate = loadHeadsMenu(key + ".heads");
return new CacheHeadsMenu.Template(categoriesTemplate, headsTemplate, close, back, search, categoriesTitle, categoryTitle);
}
return new CacheHeadsMenu.Template(categoriesTemplate, headsTemplate, close, back, search, categoriesTitle, categoryTitle);
}
}

View File

@ -1,101 +1,98 @@
package net.sothatsit.heads.config.oldmenu;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import org.bukkit.configuration.ConfigurationSection;
import net.sothatsit.heads.Heads;
import net.sothatsit.heads.config.ConfigFile;
import net.sothatsit.heads.util.Clock;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
public class MenuConfig {
private final ConfigurationSection defaults;
private final ConfigFile configFile;
private final Map<String, Menu> menus;
private final Map<String, Menu> defaultMenus;
public MenuConfig(ConfigFile configFile) {
this.menus = new HashMap<>();
this.defaultMenus = new HashMap<>();
this.configFile = configFile;
this.defaults = loadDefaults();
private final ConfigurationSection defaults;
private final ConfigFile configFile;
private final Map<String, Menu> menus;
private final Map<String, Menu> defaultMenus;
reload();
}
public MenuConfig(ConfigFile configFile) {
this.menus = new HashMap<>();
this.defaultMenus = new HashMap<>();
public Menu getMenu(String name) {
Menu menu = menus.get(name.toLowerCase());
this.configFile = configFile;
this.defaults = loadDefaults();
return (menu != null ? menu : defaultMenus.get(name.toLowerCase()));
}
public void reload() {
Clock timer = Clock.start();
configFile.copyDefaults();
configFile.reload();
reload();
}
String filename = configFile.getName();
ConfigurationSection config = configFile.getConfig();
AtomicBoolean shouldSave = new AtomicBoolean(false);
public Menu getMenu(String name) {
Menu menu = menus.get(name.toLowerCase());
menus.clear();
return (menu != null ? menu : defaultMenus.get(name.toLowerCase()));
}
for (String key : config.getKeys(false)) {
if (!config.isConfigurationSection(key)) {
Heads.warning("Unknown use of value " + key + " in " + filename);
continue;
}
public void reload() {
Clock timer = Clock.start();
ConfigurationSection menuSection = config.getConfigurationSection(key);
configFile.copyDefaults();
configFile.reload();
Menu defaultMenu = defaultMenus.get(key.toLowerCase());
Menu menu = Menu.loadMenu(filename, menuSection, shouldSave, defaultMenu);
menus.put(key.toLowerCase(), menu);
}
for (String key : defaultMenus.keySet()) {
if(menus.containsKey(key))
continue;
String filename = configFile.getName();
ConfigurationSection config = configFile.getConfig();
AtomicBoolean shouldSave = new AtomicBoolean(false);
config.set(key, defaults.getConfigurationSection(key));
menus.clear();
Heads.warning(key + " was missing in " + filename + ", creating it");
shouldSave.set(true);
}
if (shouldSave.get()) {
configFile.save();
}
Heads.info("Loaded Menu Config with " + menus.size() + " Menus " + timer);
}
for (String key : config.getKeys(false)) {
if (!config.isConfigurationSection(key)) {
Heads.warning("Unknown use of value " + key + " in " + filename);
continue;
}
private ConfigurationSection loadDefaults() {
String filename = configFile.getName();
ConfigurationSection config = configFile.getDefaults();
AtomicBoolean shouldSave = new AtomicBoolean(false);
ConfigurationSection menuSection = config.getConfigurationSection(key);
defaultMenus.clear();
Menu defaultMenu = defaultMenus.get(key.toLowerCase());
Menu menu = Menu.loadMenu(filename, menuSection, shouldSave, defaultMenu);
for (String key : config.getKeys(false)) {
if (!config.isConfigurationSection(key))
continue;
menus.put(key.toLowerCase(), menu);
}
ConfigurationSection menuSection = config.getConfigurationSection(key);
for (String key : defaultMenus.keySet()) {
if (menus.containsKey(key))
continue;
defaultMenus.put(key.toLowerCase(), Menu.loadMenu(filename, menuSection, shouldSave));
}
config.set(key, defaults.getConfigurationSection(key));
return config;
}
Heads.warning(key + " was missing in " + filename + ", creating it");
shouldSave.set(true);
}
if (shouldSave.get()) {
configFile.save();
}
Heads.info("Loaded Menu Config with " + menus.size() + " Menus " + timer);
}
private ConfigurationSection loadDefaults() {
String filename = configFile.getName();
ConfigurationSection config = configFile.getDefaults();
AtomicBoolean shouldSave = new AtomicBoolean(false);
defaultMenus.clear();
for (String key : config.getKeys(false)) {
if (!config.isConfigurationSection(key))
continue;
ConfigurationSection menuSection = config.getConfigurationSection(key);
defaultMenus.put(key.toLowerCase(), Menu.loadMenu(filename, menuSection, shouldSave));
}
return config;
}
}

View File

@ -23,6 +23,7 @@ import net.sothatsit.heads.util.Stringify;
import net.sothatsit.heads.volatilecode.ItemNBT;
import net.sothatsit.heads.volatilecode.reflection.Version;
@SuppressWarnings("deprecation")
public final class Item {
private final Material type;
@ -205,6 +206,7 @@ public final class Item {
return new Item(type, 1, data, null, null, false);
}
return new Item(type, 1, (short) 0, null, null, false);
// TODO: Needs manual testing on 1.13.
}
public static Item create(ItemStack itemStack) {
@ -361,6 +363,7 @@ public final class Item {
return Material.matchMaterial(typeName, true);
}
// Need to be kept, will look for an alternative in the future.
public static Material fromLegacyType(Material legacyType, byte data) {
return Bukkit.getUnsafe().fromLegacy(new MaterialData(legacyType, data));
}

View File

@ -1,56 +1,55 @@
package net.sothatsit.heads.oldmenu.mode;
import net.sothatsit.heads.Heads;
import net.sothatsit.heads.config.oldmenu.Menus;
import net.sothatsit.heads.cache.CacheHead;
import net.sothatsit.heads.config.oldmenu.Menu;
import net.sothatsit.heads.config.lang.Lang;
import net.sothatsit.heads.economy.Economy;
import net.sothatsit.heads.oldmenu.ConfirmMenu;
import net.sothatsit.heads.oldmenu.HeadMenu;
import net.sothatsit.heads.oldmenu.InventoryType;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import net.sothatsit.heads.Heads;
import net.sothatsit.heads.cache.CacheHead;
import net.sothatsit.heads.config.lang.Lang;
import net.sothatsit.heads.config.oldmenu.Menu;
import net.sothatsit.heads.config.oldmenu.Menus;
import net.sothatsit.heads.oldmenu.ConfirmMenu;
import net.sothatsit.heads.oldmenu.HeadMenu;
import net.sothatsit.heads.oldmenu.InventoryType;
public class GetMode extends BaseMode {
public GetMode(Player player) {
super(player);
Lang.Menu.Get.open().send(player);
}
@Override
public Menu getMenu(InventoryType type) {
return Menus.GET.fromType(type);
}
@Override
public void onHeadSelect(InventoryClickEvent e, HeadMenu menu, CacheHead head) {
Player player = getPlayer();
if(!Heads.getInstance().chargeForHead(player, head))
return;
Lang.Menu.Get.added(head.getName()).send(player);
public GetMode(Player player) {
super(player);
Lang.Menu.Get.open().send(player);
}
@Override
public Menu getMenu(InventoryType type) {
return Menus.GET.fromType(type);
}
@Override
public void onHeadSelect(InventoryClickEvent e, HeadMenu menu, CacheHead head) {
Player player = getPlayer();
if (!Heads.getInstance().chargeForHead(player, head))
return;
Lang.Menu.Get.added(head.getName()).send(player);
player.getInventory().addItem(head.getItemStack());
}
@Override
public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) {
// should not be reached
}
@Override
public boolean canOpenCategory(String category) {
if (getPlayer().hasPermission("heads.category." + category.toLowerCase().replace(' ', '_'))) {
return true;
} else {
Lang.Menu.Get.categoryPermission(category).send(getPlayer());
return false;
}
}
player.getInventory().addItem(head.getItemStack());
}
@Override
public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) {
// should not be reached
}
@Override
public boolean canOpenCategory(String category) {
if (getPlayer().hasPermission("heads.category." + category.toLowerCase().replace(' ', '_'))) {
return true;
} else {
Lang.Menu.Get.categoryPermission(category).send(getPlayer());
return false;
}
}
}

View File

@ -1,63 +1,63 @@
package net.sothatsit.heads.oldmenu.mode;
import net.sothatsit.heads.Heads;
import net.sothatsit.heads.config.oldmenu.Menus;
import net.sothatsit.heads.cache.CacheHead;
import net.sothatsit.heads.config.oldmenu.Menu;
import net.sothatsit.heads.config.lang.Lang;
import net.sothatsit.heads.economy.Economy;
import net.sothatsit.heads.oldmenu.ConfirmMenu;
import net.sothatsit.heads.oldmenu.HeadMenu;
import net.sothatsit.heads.oldmenu.InventoryType;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import net.sothatsit.heads.Heads;
import net.sothatsit.heads.cache.CacheHead;
import net.sothatsit.heads.config.lang.Lang;
import net.sothatsit.heads.config.oldmenu.Menu;
import net.sothatsit.heads.config.oldmenu.Menus;
import net.sothatsit.heads.oldmenu.ConfirmMenu;
import net.sothatsit.heads.oldmenu.HeadMenu;
import net.sothatsit.heads.oldmenu.InventoryType;
public class SearchMode extends BaseMode {
public SearchMode(Player player, List<CacheHead> heads) {
super(player, InventoryType.HEADS, "Search", heads);
}
@Override
public Menu getMenu(InventoryType type) {
return Menus.SEARCH.heads();
}
public SearchMode(Player player, List<CacheHead> heads) {
super(player, InventoryType.HEADS, "Search", heads);
}
public String getHeadId(CacheHead head) {
if(!getPlayer().hasPermission("heads.category." + head.getCategory().toLowerCase().replace(' ', '_'))) {
return "head-no-perms";
} else {
return (head.hasCost() && Heads.getMainConfig().isEconomyEnabled() ? "head-cost" : "head");
}
}
@Override
public void onHeadSelect(InventoryClickEvent e, HeadMenu menu, CacheHead head) {
Player player = getPlayer();
@Override
public Menu getMenu(InventoryType type) {
return Menus.SEARCH.heads();
}
if (!player.hasPermission("heads.category." + head.getCategory().toLowerCase().replace(' ', '_'))) {
Lang.Menu.Search.categoryPermission(head.getCategory()).send(getPlayer());
return;
}
public String getHeadId(CacheHead head) {
if (!getPlayer().hasPermission("heads.category." + head.getCategory().toLowerCase().replace(' ', '_'))) {
return "head-no-perms";
} else {
return (head.hasCost() && Heads.getMainConfig().isEconomyEnabled() ? "head-cost" : "head");
}
}
if(!Heads.getInstance().chargeForHead(player, head))
return;
Lang.Menu.Search.added(head.getName()).send(player);
@Override
public void onHeadSelect(InventoryClickEvent e, HeadMenu menu, CacheHead head) {
Player player = getPlayer();
if (!player.hasPermission("heads.category." + head.getCategory().toLowerCase().replace(' ', '_'))) {
Lang.Menu.Search.categoryPermission(head.getCategory()).send(getPlayer());
return;
}
if (!Heads.getInstance().chargeForHead(player, head))
return;
Lang.Menu.Search.added(head.getName()).send(player);
player.getInventory().addItem(head.getItemStack());
}
@Override
public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) {
// should not be reached
}
@Override
public boolean canOpenCategory(String category) {
return true;
}
player.getInventory().addItem(head.getItemStack());
}
@Override
public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) {
// should not be reached
}
@Override
public boolean canOpenCategory(String category) {
return true;
}
}

View File

@ -1,7 +1,7 @@
main: net.sothatsit.heads.Heads
author: Marido
name: Heads
version: 2.0.2
version: 2.0.3
api-version: 1.13
softdepend: [Vault, PlayerPoints, BlockStore]
loadbefore: [DeluxeMenus]