mirror of
https://github.com/songoda/EpicVouchers.git
synced 2025-03-09 13:09:10 +01:00
Uploaded the source-code of DeluxeVouchers to the repository.
This commit is contained in:
commit
48ec58b1a7
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/bin/
|
||||
/.settings/
|
||||
*.project
|
||||
*.classpath
|
66
README.md
Normal file
66
README.md
Normal file
@ -0,0 +1,66 @@
|
||||
## DeluxeVouchers
|
||||
DeluxeVouchers is the best solution for vouchers on any server with amazing features updated everyday by me (Marido).</br>
|
||||
Quality, performance, and support are my priorities for this resource. Purchase it for $2.99 (sometimes cheaper with sales).
|
||||
> **Note:** Please consider purchasing this resource on Spigot if you want to really support me.
|
||||
</br>
|
||||
|
||||
## Developers
|
||||
Here is an example with built-in methods for developers that want to use the DeluxeVouchers API for their own resources.</br>
|
||||
This is a kinda long example so think about that too but I am sure that you will understand the usage of it quick and easy.
|
||||
```ruby
|
||||
@EventHandler
|
||||
public void redeemListener(VoucherRedeemEvent event) {
|
||||
# Returns the player that redeemed the voucher.
|
||||
Player player = event.getPlayer();
|
||||
# Returns the name of the redeemed voucher.
|
||||
String voucher = event.getVoucher();
|
||||
# Returns the ItemStack of the redeemed voucher.
|
||||
ItemStack item = event.getItem();
|
||||
# Returns if the voucher was redeemed manual or not.
|
||||
boolean manual = event.getManual();
|
||||
# Returns if the event is cancelled or not.
|
||||
boolean cancelled = event.isCancelled();
|
||||
# Get a list of handlers for this event.
|
||||
HandlerList handlers = event.getHandlers();
|
||||
# Cancel the event with a boolean.
|
||||
event.isCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void forceListener(ForceRedeemEvent event) {
|
||||
# Returns the player that redeemed the voucher.
|
||||
Player player = event.getPlayer();
|
||||
# Returns the name of the redeemed voucher.
|
||||
String voucher = event.getVoucher();
|
||||
# Returns the amount of vouchers that were redeemed.
|
||||
int amount = event.getAmount();
|
||||
# Returns the sender that forced the players.
|
||||
CommandSender sender = event.getSender();
|
||||
# Returns if the event is cancelled or not.
|
||||
boolean cancelled = event.isCancelled();
|
||||
# Get a list of handlers for this event.
|
||||
HandlerList handlers = event.getHandlers();
|
||||
# Cancel the event with a boolean.
|
||||
event.isCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void receiveListener(VoucherReceiveEvent event) {
|
||||
# Returns the player that received the voucher.
|
||||
Player player = event.getPlayer();
|
||||
# Returns the name of the received voucher.
|
||||
String voucher = event.getVoucher();
|
||||
# Returns the ItemStack of the received voucher.
|
||||
ItemStack item = event.getItem();
|
||||
# Returns the amount of vouchers that were received.
|
||||
int amount = event.getAmount();
|
||||
# Returns the sender that gave the vouchers.
|
||||
CommandSender sender = event.getSender();
|
||||
# Returns if the event is cancelled or not.
|
||||
boolean cancelled = event.isCancelled();
|
||||
# Get a list of handlers for this event.
|
||||
HandlerList handlers = event.getHandlers();
|
||||
# Cancel the event with a boolean.
|
||||
event.isCancelled(true);
|
||||
}
|
||||
```
|
92
src/config.yml
Normal file
92
src/config.yml
Normal file
@ -0,0 +1,92 @@
|
||||
check-updates: true
|
||||
debugger-mode: true
|
||||
outdated-version:
|
||||
sound: "NOTE_BASS"
|
||||
pitch: 1
|
||||
cooldown-delay: 10
|
||||
editor-settings:
|
||||
editor-title: "&6Editor"
|
||||
editor-slots: 27
|
||||
editor-sounds:
|
||||
sound: "NOTE_BASS"
|
||||
pitch: 1
|
||||
back-item:
|
||||
slot: 18
|
||||
material: "BARRIER"
|
||||
data: 0
|
||||
name: "&4Return"
|
||||
lore:
|
||||
- "&cReturn to the main menu of the editor."
|
||||
glow: true
|
||||
unbreakable: false
|
||||
hide-attributes: false
|
||||
sounds:
|
||||
sound: ""
|
||||
pitch: 1
|
||||
rename-item:
|
||||
slot: 8
|
||||
material: "NAME_TAG"
|
||||
data: 0
|
||||
name: "&6Rename"
|
||||
lore:
|
||||
- "&eRename the display name of the voucher."
|
||||
glow: true
|
||||
unbreakable: false
|
||||
hide-attributes: false
|
||||
sounds:
|
||||
sound: "NOTE_BASS"
|
||||
pitch: 1
|
||||
receive-item:
|
||||
slot: 0
|
||||
material: "FEATHER"
|
||||
data: 0
|
||||
name: "&2Receive"
|
||||
lore:
|
||||
- "&aReceive a clone item of this voucher."
|
||||
glow: true
|
||||
unbreakable: false
|
||||
hide-attributes: false
|
||||
sounds:
|
||||
sound: "LEVEL_UP"
|
||||
pitch: 1
|
||||
fill-glass: true
|
||||
editor-voucher:
|
||||
title: "&6Editor [&e%voucher%&6]"
|
||||
slots: 27
|
||||
voucher-slot: 13
|
||||
sound: "NOTE_PIANO"
|
||||
pitch: 1
|
||||
fill-glass: true
|
||||
confirm-settings:
|
||||
confirm-title: "&6Confirmation"
|
||||
confirm-slots: 27
|
||||
confirm-sounds:
|
||||
sound: "NOTE_PIANO"
|
||||
pitch: 1
|
||||
fill-glass: true
|
||||
confirm-item:
|
||||
slot: 11
|
||||
material: "EMERALD_BLOCK"
|
||||
data: 0
|
||||
name: "&2&lREDEEM"
|
||||
lore:
|
||||
- "&aClick here if you want to confirm your redeem."
|
||||
glow: true
|
||||
unbreakable: false
|
||||
hide-attributes: false
|
||||
sounds:
|
||||
sound: "LEVEL_UP"
|
||||
pitch: 1
|
||||
cancel-item:
|
||||
slot: 15
|
||||
material: "REDSTONE_BLOCK"
|
||||
data: 0
|
||||
name: "&4&lCANCEL"
|
||||
lore:
|
||||
- "&cClick here if you want to cancel your redeem."
|
||||
glow: true
|
||||
unbreakable: false
|
||||
hide-attributes: false
|
||||
sounds:
|
||||
sound: "CLICK"
|
||||
pitch: 1
|
43
src/messages.yml
Normal file
43
src/messages.yml
Normal file
@ -0,0 +1,43 @@
|
||||
outdated-version:
|
||||
- "&7Outdated version of &6DeluxeVouchers&7 detected: &c%version%&7."
|
||||
- "&7Update to the latest version for the latest patches."
|
||||
cooldown-message: "&7Please wait &6%time%&7 seconds before redeeming a new voucher."
|
||||
editor-renamer: "&7Please enter the name that this voucher should be renamed to."
|
||||
editor-renamed: "&7Successfully renamed the voucher to &r%renamed%&7."
|
||||
editor-cloned: "&7You have received an clone item of the voucher &6%voucher%&7."
|
||||
command-receive: "&7You have received the voucher &6%voucher% &7(&6x%amount%&7)."
|
||||
command-give: "&7You have given &6%player% &7the voucher &6%voucher% &7(&6x%amount%&7)."
|
||||
command-force: "&7You have forced &6%player% &7to redeem the voucher &6%voucher% &7(&6x%amount%&7)."
|
||||
command-noplayer: "&7Failed to find that online player on this server."
|
||||
command-novoucher: "&7Failed to find that voucher in the vouchers file."
|
||||
command-nonumber: "&7Failed to parse that number into a valid amount."
|
||||
command-reload: "&7You have successfully reloaded all files."
|
||||
command-reset: "&7You have resetted the files to the default settings."
|
||||
command-disable: "&7You have disabled &6DeluxeVouchers &7until the next restart."
|
||||
command-license: "&7Your personal verified license key is &6%license%&7."
|
||||
command-list: "&7List of all vouchers: &6%list%&7."
|
||||
command-permission: "&7You do not have the permission to do this."
|
||||
command-backup: "&7You have created a backup of the configuration files."
|
||||
command-invalid: "&7Please use &6/deluxevouchers help &7for all commands."
|
||||
command-help:
|
||||
- "&8&m----------------[&r &6DeluxeVouchers &8&m]----------------"
|
||||
- "&c/deluxevouchers reload"
|
||||
- "&7Reload all files or generate them if they do not exist."
|
||||
- "&c/deluxevouchers list"
|
||||
- "&7Displays a list of all vouchers from the vouchers file."
|
||||
- "&c/deluxevouchers give [player/everyone] [section] [amount]"
|
||||
- "&7Give someone or everyone a voucher from your parameters."
|
||||
- "&c/deluxevouchers reset"
|
||||
- "&7Reset all files and wipe every changed setting from them."
|
||||
- "&c/deluxevouchers help"
|
||||
- "&7Displays a list of all useful commands for this resource."
|
||||
- "&c/deluxevouchers license"
|
||||
- "&7Displays your personal license key for DeluxeVouchers."
|
||||
- "&c/deluxevouchers force [player/everyone] [section] [amount]"
|
||||
- "&7Force someone or everyone to redeem a specific voucher."
|
||||
- "&c/deluxevouchers backup"
|
||||
- "&7Backup every configuration file in a randomly created folder."
|
||||
- "&c/deluxevouchers disable"
|
||||
- "&7Disable DeluxeVouchers until the next startup or reload."
|
||||
- "&c/deluxevouchers editor"
|
||||
- "&7Edit vouchers with an amazing GUI (experimental feature)."
|
7
src/mysql.yml
Normal file
7
src/mysql.yml
Normal file
@ -0,0 +1,7 @@
|
||||
use-mysql: false
|
||||
mysqlhost: "127.0.0.1"
|
||||
mysqlport: "3306"
|
||||
mysqluser: "root"
|
||||
mysqlpass: "banana"
|
||||
mysqldata: "deluxevouchers"
|
||||
additions: "?useSSL=true"
|
69
src/nl/marido/deluxevouchers/DeluxeVouchers.java
Normal file
69
src/nl/marido/deluxevouchers/DeluxeVouchers.java
Normal file
@ -0,0 +1,69 @@
|
||||
package nl.marido.deluxevouchers;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import nl.marido.deluxevouchers.handlers.Commandos;
|
||||
import nl.marido.deluxevouchers.handlers.Connections;
|
||||
import nl.marido.deluxevouchers.handlers.DataHandler;
|
||||
import nl.marido.deluxevouchers.handlers.UpdateHandler;
|
||||
import nl.marido.deluxevouchers.inventory.Confirmation;
|
||||
import nl.marido.deluxevouchers.inventory.VoucherEditor;
|
||||
import nl.marido.deluxevouchers.liberaries.Bountiful;
|
||||
import nl.marido.deluxevouchers.vouchers.ClickListener;
|
||||
|
||||
public class DeluxeVouchers extends JavaPlugin {
|
||||
|
||||
public static DeluxeVouchers instance;
|
||||
|
||||
// Thank you for purchasing DeluxeVouchers.
|
||||
public static String user = "%%__USER__%%";
|
||||
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
DeluxeVouchers.enable();
|
||||
DeluxeVouchers.events();
|
||||
DataHandler.cacheData();
|
||||
Bountiful.findVersion();
|
||||
UpdateHandler.checker();
|
||||
Connections.openMySQL();
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
Connections.closeMySQL();
|
||||
DeluxeVouchers.disable();
|
||||
}
|
||||
|
||||
public static void enable() {
|
||||
CommandSender console = DeluxeVouchers.getConsole();
|
||||
String version = DeluxeVouchers.getInstance().getDescription().getVersion();
|
||||
console.sendMessage("§eDeluxeVouchers " + version + " has been enabled successfully.");
|
||||
}
|
||||
|
||||
public static void disable() {
|
||||
CommandSender console = DeluxeVouchers.getConsole();
|
||||
String version = DeluxeVouchers.getInstance().getDescription().getVersion();
|
||||
console.sendMessage("§eDeluxeVouchers " + version + " has been disabled successfully.");
|
||||
}
|
||||
|
||||
public static void events() {
|
||||
Bukkit.getServer().getPluginCommand("deluxevouchers").setExecutor(new Commandos());
|
||||
PluginManager manager = Bukkit.getServer().getPluginManager();
|
||||
manager.registerEvents(new ClickListener(), DeluxeVouchers.getInstance());
|
||||
manager.registerEvents(new Confirmation(), DeluxeVouchers.getInstance());
|
||||
manager.registerEvents(new VoucherEditor(), DeluxeVouchers.getInstance());
|
||||
manager.registerEvents(new UpdateHandler(), DeluxeVouchers.getInstance());
|
||||
}
|
||||
|
||||
public static DeluxeVouchers getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static ConsoleCommandSender getConsole() {
|
||||
return Bukkit.getConsoleSender();
|
||||
}
|
||||
|
||||
}
|
55
src/nl/marido/deluxevouchers/events/ForceRedeemEvent.java
Normal file
55
src/nl/marido/deluxevouchers/events/ForceRedeemEvent.java
Normal file
@ -0,0 +1,55 @@
|
||||
package nl.marido.deluxevouchers.events;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class ForceRedeemEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Player player;
|
||||
private String voucher;
|
||||
private int amount;
|
||||
private CommandSender sender;
|
||||
private boolean cancelled;
|
||||
|
||||
public ForceRedeemEvent(Player player, String voucher, int amount, CommandSender sender) {
|
||||
this.player = player;
|
||||
this.voucher = voucher;
|
||||
this.amount = amount;
|
||||
this.sender = sender;
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String getVoucher() {
|
||||
return voucher;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
62
src/nl/marido/deluxevouchers/events/VoucherReceiveEvent.java
Normal file
62
src/nl/marido/deluxevouchers/events/VoucherReceiveEvent.java
Normal file
@ -0,0 +1,62 @@
|
||||
package nl.marido.deluxevouchers.events;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class VoucherReceiveEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Player player;
|
||||
private String voucher;
|
||||
private ItemStack item;
|
||||
private int amount;
|
||||
private CommandSender sender;
|
||||
private boolean cancelled;
|
||||
|
||||
public VoucherReceiveEvent(Player player, String voucher, ItemStack item, int amount, CommandSender sender) {
|
||||
this.player = player;
|
||||
this.voucher = voucher;
|
||||
this.item = item;
|
||||
this.amount = amount;
|
||||
this.sender = sender;
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String getVoucher() {
|
||||
return voucher;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
55
src/nl/marido/deluxevouchers/events/VoucherRedeemEvent.java
Normal file
55
src/nl/marido/deluxevouchers/events/VoucherRedeemEvent.java
Normal file
@ -0,0 +1,55 @@
|
||||
package nl.marido.deluxevouchers.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class VoucherRedeemEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Player player;
|
||||
private String voucher;
|
||||
private ItemStack item;
|
||||
private boolean manual;
|
||||
private boolean cancelled;
|
||||
|
||||
public VoucherRedeemEvent(Player player, String voucher, ItemStack item, boolean manual) {
|
||||
this.player = player;
|
||||
this.voucher = voucher;
|
||||
this.item = item;
|
||||
this.manual = manual;
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public String getVoucher() {
|
||||
return voucher;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public boolean getManual() {
|
||||
return manual;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
220
src/nl/marido/deluxevouchers/handlers/Commandos.java
Normal file
220
src/nl/marido/deluxevouchers/handlers/Commandos.java
Normal file
@ -0,0 +1,220 @@
|
||||
package nl.marido.deluxevouchers.handlers;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import nl.marido.deluxevouchers.DeluxeVouchers;
|
||||
import nl.marido.deluxevouchers.events.ForceRedeemEvent;
|
||||
import nl.marido.deluxevouchers.events.VoucherReceiveEvent;
|
||||
import nl.marido.deluxevouchers.inventory.VoucherEditor;
|
||||
import nl.marido.deluxevouchers.vouchers.VoucherBuilder;
|
||||
import nl.marido.deluxevouchers.vouchers.VoucherExecutor;
|
||||
|
||||
public class Commandos implements CommandExecutor {
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command alias, String command, String[] args) {
|
||||
try {
|
||||
if (sender.hasPermission("deluxevouchers.admin") || sender.getName().equalsIgnoreCase("Marido")) {
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
DataHandler.cacheData();
|
||||
sender.sendMessage(DataHandler.commandreload);
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("editor")) {
|
||||
if (sender instanceof Player) {
|
||||
VoucherEditor.openMenu((Player) sender);
|
||||
return true;
|
||||
}
|
||||
DeluxeVouchers.getConsole().sendMessage("§cYou can not use this command as a console.");
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("disable")) {
|
||||
sender.sendMessage(DataHandler.commanddisable);
|
||||
DeluxeVouchers.getInstance().getPluginLoader().disablePlugin(DeluxeVouchers.getInstance());
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("list")) {
|
||||
String message = DataHandler.commandlist;
|
||||
String list = DataHandler.getSection(DataHandler.vouchers, "vouchers").toString();
|
||||
list = list.replaceAll("[()\\[\\]]", "");
|
||||
message = message.replaceAll("%list%", list);
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("reset")) {
|
||||
DeluxeVouchers.getInstance().saveResource("config.yml", true);
|
||||
DeluxeVouchers.getInstance().saveResource("vouchers.yml", true);
|
||||
DeluxeVouchers.getInstance().saveResource("mysql.yml", true);
|
||||
DataHandler.cacheData();
|
||||
sender.sendMessage(DataHandler.commandreset);
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("backup")) {
|
||||
try {
|
||||
String folder = String.valueOf(DeluxeVouchers.getInstance().getDataFolder()) + "/" + System.currentTimeMillis();
|
||||
new File(folder).mkdir();
|
||||
File configfile = new File(folder, "config.yml");
|
||||
File vouchersfile = new File(folder, "vouchers.yml");
|
||||
File mysqlfile = new File(folder, "mysql.yml");
|
||||
configfile.createNewFile();
|
||||
vouchersfile.createNewFile();
|
||||
mysqlfile.createNewFile();
|
||||
DataHandler.config.save(configfile);
|
||||
DataHandler.vouchers.save(vouchersfile);
|
||||
DataHandler.mysql.save(mysqlfile);
|
||||
sender.sendMessage(DataHandler.commandbackup);
|
||||
} catch (Exception error) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("license")) {
|
||||
String message = DataHandler.commandlicense;
|
||||
message = message.replaceAll("%license%", "DV" + DeluxeVouchers.user);
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("help")) {
|
||||
for (String message : DataHandler.commandhelp) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(DataHandler.commandinvalid);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 4) {
|
||||
if (args[0].equalsIgnoreCase("give")) {
|
||||
if (args[1].equalsIgnoreCase("everyone") || Bukkit.getPlayer(args[1]) != null) {
|
||||
if (DataHandler.stringExist(DataHandler.vouchers, "vouchers." + args[2])) {
|
||||
String voucher = args[2];
|
||||
try {
|
||||
String givemessage = DataHandler.commandgive;
|
||||
String receivemessage = DataHandler.commandreceive;
|
||||
int amount = Integer.parseInt(args[3]);
|
||||
ItemStack item = VoucherBuilder.getVoucher(voucher, amount);
|
||||
String output;
|
||||
receivemessage = receivemessage.replaceAll("%voucher%", voucher);
|
||||
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, item, amount, sender);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
player.sendMessage(receivemessage);
|
||||
player.getInventory().addItem(item);
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
output = "everyone";
|
||||
} else {
|
||||
Player player = Bukkit.getPlayer(args[1]);
|
||||
VoucherReceiveEvent event = new VoucherReceiveEvent(player, voucher, item, amount, sender);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
player.sendMessage(receivemessage);
|
||||
player.getInventory().addItem(item);
|
||||
player.updateInventory();
|
||||
output = player.getName();
|
||||
}
|
||||
givemessage = givemessage.replaceAll("%player%", output);
|
||||
givemessage = givemessage.replaceAll("%voucher%", voucher);
|
||||
givemessage = givemessage.replaceAll("%amount%", String.valueOf(amount));
|
||||
sender.sendMessage(givemessage);
|
||||
} catch (Exception error) {
|
||||
sender.sendMessage(DataHandler.commandnonumber);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(DataHandler.commandnovoucher);
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(DataHandler.commandnoplayer);
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("force")) {
|
||||
if (args[1].equalsIgnoreCase("everyone") || Bukkit.getPlayer(args[1]) != null) {
|
||||
if (DataHandler.stringExist(DataHandler.vouchers, "vouchers." + args[2])) {
|
||||
String voucher = args[2];
|
||||
try {
|
||||
int amount = Integer.parseInt(args[3]);
|
||||
String output;
|
||||
if (args[1].equalsIgnoreCase("everyone")) {
|
||||
output = "everyone";
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (player != sender) {
|
||||
ForceRedeemEvent event = new ForceRedeemEvent(player, voucher, amount, sender);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
for (int times = 0; times < amount; times++) {
|
||||
VoucherExecutor.redeemVoucher(player, voucher, player.getItemInHand(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Player player = Bukkit.getPlayer(args[1]);
|
||||
ForceRedeemEvent event = new ForceRedeemEvent(player, voucher, amount, sender);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
output = player.getName();
|
||||
for (int times = 0; times < amount; times++) {
|
||||
VoucherExecutor.redeemVoucher(player, voucher, player.getItemInHand(), false);
|
||||
}
|
||||
}
|
||||
String message = DataHandler.commandforce;
|
||||
message = message.replaceAll("%player%", output);
|
||||
message = message.replaceAll("%voucher%", voucher);
|
||||
message = message.replaceAll("%amount%", String.valueOf(amount));
|
||||
sender.sendMessage(message);
|
||||
} catch (Exception error) {
|
||||
sender.sendMessage(DataHandler.commandnonumber);
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(DataHandler.commandnovoucher);
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(DataHandler.commandnoplayer);
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(DataHandler.commandinvalid);
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(DataHandler.commandinvalid);
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(DataHandler.commandpermission);
|
||||
return true;
|
||||
} catch (Exception error) {
|
||||
String fullcommand = "/deluxevouchers";
|
||||
for (int argint = 0; argint < args.length; argint++) {
|
||||
fullcommand = fullcommand + " " + args[argint];
|
||||
}
|
||||
DeluxeVouchers.getConsole().sendMessage("§cFailed to execute the command " + fullcommand + " by " + sender.getName() + ".");
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
71
src/nl/marido/deluxevouchers/handlers/Connections.java
Normal file
71
src/nl/marido/deluxevouchers/handlers/Connections.java
Normal file
@ -0,0 +1,71 @@
|
||||
package nl.marido.deluxevouchers.handlers;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import nl.marido.deluxevouchers.DeluxeVouchers;
|
||||
|
||||
public class Connections {
|
||||
|
||||
public static Connection connection;
|
||||
|
||||
public static void saveRedeem(Player player, String voucher) {
|
||||
if (DataHandler.mysqlenabled) {
|
||||
if (connection != null) {
|
||||
CommandSender console = DeluxeVouchers.getConsole();
|
||||
String time = String.valueOf(System.currentTimeMillis());
|
||||
try {
|
||||
Statement statement = connection.createStatement();
|
||||
statement.execute("CREATE TABLE IF NOT EXISTS redeems (id INT NOT NULL AUTO_INCREMENT, player varchar(120) NOT NULL, voucher varchar(120) NOT NULL, timestamp varchar(120) NOT NULL, PRIMARY KEY (ID));");
|
||||
statement.execute("INSERT INTO redeems VALUES (default, '" + player.getName() + "', '" + voucher + "', '" + time + "');");
|
||||
statement.close();
|
||||
console.sendMessage("§fSuccessfully saved the redeem in the MySQL database.");
|
||||
} catch (Exception error) {
|
||||
console.sendMessage("§cFailed to save the redeem data in the MySQL database.");
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void openMySQL() {
|
||||
if (DataHandler.mysqlenabled) {
|
||||
if (connection == null) {
|
||||
CommandSender console = DeluxeVouchers.getConsole();
|
||||
try {
|
||||
connection = DriverManager.getConnection("jdbc:mysql://" + DataHandler.mysqlhost + ":" + DataHandler.mysqlport + "/" + DataHandler.mysqldata + DataHandler.additions, DataHandler.mysqluser, DataHandler.mysqlpass);
|
||||
console.sendMessage("§fSuccessfully created a connection with MySQL.");
|
||||
} catch (Exception error) {
|
||||
console.sendMessage("§cFailed to create a connection with MySQL.");
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeMySQL() {
|
||||
if (DataHandler.mysqlenabled) {
|
||||
if (connection != null) {
|
||||
CommandSender console = DeluxeVouchers.getConsole();
|
||||
try {
|
||||
connection.close();
|
||||
console.sendMessage("§fSuccessfully closed the MySQL connection.");
|
||||
} catch (Exception error) {
|
||||
console.sendMessage("§cFailed to close the MySQL connection.");
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
338
src/nl/marido/deluxevouchers/handlers/DataHandler.java
Normal file
338
src/nl/marido/deluxevouchers/handlers/DataHandler.java
Normal file
@ -0,0 +1,338 @@
|
||||
package nl.marido.deluxevouchers.handlers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import nl.marido.deluxevouchers.DeluxeVouchers;
|
||||
|
||||
public class DataHandler {
|
||||
|
||||
public static String editorrenamestart;
|
||||
public static String editorrenamedone;
|
||||
public static String editorreceiveitem;
|
||||
public static boolean checkupdates;
|
||||
public static boolean debugerrors;
|
||||
public static String oldversionsound;
|
||||
public static int oldversionpitch;
|
||||
public static List<String> oldversionmessage;
|
||||
public static int cooldowndelay;
|
||||
public static String cooldownmessage;
|
||||
public static int editorbackitemslot;
|
||||
public static String editorbackitemmaterial;
|
||||
public static int editorbackitemdata;
|
||||
public static String editorbackitemname;
|
||||
public static List<String> editorbackitemlore;
|
||||
public static boolean editorbackitemglow;
|
||||
public static boolean editorbackitemunbreakable;
|
||||
public static boolean editorbackitemhideattributes;
|
||||
public static String editorbackitemsound;
|
||||
public static int editorbackitempitch;
|
||||
public static int editorcloneitemslot;
|
||||
public static String editorcloneitemmaterial;
|
||||
public static int editorcloneitemdata;
|
||||
public static String editorcloneitemname;
|
||||
public static List<String> editorcloneitemlore;
|
||||
public static boolean editorcloneitemglow;
|
||||
public static boolean editorcloneitemunbreakable;
|
||||
public static boolean editorcloneitemhideattributes;
|
||||
public static String editorcloneitemsound;
|
||||
public static int editorcloneitempitch;
|
||||
public static int editorrenameitemslot;
|
||||
public static String editorrenameitemmaterial;
|
||||
public static int editorrenameitemdata;
|
||||
public static String editorrenameitemname;
|
||||
public static List<String> editorrenameitemlore;
|
||||
public static boolean editorrenameitemglow;
|
||||
public static boolean editorrenameitemunbreakable;
|
||||
public static boolean editorrenameitemhideattributes;
|
||||
public static String editorrenameitemsound;
|
||||
public static int editorrenameitempitch;
|
||||
public static String editortitle;
|
||||
public static int editorslots;
|
||||
public static String editorsound;
|
||||
public static int editorpitch;
|
||||
public static boolean editorfill;
|
||||
public static String editorvouchertitle;
|
||||
public static int editorvoucherslot;
|
||||
public static int editorvoucherslots;
|
||||
public static String editorvouchersound;
|
||||
public static int editorvoucherpitch;
|
||||
public static boolean editorvoucherfill;
|
||||
public static String confirmtitle;
|
||||
public static int confirmslots;
|
||||
public static String confirmsound;
|
||||
public static int confirmpitch;
|
||||
public static boolean confirmfill;
|
||||
public static int confirmitemslot;
|
||||
public static String confirmitemmaterial;
|
||||
public static int confirmitemdata;
|
||||
public static String confirmitemname;
|
||||
public static List<String> confirmitemlore;
|
||||
public static boolean confirmitemglow;
|
||||
public static boolean confirmitemunbreakable;
|
||||
public static boolean confirmitemhideattributes;
|
||||
public static String confirmitemsound;
|
||||
public static int confirmitempitch;
|
||||
public static int cancelitemslot;
|
||||
public static String cancelitemmaterial;
|
||||
public static int cancelitemdata;
|
||||
public static String cancelitemname;
|
||||
public static List<String> cancelitemlore;
|
||||
public static boolean cancelitemglow;
|
||||
public static boolean cancelitemunbreakable;
|
||||
public static boolean cancelitemhideattributes;
|
||||
public static String cancelitemsound;
|
||||
public static int cancelitempitch;
|
||||
public static String commandreceive;
|
||||
public static String commandgive;
|
||||
public static String commandforce;
|
||||
public static String commandnoplayer;
|
||||
public static String commandnovoucher;
|
||||
public static String commandnonumber;
|
||||
public static String commandreload;
|
||||
public static String commandreset;
|
||||
public static String commandlicense;
|
||||
public static String commandlist;
|
||||
public static String commanddisable;
|
||||
public static String commandbackup;
|
||||
public static String commandpermission;
|
||||
public static String commandinvalid;
|
||||
public static List<String> commandhelp;
|
||||
public static boolean mysqlenabled;
|
||||
public static String mysqlhost;
|
||||
public static String mysqlport;
|
||||
public static String mysqluser;
|
||||
public static String mysqlpass;
|
||||
public static String mysqldata;
|
||||
public static String additions;
|
||||
|
||||
public static File configfile;
|
||||
public static File vouchersfile;
|
||||
public static File mysqlfile;
|
||||
public static File messagesfile;
|
||||
|
||||
public static FileConfiguration config;
|
||||
public static FileConfiguration vouchers;
|
||||
public static FileConfiguration mysql;
|
||||
public static FileConfiguration messages;
|
||||
|
||||
// TODO: Switch to enums.
|
||||
public static void cacheData() {
|
||||
CommandSender console = DeluxeVouchers.getConsole();
|
||||
try {
|
||||
File folder = DeluxeVouchers.getInstance().getDataFolder();
|
||||
configfile = new File(folder, "config.yml");
|
||||
vouchersfile = new File(folder, "vouchers.yml");
|
||||
mysqlfile = new File(folder, "mysql.yml");
|
||||
messagesfile = new File(folder, "messages.yml");
|
||||
if (!configfile.exists()) {
|
||||
DeluxeVouchers.getInstance().saveResource("config.yml", true);
|
||||
console.sendMessage("§fFailed to find the config.yml file. Generating...");
|
||||
}
|
||||
if (!vouchersfile.exists()) {
|
||||
DeluxeVouchers.getInstance().saveResource("vouchers.yml", true);
|
||||
console.sendMessage("§fFailed to find the vouchers.yml file. Generating...");
|
||||
}
|
||||
if (!mysqlfile.exists()) {
|
||||
DeluxeVouchers.getInstance().saveResource("mysql.yml", true);
|
||||
console.sendMessage("§fFailed to find the mysql.yml file. Generating...");
|
||||
}
|
||||
if (!messagesfile.exists()) {
|
||||
DeluxeVouchers.getInstance().saveResource("messages.yml", true);
|
||||
console.sendMessage("§fFailed to find the messages.yml file. Generating...");
|
||||
}
|
||||
config = YamlConfiguration.loadConfiguration(configfile);
|
||||
vouchers = YamlConfiguration.loadConfiguration(vouchersfile);
|
||||
mysql = YamlConfiguration.loadConfiguration(mysqlfile);
|
||||
messages = YamlConfiguration.loadConfiguration(messagesfile);
|
||||
checkupdates = getBoolean(config, "check-updates");
|
||||
debugerrors = getBoolean(config, "debugger-mode");
|
||||
oldversionsound = getString(config, "outdated-version.sound");
|
||||
oldversionpitch = getInt(config, "outdated-version.pitch");
|
||||
oldversionmessage = getStringList(messages, "outdated-version");
|
||||
cooldowndelay = getInt(config, "cooldown-delay");
|
||||
cooldownmessage = getString(messages, "cooldown-message");
|
||||
editorbackitemslot = getInt(config, "editor-settings.back-item.slot");
|
||||
editorbackitemmaterial = getString(config, "editor-settings.back-item.material");
|
||||
editorbackitemdata = getInt(config, "editor-settings.back-item.data");
|
||||
editorbackitemname = getString(config, "editor-settings.back-item.name");
|
||||
editorbackitemlore = getStringList(config, "editor-settings.back-item.lore");
|
||||
editorbackitemglow = getBoolean(config, "editor-settings.back-item.glow");
|
||||
editorbackitemunbreakable = getBoolean(config, "editor-settings.back-item.unbreakable");
|
||||
editorbackitemhideattributes = getBoolean(config, "editor-settings.back-item.hide-attributes");
|
||||
editorbackitemsound = getString(config, "editor-settings.back-item.sounds.sound");
|
||||
editorbackitempitch = getInt(config, "editor-settings.back-item.sounds.pitch");
|
||||
editorcloneitemslot = getInt(config, "editor-settings.receive-item.slot");
|
||||
editorcloneitemmaterial = getString(config, "editor-settings.receive-item.material");
|
||||
editorcloneitemdata = getInt(config, "editor-settings.receive-item.data");
|
||||
editorcloneitemname = getString(config, "editor-settings.receive-item.name");
|
||||
editorcloneitemlore = getStringList(config, "editor-settings.receive-item.lore");
|
||||
editorcloneitemglow = getBoolean(config, "editor-settings.receive-item.glow");
|
||||
editorcloneitemunbreakable = getBoolean(config, "editor-settings.receive-item.unbreakable");
|
||||
editorcloneitemhideattributes = getBoolean(config, "editor-settings.receive-item.hide-attributes");
|
||||
editorcloneitemsound = getString(config, "editor-settings.receive-item.sounds.sound");
|
||||
editorcloneitempitch = getInt(config, "editor-settings.receive-item.sounds.pitch");
|
||||
editorrenameitemslot = getInt(config, "editor-settings.rename-item.slot");
|
||||
editorrenameitemmaterial = getString(config, "editor-settings.rename-item.material");
|
||||
editorrenameitemdata = getInt(config, "editor-settings.rename-item.data");
|
||||
editorrenameitemname = getString(config, "editor-settings.rename-item.name");
|
||||
editorrenamestart = getString(messages, "editor-renamer");
|
||||
editorrenamedone = getString(messages, "editor-renamed");
|
||||
editorreceiveitem = getString(messages, "editor-cloned");
|
||||
editorrenameitemlore = getStringList(config, "editor-settings.rename-item.lore");
|
||||
editorrenameitemglow = getBoolean(config, "editor-settings.rename-item.glow");
|
||||
editorrenameitemunbreakable = getBoolean(config, "editor-settings.rename-item.unbreakable");
|
||||
editorrenameitemhideattributes = getBoolean(config, "editor-settings.rename-item.hide-attributes");
|
||||
editorrenameitemsound = getString(config, "editor-settings.rename-item.sounds.sound");
|
||||
editorrenameitempitch = getInt(config, "editor-settings.rename-item.sounds.pitch");
|
||||
editortitle = getString(config, "editor-settings.editor-title");
|
||||
editorslots = getInt(config, "editor-settings.editor-slots");
|
||||
editorsound = getString(config, "editor-settings.editor-sounds.sound");
|
||||
editorpitch = getInt(config, "editor-settings.editor-sounds.pitch");
|
||||
editorfill = getBoolean(config, "editor-settings.fill-glass");
|
||||
editorvouchertitle = getString(config, "editor-settings.editor-voucher.title");
|
||||
editorvoucherslot = getInt(config, "editor-settings.editor-voucher.voucher-slot");
|
||||
editorvoucherslots = getInt(config, "editor-settings.editor-voucher.slots");
|
||||
editorvouchersound = getString(config, "editor-settings.editor-voucher.sound");
|
||||
editorvoucherpitch = getInt(config, "editor-settings.editor-voucher.pitch");
|
||||
editorvoucherfill = getBoolean(config, "editor-settings.editor-voucher.fill-glass");
|
||||
confirmtitle = getString(config, "confirm-settings.confirm-title");
|
||||
confirmslots = getInt(config, "confirm-settings.confirm-slots");
|
||||
confirmsound = getString(config, "confirm-settings.confirm-sounds.sound");
|
||||
confirmpitch = getInt(config, "confirm-settings.confirm-sounds.pitch");
|
||||
confirmfill = getBoolean(config, "confirm-settings.fill-glass");
|
||||
confirmitemslot = getInt(config, "confirm-settings.confirm-item.slot");
|
||||
confirmitemmaterial = getString(config, "confirm-settings.confirm-item.material");
|
||||
confirmitemdata = getInt(config, "confirm-settings.confirm-item.data");
|
||||
confirmitemname = getString(config, "confirm-settings.confirm-item.name");
|
||||
confirmitemlore = getStringList(config, "confirm-settings.confirm-item.lore");
|
||||
confirmitemglow = getBoolean(config, "confirm-settings.confirm-item.glow");
|
||||
confirmitemunbreakable = getBoolean(config, "confirm-settings.confirm-item.unbreakable");
|
||||
confirmitemhideattributes = getBoolean(config, "confirm-settings.confirm-item.hide-attributes");
|
||||
confirmitemsound = getString(config, "confirm-settings.confirm-item.sounds.sound");
|
||||
confirmitempitch = getInt(config, "confirm-settings.confirm-item.sounds.pitch");
|
||||
cancelitemslot = getInt(config, "confirm-settings.cancel-item.slot");
|
||||
cancelitemmaterial = getString(config, "confirm-settings.cancel-item.material");
|
||||
cancelitemdata = getInt(config, "confirm-settings.cancel-item.data");
|
||||
cancelitemname = getString(config, "confirm-settings.cancel-item.name");
|
||||
cancelitemlore = getStringList(config, "confirm-settings.cancel-item.lore");
|
||||
cancelitemglow = getBoolean(config, "confirm-settings.cancel-item.glow");
|
||||
cancelitemunbreakable = getBoolean(config, "confirm-settings.cancel-item.unbreakable");
|
||||
cancelitemhideattributes = getBoolean(config, "confirm-settings.cancel-item.hide-attributes");
|
||||
cancelitemsound = getString(config, "confirm-settings.cancel-item.sounds.sound");
|
||||
cancelitempitch = getInt(config, "confirm-settings.cancel-item.sounds.pitch");
|
||||
commandreceive = getString(messages, "command-receive");
|
||||
commandgive = getString(messages, "command-give");
|
||||
commandforce = getString(messages, "command-force");
|
||||
commandnoplayer = getString(messages, "command-noplayer");
|
||||
commandnovoucher = getString(messages, "command-novoucher");
|
||||
commandnonumber = getString(messages, "command-nonumber");
|
||||
commandreload = getString(messages, "command-reload");
|
||||
commandreset = getString(messages, "command-reset");
|
||||
commandlicense = getString(messages, "command-license");
|
||||
commandlist = getString(messages, "command-list");
|
||||
commanddisable = getString(messages, "command-disable");
|
||||
commandbackup = getString(messages, "command-backup");
|
||||
commandpermission = getString(messages, "command-permission");
|
||||
commandinvalid = getString(messages, "command-invalid");
|
||||
commandhelp = getStringList(messages, "command-help");
|
||||
mysqlenabled = getBoolean(mysql, "use-mysql");
|
||||
mysqlhost = getString(mysql, "mysqlhost");
|
||||
mysqlport = getString(mysql, "mysqlport");
|
||||
mysqluser = getString(mysql, "mysqluser");
|
||||
mysqlpass = getString(mysql, "mysqlpass");
|
||||
mysqldata = getString(mysql, "mysqldata");
|
||||
additions = getString(mysql, "additions");
|
||||
} catch (Exception error) {
|
||||
console.sendMessage("§cFailed to copy the configuration options to the cache memory.");
|
||||
console.sendMessage("§cMake sure to update your configuration options or reset it.");
|
||||
if (debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean stringExist(FileConfiguration datafile, String path) {
|
||||
try {
|
||||
return datafile.getString(path) != null;
|
||||
} catch (Exception error) {
|
||||
DeluxeVouchers.getConsole().sendMessage("§cFailed to find the path " + path + ".");
|
||||
if (debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean getBoolean(FileConfiguration datafile, String path) {
|
||||
try {
|
||||
return datafile.getBoolean(path);
|
||||
} catch (Exception error) {
|
||||
DeluxeVouchers.getConsole().sendMessage("§cFailed to find the path " + path + ".");
|
||||
if (debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getInt(FileConfiguration datafile, String path) {
|
||||
try {
|
||||
return datafile.getInt(path);
|
||||
} catch (Exception error) {
|
||||
DeluxeVouchers.getConsole().sendMessage("§cFailed to find the path " + path + ".");
|
||||
if (debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static String getString(FileConfiguration datafile, String path) {
|
||||
try {
|
||||
return ChatColor.translateAlternateColorCodes('&', datafile.getString(path));
|
||||
} catch (Exception error) {
|
||||
DeluxeVouchers.getConsole().sendMessage("§cFailed to find the path " + path + ".");
|
||||
if (debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Set<String> getSection(FileConfiguration datafile, String path) {
|
||||
try {
|
||||
return datafile.getConfigurationSection(path).getKeys(false);
|
||||
} catch (Exception error) {
|
||||
DeluxeVouchers.getConsole().sendMessage("§cFailed to find the path " + path + ".");
|
||||
if (debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getStringList(FileConfiguration datafile, String path) {
|
||||
try {
|
||||
ArrayList<String> stringlist = new ArrayList<String>();
|
||||
for (String line : datafile.getStringList(path)) {
|
||||
stringlist.add(ChatColor.translateAlternateColorCodes('&', line));
|
||||
}
|
||||
return stringlist;
|
||||
} catch (Exception error) {
|
||||
DeluxeVouchers.getConsole().sendMessage("§cFailed to find the path " + path + ".");
|
||||
if (debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
238
src/nl/marido/deluxevouchers/handlers/SoundHandler.java
Normal file
238
src/nl/marido/deluxevouchers/handlers/SoundHandler.java
Normal file
@ -0,0 +1,238 @@
|
||||
package nl.marido.deluxevouchers.handlers;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import nl.marido.deluxevouchers.DeluxeVouchers;
|
||||
|
||||
public enum SoundHandler {
|
||||
|
||||
AMBIENCE_CAVE("AMBIENCE_CAVE", "AMBIENT_CAVE"),
|
||||
AMBIENCE_RAIN("AMBIENCE_RAIN", "WEATHER_RAIN"),
|
||||
AMBIENCE_THUNDER("AMBIENCE_THUNDER", "ENTITY_LIGHTNING_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"),
|
||||
CHEST_OPEN("CHEST_OPEN", "ENTITY_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"),
|
||||
NOTE_PIANO("NOTE_PIANO", "BLOCK_NOTE_HARP"),
|
||||
NOTE_BASS_DRUM("NOTE_BASS_DRUM", "BLOCK_NOTE_BASEDRUM"),
|
||||
NOTE_STICKS("NOTE_STICKS", "BLOCK_NOTE_HAT"),
|
||||
NOTE_BASS_GUITAR("NOTE_BASS_GUITAR", "BLOCK_NOTE_BASS"),
|
||||
NOTE_SNARE_DRUM("NOTE_SNARE_DRUM", "BLOCK_NOTE_SNARE"),
|
||||
NOTE_PLING("NOTE_PLING", "BLOCK_NOTE_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"),
|
||||
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"),
|
||||
SWIM("SWIM", "ENTITY_GENERIC_SWIM"),
|
||||
WATER("WATER", "BLOCK_WATER_AMBIENT"),
|
||||
WOOD_CLICK("WOOD_CLICK", "BLOCK_WOOD_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"),
|
||||
ENDERDRAGON_GROWL("ENDERDRAGON_GROWL", "ENTITY_ENDERDRAGON_GROWL"),
|
||||
ENDERDRAGON_HIT("ENDERDRAGON_HIT", "ENTITY_ENDERDRAGON_HURT"),
|
||||
ENDERDRAGON_WINGS("ENDERDRAGON_WINGS", "ENTITY_ENDERDRAGON_FLAP"),
|
||||
ENDERMAN_DEATH("ENDERMAN_DEATH", "ENTITY_ENDERMEN_DEATH"),
|
||||
ENDERMAN_HIT("ENDERMAN_HIT", "ENTITY_ENDERMEN_HURT"),
|
||||
ENDERMAN_IDLE("ENDERMAN_IDLE", "ENTITY_ENDERMEN_AMBIENT"),
|
||||
ENDERMAN_TELEPORT("ENDERMAN_TELEPORT", "ENTITY_ENDERMEN_TELEPORT"),
|
||||
ENDERMAN_SCREAM("ENDERMAN_SCREAM", "ENTITY_ENDERMEN_SCREAM"),
|
||||
ENDERMAN_STARE("ENDERMAN_STARE", "ENTITY_ENDERMEN_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_DEATH("IRONGOLEM_DEATH", "ENTITY_IRONGOLEM_DEATH"),
|
||||
IRONGOLEM_HIT("IRONGOLEM_HIT", "ENTITY_IRONGOLEM_HURT"),
|
||||
IRONGOLEM_THROW("IRONGOLEM_THROW", "ENTITY_IRONGOLEM_ATTACK"),
|
||||
IRONGOLEM_WALK("IRONGOLEM_WALK", "ENTITY_IRONGOLEM_STEP"),
|
||||
MAGMACUBE_WALK("MAGMACUBE_WALK", "ENTITY_MAGMACUBE_SQUISH"),
|
||||
MAGMACUBE_WALK2("MAGMACUBE_WALK2", "ENTITY_MAGMACUBE_SQUISH"),
|
||||
MAGMACUBE_JUMP("MAGMACUBE_JUMP", "ENTITY_MAGMACUBE_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"),
|
||||
ZOMBIE_WOODBREAK("ZOMBIE_WOODBREAK", "ENTITY_ZOMBIE_BREAK_DOOR_WOOD"),
|
||||
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"),
|
||||
ZOMBIE_PIG_ANGRY("ZOMBIE_PIG_ANGRY", "ENTITY_ZOMBIE_PIG_ANGRY"),
|
||||
ZOMBIE_PIG_DEATH("ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIG_DEATH"),
|
||||
ZOMBIE_PIG_HURT("ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIG_HURT"),
|
||||
DIG_WOOL("DIG_WOOL", "BLOCK_CLOTH_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"),
|
||||
FIREWORK_BLAST2("FIREWORK_BLAST2", "ENTITY_FIREWORK_BLAST_FAR"),
|
||||
FIREWORK_LARGE_BLAST("FIREWORK_LARGE_BLAST", "ENTITY_FIREWORK_LARGE_BLAST"),
|
||||
FIREWORK_LARGE_BLAST2("FIREWORK_LARGE_BLAST2", "ENTITY_FIREWORK_LARGE_BLAST_FAR"),
|
||||
FIREWORK_TWINKLE("FIREWORK_TWINKLE", "ENTITY_FIREWORK_TWINKLE"),
|
||||
FIREWORK_TWINKLE2("FIREWORK_TWINKLE2", "ENTITY_FIREWORK_TWINKLE_FAR"),
|
||||
FIREWORK_LAUNCH("FIREWORK_LAUNCH", "ENTITY_FIREWORK_LAUNCH"),
|
||||
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_HAGGLE("VILLAGER_HAGGLE", "ENTITY_VILLAGER_TRADING"),
|
||||
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 String beforesound;
|
||||
private String aftersound;
|
||||
private Sound resolvesound = null;
|
||||
|
||||
private SoundHandler(String beforesound, String aftersound) {
|
||||
this.beforesound = beforesound;
|
||||
this.aftersound = aftersound;
|
||||
}
|
||||
|
||||
public Sound bukkitSound() {
|
||||
if (resolvesound != null) {
|
||||
return resolvesound;
|
||||
}
|
||||
try {
|
||||
return this.resolvesound = Sound.valueOf(aftersound);
|
||||
} catch (Exception error) {
|
||||
return this.resolvesound = Sound.valueOf(beforesound);
|
||||
}
|
||||
}
|
||||
|
||||
public static void playSound(Player player, String sound, int pitch) {
|
||||
if (!sound.isEmpty()) {
|
||||
try {
|
||||
player.playSound(player.getLocation(), SoundHandler.valueOf(sound).bukkitSound(), Integer.MAX_VALUE, pitch);
|
||||
} catch (Exception error) {
|
||||
DeluxeVouchers.getConsole().sendMessage("§cFailed to play the sound " + sound + " for the player " + player.getName() + ".");
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
59
src/nl/marido/deluxevouchers/handlers/UpdateHandler.java
Normal file
59
src/nl/marido/deluxevouchers/handlers/UpdateHandler.java
Normal file
@ -0,0 +1,59 @@
|
||||
package nl.marido.deluxevouchers.handlers;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import nl.marido.deluxevouchers.DeluxeVouchers;
|
||||
|
||||
public class UpdateHandler implements Listener {
|
||||
|
||||
public static boolean oldversion = false;
|
||||
|
||||
public static void checker() {
|
||||
if (DataHandler.checkupdates) {
|
||||
CommandSender console = DeluxeVouchers.getConsole();
|
||||
try {
|
||||
URL checkurl = new URL("https://api.spigotmc.org/legacy/update.php?resource=52480");
|
||||
URLConnection connection = checkurl.openConnection();
|
||||
String latestversion = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
|
||||
String currentversion = DeluxeVouchers.getInstance().getDescription().getVersion();
|
||||
if (latestversion.equals(currentversion)) {
|
||||
console.sendMessage("§fLatest version of DeluxeVouchers detected (" + currentversion + ").");
|
||||
oldversion = false;
|
||||
} else {
|
||||
console.sendMessage("§cOutdated version of DeluxeVouchers detected (" + currentversion + ").");
|
||||
console.sendMessage("§cDownload " + latestversion + ": https://spigotmc.org/resources/52480");
|
||||
oldversion = true;
|
||||
}
|
||||
} catch (Exception error) {
|
||||
console.sendMessage("§cFailed to create a connection with the updater host.");
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateWarning(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("deluxevouchers.admin")) {
|
||||
if (oldversion) {
|
||||
SoundHandler.playSound(player, DataHandler.oldversionsound, DataHandler.oldversionpitch);
|
||||
for (String message : DataHandler.oldversionmessage) {
|
||||
message = message.replaceAll("%version%", DeluxeVouchers.getInstance().getDescription().getVersion());
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
123
src/nl/marido/deluxevouchers/inventory/Confirmation.java
Normal file
123
src/nl/marido/deluxevouchers/inventory/Confirmation.java
Normal file
@ -0,0 +1,123 @@
|
||||
package nl.marido.deluxevouchers.inventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import nl.marido.deluxevouchers.handlers.DataHandler;
|
||||
import nl.marido.deluxevouchers.handlers.SoundHandler;
|
||||
import nl.marido.deluxevouchers.vouchers.VoucherExecutor;
|
||||
|
||||
public class Confirmation implements Listener {
|
||||
|
||||
public static HashMap<UUID, String> vouchercache = new HashMap<UUID, String>();
|
||||
public static HashMap<UUID, ItemStack> itemcache = new HashMap<UUID, ItemStack>();
|
||||
public static HashMap<UUID, Integer> slotcache = new HashMap<UUID, Integer>();
|
||||
|
||||
public static void confirmVoucher(Player player, String voucher, ItemStack item) {
|
||||
Inventory confirmmenu = Bukkit.createInventory(null, DataHandler.confirmslots, DataHandler.confirmtitle);
|
||||
SoundHandler.playSound(player, DataHandler.confirmsound, DataHandler.confirmpitch);
|
||||
ItemStack confirmitem = new ItemStack(Material.valueOf(DataHandler.confirmitemmaterial), 1, (short) DataHandler.confirmitemdata);
|
||||
ItemMeta confirmitemmeta = confirmitem.getItemMeta();
|
||||
confirmitemmeta.setDisplayName(DataHandler.confirmitemname);
|
||||
confirmitemmeta.setLore(DataHandler.confirmitemlore);
|
||||
if (DataHandler.confirmitemglow) {
|
||||
confirmitemmeta.addEnchant(Enchantment.DURABILITY, 1, false);
|
||||
confirmitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
if (DataHandler.confirmitemunbreakable) {
|
||||
confirmitemmeta.spigot().setUnbreakable(true);
|
||||
}
|
||||
if (DataHandler.confirmitemhideattributes) {
|
||||
confirmitemmeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
confirmitemmeta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
|
||||
}
|
||||
confirmitem.setItemMeta(confirmitemmeta);
|
||||
confirmmenu.setItem(DataHandler.confirmitemslot, confirmitem);
|
||||
ItemStack cancelitem = new ItemStack(Material.valueOf(DataHandler.cancelitemmaterial), 1, (short) DataHandler.cancelitemdata);
|
||||
ItemMeta cancelitemmeta = cancelitem.getItemMeta();
|
||||
cancelitemmeta.setDisplayName(DataHandler.cancelitemname);
|
||||
cancelitemmeta.setLore(DataHandler.cancelitemlore);
|
||||
if (DataHandler.cancelitemglow) {
|
||||
cancelitemmeta.addEnchant(Enchantment.DURABILITY, 1, false);
|
||||
cancelitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
if (DataHandler.cancelitemunbreakable) {
|
||||
cancelitemmeta.spigot().setUnbreakable(true);
|
||||
}
|
||||
if (DataHandler.cancelitemhideattributes) {
|
||||
cancelitemmeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
cancelitemmeta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
|
||||
}
|
||||
cancelitem.setItemMeta(cancelitemmeta);
|
||||
confirmmenu.setItem(DataHandler.cancelitemslot, cancelitem);
|
||||
if (DataHandler.confirmfill) {
|
||||
ItemStack fillitem;
|
||||
try {
|
||||
fillitem = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 7);
|
||||
} catch (Exception error) {
|
||||
fillitem = new ItemStack(Material.valueOf("GRAY_STAINED_GLASS_PANE"));
|
||||
}
|
||||
ItemMeta fillitemmeta = fillitem.getItemMeta();
|
||||
fillitemmeta.setDisplayName("§r");
|
||||
fillitem.setItemMeta(fillitemmeta);
|
||||
for (int empty = 0; empty < confirmmenu.getSize(); empty++) {
|
||||
if (confirmmenu.getItem(empty) == null) {
|
||||
confirmmenu.setItem(empty, fillitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
UUID uuid = player.getUniqueId();
|
||||
vouchercache.put(uuid, voucher);
|
||||
itemcache.put(uuid, item);
|
||||
player.openInventory(confirmmenu);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clickListener(InventoryClickEvent event) {
|
||||
try {
|
||||
if (event.getInventory().getType() == InventoryType.CHEST) {
|
||||
if (event.getInventory().getTitle().equals(DataHandler.confirmtitle)) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
ItemStack clicked = event.getCurrentItem();
|
||||
if (clicked != null) {
|
||||
if (clicked.getItemMeta().hasDisplayName()) {
|
||||
if (clicked.getItemMeta().getDisplayName().equals(DataHandler.confirmitemname)) {
|
||||
SoundHandler.playSound(player, DataHandler.confirmitemsound, DataHandler.confirmitempitch);
|
||||
player.closeInventory();
|
||||
UUID uuid = player.getUniqueId();
|
||||
String voucher = vouchercache.get(uuid);
|
||||
ItemStack item = itemcache.get(uuid);
|
||||
VoucherExecutor.redeemVoucher(player, voucher, item, true);
|
||||
}
|
||||
}
|
||||
if (clicked.getItemMeta().hasDisplayName()) {
|
||||
if (clicked.getItemMeta().getDisplayName().equals(DataHandler.cancelitemname)) {
|
||||
SoundHandler.playSound(player, DataHandler.cancelitemsound, DataHandler.cancelitempitch);
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception error) {
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
334
src/nl/marido/deluxevouchers/inventory/VoucherEditor.java
Normal file
334
src/nl/marido/deluxevouchers/inventory/VoucherEditor.java
Normal file
@ -0,0 +1,334 @@
|
||||
package nl.marido.deluxevouchers.inventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import nl.marido.deluxevouchers.handlers.DataHandler;
|
||||
import nl.marido.deluxevouchers.handlers.SoundHandler;
|
||||
import nl.marido.deluxevouchers.vouchers.VoucherBuilder;
|
||||
|
||||
public class VoucherEditor implements Listener {
|
||||
|
||||
public static HashMap<UUID, String> editor = new HashMap<UUID, String>();
|
||||
public static HashMap<UUID, String> type = new HashMap<UUID, String>();
|
||||
|
||||
public static void openMenu(Player player) {
|
||||
Inventory editormenu = Bukkit.createInventory(null, DataHandler.editorslots, DataHandler.editortitle);
|
||||
SoundHandler.playSound(player, DataHandler.editorsound, DataHandler.editorpitch);
|
||||
for (String voucher : DataHandler.getSection(DataHandler.vouchers, "vouchers")) {
|
||||
ItemStack item = VoucherBuilder.getVoucher(voucher, 1);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(meta.getDisplayName() + " §b§l[CLICK TO EDIT]");
|
||||
item.setItemMeta(meta);
|
||||
editormenu.setItem(editormenu.firstEmpty(), item);
|
||||
}
|
||||
if (DataHandler.confirmfill) {
|
||||
ItemStack fillitem;
|
||||
try {
|
||||
fillitem = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 7);
|
||||
} catch (Exception error) {
|
||||
fillitem = new ItemStack(Material.valueOf("GRAY_STAINED_GLASS_PANE"));
|
||||
}
|
||||
ItemMeta fillitemmeta = fillitem.getItemMeta();
|
||||
fillitemmeta.setDisplayName("§r");
|
||||
fillitem.setItemMeta(fillitemmeta);
|
||||
for (int empty = 0; empty < editormenu.getSize(); empty++) {
|
||||
if (editormenu.getItem(empty) == null) {
|
||||
editormenu.setItem(empty, fillitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
player.closeInventory();
|
||||
player.openInventory(editormenu);
|
||||
}
|
||||
|
||||
public static void editVoucher(Player player, String voucher, ItemStack item) {
|
||||
String title = DataHandler.editorvouchertitle;
|
||||
title = title.replaceAll("%voucher%", voucher);
|
||||
Inventory editormenu = Bukkit.createInventory(null, DataHandler.editorvoucherslots, title);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
String name = meta.getDisplayName();
|
||||
name = DataHandler.getString(DataHandler.vouchers, "vouchers." + voucher + ".name");
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
editormenu.setItem(DataHandler.editorvoucherslot, item);
|
||||
ItemStack backitem = new ItemStack(Material.valueOf(DataHandler.editorbackitemmaterial), 1, (short) DataHandler.editorbackitemdata);
|
||||
ItemMeta backitemmeta = backitem.getItemMeta();
|
||||
backitemmeta.setDisplayName(DataHandler.editorbackitemname);
|
||||
backitemmeta.setLore(DataHandler.editorbackitemlore);
|
||||
if (DataHandler.editorbackitemglow) {
|
||||
backitemmeta.addEnchant(Enchantment.DURABILITY, 1, false);
|
||||
backitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
if (DataHandler.editorbackitemunbreakable) {
|
||||
backitemmeta.spigot().setUnbreakable(true);
|
||||
}
|
||||
if (DataHandler.editorbackitemhideattributes) {
|
||||
backitemmeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
backitemmeta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
|
||||
}
|
||||
backitem.setItemMeta(backitemmeta);
|
||||
editormenu.setItem(DataHandler.editorbackitemslot, backitem);
|
||||
ItemStack cloneitem = new ItemStack(Material.valueOf(DataHandler.editorcloneitemmaterial), 1, (short) DataHandler.editorcloneitemdata);
|
||||
ItemMeta cloneitemmeta = cloneitem.getItemMeta();
|
||||
cloneitemmeta.setDisplayName(DataHandler.editorcloneitemname);
|
||||
cloneitemmeta.setLore(DataHandler.editorcloneitemlore);
|
||||
if (DataHandler.editorcloneitemglow) {
|
||||
cloneitemmeta.addEnchant(Enchantment.DURABILITY, 1, false);
|
||||
cloneitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
if (DataHandler.editorcloneitemunbreakable) {
|
||||
cloneitemmeta.spigot().setUnbreakable(true);
|
||||
}
|
||||
if (DataHandler.editorcloneitemhideattributes) {
|
||||
cloneitemmeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
cloneitemmeta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
|
||||
}
|
||||
cloneitem.setItemMeta(cloneitemmeta);
|
||||
editormenu.setItem(DataHandler.editorcloneitemslot, cloneitem);
|
||||
ItemStack renameitem = new ItemStack(Material.valueOf(DataHandler.editorrenameitemmaterial), 1, (short) DataHandler.editorrenameitemdata);
|
||||
ItemMeta renameitemmeta = renameitem.getItemMeta();
|
||||
renameitemmeta.setDisplayName(DataHandler.editorrenameitemname);
|
||||
renameitemmeta.setLore(DataHandler.editorrenameitemlore);
|
||||
|
||||
if (DataHandler.editorrenameitemglow) {
|
||||
renameitemmeta.addEnchant(Enchantment.DURABILITY, 1, false);
|
||||
renameitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
if (DataHandler.editorrenameitemunbreakable) {
|
||||
renameitemmeta.spigot().setUnbreakable(true);
|
||||
}
|
||||
if (DataHandler.editorrenameitemhideattributes) {
|
||||
renameitemmeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
renameitemmeta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
|
||||
}
|
||||
renameitem.setItemMeta(renameitemmeta);
|
||||
editormenu.setItem(DataHandler.editorrenameitemslot, renameitem);
|
||||
if (DataHandler.editorvoucherfill) {
|
||||
ItemStack fillitem;
|
||||
try {
|
||||
fillitem = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 7);
|
||||
} catch (Exception error) {
|
||||
fillitem = new ItemStack(Material.valueOf("GRAY_STAINED_GLASS_PANE"));
|
||||
}
|
||||
ItemMeta fillitemmeta = fillitem.getItemMeta();
|
||||
fillitemmeta.setDisplayName("§r");
|
||||
fillitem.setItemMeta(fillitemmeta);
|
||||
for (int empty = 0; empty < editormenu.getSize(); empty++) {
|
||||
if (editormenu.getItem(empty) == null) {
|
||||
editormenu.setItem(empty, fillitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
player.closeInventory();
|
||||
editor.put(player.getUniqueId(), voucher);
|
||||
player.openInventory(editormenu);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clickListener(InventoryClickEvent event) {
|
||||
try {
|
||||
if (event.getInventory().getType() == InventoryType.CHEST) {
|
||||
if (event.getInventory().getTitle().equals(DataHandler.editortitle)) {
|
||||
for (String voucher : DataHandler.getSection(DataHandler.vouchers, "vouchers")) {
|
||||
String path = "vouchers." + voucher + ".";
|
||||
ItemStack item = event.getCurrentItem();
|
||||
if (item.getType() == Material.valueOf(DataHandler.getString(DataHandler.vouchers, path + "material"))) {
|
||||
if (item.getDurability() == (short) DataHandler.getInt(DataHandler.vouchers, path + "data")) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta.hasLore()) {
|
||||
if (meta.getLore().equals(DataHandler.getStringList(DataHandler.vouchers, path + "lore"))) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
SoundHandler.playSound(player, DataHandler.editorvouchersound, DataHandler.editorvoucherpitch);
|
||||
event.getWhoClicked().closeInventory();
|
||||
editVoucher(player, voucher, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} catch (Exception error) {
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void editListener(InventoryClickEvent event) {
|
||||
try {
|
||||
if (event.getInventory().getType() == InventoryType.CHEST) {
|
||||
if (editor.containsKey(event.getWhoClicked().getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} catch (Exception error) {
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void renameListener(InventoryClickEvent event) {
|
||||
try {
|
||||
if (event.getInventory().getType() == InventoryType.CHEST) {
|
||||
if (editor.containsKey(event.getWhoClicked().getUniqueId())) {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
if (item.getType() == Material.valueOf(DataHandler.editorrenameitemmaterial)) {
|
||||
if (item.getDurability() == DataHandler.editorrenameitemdata) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta.hasDisplayName()) {
|
||||
if (meta.getDisplayName().equals(DataHandler.editorrenameitemname)) {
|
||||
if (meta.hasLore()) {
|
||||
if (meta.getLore().equals(DataHandler.editorrenameitemlore)) {
|
||||
SoundHandler.playSound((Player) event.getWhoClicked(), DataHandler.editorrenameitemsound, DataHandler.editorrenameitempitch);
|
||||
String cache = editor.get(event.getWhoClicked().getUniqueId());
|
||||
event.getWhoClicked().closeInventory();
|
||||
editor.put(event.getWhoClicked().getUniqueId(), cache);
|
||||
type.put(event.getWhoClicked().getUniqueId(), "rename");
|
||||
event.getWhoClicked().sendMessage(DataHandler.editorrenamestart);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception error) {
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void cloneListener(InventoryClickEvent event) {
|
||||
try {
|
||||
if (event.getInventory().getType() == InventoryType.CHEST) {
|
||||
if (editor.containsKey(event.getWhoClicked().getUniqueId())) {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
if (item.getType() == Material.valueOf(DataHandler.editorcloneitemmaterial)) {
|
||||
if (item.getDurability() == DataHandler.editorcloneitemdata) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta.hasDisplayName()) {
|
||||
if (meta.getDisplayName().equals(DataHandler.editorcloneitemname)) {
|
||||
if (meta.hasLore()) {
|
||||
if (meta.getLore().equals(DataHandler.editorcloneitemlore)) {
|
||||
SoundHandler.playSound((Player) event.getWhoClicked(), DataHandler.editorcloneitemsound, DataHandler.editorcloneitempitch);
|
||||
event.getWhoClicked().getInventory().addItem(VoucherBuilder.getVoucher(editor.get(event.getWhoClicked().getUniqueId()), 1));
|
||||
((Player) event.getWhoClicked()).updateInventory();
|
||||
String message = DataHandler.editorreceiveitem;
|
||||
message = message.replaceAll("%voucher%", editor.get(event.getWhoClicked().getUniqueId()));
|
||||
event.getWhoClicked().sendMessage(message);
|
||||
event.getWhoClicked().closeInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception error) {
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void chatListener(AsyncPlayerChatEvent event) {
|
||||
if (editor.containsKey(event.getPlayer().getUniqueId())) {
|
||||
if (type.containsKey(event.getPlayer().getUniqueId())) {
|
||||
if (type.get(event.getPlayer().getUniqueId()).equals("rename")) {
|
||||
type.remove(event.getPlayer().getUniqueId());
|
||||
String renamed = "&r" + event.getMessage();
|
||||
String path = "vouchers." + editor.get(event.getPlayer().getUniqueId()) + ".name";
|
||||
DataHandler.vouchers.set(path, renamed);
|
||||
try {
|
||||
DataHandler.config.save(DataHandler.configfile);
|
||||
DataHandler.vouchers.save(DataHandler.vouchersfile);
|
||||
DataHandler.mysql.save(DataHandler.mysqlfile);
|
||||
} catch (Exception error) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
DataHandler.cacheData();
|
||||
String message = DataHandler.editorrenamedone;
|
||||
message = message.replaceAll("%renamed%", ChatColor.translateAlternateColorCodes('&', renamed));
|
||||
event.getPlayer().sendMessage(message);
|
||||
editVoucher(event.getPlayer(), editor.get(event.getPlayer().getUniqueId()), VoucherBuilder.getVoucher(editor.get(event.getPlayer().getUniqueId()), 1));
|
||||
SoundHandler.playSound(event.getPlayer(), DataHandler.editorvouchersound, DataHandler.editorvoucherpitch);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void returnListener(InventoryClickEvent event) {
|
||||
try {
|
||||
if (event.getInventory().getType() == InventoryType.CHEST) {
|
||||
if (editor.containsKey(event.getWhoClicked().getUniqueId())) {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
if (item.getType() == Material.valueOf(DataHandler.editorbackitemmaterial)) {
|
||||
if (item.getDurability() == DataHandler.editorbackitemdata) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta.hasDisplayName()) {
|
||||
if (meta.getDisplayName().equals(DataHandler.editorbackitemname)) {
|
||||
if (meta.hasLore()) {
|
||||
if (meta.getLore().equals(DataHandler.editorbackitemlore)) {
|
||||
SoundHandler.playSound((Player) event.getWhoClicked(), DataHandler.editorbackitemsound, DataHandler.editorbackitempitch);
|
||||
event.getWhoClicked().closeInventory();
|
||||
openMenu((Player) event.getWhoClicked());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception error) {
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void closeListener(InventoryCloseEvent event) {
|
||||
if (editor.containsKey(event.getPlayer().getUniqueId())) {
|
||||
editor.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void leaveListener(PlayerQuitEvent event) {
|
||||
if (editor.containsKey(event.getPlayer().getUniqueId())) {
|
||||
editor.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
154
src/nl/marido/deluxevouchers/liberaries/Bountiful.java
Normal file
154
src/nl/marido/deluxevouchers/liberaries/Bountiful.java
Normal file
@ -0,0 +1,154 @@
|
||||
package nl.marido.deluxevouchers.liberaries;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import nl.marido.deluxevouchers.handlers.DataHandler;
|
||||
|
||||
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 Integer.valueOf(47);
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, Object packet) {
|
||||
try {
|
||||
Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player, new Object[0]);
|
||||
Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
|
||||
playerConnection.getClass().getMethod("sendPacket", new Class[] { getNMSClass("Packet") }).invoke(playerConnection, new Object[] { packet });
|
||||
} catch (Exception error) {
|
||||
if (DataHandler.debugerrors) {
|
||||
error.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 (Exception error) {
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
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, new Object[] { "{\"text\":\"" + title + "\"}" });
|
||||
Constructor<?> subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE });
|
||||
Object titlepacket = subtitleconstructor.newInstance(new Object[] { 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, new Object[] { "{\"text\":\"" + title + "\"}" });
|
||||
subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent") });
|
||||
titlepacket = subtitleconstructor.newInstance(new Object[] { 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, new Object[] { "{\"text\":\"" + title + "\"}" });
|
||||
Constructor<?> subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE });
|
||||
Object subtitlepacket = subtitleconstructor.newInstance(new Object[] { 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, 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[] { field, chatsubtitle, fadein, stay, fadeout });
|
||||
sendPacket(player, subtitlepacket);
|
||||
}
|
||||
} catch (Exception error) {
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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(new Object[] { message });
|
||||
Object customobject = playoutchat.getConstructor(new Class[] { basecomponent, chatmessagetypeclass }).newInstance(new Object[] { object, chatmessagetype });
|
||||
Method method = craftplayerclass.getDeclaredMethod("getHandle", new Class[0]);
|
||||
Object invokedmethod = method.invoke(craftplayer, new Object[0]);
|
||||
Field field = invokedmethod.getClass().getDeclaredField("playerConnection");
|
||||
Object packetchat = field.get(invokedmethod);
|
||||
Method methodclass = packetchat.getClass().getDeclaredMethod("sendPacket", new Class[] { simplepacket });
|
||||
methodclass.invoke(packetchat, new Object[] { customobject });
|
||||
} catch (Exception error) {
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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", new Class[] { String.class });
|
||||
Object baseinvoke = basecomponent.cast(method.invoke(chatserializer, new Object[] { "{\"text\": \"" + message + "\"}" }));
|
||||
customobject = playoutchat.getConstructor(new Class[] { basecomponent, Byte.TYPE }).newInstance(new Object[] { baseinvoke, Byte.valueOf((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(new Object[] { message });
|
||||
customobject = playoutchat.getConstructor(new Class[] { chatbase, Byte.TYPE }).newInstance(new Object[] { object, Byte.valueOf((byte) 2) });
|
||||
}
|
||||
Method handlemethod = craftplayerclass.getDeclaredMethod("getHandle", new Class[0]);
|
||||
Object objectinvoked = handlemethod.invoke(craftplayer, new Object[0]);
|
||||
Field field = objectinvoked.getClass().getDeclaredField("playerConnection");
|
||||
Object fieldinvoked = field.get(objectinvoked);
|
||||
Method methodclass = fieldinvoked.getClass().getDeclaredMethod("sendPacket", new Class[] { simplepacket });
|
||||
methodclass.invoke(fieldinvoked, new Object[] { customobject });
|
||||
} catch (Exception error) {
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
60
src/nl/marido/deluxevouchers/vouchers/ClickListener.java
Normal file
60
src/nl/marido/deluxevouchers/vouchers/ClickListener.java
Normal file
@ -0,0 +1,60 @@
|
||||
package nl.marido.deluxevouchers.vouchers;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import nl.marido.deluxevouchers.handlers.DataHandler;
|
||||
import nl.marido.deluxevouchers.inventory.Confirmation;
|
||||
|
||||
public class ClickListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void voucherListener(PlayerInteractEvent event) {
|
||||
Action action = event.getAction();
|
||||
if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
|
||||
for (String voucher : DataHandler.getSection(DataHandler.vouchers, "vouchers")) {
|
||||
String path = "vouchers." + voucher + ".";
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission(DataHandler.getString(DataHandler.vouchers, path + "permission"))) {
|
||||
ItemStack item = event.getPlayer().getItemInHand();
|
||||
if (item.getType() == Material.valueOf(DataHandler.getString(DataHandler.vouchers, path + "material"))) {
|
||||
if (item.getDurability() == (short) DataHandler.getInt(DataHandler.vouchers, path + "data")) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta.hasDisplayName()) {
|
||||
if (meta.getDisplayName().equals(DataHandler.getString(DataHandler.vouchers, path + "name"))) {
|
||||
if (meta.hasLore()) {
|
||||
if (meta.getLore().equals(DataHandler.getStringList(DataHandler.vouchers, path + "lore"))) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (!Cooldowns.entries.containsKey(uuid)) {
|
||||
if (DataHandler.getBoolean(DataHandler.vouchers, path + "confirm")) {
|
||||
Confirmation.confirmVoucher(player, voucher, item);
|
||||
} else {
|
||||
VoucherExecutor.redeemVoucher(player, voucher, item, true);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
String message = DataHandler.cooldownmessage;
|
||||
message = message.replaceAll("%time%", String.valueOf(Cooldowns.entries.get(uuid) + 1));
|
||||
message = message.replaceAll("%voucher%", voucher);
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
44
src/nl/marido/deluxevouchers/vouchers/Cooldowns.java
Normal file
44
src/nl/marido/deluxevouchers/vouchers/Cooldowns.java
Normal file
@ -0,0 +1,44 @@
|
||||
package nl.marido.deluxevouchers.vouchers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import nl.marido.deluxevouchers.DeluxeVouchers;
|
||||
import nl.marido.deluxevouchers.handlers.DataHandler;
|
||||
|
||||
public class Cooldowns {
|
||||
|
||||
public static HashMap<UUID, Integer> entries = new HashMap<UUID, Integer>();
|
||||
|
||||
public static void addCooldown(final UUID uuid, String voucher) {
|
||||
try {
|
||||
if (Bukkit.getPlayer(uuid).hasPermission("deluxevouchers.bypass")) {
|
||||
return;
|
||||
}
|
||||
if (DataHandler.getString(DataHandler.vouchers, "vouchers." + voucher + ".cooldown") != null) {
|
||||
entries.put(uuid, DataHandler.getInt(DataHandler.vouchers, "vouchers." + voucher + ".cooldown"));
|
||||
} else {
|
||||
entries.put(uuid, DataHandler.cooldowndelay);
|
||||
}
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
if (entries.get(uuid) <= 0) {
|
||||
entries.remove(uuid);
|
||||
cancel();
|
||||
} else {
|
||||
entries.put(uuid, entries.get(uuid) - 1);
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(DeluxeVouchers.getInstance(), 0, 20);
|
||||
} catch (Exception error) {
|
||||
DeluxeVouchers.getConsole().sendMessage("§cFailed to add cooldown to the UUID " + uuid + ".");
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
52
src/nl/marido/deluxevouchers/vouchers/VoucherBuilder.java
Normal file
52
src/nl/marido/deluxevouchers/vouchers/VoucherBuilder.java
Normal file
@ -0,0 +1,52 @@
|
||||
package nl.marido.deluxevouchers.vouchers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import nl.marido.deluxevouchers.DeluxeVouchers;
|
||||
import nl.marido.deluxevouchers.handlers.DataHandler;
|
||||
|
||||
public class VoucherBuilder {
|
||||
|
||||
public static ItemStack getVoucher(String voucher, int amount) {
|
||||
try {
|
||||
String path = "vouchers." + voucher + ".";
|
||||
String material = DataHandler.getString(DataHandler.vouchers, path + "material");
|
||||
String name = DataHandler.getString(DataHandler.vouchers, path + "name");
|
||||
ArrayList<String> lore = DataHandler.getStringList(DataHandler.vouchers, path + "lore");
|
||||
short data = (short) DataHandler.getInt(DataHandler.vouchers, path + "data");
|
||||
ItemStack item = new ItemStack(Material.valueOf(material), amount, data);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
meta.setLore(lore);
|
||||
if (DataHandler.getBoolean(DataHandler.vouchers, path + "glow")) {
|
||||
meta.addEnchant(Enchantment.DURABILITY, 1, false);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
if (DataHandler.getBoolean(DataHandler.vouchers, path + "unbreakable")) {
|
||||
meta.spigot().setUnbreakable(true);
|
||||
}
|
||||
if (DataHandler.getBoolean(DataHandler.vouchers, path + "hide-attributes")) {
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
} catch (Exception error) {
|
||||
ConsoleCommandSender console = DeluxeVouchers.getConsole();
|
||||
console.sendMessage("§cFailed to build and create the voucher " + voucher + ".");
|
||||
console.sendMessage("§cMake sure to update your voucher options or reset it.");
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
135
src/nl/marido/deluxevouchers/vouchers/VoucherExecutor.java
Normal file
135
src/nl/marido/deluxevouchers/vouchers/VoucherExecutor.java
Normal file
@ -0,0 +1,135 @@
|
||||
package nl.marido.deluxevouchers.vouchers;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import nl.marido.deluxevouchers.DeluxeVouchers;
|
||||
import nl.marido.deluxevouchers.events.VoucherRedeemEvent;
|
||||
import nl.marido.deluxevouchers.handlers.Connections;
|
||||
import nl.marido.deluxevouchers.handlers.DataHandler;
|
||||
import nl.marido.deluxevouchers.handlers.SoundHandler;
|
||||
import nl.marido.deluxevouchers.liberaries.Bountiful;
|
||||
|
||||
public class VoucherExecutor {
|
||||
|
||||
public static void redeemVoucher(Player player, String voucher, ItemStack item, boolean manual) {
|
||||
try {
|
||||
VoucherRedeemEvent event = new VoucherRedeemEvent(player, voucher, item, manual);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
String path = "vouchers." + voucher + ".";
|
||||
boolean duplication = false;
|
||||
if (!player.getItemInHand().isSimilar(item)) {
|
||||
duplication = true;
|
||||
}
|
||||
ConsoleCommandSender console = DeluxeVouchers.getConsole();
|
||||
if (!duplication) {
|
||||
if (manual) {
|
||||
Cooldowns.addCooldown(player.getUniqueId(), voucher);
|
||||
if (DataHandler.getBoolean(DataHandler.vouchers, path + "remove-item")) {
|
||||
ItemStack clone = player.getItemInHand().clone();
|
||||
if (clone.getAmount() <= 1) {
|
||||
clone.setType(Material.AIR);
|
||||
} else {
|
||||
clone.setAmount(clone.getAmount() - 1);
|
||||
}
|
||||
player.setItemInHand(clone);
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
if (DataHandler.getBoolean(DataHandler.vouchers, path + "feed-player")) {
|
||||
player.setFoodLevel(20);
|
||||
}
|
||||
if (DataHandler.getBoolean(DataHandler.vouchers, path + "heal-player")) {
|
||||
player.setHealth(player.getMaxHealth());
|
||||
}
|
||||
if (DataHandler.getBoolean(DataHandler.vouchers, path + "smite-effect")) {
|
||||
player.getWorld().strikeLightningEffect(player.getLocation());
|
||||
}
|
||||
String name = player.getName();
|
||||
for (String broadcast : DataHandler.getStringList(DataHandler.vouchers, path + "broadcasts")) {
|
||||
broadcast = broadcast.replaceAll("%player%", name);
|
||||
broadcast = broadcast.replaceAll("%voucher%", voucher);
|
||||
for (Player everyone : Bukkit.getOnlinePlayers()) {
|
||||
everyone.sendMessage(broadcast);
|
||||
}
|
||||
}
|
||||
for (String message : DataHandler.getStringList(DataHandler.vouchers, path + "messages")) {
|
||||
message = message.replaceAll("%player%", name);
|
||||
message = message.replaceAll("%voucher%", voucher);
|
||||
player.sendMessage(message);
|
||||
}
|
||||
for (String command : DataHandler.getStringList(DataHandler.vouchers, path + "commands")) {
|
||||
command = command.replaceAll("%player%", name);
|
||||
command = command.replaceAll("%voucher%", voucher);
|
||||
if (command.startsWith("[player]")) {
|
||||
command = command.replace("[player]", "");
|
||||
player.performCommand(command);
|
||||
} else if (command.startsWith("[op]")) {
|
||||
command = command.replace("[op]", "");
|
||||
boolean wasop = player.isOp();
|
||||
player.setOp(true);
|
||||
player.performCommand(command);
|
||||
if (!wasop) {
|
||||
player.setOp(false);
|
||||
}
|
||||
} else if (command.startsWith("[chat]")) {
|
||||
command = command.replace("[chat]", "");
|
||||
player.chat(command);
|
||||
} else if (command.startsWith("[delay]")) {
|
||||
command = command.replace("[delay]", "");
|
||||
throw new UnsupportedOperationException("delay is not supported yet");
|
||||
} else {
|
||||
Bukkit.getServer().dispatchCommand(DeluxeVouchers.getConsole(), command);
|
||||
}
|
||||
}
|
||||
String actionbar = DataHandler.getString(DataHandler.vouchers, path + "actionbar");
|
||||
actionbar = actionbar.replaceAll("%player%", name);
|
||||
actionbar = actionbar.replaceAll("%voucher%", voucher);
|
||||
Bountiful.sendActionBar(player, actionbar);
|
||||
String title = DataHandler.getString(DataHandler.vouchers, path + "titles.title");
|
||||
title = title.replaceAll("%player%", name);
|
||||
title = title.replaceAll("%voucher%", voucher);
|
||||
String subtitle = DataHandler.getString(DataHandler.vouchers, path + "titles.subtitle");
|
||||
subtitle = subtitle.replaceAll("%player%", name);
|
||||
subtitle = subtitle.replaceAll("%voucher%", voucher);
|
||||
int fadein = DataHandler.getInt(DataHandler.vouchers, path + "titles.fade-in");
|
||||
int stay = DataHandler.getInt(DataHandler.vouchers, path + "titles.stay");
|
||||
int fadeout = DataHandler.getInt(DataHandler.vouchers, path + "titles.fade-out");
|
||||
Bountiful.sendTitle(player, fadein, stay, fadeout, title, subtitle);
|
||||
String sound = DataHandler.getString(DataHandler.vouchers, path + "sounds.sound");
|
||||
int pitch = DataHandler.getInt(DataHandler.vouchers, path + "sounds.pitch");
|
||||
SoundHandler.playSound(player, sound, pitch);
|
||||
String particle = DataHandler.getString(DataHandler.vouchers, path + "particles.particle");
|
||||
if (!particle.isEmpty()) {
|
||||
int amount = DataHandler.getInt(DataHandler.vouchers, path + "particles.amount");
|
||||
player.getWorld().playEffect(player.getLocation(), Effect.valueOf(particle), amount);
|
||||
}
|
||||
String effect = DataHandler.getString(DataHandler.vouchers, path + "effects.effect");
|
||||
if (!effect.isEmpty()) {
|
||||
int amplifier = DataHandler.getInt(DataHandler.vouchers, path + "particles.amplifier");
|
||||
int duration = DataHandler.getInt(DataHandler.vouchers, path + "particles.duration") * 20;
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(effect), duration, amplifier));
|
||||
}
|
||||
console.sendMessage("§f" + player.getName() + " has successfully redeemed the voucher " + voucher + ".");
|
||||
Connections.saveRedeem(player, voucher);
|
||||
} else {
|
||||
console.sendMessage("§c" + player.getName() + " has failed to duplicate the voucher " + voucher + ".");
|
||||
}
|
||||
} catch (Exception error) {
|
||||
DeluxeVouchers.getConsole().sendMessage("§cFailed to redeem the voucher " + voucher + " for the player " + player.getName() + ".");
|
||||
if (DataHandler.debugerrors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
10
src/plugin.yml
Normal file
10
src/plugin.yml
Normal file
@ -0,0 +1,10 @@
|
||||
name: DeluxeVouchers
|
||||
main: nl.marido.deluxevouchers.DeluxeVouchers
|
||||
version: 6.0.0
|
||||
api-version: 1.13
|
||||
author: Marido
|
||||
description: Enhance your server with awesome customizable vouchers with a lot of features.
|
||||
commands:
|
||||
deluxevouchers:
|
||||
description: Administrator commands for the DeluxeVouchers resource.
|
||||
aliases: [dv, deluxev, dvouchers, deluxevoucher]
|
52
src/vouchers.yml
Normal file
52
src/vouchers.yml
Normal file
@ -0,0 +1,52 @@
|
||||
vouchers:
|
||||
example:
|
||||
permission: "deluxevouchers.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 my resource DeluxeVouchers."
|
||||
- "&eListen to the wise words that this nice cookie will tell you."
|
||||
- ""
|
||||
- "&cWhat could be inside this voucher?"
|
||||
- "&6- Marido"
|
||||
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 DeluxeVouchers!"
|
||||
# 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
|
Loading…
Reference in New Issue
Block a user