ChangeLog:

- Replaced /ev give everyone with /ev giveall
- Replaced /ev force everyone with /ev forceall
- Added an action section to the voucher editor to give and force redeem vouchers through gui.
- Vouchers can now be redeemed using the off-hand.
- Added metrics.
- Made errors thrown when redeeming vouchers less intrusive.
- Redid the /ev help command
This commit is contained in:
GB6 2019-03-19 11:59:54 +01:00
parent b8b4faf8d5
commit 941b7f0aec
44 changed files with 940 additions and 1115 deletions

60
pom.xml
View File

@ -2,19 +2,45 @@
<groupId>com.songoda</groupId>
<artifactId>EpicVouchers</artifactId>
<modelVersion>4.0.0</modelVersion>
<version>2.0</version>
<version>2.0.2</version>
<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<version>3.6.2</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>com.songoda.epicvouchers</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
@ -22,7 +48,6 @@
<filtering>true</filtering>
</resource>
</resources>
<sourceDirectory>src/main/java</sourceDirectory>
</build>
<repositories>
@ -30,6 +55,14 @@
<id>private</id>
<url>http://repo.songoda.com/artifactory/private</url>
</repository>
<repository>
<id>aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
</repositories>
<dependencies>
@ -40,17 +73,24 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>arconix</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
</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>
<version>1.4</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -2,17 +2,19 @@ package com.songoda.epicvouchers;
import com.songoda.epicvouchers.command.CommandManager;
import com.songoda.epicvouchers.handlers.Connections;
import com.songoda.epicvouchers.libraries.Bountiful;
import com.songoda.epicvouchers.libraries.BountifulAPI;
import com.songoda.epicvouchers.libraries.inventory.FastInv;
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.voucher.*;
import com.songoda.epicvouchers.voucher.CoolDownManager;
import com.songoda.epicvouchers.voucher.Voucher;
import com.songoda.epicvouchers.voucher.VoucherExecutor;
import lombok.Getter;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@ -20,22 +22,21 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.LinkedHashMap;
@Getter
public class EpicVouchers extends JavaPlugin {
@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;
@Getter private CoolDownManager cooldowns;
@Getter private Locale locale;
private final ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName());
private CommandManager commandManager;
private Connections connections;
private CoolDownManager coolDowns;
private Locale locale;
private SettingsManager settingsManager;
@Getter private VoucherExecutor voucherExecutor;
@Getter private ConfigWrapper vouchersFile = new ConfigWrapper(this, "", "vouchers.yml");
@Getter private LinkedHashMap<String, Voucher> vouchers;
private VoucherExecutor voucherExecutor;
private ConfigWrapper vouchersFile = new ConfigWrapper(this, "", "vouchers.yml");
private LinkedHashMap<String, Voucher> vouchers;
@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..."));
@ -47,17 +48,18 @@ public class EpicVouchers extends JavaPlugin {
FastInv.init(this);
IconInv.init(this);
Debugger.init(this);
BountifulAPI.init(this);
this.settingsManager = new SettingsManager(this);
this.settingsManager.updateSettings();
this.vouchers = new LinkedHashMap<>();
getConfig().options().copyDefaults(true);
saveConfig();
this.commandManager = new CommandManager(this);
this.connections = new Connections(this);
this.cooldowns = new CoolDownManager(this);
this.coolDowns = new CoolDownManager(this);
this.voucherExecutor = new VoucherExecutor(this);
PluginManager manager = Bukkit.getServer().getPluginManager();
@ -66,26 +68,27 @@ public class EpicVouchers extends JavaPlugin {
File folder = getDataFolder();
File voucherFile = new File(folder, "vouchers.yml");
if (!voucherFile.exists()) {
saveResource("vouchers.yml", true);
}
loadVouchersFromFile();
Bountiful.findVersion();
connections.openMySQL();
new Metrics(this);
Bukkit.getConsoleSender().sendMessage(Methods.format("&a============================="));
}
private void loadVouchersFromFile() {
vouchers.clear();
/*
* Register Vouchers into VoucherManger from configuration
*/
if (vouchersFile.getConfig().contains("vouchers")) {
for (String key : vouchersFile.getConfig().getConfigurationSection("vouchers").getKeys(false)) {
Voucher voucher = new Voucher(key);
key = key.toLowerCase();
Voucher voucher = new Voucher(key, this);
ConfigurationSection cs = vouchersFile.getConfig().getConfigurationSection("vouchers." + key);
Material material = cs.getString("material") == null || cs.getString("material").equals("") ? Material.PAPER :
Material.matchMaterial(cs.getString("material")) == null ? Material.PAPER : Material.matchMaterial(cs.getString("material"));
@ -102,7 +105,7 @@ public class EpicVouchers extends JavaPlugin {
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.setCoolDown(cs.getInt("coolDown", 0));
voucher.setBroadcasts(cs.getStringList("broadcasts"));
voucher.setMessages(cs.getStringList("messages"));
voucher.setCommands(cs.getStringList("commands"));
@ -128,7 +131,6 @@ public class EpicVouchers extends JavaPlugin {
public void reload() {
vouchersFile.reloadConfig();
loadVouchersFromFile();
reloadConfig();
saveConfig();
locale.reloadMessages();

View File

@ -1,41 +0,0 @@
package com.songoda.epicvouchers.command;
import com.songoda.epicvouchers.EpicVouchers;
import org.bukkit.command.CommandSender;
public abstract class AbstractCommand {
public enum ReturnType { SUCCESS, FAILURE, SYNTAX_ERROR, NO_CONSOLE }
private final AbstractCommand parent;
private final String command;
private final boolean noConsole;
protected AbstractCommand(String command, AbstractCommand parent, boolean noConsole) {
this.command = command;
this.parent = parent;
this.noConsole = noConsole;
}
public AbstractCommand getParent() {
return parent;
}
public String getCommand() {
return command;
}
public boolean isNoConsole() {
return noConsole;
}
protected abstract ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args);
public abstract String getPermissionNode();
public abstract String getSyntax();
public abstract String getDescription();
}

View File

@ -1,83 +1,30 @@
package com.songoda.epicvouchers.command;
import co.aikar.commands.BukkitCommandManager;
import co.aikar.commands.InvalidCommandArgument;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.command.commands.*;
import com.songoda.epicvouchers.utils.Methods;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.songoda.epicvouchers.voucher.Voucher;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
public class CommandManager implements CommandExecutor {
public class CommandManager extends BukkitCommandManager {
private final EpicVouchers instance;
private final List<AbstractCommand> commands = new ArrayList<>();
private EpicVouchers instance;
public CommandManager(EpicVouchers instance) {
super(instance);
this.instance = instance;
instance.getCommand("EpicVouchers").setExecutor(this);
registerDependency(EpicVouchers.class, "instance", instance);
AbstractCommand commandEpicVouchers = addCommand(new CommandEpicVouchers());
getCommandContexts().registerContext(Voucher.class, c ->
Optional.ofNullable(instance.getVouchers().get(c.popFirstArg().toLowerCase())).orElseThrow(() ->
new InvalidCommandArgument("Unknown voucher.")));
addCommand(new CommandReload(commandEpicVouchers));
addCommand(new CommandEditor(commandEpicVouchers));
addCommand(new CommandList(commandEpicVouchers));
addCommand(new CommandGive(commandEpicVouchers));
addCommand(new CommandForce(commandEpicVouchers));
}
getCommandCompletions().registerCompletion("vouchers", c -> instance.getVouchers().keySet());
private AbstractCommand addCommand(AbstractCommand abstractCommand) {
commands.add(abstractCommand);
return abstractCommand;
}
registerCommand(new EfCommand());
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
for (AbstractCommand abstractCommand : commands) {
if (abstractCommand.getCommand().equalsIgnoreCase(command.getName())) {
if (strings.length == 0) {
processRequirements(abstractCommand, commandSender, strings);
return true;
}
} else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName())) {
String cmd = strings[0];
if (cmd.equalsIgnoreCase(abstractCommand.getCommand())) {
processRequirements(abstractCommand, commandSender, strings);
return true;
}
}
}
commandSender.sendMessage(instance.getLocale().getMessage("general.nametag.prefix") + Methods.format(instance.getLocale().getMessage("command.error.notexist")));
return true;
}
private void processRequirements(AbstractCommand command, CommandSender sender, String[] strings) {
if (!(sender instanceof Player) && command.isNoConsole() ) {
sender.sendMessage(instance.getLocale().getMessage("command.error.noconsole"));
return;
}
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings);
if (returnType == AbstractCommand.ReturnType.NO_CONSOLE) {
sender.sendMessage(instance.getLocale().getMessage("command.error.noconsole"));
return;
}
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
sender.sendMessage(instance.getLocale().getMessage("general.nametag.prefix") + Methods.format("&cInvalid Syntax!"));
sender.sendMessage(instance.getLocale().getMessage("general.nametag.prefix") + Methods.format("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
}
return;
}
sender.sendMessage(instance.getLocale().getMessage("general.nametag.prefix") + instance.getLocale().getMessage("event.general.nopermission"));
}
public List<AbstractCommand> getCommands() {
return Collections.unmodifiableList(commands);
enableUnstableAPI("help");
}
}

View File

@ -0,0 +1,83 @@
package com.songoda.epicvouchers.command;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.CommandHelp;
import co.aikar.commands.annotation.*;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.menus.VoucherMenu;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
@CommandAlias("epicvouchers|ev")
public class EfCommand extends BaseCommand {
@Dependency
private EpicVouchers instance;
@Subcommand("reload")
@CommandPermission("epicvouchers.admin")
@Description("Reload all configuration files.")
public void onReload(CommandSender sender) {
instance.reload();
sender.sendMessage(instance.getLocale().getMessage("command.reload.success"));
}
@Subcommand("list")
@CommandPermission("epicvouchers.admin")
@Description("List all available vouchers.")
public void onList(CommandSender sender) {
String message = instance.getLocale().getMessage("command.list.list").replaceAll("%list%", String.join(", ", instance.getVouchers().keySet()));
sender.sendMessage(message);
}
@Subcommand("give")
@CommandPermission("epicvouchers.admin")
@CommandCompletion("@players @vouchers @range:1-10")
@Description("Give a voucher to a player.")
public void onGivePlayer(CommandSender sender, @Flags("other") Player player, Voucher voucher, int amount) {
voucher.give(sender, Collections.singletonList(player), amount);
}
@Subcommand("giveall")
@CommandPermission("epicvouchers.admin")
@CommandCompletion("@vouchers @range:1-10")
@Description("Give everyone online a voucher.")
public void onGiveAll(CommandSender sender, Voucher voucher, int amount) {
voucher.giveAll(sender, amount);
}
@Subcommand("force")
@CommandPermission("epicvouchers.admin")
@CommandCompletion("@players @vouchers @range:1-10")
@Description("Force user to redeem voucher.")
public void onForce(CommandSender sender, @Flags("other") Player player, Voucher voucher, int amount) {
voucher.forceRedeem(sender, Collections.singletonList(player), amount);
sender.sendMessage(instance.getLocale().getMessage("command.force.send", player.getName(), voucher.getName(true), String.valueOf(amount)));
}
@Subcommand("forceall")
@CommandPermission("epicvouchers.admin")
@CommandCompletion("@vouchers @range:1-10")
@Description("Force all online users to redeem voucher.")
public void onForceAll(CommandSender sender, Voucher voucher, int amount) {
voucher.forceRedeem(sender, new ArrayList<>(Bukkit.getOnlinePlayers()), amount);
sender.sendMessage(instance.getLocale().getMessage("command.force.send", "everyone", voucher.getName(true), String.valueOf(amount)));
}
@Subcommand("editor")
@CommandPermission("epicvouchers.admin")
@Description("Opens the voucher editor.")
public void onEditor(Player player) {
new VoucherMenu(instance).open(player);
}
@HelpCommand
public void onHelp(CommandSender sender, CommandHelp help) {
help.showHelp();
}
}

View File

@ -1,39 +0,0 @@
package com.songoda.epicvouchers.command.commands;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.command.AbstractCommand;
import com.songoda.epicvouchers.menus.VoucherMenu;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CommandEditor extends AbstractCommand {
public CommandEditor(AbstractCommand parent) {
super("editor", parent, true);
}
@Override
protected ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args) {
if (args.length != 1) return ReturnType.SYNTAX_ERROR;
instance.reload();
new VoucherMenu(instance).open((Player) sender);
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "epicvouchers.admin";
}
@Override
public String getSyntax() {
return "/vouchers editor";
}
@Override
public String getDescription() {
return "Edit vouchers in a GUI.";
}
}

View File

@ -1,43 +0,0 @@
package com.songoda.epicvouchers.command.commands;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.command.AbstractCommand;
import com.songoda.epicvouchers.utils.Methods;
import org.bukkit.command.CommandSender;
public class CommandEpicVouchers extends AbstractCommand {
public CommandEpicVouchers() {
super("EpicVouchers", null, false);
}
@Override
protected ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args) {
sender.sendMessage("");
sender.sendMessage(Methods.format(instance.getLocale().getMessage("general.nametag.prefix") + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda"));
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
sender.sendMessage(Methods.format("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
}
}
sender.sendMessage("");
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return null;
}
@Override
public String getSyntax() {
return "/EpicVouchers";
}
@Override
public String getDescription() {
return "Displays this page.";
}
}

View File

@ -1,85 +0,0 @@
package com.songoda.epicvouchers.command.commands;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.command.AbstractCommand;
import com.songoda.epicvouchers.events.ForceRedeemEvent;
import com.songoda.epicvouchers.voucher.Voucher;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
public class CommandForce extends AbstractCommand {
public CommandForce(AbstractCommand parent) {
super("force", parent, true);
}
@Override
protected ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args) {
if (args.length != 4) return ReturnType.SYNTAX_ERROR;
if (!args[1].equalsIgnoreCase("everyone") && Bukkit.getPlayer(args[1]) == null) {
sender.sendMessage(instance.getLocale().getMessage("command.error.noplayer"));
return ReturnType.FAILURE;
}
if (!instance.getVouchers().containsKey(args[2])) {
sender.sendMessage(instance.getLocale().getMessage("command.error.novoucher"));
return ReturnType.FAILURE;
}
Voucher voucher = instance.getVouchers().get(args[2]);
if (!StringUtils.isNumeric(args[3])) {
sender.sendMessage(instance.getLocale().getMessage("command.error.notnumber"));
return ReturnType.SUCCESS;
}
Collection<Player> players;
String output;
int amount = Integer.parseInt(args[3]);
if(args[1].equalsIgnoreCase("everyone")) {
players = (Collection<Player>) Bukkit.getOnlinePlayers();
output = "everyone";
} else {
players = Collections.singletonList(Bukkit.getPlayer(args[1]));
output = Bukkit.getPlayer(args[1]).getName();
}
players.forEach(player -> {
ForceRedeemEvent event = new ForceRedeemEvent(player, voucher.getName(true), amount, sender);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
for (int times = 0; times < amount; times++) {
instance.getVoucherExecutor().redeemVoucher(player, voucher, player.getItemInHand(), false);
}
});
String message = instance.getLocale().getMessage("command.force.send", output, voucher.getName(true), String.valueOf(amount));
sender.sendMessage(message);
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "epicvouchers.admin";
}
@Override
public String getSyntax() {
return "/epicvouchers force [player/everyone] [section] [amount]";
}
@Override
public String getDescription() {
return "Force someone or everyone to redeem a specific voucher.";
}
}

View File

@ -1,97 +0,0 @@
package com.songoda.epicvouchers.command.commands;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.command.AbstractCommand;
import com.songoda.epicvouchers.events.VoucherReceiveEvent;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class CommandGive extends AbstractCommand {
public CommandGive(AbstractCommand parent) {
super("give", parent, false);
}
@Override
protected ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args) {
if (args.length != 4) {
return ReturnType.SYNTAX_ERROR;
}
if (!args[1].equalsIgnoreCase("everyone") && Bukkit.getPlayer(args[1]) == null) {
sender.sendMessage(instance.getLocale().getMessage("command.error.noplayer"));
return ReturnType.FAILURE;
}
if (!instance.getVouchers().containsKey(args[2])) {
sender.sendMessage(instance.getLocale().getMessage("command.error.novoucher"));
return ReturnType.FAILURE;
}
Voucher voucher = instance.getVouchers().get(args[2]);
try {
String givemessage = instance.getLocale().getMessage("command.give.send");
String receivemessage = instance.getLocale().getMessage("command.give.receive");
int amount = Integer.parseInt(args[3]);
ItemStack item = voucher.toItemStack(amount);
String output;
receivemessage = receivemessage.replaceAll("%voucher%", voucher.getName(true));
receivemessage = receivemessage.replaceAll("%amount%", String.valueOf(amount));
if (args[1].equalsIgnoreCase("everyone")) {
for (Player player : Bukkit.getOnlinePlayers()) {
if (player != sender) {
VoucherReceiveEvent event = new VoucherReceiveEvent(player, voucher.getName(true), item, amount, sender);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return ReturnType.FAILURE;
}
player.sendMessage(receivemessage);
player.getInventory().addItem(item);
player.updateInventory();
}
}
output = "everyone";
} else {
Player player = Bukkit.getPlayer(args[1]);
receivemessage = receivemessage.replaceAll("%player%", player.getName());
VoucherReceiveEvent event = new VoucherReceiveEvent(player, voucher.getName(true), item, amount, sender);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return ReturnType.FAILURE;
}
player.sendMessage(receivemessage);
player.getInventory().addItem(item);
player.updateInventory();
output = player.getName();
}
givemessage = givemessage.replaceAll("%player%", output);
givemessage = givemessage.replaceAll("%voucher%", voucher.getName(true));
givemessage = givemessage.replaceAll("%amount%", String.valueOf(amount));
sender.sendMessage(givemessage);
} catch (Exception error) {
sender.sendMessage(instance.getLocale().getMessage("command.error.notnumber"));
}
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "epicvouchers.admin";
}
@Override
public String getSyntax() {
return "/epicvouchers give [player/everyone] [section] [amount]";
}
@Override
public String getDescription() {
return "Give someone or everyone a voucher from your parameters.";
}
}

