- Included a better way to rename vouchers using the editor.

- Included a new way to set the item of the voucher using the editor (NBT support is on its way).
- Included a new way to change true/false values of vouchers using the editor.
- Made all fields in the vouchers.yml optional except for: name, lore and material. This should greatly help to keep the voucher file organized.
This commit is contained in:
GB6 2019-01-06 14:50:06 +01:00
parent c45d0b9a99
commit d0a66b933e
17 changed files with 654 additions and 145 deletions

View File

@ -2,7 +2,7 @@
<groupId>com.songoda</groupId>
<artifactId>EpicVouchers</artifactId>
<modelVersion>4.0.0</modelVersion>
<version>1.0.7</version>
<version>1.0.9</version>
<build>
<defaultGoal>clean package</defaultGoal>
<plugins>

View File

@ -4,7 +4,6 @@ import com.songoda.epicvouchers.command.CommandManager;
import com.songoda.epicvouchers.handlers.Connections;
import com.songoda.epicvouchers.libraries.Bountiful;
import com.songoda.epicvouchers.libraries.FastInv;
import com.songoda.epicvouchers.listeners.ChatListener;
import com.songoda.epicvouchers.listeners.PlayerCommandListener;
import com.songoda.epicvouchers.listeners.PlayerInteractListener;
import com.songoda.epicvouchers.utils.*;
@ -21,26 +20,25 @@ import java.io.File;
public class EpicVouchers extends JavaPlugin {
private ConsoleCommandSender console;
@Getter private CommandManager commandManager;
@Getter private Locale locale;
@Getter private VoucherManager voucherManager;
@Getter private Connections connections;
@Getter private CoolDownManager cooldowns;
@Getter private VoucherExecutor voucherExecutor;
private SettingsManager settingsManager;
private ConfigWrapper vouchersFile = new ConfigWrapper(this, "", "vouchers.yml");
@Getter private static EpicVouchers instance;
@Getter private final ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName());
@Getter private CommandManager commandManager;
@Getter private Connections connections;
private ConsoleCommandSender console;
@Getter private CoolDownManager cooldowns;
@Getter private Locale locale;
private SettingsManager settingsManager;
@Getter private VoucherExecutor voucherExecutor;
@Getter private VoucherManager voucherManager;
@Getter private ConfigWrapper vouchersFile = new ConfigWrapper(this, "", "vouchers.yml");
@Override
public void onEnable() {
console = this.getServer().getConsoleSender();
instance = this;
console = getServer().getConsoleSender();
console.sendMessage(Methods.formatText("&a============================="));
console.sendMessage(Methods.formatText("&7EpicVouchers " + this.getDescription().getVersion() + " by &5Brianna <3&7!"));
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
console = getServer().getConsoleSender();
// Locales
Locale.init(this);
@ -50,7 +48,6 @@ public class EpicVouchers extends JavaPlugin {
FastInv.init(this);
Debugger.init(this);
this.settingsManager = new SettingsManager(this);
this.settingsManager.updateSettings();
getConfig().options().copyDefaults(true);
@ -65,7 +62,6 @@ public class EpicVouchers extends JavaPlugin {
PluginManager manager = Bukkit.getServer().getPluginManager();
manager.registerEvents(new PlayerInteractListener(this), this);
manager.registerEvents(new PlayerCommandListener(), this);
manager.registerEvents(new ChatListener(this), this);
File folder = getDataFolder();
File voucherFile = new File(folder, "vouchers.yml");
@ -75,7 +71,7 @@ public class EpicVouchers extends JavaPlugin {
loadVouchersFromFile();
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, 6000, 6000);
// Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, 6000, 6000);
Bountiful.findVersion();
connections.openMySQL();
@ -92,32 +88,32 @@ public class EpicVouchers extends JavaPlugin {
Voucher voucher = new Voucher(key);
ConfigurationSection cs = vouchersFile.getConfig().getConfigurationSection("vouchers." + key);
voucher.setPermission(cs.getString("permission"));
voucher.setMaterial(Material.valueOf(cs.getString("material")));
voucher.setData((short) cs.getInt("data"));
voucher.setName(cs.getString("name"));
voucher.setPermission(cs.getString("permission", ""));
voucher.setMaterial(Material.valueOf(cs.getString("material", "PAPER")));
voucher.setData((short) cs.getInt("data", 0));
voucher.setName(cs.getString("name", "default"));
voucher.setLore(cs.getStringList("lore"));
voucher.setGlow(cs.getBoolean("glow"));
voucher.setConfirm(cs.getBoolean("confirm"));
voucher.setUnbreakable(cs.getBoolean("unbreakable"));
voucher.setHideAttributes(cs.getBoolean("hide-attributes"));
voucher.setRemoveItem(cs.getBoolean("remove-item"));
voucher.setHealPlayer(cs.getBoolean("heal-player"));
voucher.setSmiteEffect(cs.getBoolean("smite-effect"));
voucher.setCooldown(cs.getInt("cooldown"));
voucher.setGlow(cs.getBoolean("glow", false));
voucher.setConfirm(cs.getBoolean("confirm", true));
voucher.setUnbreakable(cs.getBoolean("unbreakable", false));
voucher.setHideAttributes(cs.getBoolean("hide-attributes", false));
voucher.setRemoveItem(cs.getBoolean("remove-item", true));
voucher.setHealPlayer(cs.getBoolean("heal-player", false));
voucher.setSmiteEffect(cs.getBoolean("smite-effect", false));
voucher.setCooldown(cs.getInt("cooldown", 0));
voucher.setBroadcasts(cs.getStringList("broadcasts"));
voucher.setMessages(cs.getStringList("messages"));
voucher.setCommands(cs.getStringList("commands"));
voucher.setActionBar(cs.getString("actionbar"));
voucher.setTitle(cs.getString("titles.title"));
voucher.setSubTitle(cs.getString("titles.subtitle"));
voucher.setTitleFadeIn(cs.getInt("titles.fade-in"));
voucher.setTitleStay(cs.getInt("titles.stay"));
voucher.setTitleFadeOut(cs.getInt("titles.fade-out"));
voucher.setTitleFadeIn(cs.getInt("titles.fade-in", 0));
voucher.setTitleStay(cs.getInt("titles.stay", 0));
voucher.setTitleFadeOut(cs.getInt("titles.fade-out", 0));
voucher.setSound(cs.getString("sounds.sound"));
voucher.setSoundPitch(cs.getInt("sounds.pitch"));
voucher.setSoundPitch(cs.getInt("sounds.pitch", 0));
voucher.setParticle(cs.getString("particles.particle"));
voucher.setParticleAmount(cs.getInt("particles.amount"));
voucher.setParticleAmount(cs.getInt("particles.amount", 0));
voucher.setEffect(cs.getString("effects.effect"));
voucher.setEffectAmplifer(cs.getInt("effects.amplifier"));
@ -126,64 +122,37 @@ public class EpicVouchers extends JavaPlugin {
}
}
private void saveToFile() {
public void saveToFile(Voucher voucher) {
ConfigurationSection cs = vouchersFile.getConfig().getConfigurationSection("vouchers." + voucher.getKey());
vouchersFile.getConfig().set("vouchers", null);
cs.set("material", voucher.getMaterial().name());
cs.set("name", voucher.getName(false));
cs.set("lore", voucher.getLore(false));
for (Voucher voucher : voucherManager.getVouchers()) {
ConfigurationSection cs = vouchersFile.getConfig().createSection("vouchers." + voucher.getKey());
cs.set("permission", voucher.getPermission());
cs.set("material", voucher.getMaterial().name());
if (voucher.getData() != 0)
cs.set("data", voucher.getData());
cs.set("name", voucher.getName(false));
cs.set("lore", voucher.getLore(false));
cs.set("glow", voucher.isGlow());
cs.set("confirm", voucher.isConfirm());
cs.set("unbreakable", voucher.isUnbreakable());
cs.set("hide-attributes", voucher.isHideAttributes());
cs.set("remove-item", voucher.isRemoveItem());
cs.set("heal-player", voucher.isHealPlayer());
cs.set("smite-effect", voucher.isSmiteEffect());
cs.set("cooldown", voucher.getCooldown());
cs.set("broadcasts", voucher.getBroadcasts(false));
cs.set("messages", voucher.getMessages(false));
cs.set("commands", voucher.getCommands());
cs.set("actionbar", voucher.getActionBar());
cs.set("titles.title", voucher.getTitle());
cs.set("titles.subtitle", voucher.getSubTitle());
cs.set("titles.fade-in", voucher.getTitleFadeIn());
cs.set("titles.stay", voucher.getTitleStay());
cs.set("titles.fade-out", voucher.getTitleFadeOut());
cs.set("sounds.sound", voucher.getSound());
cs.set("sounds.pitch", voucher.getSoundPitch());
cs.set("particles.particles", voucher.getParticle());
cs.set("particles.amount", voucher.getParticleAmount());
cs.set("effects.effect", voucher.getEffect());
cs.set("effects.amplifier", voucher.getEffectAmplifer());
}
this.vouchersFile.saveConfig();
vouchersFile.saveConfig();
}
public void reload() {
this.vouchersFile = new ConfigWrapper(this, "", "vouchers.yml");
vouchersFile.reloadConfig();
getVoucherManager().getVouchers().forEach(this::saveToFile);
loadVouchersFromFile();
locale.reloadMessages();
reloadConfig();
saveConfig();
locale.reloadMessages();
}
@Override
public void onDisable() {
this.saveToFile();
getVoucherManager().getVouchers().forEach(this::saveToFile);
connections.closeMySQL();
vouchersFile.saveConfig();
console.sendMessage(Methods.formatText("&a============================="));
console.sendMessage(Methods.formatText("&7EpicVouchers " + this.getDescription().getVersion() + " by &5Brianna <3&7!"));
console.sendMessage(Methods.formatText("&7Action: &cDisabling&7..."));
console.sendMessage(Methods.formatText("&a============================="));
}
}

View File

@ -34,7 +34,6 @@ public class Locale {
private final File file;
private final String name, region;
private final String prefix;
private Locale(String name, String region) {
if (plugin == null)
@ -45,7 +44,6 @@ public class Locale {
String fileName = name + "_" + region + FILE_EXTENSION;
this.file = new File(localeFolder, fileName);
this.prefix = getMessage("general.nametag.prefix") + " ";
if (this.reloadMessages()) return;
@ -374,7 +372,4 @@ public class Locale {
return true;
}
public String getPrefix() {
return prefix;
}
}

View File

@ -53,7 +53,7 @@ public class CommandManager implements CommandExecutor {
}
}
}
commandSender.sendMessage(instance.getLocale().getPrefix() + Methods.formatText(instance.getLocale().getMessage("command.error.notexist")));
commandSender.sendMessage(instance.getLocale().getMessage("general.nametag.prefix") + Methods.formatText(instance.getLocale().getMessage("command.error.notexist")));
return true;
}
@ -69,12 +69,12 @@ public class CommandManager implements CommandExecutor {
return;
}
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
sender.sendMessage(instance.getLocale().getPrefix() + Methods.formatText("&cInvalid Syntax!"));
sender.sendMessage(instance.getLocale().getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
sender.sendMessage(instance.getLocale().getMessage("general.nametag.prefix") + Methods.formatText("&cInvalid Syntax!"));
sender.sendMessage(instance.getLocale().getMessage("general.nametag.prefix") + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
}
return;
}
sender.sendMessage(instance.getLocale().getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
sender.sendMessage(instance.getLocale().getMessage("general.nametag.prefix") + instance.getLocale().getMessage("event.general.nopermission"));
}
public List<AbstractCommand> getCommands() {

View File

@ -14,7 +14,7 @@ public class CommandEpicVouchers extends AbstractCommand {
@Override
protected ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args) {
sender.sendMessage("");
sender.sendMessage(Methods.formatText(instance.getLocale().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
sender.sendMessage(Methods.formatText(instance.getLocale().getMessage("general.nametag.prefix") + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {

View File

@ -0,0 +1,268 @@
package com.songoda.epicvouchers.libraries;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.utils.NMSUtil;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
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 Sound closeSound = Sound.ENTITY_PLAYER_LEVELUP;
@SuppressWarnings("unused")
private AnvilClickEventHandler handler;
private Inventory inv;
private Map<AnvilSlot, ItemStack> items = new HashMap<>();
private Listener listener;
private OnClose onClose = null;
private Player player;
public AbstractAnvilGUI(EpicVouchers instance, final Player player, final AnvilClickEventHandler handler) {
loadClasses();
this.player = player;
this.handler = handler;
this.listener = new Listener() {
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if (!(event.getWhoClicked() instanceof Player) || !event.getInventory().equals(inv)) return;
event.setCancelled(true);
ItemStack item = event.getCurrentItem();
int slot = event.getRawSlot();
String name = "";
if (item != null) {
if (item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();
if (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();
}
}
@EventHandler
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();
player.playSound(player.getLocation(), closeSound, 1F, 1F);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
if (onClose != null) onClose.OnClose(player, inv);
destroy();
}, 1L);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
if (!event.getPlayer().equals(getPlayer())) return;
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 void setSlot(AnvilSlot slot, ItemStack item) {
items.put(slot, item);
}
public void open() {
player.setLevel(player.getLevel() + 1);
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]);
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});
} 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);
}
NMSUtil.getField(NMSUtil.getNMSClass("Container"), "checkReachable", true).set(container, false);
Method getBukkitViewMethod = container.getClass().getMethod("getBukkitView", new Class<?>[0]);
Object bukkitView = getBukkitViewMethod.invoke(container);
Method getTopInventoryMethod = bukkitView.getClass().getMethod("getTopInventory", new Class<?>[0]);
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]);
int c = (int) nextContainerCounterMethod.invoke(entityPlayer);
Constructor<?> chatMessageConstructor = ChatMessage.getConstructor(String.class, Object[].class);
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)});
} else {
packet = PacketPlayOutOpenWindow.getConstructor(int.class, String.class, NMSUtil.getNMSClass("IChatBaseComponent"), int.class).newInstance(c, "minecraft:anvil", chatMessageConstructor.newInstance("Repairing", new Object[]{}), 0);
}
NMSUtil.sendPacket(player, packet);
Field activeContainerField = NMSUtil.getField(EntityHuman, "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"));
addSlotListenerMethod.invoke(activeContainerField.get(entityPlayer), entityPlayer);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void destroy() {
onClose = null;
player = null;
handler = null;
items = null;
HandlerList.unregisterAll(listener);
listener = null;
}
private OnClose getOnClose() {
return onClose;
}
public void setOnClose(OnClose onClose) {
this.onClose = onClose;
}
public void setCloseSound(Sound sound) {
closeSound = sound;
}
public enum AnvilSlot {
INPUT_LEFT(0),
INPUT_RIGHT(1),
OUTPUT(2);
private int slot;
private AnvilSlot(int slot) {
this.slot = slot;
}
public static AnvilSlot bySlot(int slot) {
for (AnvilSlot anvilSlot : values()) {
if (anvilSlot.getSlot() == slot) {
return anvilSlot;
}
}
return null;
}
public int getSlot() {
return slot;
}
}
public interface AnvilClickEventHandler {
void onAnvilClick(AnvilClickEvent event);
}
public class AnvilClickEvent {
private boolean close = true;
private boolean destroy = true;
private String name;
private AnvilSlot slot;
public AnvilClickEvent(AnvilSlot slot, String name) {
this.slot = slot;
this.name = name;
}
public AnvilSlot getSlot() {
return slot;
}
public String getName() {
return name;
}
public boolean getWillClose() {
return close;
}
public void setWillClose(boolean close) {
this.close = close;
}
public boolean getWillDestroy() {
return destroy;
}
public void setWillDestroy(boolean destroy) {
this.destroy = destroy;
}
}
}

View File

@ -24,7 +24,7 @@ import java.util.*;
public class FastInv implements InventoryHolder {
private static Plugin plugin = null;
private boolean cancelTasksOnClose = true;
private boolean cancelTasksOnClose = true, cancelled = true;
private Set<FastInvCloseListener> closeListeners = new HashSet<>();
private Set<FastInvClickListener> clickListeners = new HashSet<>();
private Map<Integer, FastInvClickListener> itemListeners = new HashMap<>();
@ -230,17 +230,21 @@ public class FastInv implements InventoryHolder {
return this;
}
public FastInv fill(ItemStack itemStack) {
public FastInv fill(ItemStack itemStack, FastInvClickListener listener) {
runSync(() -> {
for (int i = 0; i < inventory.getSize(); i++) {
if (inventory.getItem(i) == null) {
addItem(i, itemStack);
addItem(i, itemStack, listener);
}
}
});
return this;
}
public FastInv fill(ItemStack itemStack) {
return fill(itemStack, null);
}
/**
* Add a {@link FastInvCloseListener} to listen on menus close.
*
@ -263,6 +267,15 @@ public class FastInv implements InventoryHolder {
return this;
}
public FastInv setDefaultCancel(boolean value) {
cancelled = value;
return this;
}
public boolean getDefaultCancel() {
return cancelled;
}
/**
* Schedule a task to run.
*
@ -466,7 +479,7 @@ public class FastInv implements InventoryHolder {
FastInv inv = (FastInv) event.getInventory().getHolder();
FastInvClickEvent clickEvent = new FastInvClickEvent((Player) event.getWhoClicked(), inv, slot,
event.getCurrentItem(), true, event.getAction(), event.getClick());
event.getCurrentItem(), inv.cancelled, event.getAction(), event.getClick());
if (inv.itemListeners.containsKey(slot)) {
inv.itemListeners.get(slot).onClick(clickEvent);

View File

@ -0,0 +1,10 @@
package com.songoda.epicvouchers.libraries;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
public interface OnClose {
void OnClose(Player player, Inventory inventory);
}

View File

@ -1,35 +0,0 @@
package com.songoda.epicvouchers.listeners;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.menus.EditorMenu;
import com.songoda.epicvouchers.utils.Methods;
import com.songoda.epicvouchers.utils.SoundUtils;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
public class ChatListener implements Listener {
private final EpicVouchers instance;
public ChatListener(EpicVouchers instance) {
this.instance = instance;
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
if(!EditorMenu.getRename().containsKey(event.getPlayer().getUniqueId())) {
return;
}
Voucher voucher = EditorMenu.getRename().remove(event.getPlayer().getUniqueId());
voucher.setName(event.getMessage());
event.getPlayer().sendMessage(Methods.formatText(instance.getLocale().getMessage("interface.editvoucher.renamefinish", event.getMessage())));
new EditorMenu(instance, voucher).open(event.getPlayer());
SoundUtils.playSound(event.getPlayer(), "NOTE_PIANO", 1);
event.setCancelled(true);
}
}

View File

@ -0,0 +1,65 @@
package com.songoda.epicvouchers.menus;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.FastInv;
import com.songoda.epicvouchers.libraries.ItemBuilder;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.Material;
import java.util.Collections;
import static org.bukkit.ChatColor.*;
import static org.bukkit.enchantments.Enchantment.DURABILITY;
import static org.bukkit.inventory.ItemFlag.HIDE_ENCHANTS;
public class BooleanEditor extends FastInv {
public BooleanEditor(EpicVouchers instance, Voucher voucher) {
super(9, instance.getLocale().getMessage("interface.boolean.title"));
addItem(0, new ItemBuilder(Material.BARRIER)
.name(instance.getLocale().getMessage("interface.editvoucher.backtitle"))
.lore(Collections.singletonList(instance.getLocale().getMessage("interface.editvoucher.backlore")))
.enchant(DURABILITY, 1)
.addFlags(HIDE_ENCHANTS)
.build(), event -> new EditorMenu(instance, voucher).open(event.getPlayer()));
addItem(new ItemBuilder(Material.PAPER).name(YELLOW + "Glow").lore(
voucher.isGlow() ? GREEN + "ENABLED" : RED + "DISABLED"
).build(), event -> voucher.setGlow(!voucher.isGlow()).saveSetting("glow", voucher.isGlow()));
addItem(new ItemBuilder(Material.PAPER).name(YELLOW + "Confirm").lore(
voucher.isConfirm() ? GREEN + "ENABLED" : RED + "DISABLED"
).build(), event -> voucher.setConfirm(!voucher.isConfirm()).saveSetting("confirm", voucher.isConfirm()));
addItem(new ItemBuilder(Material.PAPER).name(YELLOW + "Unbreakable").lore(
voucher.isUnbreakable() ? GREEN + "ENABLED" : RED + "DISABLED"
).build(), event -> voucher.setUnbreakable(!voucher.isUnbreakable()).saveSetting("unbreakable", voucher.isUnbreakable()));
addItem(new ItemBuilder(Material.PAPER).name(YELLOW + "Hide Attributes").lore(
voucher.isHideAttributes() ? GREEN + "ENABLED" : RED + "DISABLED"
).build(), event -> voucher.setHideAttributes(!voucher.isHideAttributes()).saveSetting("hide-attributes", voucher.isHideAttributes()));
addItem(new ItemBuilder(Material.PAPER).name(YELLOW + "Remove Item").lore(
voucher.isRemoveItem() ? GREEN + "ENABLED" : RED + "DISABLED"
).build(), event -> voucher.setRemoveItem(!voucher.isRemoveItem()).saveSetting("remove-item", voucher.isRemoveItem()));
addItem(new ItemBuilder(Material.PAPER).name(YELLOW + "Feed Player").lore(
voucher.isFeedPlayer() ? GREEN + "ENABLED" : RED + "DISABLED"
).build(), event -> voucher.setFeedPlayer(!voucher.isFeedPlayer()).saveSetting("feed-player", voucher.isFeedPlayer()));
addItem(new ItemBuilder(Material.PAPER).name(YELLOW + "Heal Player").lore(
voucher.isHealPlayer() ? GREEN + "ENABLED" : RED + "DISABLED"
).build(), event -> voucher.setHealPlayer(!voucher.isHealPlayer()).saveSetting("heal-player", voucher.isHealPlayer()));
addItem(new ItemBuilder(Material.PAPER).name(YELLOW + "Smite Effect").lore(
voucher.isSmiteEffect() ? GREEN + "ENABLED" : RED + "DISABLED"
).build(), event -> voucher.setSmiteEffect(!voucher.isSmiteEffect()).saveSetting("smite-effect", voucher.isSmiteEffect()));
onClick(event -> {
if(event.getItem() != null && event.getSlot() != 0) {
new BooleanEditor(instance, voucher).open(event.getPlayer());
}
});
}
}

View File

@ -1,6 +1,7 @@
package com.songoda.epicvouchers.menus;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.AbstractAnvilGUI;
import com.songoda.epicvouchers.libraries.FastInv;
import com.songoda.epicvouchers.libraries.ItemBuilder;
import com.songoda.epicvouchers.utils.Methods;
@ -15,14 +16,15 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.UUID;
import static com.songoda.epicvouchers.libraries.AbstractAnvilGUI.AnvilSlot.INPUT_LEFT;
import static org.bukkit.Material.NAME_TAG;
import static org.bukkit.Material.PAPER;
import static org.bukkit.Material.STONE;
import static org.bukkit.enchantments.Enchantment.DURABILITY;
import static org.bukkit.inventory.ItemFlag.HIDE_ENCHANTS;
public class EditorMenu extends FastInv {
private static final HashMap<UUID, Voucher> rename = new HashMap<>();
public EditorMenu(EpicVouchers instance, Voucher voucher) {
super(27, instance.getLocale().getMessage("interface.editvoucher.title").replaceAll("%voucher%", voucher.getKey()));
@ -54,11 +56,34 @@ public class EditorMenu extends FastInv {
.addFlags(HIDE_ENCHANTS)
.build(), event -> {
SoundUtils.playSound(event.getPlayer(), "NOTE_BASS", 1);
event.getPlayer().closeInventory();
rename.put(event.getPlayer().getUniqueId(), voucher);
event.getPlayer().sendMessage(instance.getLocale().getMessage("interface.editvoucher.renamemessage"));
AbstractAnvilGUI gui = new AbstractAnvilGUI(instance, event.getPlayer(), anvilEvent -> {
voucher.setName(anvilEvent.getName());
event.getPlayer().sendMessage(Methods.formatText(instance.getLocale().getMessage("interface.editvoucher.renamefinish", anvilEvent.getName())));
new EditorMenu(instance, voucher).open(event.getPlayer());
instance.saveToFile(voucher);
});
gui.setOnClose((player, inv) -> new EditorMenu(instance, voucher).open(player));
gui.setSlot(INPUT_LEFT, voucher.toItemStack());
gui.open();
});
addItem(2, new ItemBuilder(STONE)
.name(instance.getLocale().getMessage("interface.editvoucher.itemtitle"))
.lore(Collections.singletonList(instance.getLocale().getMessage("interface.editvoucher.itemlore")))
.enchant(DURABILITY, 1)
.addFlags(HIDE_ENCHANTS)
.build(), event -> new SetItemMenu(instance, voucher).open(event.getPlayer()));
addItem(6, new ItemBuilder(PAPER)
.name(instance.getLocale().getMessage("interface.boolean.itemtitle"))
.lore(Collections.singletonList(instance.getLocale().getMessage("interface.boolean.itemlore")))
.enchant(DURABILITY, 1)
.addFlags(HIDE_ENCHANTS)
.build(), event -> new BooleanEditor(instance, voucher).open(event.getPlayer()));
if (instance.getConfig().getBoolean("Interface.Fill Interfaces With Glass")) {
ItemStack fillItem = instance.getServerVersion().isServerVersionAtLeast(ServerVersion.V1_13) ? new ItemStack(Material.valueOf("GRAY_STAINED_GLASS_PANE")) :
new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 7);
@ -68,7 +93,4 @@ public class EditorMenu extends FastInv {
}
public static HashMap<UUID, Voucher> getRename() {
return rename;
}
}

View File

@ -0,0 +1,77 @@
package com.songoda.epicvouchers.menus;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.FastInv;
import com.songoda.epicvouchers.libraries.ItemBuilder;
import com.songoda.epicvouchers.utils.ServerVersion;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.Collections;
import static org.bukkit.enchantments.Enchantment.DURABILITY;
import static org.bukkit.inventory.ItemFlag.HIDE_ENCHANTS;
public class SetItemMenu extends FastInv {
private final EpicVouchers instance;
public SetItemMenu(EpicVouchers instance, Voucher voucher) {
super(27, instance.getLocale().getMessage("interface.setitem.title"));
this.instance = instance;
setDefaultCancel(false);
ItemStack fillItem = instance.getServerVersion().isServerVersionAtLeast(ServerVersion.V1_13) ? new ItemStack(Material.valueOf("GRAY_STAINED_GLASS_PANE")) :
new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 7);
fill(fillItem, event -> event.setCancelled(true));
addItem(13, null);
addItem(18, new ItemBuilder(Material.BARRIER)
.name(instance.getLocale().getMessage("interface.editvoucher.backtitle"))
.lore(Collections.singletonList(instance.getLocale().getMessage("interface.editvoucher.backlore")))
.enchant(DURABILITY, 1)
.addFlags(HIDE_ENCHANTS)
.build(), event -> {
event.setCancelled(true);
new EditorMenu(instance, voucher).open(event.getPlayer());
});
addItem(26, new ItemBuilder(Material.ANVIL).name(ChatColor.GREEN + "Confirm").build(), event -> {
event.setCancelled(true);
if (event.getInventory().getInventory().getItem(13) == null) {
new EditorMenu(instance, voucher).open(event.getPlayer());
return;
}
ItemStack itemStack = event.getInventory().getInventory().getItem(13);
voucher.setMaterial(itemStack.getType());
if (itemStack.getDurability() != 0) {
voucher.setData(itemStack.getDurability());
}
if (!itemStack.hasItemMeta()) {
new EditorMenu(instance, voucher).open(event.getPlayer());
return;
}
if (itemStack.getItemMeta().hasDisplayName()) {
voucher.setName(itemStack.getItemMeta().getDisplayName());
}
if (itemStack.getItemMeta().hasLore()) {
voucher.setLore(itemStack.getItemMeta().getLore());
}
new EditorMenu(instance, voucher).open(event.getPlayer());
instance.saveToFile(voucher);
});
}
}

View File

@ -0,0 +1,102 @@
package com.songoda.epicvouchers.utils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
public class NMSUtil {
public static String getVersion() {
String name = Bukkit.getServer().getClass().getPackage().getName();
return name.substring(name.lastIndexOf('.') + 1) + ".";
}
public static int getVersionNumber() {
String name = getVersion().substring(3);
return Integer.valueOf(name.substring(0, name.length() - 4));
}
public static int getVersionReleaseNumber() {
String NMSVersion = getVersion();
return Integer.valueOf(NMSVersion.substring(NMSVersion.length() - 2).replace(".", ""));
}
public static Class<?> getNMSClass(String className) {
try {
String fullName = "net.minecraft.server." + getVersion() + className;
Class<?> clazz = Class.forName(fullName);
return clazz;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static Class<?> getCraftClass(String className) throws ClassNotFoundException {
try {
String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
Class<?> clazz = Class.forName(fullName);
return clazz;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static Field getField(Class<?> clazz, String name, boolean declared) {
try {
Field field;
if (declared) {
field = clazz.getDeclaredField(name);
} else {
field = clazz.getField(name);
}
field.setAccessible(true);
return field;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static Object getFieldObject(Object object, Field field) {
try {
return field.get(object);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void setField(Object object, String fieldName, Object fieldValue, boolean declared) {
try {
Field field;
if (declared) {
field = object.getClass().getDeclaredField(fieldName);
} else {
field = object.getClass().getField(fieldName);
}
field.setAccessible(true);
field.set(object, fieldValue);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void sendPacket(Player player, Object packet) {
try {
Object handle = player.getClass().getMethod("getHandle").invoke(player);
Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
playerConnection.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(playerConnection, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,9 +1,12 @@
package com.songoda.epicvouchers.voucher;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.utils.Methods;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
@ -12,6 +15,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
@Accessors(chain = true)
public class Voucher {
@Getter private final String key;
@ -114,6 +118,12 @@ public class Voucher {
return itemMessages;
}
public void saveSetting(String key, Object value) {
ConfigurationSection cs = EpicVouchers.getInstance().getVouchersFile().getConfig().getConfigurationSection("vouchers." + getKey());
cs.set(key, value);
EpicVouchers.getInstance().getVouchersFile().saveConfig();
}
@Override
public String toString() {
return key;

View File

@ -109,22 +109,27 @@ public class VoucherExecutor {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
}
}
if(voucher.getActionBar() != null &&!voucher.getActionBar().isEmpty()) {
String actionbar = voucher.getActionBar().replaceAll("%player%", name).replaceAll("%voucher%", voucher.getName(true));
Bountiful.sendActionBar(player, actionbar);
}
String actionbar = voucher.getActionBar().replaceAll("%player%", name).replaceAll("%voucher%", voucher.getName(true));
Bountiful.sendActionBar(player, actionbar);
if(voucher.getTitle() != null &&!voucher.getTitle().isEmpty()) {
String title = voucher.getTitle().replaceAll("%player%", name).replaceAll("%voucher%", voucher.getName(true));
String subtitle = voucher.getSubTitle().replaceAll("%player%", name).replaceAll("%voucher%", voucher.getName(true));
String title = voucher.getTitle().replaceAll("%player%", name).replaceAll("%voucher%", voucher.getName(true));
String subtitle = voucher.getSubTitle().replaceAll("%player%", name).replaceAll("%voucher%", voucher.getName(true));
int fadein = voucher.getTitleFadeIn();
int stay = voucher.getTitleStay();
int fadeout = voucher.getTitleFadeOut();
int fadein = voucher.getTitleFadeIn();
int stay = voucher.getTitleStay();
int fadeout = voucher.getTitleFadeOut();
Bountiful.sendTitle(player, fadein, stay, fadeout, title, subtitle);
}
Bountiful.sendTitle(player, fadein, stay, fadeout, title, subtitle);
String sound = voucher.getSound();
int pitch = voucher.getSoundPitch();
SoundUtils.playSound(player, sound, pitch);
if(voucher.getSound() != null && !voucher.getSound().isEmpty()) {
String sound = voucher.getSound();
int pitch = voucher.getSoundPitch();
SoundUtils.playSound(player, sound, pitch);
}
String particle = voucher.getParticle();
@ -135,7 +140,7 @@ public class VoucherExecutor {
String effect = voucher.getEffect();
if (!effect.isEmpty()) {
if (effect != null && !effect.isEmpty()) {
int amplifier = voucher.getEffectAmplifer();
int duration = voucher.getEffectDuration() * 20;
player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(effect), duration, amplifier));

View File

@ -1,6 +1,6 @@
#General Messages
general.nametag.prefix= "&8[&6EpicVouchers&8]"
general.nametag.prefix= "&8[&6EpicVouchers&8] "
#Interface Messages
@ -9,6 +9,8 @@ interface.confirmsettings.confirmitemname= "&2&lREDEEM"
interface.confirmsettings.confirmitemlore= "&aClick here if you want to confirm your redeem."
interface.confirmsettings.cancelitemname= "&4&lCANCEL"
interface.confirmsettings.cancelitemlore= "&cClick here if you want to cancel your redeem."
interface.setitem.title= "&6Set item"
interface.boolean.title= "&6Edit booleans"
interface.editor.title= "&6Editor"
interface.editvoucher.title= "&6Editor [&e%voucher%&6]";
interface.editvoucher.backtitle= "&4Return";
@ -21,6 +23,12 @@ interface.editvoucher.renamelore= "&eRename the display name of the voucher."
interface.editvoucher.renamemessage= "&7Please enter the name that this voucher should be renamed to."
interface.editvoucher.renamefinish= "&7Successfully renamed the voucher to &r%renamed%&7."
interface.editvoucher.itemtitle= "&6Set item"
interface.editvoucher.itemlore= "&eSet the item of your voucher."
interface.boolean.itemlore= "&eSet boolean values."
interface.boolean.itemtitle= "&eEdit the boolean values of your voucher."
#Command Messages
command.error.noplayer= "&7That user either does not exist or is not online";

View File

@ -1,6 +1,6 @@
name: EpicVouchers
main: com.songoda.epicvouchers.EpicVouchers
version: 1.0.7
version: 1.0.9
author: Songoda
website: https://songoda.host/epicvouchers
description: Enhance your server with awesome customizable vouchers with a lot of features.