mirror of
https://github.com/IHasName/CustomHeads.git
synced 2025-02-17 19:21:28 +01:00
Support for 1.14
This commit is contained in:
parent
5786bb3737
commit
8a97e0bc3b
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>de.mrstein.customheads</groupId>
|
||||
<artifactId>CustomHeads</artifactId>
|
||||
<version>2.9.5</version>
|
||||
<version>2.9.6</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
|
@ -45,36 +45,26 @@ import static de.mrstein.customheads.utils.Utils.hasPermission;
|
||||
@Getter
|
||||
public class CustomHeads extends JavaPlugin {
|
||||
|
||||
private static final boolean BETA = false;
|
||||
|
||||
public static final HashMap<String, String> uuidCache = new HashMap<>();
|
||||
public static final String chPrefix = "§7[§eCustomHeads§7] ";
|
||||
public static final String chError = chPrefix + "§cError §7: §c";
|
||||
public static final String chWarning = chPrefix + "§eWarning §7: §e";
|
||||
public static int hisOverflow = 18;
|
||||
@Getter
|
||||
private static Configs updateFile;
|
||||
@Getter
|
||||
private static Configs headsConfig;
|
||||
@Getter
|
||||
private static Configs categoryLoaderConfig;
|
||||
@Getter
|
||||
private static JsonFile playerDataFile;
|
||||
@Getter
|
||||
private static Looks looks;
|
||||
@Getter
|
||||
private static CustomHeads instance;
|
||||
@Getter
|
||||
private static Language languageManager;
|
||||
@Getter
|
||||
private static CustomHeadsAPI api;
|
||||
@Getter
|
||||
private static TagEditor tagEditor;
|
||||
@Getter
|
||||
private static SpigetFetcher spigetFetcher;
|
||||
@Getter
|
||||
private static EconomyManager economyManager;
|
||||
@Getter
|
||||
private static CategoryManager categoryManager;
|
||||
private static List<String> versions = Arrays.asList("v1_8_R1", "v1_8_R2", "v1_8_R3", "v1_9_R1", "v1_9_R2", "v1_10_R1", "v1_11_R1", "v1_12_R1");
|
||||
@Getter private static Configs updateFile;
|
||||
@Getter private static Configs headsConfig;
|
||||
@Getter private static Configs categoryLoaderConfig;
|
||||
@Getter private static JsonFile playerDataFile;
|
||||
@Getter private static Looks looks;
|
||||
@Getter private static CustomHeads instance;
|
||||
@Getter private static Language languageManager;
|
||||
@Getter private static CustomHeadsAPI api;
|
||||
@Getter private static TagEditor tagEditor;
|
||||
@Getter private static SpigetFetcher spigetFetcher;
|
||||
@Getter private static EconomyManager economyManager;
|
||||
@Getter private static CategoryManager categoryManager;
|
||||
private static List<String> versions = Arrays.asList("v1_8_R1", "v1_8_R2", "v1_8_R3", "v1_9_R1", "v1_9_R2", "v1_10_R1", "v1_11_R1", "v1_12_R1", "v1_13_R1", "v1_14_R1");
|
||||
private static String packet = Bukkit.getServer().getClass().getPackage().getName();
|
||||
public static String version = packet.substring(packet.lastIndexOf('.') + 1);
|
||||
|
||||
@ -235,6 +225,8 @@ public class CustomHeads extends JavaPlugin {
|
||||
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
if(BETA)
|
||||
getServer().getConsoleSender().sendMessage("\n \n \n" + chWarning + "This is a Beta Version of the Plugin! Please update it as soon as the Project gets updated\n \n ");
|
||||
File oldHeadFile;
|
||||
if ((oldHeadFile = new File("plugins/CustomHeads", "heads.yml")).exists()) {
|
||||
oldHeadFile.renameTo(new File("plugins/CustomHeads", "config.yml"));
|
||||
@ -268,7 +260,11 @@ public class CustomHeads extends JavaPlugin {
|
||||
gitHubDownloader.download(getDescription().getVersion(), "en_EN.zip", new File(getDataFolder(), "language"), (AsyncFileDownloader.AfterTask) () -> {
|
||||
getServer().getConsoleSender().sendMessage(chPrefix + "§7Done downloading! Have fun with the Plugin =D");
|
||||
getServer().getConsoleSender().sendMessage(chPrefix + "§7---------------------------------------------");
|
||||
loadRest();
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
loadRest();
|
||||
}
|
||||
}.runTask(instance);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@ -330,16 +326,17 @@ public class CustomHeads extends JavaPlugin {
|
||||
if (headsConfig.get().getBoolean("update-notifications.console")) {
|
||||
getServer().getConsoleSender().sendMessage(chPrefix + "§bNew Update for CustomHeads found! v" + release.getReleaseName() + " (Running on v" + getDescription().getVersion() + ") - You can Download it here https://www.spigotmc.org/resources/29057");
|
||||
}
|
||||
if (!USETEXTURES) {
|
||||
getServer().getConsoleSender().sendMessage(chWarning + "Uh oh. Seems like your Server Version " + bukkitVersion + " is not compatable with CustomHeads");
|
||||
getServer().getConsoleSender().sendMessage(chWarning + "I'll disable Custom Textures from Skulls to prevent any Bugs but don't worry only Effects /heads add");
|
||||
}
|
||||
}
|
||||
|
||||
public void noUpdate() {
|
||||
}
|
||||
});
|
||||
|
||||
if (!USETEXTURES) {
|
||||
getServer().getConsoleSender().sendMessage(chWarning + "Uh oh. Seems like your Server Version " + bukkitVersion + " is not compatable with CustomHeads");
|
||||
getServer().getConsoleSender().sendMessage(chWarning + "I'll disable Custom Textures from Skulls to prevent any Bugs but don't worry only Effects /heads add");
|
||||
}
|
||||
|
||||
initMetrics();
|
||||
|
||||
// -- Timers
|
||||
@ -385,7 +382,7 @@ public class CustomHeads extends JavaPlugin {
|
||||
contentItem = nextIcon;
|
||||
}
|
||||
}
|
||||
inventoryContent[i] = CustomHeads.getTagEditor().addTags(contentItem, "menuID", CustomHeads.getLooks().getIDbyTitle(player.getOpenInventory().getTopInventory().getTitle()));
|
||||
inventoryContent[i] = CustomHeads.getTagEditor().addTags(contentItem, "menuID", CustomHeads.getLooks().getIDbyTitle(player.getOpenInventory().getTitle()));
|
||||
}
|
||||
player.getOpenInventory().getTopInventory().setContents(inventoryContent);
|
||||
}
|
||||
|
@ -16,8 +16,7 @@ public class BaseCategory {
|
||||
|
||||
private String permission;
|
||||
private String name;
|
||||
@Setter(AccessLevel.NONE)
|
||||
private String id;
|
||||
@Setter(AccessLevel.NONE) private String id;
|
||||
|
||||
BaseCategory(String id, String name, String permission) {
|
||||
this.id = id;
|
||||
|
@ -40,8 +40,7 @@ public class Category extends BaseCategory {
|
||||
private ItemStack categoryIcon;
|
||||
private List<CustomHead> heads = new ArrayList<>();
|
||||
private boolean fixedIcon;
|
||||
@Setter
|
||||
private int price;
|
||||
@Setter private int price;
|
||||
|
||||
protected Category(int id, String name, String permission, int price, ItemStack icon) {
|
||||
super(String.valueOf(id), name, permission);
|
||||
|
@ -51,7 +51,7 @@ public class EconomyManager {
|
||||
if (permanent) {
|
||||
customHeadsPlayer.unlockHead(category, id);
|
||||
} else {
|
||||
customHeadsPlayer.unwrap().getInventory().addItem(customHead);
|
||||
customHeadsPlayer.unwrap().getInventory().addItem(customHead.getPlainItem());
|
||||
}
|
||||
openCategory(category, customHeadsPlayer.unwrap(), new String[]{"openCategory", prevCategory});
|
||||
customHeadsPlayer.unwrap().sendMessage(CustomHeads.getLanguageManager().ECONOMY_BUY_SUCCESSFUL.replace("{ITEM}", customHead.getItemMeta().getDisplayName()));
|
||||
|
@ -6,7 +6,6 @@ import de.mrstein.customheads.utils.ItemEditor;
|
||||
import de.mrstein.customheads.utils.Utils;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -81,7 +80,7 @@ public class HeadFontType {
|
||||
public HeadFontType enableCache() {
|
||||
cached = true;
|
||||
cacheTime = System.currentTimeMillis();
|
||||
cacheID = RandomStringUtils.randomAlphabetic(6);
|
||||
cacheID = Utils.randomAlphabetic(6);
|
||||
cache.put(cacheID, this);
|
||||
return this;
|
||||
}
|
||||
|
@ -52,8 +52,9 @@ public class InventoryListener implements Listener {
|
||||
@EventHandler
|
||||
public void onInvOpen(InventoryOpenEvent event) {
|
||||
Player player = (Player) event.getPlayer();
|
||||
if (CustomHeads.getLooks().getMenuTitles().contains(event.getInventory().getTitle())) {
|
||||
if (!hasPermission(player, CustomHeads.getLooks().getMenuInfo(CustomHeads.getLooks().getIDbyTitle(event.getInventory().getTitle()))[1])) {
|
||||
|
||||
if (CustomHeads.getLooks().getMenuTitles().contains(event.getView().getTitle())) {
|
||||
if (!hasPermission(player, CustomHeads.getLooks().getMenuInfo(CustomHeads.getLooks().getIDbyTitle(event.getView().getTitle()))[1])) {
|
||||
player.closeInventory();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -102,7 +103,7 @@ public class InventoryListener implements Listener {
|
||||
.getItem();
|
||||
}
|
||||
}
|
||||
inventoryContent[i] = CustomHeads.getTagEditor().addTags(contentItem, "menuID", CustomHeads.getLooks().getIDbyTitle(event.getInventory().getTitle()));
|
||||
inventoryContent[i] = CustomHeads.getTagEditor().addTags(contentItem, "menuID", CustomHeads.getLooks().getIDbyTitle(event.getView().getTitle()));
|
||||
}
|
||||
event.getInventory().setContents(inventoryContent);
|
||||
}
|
||||
@ -117,14 +118,14 @@ public class InventoryListener implements Listener {
|
||||
|
||||
// player.sendMessage("§7[CHTags Tags] §r" + CustomHeads.getTagEditor().getTags(event.getCurrentItem())); // Yeah debug at its finest
|
||||
|
||||
if (event.getInventory().getTitle().equals(CustomHeads.getLanguageManager().LOADING)) {
|
||||
if (event.getView().getTitle().equals(CustomHeads.getLanguageManager().LOADING)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
CustomHeadsPlayer customHeadsPlayer = CustomHeads.getApi().wrapPlayer(player);
|
||||
List<String> itemTags = CustomHeads.getTagEditor().getTags(event.getCurrentItem());
|
||||
|
||||
// Delete Head
|
||||
if (event.getInventory().getTitle().equals(CustomHeads.getLanguageManager().SAVED_HEADS_TITLE.replace("{PLAYER}", player.getName()))) {
|
||||
if (event.getView().getTitle().equals(CustomHeads.getLanguageManager().SAVED_HEADS_TITLE.replace("{PLAYER}", player.getName()))) {
|
||||
if (event.getClick() == ClickType.SHIFT_RIGHT) {
|
||||
event.setCancelled(true);
|
||||
String name = toConfigString(ChatColor.stripColor(event.getCurrentItem().getItemMeta().getDisplayName()));
|
||||
@ -136,7 +137,7 @@ public class InventoryListener implements Listener {
|
||||
}
|
||||
|
||||
// History Inventory
|
||||
if (event.getInventory().getTitle().equalsIgnoreCase(CustomHeads.getLanguageManager().HISTORY_INV_TITLE.replace("{PLAYER}", player.getName()))) {
|
||||
if (event.getView().getTitle().equalsIgnoreCase(CustomHeads.getLanguageManager().HISTORY_INV_TITLE.replace("{PLAYER}", player.getName()))) {
|
||||
event.setCancelled(true);
|
||||
if (itemTags.contains("history")) {
|
||||
String[] args = itemTags.get(itemTags.indexOf("history") + 1).split("#>");
|
||||
@ -423,7 +424,7 @@ public class InventoryListener implements Listener {
|
||||
if (args[1].equalsIgnoreCase("menu")) {
|
||||
Inventory menu = CustomHeads.getLooks().getCreatedMenus().get(args[2]);
|
||||
if (menu != null)
|
||||
player.openInventory(cloneInventory(menu, player));
|
||||
player.openInventory(cloneInventory(menu, CustomHeads.getLooks().getCreatedMenuTitles().get(args[2]), player));
|
||||
} else if (args[1].equalsIgnoreCase("category")) {
|
||||
Category originCategory = CustomHeads.getCategoryManager().getCategory(args[2]);
|
||||
if (originCategory != null && customHeadsPlayer.getUnlockedCategories(CustomHeads.hasEconomy() && !CustomHeads.keepCategoryPermissions()).contains(originCategory))
|
||||
|
@ -37,6 +37,7 @@ public class Looks {
|
||||
|
||||
public HashMap<Integer, Inventory> subCategoryLooks = new HashMap<>();
|
||||
private HashMap<String, Inventory> createdMenus = new HashMap<>();
|
||||
private HashMap<String, String> createdMenuTitles = new HashMap<>();
|
||||
private HashMap<String, String[]> menuInfo = new HashMap<>();
|
||||
private HashMap<String, ItemStack> items = new HashMap<>();
|
||||
|
||||
@ -149,6 +150,7 @@ public class Looks {
|
||||
|
||||
menuInfo.put(menuJson.get("id").getAsString(), new String[]{menuJson.get("title").getAsString(), menuJson.has("permission") ? menuJson.get("permission").getAsString() : "heads.view.menu." + menuJson.get("id").getAsString()});
|
||||
createdMenus.put(menuJson.get("id").getAsString(), menu);
|
||||
createdMenuTitles.put(menuJson.get("id").getAsString(), menuJson.get("title").getAsString());
|
||||
}
|
||||
|
||||
// Sub Category Slots
|
||||
@ -196,15 +198,13 @@ public class Looks {
|
||||
|
||||
public String getIDbyTitle(String title) {
|
||||
for (String id : createdMenus.keySet()) {
|
||||
if (createdMenus.get(id).getTitle().equals(title)) return id;
|
||||
if (createdMenuTitles.get(id).equals(title)) return id;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> getMenuTitles() {
|
||||
List<String> titles = new ArrayList<>();
|
||||
createdMenus.values().forEach(inv -> titles.add(inv.getTitle()));
|
||||
return titles;
|
||||
return new ArrayList<>(createdMenuTitles.values());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@ -19,28 +20,26 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* @author chasechocolate (Main Class), PhillipsNonstrum (Reflection)
|
||||
* @version 1.2
|
||||
* Modified for some extra Stuff
|
||||
* @version 1.3
|
||||
* Modified for some extra Stuff and 1.14 Support
|
||||
*/
|
||||
public class AnvilGUI {
|
||||
|
||||
private HashMap<AnvilSlot, ItemStack> items = new HashMap<>();
|
||||
|
||||
private AnvilClickEventHandler handler;
|
||||
|
||||
private ItemStack currentitem = null;
|
||||
|
||||
private Inventory inventory;
|
||||
|
||||
private Listener listener;
|
||||
|
||||
private Player player;
|
||||
private String title;
|
||||
|
||||
public AnvilGUI(final Player player, final AnvilClickEventHandler anvilhandler) {
|
||||
public AnvilGUI(final Player player, String title, final AnvilClickEventHandler anvilhandler) {
|
||||
this.player = player;
|
||||
this.title = title;
|
||||
handler = anvilhandler;
|
||||
this.listener = new Listener() {
|
||||
@EventHandler
|
||||
@ -126,25 +125,37 @@ public class AnvilGUI {
|
||||
player.setLevel(player.getLevel() + 1);
|
||||
}
|
||||
try {
|
||||
|
||||
Object p = player.getClass().getMethod("getHandle").invoke(player);
|
||||
Object container = getClassbyName("ContainerAnvil").getConstructor(getClassbyName("PlayerInventory"), getClassbyName("World"), getClassbyName("BlockPosition"), getClassbyName("EntityHuman")).newInstance(p.getClass().getField("inventory").get(p), p.getClass().getField("world").get(p), getClassbyName("BlockPosition").getConstructor(int.class, int.class, int.class).newInstance(0, 0, 0), p);
|
||||
getClassbyName("Container").getField("checkReachable").set(container, false);
|
||||
|
||||
int nextContainerId = (int) p.getClass().getMethod("nextContainerCounter").invoke(p);
|
||||
|
||||
Location location = player.getLocation();
|
||||
Object container = CustomHeads.version.contains("v1_14_") ?
|
||||
getClassbyName("ContainerAnvil").getConstructor(int.class, getClassbyName("PlayerInventory"), getClassbyName("ContainerAccess")).newInstance(nextContainerId, p.getClass().getField("inventory").get(p), getClassbyName("ContainerAccess").getMethod("at", getClassbyName("World"), getClassbyName("BlockPosition")).invoke(getClassbyName("ContainerAccess"), p.getClass().getField("world").get(p), getClassbyName("BlockPosition").getConstructor(int.class, int.class, int.class).newInstance(location.getBlockX(), location.getBlockY(), location.getBlockZ()))):
|
||||
getClassbyName("ContainerAnvil").getConstructor(getClassbyName("PlayerInventory"), getClassbyName("World"), getClassbyName("BlockPosition"), getClassbyName("EntityHuman")).newInstance(p.getClass().getField("inventory").get(p), p.getClass().getField("world").get(p), getClassbyName("BlockPosition").getConstructor(int.class, int.class, int.class).newInstance(location.getBlockX(), location.getBlockY(), location.getBlockZ()), p);;
|
||||
|
||||
Object bukkitView = container.getClass().getMethod("getBukkitView").invoke(container);
|
||||
inventory = (Inventory) bukkitView.getClass().getMethod("getTopInventory").invoke(bukkitView);
|
||||
for (AnvilSlot slot : items.keySet()) {
|
||||
inventory.setItem(slot.getSlot(), items.get(slot));
|
||||
}
|
||||
int c = (int) p.getClass().getMethod("nextContainerCounter").invoke(p);
|
||||
|
||||
getClassbyName("Container").getField("checkReachable").set(container, false);
|
||||
Constructor<?> chatMessageConstructor = getClassbyName("ChatMessage").getConstructor(String.class, Object[].class);
|
||||
Object connection = p.getClass().getField("playerConnection").get(p);
|
||||
Object packet = getClassbyName("PacketPlayOutOpenWindow").getConstructor(int.class, String.class, getClassbyName("IChatBaseComponent"), int.class).newInstance(c, "minecraft:anvil", chatMessageConstructor.newInstance("Repairing", new Object[]{}), 0);
|
||||
Object packet = CustomHeads.version.contains("v1_14_") ?
|
||||
getClassbyName("PacketPlayOutOpenWindow").getConstructor(int.class, getClassbyName("Containers"), getClassbyName("IChatBaseComponent")).newInstance(nextContainerId, getClassbyName("Containers").getField("ANVIL").get(getClassbyName("Containers")), chatMessageConstructor.newInstance(title, new Object[]{})) :
|
||||
getClassbyName("PacketPlayOutOpenWindow").getConstructor(int.class, String.class, getClassbyName("IChatBaseComponent"), int.class).newInstance(nextContainerId, "minecraft:anvil", chatMessageConstructor.newInstance(title, new Object[]{}), 0);
|
||||
connection.getClass().getMethod("sendPacket", getClassbyName("Packet")).invoke(connection, packet);
|
||||
Field activeContainerField = getClassbyName("EntityHuman").getDeclaredField("activeContainer");
|
||||
activeContainerField.setAccessible(true);
|
||||
activeContainerField.set(p, container);
|
||||
getClassbyName("Container").getField("windowId").set(activeContainerField.get(p), c);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Field windowIdField = getClassbyName("Container").getField("windowId");
|
||||
windowIdField.setAccessible(true);
|
||||
windowIdField.set(activeContainerField.get(p), nextContainerId);
|
||||
} catch (Exception exception) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to open AnvilGUI", exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import de.mrstein.customheads.CustomHeads;
|
||||
import de.mrstein.customheads.utils.Utils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -62,8 +63,20 @@ public class TagEditor {
|
||||
Object itemTagCompound = hasNBTTag(itemStack) ? copy.getClass().getMethod("getTag").invoke(copy) : Utils.getClassbyName("NBTTagCompound").newInstance();
|
||||
Object nbtTagCompound = ((boolean) itemTagCompound.getClass().getMethod("hasKey", String.class).invoke(itemTagCompound, "tagEditor")) ? itemTagCompound.getClass().getMethod("get", String.class).invoke(itemTagCompound, "tagEditor") : Utils.getClassbyName("NBTTagCompound").newInstance();
|
||||
Object nbtTagList = Utils.getClassbyName("NBTTagList").newInstance();
|
||||
Method nbtTagListAdd;
|
||||
|
||||
if (CustomHeads.version.contains("v1_14_")) {
|
||||
nbtTagListAdd = nbtTagList.getClass().getMethod("add", int.class, Utils.getClassbyName("NBTBase"));
|
||||
} else {
|
||||
nbtTagListAdd = nbtTagList.getClass().getMethod("add", Utils.getClassbyName("NBTBase"));
|
||||
}
|
||||
int c = 0;
|
||||
for (String tag : tags) {
|
||||
nbtTagList.getClass().getMethod("add", Utils.getClassbyName("NBTBase")).invoke(nbtTagList, Utils.getClassbyName("NBTTagString").getConstructor(String.class).newInstance(tag));
|
||||
if(CustomHeads.version.contains("v1_14_")) {
|
||||
nbtTagListAdd.invoke(nbtTagList, c++, Utils.getClassbyName("NBTTagString").getConstructor(String.class).newInstance(tag));
|
||||
} else {
|
||||
nbtTagListAdd.invoke(nbtTagList, Utils.getClassbyName("NBTTagString").getConstructor(String.class).newInstance(tag));
|
||||
}
|
||||
}
|
||||
nbtTagCompound.getClass().getMethod("set", String.class, Utils.getClassbyName("NBTBase")).invoke(nbtTagCompound, tagname, nbtTagList);
|
||||
itemTagCompound.getClass().getMethod("set", String.class, Utils.getClassbyName("NBTBase")).invoke(itemTagCompound, "tagEditor", nbtTagCompound);
|
||||
|
@ -102,7 +102,7 @@ public class CHCommand implements CommandExecutor {
|
||||
if (menu == null) {
|
||||
return true;
|
||||
}
|
||||
player.openInventory(cloneInventory(menu, player));
|
||||
player.openInventory(cloneInventory(menu, CustomHeads.getLooks().getCreatedMenuTitles().get(headsConfig.get().getString("mainMenu")), player));
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("help")) {
|
||||
@ -674,7 +674,7 @@ public class CHCommand implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
if (player.getItemInHand().getData().toString().equalsIgnoreCase("SKULL_ITEM(3)")) {
|
||||
if (player.getItemInHand().getData().toString().contains("SKULL_ITEM(3)")) {
|
||||
if (!customHeadsPlayer.hasHead(args[1])) {
|
||||
ItemEditor itemStack = new ItemEditor(player.getItemInHand());
|
||||
args[1] = toConfigString(args[1]);
|
||||
|
@ -1,12 +1,12 @@
|
||||
package de.mrstein.customheads.updaters;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import de.mrstein.customheads.CustomHeads;
|
||||
import de.mrstein.customheads.utils.Utils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.File;
|
||||
@ -113,7 +113,9 @@ public class GitHubDownloader {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
FileUtils.copyFile(new File(downloadDir, assetName), downloadTo);
|
||||
Files.copy(new File(downloadDir, assetName), downloadTo);
|
||||
|
||||
//FileUtils.copyFile(new File(downloadDir, assetName), downloadTo);
|
||||
if (afterTask.length > 0)
|
||||
afterTask[0].call();
|
||||
} catch (Exception e) {
|
||||
|
@ -6,7 +6,6 @@ import de.mrstein.customheads.utils.Configs;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@ -15,6 +14,7 @@ import java.lang.reflect.Type;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
@ -59,7 +59,8 @@ public class SpigetFetcher {
|
||||
JsonArray versionArray;
|
||||
boolean fromCache = false;
|
||||
if (updateFile.get().isSet("lastVersionFetch") && TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - lastFetch) <= 0) {
|
||||
versionArray = jsonParser.parse(new String(Base64.decodeBase64(updateFile.get().getString("lastVersionFetch").getBytes()))).getAsJsonArray();
|
||||
versionArray = jsonParser.parse(new String(Base64.getDecoder().decode(updateFile.get().getString("lastVersionFetch").getBytes()))).getAsJsonArray();
|
||||
//versionArray = jsonParser.parse(new String(Base64.decodeBase64(updateFile.get().getString("lastVersionFetch").getBytes()))).getAsJsonArray();
|
||||
fromCache = true;
|
||||
} else {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(versionUrlFormatted).openConnection();
|
||||
@ -74,7 +75,8 @@ public class SpigetFetcher {
|
||||
}
|
||||
if (!fromCache) {
|
||||
updateFile.get().set("lastUpdateCheck", System.currentTimeMillis());
|
||||
updateFile.get().set("lastVersionFetch", new String(Base64.encodeBase64(GSON.toJson(releaseList).getBytes())));
|
||||
updateFile.get().set("lastVersionFetch", new String(Base64.getEncoder().encode(GSON.toJson(releaseList).getBytes())));
|
||||
//updateFile.get().set("lastVersionFetch", new String(Base64.encodeBase64(GSON.toJson(releaseList).getBytes())));
|
||||
updateFile.save();
|
||||
}
|
||||
ResourceRelease latestRelease = releaseList.get(0);
|
||||
@ -106,7 +108,10 @@ public class SpigetFetcher {
|
||||
JsonArray descriptionArray;
|
||||
boolean fromCache = false;
|
||||
if (updateFile.get().isSet("lastDescriptionFetch") && TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - lastFetch) == 0) {
|
||||
descriptionArray = jsonParser.parse(new String(Base64.decodeBase64(updateFile.get().getString("lastDescriptionFetch")))).getAsJsonArray();
|
||||
|
||||
|
||||
descriptionArray = jsonParser.parse(new String(Base64.getDecoder().decode(updateFile.get().getString("lastDescriptionFetch")))).getAsJsonArray();
|
||||
//descriptionArray = jsonParser.parse(new String(Base64.decodeBase64(updateFile.get().getString("lastDescriptionFetch")))).getAsJsonArray();
|
||||
fromCache = true;
|
||||
} else {
|
||||
HttpURLConnection descriptionConnection = (HttpURLConnection) new URL(decriptionUrlFormatted).openConnection();
|
||||
@ -120,7 +125,8 @@ public class SpigetFetcher {
|
||||
updateList.add(GSON.fromJson(updateRaw, ResourceUpdate.class));
|
||||
}
|
||||
if (!fromCache) {
|
||||
updateFile.get().set("lastDescriptionFetch", new String(Base64.encodeBase64(GSON.toJson(updateList).getBytes())));
|
||||
updateFile.get().set("lastDescriptionFetch", new String(Base64.getEncoder().encode(GSON.toJson(updateList).getBytes())));
|
||||
//updateFile.get().set("lastDescriptionFetch", new String(Base64.encodeBase64(GSON.toJson(updateList).getBytes())));
|
||||
updateFile.save();
|
||||
}
|
||||
consumer.accept(updateList);
|
||||
|
@ -16,7 +16,6 @@ import de.mrstein.customheads.category.CustomHead;
|
||||
import de.mrstein.customheads.headwriter.HeadFontType;
|
||||
import de.mrstein.customheads.headwriter.HeadWriter;
|
||||
import de.mrstein.customheads.reflection.TagEditor;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@ -37,7 +36,9 @@ public class APIHandler implements CustomHeadsAPI {
|
||||
|
||||
// Head Util Impl
|
||||
public String getSkullTexture(ItemStack itemStack) {
|
||||
Validate.notNull(itemStack, "Item cannot be null");
|
||||
if(itemStack == null) {
|
||||
throw new NullPointerException("Item cannot be null");
|
||||
}
|
||||
if (!itemStack.getData().toString().contains("SKULL_ITEM(3)")) {
|
||||
throw new IllegalArgumentException("An PlayerHead is required to get the Texture");
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package de.mrstein.customheads.utils;
|
||||
import de.mrstein.customheads.CustomHeads;
|
||||
import de.mrstein.customheads.loader.Language;
|
||||
import de.mrstein.customheads.reflection.TagEditor;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -44,7 +43,7 @@ public class ScrollableInventory {
|
||||
|
||||
public ScrollableInventory(String title, List<ItemStack> content) {
|
||||
inventory = Bukkit.createInventory(null, 54, title);
|
||||
uid = RandomStringUtils.randomAlphabetic(6);
|
||||
uid = Utils.randomAlphabetic(6);
|
||||
setContent(content);
|
||||
cachedInventories.put(uid, this);
|
||||
cacheTime = System.currentTimeMillis();
|
||||
|
@ -17,8 +17,6 @@ import de.mrstein.customheads.updaters.AsyncFileDownloader;
|
||||
import de.mrstein.customheads.updaters.FetchResult;
|
||||
import de.mrstein.customheads.updaters.GitHubDownloader;
|
||||
import de.mrstein.customheads.updaters.JsonFetcher;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -35,6 +33,7 @@ import java.lang.reflect.Modifier;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -54,6 +53,8 @@ public class Utils {
|
||||
public static final Gson GSON_PRETTY = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
|
||||
public static final Gson GSON = new GsonBuilder().disableHtmlEscaping().create();
|
||||
|
||||
public static final Random RANDOM = new Random();
|
||||
|
||||
private static HashMap<Character, ItemStack> alphabet;
|
||||
private static HashMap<String, String[]> subCommands;
|
||||
private static HashMap<String, String[]> perms;
|
||||
@ -92,7 +93,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static void openSearchGUI(Player player, String itemname, String... action) {
|
||||
AnvilGUI gui = new AnvilGUI(player, event -> {
|
||||
AnvilGUI gui = new AnvilGUI(player, "Search", event -> {
|
||||
event.setCancelled(true);
|
||||
if (event.getSlot() == AnvilGUI.AnvilSlot.OUTPUT) {
|
||||
if (event.getName().equals("")) {
|
||||
@ -134,7 +135,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static void openGetGUI(Player player) {
|
||||
AnvilGUI gui = new AnvilGUI(player, event -> {
|
||||
AnvilGUI gui = new AnvilGUI(player, "Enter Player Name", event -> {
|
||||
event.update();
|
||||
if (event.getSlot() == AnvilGUI.AnvilSlot.OUTPUT) {
|
||||
if (event.getItem().getType() == Material.PAPER) {
|
||||
@ -354,16 +355,22 @@ public class Utils {
|
||||
return UUID.fromString(uuidStr.substring(0, 8) + "-" + uuidStr.substring(8, 12) + "-" + uuidStr.substring(12, 16) + "-" + uuidStr.substring(16, 20) + "-" + uuidStr.substring(20));
|
||||
}
|
||||
|
||||
public static Inventory cloneInventory(Inventory inventory) {
|
||||
Inventory inv = Bukkit.createInventory(inventory.getHolder(), inventory.getSize(), inventory.getTitle());
|
||||
public static Inventory cloneInventory(Inventory inventory, String title, Player newOwner) {
|
||||
Inventory inv = Bukkit.createInventory(newOwner, inventory.getSize(), title);
|
||||
inv.setContents(inventory.getContents());
|
||||
return inv;
|
||||
}
|
||||
|
||||
public static Inventory cloneInventory(Inventory inventory, Player newOwner) {
|
||||
Inventory inv = Bukkit.createInventory(newOwner, inventory.getSize(), inventory.getTitle());
|
||||
inv.setContents(inventory.getContents());
|
||||
return inv;
|
||||
public static String randomAlphabetic(int length) {
|
||||
return randomString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray(), length);
|
||||
}
|
||||
|
||||
public static String randomString(char[] chars, int length) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for(int i = 0; i < RANDOM.nextInt(length); i++) {
|
||||
builder.append(chars[RANDOM.nextInt(chars.length)]);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static boolean inject(Class<?> sourceClass, Object instance, String fieldName, Object value) {
|
||||
@ -538,21 +545,19 @@ public class Utils {
|
||||
public static void unzipFile(File zipFile, File outputDir) {
|
||||
try (ZipInputStream inputStream = new ZipInputStream(new FileInputStream(zipFile))) {
|
||||
if (!outputDir.exists())
|
||||
Files.createParentDirs(outputDir);
|
||||
byte[] buffer = new byte[0x1000];
|
||||
Files.createParentDirs(new File(outputDir, "a.temp"));
|
||||
ZipEntry zipEntry;
|
||||
System.out.println("[FileZipper] Unzipping " + zipFile.getName());
|
||||
while ((zipEntry = inputStream.getNextEntry()) != null) {
|
||||
File zipEntryFile = new File(outputDir, zipEntry.getName());
|
||||
if (FilenameUtils.getExtension(zipEntry.getName()).length() > 0) {
|
||||
if (getExtension(zipEntry.getName()).length() > 0) {
|
||||
if (!zipEntryFile.exists())
|
||||
Files.createParentDirs(zipEntryFile);
|
||||
OutputStream streamOut = new FileOutputStream(zipEntryFile);
|
||||
int len;
|
||||
while ((len = inputStream.read(buffer)) > 0) {
|
||||
streamOut.write(buffer, 0, len);
|
||||
}
|
||||
streamOut.close();
|
||||
ReadableByteChannel byteChannel = Channels.newChannel(inputStream);
|
||||
FileOutputStream outputStream = new FileOutputStream(zipEntryFile);
|
||||
outputStream.getChannel().transferFrom(byteChannel, 0, Integer.MAX_VALUE);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
}
|
||||
}
|
||||
inputStream.closeEntry();
|
||||
@ -586,7 +591,10 @@ public class Utils {
|
||||
File langRoot = new File("plugins/CustomHeads/language");
|
||||
|
||||
for (File langDir : langRoot.listFiles()) {
|
||||
FileUtils.moveDirectory(langDir, new File(backUpRoot + "/" + langDir.getName()));
|
||||
if(!langDir.renameTo(new File(backUpRoot + "/" + langDir.getName()))) {
|
||||
Bukkit.getLogger().warning("Failed to move Directory");
|
||||
}
|
||||
// FileUtils.moveDirectory(langDir, new File(backUpRoot + "/" + langDir.getName()));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
@ -673,6 +681,17 @@ public class Utils {
|
||||
return in;
|
||||
}
|
||||
|
||||
public static String getExtension(String filename) {
|
||||
filename = filename.replace("\\", "/");
|
||||
if(filename.contains("/")) {
|
||||
filename = filename.substring(filename.lastIndexOf("/")+1);
|
||||
}
|
||||
if(filename.lastIndexOf(".") > 0 && filename.lastIndexOf(".") < filename.length()) {
|
||||
return filename.substring(filename.lastIndexOf(".") + 1);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static Class<?> getClassbyName(String className) {
|
||||
try {
|
||||
if (className.equals("ChatSerializer") && !CustomHeads.version.equals("v1_8_R1"))
|
||||
|
Loading…
Reference in New Issue
Block a user