From ab392acf48786c466825a1425b7e9290c9b04383 Mon Sep 17 00:00:00 2001 From: CoderMarido Date: Fri, 14 Sep 2018 21:21:12 +0200 Subject: [PATCH] Updated to 6.0.3 (resolved some issues and patches). --- .../marido/deluxevouchers/DeluxeVouchers.java | 17 +-- .../deluxevouchers/handlers/Commandos.java | 6 +- .../deluxevouchers/handlers/Connections.java | 16 +-- .../deluxevouchers/handlers/DataHandler.java | 31 +++-- .../deluxevouchers/handlers/SoundHandler.java | 119 +++++++++--------- .../handlers/UpdateHandler.java | 10 +- .../inventory/VoucherEditor.java | 4 +- .../deluxevouchers/vouchers/Cooldowns.java | 2 +- .../vouchers/VoucherBuilder.java | 6 +- .../vouchers/VoucherExecutor.java | 10 +- src/plugin.yml | 2 +- 11 files changed, 107 insertions(+), 116 deletions(-) diff --git a/src/nl/marido/deluxevouchers/DeluxeVouchers.java b/src/nl/marido/deluxevouchers/DeluxeVouchers.java index 3895a51..b91b0ba 100644 --- a/src/nl/marido/deluxevouchers/DeluxeVouchers.java +++ b/src/nl/marido/deluxevouchers/DeluxeVouchers.java @@ -1,7 +1,7 @@ package nl.marido.deluxevouchers; import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; +import org.bukkit.ChatColor; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -18,6 +18,7 @@ import nl.marido.deluxevouchers.vouchers.ClickListener; public class DeluxeVouchers extends JavaPlugin { public static DeluxeVouchers instance; + public static ConsoleCommandSender console; // Thank you for purchasing DeluxeVouchers. public static String user = "%%__USER__%%"; @@ -38,15 +39,13 @@ public class DeluxeVouchers extends JavaPlugin { } public static void enable() { - CommandSender console = DeluxeVouchers.getConsole(); String version = DeluxeVouchers.getInstance().getDescription().getVersion(); - console.sendMessage("§eDeluxeVouchers " + version + " has been enabled successfully."); + DeluxeVouchers.printConsole("§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."); + DeluxeVouchers.printConsole("§eDeluxeVouchers " + version + " has been disabled successfully."); } public static void events() { @@ -62,8 +61,12 @@ public class DeluxeVouchers extends JavaPlugin { return instance; } - public static ConsoleCommandSender getConsole() { - return Bukkit.getConsoleSender(); + public static String applyColor(String message) { + return ChatColor.translateAlternateColorCodes('&', message); + } + + public static void printConsole(String message) { + console.sendMessage(applyColor(message)); } } \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/handlers/Commandos.java b/src/nl/marido/deluxevouchers/handlers/Commandos.java index b35f347..7590219 100644 --- a/src/nl/marido/deluxevouchers/handlers/Commandos.java +++ b/src/nl/marido/deluxevouchers/handlers/Commandos.java @@ -20,7 +20,7 @@ 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 (sender.hasPermission("deluxevouchers.admin") || sender.isOp()) { if (args.length == 1) { if (args[0].equalsIgnoreCase("reload")) { DataHandler.cacheData(); @@ -32,7 +32,7 @@ public class Commandos implements CommandExecutor { VoucherEditor.openMenu((Player) sender); return true; } - DeluxeVouchers.getConsole().sendMessage("§cYou can not use this command as a console."); + DeluxeVouchers.printConsole("§cYou can not use this command as a console."); return true; } if (args[0].equalsIgnoreCase("disable")) { @@ -209,7 +209,7 @@ public class Commandos implements CommandExecutor { for (int argint = 0; argint < args.length; argint++) { fullcommand = fullcommand + " " + args[argint]; } - DeluxeVouchers.getConsole().sendMessage("§cFailed to execute the command " + fullcommand + " by " + sender.getName() + "."); + DeluxeVouchers.printConsole("§cFailed to execute the command " + fullcommand + " by " + sender.getName() + "."); if (DataHandler.debugerrors) { error.printStackTrace(); } diff --git a/src/nl/marido/deluxevouchers/handlers/Connections.java b/src/nl/marido/deluxevouchers/handlers/Connections.java index 5d9f24e..21b4277 100644 --- a/src/nl/marido/deluxevouchers/handlers/Connections.java +++ b/src/nl/marido/deluxevouchers/handlers/Connections.java @@ -6,7 +6,6 @@ import java.sql.DriverManager; import java.sql.Statement; import java.sql.Timestamp; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import nl.marido.deluxevouchers.DeluxeVouchers; @@ -18,7 +17,6 @@ public class Connections { public static void saveRedeem(Player player, String voucher) { if (DataHandler.mysqlenabled) { if (connection != null) { - CommandSender console = DeluxeVouchers.getConsole(); Timestamp stamp = new Timestamp(System.currentTimeMillis()); Date date = new Date(stamp.getTime()); String time = date.toString(); @@ -27,9 +25,9 @@ public class Connections { 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."); + DeluxeVouchers.printConsole("§fSuccessfully saved the redeem in the MySQL database."); } catch (Exception error) { - console.sendMessage("§cFailed to save the redeem data in the MySQL database."); + DeluxeVouchers.printConsole("§cFailed to save the redeem data in the MySQL database."); if (DataHandler.debugerrors) { error.printStackTrace(); } @@ -41,12 +39,11 @@ public class Connections { 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."); + DeluxeVouchers.printConsole("§fSuccessfully created a connection with MySQL."); } catch (Exception error) { - console.sendMessage("§cFailed to create a connection with MySQL."); + DeluxeVouchers.printConsole("§cFailed to create a connection with MySQL."); if (DataHandler.debugerrors) { error.printStackTrace(); } @@ -58,12 +55,11 @@ public class Connections { public static void closeMySQL() { if (DataHandler.mysqlenabled) { if (connection != null) { - CommandSender console = DeluxeVouchers.getConsole(); try { connection.close(); - console.sendMessage("§fSuccessfully closed the MySQL connection."); + DeluxeVouchers.printConsole("§fSuccessfully closed the MySQL connection."); } catch (Exception error) { - console.sendMessage("§cFailed to close the MySQL connection."); + DeluxeVouchers.printConsole("§cFailed to close the MySQL connection."); if (DataHandler.debugerrors) { error.printStackTrace(); } diff --git a/src/nl/marido/deluxevouchers/handlers/DataHandler.java b/src/nl/marido/deluxevouchers/handlers/DataHandler.java index 9ed3b95..ae0cb37 100644 --- a/src/nl/marido/deluxevouchers/handlers/DataHandler.java +++ b/src/nl/marido/deluxevouchers/handlers/DataHandler.java @@ -5,8 +5,6 @@ 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; @@ -125,7 +123,6 @@ public class DataHandler { // TODO: Switch to enums. public static void cacheData() { - CommandSender console = DeluxeVouchers.getConsole(); try { File folder = DeluxeVouchers.getInstance().getDataFolder(); configfile = new File(folder, "config.yml"); @@ -134,19 +131,19 @@ public class DataHandler { 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..."); + DeluxeVouchers.printConsole("§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..."); + DeluxeVouchers.printConsole("§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..."); + DeluxeVouchers.printConsole("§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..."); + DeluxeVouchers.printConsole("§fFailed to find the messages.yml file. Generating..."); } config = YamlConfiguration.loadConfiguration(configfile); vouchers = YamlConfiguration.loadConfiguration(vouchersfile); @@ -251,8 +248,8 @@ public class DataHandler { 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."); + DeluxeVouchers.printConsole("§cFailed to copy the configuration options to the cache memory."); + DeluxeVouchers.printConsole("§cMake sure to update your configuration options or reset it."); if (debugerrors) { error.printStackTrace(); } @@ -263,7 +260,7 @@ public class DataHandler { try { return datafile.getString(path) != null; } catch (Exception error) { - DeluxeVouchers.getConsole().sendMessage("§cFailed to find the path " + path + "."); + DeluxeVouchers.printConsole("§cFailed to find the path " + path + "."); if (debugerrors) { error.printStackTrace(); } @@ -275,7 +272,7 @@ public class DataHandler { try { return datafile.getBoolean(path); } catch (Exception error) { - DeluxeVouchers.getConsole().sendMessage("§cFailed to find the path " + path + "."); + DeluxeVouchers.printConsole("§cFailed to find the path " + path + "."); if (debugerrors) { error.printStackTrace(); } @@ -287,7 +284,7 @@ public class DataHandler { try { return datafile.getInt(path); } catch (Exception error) { - DeluxeVouchers.getConsole().sendMessage("§cFailed to find the path " + path + "."); + DeluxeVouchers.printConsole("§cFailed to find the path " + path + "."); if (debugerrors) { error.printStackTrace(); } @@ -297,9 +294,9 @@ public class DataHandler { public static String getString(FileConfiguration datafile, String path) { try { - return ChatColor.translateAlternateColorCodes('&', datafile.getString(path)); + return DeluxeVouchers.applyColor(datafile.getString(path)); } catch (Exception error) { - DeluxeVouchers.getConsole().sendMessage("§cFailed to find the path " + path + "."); + DeluxeVouchers.printConsole("§cFailed to find the path " + path + "."); if (debugerrors) { error.printStackTrace(); } @@ -311,7 +308,7 @@ public class DataHandler { try { return datafile.getConfigurationSection(path).getKeys(false); } catch (Exception error) { - DeluxeVouchers.getConsole().sendMessage("§cFailed to find the path " + path + "."); + DeluxeVouchers.printConsole("§cFailed to find the path " + path + "."); if (debugerrors) { error.printStackTrace(); } @@ -323,11 +320,11 @@ public class DataHandler { try { ArrayList stringlist = new ArrayList(); for (String line : datafile.getStringList(path)) { - stringlist.add(ChatColor.translateAlternateColorCodes('&', line)); + stringlist.add(DeluxeVouchers.applyColor(line)); } return stringlist; } catch (Exception error) { - DeluxeVouchers.getConsole().sendMessage("§cFailed to find the path " + path + "."); + DeluxeVouchers.printConsole("§cFailed to find the path " + path + "."); if (debugerrors) { error.printStackTrace(); } diff --git a/src/nl/marido/deluxevouchers/handlers/SoundHandler.java b/src/nl/marido/deluxevouchers/handlers/SoundHandler.java index f2efee6..9dce630 100644 --- a/src/nl/marido/deluxevouchers/handlers/SoundHandler.java +++ b/src/nl/marido/deluxevouchers/handlers/SoundHandler.java @@ -3,18 +3,20 @@ 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"), + AMBIENCE_THUNDER("AMBIENCE_THUNDER", "ENTITY_LIGHTNING_THUNDER", "ENTITY_LIGHTNING_BOLT_THUNDER"), ANVIL_BREAK("ANVIL_BREAK", "BLOCK_ANVIL_BREAK"), ANVIL_LAND("ANVIL_LAND", "BLOCK_ANVIL_LAND"), ANVIL_USE("ANVIL_USE", "BLOCK_ANVIL_USE"), ARROW_HIT("ARROW_HIT", "ENTITY_ARROW_HIT"), BURP("BURP", "ENTITY_PLAYER_BURP"), - CHEST_CLOSE("CHEST_CLOSE", "ENTITY_CHEST_CLOSE"), - CHEST_OPEN("CHEST_OPEN", "ENTITY_CHEST_OPEN"), + CHEST_CLOSE("CHEST_CLOSE", "ENTITY_CHEST_CLOSE", "BLOCK_CHEST_CLOSE"), + CHEST_OPEN("CHEST_OPEN", "ENTITY_CHEST_OPEN", "BLOCK_CHEST_OPEN"), CLICK("CLICK", "UI_BUTTON_CLICK"), DOOR_CLOSE("DOOR_CLOSE", "BLOCK_WOODEN_DOOR_CLOSE"), DOOR_OPEN("DOOR_OPEN", "BLOCK_WOODEN_DOOR_OPEN"), @@ -36,13 +38,13 @@ public enum SoundHandler { 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"), + NOTE_BASS("NOTE_BASS", "BLOCK_NOTE_BASS", "BLOCK_NOTE_BLOCK_BASS"), + NOTE_PIANO("NOTE_PIANO", "BLOCK_NOTE_HARP", "BLOCK_NOTE_BLOCK_HARP"), + NOTE_BASS_DRUM("NOTE_BASS_DRUM", "BLOCK_NOTE_BASEDRUM", "BLOCK_NOTE_BLOCK_BASEDRUM"), + NOTE_STICKS("NOTE_STICKS", "BLOCK_NOTE_HAT", "BLOCK_NOTE_BLOCK_HAT"), + NOTE_BASS_GUITAR("NOTE_BASS_GUITAR", "BLOCK_NOTE_GUITAR", "BLOCK_NOTE_BLOCK_GUITAR", "BLOCK_NOTE_BASS" /* 1.10 doesn't know guitar... */), + NOTE_SNARE_DRUM("NOTE_SNARE_DRUM", "BLOCK_NOTE_SNARE", "BLOCK_NOTE_BLOCK_SNARE"), + NOTE_PLING("NOTE_PLING", "BLOCK_NOTE_PLING", "BLOCK_NOTE_BLOCK_PLING"), ORB_PICKUP("ORB_PICKUP", "ENTITY_EXPERIENCE_ORB_PICKUP"), PISTON_EXTEND("PISTON_EXTEND", "BLOCK_PISTON_EXTEND"), PISTON_RETRACT("PISTON_RETRACT", "BLOCK_PISTON_CONTRACT"), @@ -51,7 +53,7 @@ public enum SoundHandler { PORTAL_TRIGGER("PORTAL_TRIGGER", "BLOCK_PORTAL_TRIGGER"), SHOOT_ARROW("SHOOT_ARROW", "ENTITY_ARROW_SHOOT"), SPLASH("SPLASH", "ENTITY_GENERIC_SPLASH"), - SPLASH2("SPLASH2", "ENTITY_BOBBER_SPLASH"), + SPLASH2("SPLASH2", "ENTITY_BOBBER_SPLASH", "ENTITY_FISHING_BOBBER_SPLASH"), STEP_GRASS("STEP_GRASS", "BLOCK_GRASS_STEP"), STEP_GRAVEL("STEP_GRAVEL", "BLOCK_GRAVEL_STEP"), STEP_LADDER("STEP_LADDER", "BLOCK_LADDER_STEP"), @@ -59,10 +61,10 @@ public enum SoundHandler { 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"), + STEP_WOOL("STEP_WOOL", "BLOCK_CLOTH_STEP", "BLOCK_WOOL_STEP"), SWIM("SWIM", "ENTITY_GENERIC_SWIM"), WATER("WATER", "BLOCK_WATER_AMBIENT"), - WOOD_CLICK("WOOD_CLICK", "BLOCK_WOOD_BUTTON_CLICK_ON"), + WOOD_CLICK("WOOD_CLICK", "BLOCK_WOOD_BUTTON_CLICK_ON", "BLOCK_WOODEN_BUTTON_CLICK_ON"), BAT_DEATH("BAT_DEATH", "ENTITY_BAT_DEATH"), BAT_HURT("BAT_HURT", "ENTITY_BAT_HURT"), BAT_IDLE("BAT_IDLE", "ENTITY_BAT_AMBIENT"), @@ -85,29 +87,29 @@ public enum SoundHandler { 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"), + ENDERDRAGON_DEATH("ENDERDRAGON_DEATH", "ENTITY_ENDERDRAGON_DEATH", "ENTITY_ENDER_DRAGON_DEATH"), + ENDERDRAGON_GROWL("ENDERDRAGON_GROWL", "ENTITY_ENDERDRAGON_GROWL", "ENTITY_ENDER_DRAGON_GROWL"), + ENDERDRAGON_HIT("ENDERDRAGON_HIT", "ENTITY_ENDERDRAGON_HURT", "ENTITY_ENDER_DRAGON_HURT"), + ENDERDRAGON_WINGS("ENDERDRAGON_WINGS", "ENTITY_ENDERDRAGON_FLAP", "ENTITY_ENDER_DRAGON_FLAP"), + ENDERMAN_DEATH("ENDERMAN_DEATH", "ENTITY_ENDERMEN_DEATH", "ENTITY_ENDERMAN_DEATH"), + ENDERMAN_HIT("ENDERMAN_HIT", "ENTITY_ENDERMEN_HURT", "ENTITY_ENDERMAN_HURT"), + ENDERMAN_IDLE("ENDERMAN_IDLE", "ENTITY_ENDERMEN_AMBIENT", "ENTITY_ENDERMAN_AMBIENT"), + ENDERMAN_TELEPORT("ENDERMAN_TELEPORT", "ENTITY_ENDERMEN_TELEPORT", "ENTITY_ENDERMAN_TELEPORT"), + ENDERMAN_SCREAM("ENDERMAN_SCREAM", "ENTITY_ENDERMEN_SCREAM", "ENTITY_ENDERMAN_SCREAM"), + ENDERMAN_STARE("ENDERMAN_STARE", "ENTITY_ENDERMEN_STARE", "ENTITY_ENDERMAN_STARE"), GHAST_SCREAM("GHAST_SCREAM", "ENTITY_GHAST_SCREAM"), GHAST_SCREAM2("GHAST_SCREAM2", "ENTITY_GHAST_HURT"), GHAST_CHARGE("GHAST_CHARGE", "ENTITY_GHAST_WARN"), GHAST_DEATH("GHAST_DEATH", "ENTITY_GHAST_DEATH"), GHAST_FIREBALL("GHAST_FIREBALL", "ENTITY_GHAST_SHOOT"), GHAST_MOAN("GHAST_MOAN", "ENTITY_GHAST_AMBIENT"), - IRONGOLEM_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"), + IRONGOLEM_ATTACK("IRONGOLEM_THROW", "ENTITY_IRONGOLEM_ATTACK", "ENTITY_IRON_GOLEM_ATTACK"), + IRONGOLEM_DEATH("IRONGOLEM_DEATH", "ENTITY_IRONGOLEM_DEATH", "ENTITY_IRON_GOLEM_DEATH"), + IRONGOLEM_HIT("IRONGOLEM_HIT", "ENTITY_IRONGOLEM_HURT", "ENTITY_IRON_GOLEM_HURT"), + IRONGOLEM_WALK("IRONGOLEM_WALK", "ENTITY_IRONGOLEM_STEP", "ENTITY_IRON_GOLEM_STEP"), + MAGMACUBE_WALK("MAGMACUBE_WALK", "ENTITY_MAGMACUBE_SQUISH", "ENTITY_MAGMA_CUBE_SQUISH"), + MAGMACUBE_WALK2("MAGMACUBE_WALK2", "ENTITY_MAGMACUBE_SQUISH", "ENTITY_MAGMA_CUBE_SQUISH_SMALL"), + MAGMACUBE_JUMP("MAGMACUBE_JUMP", "ENTITY_MAGMACUBE_JUMP", "ENTITY_MAGMA_CUBE_JUMP"), PIG_IDLE("PIG_IDLE", "ENTITY_PIG_AMBIENT"), PIG_DEATH("PIG_DEATH", "ENTITY_PIG_DEATH"), PIG_WALK("PIG_WALK", "ENTITY_PIG_STEP"), @@ -143,8 +145,8 @@ public enum SoundHandler { 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_WOOD("ZOMBIE_WOOD", "ENTITY_ZOMBIE_ATTACK_DOOR_WOOD", "ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR"), + ZOMBIE_WOODBREAK("ZOMBIE_WOODBREAK", "ENTITY_ZOMBIE_BREAK_DOOR_WOOD", "ENTITY_ZOMBIE_BREAK_WOODEN_DOOR"), ZOMBIE_IDLE("ZOMBIE_IDLE", "ENTITY_ZOMBIE_AMBIENT"), ZOMBIE_DEATH("ZOMBIE_DEATH", "ENTITY_ZOMBIE_DEATH"), ZOMBIE_HURT("ZOMBIE_HURT", "ENTITY_ZOMBIE_HURT"), @@ -152,24 +154,24 @@ public enum SoundHandler { 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"), + ZOMBIE_PIG_IDLE("ZOMBIE_PIG_IDLE", "ENTITY_ZOMBIE_PIG_AMBIENT", "ENTITY_ZOMBIE_PIGMAN_AMBIENT"), + ZOMBIE_PIG_ANGRY("ZOMBIE_PIG_ANGRY", "ENTITY_ZOMBIE_PIG_ANGRY", "ENTITY_ZOMBIE_PIGMAN_ANGRY"), + ZOMBIE_PIG_DEATH("ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIGMAN_DEATH"), + ZOMBIE_PIG_HURT("ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIGMAN_HURT"), + DIG_WOOL("DIG_WOOL", "BLOCK_CLOTH_BREAK", "BLOCK_WOOL_BREAK"), DIG_GRASS("DIG_GRASS", "BLOCK_GRASS_BREAK"), DIG_GRAVEL("DIG_GRAVEL", "BLOCK_GRAVEL_BREAK"), DIG_SAND("DIG_SAND", "BLOCK_SAND_BREAK"), DIG_SNOW("DIG_SNOW", "BLOCK_SNOW_BREAK"), DIG_STONE("DIG_STONE", "BLOCK_STONE_BREAK"), DIG_WOOD("DIG_WOOD", "BLOCK_WOOD_BREAK"), - FIREWORK_BLAST("FIREWORK_BLAST", "ENTITY_FIREWORK_BLAST"), - 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"), + FIREWORK_BLAST("FIREWORK_BLAST", "ENTITY_FIREWORK_BLAST", "ENTITY_FIREWORK_ROCKET_BLAST"), + FIREWORK_BLAST2("FIREWORK_BLAST2", "ENTITY_FIREWORK_BLAST_FAR", "ENTITY_FIREWORK_ROCKET_BLAST_FAR"), + FIREWORK_LARGE_BLAST("FIREWORK_LARGE_BLAST", "ENTITY_FIREWORK_LARGE_BLAST", "ENTITY_FIREWORK_ROCKET_LARGE_BLAST"), + FIREWORK_LARGE_BLAST2("FIREWORK_LARGE_BLAST2", "ENTITY_FIREWORK_LARGE_BLAST_FAR", "ENTITY_FIREWORK_ROCKET_LARGE_BLAST_FAR"), + FIREWORK_LAUNCH("FIREWORK_LAUNCH", "ENTITY_FIREWORK_LAUNCH", "ENTITY_FIREWORK_ROCKET_LAUNCH"), + FIREWORK_TWINKLE("FIREWORK_TWINKLE", "ENTITY_FIREWORK_TWINKLE", "ENTITY_FIREWORK_ROCKET_TWINKLE"), + FIREWORK_TWINKLE2("FIREWORK_TWINKLE2", "ENTITY_FIREWORK_TWINKLE_FAR", "ENTITY_FIREWORK_ROCKET_TWINKLE_FAR"), SUCCESSFUL_HIT("SUCCESSFUL_HIT", "ENTITY_PLAYER_ATTACK_STRONG"), HORSE_ANGRY("HORSE_ANGRY", "ENTITY_HORSE_ANGRY"), HORSE_ARMOR("HORSE_ARMOR", "ENTITY_HORSE_ARMOR"), @@ -194,36 +196,35 @@ public enum SoundHandler { 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_TRADE("VILLAGER_HAGGLE", "ENTITY_VILLAGER_TRADING", "ENTITY_VILLAGER_TRADE"), VILLAGER_HIT("VILLAGER_HIT", "ENTITY_VILLAGER_HURT"), VILLAGER_IDLE("VILLAGER_IDLE", "ENTITY_VILLAGER_AMBIENT"), VILLAGER_NO("VILLAGER_NO", "ENTITY_VILLAGER_NO"), VILLAGER_YES("VILLAGER_YES", "ENTITY_VILLAGER_YES"); - private String beforesound; - private String aftersound; - private Sound resolvesound = null; + private String[] versionname; + private Sound cached = null; - private SoundHandler(String beforesound, String aftersound) { - this.beforesound = beforesound; - this.aftersound = aftersound; + SoundHandler(String... versionname) { + this.versionname = versionname; } public Sound bukkitSound() { - if (resolvesound != null) { - return resolvesound; - } - try { - return this.resolvesound = Sound.valueOf(aftersound); - } catch (Exception error) { - return this.resolvesound = Sound.valueOf(beforesound); + if (cached != null) + return cached; + for (String name : versionname) { + try { + return cached = Sound.valueOf(name); + } catch (Exception error) { + } } + DeluxeVouchers.printConsole("&cFailed to find the sound enum called " + cached + "."); + return null; } public static void playSound(Player player, String sound, int pitch) { if (!sound.isEmpty()) { player.playSound(player.getLocation(), SoundHandler.valueOf(sound).bukkitSound(), Integer.MAX_VALUE, pitch); - // TODO: Find an alternative for this to check errors. } } diff --git a/src/nl/marido/deluxevouchers/handlers/UpdateHandler.java b/src/nl/marido/deluxevouchers/handlers/UpdateHandler.java index cab4c34..890fba3 100644 --- a/src/nl/marido/deluxevouchers/handlers/UpdateHandler.java +++ b/src/nl/marido/deluxevouchers/handlers/UpdateHandler.java @@ -5,7 +5,6 @@ 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; @@ -22,22 +21,21 @@ public class UpdateHandler implements Listener { if (DataHandler.checkupdates) { new BukkitRunnable() { public void run() { - 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 + ")."); + DeluxeVouchers.printConsole("§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"); + DeluxeVouchers.printConsole("§cOutdated version of DeluxeVouchers detected (" + currentversion + ")."); + DeluxeVouchers.printConsole("§cDownload " + latestversion + ": https://spigotmc.org/resources/52480"); oldversion = true; } } catch (Exception error) { - console.sendMessage("§cFailed to create a connection with the updater host."); + DeluxeVouchers.printConsole("§cFailed to create a connection with the updater host."); if (DataHandler.debugerrors) { error.printStackTrace(); } diff --git a/src/nl/marido/deluxevouchers/inventory/VoucherEditor.java b/src/nl/marido/deluxevouchers/inventory/VoucherEditor.java index db46bc7..381b3af 100644 --- a/src/nl/marido/deluxevouchers/inventory/VoucherEditor.java +++ b/src/nl/marido/deluxevouchers/inventory/VoucherEditor.java @@ -19,7 +19,7 @@ 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.DeluxeVouchers; import nl.marido.deluxevouchers.handlers.DataHandler; import nl.marido.deluxevouchers.handlers.SoundHandler; import nl.marido.deluxevouchers.vouchers.VoucherBuilder; @@ -276,7 +276,7 @@ public class VoucherEditor implements Listener { } DataHandler.cacheData(); String message = DataHandler.editorrenamedone; - message = message.replaceAll("%renamed%", ChatColor.translateAlternateColorCodes('&', renamed)); + message = DeluxeVouchers.applyColor(message); 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); diff --git a/src/nl/marido/deluxevouchers/vouchers/Cooldowns.java b/src/nl/marido/deluxevouchers/vouchers/Cooldowns.java index 8aecec9..087e332 100644 --- a/src/nl/marido/deluxevouchers/vouchers/Cooldowns.java +++ b/src/nl/marido/deluxevouchers/vouchers/Cooldowns.java @@ -34,7 +34,7 @@ public class Cooldowns { } }.runTaskTimer(DeluxeVouchers.getInstance(), 0, 20); } catch (Exception error) { - DeluxeVouchers.getConsole().sendMessage("§cFailed to add cooldown to the UUID " + uuid + "."); + DeluxeVouchers.printConsole("§cFailed to add cooldown to the UUID " + uuid + "."); if (DataHandler.debugerrors) { error.printStackTrace(); } diff --git a/src/nl/marido/deluxevouchers/vouchers/VoucherBuilder.java b/src/nl/marido/deluxevouchers/vouchers/VoucherBuilder.java index 4ce9b38..cd6cf8c 100644 --- a/src/nl/marido/deluxevouchers/vouchers/VoucherBuilder.java +++ b/src/nl/marido/deluxevouchers/vouchers/VoucherBuilder.java @@ -3,7 +3,6 @@ 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; @@ -39,9 +38,8 @@ public class VoucherBuilder { 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."); + DeluxeVouchers.printConsole("§cFailed to build and create the voucher " + voucher + "."); + DeluxeVouchers.printConsole("§cMake sure to update your voucher options or reset it."); if (DataHandler.debugerrors) { error.printStackTrace(); } diff --git a/src/nl/marido/deluxevouchers/vouchers/VoucherExecutor.java b/src/nl/marido/deluxevouchers/vouchers/VoucherExecutor.java index bf33e30..9ecdfef 100644 --- a/src/nl/marido/deluxevouchers/vouchers/VoucherExecutor.java +++ b/src/nl/marido/deluxevouchers/vouchers/VoucherExecutor.java @@ -3,7 +3,6 @@ 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; @@ -30,7 +29,6 @@ public class VoucherExecutor { if (!player.getItemInHand().isSimilar(item)) { duplication = true; } - ConsoleCommandSender console = DeluxeVouchers.getConsole(); if (!duplication) { if (manual) { Cooldowns.addCooldown(player.getUniqueId(), voucher); @@ -88,7 +86,7 @@ public class VoucherExecutor { command = command.replace("[delay]", ""); throw new UnsupportedOperationException("delay is not supported yet"); } else { - Bukkit.getServer().dispatchCommand(DeluxeVouchers.getConsole(), command); + Bukkit.getServer().dispatchCommand(DeluxeVouchers.console, command); } } String actionbar = DataHandler.getString(DataHandler.vouchers, path + "actionbar"); @@ -119,13 +117,13 @@ public class VoucherExecutor { 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 + "."); + DeluxeVouchers.printConsole("§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 + "."); + DeluxeVouchers.printConsole("§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() + "."); + DeluxeVouchers.printConsole("§cFailed to redeem the voucher " + voucher + " for the player " + player.getName() + "."); if (DataHandler.debugerrors) { error.printStackTrace(); } diff --git a/src/plugin.yml b/src/plugin.yml index 562d9b5..4cfc27a 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: DeluxeVouchers main: nl.marido.deluxevouchers.DeluxeVouchers -version: 6.0.2 +version: 6.0.3 api-version: 1.13 author: Marido description: Enhance your server with awesome customizable vouchers with a lot of features.