Removed static methods from main class.
This commit is contained in:
parent
52c8864d27
commit
f4e64eea02
|
@ -98,7 +98,7 @@ public class EpicHeads extends JavaPlugin implements Listener {
|
|||
|
||||
ProtocolHackFixer.fix();
|
||||
tryHookBlockStore();
|
||||
new HeadNamer().registerEvents();
|
||||
new HeadNamer(this).registerEvents();
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
console.sendMessage(Methods.formatText(getDescription().getName() + " has been enabled with " + cache.getHeadCount() + " heads " + timer + "."));
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
|
@ -301,7 +301,7 @@ public class EpicHeads extends JavaPlugin implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isExemptFromCost(Player player) {
|
||||
private boolean isExemptFromCost(Player player) {
|
||||
if (!mainConfig.isEconomyEnabled() || player.hasPermission("EpicHeads.bypasscost"))
|
||||
return true;
|
||||
|
||||
|
@ -309,7 +309,6 @@ public class EpicHeads extends JavaPlugin implements Listener {
|
|||
}
|
||||
|
||||
public boolean chargeForHead(Player player, CacheHead head) {
|
||||
EpicHeads instance = EpicHeads.getInstance();
|
||||
if (isExemptFromCost(player))
|
||||
return true;
|
||||
|
||||
|
@ -319,20 +318,20 @@ public class EpicHeads extends JavaPlugin implements Listener {
|
|||
return true;
|
||||
|
||||
if (!economy.hasBalance(player, cost)) {
|
||||
player.sendMessage(instance.getLocale().getMessage("interface.get.notenoughmoney", head.getName(), head.getCost()));
|
||||
player.sendMessage(getLocale().getMessage("interface.get.notenoughmoney", head.getName(), head.getCost()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!economy.takeBalance(player, cost)) {
|
||||
player.sendMessage(instance.getLocale().getMessage("interface.get.transactionerror", head.getName(), head.getCost()));
|
||||
player.sendMessage(getLocale().getMessage("interface.get.transactionerror", head.getName(), head.getCost()));
|
||||
return false;
|
||||
}
|
||||
|
||||
player.sendMessage(instance.getLocale().getMessage("interface.get.purchased", head.getName(), head.getCost()));
|
||||
player.sendMessage(getLocale().getMessage("interface.get.purchased", head.getName(), head.getCost()));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getCategoryPermission(String category) {
|
||||
public String getCategoryPermission(String category) {
|
||||
return "EpicHeads.category." + category.toLowerCase().replace(' ', '_');
|
||||
}
|
||||
|
||||
|
@ -341,39 +340,39 @@ public class EpicHeads extends JavaPlugin implements Listener {
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static LegacyIDs getLegacyIDs() {
|
||||
public LegacyIDs getLegacyIDs() {
|
||||
return INSTANCE.legacyIDs;
|
||||
}
|
||||
|
||||
public static MainConfig getMainConfig() {
|
||||
public MainConfig getMainConfig() {
|
||||
return INSTANCE.mainConfig;
|
||||
}
|
||||
|
||||
public static CacheFile getCache() {
|
||||
public CacheFile getCache() {
|
||||
return INSTANCE.cache;
|
||||
}
|
||||
|
||||
public static Menus getMenus() {
|
||||
public Menus getMenus() {
|
||||
return INSTANCE.menus;
|
||||
}
|
||||
|
||||
public static MenuConfig getMenuConfig() {
|
||||
public MenuConfig getMenuConfig() {
|
||||
return INSTANCE.oldMenuConfig;
|
||||
}
|
||||
|
||||
public static Economy getEconomy() {
|
||||
public Economy getEconomy() {
|
||||
return INSTANCE.economy;
|
||||
}
|
||||
|
||||
public static boolean isBlockStoreAvailable() {
|
||||
public boolean isBlockStoreAvailable() {
|
||||
return INSTANCE.blockStoreAvailable;
|
||||
}
|
||||
|
||||
public static void sync(Runnable task) {
|
||||
public void sync(Runnable task) {
|
||||
Bukkit.getScheduler().runTask(INSTANCE, task);
|
||||
}
|
||||
|
||||
public static FileConfigFile getVersionedConfig(String resource) {
|
||||
public FileConfigFile getVersionedConfig(String resource) {
|
||||
if (Version.isBelow(Version.v1_13))
|
||||
return new FileConfigFile(resource, "pre1_13/" + resource);
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public class EpicHeadsAPI {
|
|||
}
|
||||
|
||||
public static Head getHead(int id) {
|
||||
CacheHead head = EpicHeads.getCache().findHead(id);
|
||||
CacheHead head = EpicHeads.getInstance().getCache().findHead(id);
|
||||
if (head == null)
|
||||
return null;
|
||||
return new Head(head);
|
||||
|
@ -77,27 +77,27 @@ public class EpicHeadsAPI {
|
|||
|
||||
@Deprecated
|
||||
public static List<Head> searchHeads(String query) {
|
||||
List<CacheHead> search = EpicHeads.getCache().searchHeads(query);
|
||||
List<CacheHead> search = EpicHeads.getInstance().getCache().searchHeads(query);
|
||||
return Head.fromCacheHeads(search);
|
||||
}
|
||||
|
||||
public static void searchHeads(String query, Consumer<List<Head>> onResult) {
|
||||
EpicHeads.getCache().searchHeadsAsync(query, heads -> {
|
||||
EpicHeads.getInstance().getCache().searchHeadsAsync(query, heads -> {
|
||||
onResult.accept(Head.fromCacheHeads(heads));
|
||||
});
|
||||
}
|
||||
|
||||
public static Set<String> getCategories() {
|
||||
return EpicHeads.getCache().getCategories();
|
||||
return EpicHeads.getInstance().getCache().getCategories();
|
||||
}
|
||||
|
||||
public static List<Head> getCategoryHeads(String category) {
|
||||
List<CacheHead> categoryHeads = EpicHeads.getCache().getCategoryHeads(category);
|
||||
List<CacheHead> categoryHeads = EpicHeads.getInstance().getCache().getCategoryHeads(category);
|
||||
return Head.fromCacheHeads(categoryHeads);
|
||||
}
|
||||
|
||||
public static List<Head> getAllHeads() {
|
||||
List<CacheHead> heads = EpicHeads.getCache().getHeads();
|
||||
List<CacheHead> heads = EpicHeads.getInstance().getCache().getHeads();
|
||||
return Head.fromCacheHeads(heads);
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ public final class CacheFile implements Mod {
|
|||
public void run() {
|
||||
List<CacheHead> matches = Search.searchHeads(query, headsCopy, 0.4d);
|
||||
|
||||
EpicHeads.sync(() -> onResult.accept(matches));
|
||||
EpicHeads.getInstance().sync(() -> onResult.accept(matches));
|
||||
}
|
||||
}.runTaskAsynchronously(EpicHeads.getInstance());
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public final class CacheHead implements Comparable<CacheHead> {
|
|||
}
|
||||
|
||||
public String getPermission() {
|
||||
return EpicHeads.getCategoryPermission(category);
|
||||
return EpicHeads.getInstance().getCategoryPermission(category);
|
||||
}
|
||||
|
||||
public String getTexture() {
|
||||
|
@ -93,7 +93,7 @@ public final class CacheHead implements Comparable<CacheHead> {
|
|||
}
|
||||
|
||||
public double getCost() {
|
||||
return (hasCost() ? cost : EpicHeads.getMainConfig().getCategoryCost(category));
|
||||
return (hasCost() ? cost : EpicHeads.getInstance().getMainConfig().getCategoryCost(category));
|
||||
}
|
||||
|
||||
public double getRawCost() {
|
||||
|
|
|
@ -64,8 +64,8 @@ public class CommandAdd extends AbstractCommand {
|
|||
|
||||
CacheHead head = new CacheHead(name, category, texture);
|
||||
|
||||
EpicHeads.getCache().addHead(head);
|
||||
EpicHeads.getInstance().saveCache();
|
||||
instance.getCache().addHead(head);
|
||||
instance.saveCache();
|
||||
|
||||
sender.sendMessage(instance.getLocale().getMessage("command.add.added", name, category));
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class CommandGive extends AbstractCommand {
|
|||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
CacheHead head = EpicHeads.getCache().findHead(id);
|
||||
CacheHead head = EpicHeads.getInstance().getCache().findHead(id);
|
||||
|
||||
if (head == null) {
|
||||
sender.sendMessage(instance.getLocale().getMessage("command.give.cantfindhead", id));
|
||||
|
|
|
@ -86,7 +86,7 @@ public class CommandHand extends AbstractCommand {
|
|||
public void add(EpicHeads instance, CommandSender sender, String category, String name, String texture) {
|
||||
CacheHead head = new CacheHead(name, category, texture);
|
||||
|
||||
EpicHeads.getCache().addHead(head);
|
||||
EpicHeads.getInstance().getCache().addHead(head);
|
||||
EpicHeads.getInstance().saveCache();
|
||||
|
||||
sender.sendMessage(instance.getLocale().getMessage("command.add.added", name, category));
|
||||
|
|
|
@ -32,7 +32,7 @@ public class CommandId extends AbstractCommand {
|
|||
}
|
||||
|
||||
String texture = ItemNBT.getTextureProperty(hand);
|
||||
CacheHead head = EpicHeads.getCache().findHeadByTexture(texture);
|
||||
CacheHead head = EpicHeads.getInstance().getCache().findHeadByTexture(texture);
|
||||
if (head == null) {
|
||||
ItemMeta meta = hand.getItemMeta();
|
||||
String name = ChatColor.stripColor(meta.hasDisplayName() ? meta.getDisplayName() : "");
|
||||
|
|
|
@ -54,7 +54,7 @@ public class CommandItemEco extends AbstractCommand {
|
|||
|
||||
Item item = Item.create(itemStack).amount(1);
|
||||
|
||||
EpicHeads.getMainConfig().setItemEcoItem(item);
|
||||
EpicHeads.getInstance().getMainConfig().setItemEcoItem(item);
|
||||
|
||||
player.sendMessage(instance.getLocale().getMessage("command.itemeco.set"));
|
||||
return ReturnType.SUCCESS;
|
||||
|
@ -127,7 +127,7 @@ public class CommandItemEco extends AbstractCommand {
|
|||
int giveAmount = Math.min(64, amount);
|
||||
amount -= giveAmount;
|
||||
|
||||
ItemStack itemStack = EpicHeads.getMainConfig().getItemEconomyItem().amount(giveAmount).build();
|
||||
ItemStack itemStack = EpicHeads.getInstance().getMainConfig().getItemEconomyItem().amount(giveAmount).build();
|
||||
|
||||
if (player.getInventory().firstEmpty() != -1) {
|
||||
player.getInventory().addItem(itemStack);
|
||||
|
|
|
@ -23,12 +23,12 @@ public class CommandRandom extends AbstractCommand {
|
|||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if (EpicHeads.getCache().getHeadCount() == 0) {
|
||||
if (EpicHeads.getInstance().getCache().getHeadCount() == 0) {
|
||||
sender.sendMessage(instance.getLocale().getMessage("command.random.noheads"));
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
CacheHead random = EpicHeads.getCache().getRandomHead(RANDOM);
|
||||
CacheHead random = EpicHeads.getInstance().getCache().getRandomHead(RANDOM);
|
||||
|
||||
if (args.length == 1) {
|
||||
if (!(sender instanceof Player)) {
|
||||
|
|
|
@ -27,7 +27,7 @@ public class CommandSearch extends AbstractCommand {
|
|||
|
||||
String query = queryBuilder.toString().trim();
|
||||
|
||||
EpicHeads.getCache().searchHeadsAsync(query, matches -> {
|
||||
EpicHeads.getInstance().getCache().searchHeadsAsync(query, matches -> {
|
||||
if (matches.size() == 0) {
|
||||
|
||||
sender.sendMessage(instance.getLocale().getMessage("command.search.nonefound", query));
|
||||
|
|
|
@ -56,7 +56,7 @@ public class MainConfig {
|
|||
private String helpLabel;
|
||||
|
||||
public MainConfig() {
|
||||
this.configFile = EpicHeads.getVersionedConfig("config.yml");
|
||||
this.configFile = EpicHeads.getInstance().getVersionedConfig("config.yml");
|
||||
|
||||
reload();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public class MenuConfig {
|
|||
private final AtomicBoolean requiresSave;
|
||||
|
||||
public MenuConfig(String fileName) {
|
||||
this(EpicHeads.getVersionedConfig(fileName));
|
||||
this(EpicHeads.getInstance().getVersionedConfig(fileName));
|
||||
}
|
||||
|
||||
public MenuConfig(ConfigFile config) {
|
||||
|
|
|
@ -49,7 +49,7 @@ public class Menu {
|
|||
}
|
||||
|
||||
private Function<String, Boolean> getItemLoreFilter() {
|
||||
return EpicHeads.getMainConfig().isEconomyEnabled() ? null : FILTER_ECONOMY_LINES_OUT;
|
||||
return EpicHeads.getInstance().getMainConfig().isEconomyEnabled() ? null : FILTER_ECONOMY_LINES_OUT;
|
||||
}
|
||||
|
||||
public void load(String filename, ConfigurationSection section, AtomicBoolean shouldSave) {
|
||||
|
|
|
@ -21,7 +21,7 @@ public class Menus {
|
|||
public static final MenusGroup ID = new MenusGroup("id");
|
||||
|
||||
public static Menu get(String name) {
|
||||
return EpicHeads.getMenuConfig().getMenu(name);
|
||||
return EpicHeads.getInstance().getMenuConfig().getMenu(name);
|
||||
}
|
||||
|
||||
public static class MenusGroup {
|
||||
|
|
|
@ -11,7 +11,7 @@ public class ItemEconomy implements Economy {
|
|||
if (itemStack == null)
|
||||
return false;
|
||||
Item item = Item.create(itemStack).amount(1);
|
||||
return item.equals(EpicHeads.getMainConfig().getItemEconomyItem());
|
||||
return item.equals(EpicHeads.getInstance().getMainConfig().getItemEconomyItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,13 +32,19 @@ import java.util.List;
|
|||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class HeadNamer implements Listener {
|
||||
|
||||
private final EpicHeads instance;
|
||||
|
||||
public HeadNamer(EpicHeads instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void registerEvents() {
|
||||
Bukkit.getPluginManager().registerEvents(this, EpicHeads.getInstance());
|
||||
}
|
||||
|
||||
private boolean shouldUseBlockStore() {
|
||||
return EpicHeads.getMainConfig().shouldUseBlockStore() && EpicHeads.isBlockStoreAvailable();
|
||||
return instance.getMainConfig().shouldUseBlockStore() && instance.isBlockStoreAvailable();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -72,21 +78,21 @@ public class HeadNamer implements Listener {
|
|||
}
|
||||
|
||||
private String findHeadName(Block block) {
|
||||
if (EpicHeads.getMainConfig().shouldUseCacheNames()) {
|
||||
if (instance.getMainConfig().shouldUseCacheNames()) {
|
||||
GameProfile profile = getGameProfile(block);
|
||||
String texture = TextureGetter.findTexture(profile);
|
||||
CacheHead head = EpicHeads.getCache().findHeadByTexture(texture);
|
||||
CacheHead head = instance.getCache().findHeadByTexture(texture);
|
||||
|
||||
if (head != null)
|
||||
return ChatColor.GRAY + head.getName();
|
||||
}
|
||||
|
||||
return ChatColor.GRAY + EpicHeads.getMainConfig().getDefaultHeadName();
|
||||
return ChatColor.GRAY + instance.getMainConfig().getDefaultHeadName();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
if (!EpicHeads.getMainConfig().isHeadNamesEnabled() || !shouldUseBlockStore() || !isHeadsHead(e.getItemInHand()))
|
||||
if (!instance.getMainConfig().isHeadNamesEnabled() || !shouldUseBlockStore() || !isHeadsHead(e.getItemInHand()))
|
||||
return;
|
||||
|
||||
ItemMeta meta = e.getItemInHand().getItemMeta();
|
||||
|
@ -94,12 +100,12 @@ public class HeadNamer implements Listener {
|
|||
if (!meta.hasDisplayName())
|
||||
return;
|
||||
|
||||
BlockStoreApi.setBlockMeta(e.getBlock(), EpicHeads.getInstance(), "name", meta.getDisplayName());
|
||||
BlockStoreApi.setBlockMeta(e.getBlock(), instance, "name", meta.getDisplayName());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockBreak(BlockBreakEvent e) {
|
||||
if (!EpicHeads.getMainConfig().isHeadNamesEnabled())
|
||||
if (!instance.getMainConfig().isHeadNamesEnabled())
|
||||
return;
|
||||
|
||||
Block block = e.getBlock();
|
||||
|
@ -111,7 +117,7 @@ public class HeadNamer implements Listener {
|
|||
e.setCancelled(true);
|
||||
|
||||
if (shouldUseBlockStore()) {
|
||||
BlockStoreApi.retrieveBlockMeta(EpicHeads.getInstance(), block, EpicHeads.getInstance(), "name", metaValue -> {
|
||||
BlockStoreApi.retrieveBlockMeta(instance, block, instance, "name", metaValue -> {
|
||||
String newName;
|
||||
|
||||
if (metaValue instanceof String) {
|
||||
|
@ -163,13 +169,13 @@ public class HeadNamer implements Listener {
|
|||
private final BlockBreakEvent event;
|
||||
private final CountdownRunnable countdown;
|
||||
|
||||
public BlockBreakEventCaller(RegisteredListener listener, BlockBreakEvent event, CountdownRunnable countdown) {
|
||||
BlockBreakEventCaller(RegisteredListener listener, BlockBreakEvent event, CountdownRunnable countdown) {
|
||||
this.listener = listener;
|
||||
this.event = event;
|
||||
this.countdown = countdown;
|
||||
}
|
||||
|
||||
public void scheduleTask() {
|
||||
void scheduleTask() {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(listener.getPlugin(), this);
|
||||
}
|
||||
|
||||
|
@ -191,16 +197,16 @@ public class HeadNamer implements Listener {
|
|||
private final AtomicInteger countdown;
|
||||
private final Runnable runnable;
|
||||
|
||||
public CountdownRunnable(int count, Runnable runnable) {
|
||||
CountdownRunnable(int count, Runnable runnable) {
|
||||
this.countdown = new AtomicInteger(count);
|
||||
this.runnable = runnable;
|
||||
}
|
||||
|
||||
public void countdown() {
|
||||
void countdown() {
|
||||
if (countdown.decrementAndGet() != 0)
|
||||
return;
|
||||
|
||||
EpicHeads.sync(runnable);
|
||||
EpicHeads.getInstance().sync(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -255,7 +255,7 @@ public final class Item {
|
|||
|
||||
if (section.isInt("type")) {
|
||||
int typeId = section.getInt("type");
|
||||
String convertedType = EpicHeads.getLegacyIDs().fromId(typeId);
|
||||
String convertedType = EpicHeads.getInstance().getLegacyIDs().fromId(typeId);
|
||||
|
||||
if (convertedType == null || convertedType.isEmpty()) {
|
||||
Methods.formatText("Invalid type of item " + section.getCurrentPath() + ", " + "unknown type id " + typeId);
|
||||
|
|
|
@ -29,12 +29,12 @@ public class CategorySelectMenu extends AbstractModedInventory {
|
|||
|
||||
@Override
|
||||
public void recreate() {
|
||||
CacheFile cache = EpicHeads.getCache();
|
||||
CacheFile cache = EpicHeads.getInstance().getCache();
|
||||
|
||||
this.heads = new HashMap<>();
|
||||
this.categories = new ArrayList<>();
|
||||
|
||||
if (EpicHeads.getMainConfig().shouldHideNoPermCategories()) {
|
||||
if (EpicHeads.getInstance().getMainConfig().shouldHideNoPermCategories()) {
|
||||
Player player = this.getInvMode().getPlayer();
|
||||
|
||||
for (String category : cache.getCategories()) {
|
||||
|
|
|
@ -35,7 +35,7 @@ public class CategoryCostMode extends BaseMode {
|
|||
}
|
||||
|
||||
public CacheHead getCategoryHead(String category) {
|
||||
List<CacheHead> heads = EpicHeads.getCache().getCategoryHeads(category);
|
||||
List<CacheHead> heads = EpicHeads.getInstance().getCache().getCategoryHeads(category);
|
||||
|
||||
return (heads.size() > 0 ? heads.get(0) : null);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class CategoryCostMode extends BaseMode {
|
|||
public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) {
|
||||
EpicHeads.getInstance().getLocale().getMessage("interface.categorycost.setcost", head.getCategory(), cost);
|
||||
|
||||
EpicHeads.getMainConfig().setCategoryCost(head.getCategory(), cost);
|
||||
EpicHeads.getInstance().getMainConfig().setCategoryCost(head.getCategory(), cost);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.util.List;
|
|||
|
||||
public class CategoryCostRemoveMode extends BaseMode {
|
||||
|
||||
private final double newCost = EpicHeads.getMainConfig().getDefaultHeadCost();
|
||||
private final double newCost = EpicHeads.getInstance().getMainConfig().getDefaultHeadCost();
|
||||
|
||||
public CategoryCostRemoveMode(Player player) {
|
||||
super(player);
|
||||
|
@ -31,7 +31,7 @@ public class CategoryCostRemoveMode extends BaseMode {
|
|||
}
|
||||
|
||||
public CacheHead getCategoryHead(String category) {
|
||||
List<CacheHead> heads = EpicHeads.getCache().getCategoryHeads(category);
|
||||
List<CacheHead> heads = EpicHeads.getInstance().getCache().getCategoryHeads(category);
|
||||
|
||||
return (heads.size() > 0 ? heads.get(0) : null);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class CategoryCostRemoveMode extends BaseMode {
|
|||
public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) {
|
||||
e.getWhoClicked().sendMessage(EpicHeads.getInstance().getLocale().getMessage("interface.categorycost.removecost", newCost));
|
||||
|
||||
EpicHeads.getMainConfig().removeCategoryCost(head.getCategory());
|
||||
EpicHeads.getInstance().getMainConfig().removeCategoryCost(head.getCategory());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,7 +30,7 @@ public class RemoveMode extends BaseMode {
|
|||
|
||||
@Override
|
||||
public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) {
|
||||
EpicHeads.getCache().removeHead(head);
|
||||
EpicHeads.getInstance().getCache().removeHead(head);
|
||||
EpicHeads.getInstance().saveCache();
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public class SearchMode extends BaseMode {
|
|||
if (!getPlayer().hasPermission("heads.category." + head.getCategory().toLowerCase().replace(' ', '_'))) {
|
||||
return "head-no-perms";
|
||||
} else {
|
||||
return (head.hasCost() && EpicHeads.getMainConfig().isEconomyEnabled() ? "head-cost" : "head");
|
||||
return (head.hasCost() && EpicHeads.getInstance().getMainConfig().isEconomyEnabled() ? "head-cost" : "head");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public class TextureGetter {
|
|||
}
|
||||
|
||||
TileEntitySkull.resolveTexture(name, profile -> {
|
||||
EpicHeads.sync(() -> safeCallback.accept(findTexture(profile, true)));
|
||||
EpicHeads.getInstance().sync(() -> safeCallback.accept(findTexture(profile, true)));
|
||||
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
package nl.marido.deluxeheads.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import nl.marido.deluxeheads.DeluxeHeads;
|
||||
import nl.marido.deluxeheads.command.admin.AddCommand;
|
||||
import nl.marido.deluxeheads.command.admin.CategoryCostCommand;
|
||||
import nl.marido.deluxeheads.command.admin.CostCommand;
|
||||
import nl.marido.deluxeheads.command.admin.GiveCommand;
|
||||
import nl.marido.deluxeheads.command.admin.HandCommand;
|
||||
import nl.marido.deluxeheads.command.admin.IdCommand;
|
||||
import nl.marido.deluxeheads.command.admin.ItemEcoCommand;
|
||||
import nl.marido.deluxeheads.command.admin.ReloadCommand;
|
||||
import nl.marido.deluxeheads.command.admin.RemoveCommand;
|
||||
import nl.marido.deluxeheads.command.admin.RenameCommand;
|
||||
import nl.marido.deluxeheads.command.user.GetCommand;
|
||||
import nl.marido.deluxeheads.command.user.OpenMenuCommand;
|
||||
import nl.marido.deluxeheads.command.user.RandomCommand;
|
||||
import nl.marido.deluxeheads.command.user.SearchCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
import nl.marido.deluxeheads.config.lang.LangMessage;
|
||||
|
||||
public class HeadsCommand implements CommandExecutor {
|
||||
|
||||
private static final OpenMenuCommand openMenu = new OpenMenuCommand();
|
||||
private static final HelpCommand help = new HelpCommand();
|
||||
|
||||
public static final AbstractCommand[] commands = { new OpenMenuCommand(), new SearchCommand(), new GetCommand(), new RandomCommand(),
|
||||
|
||||
new AddCommand(), new HandCommand(), new RemoveCommand(), new RenameCommand(), new IdCommand(), new GiveCommand(), new CostCommand(), new CategoryCostCommand(), new ItemEcoCommand(),
|
||||
|
||||
new ReloadCommand(), new HelpCommand() };
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command bukkitCommand, String label, String[] args) {
|
||||
if (args.length == 0) {
|
||||
String permission = openMenu.getPermission();
|
||||
|
||||
if (permission != null && !sender.hasPermission(permission)) {
|
||||
Lang.Command.Errors.noPermission().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
return openMenu.onCommand(sender, bukkitCommand, label, args);
|
||||
}
|
||||
|
||||
String argument = args[0];
|
||||
MainConfig config = DeluxeHeads.getMainConfig();
|
||||
|
||||
for (AbstractCommand command : commands) {
|
||||
String commandLabel = command.getCommandLabel(config);
|
||||
|
||||
if (commandLabel == null || !argument.equalsIgnoreCase(commandLabel))
|
||||
continue;
|
||||
|
||||
String permission = command.getPermission();
|
||||
|
||||
if (permission != null && !sender.hasPermission(permission)) {
|
||||
Lang.Command.Errors.noPermission().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
return command.onCommand(sender, bukkitCommand, label, args);
|
||||
}
|
||||
|
||||
LangMessage unknownCommandMessage = Lang.Command.unknownCommand(argument);
|
||||
|
||||
unknownCommandMessage.send(sender);
|
||||
|
||||
return help.onCommand(sender, new String[0], 10 - unknownCommandMessage.getLineCount());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
package nl.marido.deluxeheads.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
import nl.marido.deluxeheads.config.lang.Lang.HelpSection;
|
||||
|
||||
public class HelpCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return config.getHelpCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.Help.help();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command bukkitCommand, String label, String[] args) {
|
||||
return onCommand(sender, args, 10);
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, String[] args, int screenSpace) {
|
||||
if(args.length > 2) {
|
||||
sendInvalidArgs(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
int page = 1;
|
||||
|
||||
if(args.length == 2) {
|
||||
try {
|
||||
page = Integer.valueOf(args[1]);
|
||||
} catch(NumberFormatException e) {
|
||||
Lang.Command.Errors.integer(args[1]).send(sender);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int lineLength = Lang.Command.Help.getLineCountPerLine();
|
||||
int linesPerPage = (lineLength >= 1 && lineLength <= (screenSpace - 2) ? (screenSpace - 2) / lineLength : 1);
|
||||
int pages = (linesPerPage + HeadsCommand.commands.length - 1) / linesPerPage;
|
||||
int nextPage = (page >= pages ? 1 : page + 1);
|
||||
|
||||
if(page < 1 || page > pages) {
|
||||
Lang.Command.Help.unknownPage(page, pages).send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
Lang.Command.Help.header(page, pages, nextPage).send(sender);
|
||||
|
||||
int startIndex = (page - 1) * linesPerPage;
|
||||
int endIndex = page * linesPerPage;
|
||||
|
||||
if(endIndex > HeadsCommand.commands.length) {
|
||||
endIndex = HeadsCommand.commands.length;
|
||||
}
|
||||
|
||||
for(int index = startIndex; index < endIndex; ++index) {
|
||||
HelpSection helpSection = HeadsCommand.commands[index].getHelp();
|
||||
|
||||
Lang.Command.Help.line(helpSection).send(sender);
|
||||
}
|
||||
|
||||
Lang.Command.Help.footer(page, pages, nextPage).send(sender);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package nl.marido.deluxeheads.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class RuntimeCommand extends Command {
|
||||
|
||||
private CommandExecutor executor;
|
||||
|
||||
public RuntimeCommand(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void setExecutor(CommandExecutor executor) {
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public CommandExecutor getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
return executor.onCommand(sender, this, label, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
package nl.marido.deluxeheads.command.admin;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import nl.marido.deluxeheads.DeluxeHeads;
|
||||
import nl.marido.deluxeheads.cache.CacheHead;
|
||||
import nl.marido.deluxeheads.command.AbstractCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
import nl.marido.deluxeheads.volatilecode.TextureGetter;
|
||||
import nl.marido.deluxeheads.volatilecode.reflection.Version;
|
||||
|
||||
public class AddCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return config.getAddCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "deluxeheads.add";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.Add.help();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
|
||||
if (Version.v1_8.higherThan(Version.getVersion())) {
|
||||
Lang.Command.Add.notSupported().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 3) {
|
||||
sendInvalidArgs(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
final String playerName = args[1];
|
||||
final String category = args[2];
|
||||
|
||||
final String name;
|
||||
|
||||
if (args.length > 3) {
|
||||
StringBuilder nameBuilder = new StringBuilder();
|
||||
for (int i = 3; i < args.length; i++) {
|
||||
nameBuilder.append(' ');
|
||||
nameBuilder.append(args[i]);
|
||||
}
|
||||
name = nameBuilder.toString().substring(1);
|
||||
} else {
|
||||
name = playerName;
|
||||
}
|
||||
|
||||
if (category.length() > 32) {
|
||||
Lang.Command.Add.categoryLength(category).send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
String texture = TextureGetter.getCachedTexture(playerName);
|
||||
|
||||
if (texture != null) {
|
||||
add(sender, category, name, playerName, texture);
|
||||
} else {
|
||||
Lang.Command.Add.fetching().send(sender);
|
||||
TextureGetter.getTexture(playerName, (resolvedTexture) -> {
|
||||
add(sender, category, name, playerName, resolvedTexture);
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void add(CommandSender sender, String category, String name, String playerName, String texture) {
|
||||
if (texture == null || texture.isEmpty()) {
|
||||
Lang.Command.Add.cantFind(playerName).send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
CacheHead head = new CacheHead(name, category, texture);
|
||||
|
||||
DeluxeHeads.getCache().addHead(head);
|
||||
DeluxeHeads.getInstance().saveCache();
|
||||
|
||||
Lang.Command.Add.added(name, category).send(sender);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package nl.marido.deluxeheads.command.admin;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import nl.marido.deluxeheads.command.AbstractCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
import nl.marido.deluxeheads.oldmenu.mode.CategoryCostMode;
|
||||
import nl.marido.deluxeheads.oldmenu.mode.InvModeType;
|
||||
|
||||
public class CategoryCostCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return config.getCategoryCostCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "deluxeheads.category-cost";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.CategoryCost.help();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
Lang.Command.Errors.mustBePlayer().send(sender);
|
||||
return true;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
sendInvalidArgs(sender);
|
||||
return true;
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("reset")) {
|
||||
InvModeType.CATEGORY_COST_REMOVE.open((Player) sender);
|
||||
return true;
|
||||
}
|
||||
double cost;
|
||||
try {
|
||||
cost = Double.valueOf(args[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
Lang.Command.Errors.number(args[1]).send(sender);
|
||||
return true;
|
||||
}
|
||||
if (cost < 0) {
|
||||
Lang.Command.Errors.negative(args[1]).send(sender);
|
||||
return true;
|
||||
}
|
||||
InvModeType.CATEGORY_COST.open((Player) sender).asType(CategoryCostMode.class).setCost(cost);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package nl.marido.deluxeheads.command.admin;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import nl.marido.deluxeheads.command.AbstractCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
import nl.marido.deluxeheads.oldmenu.mode.CostMode;
|
||||
import nl.marido.deluxeheads.oldmenu.mode.InvModeType;
|
||||
|
||||
public class CostCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return config.getCostCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "deluxeheads.cost";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.Cost.help();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
Lang.Command.Errors.mustBePlayer().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 2) {
|
||||
sendInvalidArgs(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
double cost;
|
||||
try {
|
||||
cost = Double.valueOf(args[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
Lang.Command.Errors.number(args[1]).send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (cost < 0) {
|
||||
Lang.Command.Errors.negative(args[1]).send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
InvModeType.COST.open((Player) sender).asType(CostMode.class).setCost(cost);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package nl.marido.deluxeheads.command.admin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import nl.marido.deluxeheads.DeluxeHeads;
|
||||
import nl.marido.deluxeheads.cache.CacheHead;
|
||||
import nl.marido.deluxeheads.command.AbstractCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
|
||||
public class GiveCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return config.getGiveCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "deluxeheads.give";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.Give.help();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||
if (args.length != 4) {
|
||||
sendInvalidArgs(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
int id;
|
||||
try {
|
||||
id = Integer.valueOf(args[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
Lang.Command.Errors.integer(args[1]).send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
int amount;
|
||||
try {
|
||||
amount = Integer.valueOf(args[3]);
|
||||
} catch (NumberFormatException e) {
|
||||
Lang.Command.Give.invalidAmount(args[3]).send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (amount <= 0) {
|
||||
Lang.Command.Give.invalidAmount(args[3]).send(sender);
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(args[2]);
|
||||
|
||||
if (player == null || !player.isOnline()) {
|
||||
Lang.Command.Give.cantFindPlayer(args[2]).send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
CacheHead head = DeluxeHeads.getCache().findHead(id);
|
||||
|
||||
if (head == null) {
|
||||
Lang.Command.Give.cantFindHead(id).send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemStack headItem = head.getItemStack();
|
||||
for (int i = 0; i < amount; i++) {
|
||||
if (player.getInventory().firstEmpty() != -1) {
|
||||
player.getInventory().addItem(headItem.clone());
|
||||
} else {
|
||||
Item item = player.getWorld().dropItemNaturally(player.getEyeLocation(), headItem.clone());
|
||||
item.setPickupDelay(0);
|
||||
}
|
||||
}
|
||||
|
||||
Lang.Command.Give.give(amount, head.getName(), player.getName()).send(sender);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
package nl.marido.deluxeheads.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 nl.marido.deluxeheads.DeluxeHeads;
|
||||
import nl.marido.deluxeheads.cache.CacheHead;
|
||||
import nl.marido.deluxeheads.command.AbstractCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
import nl.marido.deluxeheads.volatilecode.ItemNBT;
|
||||
import nl.marido.deluxeheads.volatilecode.Items;
|
||||
import nl.marido.deluxeheads.volatilecode.TextureGetter;
|
||||
import nl.marido.deluxeheads.volatilecode.reflection.Version;
|
||||
|
||||
public class HandCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return config.getHandCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "deluxeheads.hand";
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
String name = nameBuilder.toString().substring(1);
|
||||
String category = args[1];
|
||||
|
||||
if (category.length() > 32) {
|
||||
Lang.Command.Hand.categoryLength(category).send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
ItemStack hand = player.getInventory().getItemInHand();
|
||||
|
||||
if (!Items.isSkull(hand)) {
|
||||
Lang.Command.Hand.notSkull().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
String texture = ItemNBT.getTextureProperty(hand);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
SkullMeta meta = (SkullMeta) hand.getItemMeta();
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
final String owner = meta.getOwner();
|
||||
|
||||
if (owner == null || owner.isEmpty()) {
|
||||
Lang.Command.Hand.noNameProperty().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
add(sender, category, name, resolvedTexture);
|
||||
});
|
||||
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);
|
||||
|
||||
DeluxeHeads.getCache().addHead(head);
|
||||
DeluxeHeads.getInstance().saveCache();
|
||||
|
||||
Lang.Command.Hand.adding(name, category).send(sender);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package nl.marido.deluxeheads.command.admin;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
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.ItemMeta;
|
||||
|
||||
import nl.marido.deluxeheads.DeluxeHeads;
|
||||
import nl.marido.deluxeheads.cache.CacheHead;
|
||||
import nl.marido.deluxeheads.command.AbstractCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
import nl.marido.deluxeheads.volatilecode.ItemNBT;
|
||||
import nl.marido.deluxeheads.volatilecode.Items;
|
||||
|
||||
public class IdCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return config.getIdCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "deluxeheads.id";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.Id.help();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
Lang.Command.Errors.mustBePlayer().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (args.length != 1) {
|
||||
sendInvalidArgs(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemStack hand = player.getInventory().getItemInHand();
|
||||
if (!Items.isSkull(hand)) {
|
||||
Lang.Command.Id.holdSkull().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
String texture = ItemNBT.getTextureProperty(hand);
|
||||
CacheHead head = DeluxeHeads.getCache().findHeadByTexture(texture);
|
||||
if (head == null) {
|
||||
ItemMeta meta = hand.getItemMeta();
|
||||
String name = ChatColor.stripColor(meta.hasDisplayName() ? meta.getDisplayName() : "");
|
||||
Lang.Command.Id.unknownHead(name).send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
Lang.Command.Id.foundID(head.getName(), head.getId()).send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,166 +0,0 @@
|
|||
package nl.marido.deluxeheads.command.admin;
|
||||
|
||||
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 nl.marido.deluxeheads.DeluxeHeads;
|
||||
import nl.marido.deluxeheads.command.AbstractCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
import nl.marido.deluxeheads.menu.ui.item.Item;
|
||||
|
||||
public class ItemEcoCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return config.getItemEcoCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "deluxeheads.item-eco";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.ItemEco.help();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length < 2) {
|
||||
sendInvalidArgs(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("give")) {
|
||||
onGiveCommand(sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
Lang.Command.Errors.mustBePlayer().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (args[1].equalsIgnoreCase("set")) {
|
||||
onSetCommand(player, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("get")) {
|
||||
onGetCommand(player, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
sendInvalidArgs(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void onSetCommand(Player player, String[] args) {
|
||||
if (args.length != 2) {
|
||||
Lang.Command.ItemEco.Set.help().sendInvalidArgs(player);
|
||||
return;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
// Had to do this to resolve the compatibility issue with 1.13.
|
||||
ItemStack itemStack = player.getInventory().getItemInHand();
|
||||
|
||||
if (itemStack == null) {
|
||||
Lang.Command.ItemEco.Set.noItem().send(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Item item = Item.create(itemStack).amount(1);
|
||||
|
||||
DeluxeHeads.getMainConfig().setItemEcoItem(item);
|
||||
|
||||
Lang.Command.ItemEco.Set.set().send(player);
|
||||
}
|
||||
|
||||
private void onGetCommand(Player player, String[] args) {
|
||||
if (args.length != 2 && args.length != 3) {
|
||||
Lang.Command.ItemEco.Get.help().sendInvalidArgs(player);
|
||||
return;
|
||||
}
|
||||
|
||||
int amount = 1;
|
||||
|
||||
if (args.length == 3) {
|
||||
try {
|
||||
amount = Integer.valueOf(args[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
Lang.Command.Errors.integer(args[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (amount < 1) {
|
||||
Lang.Command.Errors.negative(args[2]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
giveTokens(player, amount);
|
||||
|
||||
Lang.Command.ItemEco.Get.got(amount).send(player);
|
||||
}
|
||||
|
||||
private void onGiveCommand(CommandSender sender, String[] args) {
|
||||
if (args.length != 3 && args.length != 4) {
|
||||
Lang.Command.ItemEco.Give.help().sendInvalidArgs(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
int amount = 1;
|
||||
|
||||
if (args.length == 4) {
|
||||
try {
|
||||
amount = Integer.valueOf(args[3]);
|
||||
} catch (NumberFormatException e) {
|
||||
Lang.Command.Errors.integer(args[3]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (amount < 1) {
|
||||
Lang.Command.Errors.negative(args[3]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(args[2]);
|
||||
|
||||
if (player == null) {
|
||||
Lang.Command.ItemEco.Give.unknownPlayer(args[2]).send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
giveTokens(player, amount);
|
||||
|
||||
Lang.Command.ItemEco.Give.got(amount).send(player);
|
||||
Lang.Command.ItemEco.Give.given(player.getName(), amount).send(sender);
|
||||
}
|
||||
|
||||
private void giveTokens(Player player, int amount) {
|
||||
while (amount > 0) {
|
||||
int giveAmount = Math.min(64, amount);
|
||||
amount -= giveAmount;
|
||||
|
||||
ItemStack itemStack = DeluxeHeads.getMainConfig().getItemEconomyItem().amount(giveAmount).build();
|
||||
|
||||
if (player.getInventory().firstEmpty() != -1) {
|
||||
player.getInventory().addItem(itemStack);
|
||||
} else {
|
||||
org.bukkit.entity.Item item = player.getWorld().dropItemNaturally(player.getEyeLocation(), itemStack);
|
||||
|
||||
item.setPickupDelay(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package nl.marido.deluxeheads.command.admin;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import nl.marido.deluxeheads.DeluxeHeads;
|
||||
import nl.marido.deluxeheads.command.AbstractCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
|
||||
public class ReloadCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return config.getReloadCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "deluxeheads.reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.Reload.help();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length != 1) {
|
||||
sendInvalidArgs(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
DeluxeHeads.getInstance().reloadConfigs();
|
||||
|
||||
Lang.Command.Reload.reloaded().send(sender);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package nl.marido.deluxeheads.command.admin;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import nl.marido.deluxeheads.command.AbstractCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
import nl.marido.deluxeheads.oldmenu.mode.InvModeType;
|
||||
|
||||
public class RemoveCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return config.getRemoveCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "deluxeheads.remove";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.Remove.help();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
Lang.Command.Errors.mustBePlayer().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 1) {
|
||||
sendInvalidArgs(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
InvModeType.REMOVE.open((Player) sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package nl.marido.deluxeheads.command.admin;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import nl.marido.deluxeheads.command.AbstractCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
import nl.marido.deluxeheads.oldmenu.mode.InvModeType;
|
||||
import nl.marido.deluxeheads.oldmenu.mode.RenameMode;
|
||||
|
||||
public class RenameCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return config.getRenameCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "deluxeheads.rename";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.Rename.help();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
Lang.Command.Errors.mustBePlayer().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length <= 1) {
|
||||
sendInvalidArgs(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
if (i != 1) {
|
||||
builder.append(' ');
|
||||
}
|
||||
|
||||
builder.append(args[i]);
|
||||
}
|
||||
|
||||
String name = builder.toString();
|
||||
|
||||
InvModeType.RENAME.open((Player) sender).asType(RenameMode.class).setName(name);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
package nl.marido.deluxeheads.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 nl.marido.deluxeheads.cache.CacheHead;
|
||||
import nl.marido.deluxeheads.command.AbstractCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
import nl.marido.deluxeheads.volatilecode.Items;
|
||||
import nl.marido.deluxeheads.volatilecode.TextureGetter;
|
||||
import nl.marido.deluxeheads.volatilecode.reflection.Version;
|
||||
|
||||
public class GetCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return config.getGetCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "deluxeheads.get";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.Get.help();
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
if (args.length != 2) {
|
||||
sendInvalidArgs(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Version.v1_8.higherThan(Version.getVersion())) {
|
||||
Lang.Command.Get.oldMethod().send(sender);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
String texture = TextureGetter.getCachedTexture(args[1]);
|
||||
|
||||
if (texture != null) {
|
||||
giveHead((Player) sender, args[1], texture);
|
||||
return true;
|
||||
}
|
||||
|
||||
Lang.Command.Get.fetching().send(sender);
|
||||
|
||||
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());
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package nl.marido.deluxeheads.command.user;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import nl.marido.deluxeheads.command.AbstractCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
import nl.marido.deluxeheads.oldmenu.mode.InvModeType;
|
||||
|
||||
public class OpenMenuCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "deluxeheads.menu";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.OpenMenu.help();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
Lang.Command.Errors.mustBePlayer().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
InvModeType.GET.open((Player) sender);
|
||||
|
||||
// CacheHeadsMenu.openHeadsMenu((Player) sender);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
package nl.marido.deluxeheads.command.user;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import nl.marido.deluxeheads.DeluxeHeads;
|
||||
import nl.marido.deluxeheads.cache.CacheHead;
|
||||
import nl.marido.deluxeheads.command.AbstractCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
|
||||
public class RandomCommand extends AbstractCommand {
|
||||
|
||||
private static final Random RANDOM = new Random();
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return config.getRandomCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "deluxeheads.random";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.Random.help();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length != 1 && args.length != 2) {
|
||||
sendInvalidArgs(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (DeluxeHeads.getCache().getHeadCount() == 0) {
|
||||
Lang.Command.Random.noHeads().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
CacheHead random = DeluxeHeads.getCache().getRandomHead(RANDOM);
|
||||
|
||||
if (args.length == 1) {
|
||||
if (!(sender instanceof Player)) {
|
||||
Lang.Command.Errors.mustBePlayer().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
Lang.Command.Random.retrievingOwn(random).send(sender);
|
||||
|
||||
((Player) sender).getInventory().addItem(random.getItemStack());
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(args[1]);
|
||||
|
||||
if (player == null) {
|
||||
Lang.Command.Random.cantFindPlayer(args[1]).send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
Lang.Command.Random.retrieving(random).send(player);
|
||||
Lang.Command.Random.give(player, random).send(sender);
|
||||
|
||||
player.getInventory().addItem(random.getItemStack());
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package nl.marido.deluxeheads.command.user;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import nl.marido.deluxeheads.DeluxeHeads;
|
||||
import nl.marido.deluxeheads.command.AbstractCommand;
|
||||
import nl.marido.deluxeheads.config.MainConfig;
|
||||
import nl.marido.deluxeheads.config.lang.Lang;
|
||||
import nl.marido.deluxeheads.oldmenu.mode.SearchMode;
|
||||
|
||||
public class SearchCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return config.getSearchCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "deluxeheads.search";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.Search.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 <= 1) {
|
||||
sendInvalidArgs(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
StringBuilder queryBuilder = new StringBuilder();
|
||||
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
queryBuilder.append(args[i]);
|
||||
queryBuilder.append(' ');
|
||||
}
|
||||
|
||||
String query = queryBuilder.toString().trim();
|
||||
|
||||
DeluxeHeads.getCache().searchHeadsAsync(query, matches -> {
|
||||
if (matches.size() == 0) {
|
||||
Lang.Command.Search.noneFound(query).send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
Lang.Command.Search.found(query, matches.size()).send(sender);
|
||||
|
||||
new SearchMode((Player) sender, matches);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,684 +0,0 @@
|
|||
package nl.marido.deluxeheads.config.lang;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import nl.marido.deluxeheads.DeluxeHeads;
|
||||
import nl.marido.deluxeheads.cache.CacheHead;
|
||||
|
||||
public class Lang {
|
||||
|
||||
public static LangMessage get(String key) {
|
||||
return DeluxeHeads.getLangConfig().getMessage(key);
|
||||
}
|
||||
|
||||
public static class HelpSection {
|
||||
|
||||
private String key;
|
||||
|
||||
public HelpSection(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String key() {
|
||||
return key + ".help";
|
||||
}
|
||||
|
||||
public String command() {
|
||||
return get(key() + ".command").getSingle();
|
||||
}
|
||||
|
||||
public String description() {
|
||||
return get(key() + ".description").getSingle();
|
||||
}
|
||||
|
||||
public void sendInvalidArgs(CommandSender sender) {
|
||||
Lang.Command.Errors.invalidArgs(this).send(sender);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Updater {
|
||||
|
||||
public static String key() {
|
||||
return "updater";
|
||||
}
|
||||
|
||||
public static LangMessage oldVersion() {
|
||||
return get(key() + ".old-version");
|
||||
}
|
||||
|
||||
public static LangMessage newVersion() {
|
||||
return get(key() + ".new-version");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Currency {
|
||||
|
||||
public static String key() {
|
||||
return "currency";
|
||||
}
|
||||
|
||||
public static LangMessage format(Player player, double amount) {
|
||||
if (amount > 0 && player != null && DeluxeHeads.getInstance().isExemptFromCost(player))
|
||||
return exempt(amount);
|
||||
|
||||
return format(amount);
|
||||
}
|
||||
|
||||
public static LangMessage format(double amount) {
|
||||
return (amount <= 0 ? zero() : nonZero(amount));
|
||||
}
|
||||
|
||||
public static LangMessage zero() {
|
||||
return get(key() + ".zero");
|
||||
}
|
||||
|
||||
public static LangMessage nonZero(double amount) {
|
||||
return get(key() + ".non-zero").with("%amount%", DeluxeHeads.getEconomy().formatBalance(amount));
|
||||
}
|
||||
|
||||
public static LangMessage exempt(double amount) {
|
||||
return get(key() + ".exempt").with("%cost%", format(amount));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Menu {
|
||||
|
||||
public static String key() {
|
||||
return "menu";
|
||||
}
|
||||
|
||||
public static class Get {
|
||||
|
||||
public static String key() {
|
||||
return Menu.key() + ".get";
|
||||
}
|
||||
|
||||
public static LangMessage open() {
|
||||
return get(key() + ".open");
|
||||
}
|
||||
|
||||
public static LangMessage added(String name) {
|
||||
return get(key() + ".added").with("%name%", name);
|
||||
}
|
||||
|
||||
public static LangMessage purchased(String name, double cost) {
|
||||
return get(key() + ".purchased").with("%name%", name).with("%cost%", Currency.format(cost));
|
||||
}
|
||||
|
||||
public static LangMessage notEnoughMoney(String name, double cost) {
|
||||
return get(key() + ".not-enough-money").with("%name%", name).with("%cost%", cost);
|
||||
}
|
||||
|
||||
public static LangMessage transactionError(String name, double cost) {
|
||||
return get(key() + ".transaction-error").with("%name%", name).with("%cost%", cost);
|
||||
}
|
||||
|
||||
public static LangMessage categoryPermission(String category) {
|
||||
return get(key() + ".category-permission").with("%category%", category);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Search {
|
||||
|
||||
public static String key() {
|
||||
return Menu.key() + ".get";
|
||||
}
|
||||
|
||||
public static LangMessage added(String name) {
|
||||
return get(key() + ".added").with("%name%", name);
|
||||
}
|
||||
|
||||
public static LangMessage notEnoughMoney(String name, double cost) {
|
||||
return get(key() + ".not-enough-money").with("%name%", name).with("%cost%", cost);
|
||||
}
|
||||
|
||||
public static LangMessage transactionError(String name, double cost) {
|
||||
return get(key() + ".transaction-error").with("%name%", name).with("%cost%", cost);
|
||||
}
|
||||
|
||||
public static LangMessage categoryPermission(String category) {
|
||||
return get(key() + ".category-permission").with("%category%", category);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Remove {
|
||||
|
||||
public static String key() {
|
||||
return Menu.key() + ".remove";
|
||||
}
|
||||
|
||||
public static LangMessage open() {
|
||||
return get(key() + ".open");
|
||||
}
|
||||
|
||||
public static LangMessage removed(String name) {
|
||||
return get(key() + ".removed").with("%name%", name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Rename {
|
||||
|
||||
public static String key() {
|
||||
return Menu.key() + ".rename";
|
||||
}
|
||||
|
||||
public static LangMessage open(String newName) {
|
||||
return get(key() + ".open").with("%newname%", newName);
|
||||
}
|
||||
|
||||
public static LangMessage renamed(String oldName, String newName) {
|
||||
return get(key() + ".renamed").with("%name%", oldName).with("%newname%", newName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Cost {
|
||||
|
||||
public static String key() {
|
||||
return Menu.key() + ".cost";
|
||||
}
|
||||
|
||||
public static LangMessage open(double newCost) {
|
||||
return get(key() + ".open").with("%newcost%", Currency.format(newCost));
|
||||
}
|
||||
|
||||
public static LangMessage setCost(String name, double newCost) {
|
||||
return get(key() + ".set-cost").with("%name%", name).with("%newcost%", Currency.format(newCost));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class CategoryCost {
|
||||
|
||||
public static String key() {
|
||||
return Menu.key() + ".category-cost";
|
||||
}
|
||||
|
||||
public static LangMessage open(double newCost) {
|
||||
return get(key() + ".open").with("%newcost%", Currency.format(newCost));
|
||||
}
|
||||
|
||||
public static LangMessage setCost(String category, double newCost) {
|
||||
return get(key() + ".set-cost").with("%category%", category).with("%newcost%", Currency.format(newCost));
|
||||
}
|
||||
|
||||
public static LangMessage openRemove(double newCost) {
|
||||
return get(key() + ".open-remove").with("%newcost%", Currency.format(newCost));
|
||||
}
|
||||
|
||||
public static LangMessage removeCost(String category, double newCost) {
|
||||
return get(key() + ".remove-cost").with("%category%", category).with("%newcost%", Currency.format(newCost));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Id {
|
||||
|
||||
public static String key() {
|
||||
return Menu.key() + ".id";
|
||||
}
|
||||
|
||||
public static LangMessage open() {
|
||||
return get(key() + ".open");
|
||||
}
|
||||
|
||||
public static LangMessage clicked(String name, int id) {
|
||||
return get(key() + ".clicked").with("%name%", name).with("%id%", id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Command {
|
||||
|
||||
public static String key() {
|
||||
return "command";
|
||||
}
|
||||
|
||||
public static LangMessage unknownCommand(String command) {
|
||||
return get(key() + ".unknown-command").with("%command%", command);
|
||||
}
|
||||
|
||||
public static class Errors {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".errors";
|
||||
}
|
||||
|
||||
public static LangMessage mustBePlayer() {
|
||||
return get(key() + ".must-be-player");
|
||||
}
|
||||
|
||||
public static LangMessage noPermission() {
|
||||
return get(key() + ".no-permission");
|
||||
}
|
||||
|
||||
public static LangMessage invalidArgs(HelpSection commandHelp) {
|
||||
return invalidArgs(commandHelp.command());
|
||||
}
|
||||
|
||||
public static LangMessage invalidArgs(String valid) {
|
||||
return get(key() + ".invalid-arguments").with("%valid%", valid);
|
||||
}
|
||||
|
||||
public static LangMessage integer(String number) {
|
||||
return get(key() + ".integer").with("%number%", number);
|
||||
}
|
||||
|
||||
public static LangMessage number(String number) {
|
||||
return get(key() + ".number").with("%number%", number);
|
||||
}
|
||||
|
||||
public static LangMessage negative(String number) {
|
||||
return get(key() + ".negative").with("%number%", number);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Help {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".help";
|
||||
}
|
||||
|
||||
public static LangMessage header(int page, int pages, int nextPage) {
|
||||
return get(key() + ".header").with("%page%", page).with("%pages%", pages).with("%next-page%", nextPage);
|
||||
}
|
||||
|
||||
public static int getLineCountPerLine() {
|
||||
return get(key() + ".line").getLineCount();
|
||||
}
|
||||
|
||||
public static LangMessage line(HelpSection commandHelp) {
|
||||
return line(commandHelp.command(), commandHelp.description());
|
||||
}
|
||||
|
||||
public static LangMessage line(String command, String description) {
|
||||
return get(key() + ".line").with("%command%", command).with("%description%", description);
|
||||
}
|
||||
|
||||
public static LangMessage footer(int page, int pages, int nextPage) {
|
||||
return get(key() + ".footer").with("%page%", page).with("%pages%", pages).with("%next-page%", nextPage);
|
||||
}
|
||||
|
||||
public static LangMessage unknownPage(int page, int pages) {
|
||||
return get(key() + ".unknown-page").with("%page%", page).with("%pages%", pages);
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Reload {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".reload";
|
||||
}
|
||||
|
||||
public static LangMessage reloaded() {
|
||||
return get(key() + ".reloaded");
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Get {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".get";
|
||||
}
|
||||
|
||||
public static LangMessage headName(String name) {
|
||||
return get(key() + ".head-name").with("%name%", name);
|
||||
}
|
||||
|
||||
public static LangMessage oldMethod() {
|
||||
return get(key() + ".old-method");
|
||||
}
|
||||
|
||||
public static LangMessage adding(String name) {
|
||||
return get(key() + ".adding").with("%name%", name);
|
||||
}
|
||||
|
||||
public static LangMessage fetching() {
|
||||
return get(key() + ".fetching");
|
||||
}
|
||||
|
||||
public static LangMessage cantFind(String name) {
|
||||
return get(key() + ".cant-find").with("%name%", name);
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Random {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".random";
|
||||
}
|
||||
|
||||
public static LangMessage noHeads() {
|
||||
return get(key() + ".no-heads");
|
||||
}
|
||||
|
||||
public static LangMessage cantFindPlayer(String name) {
|
||||
return get(key() + ".cant-find-player").with("%name%", name);
|
||||
}
|
||||
|
||||
public static LangMessage retrievingOwn(CacheHead head) {
|
||||
return get(key() + ".retrieve-own").with("%name%", head.getName()).with("%category%", head.getCategory());
|
||||
}
|
||||
|
||||
public static LangMessage retrieving(CacheHead head) {
|
||||
return get(key() + ".retrieve").with("%name%", head.getName()).with("%category%", head.getCategory());
|
||||
}
|
||||
|
||||
public static LangMessage give(Player player, CacheHead head) {
|
||||
return get(key() + ".give").with("%player%", player.getName()).with("%name%", head.getName()).with("%category%", head.getCategory());
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Add {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".add";
|
||||
}
|
||||
|
||||
public static LangMessage notSupported() {
|
||||
return get(key() + ".not-supported");
|
||||
}
|
||||
|
||||
public static LangMessage categoryLength(String category) {
|
||||
return get(key() + ".category-length").with("%category%", category).with("%length%", category.length());
|
||||
}
|
||||
|
||||
public static LangMessage added(String name, String category) {
|
||||
return get(key() + ".added").with("%name%", name).with("%category%", category);
|
||||
}
|
||||
|
||||
public static LangMessage fetching() {
|
||||
return get(key() + ".fetching");
|
||||
}
|
||||
|
||||
public static LangMessage cantFind(String name) {
|
||||
return get(key() + ".cant-find").with("%name%", name);
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Hand {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".hand";
|
||||
}
|
||||
|
||||
public static LangMessage notSupported() {
|
||||
return get(key() + ".not-supported");
|
||||
}
|
||||
|
||||
public static LangMessage noTextureProperty() {
|
||||
return get(key() + ".no-texture-property");
|
||||
}
|
||||
|
||||
public static LangMessage noNameProperty() {
|
||||
return get(key() + ".no-name-property");
|
||||
}
|
||||
|
||||
public static LangMessage notSkull() {
|
||||
return get(key() + ".not-skull");
|
||||
}
|
||||
|
||||
public static LangMessage categoryLength(String category) {
|
||||
return get(key() + ".category-length").with("%category%", category).with("%length%", category.length());
|
||||
}
|
||||
|
||||
public static LangMessage adding(String name, String category) {
|
||||
return get(key() + ".adding").with("%name%", name).with("%category%", category);
|
||||
}
|
||||
|
||||
public static LangMessage fetching() {
|
||||
return get(key() + ".fetching");
|
||||
}
|
||||
|
||||
public static LangMessage cantFind(String name) {
|
||||
return get(key() + ".cant-find").with("%name%", name);
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Give {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".give";
|
||||
}
|
||||
|
||||
public static LangMessage cantFindPlayer(String name) {
|
||||
return get(key() + ".cant-find-player").with("%name%", name);
|
||||
}
|
||||
|
||||
public static LangMessage cantFindHead(int id) {
|
||||
return get(key() + ".cant-find-head").with("%id%", id);
|
||||
}
|
||||
|
||||
public static LangMessage give(int amount, String head, String name) {
|
||||
return get(key() + ".give").with("%amount%", amount).with("%head%", head).with("%name%", name);
|
||||
}
|
||||
|
||||
public static LangMessage invalidAmount(String number) {
|
||||
return get(key() + ".invalid-amount").with("%number%", number);
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class OpenMenu {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".open-menu";
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Remove {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".remove";
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Rename {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".rename";
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Search {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".search";
|
||||
}
|
||||
|
||||
public static LangMessage found(String query, int heads) {
|
||||
return get(key() + ".found").with("%query%", query).with("%heads%", heads);
|
||||
}
|
||||
|
||||
public static LangMessage noneFound(String query) {
|
||||
return get(key() + ".none-found").with("%query%", query);
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Cost {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".cost";
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class CategoryCost {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".category-cost";
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Id {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".id";
|
||||
}
|
||||
|
||||
public static LangMessage holdSkull() {
|
||||
return get(key() + ".hold-skull");
|
||||
}
|
||||
|
||||
public static LangMessage unknownHead(String name) {
|
||||
return get(key() + ".unknown-head").with("%name%", name);
|
||||
}
|
||||
|
||||
public static LangMessage foundID(String name, int id) {
|
||||
return get(key() + ".found-id").with("%name%", name).with("%id%", id);
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class ItemEco {
|
||||
|
||||
public static String key() {
|
||||
return Command.key() + ".item-eco";
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
public static class Set {
|
||||
|
||||
public static String key() {
|
||||
return ItemEco.key() + ".set";
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
public static LangMessage set() {
|
||||
return get(key() + ".set");
|
||||
}
|
||||
|
||||
public static LangMessage noItem() {
|
||||
return get(key() + ".no-item");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Get {
|
||||
|
||||
public static String key() {
|
||||
return ItemEco.key() + ".get";
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
public static LangMessage got(int amount) {
|
||||
return get(key() + ".got").with("%amount%", amount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Give {
|
||||
|
||||
public static String key() {
|
||||
return ItemEco.key() + ".give";
|
||||
}
|
||||
|
||||
public static HelpSection help() {
|
||||
return new HelpSection(key());
|
||||
}
|
||||
|
||||
public static LangMessage got(int amount) {
|
||||
return get(key() + ".got").with("%amount%", amount);
|
||||
}
|
||||
|
||||
public static LangMessage given(String player, int amount) {
|
||||
return get(key() + ".given").with("%player%", player).with("%amount%", amount);
|
||||
}
|
||||
|
||||
public static LangMessage unknownPlayer(String player) {
|
||||
return get(key() + ".unknown-player").with("%player%", player);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
package nl.marido.deluxeheads.config.lang;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import nl.marido.deluxeheads.DeluxeHeads;
|
||||
import nl.marido.deluxeheads.config.ConfigFile;
|
||||
import nl.marido.deluxeheads.config.FileConfigFile;
|
||||
import nl.marido.deluxeheads.util.Clock;
|
||||
|
||||
public class LangConfig {
|
||||
|
||||
private final ConfigFile configFile;
|
||||
private Map<String, LangMessage> defaults;
|
||||
private Map<String, LangMessage> messages;
|
||||
|
||||
public LangConfig() {
|
||||
this.configFile = new FileConfigFile("lang.yml");
|
||||
reload();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
Clock timer = Clock.start();
|
||||
|
||||
this.configFile.copyDefaults();
|
||||
this.configFile.reload();
|
||||
|
||||
ConfigurationSection defaultConfig = this.configFile.getDefaults();
|
||||
|
||||
this.defaults = load(defaultConfig);
|
||||
|
||||
ConfigurationSection config = this.configFile.getConfig();
|
||||
|
||||
this.messages = load(config);
|
||||
|
||||
boolean save = false;
|
||||
|
||||
for (Entry<String, LangMessage> def : this.defaults.entrySet()) {
|
||||
if (!this.messages.containsKey(def.getKey())) {
|
||||
DeluxeHeads.print("\"lang.yml\" is missing key \"" + def.getKey() + "\", adding it");
|
||||
|
||||
config.set(def.getKey(), def.getValue().getConfigSaveValue());
|
||||
this.messages.put(def.getKey(), def.getValue());
|
||||
save = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (save) {
|
||||
this.configFile.save();
|
||||
}
|
||||
|
||||
DeluxeHeads.print("Loaded Lang File with " + this.messages.size() + " messages " + timer);
|
||||
}
|
||||
|
||||
private Map<String, LangMessage> load(ConfigurationSection sec) {
|
||||
Map<String, LangMessage> map = new HashMap<>();
|
||||
|
||||
for (String key : sec.getKeys(false)) {
|
||||
if (sec.isConfigurationSection(key)) {
|
||||
map.putAll(load(sec.getConfigurationSection(key)));
|
||||
continue;
|
||||
}
|
||||
|
||||
String pathKey = (sec.getCurrentPath().isEmpty() ? key : sec.getCurrentPath() + "." + key);
|
||||
|
||||
if (sec.isList(key)) {
|
||||
List<String> lines = sec.getStringList(key);
|
||||
|
||||
map.put(pathKey, new LangMessage(lines.toArray(new String[0])));
|
||||
} else if (sec.isString(key)) {
|
||||
map.put(pathKey, new LangMessage(sec.getString(key)));
|
||||
} else {
|
||||
DeluxeHeads.print("Unable to load message at \"" + pathKey + "\", was not text or a list of text.");
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public LangMessage getMessage(String key) {
|
||||
LangMessage message = this.messages.get(key);
|
||||
return (message == null ? this.defaults.get(key) : message);
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
package nl.marido.deluxeheads.config.lang;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import nl.marido.deluxeheads.util.ArrayUtils;
|
||||
|
||||
public final class LangMessage {
|
||||
|
||||
private final String[] messages;
|
||||
private final Placeholder[] placeholders;
|
||||
|
||||
public LangMessage(String... messages) {
|
||||
this(messages, new Placeholder[0]);
|
||||
}
|
||||
|
||||
private LangMessage(String[] messages, Placeholder[] placeholders) {
|
||||
this.messages = messages;
|
||||
this.placeholders = placeholders;
|
||||
}
|
||||
|
||||
public LangMessage with(Placeholder... placeholders) {
|
||||
return new LangMessage(messages, ArrayUtils.append(this.placeholders, placeholders));
|
||||
}
|
||||
|
||||
public LangMessage with(String key, Object value) {
|
||||
return with(new Placeholder(key, value));
|
||||
}
|
||||
|
||||
public int getLineCount() {
|
||||
return messages.length;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getLineCount() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getSingle();
|
||||
}
|
||||
|
||||
public String getSingle() {
|
||||
return (isEmpty() ? "" : get()[0]);
|
||||
}
|
||||
|
||||
public String[] get() {
|
||||
return Placeholder.applyAll(Placeholder.colourAll(messages), placeholders);
|
||||
}
|
||||
|
||||
public void send(CommandSender sender) {
|
||||
for (String message : get()) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void send(Player player) {
|
||||
for (String message : get()) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getConfigSaveValue() {
|
||||
if (isEmpty())
|
||||
return "";
|
||||
|
||||
if (getLineCount() == 1)
|
||||
return messages[0];
|
||||
|
||||
return Arrays.asList(messages);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue