mirror of
https://github.com/songoda/EpicVouchers.git
synced 2024-11-22 01:56:21 +01:00
Merge branch 'development'
This commit is contained in:
commit
2ac10559df
@ -4,7 +4,7 @@ stages:
|
||||
variables:
|
||||
name: "EpicVouchers"
|
||||
path: "/builds/$CI_PROJECT_PATH"
|
||||
version: "2.1.11"
|
||||
version: "2.1.12"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
@ -17,14 +17,13 @@ import com.songoda.epicvouchers.settings.Settings;
|
||||
import com.songoda.epicvouchers.voucher.CoolDownManager;
|
||||
import com.songoda.epicvouchers.voucher.Voucher;
|
||||
import com.songoda.epicvouchers.voucher.VoucherExecutor;
|
||||
import com.songoda.epicvouchers.voucher.VoucherManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class EpicVouchers extends SongodaPlugin {
|
||||
@ -32,12 +31,13 @@ public class EpicVouchers extends SongodaPlugin {
|
||||
private static EpicVouchers INSTANCE;
|
||||
|
||||
private final GuiManager guiManager = new GuiManager(this);
|
||||
private CommandManager commandManager;
|
||||
private VoucherManager voucherManager;
|
||||
|
||||
private Connections connections;
|
||||
private CoolDownManager coolDowns;
|
||||
private VoucherExecutor voucherExecutor;
|
||||
private CommandManager commandManager;
|
||||
private Config vouchersConfig = new Config(this, "vouchers.yml");
|
||||
private LinkedHashMap<String, Voucher> vouchers;
|
||||
|
||||
public static EpicVouchers getInstance() {
|
||||
return INSTANCE;
|
||||
@ -51,6 +51,7 @@ public class EpicVouchers extends SongodaPlugin {
|
||||
@Override
|
||||
public void onPluginDisable() {
|
||||
connections.closeMySQL();
|
||||
saveVouchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -79,30 +80,30 @@ public class EpicVouchers extends SongodaPlugin {
|
||||
IconInv.init(this);
|
||||
BountifulAPI.init(this);
|
||||
|
||||
this.vouchers = new LinkedHashMap<>();
|
||||
|
||||
this.connections = new Connections(this);
|
||||
this.coolDowns = new CoolDownManager(this);
|
||||
this.voucherExecutor = new VoucherExecutor(this);
|
||||
this.voucherManager = new VoucherManager();
|
||||
|
||||
PluginManager manager = Bukkit.getServer().getPluginManager();
|
||||
|
||||
// Listeners
|
||||
guiManager.init();
|
||||
manager.registerEvents(new PlayerInteractListener(this), this);
|
||||
manager.registerEvents(new PlayerCommandListener(), this);
|
||||
|
||||
File folder = getDataFolder();
|
||||
File voucherFile = new File(folder, "vouchers.yml");
|
||||
|
||||
if (!voucherFile.exists()) {
|
||||
saveResource("vouchers.yml", true);
|
||||
}
|
||||
saveResource("vouchers.yml", false);
|
||||
vouchersConfig.load();
|
||||
|
||||
loadVouchersFromFile();
|
||||
|
||||
connections.openMySQL();
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveVouchers, 6000, 6000);
|
||||
}
|
||||
|
||||
private void loadVouchersFromFile() {
|
||||
vouchers.clear();
|
||||
voucherManager.clearVouchers();
|
||||
|
||||
if (vouchersConfig.contains("vouchers")) {
|
||||
for (String key : vouchersConfig.getConfigurationSection("vouchers").getKeys(false)) {
|
||||
@ -120,41 +121,82 @@ public class EpicVouchers extends SongodaPlugin {
|
||||
if (material == null) material = Material.PAPER;
|
||||
}
|
||||
|
||||
voucher.setPermission(cs.getString("permission", ""));
|
||||
voucher.setMaterial(material);
|
||||
voucher.setData((short) cs.getInt("data", 0));
|
||||
voucher.setName(cs.getString("name", "default"));
|
||||
voucher.setLore(cs.getStringList("lore"));
|
||||
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", 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", 0));
|
||||
voucher.setParticle(cs.getString("particles.particle"));
|
||||
voucher.setParticleAmount(cs.getInt("particles.amount", 0));
|
||||
voucher.setEffect(cs.getString("effects.effect"));
|
||||
voucher.setEffectAmplifier(cs.getInt("effects.amplifier"));
|
||||
voucher.setItemStack(cs.getItemStack("itemstack", null));
|
||||
voucher.setPermission(cs.getString("permission", ""))
|
||||
.setMaterial(material)
|
||||
.setData((short) cs.getInt("data", 0))
|
||||
.setName(cs.getString("name", "default"))
|
||||
.setLore(cs.getStringList("lore"))
|
||||
.setGlow(cs.getBoolean("glow", false))
|
||||
.setConfirm(cs.getBoolean("confirm", true))
|
||||
.setUnbreakable(cs.getBoolean("unbreakable", false))
|
||||
.setHideAttributes(cs.getBoolean("hide-attributes", false))
|
||||
.setRemoveItem(cs.getBoolean("remove-item", true))
|
||||
.setHealPlayer(cs.getBoolean("heal-player", false))
|
||||
.setSmiteEffect(cs.getBoolean("smite-effect", false))
|
||||
.setCoolDown(cs.getInt("coolDown", 0))
|
||||
.setBroadcasts(cs.getStringList("broadcasts"))
|
||||
.setMessages(cs.getStringList("messages"))
|
||||
.setCommands(cs.getStringList("commands"))
|
||||
.setActionBar(cs.getString("actionbar"))
|
||||
.setTitle(cs.getString("titles.title"))
|
||||
.setSubTitle(cs.getString("titles.subtitle"))
|
||||
.setTitleFadeIn(cs.getInt("titles.fade-in", 0))
|
||||
.setTitleStay(cs.getInt("titles.stay", 0))
|
||||
.setTitleFadeOut(cs.getInt("titles.fade-out", 0))
|
||||
.setSound(cs.getString("sounds.sound"))
|
||||
.setSoundPitch(cs.getInt("sounds.pitch", 0))
|
||||
.setParticle(cs.getString("particles.particle"))
|
||||
.setParticleAmount(cs.getInt("particles.amount", 0))
|
||||
.setEffect(cs.getString("effects.effect"))
|
||||
.setEffectAmplifier(cs.getInt("effects.amplifier"))
|
||||
.setItemStack(cs.getItemStack("itemstack", null));
|
||||
|
||||
vouchers.put(key, voucher);
|
||||
voucherManager.addVoucher(voucher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void saveVouchers() {
|
||||
for (String voucherName : vouchersConfig.getConfigurationSection("vouchers").getKeys(false)) {
|
||||
if (voucherManager.getVouchers().stream().noneMatch(voucher -> voucher.getKey().equals(voucherName)))
|
||||
vouchersConfig.set("vouchers." + voucherName, null);
|
||||
}
|
||||
|
||||
for (Voucher voucher : voucherManager.getVouchers()) {
|
||||
String prefix = "vouchers." + voucher.getKey() + ".";
|
||||
vouchersConfig.set(prefix + "permission", voucher.getPermission());
|
||||
vouchersConfig.set(prefix + "material", voucher.getMaterial().name());
|
||||
vouchersConfig.set(prefix + "data", voucher.getData());
|
||||
vouchersConfig.set(prefix + "name", voucher.getName());
|
||||
vouchersConfig.set(prefix + "lore", voucher.getLore());
|
||||
vouchersConfig.set(prefix + "glow", voucher.isGlow());
|
||||
vouchersConfig.set(prefix + "confirm", voucher.isConfirm());
|
||||
vouchersConfig.set(prefix + "unbreakable", voucher.isUnbreakable());
|
||||
vouchersConfig.set(prefix + "hide-attributes", voucher.isHideAttributes());
|
||||
vouchersConfig.set(prefix + "remove-item", voucher.isRemoveItem());
|
||||
vouchersConfig.set(prefix + "heal-player", voucher.isHealPlayer());
|
||||
vouchersConfig.set(prefix + "smite-effect", voucher.isSmiteEffect());
|
||||
vouchersConfig.set(prefix + "coolDown", voucher.getCoolDown());
|
||||
vouchersConfig.set(prefix + "broadcasts", voucher.getBroadcasts());
|
||||
vouchersConfig.set(prefix + "messages", voucher.getMessages());
|
||||
vouchersConfig.set(prefix + "commands", voucher.getCommands());
|
||||
vouchersConfig.set(prefix + "actionbar", voucher.getActionBar());
|
||||
vouchersConfig.set(prefix + "titles.title", voucher.getTitle());
|
||||
vouchersConfig.set(prefix + "titles.subtitle", voucher.getSubTitle());
|
||||
vouchersConfig.set(prefix + "titles.fade-in", voucher.getTitleFadeIn());
|
||||
vouchersConfig.set(prefix + "titles.stay", voucher.getTitleStay());
|
||||
vouchersConfig.set(prefix + "titles.fade-out", voucher.getTitleFadeOut());
|
||||
vouchersConfig.set(prefix + "sounds.sound", voucher.getSound());
|
||||
vouchersConfig.set(prefix + "sounds.pitch", voucher.getSoundPitch());
|
||||
vouchersConfig.set(prefix + "particles.particle", voucher.getParticle());
|
||||
vouchersConfig.set(prefix + "particles.amount", voucher.getParticleAmount());
|
||||
vouchersConfig.set(prefix + "effects.effect", voucher.getEffect());
|
||||
vouchersConfig.set(prefix + "effects.amplifier", voucher.getEffectAmplifier());
|
||||
vouchersConfig.set(prefix + "itemstack", voucher.getItemStack());
|
||||
}
|
||||
vouchersConfig.saveChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigReload() {
|
||||
vouchersConfig.load();
|
||||
@ -184,14 +226,14 @@ public class EpicVouchers extends SongodaPlugin {
|
||||
return this.vouchersConfig;
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, Voucher> getVouchers() {
|
||||
return this.vouchers;
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
public VoucherManager getVoucherManager() {
|
||||
return voucherManager;
|
||||
}
|
||||
|
||||
public GuiManager getGuiManager() {
|
||||
return guiManager;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class CommandForce extends AbstractCommand {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Voucher voucher = instance.getVouchers().get(args[1]);
|
||||
Voucher voucher = instance.getVoucherManager().getVoucher(args[1]);
|
||||
if (voucher == null) {
|
||||
sender.sendMessage("Unknown voucher...");
|
||||
return ReturnType.FAILURE;
|
||||
@ -54,7 +54,7 @@ public class CommandForce extends AbstractCommand {
|
||||
if (args.length == 1) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 2) {
|
||||
return new ArrayList<>(instance.getVouchers().keySet());
|
||||
return instance.getVoucherManager().getVouchers().stream().map(Voucher::getKey).collect(Collectors.toList());
|
||||
} else if (args.length == 3) {
|
||||
return Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandForceAll extends AbstractCommand {
|
||||
|
||||
@ -24,7 +25,7 @@ public class CommandForceAll extends AbstractCommand {
|
||||
if (args.length != 2)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
Voucher voucher = instance.getVouchers().get(args[0]);
|
||||
Voucher voucher = instance.getVoucherManager().getVoucher(args[0]);
|
||||
if (voucher == null) {
|
||||
sender.sendMessage("Unknown voucher...");
|
||||
return ReturnType.FAILURE;
|
||||
@ -42,7 +43,7 @@ public class CommandForceAll extends AbstractCommand {
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (args.length == 1) {
|
||||
return new ArrayList<>(instance.getVouchers().keySet());
|
||||
return instance.getVoucherManager().getVouchers().stream().map(Voucher::getKey).collect(Collectors.toList());
|
||||
} else if (args.length == 2) {
|
||||
return Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class CommandGive extends AbstractCommand {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Voucher voucher = instance.getVouchers().get(args[1]);
|
||||
Voucher voucher = instance.getVoucherManager().getVoucher(args[1]);
|
||||
if (voucher == null) {
|
||||
sender.sendMessage("Unknown voucher...");
|
||||
return ReturnType.FAILURE;
|
||||
@ -50,7 +50,7 @@ public class CommandGive extends AbstractCommand {
|
||||
if (args.length == 1) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 2) {
|
||||
return new ArrayList<>(instance.getVouchers().keySet());
|
||||
return instance.getVoucherManager().getVouchers().stream().map(Voucher::getKey).collect(Collectors.toList());
|
||||
} else if (args.length == 3) {
|
||||
return Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public class CommandGiveAll extends AbstractCommand {
|
||||
if (args.length != 2)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
Voucher voucher = instance.getVouchers().get(args[0]);
|
||||
Voucher voucher = instance.getVoucherManager().getVoucher(args[0]);
|
||||
if (voucher == null) {
|
||||
sender.sendMessage("Unknown voucher...");
|
||||
return ReturnType.FAILURE;
|
||||
@ -41,7 +41,7 @@ public class CommandGiveAll extends AbstractCommand {
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (args.length == 1) {
|
||||
return new ArrayList<>(instance.getVouchers().keySet());
|
||||
return instance.getVoucherManager().getVouchers().stream().map(Voucher::getKey).collect(Collectors.toList());
|
||||
} else if (args.length == 2) {
|
||||
return Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
|
||||
}
|
||||
|
@ -3,10 +3,12 @@ package com.songoda.epicvouchers.commands;
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicvouchers.EpicVouchers;
|
||||
import com.songoda.epicvouchers.menus.VoucherMenu;
|
||||
import com.songoda.epicvouchers.voucher.Voucher;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandList extends AbstractCommand {
|
||||
|
||||
@ -20,7 +22,8 @@ public class CommandList extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
instance.getLocale().getMessage("command.list.list")
|
||||
.processPlaceholder("list", String.join(", ", instance.getVouchers().keySet()))
|
||||
.processPlaceholder("list",
|
||||
instance.getVoucherManager().getVouchers().stream().map(Voucher::getKey).collect(Collectors.joining(", ")))
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class PlayerInteractListener implements Listener {
|
||||
return;
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
for (Voucher voucher : instance.getVouchers().values()) {
|
||||
for (Voucher voucher : instance.getVoucherManager().getVouchers()) {
|
||||
final ItemStack voucherItem = voucher.toItemStack();
|
||||
// does the item they're holding match this voucher?
|
||||
|
||||
|
@ -32,31 +32,31 @@ public class VoucherEditorMenu extends IconInv {
|
||||
|
||||
//Booleans
|
||||
|
||||
addIcon(0, new ToggleableIcon("Glow", event -> voucher.setGlow(!voucher.isGlow()).saveSetting("glow", voucher.isGlow()), voucher.isGlow()));
|
||||
addIcon(0, new ToggleableIcon("Glow", event -> voucher.setGlow(!voucher.isGlow()), voucher.isGlow()));
|
||||
|
||||
addIcon(1, new ToggleableIcon("Confirm", event -> voucher.setConfirm(!voucher.isConfirm()).saveSetting("confirm", voucher.isConfirm()), voucher.isConfirm()));
|
||||
addIcon(1, new ToggleableIcon("Confirm", event -> voucher.setConfirm(!voucher.isConfirm()), voucher.isConfirm()));
|
||||
|
||||
addIcon(2, new ToggleableIcon("Unbreakable", event -> voucher.setUnbreakable(!voucher.isUnbreakable()).saveSetting("unbreakable", voucher.isUnbreakable()), voucher.isUnbreakable()));
|
||||
addIcon(2, new ToggleableIcon("Unbreakable", event -> voucher.setUnbreakable(!voucher.isUnbreakable()), voucher.isUnbreakable()));
|
||||
|
||||
addIcon(3, new ToggleableIcon("Hide Attributes", event -> voucher.setHideAttributes(!voucher.isHideAttributes()).saveSetting("hide-attributes", voucher.isHideAttributes()), voucher.isHideAttributes()));
|
||||
addIcon(3, new ToggleableIcon("Hide Attributes", event -> voucher.setHideAttributes(!voucher.isHideAttributes()), voucher.isHideAttributes()));
|
||||
|
||||
addIcon(4, new ToggleableIcon("Remove Item", event -> voucher.setRemoveItem(!voucher.isRemoveItem()).saveSetting("remove-item", voucher.isRemoveItem()), voucher.isRemoveItem()));
|
||||
addIcon(4, new ToggleableIcon("Remove Item", event -> voucher.setRemoveItem(!voucher.isRemoveItem()), voucher.isRemoveItem()));
|
||||
|
||||
addIcon(5, new ToggleableIcon("Feed Player", event -> voucher.setFeedPlayer(!voucher.isFeedPlayer()).saveSetting("feed-player", voucher.isFeedPlayer()), voucher.isFeedPlayer()));
|
||||
addIcon(5, new ToggleableIcon("Feed Player", event -> voucher.setFeedPlayer(!voucher.isFeedPlayer()), voucher.isFeedPlayer()));
|
||||
|
||||
addIcon(6, new ToggleableIcon("Heal Player", event -> voucher.setHealPlayer(!voucher.isHealPlayer()).saveSetting("heal-player", voucher.isHealPlayer()), voucher.isHealPlayer()));
|
||||
addIcon(6, new ToggleableIcon("Heal Player", event -> voucher.setHealPlayer(!voucher.isHealPlayer()), voucher.isHealPlayer()));
|
||||
|
||||
addIcon(7, new ToggleableIcon("Smite Effect", event -> voucher.setSmiteEffect(!voucher.isSmiteEffect()).saveSetting("smite-effect", voucher.isSmiteEffect()), voucher.isSmiteEffect()));
|
||||
addIcon(7, new ToggleableIcon("Smite Effect", event -> voucher.setSmiteEffect(!voucher.isSmiteEffect()), voucher.isSmiteEffect()));
|
||||
|
||||
//Strings
|
||||
|
||||
addIcon(9, new StringIcon(instance, "Permission", voucher.getPermission(), (player, editString) -> {
|
||||
voucher.setPermission(editString).saveSetting("permission", editString);
|
||||
voucher.setPermission(editString);
|
||||
reopen(player);
|
||||
}));
|
||||
|
||||
addIcon(10, new StringIcon(instance, "Actionbar", voucher.getActionBar(), (player, editString) -> {
|
||||
voucher.setActionBar(editString).saveSetting("actionbar", editString);
|
||||
voucher.setActionBar(editString);
|
||||
reopen(player);
|
||||
}));
|
||||
|
||||
@ -65,7 +65,7 @@ public class VoucherEditorMenu extends IconInv {
|
||||
voucher.setData(Short.parseShort(editString.split(":")[1]));
|
||||
voucher.setMaterial(Material.valueOf(editString.split(":")[0]));
|
||||
} else {
|
||||
voucher.setMaterial(Material.valueOf(editString)).saveSetting("material", editString);
|
||||
voucher.setMaterial(Material.valueOf(editString));
|
||||
}
|
||||
|
||||
reopen(player);
|
||||
@ -83,7 +83,7 @@ public class VoucherEditorMenu extends IconInv {
|
||||
}, true));
|
||||
|
||||
addIcon(12, new StringIcon(instance, "Name", voucher.getName(false), (player, editString) -> {
|
||||
voucher.setName(editString).saveSetting("name", editString);
|
||||
voucher.setName(editString);
|
||||
reopen(player);
|
||||
}));
|
||||
|
||||
|
@ -17,9 +17,9 @@ import static org.bukkit.Material.PAPER;
|
||||
public class VoucherMenu extends IconInv {
|
||||
|
||||
public VoucherMenu(EpicVouchers instance) {
|
||||
super((int) (Math.ceil(instance.getVouchers().size() / 9.0) * 9 + (instance.getVouchers().size() % 9 == 0 ? 9 : 0)), "Vouchers");
|
||||
super((int) (Math.ceil(instance.getVoucherManager().getVouchers().size() / 9.0) * 9 + (instance.getVoucherManager().getVouchers().size() % 9 == 0 ? 9 : 0)), "Vouchers");
|
||||
|
||||
for (Voucher voucher : instance.getVouchers().values()) {
|
||||
for (Voucher voucher : instance.getVoucherManager().getVouchers()) {
|
||||
if (getInventory().firstEmpty() != -1) {
|
||||
addIcon(getInventory().firstEmpty(), voucher.toItemStack(), event -> new OptionMenu(instance, voucher).open(event.getPlayer()));
|
||||
}
|
||||
@ -32,7 +32,7 @@ public class VoucherMenu extends IconInv {
|
||||
gui.setTitle("Insert id");
|
||||
gui.setAction(aevent -> {
|
||||
final String msg = gui.getInputText().trim();
|
||||
if (instance.getVouchers().containsKey(msg)) {
|
||||
if (instance.getVoucherManager().getVoucher(msg) != null) {
|
||||
event.getPlayer().sendMessage(TextUtils.formatText("&cAlready a voucher registered with the id: " + msg));
|
||||
new VoucherMenu(instance).open(event.getPlayer());
|
||||
return;
|
||||
@ -42,10 +42,7 @@ public class VoucherMenu extends IconInv {
|
||||
voucher.setMaterial(PAPER);
|
||||
voucher.setName("&f" + msg);
|
||||
|
||||
instance.getVouchers().put(msg, voucher);
|
||||
instance.getConfig().set("vouchers." + msg + ".material", voucher.getMaterial().toString());
|
||||
instance.getConfig().set("vouchers." + msg + ".name", voucher.getName(false));
|
||||
instance.getVouchersConfig().save();
|
||||
instance.getVoucherManager().addVoucher(voucher);
|
||||
event.getPlayer().sendMessage(TextUtils.formatText("&7Successfully created voucher with id &r" + msg + "&7."));
|
||||
new VoucherMenu(instance).open(event.getPlayer());
|
||||
});
|
||||
|
@ -17,17 +17,17 @@ public class EffectsMenu extends IconInv {
|
||||
super(9, "Titles");
|
||||
|
||||
addIcon(1, new StringIcon(instance, "Effect", voucher.getEffect(), (player, editString) -> {
|
||||
voucher.setEffect(editString).saveSetting("effects.effect", editString);
|
||||
voucher.setEffect(editString);
|
||||
new EffectsMenu(instance, voucher).open(player);
|
||||
}));
|
||||
|
||||
addIcon(2, new IntegerIcon(instance, "Effect Amplifier", voucher.getEffectAmplifier(), (player, number) -> {
|
||||
voucher.setEffectAmplifier(number).saveSetting("effects.amplifier", number);
|
||||
voucher.setEffectAmplifier(number);
|
||||
new EffectsMenu(instance, voucher).open(player);
|
||||
}));
|
||||
|
||||
addIcon(3, new IntegerIcon(instance, "Duration", voucher.getEffectDuration(), (player, number) -> {
|
||||
voucher.setEffectDuration(number).saveSetting("effects.duration", number);
|
||||
voucher.setEffectDuration(number);
|
||||
new EffectsMenu(instance, voucher).open(player);
|
||||
}));
|
||||
|
||||
|
@ -17,12 +17,12 @@ public class ParticlesMenu extends IconInv {
|
||||
super(9, "Particles");
|
||||
|
||||
addIcon(1, new StringIcon(instance, "Particle", voucher.getParticle(), (player, editString) -> {
|
||||
voucher.setParticle(editString).saveSetting("particles.particle", editString);
|
||||
voucher.setParticle(editString);
|
||||
new ParticlesMenu(instance, voucher).open(player);
|
||||
}));
|
||||
|
||||
addIcon(2, new IntegerIcon(instance, "Stay", voucher.getParticleAmount(), (player, number) -> {
|
||||
voucher.setParticleAmount(number).saveSetting("particles.amount", number);
|
||||
voucher.setParticleAmount(number);
|
||||
new ParticlesMenu(instance, voucher).open(player);
|
||||
}));
|
||||
|
||||
|
@ -51,11 +51,9 @@ public class SetItemMenu extends FastInv {
|
||||
voucher.setName("");
|
||||
voucher.setLore(null);
|
||||
voucher.setItemStack(itemStack);
|
||||
voucher.saveSetting("itemstack", itemStack);
|
||||
}
|
||||
|
||||
voucher.setMaterial(itemStack.getType());
|
||||
voucher.saveSetting("material", itemStack.getType().toString());
|
||||
|
||||
if (itemStack.getDurability() != 0) {
|
||||
voucher.setData(itemStack.getDurability());
|
||||
@ -68,12 +66,10 @@ public class SetItemMenu extends FastInv {
|
||||
|
||||
if (itemStack.getItemMeta().hasDisplayName()) {
|
||||
voucher.setName(itemStack.getItemMeta().getDisplayName());
|
||||
voucher.saveSetting("name", itemStack.getItemMeta().getDisplayName());
|
||||
}
|
||||
|
||||
if (itemStack.getItemMeta().hasLore()) {
|
||||
voucher.setLore(itemStack.getItemMeta().getLore());
|
||||
voucher.saveSetting("lore", itemStack.getItemMeta().getLore());
|
||||
}
|
||||
|
||||
new OptionMenu(instance, voucher).open(event.getPlayer());
|
||||
|
@ -19,12 +19,12 @@ public class SoundsMenu extends IconInv {
|
||||
super(9, "Sound");
|
||||
|
||||
addIcon(1, new StringIcon(instance, "Sound", voucher.getSound(), (player, editString) -> {
|
||||
voucher.setSound(editString).saveSetting("sounds.sound", editString);
|
||||
voucher.setSound(editString);
|
||||
new SoundsMenu(instance, voucher).open(player);
|
||||
}, string -> Enums.getIfPresent(Sound.class, string).isPresent()));
|
||||
|
||||
addIcon(2, new IntegerIcon(instance, "Pitch", voucher.getSoundPitch(), (player, number) -> {
|
||||
voucher.setSoundPitch(number).saveSetting("sounds.pitch", number);
|
||||
voucher.setSoundPitch(number);
|
||||
new SoundsMenu(instance, voucher).open(player);
|
||||
}));
|
||||
|
||||
|
@ -17,27 +17,27 @@ public class TitlesMenu extends IconInv {
|
||||
super(9, "Titles");
|
||||
|
||||
addIcon(1, new StringIcon(instance, "Title", voucher.getTitle(), (player, editString) -> {
|
||||
voucher.setTitle(editString).saveSetting("titles.title", editString);
|
||||
voucher.setTitle(editString);
|
||||
new TitlesMenu(instance, voucher).open(player);
|
||||
}));
|
||||
|
||||
addIcon(2, new StringIcon(instance, "Subtitle", voucher.getSubTitle(), (player, editString) -> {
|
||||
voucher.setSubTitle(editString).saveSetting("titles.subtitle", editString);
|
||||
voucher.setSubTitle(editString);
|
||||
new TitlesMenu(instance, voucher).open(player);
|
||||
}));
|
||||
|
||||
addIcon(3, new IntegerIcon(instance, "Fade in", voucher.getTitleFadeIn(), (player, number) -> {
|
||||
voucher.setTitleFadeIn(number).saveSetting("titles.fade-in", number);
|
||||
voucher.setTitleFadeIn(number);
|
||||
new TitlesMenu(instance, voucher).open(player);
|
||||
}));
|
||||
|
||||
addIcon(4, new IntegerIcon(instance, "Fade out", voucher.getTitleFadeOut(), (player, number) -> {
|
||||
voucher.setTitleFadeOut(number).saveSetting("titles.fade-out", number);
|
||||
voucher.setTitleFadeOut(number);
|
||||
new TitlesMenu(instance, voucher).open(player);
|
||||
}));
|
||||
|
||||
addIcon(5, new IntegerIcon(instance, "Stay", voucher.getTitleStay(), (player, number) -> {
|
||||
voucher.setTitleStay(number).saveSetting("titles.stay", number);
|
||||
voucher.setTitleStay(number);
|
||||
new TitlesMenu(instance, voucher).open(player);
|
||||
}));
|
||||
|
||||
|
@ -8,7 +8,6 @@ import lombok.experimental.Accessors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
@ -123,10 +122,21 @@ public class Voucher {
|
||||
return applyFormatting ? messages.stream().map(TextUtils::formatText).collect(Collectors.toList()) : messages;
|
||||
}
|
||||
|
||||
public void saveSetting(String key, Object value) {
|
||||
ConfigurationSection cs = instance.getConfig().getConfigurationSection("vouchers." + getKey());
|
||||
cs.set(key, value);
|
||||
instance.getVouchersConfig().save();
|
||||
public void saveSetting(String key, List<String> list) {
|
||||
switch (key) {
|
||||
case "Commands":
|
||||
commands = list;
|
||||
break;
|
||||
case "Broadcasts":
|
||||
broadcasts = list;
|
||||
break;
|
||||
case "Messages":
|
||||
messages = list;
|
||||
break;
|
||||
case "Lore":
|
||||
lore = list;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,28 @@
|
||||
package com.songoda.epicvouchers.voucher;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class VoucherManager {
|
||||
|
||||
private final Map<String, Voucher> registeredVouchers = new HashMap<>();
|
||||
|
||||
public Voucher addVoucher(Voucher voucher) {
|
||||
return registeredVouchers.put(voucher.getKey(), voucher);
|
||||
}
|
||||
|
||||
public Voucher removeVoucher(Voucher voucher) {
|
||||
return registeredVouchers.remove(voucher);
|
||||
}
|
||||
|
||||
public Voucher getVoucher(String key) {
|
||||
return registeredVouchers.get(key);
|
||||
}
|
||||
|
||||
public Collection<Voucher> getVouchers() {
|
||||
return registeredVouchers.values();
|
||||
}
|
||||
|
||||
public void clearVouchers() {
|
||||
registeredVouchers.clear();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user