mirror of
https://github.com/songoda/EpicHeads.git
synced 2025-02-20 13:21:23 +01:00
Updated to 2.0.4 (not too much manual changes).
This commit is contained in:
parent
02be1447fc
commit
122aecdc7e
@ -1,24 +1,11 @@
|
||||
package net.sothatsit.heads;
|
||||
|
||||
import net.sothatsit.heads.cache.*;
|
||||
import net.sothatsit.heads.cache.legacy.CacheFileConverter;
|
||||
import net.sothatsit.heads.command.HeadsCommand;
|
||||
import net.sothatsit.heads.command.RuntimeCommand;
|
||||
import net.sothatsit.heads.config.FileConfigFile;
|
||||
import net.sothatsit.heads.config.MainConfig;
|
||||
import net.sothatsit.heads.cache.legacy.LegacyCacheConfig;
|
||||
import net.sothatsit.heads.config.lang.Lang;
|
||||
import net.sothatsit.heads.config.lang.LangConfig;
|
||||
import net.sothatsit.heads.config.menu.Menus;
|
||||
import net.sothatsit.heads.config.oldmenu.MenuConfig;
|
||||
import net.sothatsit.heads.economy.*;
|
||||
import net.sothatsit.heads.menu.ui.InventoryMenu;
|
||||
import net.sothatsit.heads.oldmenu.ClickInventory;
|
||||
import net.sothatsit.heads.util.Clock;
|
||||
import net.sothatsit.heads.volatilecode.injection.ProtocolHackFixer;
|
||||
import net.sothatsit.heads.volatilecode.reflection.Version;
|
||||
import net.sothatsit.heads.volatilecode.reflection.craftbukkit.CommandMap;
|
||||
import net.sothatsit.heads.volatilecode.reflection.craftbukkit.CraftServer;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@ -34,423 +21,441 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import net.sothatsit.heads.cache.CacheFile;
|
||||
import net.sothatsit.heads.cache.CacheHead;
|
||||
import net.sothatsit.heads.cache.ModsFile;
|
||||
import net.sothatsit.heads.cache.ModsFileHeader;
|
||||
import net.sothatsit.heads.cache.legacy.CacheFileConverter;
|
||||
import net.sothatsit.heads.cache.legacy.LegacyCacheConfig;
|
||||
import net.sothatsit.heads.command.HeadsCommand;
|
||||
import net.sothatsit.heads.command.RuntimeCommand;
|
||||
import net.sothatsit.heads.config.FileConfigFile;
|
||||
import net.sothatsit.heads.config.MainConfig;
|
||||
import net.sothatsit.heads.config.lang.Lang;
|
||||
import net.sothatsit.heads.config.lang.LangConfig;
|
||||
import net.sothatsit.heads.config.menu.Menus;
|
||||
import net.sothatsit.heads.config.oldmenu.MenuConfig;
|
||||
import net.sothatsit.heads.economy.Economy;
|
||||
import net.sothatsit.heads.economy.ItemEconomy;
|
||||
import net.sothatsit.heads.economy.NoEconomy;
|
||||
import net.sothatsit.heads.economy.PlayerPointsEconomy;
|
||||
import net.sothatsit.heads.economy.VaultEconomy;
|
||||
import net.sothatsit.heads.menu.ui.InventoryMenu;
|
||||
import net.sothatsit.heads.oldmenu.ClickInventory;
|
||||
import net.sothatsit.heads.util.Clock;
|
||||
import net.sothatsit.heads.volatilecode.injection.ProtocolHackFixer;
|
||||
import net.sothatsit.heads.volatilecode.reflection.Version;
|
||||
import net.sothatsit.heads.volatilecode.reflection.craftbukkit.CommandMap;
|
||||
import net.sothatsit.heads.volatilecode.reflection.craftbukkit.CraftServer;
|
||||
|
||||
public class Heads extends JavaPlugin implements Listener {
|
||||
|
||||
private static Heads instance;
|
||||
private CacheFile cache;
|
||||
private MenuConfig oldMenuConfig;
|
||||
private Menus menus;
|
||||
private MainConfig mainConfig;
|
||||
private LangConfig langConfig;
|
||||
private Economy economy;
|
||||
private LegacyIDs legacyIDs;
|
||||
private boolean commandsRegistered = false;
|
||||
private boolean blockStoreAvailable = false;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if(Version.isBelow(Version.v1_8)) {
|
||||
System.err.println("------------------------------------------------------------");
|
||||
System.err.println(" Heads no longer supports versions below MineCraft 1.8 ");
|
||||
System.err.println(" Please switch to Heads version 1.15.1 or before ");
|
||||
System.err.println("------------------------------------------------------------");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
instance = this;
|
||||
|
||||
Clock timer = Clock.start();
|
||||
|
||||
loadCache();
|
||||
|
||||
try {
|
||||
legacyIDs = LegacyIDs.readResource("legacy-ids.txt");
|
||||
} catch(IOException exception) {
|
||||
legacyIDs = LegacyIDs.EMPTY;
|
||||
severe("Unable to load legacy IDs to perform conversion from older Spigot versions");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
this.menus = new Menus();
|
||||
this.menus.reload();
|
||||
private static Heads instance;
|
||||
private CacheFile cache;
|
||||
private MenuConfig oldMenuConfig;
|
||||
private Menus menus;
|
||||
private MainConfig mainConfig;
|
||||
private LangConfig langConfig;
|
||||
private Economy economy;
|
||||
private LegacyIDs legacyIDs;
|
||||
private boolean commandsRegistered = false;
|
||||
private boolean blockStoreAvailable = false;
|
||||
|
||||
this.oldMenuConfig = new MenuConfig(getVersionedConfig("menus.yml"));
|
||||
this.langConfig = new LangConfig();
|
||||
this.mainConfig = new MainConfig();
|
||||
this.economy = hookEconomy();
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (Version.isBelow(Version.v1_8)) {
|
||||
System.err.println("------------------------------------------------------------");
|
||||
System.err.println(" Heads no longer supports versions below MineCraft 1.8 ");
|
||||
System.err.println(" Please switch to Heads version 1.15.1 or before ");
|
||||
System.err.println("------------------------------------------------------------");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
ProtocolHackFixer.fix();
|
||||
instance = this;
|
||||
|
||||
registerCommands();
|
||||
tryHookBlockStore();
|
||||
Clock timer = Clock.start();
|
||||
|
||||
new HeadNamer().registerEvents();
|
||||
loadCache();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
try {
|
||||
legacyIDs = LegacyIDs.readResource("legacy-ids.txt");
|
||||
} catch (IOException exception) {
|
||||
legacyIDs = LegacyIDs.EMPTY;
|
||||
severe("Unable to load legacy IDs to perform conversion from older Spigot versions");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
if(mainConfig.shouldCheckForUpdates()) {
|
||||
checkForUpdates();
|
||||
}
|
||||
this.menus = new Menus();
|
||||
this.menus.reload();
|
||||
|
||||
info("Heads plugin enabled with " + cache.getHeadCount() + " heads " + timer);
|
||||
}
|
||||
this.oldMenuConfig = new MenuConfig(getVersionedConfig("menus.yml"));
|
||||
this.langConfig = new LangConfig();
|
||||
this.mainConfig = new MainConfig();
|
||||
this.economy = hookEconomy();
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
instance = null;
|
||||
|
||||
unregisterCommands();
|
||||
}
|
||||
ProtocolHackFixer.fix();
|
||||
|
||||
private void checkForUpdates() {
|
||||
async(() -> {
|
||||
try {
|
||||
String currentVersion = UpdateChecker.getCurrentVersion();
|
||||
String latestVersion = UpdateChecker.getLatestVersion();
|
||||
registerCommands();
|
||||
tryHookBlockStore();
|
||||
|
||||
if(!UpdateChecker.isNewerVersion(latestVersion))
|
||||
return;
|
||||
new HeadNamer().registerEvents();
|
||||
|
||||
warning("A newer version of Heads, Heads v" + latestVersion + ", is available for download");
|
||||
warning("You are currently using Heads v" + currentVersion);
|
||||
} catch(IOException e) {
|
||||
severe("There was an error checking for an update for Heads");
|
||||
}
|
||||
});
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
|
||||
private void registerCommands() {
|
||||
if (commandsRegistered) {
|
||||
unregisterCommands();
|
||||
}
|
||||
if (mainConfig.shouldCheckForUpdates()) {
|
||||
checkForUpdates();
|
||||
}
|
||||
|
||||
SimpleCommandMap commandMap = CraftServer.get().getCommandMap();
|
||||
info("Heads plugin enabled with " + cache.getHeadCount() + " heads " + timer);
|
||||
}
|
||||
|
||||
RuntimeCommand heads = new RuntimeCommand(mainConfig.getHeadCommand());
|
||||
heads.setExecutor(new HeadsCommand());
|
||||
heads.setDescription(mainConfig.getHeadDescription());
|
||||
heads.setAliases(Arrays.asList(mainConfig.getHeadAliases()));
|
||||
|
||||
commandMap.register("heads", heads);
|
||||
|
||||
commandsRegistered = true;
|
||||
}
|
||||
|
||||
private void unregisterCommands() {
|
||||
SimpleCommandMap commandMap = CraftServer.get().getCommandMap();
|
||||
Map<String, Command> map = CommandMap.getCommandMap(commandMap);
|
||||
|
||||
map.values().removeIf(command -> command instanceof RuntimeCommand);
|
||||
|
||||
commandsRegistered = false;
|
||||
}
|
||||
@Override
|
||||
public void onDisable() {
|
||||
instance = null;
|
||||
|
||||
public void reloadConfigs() {
|
||||
oldMenuConfig.reload();
|
||||
menus.reload();
|
||||
langConfig.reload();
|
||||
mainConfig.reload();
|
||||
unregisterCommands();
|
||||
}
|
||||
|
||||
registerCommands();
|
||||
private void checkForUpdates() {
|
||||
async(() -> {
|
||||
try {
|
||||
String currentVersion = UpdateChecker.getCurrentVersion();
|
||||
String latestVersion = UpdateChecker.getLatestVersion();
|
||||
|
||||
economy = hookEconomy();
|
||||
if (!UpdateChecker.isNewerVersion(latestVersion))
|
||||
return;
|
||||
|
||||
tryHookBlockStore();
|
||||
}
|
||||
warning("A newer version of Heads, Heads v" + latestVersion + ", is available for download");
|
||||
warning("You are currently using Heads v" + currentVersion);
|
||||
} catch (IOException e) {
|
||||
severe("There was an error checking for an update for Heads");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public File getCacheFile() {
|
||||
if(!getDataFolder().exists() && !getDataFolder().mkdirs())
|
||||
throw new RuntimeException("Unable to create the data folder to save plugin files");
|
||||
private void registerCommands() {
|
||||
if (commandsRegistered) {
|
||||
unregisterCommands();
|
||||
}
|
||||
|
||||
if(!getDataFolder().isDirectory())
|
||||
throw new RuntimeException("plugins/Heads should be a directory, yet there is a file with the same name");
|
||||
SimpleCommandMap commandMap = CraftServer.get().getCommandMap();
|
||||
|
||||
return new File(getDataFolder(), "heads.cache");
|
||||
}
|
||||
RuntimeCommand heads = new RuntimeCommand(mainConfig.getHeadCommand());
|
||||
heads.setExecutor(new HeadsCommand());
|
||||
heads.setDescription(mainConfig.getHeadDescription());
|
||||
heads.setAliases(Arrays.asList(mainConfig.getHeadAliases()));
|
||||
|
||||
private CacheFile loadCache() {
|
||||
File file = getCacheFile();
|
||||
FileConfigFile legacyConfig = new FileConfigFile("cache.yml");
|
||||
commandMap.register("heads", heads);
|
||||
|
||||
boolean requiresWrite = false;
|
||||
commandsRegistered = true;
|
||||
}
|
||||
|
||||
if(!file.exists()) {
|
||||
requiresWrite = true;
|
||||
private void unregisterCommands() {
|
||||
SimpleCommandMap commandMap = CraftServer.get().getCommandMap();
|
||||
Map<String, Command> map = CommandMap.getCommandMap(commandMap);
|
||||
|
||||
if(legacyConfig.getFile().exists()) {
|
||||
Clock timer = Clock.start();
|
||||
map.values().removeIf(command -> command instanceof RuntimeCommand);
|
||||
|
||||
LegacyCacheConfig legacy = new LegacyCacheConfig(legacyConfig);
|
||||
cache = CacheFileConverter.convertToCacheFile("main-cache", legacy);
|
||||
commandsRegistered = false;
|
||||
}
|
||||
|
||||
info("Converted legacy yaml cache file to new binary file " + timer);
|
||||
} else {
|
||||
cache = new CacheFile("main-cache");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Clock timer = Clock.start();
|
||||
public void reloadConfigs() {
|
||||
oldMenuConfig.reload();
|
||||
menus.reload();
|
||||
langConfig.reload();
|
||||
mainConfig.reload();
|
||||
|
||||
cache = CacheFile.read(file);
|
||||
registerCommands();
|
||||
|
||||
info("Loaded cache file " + timer);
|
||||
} catch (IOException e) {
|
||||
severe("Unable to read heads.cache file");
|
||||
throw new RuntimeException("There was an exception reading the heads.cache file", e);
|
||||
}
|
||||
}
|
||||
economy = hookEconomy();
|
||||
|
||||
if(installAddons() || requiresWrite) {
|
||||
saveCache();
|
||||
}
|
||||
tryHookBlockStore();
|
||||
}
|
||||
|
||||
if(legacyConfig.getFile().exists() && !legacyConfig.getFile().delete()) {
|
||||
severe("Unable to delete legacy yaml cache file");
|
||||
}
|
||||
public File getCacheFile() {
|
||||
if (!getDataFolder().exists() && !getDataFolder().mkdirs())
|
||||
throw new RuntimeException("Unable to create the data folder to save plugin files");
|
||||
|
||||
return cache;
|
||||
}
|
||||
if (!getDataFolder().isDirectory())
|
||||
throw new RuntimeException("plugins/Heads should be a directory, yet there is a file with the same name");
|
||||
|
||||
public void saveCache() {
|
||||
File file = getCacheFile();
|
||||
return new File(getDataFolder(), "heads.cache");
|
||||
}
|
||||
|
||||
try {
|
||||
Clock timer = Clock.start();
|
||||
private CacheFile loadCache() {
|
||||
File file = getCacheFile();
|
||||
FileConfigFile legacyConfig = new FileConfigFile("cache.yml");
|
||||
|
||||
cache.write(file);
|
||||
boolean requiresWrite = false;
|
||||
|
||||
info("Saved cache file " + timer);
|
||||
} catch (IOException e) {
|
||||
severe("Unable to save the cache to heads.cache");
|
||||
throw new RuntimeException("There was an exception saving the cache", e);
|
||||
}
|
||||
}
|
||||
if (!file.exists()) {
|
||||
requiresWrite = true;
|
||||
|
||||
private ModsFileHeader readModsFileHeader() {
|
||||
try {
|
||||
return ModsFileHeader.readResource("cache.mods");
|
||||
} catch (IOException e) {
|
||||
severe("Unable to read header of cache.mods");
|
||||
throw new RuntimeException("Unable to read header of cache.mods", e);
|
||||
}
|
||||
}
|
||||
if (legacyConfig.getFile().exists()) {
|
||||
Clock timer = Clock.start();
|
||||
|
||||
private ModsFile readModsFile() {
|
||||
try {
|
||||
return ModsFile.readResource("cache.mods");
|
||||
} catch (IOException e) {
|
||||
severe("Unable to read mods from cache.mods");
|
||||
throw new RuntimeException("Unable to read mods from cache.mods", e);
|
||||
}
|
||||
}
|
||||
LegacyCacheConfig legacy = new LegacyCacheConfig(legacyConfig);
|
||||
cache = CacheFileConverter.convertToCacheFile("main-cache", legacy);
|
||||
|
||||
private boolean installAddons() {
|
||||
Clock timer = Clock.start();
|
||||
info("Converted legacy yaml cache file to new binary file " + timer);
|
||||
} else {
|
||||
cache = new CacheFile("main-cache");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Clock timer = Clock.start();
|
||||
|
||||
ModsFileHeader header = readModsFileHeader();
|
||||
int newMods = header.getUninstalledMods(cache);
|
||||
cache = CacheFile.read(file);
|
||||
|
||||
if(newMods == 0)
|
||||
return false;
|
||||
info("Loaded cache file " + timer);
|
||||
} catch (IOException e) {
|
||||
severe("Unable to read heads.cache file");
|
||||
throw new RuntimeException("There was an exception reading the heads.cache file", e);
|
||||
}
|
||||
}
|
||||
|
||||
ModsFile mods = readModsFile();
|
||||
if (installAddons() || requiresWrite) {
|
||||
saveCache();
|
||||
}
|
||||
|
||||
int newHeads = mods.installMods(cache);
|
||||
if (legacyConfig.getFile().exists() && !legacyConfig.getFile().delete()) {
|
||||
severe("Unable to delete legacy yaml cache file");
|
||||
}
|
||||
|
||||
if(newHeads > 0) {
|
||||
info("Added " + newHeads + " new heads from " + newMods + " addons " + timer);
|
||||
} else {
|
||||
info("Installed " + newMods + " addons " + timer);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public void saveCache() {
|
||||
File file = getCacheFile();
|
||||
|
||||
private Economy hookEconomy() {
|
||||
if(!mainConfig.isEconomyEnabled())
|
||||
return new NoEconomy();
|
||||
try {
|
||||
Clock timer = Clock.start();
|
||||
|
||||
Economy economy = null;
|
||||
cache.write(file);
|
||||
|
||||
if(mainConfig.isVaultEconomyEnabled()) {
|
||||
economy = tryHookEconomy(null, new VaultEconomy());
|
||||
}
|
||||
info("Saved cache file " + timer);
|
||||
} catch (IOException e) {
|
||||
severe("Unable to save the cache to heads.cache");
|
||||
throw new RuntimeException("There was an exception saving the cache", e);
|
||||
}
|
||||
}
|
||||
|
||||
if(mainConfig.isItemEconomyEnabled()) {
|
||||
economy = tryHookEconomy(economy, new ItemEconomy());
|
||||
}
|
||||
private ModsFileHeader readModsFileHeader() {
|
||||
try {
|
||||
return ModsFileHeader.readResource("cache.mods");
|
||||
} catch (IOException e) {
|
||||
severe("Unable to read header of cache.mods");
|
||||
throw new RuntimeException("Unable to read header of cache.mods", e);
|
||||
}
|
||||
}
|
||||
|
||||
if(mainConfig.isPlayerPointsEconomyEnabled()) {
|
||||
economy = tryHookEconomy(economy, new PlayerPointsEconomy());
|
||||
}
|
||||
private ModsFile readModsFile() {
|
||||
try {
|
||||
return ModsFile.readResource("cache.mods");
|
||||
} catch (IOException e) {
|
||||
severe("Unable to read mods from cache.mods");
|
||||
throw new RuntimeException("Unable to read mods from cache.mods", e);
|
||||
}
|
||||
}
|
||||
|
||||
if(economy == null || economy instanceof NoEconomy) {
|
||||
severe("Economy enabled in config.yml yet Vault, PlayerPoints and Item economies disabled. " +
|
||||
"Player's will not be able to purchase heads.");
|
||||
private boolean installAddons() {
|
||||
Clock timer = Clock.start();
|
||||
|
||||
economy = (economy != null ? economy : new NoEconomy());
|
||||
}
|
||||
ModsFileHeader header = readModsFileHeader();
|
||||
int newMods = header.getUninstalledMods(cache);
|
||||
|
||||
return economy;
|
||||
}
|
||||
if (newMods == 0)
|
||||
return false;
|
||||
|
||||
private Economy tryHookEconomy(Economy currentlyHooked, Economy toHook) {
|
||||
if(currentlyHooked != null) {
|
||||
warning(toHook.getName() + " economy is not the only economy enabled in the config.yml.");
|
||||
ModsFile mods = readModsFile();
|
||||
|
||||
if(!(currentlyHooked instanceof NoEconomy))
|
||||
return currentlyHooked;
|
||||
}
|
||||
int newHeads = mods.installMods(cache);
|
||||
|
||||
if(!toHook.tryHook()) {
|
||||
severe(toHook.getName() + " enabled in config.yml, yet Heads was unable to hook into it.");
|
||||
return new NoEconomy();
|
||||
}
|
||||
if (newHeads > 0) {
|
||||
info("Added " + newHeads + " new heads from " + newMods + " addons " + timer);
|
||||
} else {
|
||||
info("Installed " + newMods + " addons " + timer);
|
||||
}
|
||||
|
||||
info("Loaded " + toHook.getName() + " economy");
|
||||
return toHook;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void tryHookBlockStore() {
|
||||
if (mainConfig.shouldUseBlockStore() && Bukkit.getPluginManager().getPlugin("BlockStore") != null) {
|
||||
blockStoreAvailable = false;
|
||||
|
||||
try {
|
||||
Class<?> apiClass = Class.forName("net.sothatsit.blockstore.BlockStoreApi");
|
||||
|
||||
apiClass.getDeclaredMethod("retrieveBlockMeta",
|
||||
Plugin.class, Location.class, Plugin.class, String.class, Consumer.class);
|
||||
|
||||
info("Hooked BlockStore");
|
||||
|
||||
blockStoreAvailable = true;
|
||||
|
||||
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||
severe("Unable to hook BlockStore, the version of BlockStore you are " +
|
||||
"using may be outdated. Heads requires BlockStore v1.5.0.");
|
||||
severe("Please update BlockStore and report this to Sothatsit if the problem persists.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
Inventory inventory = e.getInventory();
|
||||
|
||||
if(inventory == null)
|
||||
return;
|
||||
|
||||
InventoryHolder holder = inventory.getHolder();
|
||||
|
||||
if (holder instanceof ClickInventory) {
|
||||
((ClickInventory) holder).onClick(e);
|
||||
} else if (holder instanceof InventoryMenu) {
|
||||
((InventoryMenu) holder).onClick(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isExemptFromCost(Player player) {
|
||||
if(!mainConfig.isEconomyEnabled() || player.hasPermission("heads.bypasscost") )
|
||||
return true;
|
||||
|
||||
return mainConfig.isFreeInCreative() && player.getGameMode() == GameMode.CREATIVE;
|
||||
}
|
||||
|
||||
public boolean chargeForHead(Player player, CacheHead head) {
|
||||
if(isExemptFromCost(player))
|
||||
return true;
|
||||
|
||||
double cost = head.getCost();
|
||||
|
||||
if(cost <= 0)
|
||||
return true;
|
||||
|
||||
if(!economy.hasBalance(player, cost)) {
|
||||
Lang.Menu.Get.notEnoughMoney(head.getName(), head.getCost()).send(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!economy.takeBalance(player, cost)) {
|
||||
Lang.Menu.Get.transactionError(head.getName(), head.getCost()).send(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
Lang.Menu.Get.purchased(head.getName(), head.getCost()).send(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getCategoryPermission(String category) {
|
||||
return "heads.category." + category.toLowerCase().replace(' ', '_');
|
||||
}
|
||||
|
||||
public static Heads getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static LegacyIDs getLegacyIDs() {
|
||||
return instance.legacyIDs;
|
||||
}
|
||||
|
||||
public static MainConfig getMainConfig() {
|
||||
return instance.mainConfig;
|
||||
}
|
||||
|
||||
public static CacheFile getCache() {
|
||||
return instance.cache;
|
||||
}
|
||||
|
||||
public static Menus getMenus() {
|
||||
return instance.menus;
|
||||
}
|
||||
|
||||
public static MenuConfig getMenuConfig() {
|
||||
return instance.oldMenuConfig;
|
||||
}
|
||||
|
||||
public static LangConfig getLangConfig() {
|
||||
return instance.langConfig;
|
||||
}
|
||||
|
||||
public static Economy getEconomy() {
|
||||
return instance.economy;
|
||||
}
|
||||
|
||||
public static boolean isBlockStoreAvailable() {
|
||||
return instance.blockStoreAvailable;
|
||||
}
|
||||
|
||||
public static void info(String info) {
|
||||
instance.getLogger().info(info);
|
||||
}
|
||||
|
||||
public static void warning(String warning) {
|
||||
instance.getLogger().warning(warning);
|
||||
}
|
||||
|
||||
public static void severe(String severe) {
|
||||
instance.getLogger().severe(severe);
|
||||
}
|
||||
|
||||
public static void sync(Runnable task) {
|
||||
Bukkit.getScheduler().runTask(instance, task);
|
||||
}
|
||||
|
||||
public static void async(Runnable task) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(instance, task);
|
||||
}
|
||||
|
||||
public static FileConfigFile getVersionedConfig(String resource) {
|
||||
if(Version.isBelow(Version.v1_13))
|
||||
return new FileConfigFile(resource, "pre1_13/" + resource);
|
||||
|
||||
return new FileConfigFile(resource);
|
||||
}
|
||||
private Economy hookEconomy() {
|
||||
if (!mainConfig.isEconomyEnabled())
|
||||
return new NoEconomy();
|
||||
|
||||
Economy economy = null;
|
||||
|
||||
if (mainConfig.isVaultEconomyEnabled()) {
|
||||
economy = tryHookEconomy(null, new VaultEconomy());
|
||||
}
|
||||
|
||||
if (mainConfig.isItemEconomyEnabled()) {
|
||||
economy = tryHookEconomy(economy, new ItemEconomy());
|
||||
}
|
||||
|
||||
if (mainConfig.isPlayerPointsEconomyEnabled()) {
|
||||
economy = tryHookEconomy(economy, new PlayerPointsEconomy());
|
||||
}
|
||||
|
||||
if (economy == null || economy instanceof NoEconomy) {
|
||||
severe("Economy enabled in config.yml yet Vault, PlayerPoints and Item economies disabled. " + "Player's will not be able to purchase heads.");
|
||||
|
||||
economy = (economy != null ? economy : new NoEconomy());
|
||||
}
|
||||
|
||||
return economy;
|
||||
}
|
||||
|
||||
private Economy tryHookEconomy(Economy currentlyHooked, Economy toHook) {
|
||||
if (currentlyHooked != null) {
|
||||
warning(toHook.getName() + " economy is not the only economy enabled in the config.yml.");
|
||||
|
||||
if (!(currentlyHooked instanceof NoEconomy))
|
||||
return currentlyHooked;
|
||||
}
|
||||
|
||||
if (!toHook.tryHook()) {
|
||||
severe(toHook.getName() + " enabled in config.yml, yet Heads was unable to hook into it.");
|
||||
return new NoEconomy();
|
||||
}
|
||||
|
||||
info("Loaded " + toHook.getName() + " economy");
|
||||
return toHook;
|
||||
}
|
||||
|
||||
private void tryHookBlockStore() {
|
||||
if (mainConfig.shouldUseBlockStore() && Bukkit.getPluginManager().getPlugin("BlockStore") != null) {
|
||||
blockStoreAvailable = false;
|
||||
|
||||
try {
|
||||
Class<?> apiClass = Class.forName("net.sothatsit.blockstore.BlockStoreApi");
|
||||
|
||||
apiClass.getDeclaredMethod("retrieveBlockMeta", Plugin.class, Location.class, Plugin.class, String.class, Consumer.class);
|
||||
|
||||
info("Hooked BlockStore");
|
||||
|
||||
blockStoreAvailable = true;
|
||||
|
||||
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||
severe("Unable to hook BlockStore, the version of BlockStore you are " + "using may be outdated. Heads requires BlockStore v1.5.0.");
|
||||
severe("Please update BlockStore and report this to Sothatsit if the problem persists.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
Inventory inventory = e.getInventory();
|
||||
|
||||
if (inventory == null)
|
||||
return;
|
||||
|
||||
InventoryHolder holder = inventory.getHolder();
|
||||
|
||||
if (holder instanceof ClickInventory) {
|
||||
((ClickInventory) holder).onClick(e);
|
||||
} else if (holder instanceof InventoryMenu) {
|
||||
((InventoryMenu) holder).onClick(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isExemptFromCost(Player player) {
|
||||
if (!mainConfig.isEconomyEnabled() || player.hasPermission("heads.bypasscost"))
|
||||
return true;
|
||||
|
||||
return mainConfig.isFreeInCreative() && player.getGameMode() == GameMode.CREATIVE;
|
||||
}
|
||||
|
||||
public boolean chargeForHead(Player player, CacheHead head) {
|
||||
if (isExemptFromCost(player))
|
||||
return true;
|
||||
|
||||
double cost = head.getCost();
|
||||
|
||||
if (cost <= 0)
|
||||
return true;
|
||||
|
||||
if (!economy.hasBalance(player, cost)) {
|
||||
Lang.Menu.Get.notEnoughMoney(head.getName(), head.getCost()).send(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!economy.takeBalance(player, cost)) {
|
||||
Lang.Menu.Get.transactionError(head.getName(), head.getCost()).send(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
Lang.Menu.Get.purchased(head.getName(), head.getCost()).send(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getCategoryPermission(String category) {
|
||||
return "heads.category." + category.toLowerCase().replace(' ', '_');
|
||||
}
|
||||
|
||||
public static Heads getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static LegacyIDs getLegacyIDs() {
|
||||
return instance.legacyIDs;
|
||||
}
|
||||
|
||||
public static MainConfig getMainConfig() {
|
||||
return instance.mainConfig;
|
||||
}
|
||||
|
||||
public static CacheFile getCache() {
|
||||
return instance.cache;
|
||||
}
|
||||
|
||||
public static Menus getMenus() {
|
||||
return instance.menus;
|
||||
}
|
||||
|
||||
public static MenuConfig getMenuConfig() {
|
||||
return instance.oldMenuConfig;
|
||||
}
|
||||
|
||||
public static LangConfig getLangConfig() {
|
||||
return instance.langConfig;
|
||||
}
|
||||
|
||||
public static Economy getEconomy() {
|
||||
return instance.economy;
|
||||
}
|
||||
|
||||
public static boolean isBlockStoreAvailable() {
|
||||
return instance.blockStoreAvailable;
|
||||
}
|
||||
|
||||
public static void info(String info) {
|
||||
instance.getLogger().info(info);
|
||||
}
|
||||
|
||||
public static void warning(String warning) {
|
||||
instance.getLogger().warning(warning);
|
||||
}
|
||||
|
||||
public static void severe(String severe) {
|
||||
instance.getLogger().severe(severe);
|
||||
}
|
||||
|
||||
public static void sync(Runnable task) {
|
||||
Bukkit.getScheduler().runTask(instance, task);
|
||||
}
|
||||
|
||||
public static void async(Runnable task) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(instance, task);
|
||||
}
|
||||
|
||||
public static FileConfigFile getVersionedConfig(String resource) {
|
||||
if (Version.isBelow(Version.v1_13))
|
||||
return new FileConfigFile(resource, "pre1_13/" + resource);
|
||||
|
||||
return new FileConfigFile(resource);
|
||||
}
|
||||
|
||||
}
|
@ -3,24 +3,42 @@ package net.sothatsit.heads;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class LiveHead {
|
||||
|
||||
private int frames;
|
||||
private List<Heads> fases;
|
||||
private List<Heads> texures;
|
||||
private Location location;
|
||||
|
||||
public LiveHead(int frames, List<Heads> fases, Location location /*.more.*/) {
|
||||
// Do not pay attention to this class, this is just a sort of sketch which is not ready.
|
||||
|
||||
public LiveHead(int frames, List<Heads> texures, Location location /*.more.*/) {
|
||||
// Safety first, experimental features should not crash servers.
|
||||
if (frames > 60)
|
||||
frames = 60;
|
||||
this.frames = frames;
|
||||
this.fases = fases;
|
||||
if (texures.size() > frames)
|
||||
while (texures.size() != frames) {
|
||||
texures.remove(0);
|
||||
}
|
||||
this.texures = texures;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public void renderTexure() {
|
||||
public void renderTexures() {
|
||||
int interval = frames / 20;
|
||||
new BukkitRunnable() {
|
||||
int fases;
|
||||
|
||||
public void run() {
|
||||
// nessecary checks for head texures for fases.
|
||||
fases++;
|
||||
if (fases >= frames)
|
||||
fases = 0;
|
||||
|
||||
}
|
||||
}.runTaskTimer(Heads.getInstance(), 0, interval);
|
||||
// Render (but I am too tired for now).
|
||||
// TODO: External classes from the animation packages.
|
||||
}
|
||||
|
@ -93,6 +93,7 @@ public class GetCommand extends AbstractCommand {
|
||||
Lang.Command.Get.adding(name).send(player);
|
||||
|
||||
player.getInventory().addItem(head.getItemStack());
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,43 @@
|
||||
package net.sothatsit.heads.command.user;
|
||||
|
||||
import net.sothatsit.heads.command.AbstractCommand;
|
||||
import net.sothatsit.heads.config.MainConfig;
|
||||
import net.sothatsit.heads.config.lang.Lang;
|
||||
|
||||
import net.sothatsit.heads.oldmenu.mode.InvModeType;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.sothatsit.heads.command.AbstractCommand;
|
||||
import net.sothatsit.heads.config.MainConfig;
|
||||
import net.sothatsit.heads.config.lang.Lang;
|
||||
import net.sothatsit.heads.oldmenu.mode.InvModeType;
|
||||
|
||||
public class OpenMenuCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String getCommandLabel(MainConfig config) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "heads.menu";
|
||||
}
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "heads.menu";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lang.HelpSection getHelp() {
|
||||
return Lang.Command.OpenMenu.help();
|
||||
}
|
||||
@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);
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
Lang.Command.Errors.mustBePlayer().send(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
// CacheHeadsMenu.openHeadsMenu((Player) sender);
|
||||
InvModeType.GET.open((Player) sender);
|
||||
|
||||
// CacheHeadsMenu.openHeadsMenu((Player) sender);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,201 +1,193 @@
|
||||
package net.sothatsit.heads.menu;
|
||||
|
||||
import net.sothatsit.heads.menu.ui.element.Element;
|
||||
import net.sothatsit.heads.Heads;
|
||||
import net.sothatsit.heads.cache.CacheFile;
|
||||
import net.sothatsit.heads.cache.CacheHead;
|
||||
import net.sothatsit.heads.menu.ui.*;
|
||||
import net.sothatsit.heads.menu.ui.item.Button;
|
||||
import net.sothatsit.heads.util.Checks;
|
||||
import net.sothatsit.heads.menu.ui.item.Item;
|
||||
import net.sothatsit.heads.util.Stringify;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.sothatsit.heads.Heads;
|
||||
import net.sothatsit.heads.cache.CacheFile;
|
||||
import net.sothatsit.heads.cache.CacheHead;
|
||||
import net.sothatsit.heads.menu.ui.Bounds;
|
||||
import net.sothatsit.heads.menu.ui.InventoryMenu;
|
||||
import net.sothatsit.heads.menu.ui.MenuResponse;
|
||||
import net.sothatsit.heads.menu.ui.element.Element;
|
||||
import net.sothatsit.heads.menu.ui.item.Button;
|
||||
import net.sothatsit.heads.menu.ui.item.Item;
|
||||
import net.sothatsit.heads.util.Checks;
|
||||
import net.sothatsit.heads.util.Stringify;
|
||||
|
||||
public class CacheHeadsMenu extends Element {
|
||||
|
||||
public static final Item defaultClose = Item.create(Material.REDSTONE_BLOCK).name("&cClose Menu");
|
||||
public static final Item defaultBack = Item.create(Material.REDSTONE_BLOCK).name("&cBack to Categories");
|
||||
public static final Item defaultSearch = Item.create(Material.COMPASS).name("&7Search Heads");
|
||||
public static final String defaultCategoriesTitle = "Categories";
|
||||
public static final String defaultCategoryTitle = "%category%";
|
||||
public static final Item defaultClose = Item.create(Material.REDSTONE_BLOCK).name("&cClose Menu");
|
||||
public static final Item defaultBack = Item.create(Material.REDSTONE_BLOCK).name("&cBack to Categories");
|
||||
public static final Item defaultSearch = Item.create(Material.COMPASS).name("&7Search Heads");
|
||||
public static final String defaultCategoriesTitle = "Categories";
|
||||
public static final String defaultCategoryTitle = "%category%";
|
||||
|
||||
public static final Template defaultTemplate = new Template(
|
||||
CategoriesMenu.defaultTemplate, HeadsMenu.defaultTemplate,
|
||||
defaultClose, defaultBack, defaultSearch,
|
||||
defaultCategoriesTitle, defaultCategoryTitle
|
||||
);
|
||||
public static final Template defaultTemplate = new Template(CategoriesMenu.defaultTemplate, HeadsMenu.defaultTemplate, defaultClose, defaultBack, defaultSearch, defaultCategoriesTitle, defaultCategoryTitle);
|
||||
|
||||
private Template template;
|
||||
private Template template;
|
||||
|
||||
private final CacheFile cache;
|
||||
private final InventoryMenu inventoryMenu;
|
||||
private final CacheFile cache;
|
||||
private final InventoryMenu inventoryMenu;
|
||||
|
||||
private final CategoriesMenu categoriesMenu;
|
||||
private final HeadsMenu headsMenu;
|
||||
private final CategoriesMenu categoriesMenu;
|
||||
private final HeadsMenu headsMenu;
|
||||
|
||||
private String selectedCategory = null;
|
||||
private String selectedCategory = null;
|
||||
|
||||
public CacheHeadsMenu(CacheFile cache, InventoryMenu inventoryMenu, Bounds bounds,
|
||||
Function<CacheHead, MenuResponse> onSelect) {
|
||||
super(bounds);
|
||||
public CacheHeadsMenu(CacheFile cache, InventoryMenu inventoryMenu, Bounds bounds, Function<CacheHead, MenuResponse> onSelect) {
|
||||
super(bounds);
|
||||
|
||||
Checks.ensureNonNull(cache, "cache");
|
||||
Checks.ensureNonNull(inventoryMenu, "inventoryMenu");
|
||||
Checks.ensureNonNull(onSelect, "onSelect");
|
||||
Checks.ensureTrue(bounds.height >= 3, "bounds must have a height of at least 3");
|
||||
Checks.ensureNonNull(cache, "cache");
|
||||
Checks.ensureNonNull(inventoryMenu, "inventoryMenu");
|
||||
Checks.ensureNonNull(onSelect, "onSelect");
|
||||
Checks.ensureTrue(bounds.height >= 3, "bounds must have a height of at least 3");
|
||||
|
||||
this.cache = cache;
|
||||
this.inventoryMenu = inventoryMenu;
|
||||
this.cache = cache;
|
||||
this.inventoryMenu = inventoryMenu;
|
||||
|
||||
this.categoriesMenu = new CategoriesMenu(cache, bounds, this::selectCategory);
|
||||
this.headsMenu = new HeadsMenu(bounds, onSelect);
|
||||
this.categoriesMenu = new CategoriesMenu(cache, bounds, this::selectCategory);
|
||||
this.headsMenu = new HeadsMenu(bounds, onSelect);
|
||||
|
||||
setTemplate(defaultTemplate);
|
||||
}
|
||||
setTemplate(defaultTemplate);
|
||||
}
|
||||
|
||||
public boolean onCategoriesScreen() {
|
||||
return selectedCategory == null;
|
||||
}
|
||||
public boolean onCategoriesScreen() {
|
||||
return selectedCategory == null;
|
||||
}
|
||||
|
||||
public MenuResponse close() {
|
||||
return MenuResponse.CLOSE;
|
||||
}
|
||||
public MenuResponse close() {
|
||||
return MenuResponse.CLOSE;
|
||||
}
|
||||
|
||||
public MenuResponse back() {
|
||||
this.selectedCategory = null;
|
||||
public MenuResponse back() {
|
||||
this.selectedCategory = null;
|
||||
|
||||
inventoryMenu.setTitle(template.getCategoriesTitle());
|
||||
inventoryMenu.setTitle(template.getCategoriesTitle());
|
||||
|
||||
return MenuResponse.UPDATE;
|
||||
}
|
||||
return MenuResponse.UPDATE;
|
||||
}
|
||||
|
||||
public MenuResponse search() {
|
||||
inventoryMenu.getPlayer().sendMessage("Search");
|
||||
public MenuResponse search() {
|
||||
inventoryMenu.getPlayer().sendMessage("Search");
|
||||
|
||||
return MenuResponse.NONE;
|
||||
}
|
||||
return MenuResponse.NONE;
|
||||
}
|
||||
|
||||
public MenuResponse selectCategory(String category) {
|
||||
Checks.ensureNonNull(category, "category");
|
||||
public MenuResponse selectCategory(String category) {
|
||||
Checks.ensureNonNull(category, "category");
|
||||
|
||||
List<CacheHead> heads = cache.getCategoryHeads(category);
|
||||
List<CacheHead> heads = cache.getCategoryHeads(category);
|
||||
|
||||
if(heads.size() == 0) {
|
||||
return back();
|
||||
}
|
||||
if (heads.size() == 0) {
|
||||
return back();
|
||||
}
|
||||
|
||||
this.selectedCategory = category;
|
||||
this.headsMenu.setItems(heads);
|
||||
this.selectedCategory = category;
|
||||
this.headsMenu.setItems(heads);
|
||||
|
||||
inventoryMenu.setTitle(template.getCategoryTitle(category));
|
||||
inventoryMenu.setTitle(template.getCategoryTitle(category));
|
||||
|
||||
return MenuResponse.UPDATE;
|
||||
}
|
||||
return MenuResponse.UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button[] getItems() {
|
||||
if(onCategoriesScreen()) {
|
||||
return categoriesMenu.getItems();
|
||||
} else {
|
||||
return headsMenu.getItems();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Button[] getItems() {
|
||||
if (onCategoriesScreen()) {
|
||||
return categoriesMenu.getItems();
|
||||
} else {
|
||||
return headsMenu.getItems();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTemplate(Template template) {
|
||||
Checks.ensureNonNull(template, "template");
|
||||
public void setTemplate(Template template) {
|
||||
Checks.ensureNonNull(template, "template");
|
||||
|
||||
this.template = template;
|
||||
this.template.init(this);
|
||||
this.template = template;
|
||||
this.template.init(this);
|
||||
|
||||
if(onCategoriesScreen()) {
|
||||
inventoryMenu.setTitle(template.getCategoriesTitle());
|
||||
} else {
|
||||
inventoryMenu.setTitle(template.getCategoryTitle(selectedCategory));
|
||||
}
|
||||
}
|
||||
if (onCategoriesScreen()) {
|
||||
inventoryMenu.setTitle(template.getCategoriesTitle());
|
||||
} else {
|
||||
inventoryMenu.setTitle(template.getCategoryTitle(selectedCategory));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Stringify.builder()
|
||||
.entry("template", template)
|
||||
.entry("cache", cache)
|
||||
.entry("headsMenu", headsMenu)
|
||||
.entry("categoriesMenu", categoriesMenu).toString();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return Stringify.builder().entry("template", template).entry("cache", cache).entry("headsMenu", headsMenu).entry("categoriesMenu", categoriesMenu).toString();
|
||||
}
|
||||
|
||||
public static final class Template {
|
||||
public static final class Template {
|
||||
|
||||
private final CategoriesMenu.Template categoriesTemplate;
|
||||
private final HeadsMenu.Template headsTemplate;
|
||||
private final Item close;
|
||||
private final Item back;
|
||||
private final Item search;
|
||||
private final String categoriesTitle;
|
||||
private final String categoryTitle;
|
||||
private final CategoriesMenu.Template categoriesTemplate;
|
||||
private final HeadsMenu.Template headsTemplate;
|
||||
private final Item close;
|
||||
private final Item back;
|
||||
private final Item search;
|
||||
private final String categoriesTitle;
|
||||
private final String categoryTitle;
|
||||
|
||||
public Template(CategoriesMenu.Template categoriesTemplate, HeadsMenu.Template headsTemplate,
|
||||
Item close, Item back, Item search, String categoriesTitle, String categoryTitle) {
|
||||
public Template(CategoriesMenu.Template categoriesTemplate, HeadsMenu.Template headsTemplate, Item close, Item back, Item search, String categoriesTitle, String categoryTitle) {
|
||||
|
||||
Checks.ensureNonNull(categoriesTemplate, "categoriesTemplate");
|
||||
Checks.ensureNonNull(headsTemplate, "headsTemplate");
|
||||
Checks.ensureNonNull(close, "close");
|
||||
Checks.ensureNonNull(back, "back");
|
||||
Checks.ensureNonNull(search, "search");
|
||||
Checks.ensureNonNull(categoriesTemplate, "categoriesTemplate");
|
||||
Checks.ensureNonNull(categoryTitle, "categoryTitle");
|
||||
Checks.ensureNonNull(categoriesTemplate, "categoriesTemplate");
|
||||
Checks.ensureNonNull(headsTemplate, "headsTemplate");
|
||||
Checks.ensureNonNull(close, "close");
|
||||
Checks.ensureNonNull(back, "back");
|
||||
Checks.ensureNonNull(search, "search");
|
||||
Checks.ensureNonNull(categoriesTemplate, "categoriesTemplate");
|
||||
Checks.ensureNonNull(categoryTitle, "categoryTitle");
|
||||
|
||||
this.categoriesTemplate = categoriesTemplate;
|
||||
this.headsTemplate = headsTemplate;
|
||||
this.close = close;
|
||||
this.back = back;
|
||||
this.search = search;
|
||||
this.categoriesTitle = ChatColor.translateAlternateColorCodes('&', categoriesTitle);
|
||||
this.categoryTitle = ChatColor.translateAlternateColorCodes('&', categoryTitle);
|
||||
}
|
||||
this.categoriesTemplate = categoriesTemplate;
|
||||
this.headsTemplate = headsTemplate;
|
||||
this.close = close;
|
||||
this.back = back;
|
||||
this.search = search;
|
||||
this.categoriesTitle = ChatColor.translateAlternateColorCodes('&', categoriesTitle);
|
||||
this.categoryTitle = ChatColor.translateAlternateColorCodes('&', categoryTitle);
|
||||
}
|
||||
|
||||
public String getCategoriesTitle() {
|
||||
return categoriesTitle;
|
||||
}
|
||||
public String getCategoriesTitle() {
|
||||
return categoriesTitle;
|
||||
}
|
||||
|
||||
public String getCategoryTitle(String category) {
|
||||
return categoryTitle.replace("%category%", category);
|
||||
}
|
||||
public String getCategoryTitle(String category) {
|
||||
return categoryTitle.replace("%category%", category);
|
||||
}
|
||||
|
||||
private void init(CacheHeadsMenu menu) {
|
||||
Button close = this.close.buildButton(menu::close);
|
||||
Button back = this.back.buildButton(menu::back);
|
||||
Button search = this.search.buildButton(menu::search);
|
||||
private void init(CacheHeadsMenu menu) {
|
||||
Button close = this.close.buildButton(menu::close);
|
||||
Button back = this.back.buildButton(menu::back);
|
||||
Button search = this.search.buildButton(menu::search);
|
||||
|
||||
menu.categoriesMenu.setTemplate(categoriesTemplate, close, search);
|
||||
menu.headsMenu.setTemplate(headsTemplate, back, search);
|
||||
}
|
||||
menu.categoriesMenu.setTemplate(categoriesTemplate, close, search);
|
||||
menu.headsMenu.setTemplate(headsTemplate, back, search);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Stringify.builder()
|
||||
.entry("categoriesTemplate", categoriesTemplate)
|
||||
.entry("headsTemplate", headsTemplate).toString();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return Stringify.builder().entry("categoriesTemplate", categoriesTemplate).entry("headsTemplate", headsTemplate).toString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void openHeadsMenu(Player player) {
|
||||
InventoryMenu inventory = new InventoryMenu(player, "Heads", 6);
|
||||
@Deprecated
|
||||
public static void openHeadsMenu(Player player) {
|
||||
InventoryMenu inventory = new InventoryMenu(player, "Heads", 6);
|
||||
|
||||
CacheHeadsMenu menu = new CacheHeadsMenu(Heads.getCache(), inventory, inventory.bounds, head -> {
|
||||
player.sendMessage(head.getName());
|
||||
return MenuResponse.NONE;
|
||||
});
|
||||
CacheHeadsMenu menu = new CacheHeadsMenu(Heads.getCache(), inventory, inventory.bounds, head -> {
|
||||
player.sendMessage(head.getName());
|
||||
return MenuResponse.NONE;
|
||||
});
|
||||
|
||||
menu.setTemplate(Heads.getMenus().getBrowseTemplate());
|
||||
menu.setTemplate(Heads.getMenus().getBrowseTemplate());
|
||||
|
||||
inventory.addElement(menu);
|
||||
inventory.open();
|
||||
}
|
||||
inventory.addElement(menu);
|
||||
inventory.open();
|
||||
}
|
||||
|
||||
}
|
||||
|
21
src/net/sothatsit/heads/patches/HeadPlace.java
Normal file
21
src/net/sothatsit/heads/patches/HeadPlace.java
Normal file
@ -0,0 +1,21 @@
|
||||
package net.sothatsit.heads.patches;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
import net.sothatsit.heads.volatilecode.reflection.Version;
|
||||
|
||||
public class HeadPlace implements Listener {
|
||||
|
||||
// TODO: Patch the issue reported by BlackGamer000 on 1.8.
|
||||
// register event
|
||||
|
||||
@EventHandler
|
||||
public void onHeadPlace(BlockPlaceEvent event) {
|
||||
if (Version.isBelow(Version.v1_8)) {
|
||||
// Need to find a fix for the texures on 1.8
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
main: net.sothatsit.heads.Heads
|
||||
author: Marido
|
||||
name: Heads
|
||||
version: 2.0.3
|
||||
version: 2.0.4
|
||||
api-version: 1.13
|
||||
softdepend: [Vault, PlayerPoints, BlockStore]
|
||||
loadbefore: [DeluxeMenus]
|
||||
|
Loading…
Reference in New Issue
Block a user