View File

@ -1,43 +0,0 @@
package com.songoda.epicvouchers.command.commands;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.command.AbstractCommand;
import org.bukkit.command.CommandSender;
import java.util.stream.Collectors;
public class CommandList extends AbstractCommand {
public CommandList(AbstractCommand parent) {
super("list", parent, false);
}
@Override
protected ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args) {
if (args.length != 1) {
return ReturnType.SYNTAX_ERROR;
}
String list = String.join(", ", instance.getVouchers().keySet());
String message = instance.getLocale().getMessage("command.list.list").replaceAll("%list%", list);
sender.sendMessage(message);
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "epicvouchers.admin";
}
@Override
public String getSyntax() {
return "/vouchers list";
}
@Override
public String getDescription() {
return "Displays all vouchers";
}
}

View File

@ -1,38 +0,0 @@
package com.songoda.epicvouchers.command.commands;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.command.AbstractCommand;
import org.bukkit.command.CommandSender;
public class CommandReload extends AbstractCommand {
public CommandReload(AbstractCommand parent) {
super("reload", parent, false);
}
@Override
protected ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args) {
if (args.length != 1) return ReturnType.SYNTAX_ERROR;
instance.reload();
sender.sendMessage(instance.getLocale().getMessage("command.reload.success"));
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "epicvouchers.admin";
}
@Override
public String getSyntax() {
return "/vouchers reload";
}
@Override
public String getDescription() {
return "Reload the config files.";
}
}

View File

@ -1,7 +1,6 @@
package com.songoda.epicvouchers.handlers;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.utils.Debugger;
import com.songoda.epicvouchers.utils.Methods;
import org.bukkit.entity.Player;
@ -32,7 +31,7 @@ public class Connections {
System.out.println(Methods.format("&fSuccessfully created a connection with MySQL."));
} catch (Exception error) {
System.out.println(Methods.format("&cFailed to create a connection with MySQL."));
Debugger.runReport(error);
error.printStackTrace();
}
}
@ -45,7 +44,7 @@ public class Connections {
System.out.println(Methods.format("&fSuccessfully closed the MySQL connection."));
} catch (Exception error) {
System.out.println(Methods.format("&cFailed to close the MySQL connection."));
Debugger.runReport(error);
error.printStackTrace();
}
}
@ -64,7 +63,7 @@ public class Connections {
System.out.println(Methods.format("&fSuccessfully saved the redeem in the MySQL database."));
} catch (Exception error) {
System.out.println(Methods.format("&cFailed to save the redeem data in the MySQL database."));
Debugger.runReport(error);
error.printStackTrace();
}
}

View File

@ -3,7 +3,6 @@ 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;
@ -84,7 +83,7 @@ public class AbstractAnvilGUI {
inv.clear();
OnClose onClose = getOnClose();
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
if (onClose != null) onClose.OnClose(player, inv);
if (onClose != null) onClose.onClose(player, inv);
destroy();
}, 1L);
}
@ -259,5 +258,11 @@ public class AbstractAnvilGUI {
this.destroy = destroy;
}
}
public static interface OnClose {
void onClose(Player player, Inventory inventory);
}
}

View File

@ -1,143 +0,0 @@
package com.songoda.epicvouchers.libraries;
import com.songoda.epicvouchers.utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class Bountiful {
public static boolean oldmethod;
public static String nmsversion;
public static void findVersion() {
nmsversion = Bukkit.getServer().getClass().getPackage().getName();
nmsversion = nmsversion.substring(nmsversion.lastIndexOf(".") + 1);
}
public static Integer getPlayerProtocol(Player player) {
return 47;
}
public static void sendPacket(Player player, Object packet) {
try {
Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player);
Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
playerConnection.getClass().getMethod("sendPacket", new Class[] { getNMSClass("Packet") }).invoke(playerConnection, packet);
} catch (Exception error) {
Debugger.runReport(error);
}
}
public static Class<?> getNMSClass(String name) {
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
try {
return Class.forName("net.minecraft.server." + version + "." + name);
} catch (Exception error) {
Debugger.runReport(error);
}
return null;
}
public static void sendTitle(Player player, Integer fadein, Integer stay, Integer fadeout, String title, String subtitle) {
try {
if (title != null) {
Object field = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null);
Object chattitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, "{\"text\":\"" + title + "\"}");
Constructor<?> subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE);
Object titlepacket = subtitleconstructor.newInstance(field, chattitle, fadein, stay, fadeout);
sendPacket(player, titlepacket);
field = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE").get(null);
chattitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, "{\"text\":\"" + title + "\"}");
subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"));
titlepacket = subtitleconstructor.newInstance(field, chattitle);
sendPacket(player, titlepacket);
}
if (subtitle != null) {
Object field = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null);
Object chatsubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, "{\"text\":\"" + title + "\"}");
Constructor<?> subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE);
Object subtitlepacket = subtitleconstructor.newInstance(field, chatsubtitle, fadein, stay, fadeout);
sendPacket(player, subtitlepacket);
field = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE").get(null);
chatsubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, "{\"text\":\"" + subtitle + "\"}");
subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE);
subtitlepacket = subtitleconstructor.newInstance(field, chatsubtitle, fadein, stay, fadeout);
sendPacket(player, subtitlepacket);
}
} catch (Exception error) {
Debugger.runReport(error);
}
}
public static void sendActionBar(Player player, String message) {
if (nmsversion.startsWith("v1_12_")) {
sendActionbarBefore(player, message);
} else {
sendActionbarAfter(player, message);
}
}
public static void sendActionbarBefore(Player player, String message) {
try {
Class<?> craftplayerclass = Class.forName("org.bukkit.craftbukkit." + nmsversion + ".entity.CraftPlayer");
Object craftplayer = craftplayerclass.cast(player);
Class<?> playoutchat = Class.forName("net.minecraft.server." + nmsversion + ".PacketPlayOutChat");
Class<?> simplepacket = Class.forName("net.minecraft.server." + nmsversion + ".Packet");
Class<?> chatcomponent = Class.forName("net.minecraft.server." + nmsversion + ".ChatComponentText");
Class<?> basecomponent = Class.forName("net.minecraft.server." + nmsversion + ".IChatBaseComponent");
Class<?> chatmessagetypeclass = Class.forName("net.minecraft.server." + nmsversion + ".ChatMessageType");
Object[] chatmessagetypes = chatmessagetypeclass.getEnumConstants();
Object chatmessagetype = null;
for (Object object : chatmessagetypes) {
if (object.toString().equals("GAME_INFO")) {
chatmessagetype = object;
}
}
Object object = chatcomponent.getConstructor(new Class[] { String.class }).newInstance(message);
Object customobject = playoutchat.getConstructor(new Class[] { basecomponent, chatmessagetypeclass }).newInstance(object, chatmessagetype);
Method method = craftplayerclass.getDeclaredMethod("getHandle");
Object invokedmethod = method.invoke(craftplayer);
Field field = invokedmethod.getClass().getDeclaredField("playerConnection");
Object packetchat = field.get(invokedmethod);
Method methodclass = packetchat.getClass().getDeclaredMethod("sendPacket", simplepacket);
methodclass.invoke(packetchat, customobject);
} catch (Exception error) {
Debugger.runReport(error);
}
}
public static void sendActionbarAfter(Player player, String message) {
try {
Class<?> craftplayerclass = Class.forName("org.bukkit.craftbukkit." + nmsversion + ".entity.CraftPlayer");
Object craftplayer = craftplayerclass.cast(player);
Class<?> playoutchat = Class.forName("net.minecraft.server." + nmsversion + ".PacketPlayOutChat");
Class<?> simplepacket = Class.forName("net.minecraft.server." + nmsversion + ".Packet");
Object customobject;
if (oldmethod) {
Class<?> chatserializer = Class.forName("net.minecraft.server." + nmsversion + ".ChatSerializer");
Class<?> basecomponent = Class.forName("net.minecraft.server." + nmsversion + ".IChatBaseComponent");
Method method = chatserializer.getDeclaredMethod("a", String.class);
Object baseinvoke = basecomponent.cast(method.invoke(chatserializer, "{\"text\": \"" + message + "\"}"));
customobject = playoutchat.getConstructor(new Class[] { basecomponent, Byte.TYPE }).newInstance(baseinvoke, (byte) 2);
} else {
Class<?> componenttext = Class.forName("net.minecraft.server." + nmsversion + ".ChatComponentText");
Class<?> chatbase = Class.forName("net.minecraft.server." + nmsversion + ".IChatBaseComponent");
Object object = componenttext.getConstructor(new Class[] { String.class }).newInstance(message);
customobject = playoutchat.getConstructor(new Class[] { chatbase, Byte.TYPE }).newInstance(object, (byte) 2);
}
Method handlemethod = craftplayerclass.getDeclaredMethod("getHandle");
Object objectinvoked = handlemethod.invoke(craftplayer);
Field field = objectinvoked.getClass().getDeclaredField("playerConnection");
Object fieldinvoked = field.get(objectinvoked);
Method methodclass = fieldinvoked.getClass().getDeclaredMethod("sendPacket", simplepacket);
methodclass.invoke(fieldinvoked, customobject);
} catch (Exception error) {
Debugger.runReport(error);
}
}
}

