mirror of
https://github.com/songoda/EpicVouchers.git
synced 2025-01-25 17:01:24 +01:00
Merge branch 'development' into 'master'
1.14 See merge request Songoda/epicvouchers!7
This commit is contained in:
commit
aa9e666542
@ -4,7 +4,7 @@ stages:
|
||||
variables:
|
||||
name: "EpicVouchers"
|
||||
path: "/builds/$CI_PROJECT_PATH"
|
||||
version: "2.0.3"
|
||||
version: "2.1"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
25
EpicVouchers.iml
Normal file
25
EpicVouchers.iml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot:1.13.2" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: co.aikar:acf-bukkit:0.5.0-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Maven: co.aikar:acf-core:0.5.0-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Maven: co.aikar:Table:1.0.0-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Maven: co.aikar:DelegatingMap:1.0.0-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Maven: co.aikar:locales:1.0-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.jodah:expiringmap:0.5.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: co.aikar:minecraft-timings:1.0.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.bstats:bstats-bukkit:1.4" level="project" />
|
||||
</component>
|
||||
</module>
|
12
pom.xml
12
pom.xml
@ -2,7 +2,7 @@
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>EpicVouchers</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>2.0.3</version>
|
||||
<version>maven-version-number</version>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
@ -69,24 +69,26 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.13.2</version>
|
||||
<version>1.14</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>songodaupdater</artifactId>
|
||||
<version>1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>co.aikar</groupId>
|
||||
<artifactId>acf-bukkit</artifactId>
|
||||
<version>0.5.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
|
@ -8,9 +8,12 @@ import com.songoda.epicvouchers.libraries.inventory.IconInv;
|
||||
import com.songoda.epicvouchers.listeners.PlayerCommandListener;
|
||||
import com.songoda.epicvouchers.listeners.PlayerInteractListener;
|
||||
import com.songoda.epicvouchers.utils.*;
|
||||
import com.songoda.epicvouchers.utils.updateModules.LocaleModule;
|
||||
import com.songoda.epicvouchers.voucher.CoolDownManager;
|
||||
import com.songoda.epicvouchers.voucher.Voucher;
|
||||
import com.songoda.epicvouchers.voucher.VoucherExecutor;
|
||||
import com.songoda.update.Plugin;
|
||||
import com.songoda.update.SongodaUpdate;
|
||||
import lombok.Getter;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -25,6 +28,8 @@ import java.util.LinkedHashMap;
|
||||
@Getter
|
||||
public class EpicVouchers extends JavaPlugin {
|
||||
|
||||
private static EpicVouchers INSTANCE;
|
||||
|
||||
private final ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName());
|
||||
private CommandManager commandManager;
|
||||
private Connections connections;
|
||||
@ -35,8 +40,13 @@ public class EpicVouchers extends JavaPlugin {
|
||||
private ConfigWrapper vouchersFile = new ConfigWrapper(this, "", "vouchers.yml");
|
||||
private LinkedHashMap<String, Voucher> vouchers;
|
||||
|
||||
public static EpicVouchers getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
INSTANCE = this;
|
||||
Bukkit.getConsoleSender().sendMessage(Methods.format("&a============================="));
|
||||
Bukkit.getConsoleSender().sendMessage(Methods.format("&7EpicVouchers " + this.getDescription().getVersion() + " by &5Songoda <3&7!"));
|
||||
Bukkit.getConsoleSender().sendMessage(Methods.format("&7Action: &aEnabling&7..."));
|
||||
@ -46,6 +56,11 @@ public class EpicVouchers extends JavaPlugin {
|
||||
Locale.saveDefaultLocale("en_US");
|
||||
this.locale = Locale.getLocale(getConfig().getString("Locale", "en_US"));
|
||||
|
||||
//Running Songoda Updater
|
||||
Plugin plugin = new Plugin(this, 25);
|
||||
plugin.addModule(new LocaleModule());
|
||||
SongodaUpdate.load(plugin);
|
||||
|
||||
FastInv.init(this);
|
||||
IconInv.init(this);
|
||||
BountifulAPI.init(this);
|
||||
|
@ -150,11 +150,11 @@ public class Locale {
|
||||
/**
|
||||
* Save a default locale file from the project source directory, to the locale folder
|
||||
*
|
||||
* @param path the path to the file to save
|
||||
* @param in file to save
|
||||
* @param fileName the name of the file to save
|
||||
* @return true if the operation was successful, false otherwise
|
||||
*/
|
||||
public static boolean saveDefaultLocale(String path, String fileName) {
|
||||
public static boolean saveDefaultLocale(InputStream in, String fileName) {
|
||||
if (!localeFolder.exists()) localeFolder.mkdirs();
|
||||
|
||||
if (!fileName.endsWith(FILE_EXTENSION))
|
||||
@ -166,7 +166,7 @@ public class Locale {
|
||||
}
|
||||
|
||||
try (OutputStream outputStream = new FileOutputStream(destinationFile)) {
|
||||
copy(plugin.getResource(fileName), outputStream);
|
||||
copy(in == null ? plugin.getResource(fileName) : in, outputStream);
|
||||
|
||||
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
String[] localeValues = fileName.split("_");
|
||||
@ -189,7 +189,7 @@ public class Locale {
|
||||
* @return true if the operation was successful, false otherwise
|
||||
*/
|
||||
public static boolean saveDefaultLocale(String fileName) {
|
||||
return saveDefaultLocale("", fileName);
|
||||
return saveDefaultLocale(null, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -314,7 +314,7 @@ public class Locale {
|
||||
public String getMessage(String node, Object... args) {
|
||||
String message = getMessage(node);
|
||||
for (Object arg : args) {
|
||||
message = message.replaceFirst("%.*?%", arg.toString());
|
||||
message = message.replaceFirst("\\%.*?\\%", arg.toString());
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.songoda.epicvouchers.utils.NMSUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
@ -22,100 +23,111 @@ import java.util.Map;
|
||||
|
||||
public class AbstractAnvilGUI {
|
||||
|
||||
private static Class<?> BlockPosition;
|
||||
private static Class<?> PacketPlayOutOpenWindow;
|
||||
private static Class<?> ContainerAnvil;
|
||||
private static Class<?> ChatMessage;
|
||||
private static Class<?> EntityHuman;
|
||||
private static boolean loadedClasses = false;
|
||||
private AnvilClickEventHandler handler;
|
||||
private Inventory inv;
|
||||
private Map<AnvilSlot, ItemStack> items = new HashMap<>();
|
||||
private Listener listener;
|
||||
private OnClose onClose = null;
|
||||
private Player player;
|
||||
private static Class<?> BlockPositionClass;
|
||||
private static Class<?> PacketPlayOutOpenWindowClass;
|
||||
private static Class<?> IChatBaseComponentClass;
|
||||
private static Class<?> ICraftingClass;
|
||||
private static Class<?> ContainerAnvilClass;
|
||||
private static Class<?> ChatMessageClass;
|
||||
private static Class<?> EntityHumanClass;
|
||||
private static Class<?> ContainerClass;
|
||||
private static Class<?> ContainerAccessClass;
|
||||
private static Class<?> WorldClass;
|
||||
private static Class<?> PlayerInventoryClass;
|
||||
private static Class<?> ContainersClass;
|
||||
|
||||
private Player player;
|
||||
private Map<AnvilSlot, ItemStack> items = new HashMap<>();
|
||||
private Inventory inv;
|
||||
private Listener listener;
|
||||
|
||||
static {
|
||||
BlockPositionClass = NMSUtil.getNMSClass("BlockPosition");
|
||||
PacketPlayOutOpenWindowClass = NMSUtil.getNMSClass("PacketPlayOutOpenWindow");
|
||||
IChatBaseComponentClass = NMSUtil.getNMSClass("IChatBaseComponent");
|
||||
ICraftingClass = NMSUtil.getNMSClass("ICrafting");
|
||||
ContainerAnvilClass = NMSUtil.getNMSClass("ContainerAnvil");
|
||||
EntityHumanClass = NMSUtil.getNMSClass("EntityHuman");
|
||||
ChatMessageClass = NMSUtil.getNMSClass("ChatMessage");
|
||||
ContainerClass = NMSUtil.getNMSClass("Container");
|
||||
WorldClass = NMSUtil.getNMSClass("World");
|
||||
PlayerInventoryClass = NMSUtil.getNMSClass("PlayerInventory");
|
||||
|
||||
if (NMSUtil.getVersionNumber() > 13) {
|
||||
ContainerAccessClass = NMSUtil.getNMSClass("ContainerAccess");
|
||||
ContainersClass = NMSUtil.getNMSClass("Containers");
|
||||
}
|
||||
}
|
||||
public AbstractAnvilGUI(EpicVouchers instance, final Player player, final AnvilClickEventHandler handler) {
|
||||
loadClasses();
|
||||
this.player = player;
|
||||
this.handler = handler;
|
||||
|
||||
this.listener = new Listener() {
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player) || !event.getInventory().equals(inv)) return;
|
||||
if (event.getWhoClicked() instanceof Player) {
|
||||
|
||||
event.setCancelled(true);
|
||||
if (event.getInventory().equals(inv)) {
|
||||
event.setCancelled(true);
|
||||
|
||||
ItemStack item = event.getCurrentItem();
|
||||
int slot = event.getRawSlot();
|
||||
String name = "";
|
||||
ItemStack item = event.getCurrentItem();
|
||||
int slot = event.getRawSlot();
|
||||
String name = "";
|
||||
|
||||
if (item != null) {
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (item != null) {
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if (meta.hasDisplayName()) {
|
||||
name = meta.getDisplayName();
|
||||
if (meta != null && meta.hasDisplayName()) {
|
||||
name = meta.getDisplayName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AnvilClickEvent clickEvent = new AnvilClickEvent(AnvilSlot.bySlot(slot), name);
|
||||
|
||||
handler.onAnvilClick(clickEvent);
|
||||
|
||||
if (clickEvent.getWillClose()) {
|
||||
event.getWhoClicked().closeInventory();
|
||||
}
|
||||
|
||||
if (clickEvent.getWillDestroy()) {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AnvilClickEvent clickEvent = new AnvilClickEvent(AnvilSlot.bySlot(slot), name);
|
||||
|
||||
handler.onAnvilClick(clickEvent);
|
||||
|
||||
if (clickEvent.getWillClose()) {
|
||||
event.getWhoClicked().closeInventory();
|
||||
}
|
||||
|
||||
if (clickEvent.getWillDestroy()) {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
if (!(event.getPlayer() instanceof Player)) return;
|
||||
Inventory inv = event.getInventory();
|
||||
player.setLevel(player.getLevel() - 1);
|
||||
if (!inv.equals(AbstractAnvilGUI.this.inv)) return;
|
||||
inv.clear();
|
||||
OnClose onClose = getOnClose();
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
if (onClose != null) onClose.onClose(player, inv);
|
||||
destroy();
|
||||
}, 1L);
|
||||
if (event.getPlayer() instanceof Player) {
|
||||
Inventory inv = event.getInventory();
|
||||
player.setLevel(player.getLevel() - 1);
|
||||
if (inv.equals(inv)) {
|
||||
inv.clear();
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (!event.getPlayer().equals(getPlayer())) return;
|
||||
player.setLevel(player.getLevel() - 1);
|
||||
destroy();
|
||||
if (event.getPlayer().equals(getPlayer())) {
|
||||
player.setLevel(player.getLevel() - 1);
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(listener, instance);
|
||||
}
|
||||
|
||||
private void loadClasses() {
|
||||
if (loadedClasses) return;
|
||||
BlockPosition = NMSUtil.getNMSClass("BlockPosition");
|
||||
PacketPlayOutOpenWindow = NMSUtil.getNMSClass("PacketPlayOutOpenWindow");
|
||||
ContainerAnvil = NMSUtil.getNMSClass("ContainerAnvil");
|
||||
EntityHuman = NMSUtil.getNMSClass("EntityHuman");
|
||||
ChatMessage = NMSUtil.getNMSClass("ChatMessage");
|
||||
loadedClasses = true;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public AbstractAnvilGUI setSlot(AnvilSlot slot, ItemStack item) {
|
||||
public void setSlot(AnvilSlot slot, ItemStack item) {
|
||||
items.put(slot, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void open() {
|
||||
@ -123,50 +135,66 @@ public class AbstractAnvilGUI {
|
||||
|
||||
try {
|
||||
Object craftPlayer = NMSUtil.getCraftClass("entity.CraftPlayer").cast(player);
|
||||
Method getHandleMethod = craftPlayer.getClass().getMethod("getHandle", new Class<?>[0]);
|
||||
Object entityPlayer = getHandleMethod.invoke(craftPlayer, new Object[0]);
|
||||
Method getHandleMethod = craftPlayer.getClass().getMethod("getHandle");
|
||||
Object entityPlayer = getHandleMethod.invoke(craftPlayer);
|
||||
Object playerInventory = NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "inventory", false));
|
||||
Object world = NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "world", false));
|
||||
Object blockPosition = BlockPositionClass.getConstructor(int.class, int.class, int.class).newInstance(0, 0, 0);
|
||||
|
||||
Object container;
|
||||
|
||||
if (NMSUtil.getVersionNumber() == 7) {
|
||||
container = ContainerAnvil.getConstructor(new Class[]{NMSUtil.getNMSClass("PlayerInventory"), NMSUtil.getNMSClass("World"), Integer.TYPE, Integer.TYPE, Integer.TYPE, EntityHuman}).newInstance(new Object[]{NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "inventory", false)), NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "world", false)), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), entityPlayer});
|
||||
if (NMSUtil.getVersionNumber() > 13) {
|
||||
container = ContainerAnvilClass
|
||||
.getConstructor(int.class, PlayerInventoryClass, ContainerAccessClass)
|
||||
.newInstance(7, playerInventory, ContainerAccessClass.getMethod("at", WorldClass, BlockPositionClass).invoke(null, world, blockPosition));
|
||||
} else {
|
||||
container = ContainerAnvil.getConstructor(NMSUtil.getNMSClass("PlayerInventory"), NMSUtil.getNMSClass("World"), BlockPosition, EntityHuman).newInstance(NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "inventory", false)), NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "world", false)), BlockPosition.getConstructor(int.class, int.class, int.class).newInstance(0, 0, 0), entityPlayer);
|
||||
container = ContainerAnvilClass
|
||||
.getConstructor(PlayerInventoryClass, WorldClass, BlockPositionClass, EntityHumanClass)
|
||||
.newInstance(playerInventory, world, blockPosition, entityPlayer);
|
||||
}
|
||||
|
||||
NMSUtil.getField(NMSUtil.getNMSClass("Container"), "checkReachable", true).set(container, false);
|
||||
NMSUtil.getField(ContainerClass, "checkReachable", true).set(container, false);
|
||||
|
||||
Method getBukkitViewMethod = container.getClass().getMethod("getBukkitView", new Class<?>[0]);
|
||||
Method getBukkitViewMethod = container.getClass().getMethod("getBukkitView");
|
||||
Object bukkitView = getBukkitViewMethod.invoke(container);
|
||||
Method getTopInventoryMethod = bukkitView.getClass().getMethod("getTopInventory", new Class<?>[0]);
|
||||
Method getTopInventoryMethod = bukkitView.getClass().getMethod("getTopInventory");
|
||||
inv = (Inventory) getTopInventoryMethod.invoke(bukkitView);
|
||||
|
||||
for (AnvilSlot slot : items.keySet()) {
|
||||
inv.setItem(slot.getSlot(), items.get(slot));
|
||||
}
|
||||
|
||||
Method nextContainerCounterMethod = entityPlayer.getClass().getMethod("nextContainerCounter", new Class<?>[0]);
|
||||
Method nextContainerCounterMethod = entityPlayer.getClass().getMethod("nextContainerCounter");
|
||||
int c = (int) nextContainerCounterMethod.invoke(entityPlayer);
|
||||
|
||||
Constructor<?> chatMessageConstructor = ChatMessage.getConstructor(String.class, Object[].class);
|
||||
Constructor<?> chatMessageConstructor = ChatMessageClass.getConstructor(String.class, Object[].class);
|
||||
Object inventoryTitle = chatMessageConstructor.newInstance("Repairing", new Object[]{});
|
||||
|
||||
Object packet;
|
||||
|
||||
if (NMSUtil.getVersionNumber() == 7) {
|
||||
packet = PacketPlayOutOpenWindow.getConstructor(new Class[]{Integer.TYPE, Integer.TYPE, String.class, Integer.TYPE, Boolean.TYPE, Integer.TYPE}).newInstance(new Object[]{Integer.valueOf(c), Integer.valueOf(8), "Repairing", Integer.valueOf(0), Boolean.valueOf(true), Integer.valueOf(0)});
|
||||
if (NMSUtil.getVersionNumber() > 13) {
|
||||
packet = PacketPlayOutOpenWindowClass
|
||||
.getConstructor(int.class, ContainersClass, IChatBaseComponentClass)
|
||||
.newInstance(c, ContainersClass.getField("ANVIL").get(null), inventoryTitle);
|
||||
} else {
|
||||
packet = PacketPlayOutOpenWindow.getConstructor(int.class, String.class, NMSUtil.getNMSClass("IChatBaseComponent"), int.class).newInstance(c, "minecraft:anvil", chatMessageConstructor.newInstance("Repairing", new Object[]{}), 0);
|
||||
packet = PacketPlayOutOpenWindowClass
|
||||
.getConstructor(int.class, String.class, IChatBaseComponentClass, int.class)
|
||||
.newInstance(c, "minecraft:anvil", inventoryTitle, 0);
|
||||
}
|
||||
|
||||
NMSUtil.sendPacket(player, packet);
|
||||
|
||||
Field activeContainerField = NMSUtil.getField(EntityHuman, "activeContainer", true);
|
||||
Field activeContainerField = NMSUtil.getField(EntityHumanClass, "activeContainer", true);
|
||||
|
||||
if (activeContainerField != null) {
|
||||
activeContainerField.set(entityPlayer, container);
|
||||
NMSUtil.getField(NMSUtil.getNMSClass("Container"), "windowId", true).set(activeContainerField.get(entityPlayer), c);
|
||||
|
||||
Method addSlotListenerMethod = activeContainerField.get(entityPlayer).getClass().getMethod("addSlotListener", NMSUtil.getNMSClass("ICrafting"));
|
||||
NMSUtil.getField(ContainerClass, "windowId", true).set(activeContainerField.get(entityPlayer), c);
|
||||
Method addSlotListenerMethod = activeContainerField.get(entityPlayer).getClass().getMethod("addSlotListener", ICraftingClass);
|
||||
addSlotListenerMethod.invoke(activeContainerField.get(entityPlayer), entityPlayer);
|
||||
|
||||
if (NMSUtil.getVersionNumber() > 13) {
|
||||
ContainerClass.getMethod("setTitle", IChatBaseComponentClass).invoke(container, inventoryTitle);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -174,9 +202,7 @@ public class AbstractAnvilGUI {
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
onClose = null;
|
||||
player = null;
|
||||
handler = null;
|
||||
items = null;
|
||||
|
||||
HandlerList.unregisterAll(listener);
|
||||
@ -184,15 +210,6 @@ public class AbstractAnvilGUI {
|
||||
listener = null;
|
||||
}
|
||||
|
||||
private OnClose getOnClose() {
|
||||
return onClose;
|
||||
}
|
||||
|
||||
public AbstractAnvilGUI setOnClose(OnClose onClose) {
|
||||
this.onClose = onClose;
|
||||
return this;
|
||||
}
|
||||
|
||||
public enum AnvilSlot {
|
||||
INPUT_LEFT(0),
|
||||
INPUT_RIGHT(1),
|
||||
@ -219,15 +236,18 @@ public class AbstractAnvilGUI {
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface AnvilClickEventHandler {
|
||||
void onAnvilClick(AnvilClickEvent event);
|
||||
}
|
||||
|
||||
public class AnvilClickEvent {
|
||||
private AnvilSlot slot;
|
||||
|
||||
private String name;
|
||||
|
||||
private boolean close = true;
|
||||
private boolean destroy = true;
|
||||
private String name;
|
||||
private AnvilSlot slot;
|
||||
|
||||
public AnvilClickEvent(AnvilSlot slot, String name) {
|
||||
this.slot = slot;
|
||||
@ -259,10 +279,4 @@ public class AbstractAnvilGUI {
|
||||
}
|
||||
}
|
||||
|
||||
public static interface OnClose {
|
||||
|
||||
void onClose(Player player, Inventory inventory);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,7 @@ package com.songoda.epicvouchers.libraries.inventory.icons;
|
||||
import com.songoda.epicvouchers.EpicVouchers;
|
||||
import com.songoda.epicvouchers.libraries.AbstractAnvilGUI;
|
||||
import com.songoda.epicvouchers.libraries.ItemBuilder;
|
||||
import javafx.util.Pair;
|
||||
import com.songoda.epicvouchers.utils.Pair;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.songoda.epicvouchers.libraries.inventory.icons;
|
||||
import com.songoda.epicvouchers.EpicVouchers;
|
||||
import com.songoda.epicvouchers.libraries.AbstractAnvilGUI;
|
||||
import com.songoda.epicvouchers.libraries.ItemBuilder;
|
||||
import com.songoda.epicvouchers.utils.ServerVersion;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -16,7 +17,6 @@ import static com.songoda.epicvouchers.libraries.AbstractAnvilGUI.AnvilSlot.INPU
|
||||
import static com.songoda.epicvouchers.utils.Methods.format;
|
||||
import static org.bukkit.ChatColor.GRAY;
|
||||
import static org.bukkit.ChatColor.WHITE;
|
||||
import static org.bukkit.Material.SIGN;
|
||||
|
||||
public class StringIcon extends Icon {
|
||||
|
||||
@ -30,12 +30,12 @@ public class StringIcon extends Icon {
|
||||
}
|
||||
|
||||
public StringIcon(EpicVouchers instance, String string, String current, BiConsumer<Player, String> consumer, Predicate<String> predicate) {
|
||||
this(instance, new ItemBuilder(SIGN).name(ChatColor.YELLOW + string)
|
||||
this(instance, new ItemBuilder(instance.getServerVersion().isServerVersionAtLeast(ServerVersion.V1_14) ? Material.OAK_SIGN : Material.valueOf("SIGN")).name(ChatColor.YELLOW + string)
|
||||
.lore(GRAY + "Current: " + WHITE + current, GRAY + "Right click to edit", GRAY + "Left click to clear").build(), current, consumer, predicate, false);
|
||||
}
|
||||
|
||||
public StringIcon(EpicVouchers instance, String string, String current, BiConsumer<Player, String> consumer, Predicate<String> predicate, boolean noLeft) {
|
||||
this(instance, new ItemBuilder(SIGN).name(ChatColor.YELLOW + string)
|
||||
this(instance, new ItemBuilder(instance.getServerVersion().isServerVersionAtLeast(ServerVersion.V1_14) ? Material.OAK_SIGN : Material.valueOf("SIGN")).name(ChatColor.YELLOW + string)
|
||||
.lore(GRAY + "Current: " + WHITE + current, GRAY + "Right click to edit", GRAY + "Left click to clear").build(), current, consumer, predicate, noLeft);
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ public class StringIcon extends Icon {
|
||||
consumer.accept(event.getPlayer(), anvilEvent.getName());
|
||||
event.getPlayer().sendMessage(format("&7Successfully set to &r{changed}&7.", "{changed}", anvilEvent.getName()));
|
||||
});
|
||||
anvilGUI.setSlot(INPUT_LEFT, new ItemBuilder(SIGN).name(current).build());
|
||||
anvilGUI.setSlot(INPUT_LEFT, new ItemBuilder(instance.getServerVersion().isServerVersionAtLeast(ServerVersion.V1_14) ? Material.OAK_SIGN : Material.valueOf("SIGN")).name(current).build());
|
||||
anvilGUI.open();
|
||||
}
|
||||
|
||||
|
102
src/main/java/com/songoda/epicvouchers/utils/Pair.java
Normal file
102
src/main/java/com/songoda/epicvouchers/utils/Pair.java
Normal file
@ -0,0 +1,102 @@
|
||||
package com.songoda.epicvouchers.utils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>A convenience class to represent name-value pairs.</p>
|
||||
* @since JavaFX 2.0
|
||||
*/
|
||||
public class Pair<K,V> implements Serializable{
|
||||
|
||||
/**
|
||||
* Key of this <code>Pair</code>.
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* Gets the key for this pair.
|
||||
* @return key for this pair
|
||||
*/
|
||||
public String getKey() { return key; }
|
||||
|
||||
/**
|
||||
* Value of this this <code>Pair</code>.
|
||||
*/
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* Gets the value for this pair.
|
||||
* @return value for this pair
|
||||
*/
|
||||
public String getValue() { return value; }
|
||||
|
||||
/**
|
||||
* Creates a new pair
|
||||
* @param key The key for this pair
|
||||
* @param value The value to use for this pair
|
||||
*/
|
||||
public Pair(String key, String value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p><code>String</code> representation of this
|
||||
* <code>Pair</code>.</p>
|
||||
*
|
||||
* <p>The default name/value delimiter '=' is always used.</p>
|
||||
*
|
||||
* @return <code>String</code> representation of this <code>Pair</code>
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return key + "=" + value;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Generate a hash code for this <code>Pair</code>.</p>
|
||||
*
|
||||
* <p>The hash code is calculated using both the name and
|
||||
* the value of the <code>Pair</code>.</p>
|
||||
*
|
||||
* @return hash code for this <code>Pair</code>
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// name's hashCode is multiplied by an arbitrary prime number (13)
|
||||
// in order to make sure there is a difference in the hashCode between
|
||||
// these two parameters:
|
||||
// name: a value: aa
|
||||
// name: aa value: a
|
||||
return key.hashCode() * 13 + (value == null ? 0 : value.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Test this <code>Pair</code> for equality with another
|
||||
* <code>Object</code>.</p>
|
||||
*
|
||||
* <p>If the <code>Object</code> to be tested is not a
|
||||
* <code>Pair</code> or is <code>null</code>, then this method
|
||||
* returns <code>false</code>.</p>
|
||||
*
|
||||
* <p>Two <code>Pair</code>s are considered equal if and only if
|
||||
* both the names and values are equal.</p>
|
||||
*
|
||||
* @param o the <code>Object</code> to test for
|
||||
* equality with this <code>Pair</code>
|
||||
* @return <code>true</code> if the given <code>Object</code> is
|
||||
* equal to this <code>Pair</code> else <code>false</code>
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o instanceof Pair) {
|
||||
Pair pair = (Pair) o;
|
||||
if (key != null ? !key.equals(pair.key) : pair.key != null) return false;
|
||||
if (value != null ? !value.equals(pair.value) : pair.value != null) return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,8 @@ public enum ServerVersion {
|
||||
V1_10("org.bukkit.craftbukkit.v1_10"),
|
||||
V1_11("org.bukkit.craftbukkit.v1_11"),
|
||||
V1_12("org.bukkit.craftbukkit.v1_12"),
|
||||
V1_13("org.bukkit.craftbukkit.v1_13");
|
||||
V1_13("org.bukkit.craftbukkit.v1_13"),
|
||||
V1_14("org.bukkit.craftbukkit.v1_15");
|
||||
|
||||
|
||||
private final String packagePrefix;
|
||||
|
@ -33,6 +33,7 @@ public class SettingsManager implements Listener {
|
||||
DATABASE_USERNAME("Database.Username", "PUT_USERNAME_HERE"),
|
||||
DATABASE_PASSWORD("Database.Password", "PUT_PASSWORD_HERE"),
|
||||
|
||||
LANGUGE_MODE("System.Language Mode", "en_US"),
|
||||
DEBUGGER_ENABLED("System.Debugger Enabled", false);
|
||||
|
||||
private final String setting;
|
||||
|
@ -0,0 +1,32 @@
|
||||
package com.songoda.epicvouchers.utils.updateModules;
|
||||
|
||||
import com.songoda.epicvouchers.EpicVouchers;
|
||||
import com.songoda.update.Module;
|
||||
import com.songoda.update.Plugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
public class LocaleModule implements Module {
|
||||
|
||||
@Override
|
||||
public void run(Plugin plugin) {
|
||||
JSONObject json = plugin.getJson();
|
||||
try {
|
||||
JSONArray files = (JSONArray) json.get("neededFiles");
|
||||
for (Object o : files) {
|
||||
JSONObject file = (JSONObject) o;
|
||||
|
||||
if (file.get("type").equals("locale")) {
|
||||
InputStream in = new URL((String) file.get("link")).openStream();
|
||||
EpicVouchers.getInstance().getLocale().saveDefaultLocale(in, (String) file.get("name"));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
name: EpicVouchers
|
||||
main: com.songoda.epicvouchers.EpicVouchers
|
||||
version: ${project.version}
|
||||
version: maven-version-number
|
||||
author: Songoda
|
||||
website: https://songoda.host/epicvouchers
|
||||
description: Enhance your server with awesome customizable vouchers with a lot of features.
|
||||
|
Loading…
Reference in New Issue
Block a user