View File

@ -0,0 +1,306 @@
package com.songoda.epicvouchers.libraries;
import com.songoda.epicvouchers.EpicVouchers;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class BountifulAPI {
public static String nmsver;
private static boolean useOldMethods = false;
private static EpicVouchers instance;
@Deprecated
public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String message) {
sendTitle(player, fadeIn, stay, fadeOut, message, null);
}
@Deprecated
public static void sendSubtitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String message) {
sendTitle(player, fadeIn, stay, fadeOut, null, message);
}
@Deprecated
public static void sendFullTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) {
sendTitle(player, fadeIn, stay, fadeOut, title, subtitle);
}
@Deprecated
public static Integer getPlayerProtocol(Player player) {
/* Returns the 1.8 protocol version as this is the only protocol a player can possibly be on with Spigot 1.8 */
return 47;
}
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();
}
}
public static Class<?> getNMSClass(String name) {
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
try {
return Class.forName("net.minecraft.server." + version + "." + name);
} catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
}
}
public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) {
try {
Object e;
Object chatTitle;
Object chatSubtitle;
Constructor subtitleConstructor;
Object titlePacket;
Object subtitlePacket;
if (title != null) {
title = ChatColor.translateAlternateColorCodes('&', title);
title = title.replaceAll("%player%", player.getDisplayName());
// Times packets
e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get((Object) null);
chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke((Object) null, new Object[]{"{\"text\":\"" + title + "\"}"});
subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[]{getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE});
titlePacket = subtitleConstructor.newInstance(new Object[]{e, chatTitle, fadeIn, stay, fadeOut});
sendPacket(player, titlePacket);
e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE").get((Object) null);
chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke((Object) null, new Object[]{"{\"text\":\"" + title + "\"}"});
subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[]{getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent")});
titlePacket = subtitleConstructor.newInstance(new Object[]{e, chatTitle});
sendPacket(player, titlePacket);
}
if (subtitle != null) {
subtitle = ChatColor.translateAlternateColorCodes('&', subtitle);
subtitle = subtitle.replaceAll("%player%", player.getDisplayName());
// Times packets
e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get((Object) null);
chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke((Object) null, new Object[]{"{\"text\":\"" + title + "\"}"});
subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[]{getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE});
subtitlePacket = subtitleConstructor.newInstance(new Object[]{e, chatSubtitle, fadeIn, stay, fadeOut});
sendPacket(player, subtitlePacket);
e = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE").get((Object) null);
chatSubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[]{String.class}).invoke((Object) null, new Object[]{"{\"text\":\"" + subtitle + "\"}"});
subtitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[]{getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE});
subtitlePacket = subtitleConstructor.newInstance(new Object[]{e, chatSubtitle, fadeIn, stay, fadeOut});
sendPacket(player, subtitlePacket);
}
} catch (Exception var11) {
var11.printStackTrace();
}
}
public static void clearTitle(Player player) {
sendTitle(player, 0, 0, 0, "", "");
}
public static void sendTabTitle(Player player, String header, String footer) {
if (header == null) header = "";
header = ChatColor.translateAlternateColorCodes('&', header);
if (footer == null) footer = "";
footer = ChatColor.translateAlternateColorCodes('&', footer);
header = header.replaceAll("%player%", player.getDisplayName());
footer = footer.replaceAll("%player%", player.getDisplayName());
try {
Object tabHeader = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\":\"" + header + "\"}");
Object tabFooter = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\":\"" + footer + "\"}");
Constructor<?> titleConstructor = getNMSClass("PacketPlayOutPlayerListHeaderFooter").getConstructor();
Object packet = titleConstructor.newInstance();
try {
Field aField = packet.getClass().getDeclaredField("a");
aField.setAccessible(true);
aField.set(packet, tabHeader);
Field bField = packet.getClass().getDeclaredField("b");
bField.setAccessible(true);
bField.set(packet, tabFooter);
} catch (Exception e) {
Field aField = packet.getClass().getDeclaredField("header");
aField.setAccessible(true);
aField.set(packet, tabHeader);
Field bField = packet.getClass().getDeclaredField("footer");
bField.setAccessible(true);
bField.set(packet, tabFooter);
}
sendPacket(player, packet);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void sendActionBar(Player player, String message) {
if (!player.isOnline()) {
return; // Player may have logged out
}
try {
Class<?> craftPlayerClass = Class.forName("org.bukkit.craftbukkit." + nmsver + ".entity.CraftPlayer");
Object craftPlayer = craftPlayerClass.cast(player);
Object packet;
Class<?> packetPlayOutChatClass = Class.forName("net.minecraft.server." + nmsver + ".PacketPlayOutChat");
Class<?> packetClass = Class.forName("net.minecraft.server." + nmsver + ".Packet");
if (useOldMethods) {
Class<?> chatSerializerClass = Class.forName("net.minecraft.server." + nmsver + ".ChatSerializer");
Class<?> iChatBaseComponentClass = Class.forName("net.minecraft.server." + nmsver + ".IChatBaseComponent");
Method m3 = chatSerializerClass.getDeclaredMethod("a", String.class);
Object cbc = iChatBaseComponentClass.cast(m3.invoke(chatSerializerClass, "{\"text\": \"" + message + "\"}"));
packet = packetPlayOutChatClass.getConstructor(new Class<?>[]{iChatBaseComponentClass, byte.class}).newInstance(cbc, (byte) 2);
} else {
Class<?> chatComponentTextClass = Class.forName("net.minecraft.server." + nmsver + ".ChatComponentText");
Class<?> iChatBaseComponentClass = Class.forName("net.minecraft.server." + nmsver + ".IChatBaseComponent");
try {
Class<?> chatMessageTypeClass = Class.forName("net.minecraft.server." + nmsver + ".ChatMessageType");
Object[] chatMessageTypes = chatMessageTypeClass.getEnumConstants();
Object chatMessageType = null;
for (Object obj : chatMessageTypes) {
if (obj.toString().equals("GAME_INFO")) {
chatMessageType = obj;
}
}
Object chatCompontentText = chatComponentTextClass.getConstructor(new Class<?>[]{String.class}).newInstance(message);
packet = packetPlayOutChatClass.getConstructor(new Class<?>[]{iChatBaseComponentClass, chatMessageTypeClass}).newInstance(chatCompontentText, chatMessageType);
} catch (ClassNotFoundException cnfe) {
Object chatCompontentText = chatComponentTextClass.getConstructor(new Class<?>[]{String.class}).newInstance(message);
packet = packetPlayOutChatClass.getConstructor(new Class<?>[]{iChatBaseComponentClass, byte.class}).newInstance(chatCompontentText, (byte) 2);
}
}
Method craftPlayerHandleMethod = craftPlayerClass.getDeclaredMethod("getHandle");
Object craftPlayerHandle = craftPlayerHandleMethod.invoke(craftPlayer);
Field playerConnectionField = craftPlayerHandle.getClass().getDeclaredField("playerConnection");
Object playerConnection = playerConnectionField.get(craftPlayerHandle);
Method sendPacketMethod = playerConnection.getClass().getDeclaredMethod("sendPacket", packetClass);
sendPacketMethod.invoke(playerConnection, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void sendActionBarPost112(Player player, String message) {
if (!player.isOnline()) {
return; // Player may have logged out
}
try {
Class<?> craftPlayerClass = Class.forName("org.bukkit.craftbukkit." + nmsver + ".entity.CraftPlayer");
Object craftPlayer = craftPlayerClass.cast(player);
Object ppoc;
Class<?> c4 = Class.forName("net.minecraft.server." + nmsver + ".PacketPlayOutChat");
Class<?> c5 = Class.forName("net.minecraft.server." + nmsver + ".Packet");
Class<?> c2 = Class.forName("net.minecraft.server." + nmsver + ".ChatComponentText");
Class<?> c3 = Class.forName("net.minecraft.server." + nmsver + ".IChatBaseComponent");
Class<?> chatMessageTypeClass = Class.forName("net.minecraft.server." + nmsver + ".ChatMessageType");
Object[] chatMessageTypes = chatMessageTypeClass.getEnumConstants();
Object chatMessageType = null;
for (Object obj : chatMessageTypes) {
if (obj.toString().equals("GAME_INFO")) {
chatMessageType = obj;
}
}
Object o = c2.getConstructor(new Class<?>[]{String.class}).newInstance(message);
ppoc = c4.getConstructor(new Class<?>[]{c3, chatMessageTypeClass}).newInstance(o, chatMessageType);
Method m1 = craftPlayerClass.getDeclaredMethod("getHandle");
Object h = m1.invoke(craftPlayer);
Field f1 = h.getClass().getDeclaredField("playerConnection");
Object pc = f1.get(h);
Method m5 = pc.getClass().getDeclaredMethod("sendPacket", c5);
m5.invoke(pc, ppoc);
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static void sendActionBarPre112(Player player, String message) {
if (!player.isOnline()) {
return; // Player may have logged out
}
try {
Class<?> craftPlayerClass = Class.forName("org.bukkit.craftbukkit." + nmsver + ".entity.CraftPlayer");
Object craftPlayer = craftPlayerClass.cast(player);
Object ppoc;
Class<?> c4 = Class.forName("net.minecraft.server." + nmsver + ".PacketPlayOutChat");
Class<?> c5 = Class.forName("net.minecraft.server." + nmsver + ".Packet");
if (useOldMethods) {
Class<?> c2 = Class.forName("net.minecraft.server." + nmsver + ".ChatSerializer");
Class<?> c3 = Class.forName("net.minecraft.server." + nmsver + ".IChatBaseComponent");
Method m3 = c2.getDeclaredMethod("a", String.class);
Object cbc = c3.cast(m3.invoke(c2, "{\"text\": \"" + message + "\"}"));
ppoc = c4.getConstructor(new Class<?>[]{c3, byte.class}).newInstance(cbc, (byte) 2);
} else {
Class<?> c2 = Class.forName("net.minecraft.server." + nmsver + ".ChatComponentText");
Class<?> c3 = Class.forName("net.minecraft.server." + nmsver + ".IChatBaseComponent");
Object o = c2.getConstructor(new Class<?>[]{String.class}).newInstance(message);
ppoc = c4.getConstructor(new Class<?>[]{c3, byte.class}).newInstance(o, (byte) 2);
}
Method m1 = craftPlayerClass.getDeclaredMethod("getHandle");
Object h = m1.invoke(craftPlayer);
Field f1 = h.getClass().getDeclaredField("playerConnection");
Object pc = f1.get(h);
Method m5 = pc.getClass().getDeclaredMethod("sendPacket", c5);
m5.invoke(pc, ppoc);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void sendActionBar(final Player player, final String message, int duration) {
sendActionBar(player, message);
if (duration >= 0) {
// Sends empty message at the end of the duration. Allows messages shorter than 3 seconds, ensures precision.
new BukkitRunnable() {
@Override
public void run() {
sendActionBar(player, "");
}
}.runTaskLater(instance, duration + 1);
}
// Re-sends the messages every 3 seconds so it doesn't go away from the player's screen.
while (duration > 60) {
duration -= 60;
int sched = duration % 60;
new BukkitRunnable() {
@Override
public void run() {
sendActionBar(player, message);
}
}.runTaskLater(instance, (long) sched);
}
}
public static void sendActionBarToAllPlayers(String message) {
sendActionBarToAllPlayers(message, -1);
}
public static void sendActionBarToAllPlayers(String message, int duration) {
for (Player p : Bukkit.getOnlinePlayers()) {
sendActionBar(p, message, duration);
}
}
public static void init(EpicVouchers epicVouchers) {
instance = epicVouchers;
nmsver = Bukkit.getServer().getClass().getPackage().getName();
nmsver = nmsver.substring(nmsver.lastIndexOf(".") + 1);
if (nmsver.equalsIgnoreCase("v1_8_R1") || nmsver.equalsIgnoreCase("v1_7_")) { // Not sure if 1_7 works for the protocol hack?
useOldMethods = true;
}
}
}

View File

@ -1,10 +0,0 @@
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

@ -535,4 +535,14 @@ public class FastInv implements InventoryHolder {
this.cancelTasksOnClose = cancelTasksOnClose;
return this;
}
public void reOpen(Player player) {
player.closeInventory();
refresh();
player.openInventory(inventory);
}
public void refresh() {
}
}

View File

@ -0,0 +1,107 @@
package com.songoda.epicvouchers.libraries.inventory;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.ItemBuilder;
import com.songoda.epicvouchers.menus.ActionMenu;
import com.songoda.epicvouchers.utils.NMSUtil;
import com.songoda.epicvouchers.utils.ServerVersion;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.stream.IntStream;
import static org.bukkit.ChatColor.*;
import static org.bukkit.Material.*;
public abstract class PlayersMenu extends FastInv {
private final int SLOTS = 17;
private final EpicVouchers instance;
private final Voucher voucher;
private final BiConsumer<CommandSender, Player> playerConsumer;
private final List<Player> players;
private int page;
public PlayersMenu(EpicVouchers instance, Voucher voucher, String menu, BiConsumer<CommandSender, Player> playerConsumer, List<Player> players) {
super(27, menu);
this.instance = instance;
this.voucher = voucher;
this.playerConsumer = playerConsumer;
this.players = players;
refresh();
}
@Override
public void refresh() {
fill(null);
final int startIndex = page * (players.size() - 1);
IntStream.rangeClosed(0, SLOTS).forEach(slot -> {
int index = startIndex + slot;
if (index >= players.size()) {
return;
}
Player player = players.get(index);
ItemStack itemStack = new ItemStack(NMSUtil.getVersionNumber() > 12 ? PLAYER_HEAD : Material.valueOf("SKULL_ITEM"));
SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();
try {
skullMeta.setOwningPlayer(player);
} catch (Throwable ignore) {
}
skullMeta.setDisplayName(YELLOW + player.getName());
itemStack.setItemMeta(skullMeta);
addItem(slot, itemStack, event -> playerConsumer.accept(event.getPlayer(), player));
});
if (players.size() / SLOTS > page) {
addItem(26, new ItemBuilder(ARROW)
.name(YELLOW + "Next")
.lore(GRAY + "Click to go to the next page of players")
.build(), event -> {
page++;
refresh();
});
} else {
addItem(26, null);
}
if (page > 0) {
addItem(18, new ItemBuilder(ARROW)
.name(YELLOW + "Previous")
.lore(GRAY + "Click to go to the previous page of players")
.build(), event -> {
page--;
refresh();
});
} else {
addItem(18, new ItemBuilder(BARRIER)
.name(YELLOW + "Return")
.lore(GRAY + "Return to the action menu")
.addGlow().build(), event -> new ActionMenu(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);
IntStream.rangeClosed(SLOTS + 1, 26).forEach(slot -> {
if (getInventory().getItem(slot) == null)
addItem(slot, new ItemBuilder(fillItem).name(ChatColor.RESET.toString()).build());
});
}
}
}

View File

@ -3,19 +3,18 @@ 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.Tuple;
import javafx.util.Pair;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import java.util.function.BiConsumer;
import static com.songoda.epicvouchers.libraries.AbstractAnvilGUI.AnvilSlot.INPUT_LEFT;
import static org.bukkit.ChatColor.GRAY;
import static org.bukkit.ChatColor.YELLOW;
import static org.bukkit.ChatColor.*;
import static org.bukkit.Material.PAPER;
public class ListEntryIcon extends Icon {
public ListEntryIcon(EpicVouchers instance, String entry, BiConsumer<Player, String> onRemove, BiConsumer<Player, Tuple<String, String>> onEdit) {
public ListEntryIcon(EpicVouchers instance, String entry, BiConsumer<Player, String> onRemove, BiConsumer<Player, Pair<String, String>> onEdit) {
super(new ItemBuilder(PAPER).name(YELLOW + entry).lore(GRAY + "Right click to edit",
GRAY + "Left click to remove").build(), event -> {
if (event.getClickType() == ClickType.LEFT) {
@ -23,7 +22,7 @@ public class ListEntryIcon extends Icon {
return;
}
AbstractAnvilGUI anvilGUI = new AbstractAnvilGUI(instance, event.getPlayer(), anvilEvent -> onEdit.accept(event.getPlayer(), new Tuple<>(entry, anvilEvent.getName())));
AbstractAnvilGUI anvilGUI = new AbstractAnvilGUI(instance, event.getPlayer(), anvilEvent -> onEdit.accept(event.getPlayer(), new Pair<String, String>(entry, anvilEvent.getName())));
anvilGUI.setSlot(INPUT_LEFT, new ItemBuilder(PAPER).name(entry).build());
anvilGUI.open();

View File

@ -2,7 +2,7 @@ package com.songoda.epicvouchers.libraries.inventory.icons;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.ItemBuilder;
import com.songoda.epicvouchers.menus.sub.StringListMenu;
import com.songoda.epicvouchers.menus.sub.editor.StringListMenu;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.ChatColor;
import org.bukkit.Material;

View File

@ -23,7 +23,7 @@ public class PlayerInteractListener implements Listener {
@EventHandler
public void voucherListener(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) {
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.hasItem()) {
return;
}
@ -33,10 +33,10 @@ public class PlayerInteractListener implements Listener {
continue;
}
ItemStack item = event.getPlayer().getItemInHand();
ItemStack item = event.getItem();
if (voucher.getItemStack() != null) {
if(!voucher.getItemStack().isSimilar(item)) {
if (!voucher.getItemStack().isSimilar(item)) {
continue;
}
} else {
@ -54,19 +54,21 @@ public class PlayerInteractListener implements Listener {
UUID uuid = player.getUniqueId();
if (instance.getCooldowns().isOnCoolDown(uuid)) {
player.sendMessage(instance.getLocale().getMessage("event.general.cooldown", instance.getCooldowns().getTime(uuid), voucher.getName(true)));
if (instance.getCoolDowns().isOnCoolDown(uuid)) {
player.sendMessage(instance.getLocale().getMessage("event.general.coolDown", instance.getCoolDowns().getTime(uuid), voucher.getName(true)));
return;
}
event.setCancelled(true);
if (voucher.isConfirm()) {
new ConfirmMenu(instance, voucher).open(player);
new ConfirmMenu(instance,
() -> instance.getVoucherExecutor().redeemVoucher(player, voucher, item, true, event),
() -> {
})
.open(player);
return;
}
instance.getVoucherExecutor().redeemVoucher(player, voucher, item, true);
}
}
}

View File

@ -0,0 +1,70 @@
package com.songoda.epicvouchers.menus;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.ItemBuilder;
import com.songoda.epicvouchers.libraries.inventory.FastInv;
import com.songoda.epicvouchers.menus.sub.action.ForceMenu;
import com.songoda.epicvouchers.menus.sub.action.GiveMenu;
import com.songoda.epicvouchers.utils.ServerVersion;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import static com.songoda.epicvouchers.utils.Methods.format;
import static org.bukkit.ChatColor.*;
import static org.bukkit.Material.BARRIER;
public class ActionMenu extends FastInv {
public ActionMenu(EpicVouchers instance, Voucher voucher) {
super(27, "Give menu");
addItem(10, new ItemBuilder(Material.FEATHER)
.name(format("&6Give voucher"))
.lore(format("&eGive the voucher to a"),
format("&especific player."))
.build(), event -> new GiveMenu(instance, voucher).open(event.getPlayer()));
addItem(14, new ItemBuilder(Material.ANVIL)
.name(format("&6Force voucher"))
.lore(format("&eForce the redeeming of the"),
format("&evoucher on a specific player."))
.build(), event -> new ForceMenu(instance, voucher).open(event.getPlayer()));
addItem(12, new ItemBuilder(Material.FEATHER)
.name(format("&6Give all voucher"))
.lore(format("&eGive the voucher to all"),
format("&eonline players."))
.build(), event -> new ConfirmMenu(instance,
() -> {
voucher.giveAll(event.getPlayer(), 1);
open(event.getPlayer());
}, () -> open(event.getPlayer())).open(event.getPlayer()));
addItem(16, new ItemBuilder(Material.ANVIL)
.name(format("&6Force all voucher"))
.lore(format("&eForce the redeeming of the"),
format("&evoucher on all online players."))
.build(), event -> new ConfirmMenu(instance,
() -> {
voucher.forceRedeem(event.getPlayer(), new ArrayList<>(Bukkit.getOnlinePlayers()), 1);
open(event.getPlayer());
}, () -> open(event.getPlayer())).open(event.getPlayer()));
addItem(18, new ItemBuilder(BARRIER)
.name(YELLOW + "Return")
.lore(GRAY + "Return to the editor")
.addGlow().build(), event -> new VoucherMenu(instance).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);
fill(new ItemBuilder(fillItem).name(ChatColor.RESET.toString()).build());
}
}
}

View File

@ -1,11 +1,9 @@
package com.songoda.epicvouchers.menus;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.inventory.FastInv;
import com.songoda.epicvouchers.libraries.ItemBuilder;
import com.songoda.epicvouchers.libraries.inventory.FastInv;
import com.songoda.epicvouchers.utils.ServerVersion;
import com.songoda.epicvouchers.utils.SoundUtils;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@ -14,7 +12,7 @@ import static org.bukkit.enchantments.Enchantment.DURABILITY;
import static org.bukkit.inventory.ItemFlag.HIDE_ENCHANTS;
public class ConfirmMenu extends FastInv {
public ConfirmMenu(EpicVouchers instance, Voucher voucher) {
public ConfirmMenu(EpicVouchers instance, Runnable success, Runnable failure) {
super(27, instance.getLocale().getMessage("interface.confirmsettings.title"));
addItem(11, new ItemBuilder(Material.EMERALD)
@ -22,7 +20,7 @@ public class ConfirmMenu extends FastInv {
.lore(instance.getLocale().getMessage("interface.confirmsettings.confirmitemlore"))
.addGlow().build(), event -> {
event.getPlayer().closeInventory();
instance.getVoucherExecutor().redeemVoucher(event.getPlayer(), voucher, event.getPlayer().getItemInHand(), true);
success.run();
});
addItem(15, new ItemBuilder(Material.REDSTONE_BLOCK)
@ -31,7 +29,7 @@ public class ConfirmMenu extends FastInv {
.enchant(DURABILITY, 1)
.addFlags(HIDE_ENCHANTS)
.build(), event -> {
SoundUtils.playSound(event.getPlayer(), "CLICK", 1);
failure.run();
event.getPlayer().closeInventory();
});

View File

@ -3,18 +3,16 @@ package com.songoda.epicvouchers.menus;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.ItemBuilder;
import com.songoda.epicvouchers.libraries.inventory.FastInv;
import com.songoda.epicvouchers.menus.sub.SetItemMenu;
import com.songoda.epicvouchers.menus.sub.editor.SetItemMenu;
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 static com.songoda.epicvouchers.utils.Methods.format;
import static org.bukkit.ChatColor.GRAY;
import static org.bukkit.ChatColor.YELLOW;
import static org.bukkit.Material.BOOK;
import static org.bukkit.Material.STONE;
import static org.bukkit.ChatColor.*;
import static org.bukkit.Material.valueOf;
import static org.bukkit.Material.*;
public class OptionMenu extends FastInv {
@ -23,16 +21,16 @@ public class OptionMenu extends FastInv {
addItem(13, new ItemBuilder(voucher.toItemStack()).name(format(voucher.getName(true))).build());
addItem(18, new ItemBuilder(Material.BARRIER)
addItem(18, new ItemBuilder(BARRIER)
.name(YELLOW + "Return")
.lore(GRAY + "Return to the editor")
.addGlow().build(), event -> new VoucherMenu(instance).open(event.getPlayer()));
addItem(0, new ItemBuilder(Material.FEATHER)
.name(format("&6Receive voucher"))
.lore(format("&eReceive a copy of the voucher"))
addItem(0, new ItemBuilder(FEATHER)
.name(format("&6Voucher actions"))
.lore(format("&eGive or redeem your voucher"))
.addGlow()
.build(), event -> event.getPlayer().getInventory().addItem(voucher.toItemStack()));
.build(), event -> new ActionMenu(instance, voucher).open(event.getPlayer()));
addItem(26, new ItemBuilder(STONE)
.name(format("&6Set item"))
@ -45,8 +43,8 @@ public class OptionMenu extends FastInv {
.build(), event -> new VoucherEditorMenu(instance, voucher).open(event.getPlayer()));
fill(new ItemBuilder(instance.getServerVersion().isServerVersionAtLeast(ServerVersion.V1_13) ?
new ItemStack(Material.valueOf("GRAY_STAINED_GLASS_PANE")) :
new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 7)).name(ChatColor.RESET.toString()).build());
new ItemStack(valueOf("GRAY_STAINED_GLASS_PANE")) :
new ItemStack(valueOf("STAINED_GLASS_PANE"), 1, (short) 7)).name(ChatColor.RESET.toString()).build());
}
}

View File

@ -3,22 +3,15 @@ package com.songoda.epicvouchers.menus;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.ItemBuilder;
import com.songoda.epicvouchers.libraries.inventory.IconInv;
import com.songoda.epicvouchers.libraries.inventory.icons.Icon;
import com.songoda.epicvouchers.libraries.inventory.icons.StringIcon;
import com.songoda.epicvouchers.libraries.inventory.icons.StringListIcon;
import com.songoda.epicvouchers.libraries.inventory.icons.ToggleableIcon;
import com.songoda.epicvouchers.menus.sub.EffectsMenu;
import com.songoda.epicvouchers.menus.sub.ParticlesMenu;
import com.songoda.epicvouchers.menus.sub.SoundsMenu;
import com.songoda.epicvouchers.menus.sub.TitlesMenu;
import com.songoda.epicvouchers.libraries.inventory.icons.*;
import com.songoda.epicvouchers.menus.sub.editor.*;
import com.songoda.epicvouchers.voucher.Voucher;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import static org.bukkit.ChatColor.GRAY;
import static org.bukkit.ChatColor.YELLOW;
import static org.bukkit.ChatColor.*;
import static org.bukkit.Material.BOOK;
public class VoucherEditorMenu extends IconInv {

View File

@ -36,7 +36,7 @@ public class VoucherMenu extends IconInv {
return;
}
Voucher voucher = new Voucher(anvilEvent.getName());
Voucher voucher = new Voucher(anvilEvent.getName(), instance);
voucher.setMaterial(PAPER);
voucher.setName("&f" + anvilEvent.getName());

View File

@ -0,0 +1,15 @@
package com.songoda.epicvouchers.menus.sub.action;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.inventory.PlayersMenu;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import java.util.Collections;
public class ForceMenu extends PlayersMenu {
public ForceMenu(EpicVouchers instance, Voucher voucher) {
super(instance, voucher, "Force Menu", (who, player) -> voucher.forceRedeem(who, Collections.singletonList(player), 1), new ArrayList<>(Bukkit.getOnlinePlayers()));
}
}

View File

@ -0,0 +1,15 @@
package com.songoda.epicvouchers.menus.sub.action;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.inventory.PlayersMenu;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import java.util.Collections;
public class GiveMenu extends PlayersMenu {
public GiveMenu(EpicVouchers instance, Voucher voucher) {
super(instance, voucher, "Give Menu", (who, player) -> voucher.give(who, Collections.singletonList(player), 1), new ArrayList<>(Bukkit.getOnlinePlayers()));
}
}

View File

@ -1,4 +1,4 @@
package com.songoda.epicvouchers.menus.sub;
package com.songoda.epicvouchers.menus.sub.editor;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.ItemBuilder;
@ -8,10 +8,8 @@ import com.songoda.epicvouchers.libraries.inventory.icons.StringIcon;
import com.songoda.epicvouchers.menus.VoucherEditorMenu;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.Material;
import org.bukkit.potion.PotionEffectType;
import static org.bukkit.ChatColor.GRAY;
import static org.bukkit.ChatColor.YELLOW;
import static org.bukkit.ChatColor.*;
public class EffectsMenu extends IconInv {
public EffectsMenu(EpicVouchers instance, Voucher voucher) {

View File

@ -1,4 +1,4 @@
package com.songoda.epicvouchers.menus.sub;
package com.songoda.epicvouchers.menus.sub.editor;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.ItemBuilder;
@ -9,8 +9,7 @@ import com.songoda.epicvouchers.menus.VoucherEditorMenu;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.Material;
import static org.bukkit.ChatColor.GRAY;
import static org.bukkit.ChatColor.YELLOW;
import static org.bukkit.ChatColor.*;
public class ParticlesMenu extends IconInv {
public ParticlesMenu(EpicVouchers instance, Voucher voucher) {

View File

@ -1,4 +1,4 @@
package com.songoda.epicvouchers.menus.sub;
package com.songoda.epicvouchers.menus.sub.editor;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.ItemBuilder;
@ -11,11 +11,7 @@ import org.bukkit.Material;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import static com.songoda.epicvouchers.utils.Methods.format;
import static org.bukkit.ChatColor.GRAY;
import static org.bukkit.ChatColor.YELLOW;
import static org.bukkit.ChatColor.*;
public class SetItemMenu extends FastInv {

View File

@ -1,4 +1,4 @@
package com.songoda.epicvouchers.menus.sub;
package com.songoda.epicvouchers.menus.sub.editor;
import com.google.common.base.Enums;
import com.songoda.epicvouchers.EpicVouchers;
@ -7,13 +7,11 @@ import com.songoda.epicvouchers.libraries.inventory.IconInv;
import com.songoda.epicvouchers.libraries.inventory.icons.IntegerIcon;
import com.songoda.epicvouchers.libraries.inventory.icons.StringIcon;
import com.songoda.epicvouchers.menus.VoucherEditorMenu;
import com.songoda.epicvouchers.utils.SoundUtils;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.Material;
import org.bukkit.Sound;
import static org.bukkit.ChatColor.GRAY;
import static org.bukkit.ChatColor.YELLOW;
import static org.bukkit.ChatColor.*;
public class SoundsMenu extends IconInv {
public SoundsMenu(EpicVouchers instance, Voucher voucher) {
@ -22,7 +20,7 @@ public class SoundsMenu extends IconInv {
addIcon(1, new StringIcon(instance, "Sound", voucher.getSound(), (player, editString) -> {
voucher.setSound(editString).saveSetting("sounds.sound", editString);
new SoundsMenu(instance, voucher).open(player);
}, string -> Enums.getIfPresent(SoundUtils.class, string).isPresent()));
}, string -> Enums.getIfPresent(Sound.class, string).isPresent()));
addIcon(2, new IntegerIcon(instance, "Pitch", voucher.getSoundPitch(), (player, number) -> {
voucher.setSoundPitch(number).saveSetting("sounds.pitch", number);

View File

@ -1,4 +1,4 @@
package com.songoda.epicvouchers.menus.sub;
package com.songoda.epicvouchers.menus.sub.editor;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.AbstractAnvilGUI;
@ -51,7 +51,7 @@ public class StringListMenu extends IconInv {
voucher.saveSetting(key.toLowerCase(), list);
new StringListMenu(instance, key, list, toEdit, voucher).open(player);
}, (player, tuple) -> {
list.set(list.indexOf(tuple.x), tuple.y);
list.set(list.indexOf(tuple.getKey()), tuple.getValue());
voucher.saveSetting(key.toLowerCase(), list);
new StringListMenu(instance, key, list, toEdit, voucher).open(player);
}));

View File

@ -1,4 +1,4 @@
package com.songoda.epicvouchers.menus.sub;
package com.songoda.epicvouchers.menus.sub.editor;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.libraries.ItemBuilder;
@ -9,8 +9,7 @@ import com.songoda.epicvouchers.menus.VoucherEditorMenu;
import com.songoda.epicvouchers.voucher.Voucher;
import org.bukkit.Material;
import static org.bukkit.ChatColor.GRAY;
import static org.bukkit.ChatColor.YELLOW;
import static org.bukkit.ChatColor.*;
public class TitlesMenu extends IconInv {
public TitlesMenu(EpicVouchers instance, Voucher voucher) {

View File

@ -1,34 +0,0 @@
package com.songoda.epicvouchers.utils;
import com.songoda.epicvouchers.EpicVouchers;
/**
* Created by songoda on 3/21/2017.
*/
public class Debugger {
private static EpicVouchers instance;
public static void init(EpicVouchers plugin) {
instance = plugin;
}
public static void runReport(Exception e) {
if (isDebug()) {
System.out.println("==============================================================");
System.out.println("The following is an error encountered in EpicVouchers.");
System.out.println("--------------------------------------------------------------");
e.printStackTrace();
System.out.println("==============================================================");
}
sendReport(e);
}
public static void sendReport(Exception e) {
}
public static boolean isDebug() {
return instance.getConfig().getBoolean("System.Debugger Enabled");
}
}

View File

@ -16,12 +16,12 @@ public class SettingsManager implements Listener {
}
public void updateSettings() {
for (settings s : settings.values()) {
for (Settings s : Settings.values()) {
instance.getConfig().addDefault(s.setting, s.option);
}
}
public enum settings {
public enum Settings {
CONFIRM_FILL_GLASS("Interface.Fill Interfaces With Glass", true),
COOLDOWN_DELAY("Main.Cooldown Delay", 10),
@ -38,7 +38,7 @@ public class SettingsManager implements Listener {
private final String setting;
private final Object option;
settings(String setting, Object option) {
Settings(String setting, Object option) {
this.setting = setting;
this.option = option;
}

View File

@ -1,229 +0,0 @@
package com.songoda.epicvouchers.utils;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
public enum SoundUtils {
AMBIENCE_CAVE("AMBIENCE_CAVE", "AMBIENT_CAVE"),
AMBIENCE_RAIN("AMBIENCE_RAIN", "WEATHER_RAIN"),
AMBIENCE_THUNDER("AMBIENCE_THUNDER", "ENTITY_LIGHTNING_THUNDER", "ENTITY_LIGHTNING_BOLT_THUNDER"),
ANVIL_BREAK("ANVIL_BREAK", "BLOCK_ANVIL_BREAK"),
ANVIL_LAND("ANVIL_LAND", "BLOCK_ANVIL_LAND"),
ANVIL_USE("ANVIL_USE", "BLOCK_ANVIL_USE"),
ARROW_HIT("ARROW_HIT", "ENTITY_ARROW_HIT"),
BURP("BURP", "ENTITY_PLAYER_BURP"),
CHEST_CLOSE("CHEST_CLOSE", "ENTITY_CHEST_CLOSE", "BLOCK_CHEST_CLOSE"),
CHEST_OPEN("CHEST_OPEN", "ENTITY_CHEST_OPEN", "BLOCK_CHEST_OPEN"),
CLICK("CLICK", "UI_BUTTON_CLICK"),
DOOR_CLOSE("DOOR_CLOSE", "BLOCK_WOODEN_DOOR_CLOSE"),
DOOR_OPEN("DOOR_OPEN", "BLOCK_WOODEN_DOOR_OPEN"),
DRINK("DRINK", "ENTITY_GENERIC_DRINK"),
EAT("EAT", "ENTITY_GENERIC_EAT"),
EXPLODE("EXPLODE", "ENTITY_GENERIC_EXPLODE"),
FALL_BIG("FALL_BIG", "ENTITY_GENERIC_BIG_FALL"),
FALL_SMALL("FALL_SMALL", "ENTITY_GENERIC_SMALL_FALL"),
FIRE("FIRE", "BLOCK_FIRE_AMBIENT"),
FIRE_IGNITE("FIRE_IGNITE", "ITEM_FLINTANDSTEEL_USE"),
FIZZ("FIZZ", "BLOCK_FIRE_EXTINGUISH"),
FUSE("FUSE", "ENTITY_TNT_PRIMED"),
GLASS("GLASS", "BLOCK_GLASS_BREAK"),
HURT_FLESH("HURT_FLESH", "ENTITY_PLAYER_HURT"),
ITEM_BREAK("ITEM_BREAK", "ENTITY_ITEM_BREAK"),
ITEM_PICKUP("ITEM_PICKUP", "ENTITY_ITEM_PICKUP"),
LAVA("LAVA", "BLOCK_LAVA_AMBIENT"),
LAVA_POP("LAVA_POP", "BLOCK_LAVA_POP"),
LEVEL_UP("LEVEL_UP", "ENTITY_PLAYER_LEVELUP"),
MINECART_BASE("MINECART_BASE", "ENTITY_MINECART_RIDING"),
MINECART_INSIDE("MINECART_INSIDE", "ENTITY_MINECART_RIDING"),
NOTE_BASS("NOTE_BASS", "BLOCK_NOTE_BASS", "BLOCK_NOTE_BLOCK_BASS"),
NOTE_PIANO("NOTE_PIANO", "BLOCK_NOTE_HARP", "BLOCK_NOTE_BLOCK_HARP"),
NOTE_BASS_DRUM("NOTE_BASS_DRUM", "BLOCK_NOTE_BASEDRUM", "BLOCK_NOTE_BLOCK_BASEDRUM"),
NOTE_STICKS("NOTE_STICKS", "BLOCK_NOTE_HAT", "BLOCK_NOTE_BLOCK_HAT"),
NOTE_BASS_GUITAR("NOTE_BASS_GUITAR", "BLOCK_NOTE_GUITAR", "BLOCK_NOTE_BLOCK_GUITAR", "BLOCK_NOTE_BASS" /* 1.10 doesn't know guitar... */),
NOTE_SNARE_DRUM("NOTE_SNARE_DRUM", "BLOCK_NOTE_SNARE", "BLOCK_NOTE_BLOCK_SNARE"),
NOTE_PLING("NOTE_PLING", "BLOCK_NOTE_PLING", "BLOCK_NOTE_BLOCK_PLING"),
ORB_PICKUP("ORB_PICKUP", "ENTITY_EXPERIENCE_ORB_PICKUP"),
PISTON_EXTEND("PISTON_EXTEND", "BLOCK_PISTON_EXTEND"),
PISTON_RETRACT("PISTON_RETRACT", "BLOCK_PISTON_CONTRACT"),
PORTAL("PORTAL", "BLOCK_PORTAL_AMBIENT"),
PORTAL_TRAVEL("PORTAL_TRAVEL", "BLOCK_PORTAL_TRAVEL"),
PORTAL_TRIGGER("PORTAL_TRIGGER", "BLOCK_PORTAL_TRIGGER"),
SHOOT_ARROW("SHOOT_ARROW", "ENTITY_ARROW_SHOOT"),
SPLASH("SPLASH", "ENTITY_GENERIC_SPLASH"),
SPLASH2("SPLASH2", "ENTITY_BOBBER_SPLASH", "ENTITY_FISHING_BOBBER_SPLASH"),
STEP_GRASS("STEP_GRASS", "BLOCK_GRASS_STEP"),
STEP_GRAVEL("STEP_GRAVEL", "BLOCK_GRAVEL_STEP"),
STEP_LADDER("STEP_LADDER", "BLOCK_LADDER_STEP"),
STEP_SAND("STEP_SAND", "BLOCK_SAND_STEP"),
STEP_SNOW("STEP_SNOW", "BLOCK_SNOW_STEP"),
STEP_STONE("STEP_STONE", "BLOCK_STONE_STEP"),
STEP_WOOD("STEP_WOOD", "BLOCK_WOOD_STEP"),
STEP_WOOL("STEP_WOOL", "BLOCK_CLOTH_STEP", "BLOCK_WOOL_STEP"),
SWIM("SWIM", "ENTITY_GENERIC_SWIM"),
WATER("WATER", "BLOCK_WATER_AMBIENT"),
WOOD_CLICK("WOOD_CLICK", "BLOCK_WOOD_BUTTON_CLICK_ON", "BLOCK_WOODEN_BUTTON_CLICK_ON"),
BAT_DEATH("BAT_DEATH", "ENTITY_BAT_DEATH"),
BAT_HURT("BAT_HURT", "ENTITY_BAT_HURT"),
BAT_IDLE("BAT_IDLE", "ENTITY_BAT_AMBIENT"),
BAT_LOOP("BAT_LOOP", "ENTITY_BAT_LOOP"),
BAT_TAKEOFF("BAT_TAKEOFF", "ENTITY_BAT_TAKEOFF"),
BLAZE_BREATH("BLAZE_BREATH", "ENTITY_BLAZE_AMBIENT"),
BLAZE_DEATH("BLAZE_DEATH", "ENTITY_BLAZE_DEATH"),
BLAZE_HIT("BLAZE_HIT", "ENTITY_BLAZE_HURT"),
CAT_HISS("CAT_HISS", "ENTITY_CAT_HISS"),
CAT_HIT("CAT_HIT", "ENTITY_CAT_HURT"),
CAT_MEOW("CAT_MEOW", "ENTITY_CAT_AMBIENT"),
CAT_PURR("CAT_PURR", "ENTITY_CAT_PURR"),
CAT_PURREOW("CAT_PURREOW", "ENTITY_CAT_PURREOW"),
CHICKEN_IDLE("CHICKEN_IDLE", "ENTITY_CHICKEN_AMBIENT"),
CHICKEN_HURT("CHICKEN_HURT", "ENTITY_CHICKEN_HURT"),
CHICKEN_EGG_POP("CHICKEN_EGG_POP", "ENTITY_CHICKEN_EGG"),
CHICKEN_WALK("CHICKEN_WALK", "ENTITY_CHICKEN_STEP"),
COW_IDLE("COW_IDLE", "ENTITY_COW_AMBIENT"),
COW_HURT("COW_HURT", "ENTITY_COW_HURT"),
COW_WALK("COW_WALK", "ENTITY_COW_STEP"),
CREEPER_HISS("CREEPER_HISS", "ENTITY_CREEPER_PRIMED"),
CREEPER_DEATH("CREEPER_DEATH", "ENTITY_CREEPER_DEATH"),
ENDERDRAGON_DEATH("ENDERDRAGON_DEATH", "ENTITY_ENDERDRAGON_DEATH", "ENTITY_ENDER_DRAGON_DEATH"),
ENDERDRAGON_GROWL("ENDERDRAGON_GROWL", "ENTITY_ENDERDRAGON_GROWL", "ENTITY_ENDER_DRAGON_GROWL"),
ENDERDRAGON_HIT("ENDERDRAGON_HIT", "ENTITY_ENDERDRAGON_HURT", "ENTITY_ENDER_DRAGON_HURT"),
ENDERDRAGON_WINGS("ENDERDRAGON_WINGS", "ENTITY_ENDERDRAGON_FLAP", "ENTITY_ENDER_DRAGON_FLAP"),
ENDERMAN_DEATH("ENDERMAN_DEATH", "ENTITY_ENDERMEN_DEATH", "ENTITY_ENDERMAN_DEATH"),
ENDERMAN_HIT("ENDERMAN_HIT", "ENTITY_ENDERMEN_HURT", "ENTITY_ENDERMAN_HURT"),
ENDERMAN_IDLE("ENDERMAN_IDLE", "ENTITY_ENDERMEN_AMBIENT", "ENTITY_ENDERMAN_AMBIENT"),
ENDERMAN_TELEPORT("ENDERMAN_TELEPORT", "ENTITY_ENDERMEN_TELEPORT", "ENTITY_ENDERMAN_TELEPORT"),
ENDERMAN_SCREAM("ENDERMAN_SCREAM", "ENTITY_ENDERMEN_SCREAM", "ENTITY_ENDERMAN_SCREAM"),
ENDERMAN_STARE("ENDERMAN_STARE", "ENTITY_ENDERMEN_STARE", "ENTITY_ENDERMAN_STARE"),
GHAST_SCREAM("GHAST_SCREAM", "ENTITY_GHAST_SCREAM"),
GHAST_SCREAM2("GHAST_SCREAM2", "ENTITY_GHAST_HURT"),
GHAST_CHARGE("GHAST_CHARGE", "ENTITY_GHAST_WARN"),
GHAST_DEATH("GHAST_DEATH", "ENTITY_GHAST_DEATH"),
GHAST_FIREBALL("GHAST_FIREBALL", "ENTITY_GHAST_SHOOT"),
GHAST_MOAN("GHAST_MOAN", "ENTITY_GHAST_AMBIENT"),
IRONGOLEM_ATTACK("IRONGOLEM_THROW", "ENTITY_IRONGOLEM_ATTACK", "ENTITY_IRON_GOLEM_ATTACK"),
IRONGOLEM_DEATH("IRONGOLEM_DEATH", "ENTITY_IRONGOLEM_DEATH", "ENTITY_IRON_GOLEM_DEATH"),
IRONGOLEM_HIT("IRONGOLEM_HIT", "ENTITY_IRONGOLEM_HURT", "ENTITY_IRON_GOLEM_HURT"),
IRONGOLEM_WALK("IRONGOLEM_WALK", "ENTITY_IRONGOLEM_STEP", "ENTITY_IRON_GOLEM_STEP"),
MAGMACUBE_WALK("MAGMACUBE_WALK", "ENTITY_MAGMACUBE_SQUISH", "ENTITY_MAGMA_CUBE_SQUISH"),
MAGMACUBE_WALK2("MAGMACUBE_WALK2", "ENTITY_MAGMACUBE_SQUISH", "ENTITY_MAGMA_CUBE_SQUISH_SMALL"),
MAGMACUBE_JUMP("MAGMACUBE_JUMP", "ENTITY_MAGMACUBE_JUMP", "ENTITY_MAGMA_CUBE_JUMP"),
PIG_IDLE("PIG_IDLE", "ENTITY_PIG_AMBIENT"),
PIG_DEATH("PIG_DEATH", "ENTITY_PIG_DEATH"),
PIG_WALK("PIG_WALK", "ENTITY_PIG_STEP"),
SHEEP_IDLE("SHEEP_IDLE", "ENTITY_SHEEP_AMBIENT"),
SHEEP_SHEAR("SHEEP_SHEAR", "ENTITY_SHEEP_SHEAR"),
SHEEP_WALK("SHEEP_WALK", "ENTITY_SHEEP_STEP"),
SILVERFISH_HIT("SILVERFISH_HIT", "ENTITY_SILVERFISH_HURT"),
SILVERFISH_KILL("SILVERFISH_KILL", "ENTITY_SILVERFISH_DEATH"),
SILVERFISH_IDLE("SILVERFISH_IDLE", "ENTITY_SILVERFISH_AMBIENT"),
SILVERFISH_WALK("SILVERFISH_WALK", "ENTITY_SILVERFISH_STEP"),
SKELETON_IDLE("SKELETON_IDLE", "ENTITY_SKELETON_AMBIENT"),
SKELETON_DEATH("SKELETON_DEATH", "ENTITY_SKELETON_DEATH"),
SKELETON_HURT("SKELETON_HURT", "ENTITY_SKELETON_HURT"),
SKELETON_WALK("SKELETON_WALK", "ENTITY_SKELETON_STEP"),
SLIME_ATTACK("SLIME_ATTACK", "ENTITY_SLIME_ATTACK"),
SLIME_WALK("SLIME_WALK", "ENTITY_SLIME_JUMP"),
SLIME_WALK2("SLIME_WALK2", "ENTITY_SLIME_SQUISH"),
SPIDER_IDLE("SPIDER_IDLE", "ENTITY_SPIDER_AMBIENT"),
SPIDER_DEATH("SPIDER_DEATH", "ENTITY_SPIDER_DEATH"),
SPIDER_WALK("SPIDER_WALK", "ENTITY_SPIDER_STEP"),
WITHER_DEATH("WITHER_DEATH", "ENTITY_WITHER_DEATH"),
WITHER_HURT("WITHER_HURT", "ENTITY_WITHER_HURT"),
WITHER_IDLE("WITHER_IDLE", "ENTITY_WITHER_AMBIENT"),
WITHER_SHOOT("WITHER_SHOOT", "ENTITY_WITHER_SHOOT"),
WITHER_SPAWN("WITHER_SPAWN", "ENTITY_WITHER_SPAWN"),
WOLF_BARK("WOLF_BARK", "ENTITY_WOLF_AMBIENT"),
WOLF_DEATH("WOLF_DEATH", "ENTITY_WOLF_DEATH"),
WOLF_GROWL("WOLF_GROWL", "ENTITY_WOLF_GROWL"),
WOLF_HOWL("WOLF_HOWL", "ENTITY_WOLF_HOWL"),
WOLF_HURT("WOLF_HURT", "ENTITY_WOLF_HURT"),
WOLF_PANT("WOLF_PANT", "ENTITY_WOLF_PANT"),
WOLF_SHAKE("WOLF_SHAKE", "ENTITY_WOLF_SHAKE"),
WOLF_WALK("WOLF_WALK", "ENTITY_WOLF_STEP"),
WOLF_WHINE("WOLF_WHINE", "ENTITY_WOLF_WHINE"),
ZOMBIE_METAL("ZOMBIE_METAL", "ENTITY_ZOMBIE_ATTACK_IRON_DOOR"),
ZOMBIE_WOOD("ZOMBIE_WOOD", "ENTITY_ZOMBIE_ATTACK_DOOR_WOOD", "ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR"),
ZOMBIE_WOODBREAK("ZOMBIE_WOODBREAK", "ENTITY_ZOMBIE_BREAK_DOOR_WOOD", "ENTITY_ZOMBIE_BREAK_WOODEN_DOOR"),
ZOMBIE_IDLE("ZOMBIE_IDLE", "ENTITY_ZOMBIE_AMBIENT"),
ZOMBIE_DEATH("ZOMBIE_DEATH", "ENTITY_ZOMBIE_DEATH"),
ZOMBIE_HURT("ZOMBIE_HURT", "ENTITY_ZOMBIE_HURT"),
ZOMBIE_INFECT("ZOMBIE_INFECT", "ENTITY_ZOMBIE_INFECT"),
ZOMBIE_UNFECT("ZOMBIE_UNFECT", "ENTITY_ZOMBIE_VILLAGER_CONVERTED"),
ZOMBIE_REMEDY("ZOMBIE_REMEDY", "ENTITY_ZOMBIE_VILLAGER_CURE"),
ZOMBIE_WALK("ZOMBIE_WALK", "ENTITY_ZOMBIE_STEP"),
ZOMBIE_PIG_IDLE("ZOMBIE_PIG_IDLE", "ENTITY_ZOMBIE_PIG_AMBIENT", "ENTITY_ZOMBIE_PIGMAN_AMBIENT"),
ZOMBIE_PIG_ANGRY("ZOMBIE_PIG_ANGRY", "ENTITY_ZOMBIE_PIG_ANGRY", "ENTITY_ZOMBIE_PIGMAN_ANGRY"),
ZOMBIE_PIG_DEATH("ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIGMAN_DEATH"),
ZOMBIE_PIG_HURT("ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIGMAN_HURT"),
DIG_WOOL("DIG_WOOL", "BLOCK_CLOTH_BREAK", "BLOCK_WOOL_BREAK"),
DIG_GRASS("DIG_GRASS", "BLOCK_GRASS_BREAK"),
DIG_GRAVEL("DIG_GRAVEL", "BLOCK_GRAVEL_BREAK"),
DIG_SAND("DIG_SAND", "BLOCK_SAND_BREAK"),
DIG_SNOW("DIG_SNOW", "BLOCK_SNOW_BREAK"),
DIG_STONE("DIG_STONE", "BLOCK_STONE_BREAK"),
DIG_WOOD("DIG_WOOD", "BLOCK_WOOD_BREAK"),
FIREWORK_BLAST("FIREWORK_BLAST", "ENTITY_FIREWORK_BLAST", "ENTITY_FIREWORK_ROCKET_BLAST"),
FIREWORK_BLAST2("FIREWORK_BLAST2", "ENTITY_FIREWORK_BLAST_FAR", "ENTITY_FIREWORK_ROCKET_BLAST_FAR"),
FIREWORK_LARGE_BLAST("FIREWORK_LARGE_BLAST", "ENTITY_FIREWORK_LARGE_BLAST", "ENTITY_FIREWORK_ROCKET_LARGE_BLAST"),
FIREWORK_LARGE_BLAST2("FIREWORK_LARGE_BLAST2", "ENTITY_FIREWORK_LARGE_BLAST_FAR", "ENTITY_FIREWORK_ROCKET_LARGE_BLAST_FAR"),
FIREWORK_LAUNCH("FIREWORK_LAUNCH", "ENTITY_FIREWORK_LAUNCH", "ENTITY_FIREWORK_ROCKET_LAUNCH"),
FIREWORK_TWINKLE("FIREWORK_TWINKLE", "ENTITY_FIREWORK_TWINKLE", "ENTITY_FIREWORK_ROCKET_TWINKLE"),
FIREWORK_TWINKLE2("FIREWORK_TWINKLE2", "ENTITY_FIREWORK_TWINKLE_FAR", "ENTITY_FIREWORK_ROCKET_TWINKLE_FAR"),
SUCCESSFUL_HIT("SUCCESSFUL_HIT", "ENTITY_PLAYER_ATTACK_STRONG"),
HORSE_ANGRY("HORSE_ANGRY", "ENTITY_HORSE_ANGRY"),
HORSE_ARMOR("HORSE_ARMOR", "ENTITY_HORSE_ARMOR"),
HORSE_BREATHE("HORSE_BREATHE", "ENTITY_HORSE_BREATHE"),
HORSE_DEATH("HORSE_DEATH", "ENTITY_HORSE_DEATH"),
HORSE_GALLOP("HORSE_GALLOP", "ENTITY_HORSE_GALLOP"),
HORSE_HIT("HORSE_HIT", "ENTITY_HORSE_HURT"),
HORSE_IDLE("HORSE_IDLE", "ENTITY_HORSE_AMBIENT"),
HORSE_JUMP("HORSE_JUMP", "ENTITY_HORSE_JUMP"),
HORSE_LAND("HORSE_LAND", "ENTITY_HORSE_LAND"),
HORSE_SADDLE("HORSE_SADDLE", "ENTITY_HORSE_SADDLE"),
HORSE_SOFT("HORSE_SOFT", "ENTITY_HORSE_STEP"),
HORSE_WOOD("HORSE_WOOD", "ENTITY_HORSE_STEP_WOOD"),
DONKEY_ANGRY("DONKEY_ANGRY", "ENTITY_DONKEY_ANGRY"),
DONKEY_DEATH("DONKEY_DEATH", "ENTITY_DONKEY_DEATH"),
DONKEY_HIT("DONKEY_HIT", "ENTITY_DONKEY_HURT"),
DONKEY_IDLE("DONKEY_IDLE", "ENTITY_DONKEY_AMBIENT"),
HORSE_SKELETON_DEATH("HORSE_SKELETON_DEATH", "ENTITY_SKELETON_HORSE_DEATH"),
HORSE_SKELETON_HIT("HORSE_SKELETON_HIT", "ENTITY_SKELETON_HORSE_HURT"),
HORSE_SKELETON_IDLE("HORSE_SKELETON_IDLE", "ENTITY_SKELETON_HORSE_AMBIENT"),
HORSE_ZOMBIE_DEATH("HORSE_ZOMBIE_DEATH", "ENTITY_ZOMBIE_HORSE_DEATH"),
HORSE_ZOMBIE_HIT("HORSE_ZOMBIE_HIT", "ENTITY_ZOMBIE_HORSE_HURT"),
HORSE_ZOMBIE_IDLE("HORSE_ZOMBIE_IDLE", "ENTITY_ZOMBIE_HORSE_AMBIENT"),
VILLAGER_DEATH("VILLAGER_DEATH", "ENTITY_VILLAGER_DEATH"),
VILLAGER_TRADE("VILLAGER_HAGGLE", "ENTITY_VILLAGER_TRADING", "ENTITY_VILLAGER_TRADE"),
VILLAGER_HIT("VILLAGER_HIT", "ENTITY_VILLAGER_HURT"),
VILLAGER_IDLE("VILLAGER_IDLE", "ENTITY_VILLAGER_AMBIENT"),
VILLAGER_NO("VILLAGER_NO", "ENTITY_VILLAGER_NO"),
VILLAGER_YES("VILLAGER_YES", "ENTITY_VILLAGER_YES");
private final String[] versionname;
private Sound cached = null;
SoundUtils(String... versionname) {
this.versionname = versionname;
}
public Sound bukkitSound() {
if (cached != null)
return cached;
for (String name : versionname) {
try {
return cached = Sound.valueOf(name);
} catch (Exception ignore) {
}
}
System.out.println(Methods.format("&cFailed to find the sound enum called " + cached + "."));
return null;
}
public static void playSound(Player player, String sound, int pitch) {
if (!sound.isEmpty()) {
player.playSound(player.getLocation(), SoundUtils.valueOf(sound).bukkitSound(), Integer.MAX_VALUE, pitch);
}
}
}

View File

@ -1,10 +0,0 @@
package com.songoda.epicvouchers.utils;
public class Tuple<X, Y> {
public final X x;
public final Y y;
public Tuple(X x, Y y) {
this.x = x;
this.y = y;
}
}

View File

@ -15,13 +15,13 @@ public class CoolDownManager {
this.instance = instance;
}
void addCooldown(final UUID uuid, Voucher voucher) {
void addCoolDown(final UUID uuid, Voucher voucher) {
if (Bukkit.getPlayer(uuid).hasPermission("epicvouchers.bypass")) {
return;
}
if (voucher.getCooldown() != 0) {
entries.put(uuid, System.currentTimeMillis() + voucher.getCooldown() * 1000);
if (voucher.getCoolDown() != 0) {
entries.put(uuid, System.currentTimeMillis() + voucher.getCoolDown() * 1000);
} else {
entries.put(uuid, System.currentTimeMillis() + instance.getConfig().getInt("Main.Cooldown Delay") * 1000);
}

View File

@ -1,14 +1,18 @@
package com.songoda.epicvouchers.voucher;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.events.ForceRedeemEvent;
import com.songoda.epicvouchers.events.VoucherReceiveEvent;
import com.songoda.epicvouchers.utils.Methods;
import lombok.Getter;
import lombok.Setter;
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;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -20,51 +24,55 @@ import java.util.stream.Collectors;
import static com.songoda.epicvouchers.utils.Methods.format;
import static org.bukkit.Material.PAPER;
@Getter
@Setter
@Accessors(chain = true)
public class Voucher {
@Getter private final String key;
@Getter @Setter private String permission = "";
@Getter @Setter private Material material = PAPER;
@Getter @Setter private short data = 0;
@Getter @Setter private int cooldown = 0;
@Setter private String name;
@Setter private List<String> lore = new ArrayList<>();
@Getter @Setter private boolean glow = true;
@Getter @Setter private boolean confirm = true;
@Getter @Setter private boolean unbreakable = false;
@Getter @Setter private boolean hideAttributes = false;
@Getter @Setter private boolean removeItem = true;
@Getter @Setter private boolean feedPlayer = false;
@Getter @Setter private boolean healPlayer = false;
@Getter @Setter private boolean smiteEffect = false;
private final String key;
private final EpicVouchers instance;
private String permission = "";
private Material material = PAPER;
private short data = 0;
private int coolDown = 0;
private String name;
private List<String> lore = new ArrayList<>();
private boolean glow = true;
private boolean confirm = true;
private boolean unbreakable = false;
private boolean hideAttributes = false;
private boolean removeItem = true;
private boolean feedPlayer = false;
private boolean healPlayer = false;
private boolean smiteEffect = false;
@Setter private List<String> broadcasts = new ArrayList<>();
@Setter private List<String> messages = new ArrayList<>();
@Setter @Getter private List<String> commands = new ArrayList<>();
private List<String> broadcasts = new ArrayList<>();
private List<String> messages = new ArrayList<>();
private List<String> commands = new ArrayList<>();
@Setter private String actionBar;
private String actionBar;
@Setter private String title = "";
@Setter private String subTitle = "";
@Getter @Setter private int titleFadeIn = 0;
@Getter @Setter private int titleStay = 0;
@Getter @Setter private int titleFadeOut = 0;
private String title = "";
private String subTitle = "";
private int titleFadeIn = 0;
private int titleStay = 0;
private int titleFadeOut = 0;
@Getter @Setter private String sound = "";
@Getter @Setter private int soundPitch = 0;
private String sound = "";
private int soundPitch = 0;
@Getter @Setter private String particle = "";
@Getter @Setter private int particleAmount = 0;
private String particle = "";
private int particleAmount = 0;
@Getter @Setter private String effect = "";
@Getter @Setter private int effectAmplifier = 0;
@Getter @Setter private int effectDuration = 0;
private String effect = "";
private int effectAmplifier = 0;
private int effectDuration = 0;
@Getter @Setter private ItemStack itemStack;
private ItemStack itemStack;
public Voucher(String key) {
public Voucher(String key, EpicVouchers instance) {
this.key = key;
this.instance = instance;
}
public ItemStack toItemStack() {
@ -75,11 +83,11 @@ public class Voucher {
ItemStack item = itemStack == null ? new ItemStack(material, amount, data) : itemStack;
ItemMeta meta = item.getItemMeta();
if(meta == null) {
if (meta == null) {
meta = Bukkit.getItemFactory().getItemMeta(material);
}
if(!name.isEmpty()) {
if (!name.isEmpty()) {
meta.setDisplayName(format(name));
}
@ -121,9 +129,9 @@ public class Voucher {
}
public void saveSetting(String key, Object value) {
ConfigurationSection cs = EpicVouchers.getInstance().getVouchersFile().getConfig().getConfigurationSection("vouchers." + getKey());
ConfigurationSection cs = instance.getVouchersFile().getConfig().getConfigurationSection("vouchers." + getKey());
cs.set(key, value);
EpicVouchers.getInstance().getVouchersFile().saveConfig();
instance.getVouchersFile().saveConfig();
}
@Override
@ -131,6 +139,52 @@ public class Voucher {
return key;
}
public void giveAll(CommandSender sender, int amount) {
give(sender, new ArrayList<>(Bukkit.getOnlinePlayers()), amount);
}
public void give(CommandSender sender, List<Player> players, int amount) {
String giveMessage = instance.getLocale().getMessage("command.give.send")
.replaceAll("%player%", players.size() == 1 ? players.get(0).getName() : "everyone")
.replaceAll("%voucher%", getName(true))
.replaceAll("%amount%", String.valueOf(amount));
for (Player player : players) {
String receiveMessage = instance.getLocale().getMessage("command.give.receive")
.replaceAll("%voucher%", getName(true))
.replaceAll("%player%", player.getName())
.replaceAll("%amount%", String.valueOf(amount));
VoucherReceiveEvent event = new VoucherReceiveEvent(player, getName(true), toItemStack(amount), amount, sender);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
sender.sendMessage(instance.getLocale().getMessage("command.give.cancelled"));
continue;
}
player.sendMessage(receiveMessage);
player.getInventory().addItem(toItemStack(amount));
}
sender.sendMessage(giveMessage);
}
public void forceRedeem(CommandSender sender, List<Player> players, int amount) {
for (Player player : players) {
ForceRedeemEvent event = new ForceRedeemEvent(player, getName(true), amount, sender);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || player.equals(sender)) {
continue;
}
for (int i = 0; i < amount; i++) {
instance.getVoucherExecutor().redeemVoucher(player, this, player.getItemInHand(), false, null);
}
}
}
public String getActionBar() {
return format(actionBar);
}

View File

@ -2,18 +2,19 @@ package com.songoda.epicvouchers.voucher;
import com.songoda.epicvouchers.EpicVouchers;
import com.songoda.epicvouchers.events.VoucherRedeemEvent;
import com.songoda.epicvouchers.libraries.Bountiful;
import com.songoda.epicvouchers.libraries.BountifulAPI;
import com.songoda.epicvouchers.listeners.PlayerCommandListener;
import com.songoda.epicvouchers.utils.Debugger;
import com.songoda.epicvouchers.utils.Methods;
import com.songoda.epicvouchers.utils.SoundUtils;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.Nullable;
import java.util.logging.Level;
@ -24,32 +25,42 @@ public class VoucherExecutor {
this.instance = instance;
}
public void redeemVoucher(Player player, Voucher voucher, ItemStack item, boolean manual) {
public void redeemVoucher(Player player, Voucher voucher, ItemStack item, boolean manual, @Nullable PlayerInteractEvent event) {
try {
VoucherRedeemEvent event = new VoucherRedeemEvent(player, voucher.getName(true), item, manual);
Bukkit.getServer().getPluginManager().callEvent(event);
VoucherRedeemEvent redeemEvent = new VoucherRedeemEvent(player, voucher.getName(true), item, manual);
Bukkit.getServer().getPluginManager().callEvent(redeemEvent);
if (event.isCancelled()) {
if (redeemEvent.isCancelled()) {
return;
}
boolean duplication = false;
int slot = player.getInventory().getHeldItemSlot();
if (!player.getItemInHand().isSimilar(item)) {
duplication = true;
if (event != null) {
slot = event.getPlayer().getInventory().getHeldItemSlot();
try {
if (event.getHand() == EquipmentSlot.OFF_HAND) slot = 40;
} catch (Exception | Error ignore) {
}
if (player.getInventory().getItem(slot) != null && !player.getInventory().getItem(slot).isSimilar(item)) {
duplication = true;
}
}
if (!duplication) {
if (manual) {
instance.getCooldowns().addCooldown(player.getUniqueId(), voucher);
instance.getCoolDowns().addCoolDown(player.getUniqueId(), voucher);
if (voucher.isRemoveItem()) {
ItemStack clone = player.getItemInHand().clone();
ItemStack clone = item.clone();
if (clone.getAmount() <= 1) {
clone.setType(Material.AIR);
clone = null;
} else {
clone.setAmount(clone.getAmount() - 1);
}
player.setItemInHand(clone);
player.getInventory().setItem(slot, clone);
player.updateInventory();
}
}
@ -112,7 +123,7 @@ public class VoucherExecutor {
}
if (voucher.getActionBar() != null && !voucher.getActionBar().isEmpty()) {
String actionbar = voucher.getActionBar().replaceAll("%player%", name).replaceAll("%voucher%", voucher.getName(true));
Bountiful.sendActionBar(player, actionbar);
BountifulAPI.sendActionBar(player, actionbar);
}
if (voucher.getTitle() != null && !voucher.getTitle().isEmpty()) {
@ -123,20 +134,17 @@ public class VoucherExecutor {
int stay = voucher.getTitleStay();
int fadeout = voucher.getTitleFadeOut();
Bountiful.sendTitle(player, fadein, stay, fadeout, title, subtitle);
BountifulAPI.sendTitle(player, fadein, stay, fadeout, title, subtitle);
}
if (voucher.getSound() != null && !voucher.getSound().isEmpty()) {
String sound = voucher.getSound();
int pitch = voucher.getSoundPitch();
SoundUtils.playSound(player, sound, pitch);
player.getWorld().playSound(player.getLocation(), Sound.valueOf(voucher.getSound()), Integer.MAX_VALUE, voucher.getSoundPitch());
}
String particle = voucher.getParticle();
if (particle != null && !particle.isEmpty()) {
int amount = voucher.getParticleAmount();
player.getWorld().playEffect(player.getLocation(), Effect.valueOf(particle), amount);
player.getWorld().playEffect(player.getLocation(), Effect.valueOf(particle), voucher.getParticleAmount());
}
String effect = voucher.getEffect();
@ -153,9 +161,8 @@ public class VoucherExecutor {
instance.getLogger().log(Level.WARNING, Methods.format("&c" + player.getName() + " has failed to duplicate the voucher " + voucher.getKey() + "."));
}
} catch (Exception error) {
error.printStackTrace();
instance.getLogger().log(Level.SEVERE, Methods.format("&cFailed to redeem the voucher " + voucher.getKey() + " for the player " + player.getName() + "."));
Debugger.runReport(error);
instance.getLogger().log(Level.SEVERE, error.getMessage());
}
}

View File

@ -5,20 +5,21 @@ general.nametag.prefix= "&8[&6EpicVouchers&8] "
#Interface Messages
interface.confirmsettings.title= "&6Confirmation"
interface.confirmsettings.confirmitemname= "&2&lREDEEM"
interface.confirmsettings.confirmitemlore= "&aClick here if you want to confirm your redeem."
interface.confirmsettings.confirmitemname= "&2&lCONFIRM"
interface.confirmsettings.confirmitemlore= "&aClick here if you want to confirm your action."
interface.confirmsettings.cancelitemname= "&4&lCANCEL"
interface.confirmsettings.cancelitemlore= "&cClick here if you want to cancel your redeem."
interface.confirmsettings.cancelitemlore= "&cClick here if you want to cancel your action."
#Command Messages
command.error.noplayer= "&7That user either does not exist or is not online";
command.error.noplayer= "&7That user either does not exist or is not online"
command.error.novoucher= "&cThat voucher does not exist.";
command.error.notexist= "&7The command you entered does not exist or is spelt incorrectly."
command.error.notnumber= "&7Failed to parse that number into a valid amount."
command.reload.success= "&7Reloaded all config files and vouchers."
command.give.send= "&7You have received the voucher &6%voucher% &7(&6x%amount%&7)."
command.give.receive= "&7You have given &6%player% &7the voucher &6%voucher% &7(&6x%amount%&7)."
command.give.send= "&7You have given &6%player% &7the voucher &6%voucher% &7(&6x%amount%&7)."
command.give.receive= "&7You have received the voucher &6%voucher% &7(&6x%amount%&7)."
command.give.cancelled= "&cEvent got cancelled."
command.force.send= "&7You have forced &6%player% &7to redeem the voucher &6%voucher% &7(&6x%amount%&7).";
command.list.list= "&7List of all vouchers: &6%list%&7."

View File

@ -4,8 +4,4 @@ version: ${project.version}
author: Songoda
website: https://songoda.host/epicvouchers
description: Enhance your server with awesome customizable vouchers with a lot of features.
api-version: 1.13
commands:
epicvouchers:
description: Administrator commands for the EpicVouchers resource.
aliases: [dv, deluxev, dvouchers, deluxevoucher, ev, vouchers, voucher]
api-version: 1.13

View File

@ -1,54 +1,54 @@
vouchers:
example:
permission: "epicvouchers.example"
material: "COOKIE"
# Keep data on 0 if you are on 1.13 or higher.
data: 0
name: "&6Example Voucher"
lore:
- "&eThank you so much for purchasing"
- "&emy resource EpicVouchers."
- "&eListen to the wise words that"
- "&ethis nice cookie will tell you."
- ""
- "&cWhat could be inside this voucher?"
- "&6- Songoda"
glow: true
confirm: true
unbreakable: true
hide-attributes: false
remove-item: true
feed-player: true
heal-player: true
smite-effect: true
# Enter a custom cooldown if you wish to.
cooldown: 0
broadcasts:
- "&6&l> &e%player% has redeemed the voucher &6%voucher%&e. &6&l<"
- "&cUseful addons: [chat] [player], and [op]."
- "&cDo not add them to let the console execute it."
messages:
- "&bYou have redeemed the voucher &6%voucher% &bsuccessfully."
commands:
- "give %player% stick 1"
- "[chat]I love EpicVouchers!"
# You can use [chat], [player] and [op].
# Also use [delay-10] for 10 seconds delay.
# Change 10 to any number you want to have.
actionbar: "&6Actionbar works on every version."
titles:
title: "&6Thank you."
subtitle: "&eYou have redeemed the voucher %voucher%."
fade-in: 10
stay: 50
fade-out: 10
sounds:
sound: "NOTE_PLING"
pitch: 1
particles:
particle: "FLAME"
amount: 100
effects:
effect: "SPEED"
amplifier: 2
duration: 10
example:
permission: "epicvouchers.example"
material: "COOKIE"
# Keep data on 0 if you are on 1.13 or higher.
data: 0
name: "&6Example Voucher"
lore:
- "&eThank you so much for purchasing"
- "&emy resource EpicVouchers."
- "&eListen to the wise words that"
- "&ethis nice cookie will tell you."
- ""
- "&cWhat could be inside this voucher?"
- "&6- Songoda"
glow: true
confirm: true
unbreakable: true
hide-attributes: false
remove-item: true
feed-player: true
heal-player: true
smite-effect: true
# Enter a custom coolDown if you wish to.
cooldown: 0
broadcasts:
- "&6&l> &e%player% has redeemed the voucher &6%voucher%&e. &6&l<"
- "&cUseful addons: [chat] [player], and [op]."
- "&cDo not add them to let the console execute it."
messages:
- "&bYou have redeemed the voucher &6%voucher% &bsuccessfully."
commands:
- "give %player% stick 1"
- "[chat]I love EpicVouchers!"
# You can use [chat], [player] and [op].
# Also use [delay-10] for 10 seconds delay.
# Change 10 to any number you want to have.
actionbar: "&6Actionbar works on every version."
titles:
title: "&6Thank you."
subtitle: "&eYou have redeemed the voucher %voucher%."
fade-in: 10
stay: 50
fade-out: 10
sounds:
sound: "BLOCK_NOTE_BLOCK_PLING"
pitch: 1
particles:
particle: "MOBSPAWNER_FLAMES"
amount: 100
effects:
effect: "SPEED"
amplifier: 2
duration: 10