diff --git a/src/main/java/com/songoda/epicfurnaces/command/AbstractCommand.java b/src/main/java/com/songoda/epicfurnaces/command/AbstractCommand.java index 35b3190..99197c5 100644 --- a/src/main/java/com/songoda/epicfurnaces/command/AbstractCommand.java +++ b/src/main/java/com/songoda/epicfurnaces/command/AbstractCommand.java @@ -1,6 +1,6 @@ package com.songoda.epicfurnaces.command; -import com.songoda.epicfurnaces.EpicFurnacesPlugin; +import com.songoda.epicfurnaces.EpicFurnaces; import org.bukkit.command.CommandSender; public abstract class AbstractCommand { @@ -27,7 +27,7 @@ public abstract class AbstractCommand { return noConsole; } - protected abstract ReturnType runCommand(EpicFurnacesPlugin instance, CommandSender sender, String... args); + protected abstract ReturnType runCommand(EpicFurnaces plugin, CommandSender sender, String... args); public abstract String getPermissionNode(); diff --git a/src/main/java/com/songoda/epicfurnaces/command/CommandManager.java b/src/main/java/com/songoda/epicfurnaces/command/CommandManager.java index aed3066..152aa22 100644 --- a/src/main/java/com/songoda/epicfurnaces/command/CommandManager.java +++ b/src/main/java/com/songoda/epicfurnaces/command/CommandManager.java @@ -1,8 +1,8 @@ package com.songoda.epicfurnaces.command; -import com.songoda.arconix.api.methods.formatting.TextComponent; -import com.songoda.epicfurnaces.EpicFurnacesPlugin; +import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.command.commands.*; +import com.songoda.epicfurnaces.utils.Methods; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -14,14 +14,14 @@ import java.util.List; public class CommandManager implements CommandExecutor { - private EpicFurnacesPlugin instance; + private EpicFurnaces plugin; private List commands = new ArrayList<>(); - public CommandManager(EpicFurnacesPlugin instance) { - this.instance = instance; + public CommandManager(EpicFurnaces plugin) { + this.plugin = plugin; - instance.getCommand("EpicFurnaces").setExecutor(this); + plugin.getCommand("EpicFurnaces").setExecutor(this); AbstractCommand commandEpicFurnaces = addCommand(new CommandEpicFurnaces()); @@ -53,7 +53,7 @@ public class CommandManager implements CommandExecutor { } } } - commandSender.sendMessage(instance.getReferences().getPrefix() + TextComponent.formatText("&7The command you entered does not exist or is spelt incorrectly.")); + commandSender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&7The command you entered does not exist or is spelt incorrectly.")); return true; } @@ -63,14 +63,14 @@ public class CommandManager implements CommandExecutor { return; } if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) { - AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings); + AbstractCommand.ReturnType returnType = command.runCommand(plugin, sender, strings); if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) { - sender.sendMessage(instance.getReferences().getPrefix() + TextComponent.formatText("&cInvalid Syntax!")); - sender.sendMessage(instance.getReferences().getPrefix() + TextComponent.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7.")); + sender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&cInvalid Syntax!")); + sender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7.")); } return; } - sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.general.nopermission")); + sender.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.general.nopermission")); } public List getCommands() { diff --git a/src/main/java/com/songoda/epicfurnaces/command/commands/CommandBoost.java b/src/main/java/com/songoda/epicfurnaces/command/commands/CommandBoost.java index 43c1348..b6457a9 100644 --- a/src/main/java/com/songoda/epicfurnaces/command/commands/CommandBoost.java +++ b/src/main/java/com/songoda/epicfurnaces/command/commands/CommandBoost.java @@ -1,10 +1,9 @@ package com.songoda.epicfurnaces.command.commands; -import com.songoda.arconix.api.methods.formatting.TextComponent; -import com.songoda.arconix.api.methods.math.AMath; -import com.songoda.epicfurnaces.EpicFurnacesPlugin; +import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.boost.BoostData; import com.songoda.epicfurnaces.command.AbstractCommand; +import com.songoda.epicfurnaces.utils.Methods; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -18,52 +17,52 @@ public class CommandBoost extends AbstractCommand { } @Override - protected ReturnType runCommand(EpicFurnacesPlugin instance, CommandSender sender, String... args) { + protected ReturnType runCommand(EpicFurnaces plugin, CommandSender sender, String... args) { if (args.length < 3) { return ReturnType.SYNTAX_ERROR; } - if (Bukkit.getPlayer(args[1]) == null) { - sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&cThat player does not exist...")); - return ReturnType.FAILURE; - } else if (!AMath.isInt(args[2])) { - sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&6" + args[2] + " &7is not a number...")); - return ReturnType.FAILURE; - } else { - Calendar c = Calendar.getInstance(); - Date currentDate = new Date(); - c.setTime(currentDate); + if (Bukkit.getPlayer(args[1]) == null) { + sender.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&cThat player does not exist...")); + return ReturnType.FAILURE; + } else if (!Methods.isInt(args[2])) { + sender.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&6" + args[2] + " &7is not a number...")); + return ReturnType.FAILURE; + } else { + Calendar c = Calendar.getInstance(); + Date currentDate = new Date(); + c.setTime(currentDate); - String time = "&7."; + String time = "&7."; - if (args.length > 3) { - if (args[3].contains("m:")) { - String[] arr2 = (args[3]).split(":"); - c.add(Calendar.MINUTE, Integer.parseInt(arr2[1])); - time = " &7for &6" + arr2[1] + " minutes&7."; - } else if (args[3].contains("h:")) { - String[] arr2 = (args[3]).split(":"); - c.add(Calendar.HOUR, Integer.parseInt(arr2[1])); - time = " &7for &6" + arr2[1] + " hours&7."; - } else if (args[3].contains("d:")) { - String[] arr2 = (args[3]).split(":"); - c.add(Calendar.HOUR, Integer.parseInt(arr2[1]) * 24); - time = " &7for &6" + arr2[1] + " days&7."; - } else if (args[3].contains("y:")) { - String[] arr2 = (args[3]).split(":"); - c.add(Calendar.YEAR, Integer.parseInt(arr2[1])); - time = " &7for &6" + arr2[1] + " years&7."; - } else { - sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7" + args[3] + " &7is invalid.")); - return ReturnType.SUCCESS; - } + if (args.length > 3) { + if (args[3].contains("m:")) { + String[] arr2 = (args[3]).split(":"); + c.add(Calendar.MINUTE, Integer.parseInt(arr2[1])); + time = " &7for &6" + arr2[1] + " minutes&7."; + } else if (args[3].contains("h:")) { + String[] arr2 = (args[3]).split(":"); + c.add(Calendar.HOUR, Integer.parseInt(arr2[1])); + time = " &7for &6" + arr2[1] + " hours&7."; + } else if (args[3].contains("d:")) { + String[] arr2 = (args[3]).split(":"); + c.add(Calendar.HOUR, Integer.parseInt(arr2[1]) * 24); + time = " &7for &6" + arr2[1] + " days&7."; + } else if (args[3].contains("y:")) { + String[] arr2 = (args[3]).split(":"); + c.add(Calendar.YEAR, Integer.parseInt(arr2[1])); + time = " &7for &6" + arr2[1] + " years&7."; } else { - c.add(Calendar.YEAR, 10); + sender.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&7" + args[3] + " &7is invalid.")); + return ReturnType.SUCCESS; } - - BoostData boostData = new BoostData(Integer.parseInt(args[2]), c.getTime().getTime(), Bukkit.getPlayer(args[1]).getUniqueId()); - instance.getBoostManager().addBoostToPlayer(boostData); - sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7Successfully boosted &6" + Bukkit.getPlayer(args[1]).getName() + "'s &7furnaces reward amounts by &6" + args[2] + "x" + time)); + } else { + c.add(Calendar.YEAR, 10); } + + BoostData boostData = new BoostData(Integer.parseInt(args[2]), c.getTime().getTime(), Bukkit.getPlayer(args[1]).getUniqueId()); + plugin.getBoostManager().addBoostToPlayer(boostData); + sender.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&7Successfully boosted &6" + Bukkit.getPlayer(args[1]).getName() + "'s &7furnaces reward amounts by &6" + args[2] + "x" + time)); + } return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/epicfurnaces/command/commands/CommandEpicFurnaces.java b/src/main/java/com/songoda/epicfurnaces/command/commands/CommandEpicFurnaces.java index b4813b7..58b4a7b 100644 --- a/src/main/java/com/songoda/epicfurnaces/command/commands/CommandEpicFurnaces.java +++ b/src/main/java/com/songoda/epicfurnaces/command/commands/CommandEpicFurnaces.java @@ -1,8 +1,8 @@ package com.songoda.epicfurnaces.command.commands; -import com.songoda.arconix.api.methods.formatting.TextComponent; -import com.songoda.epicfurnaces.EpicFurnacesPlugin; +import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.command.AbstractCommand; +import com.songoda.epicfurnaces.utils.Methods; import org.bukkit.command.CommandSender; public class CommandEpicFurnaces extends AbstractCommand { @@ -12,13 +12,13 @@ public class CommandEpicFurnaces extends AbstractCommand { } @Override - protected ReturnType runCommand(EpicFurnacesPlugin instance, CommandSender sender, String... args) { + protected ReturnType runCommand(EpicFurnaces plugin, CommandSender sender, String... args) { sender.sendMessage(""); - sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna")); + sender.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&7Version " + plugin.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda")); - for (AbstractCommand command : instance.getCommandManager().getCommands()) { + for (AbstractCommand command : plugin.getCommandManager().getCommands()) { if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) { - sender.sendMessage(TextComponent.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription())); + sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription())); } } sender.sendMessage(""); diff --git a/src/main/java/com/songoda/epicfurnaces/command/commands/CommandGive.java b/src/main/java/com/songoda/epicfurnaces/command/commands/CommandGive.java index 8b82f15..e5bfaff 100644 --- a/src/main/java/com/songoda/epicfurnaces/command/commands/CommandGive.java +++ b/src/main/java/com/songoda/epicfurnaces/command/commands/CommandGive.java @@ -1,9 +1,9 @@ package com.songoda.epicfurnaces.command.commands; -import com.songoda.arconix.plugin.Arconix; -import com.songoda.epicfurnaces.EpicFurnacesPlugin; -import com.songoda.epicfurnaces.api.furnace.Level; +import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.command.AbstractCommand; +import com.songoda.epicfurnaces.furnace.levels.Level; +import com.songoda.epicfurnaces.utils.Methods; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -15,34 +15,34 @@ public class CommandGive extends AbstractCommand { } @Override - protected ReturnType runCommand(EpicFurnacesPlugin instance, CommandSender sender, String... args) { + protected ReturnType runCommand(EpicFurnaces plugin, CommandSender sender, String... args) { if (args.length == 2) return ReturnType.SYNTAX_ERROR; - Level level = instance.getLevelManager().getLowestLevel(); - Player player; - if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) { - sender.sendMessage(instance.getReferences().getPrefix() + Arconix.pl().getApi().format().formatText("&cThat player does not exist or is currently offline.")); + Level level = plugin.getLevelManager().getLowestLevel(); + Player player; + if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) { + sender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&cThat player does not exist or is currently offline.")); + return ReturnType.FAILURE; + } else if (args.length == 1) { + if (!(sender instanceof Player)) { + sender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&cYou need to be a player to give a farm item to yourself.")); return ReturnType.FAILURE; - } else if (args.length == 1) { - if (!(sender instanceof Player)) { - sender.sendMessage(instance.getReferences().getPrefix() + Arconix.pl().getApi().format().formatText("&cYou need to be a player to give a farm item to yourself.")); - return ReturnType.FAILURE; - } - player = (Player)sender; - } else { - player = Bukkit.getPlayer(args[1]); } + player = (Player) sender; + } else { + player = Bukkit.getPlayer(args[1]); + } - if (args.length >= 3 && !instance.getLevelManager().isLevel(Integer.parseInt(args[2]))) { - sender.sendMessage(instance.getReferences().getPrefix() + Arconix.pl().getApi().format().formatText("&cNot a valid level... The current valid levels are: &4" + instance.getLevelManager().getLowestLevel().getLevel() + "-" + instance.getLevelManager().getHighestLevel().getLevel() + "&c.")); - return ReturnType.FAILURE; - } else if (args.length != 1){ + if (args.length >= 3 && !plugin.getLevelManager().isLevel(Integer.parseInt(args[2]))) { + sender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&cNot a valid level... The current valid levels are: &4" + plugin.getLevelManager().getLowestLevel().getLevel() + "-" + plugin.getLevelManager().getHighestLevel().getLevel() + "&c.")); + return ReturnType.FAILURE; + } else if (args.length != 1) { - level = instance.getLevelManager().getLevel(Integer.parseInt(args[2])); - } - player.getInventory().addItem(instance.createLeveledFurnace(level.getLevel(), 0)); - player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.success", level.getLevel())); + level = plugin.getLevelManager().getLevel(Integer.parseInt(args[2])); + } + player.getInventory().addItem(plugin.createLeveledFurnace(level.getLevel(), 0)); + player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("command.give.success", level.getLevel())); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/epicfurnaces/command/commands/CommandReload.java b/src/main/java/com/songoda/epicfurnaces/command/commands/CommandReload.java index f140aa9..5793633 100644 --- a/src/main/java/com/songoda/epicfurnaces/command/commands/CommandReload.java +++ b/src/main/java/com/songoda/epicfurnaces/command/commands/CommandReload.java @@ -1,8 +1,8 @@ package com.songoda.epicfurnaces.command.commands; -import com.songoda.arconix.api.methods.formatting.TextComponent; -import com.songoda.epicfurnaces.EpicFurnacesPlugin; +import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.command.AbstractCommand; +import com.songoda.epicfurnaces.utils.Methods; import org.bukkit.command.CommandSender; public class CommandReload extends AbstractCommand { @@ -12,9 +12,9 @@ public class CommandReload extends AbstractCommand { } @Override - protected ReturnType runCommand(EpicFurnacesPlugin instance, CommandSender sender, String... args) { - instance.reload(); - sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7Configuration and Language files reloaded.")); + protected ReturnType runCommand(EpicFurnaces plugin, CommandSender sender, String... args) { + plugin.reload(); + sender.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&7Configuration and Language files reloaded.")); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/epicfurnaces/command/commands/CommandRemote.java b/src/main/java/com/songoda/epicfurnaces/command/commands/CommandRemote.java index 86a97d3..f9aae3e 100644 --- a/src/main/java/com/songoda/epicfurnaces/command/commands/CommandRemote.java +++ b/src/main/java/com/songoda/epicfurnaces/command/commands/CommandRemote.java @@ -1,8 +1,8 @@ package com.songoda.epicfurnaces.command.commands; -import com.songoda.epicfurnaces.EpicFurnacesPlugin; -import com.songoda.epicfurnaces.api.furnace.Furnace; +import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.command.AbstractCommand; +import com.songoda.epicfurnaces.furnace.Furnace; import org.bukkit.block.Block; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -16,13 +16,13 @@ public class CommandRemote extends AbstractCommand { } @Override - protected ReturnType runCommand(EpicFurnacesPlugin instance, CommandSender sender, String... args) { + protected ReturnType runCommand(EpicFurnaces plugin, CommandSender sender, String... args) { - if (!instance.getConfig().getBoolean("Main.Access Furnaces Remotely") || !sender.hasPermission("EpicFurnaces.Remote")) { - sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.general.nopermission")); + if (!plugin.getConfig().getBoolean("Main.Access Furnaces Remotely") || !sender.hasPermission("EpicFurnaces.Remote")) { + sender.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.general.nopermission")); return ReturnType.FAILURE; } - if (!instance.getDataFile().getConfig().contains("data.charged")) { + if (!plugin.getDataFile().getConfig().contains("data.charged")) { return ReturnType.FAILURE; } if (args.length < 2) return ReturnType.SYNTAX_ERROR; @@ -32,11 +32,11 @@ public class CommandRemote extends AbstractCommand { name.append(" ").append(args[i]); } name = new StringBuilder(name.toString().trim()); - for (Furnace furnace : instance.getFurnaceManager().getFurnaces().values()) { + for (Furnace furnace : plugin.getFurnaceManager().getFurnaces().values()) { if (furnace.getNickname() == null) continue; if (!furnace.getNickname().equalsIgnoreCase(name.toString())) { - sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.general.nopermission")); + sender.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.general.nopermission")); continue; } for (UUID uuid : furnace.getAccessList()) { @@ -50,7 +50,7 @@ public class CommandRemote extends AbstractCommand { } } - sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.remote.notfound")); + sender.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.remote.notfound")); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/epicfurnaces/command/commands/CommandSettings.java b/src/main/java/com/songoda/epicfurnaces/command/commands/CommandSettings.java index eab410a..ff45f0f 100644 --- a/src/main/java/com/songoda/epicfurnaces/command/commands/CommandSettings.java +++ b/src/main/java/com/songoda/epicfurnaces/command/commands/CommandSettings.java @@ -1,6 +1,6 @@ package com.songoda.epicfurnaces.command.commands; -import com.songoda.epicfurnaces.EpicFurnacesPlugin; +import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.command.AbstractCommand; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -12,8 +12,8 @@ public class CommandSettings extends AbstractCommand { } @Override - protected ReturnType runCommand(EpicFurnacesPlugin instance, CommandSender sender, String... args) { - instance.getSettingsManager().openSettingsManager((Player) sender); + protected ReturnType runCommand(EpicFurnaces plugin, CommandSender sender, String... args) { + plugin.getSettingsManager().openSettingsManager((Player) sender); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/epicfurnaces/economy/Economy.java b/src/main/java/com/songoda/epicfurnaces/economy/Economy.java index f28ff95..af3c286 100644 --- a/src/main/java/com/songoda/epicfurnaces/economy/Economy.java +++ b/src/main/java/com/songoda/epicfurnaces/economy/Economy.java @@ -1,4 +1,4 @@ -package com.songoda.epichoppers.economy; +package com.songoda.epicfurnaces.economy; import org.bukkit.OfflinePlayer; diff --git a/src/main/java/com/songoda/epicfurnaces/economy/PlayerPointsEconomy.java b/src/main/java/com/songoda/epicfurnaces/economy/PlayerPointsEconomy.java index dfdfbc7..fcfbaf7 100644 --- a/src/main/java/com/songoda/epicfurnaces/economy/PlayerPointsEconomy.java +++ b/src/main/java/com/songoda/epicfurnaces/economy/PlayerPointsEconomy.java @@ -1,17 +1,16 @@ -package com.songoda.epichoppers.economy; +package com.songoda.epicfurnaces.economy; -import com.songoda.epichoppers.EpicHoppers; +import com.songoda.epicfurnaces.EpicFurnaces; import org.black_ixx.playerpoints.PlayerPoints; import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; public class PlayerPointsEconomy implements Economy { - private final EpicHoppers plugin; + private final EpicFurnaces plugin; private final PlayerPoints playerPoints; - public PlayerPointsEconomy(EpicHoppers plugin) { + public PlayerPointsEconomy(EpicFurnaces plugin) { this.plugin = plugin; this.playerPoints = (PlayerPoints) plugin.getServer().getPluginManager().getPlugin("PlayerPoints"); diff --git a/src/main/java/com/songoda/epicfurnaces/economy/VaultEconomy.java b/src/main/java/com/songoda/epicfurnaces/economy/VaultEconomy.java index efc61e1..ebb6c57 100644 --- a/src/main/java/com/songoda/epicfurnaces/economy/VaultEconomy.java +++ b/src/main/java/com/songoda/epicfurnaces/economy/VaultEconomy.java @@ -1,16 +1,15 @@ -package com.songoda.epichoppers.economy; +package com.songoda.epicfurnaces.economy; -import com.songoda.epichoppers.EpicHoppers; +import com.songoda.epicfurnaces.EpicFurnaces; import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; public class VaultEconomy implements Economy { - private final EpicHoppers plugin; + private final EpicFurnaces plugin; private final net.milkbowl.vault.economy.Economy vault; - public VaultEconomy(EpicHoppers plugin) { + public VaultEconomy(EpicFurnaces plugin) { this.plugin = plugin; this.vault = plugin.getServer().getServicesManager(). diff --git a/src/main/java/com/songoda/epicfurnaces/furnace/Furnace.java b/src/main/java/com/songoda/epicfurnaces/furnace/Furnace.java index 4aaaf28..8f76f33 100644 --- a/src/main/java/com/songoda/epicfurnaces/furnace/Furnace.java +++ b/src/main/java/com/songoda/epicfurnaces/furnace/Furnace.java @@ -2,24 +2,19 @@ package com.songoda.epicfurnaces.furnace; import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.boost.BoostData; -import com.songoda.epicfurnaces.player.PlayerData; -import com.songoda.epicfurnaces.utils.Debugger; +import com.songoda.epicfurnaces.furnace.levels.Level; +import com.songoda.epicfurnaces.gui.GUIOverview; +import com.songoda.epicfurnaces.utils.CostType; import com.songoda.epicfurnaces.utils.Methods; -import net.milkbowl.vault.economy.Economy; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; +import com.songoda.epicfurnaces.utils.ServerVersion; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.entity.Player; import org.bukkit.event.inventory.FurnaceSmeltEvent; import org.bukkit.inventory.FurnaceInventory; -import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.plugin.RegisteredServiceProvider; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; @@ -29,9 +24,9 @@ import java.util.*; /** * Created by songoda on 3/7/2017. */ -public class EFurnace { +public class Furnace { - private final EpicFurnaces instance = EpicFurnaces.getInstance(); + private final EpicFurnaces plugin = EpicFurnaces.getInstance(); private Location location; private Level level; private String nickname; @@ -42,7 +37,7 @@ public class EFurnace { private List accessList = new ArrayList<>(); private Map cache = new HashMap<>(); - public EFurnace(Location location, Level level, String nickname, int uses, int tolevel, List accessList, UUID placedBy) { + public Furnace(Location location, Level level, String nickname, int uses, int tolevel, List accessList, UUID placedBy) { this.location = location; this.level = level; this.uses = uses; @@ -53,445 +48,171 @@ public class EFurnace { this.syncName(); } - public EFurnace(Block block, Level level, String nickname, int uses, int tolevel, List accessList, UUID placedBy) { + public Furnace(Block block, Level level, String nickname, int uses, int tolevel, List accessList, UUID placedBy) { this(block.getLocation(), level, nickname, uses, tolevel, accessList, placedBy); } - public void openOverview(Player p) { - try { - PlayerData playerData = instance.getPlayerDataManager().getPlayerData(p); + public void overview(Player player) { + if (placedBy == null) placedBy = player.getUniqueId(); - if (!p.hasPermission("epicfurnaces.overview")) return; - playerData.setLastFurace(this); - - Level nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel() + 1) : null; - - int multi = instance.getConfig().getInt("Main.Level Cost Multiplier"); - - int needed = (multi * level.getLevel()) - tolevel; - - ItemStack item = new ItemStack(Material.FURNACE, 1); - - ItemMeta itemmeta = item.getItemMeta(); - itemmeta.setDisplayName(instance.getLocale().getMessage("interface.furnace.currentlevel", level.getLevel())); - ArrayList lore = new ArrayList<>(); - lore.add(instance.getLocale().getMessage("interface.furnace.smeltedx", uses)); - lore.addAll(this.level.getDescription()); - lore.add(""); - if (nextLevel == null) - lore.add(instance.getLocale().getMessage("interface.furnace.alreadymaxed")); - else { - lore.add(instance.getLocale().getMessage("interface.furnace.level", nextLevel.getLevel())); - lore.addAll(nextLevel.getDescription()); - - if (instance.getConfig().getBoolean("Main.Upgrade By Smelting Materials")) { - lore.add(instance.getLocale().getMessage("interface.furnace.tolevel", needed, Methods.cleanString(instance.getConfig().getString("Main.Furnace Upgrade Cost")))); - } - } - - BoostData boostData = instance.getBoostManager().getBoost(placedBy); - if (boostData != null) { - String[] parts = instance.getLocale().getMessage("interface.button.boostedstats", Integer.toString(boostData.getMultiplier()), TimeComponent.makeReadable(boostData.getEndTime() - System.currentTimeMillis())).split("\\|"); - lore.add(""); - for (String line : parts) - lore.add(TextComponent.formatText(line)); - } - - itemmeta.setLore(lore); - item.setItemMeta(itemmeta); - - Inventory i = Bukkit.createInventory(null, 27, Arconix.pl().getApi().format().formatText(Methods.formatName(level.getLevel(), 0, false))); - - int nu = 0; - while (nu != 27) { - i.setItem(nu, Methods.getGlass()); - nu++; - } - - - ItemStack item2 = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Performance Icon")), 1); - ItemMeta itemmeta2 = item2.getItemMeta(); - itemmeta2.setDisplayName(instance.getLocale().getMessage("interface.furnace.performancetitle")); //greyed out until available - ArrayList lore2 = new ArrayList<>(); - - String[] parts = instance.getLocale().getMessage("interface.furnace.performanceinfo", level.getPerformance()).split("\\|"); - lore.add(""); - for (String line : parts) { - lore2.add(Arconix.pl().getApi().format().formatText(line)); - } - itemmeta2.setLore(lore2); - item2.setItemMeta(itemmeta2); - - ItemStack item3 = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Reward Icon")), 1); - ItemMeta itemmeta3 = item3.getItemMeta(); - itemmeta3.setDisplayName(instance.getLocale().getMessage("interface.furnace.rewardtitle")); - ArrayList lore3 = new ArrayList<>(); - - parts = instance.getLocale().getMessage("interface.furnace.rewardinfo", level.getReward().split(":")[0].replace("%", "")).split("\\|"); - lore.add(""); - for (String line : parts) { - lore3.add(Arconix.pl().getApi().format().formatText(line)); - } - itemmeta3.setLore(lore3); - item3.setItemMeta(itemmeta3); - - - ItemStack item4 = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.FuelDuration Icon")), 1); - ItemMeta itemmeta4 = item4.getItemMeta(); - itemmeta4.setDisplayName(instance.getLocale().getMessage("interface.furnace.fueldurationtitle")); - ArrayList lore4 = new ArrayList<>(); - - parts = instance.getLocale().getMessage("interface.furnace.fueldurationinfo", level.getFuelDuration()).split("\\|"); - lore.add(""); - for (String line : parts) { - lore4.add(Arconix.pl().getApi().format().formatText(line)); - } - itemmeta4.setLore(lore4); - item4.setItemMeta(itemmeta4); - - ItemStack item5 = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Overheat Icon")), 1); - ItemMeta itemmeta5 = item4.getItemMeta(); - itemmeta5.setDisplayName(instance.getLocale().getMessage("interface.furnace.overheattitle")); - ArrayList lore5 = new ArrayList<>(); - - parts = instance.getLocale().getMessage("interface.furnace.overheatinfo", level.getOverheat() * 3).split("\\|"); - lore.add(""); - for (String line : parts) { - lore5.add(Arconix.pl().getApi().format().formatText(line)); - } - itemmeta5.setLore(lore5); - item5.setItemMeta(itemmeta5); - - ItemStack item6 = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.FuelShare Icon")), 1); - ItemMeta itemmeta6 = item4.getItemMeta(); - itemmeta6.setDisplayName(instance.getLocale().getMessage("interface.furnace.fuelsharetitle")); - ArrayList lore6 = new ArrayList<>(); - - parts = instance.getLocale().getMessage("interface.furnace.fuelshareinfo", level.getOverheat() * 3).split("\\|"); - lore.add(""); - for (String line : parts) { - lore6.add(Arconix.pl().getApi().format().formatText(line)); - } - itemmeta6.setLore(lore6); - item6.setItemMeta(itemmeta6); - - ItemStack itemXP = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.XP Icon")), 1); - ItemMeta itemmetaXP = itemXP.getItemMeta(); - itemmetaXP.setDisplayName(instance.getLocale().getMessage("interface.furnace.upgradewithxp")); - ArrayList loreXP = new ArrayList<>(); - if (nextLevel != null) - loreXP.add(instance.getLocale().getMessage("interface.furnace.upgradewithxplore", level.getCostExperiance())); - else - loreXP.add(instance.getLocale().getMessage("interface.furnace.alreadymaxed")); - itemmetaXP.setLore(loreXP); - itemXP.setItemMeta(itemmetaXP); - - ItemStack itemECO = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Economy Icon")), 1); - ItemMeta itemmetaECO = itemECO.getItemMeta(); - itemmetaECO.setDisplayName(instance.getLocale().getMessage("interface.furnace.upgradewitheconomy")); - ArrayList loreECO = new ArrayList<>(); - if (nextLevel != null) - loreECO.add(instance.getLocale().getMessage("interface.furnace.upgradewitheconomylore", Arconix.pl().getApi().format().formatEconomy(level.getCostEconomy()))); - else - loreECO.add(instance.getLocale().getMessage("interface.furnace.alreadymaxed")); - itemmetaECO.setLore(loreECO); - itemECO.setItemMeta(itemmetaECO); - - i.setItem(13, item); - - i.setItem(0, Methods.getBackgroundGlass(true)); - i.setItem(1, Methods.getBackgroundGlass(true)); - i.setItem(2, Methods.getBackgroundGlass(false)); - i.setItem(6, Methods.getBackgroundGlass(false)); - i.setItem(7, Methods.getBackgroundGlass(true)); - i.setItem(8, Methods.getBackgroundGlass(true)); - i.setItem(9, Methods.getBackgroundGlass(true)); - i.setItem(10, Methods.getBackgroundGlass(false)); - i.setItem(16, Methods.getBackgroundGlass(false)); - i.setItem(17, Methods.getBackgroundGlass(true)); - i.setItem(18, Methods.getBackgroundGlass(true)); - i.setItem(19, Methods.getBackgroundGlass(true)); - i.setItem(20, Methods.getBackgroundGlass(false)); - i.setItem(24, Methods.getBackgroundGlass(false)); - i.setItem(25, Methods.getBackgroundGlass(true)); - i.setItem(26, Methods.getBackgroundGlass(true)); - - int num = -1; - Map spots = new HashMap(); - - int[] s1 = {22}; - spots.put(0, s1); - int[] s2 = {21, 23}; - spots.put(1, s2); - int[] s3 = {21, 22, 23}; - spots.put(2, s3); - int[] s4 = {20, 21, 23, 24}; - spots.put(3, s4); - int[] s5 = {20, 21, 22, 23, 24}; - spots.put(4, s5); - - if (level.getPerformance() != 0) { - num ++; - } - if (level.getReward() != null) { - num ++; - } - if (level.getFuelDuration() != 0) { - num ++; - } - if (level.getFuelShare() != 0) { - num ++; - } - if (level.getOverheat() != 0) { - num ++; - } - - int[] order = spots.get(num); - - int current = 0; - - if (level.getPerformance() != 0) { - i.setItem(order[current], item2); - current ++; - } - if (level.getReward() != null) { - i.setItem(order[current], item3); - current ++; - } - if (level.getFuelDuration() != 0) { - i.setItem(order[current], item4); - current ++; - } - if (level.getFuelShare() != 0) { - i.setItem(order[current], item6); - current ++; - } - if (level.getOverheat() != 0) { - i.setItem(order[current], item5); - } - - ItemStack hook = new ItemStack(Material.TRIPWIRE_HOOK, 1); - ItemMeta hookmeta = hook.getItemMeta(); - hookmeta.setDisplayName(instance.getLocale().getMessage("interface.furnace.remotefurnace")); - ArrayList lorehook = new ArrayList<>(); - - parts = instance.getLocale().getMessage("interface.furnace.remotefurnacelore", nickname == null ? "Unset" : nickname).split("\\|"); - - for (String line : parts) { - lorehook.add(Arconix.pl().getApi().format().formatText(line)); - } - if (nickname != null) { - parts = instance.getLocale().getMessage("interface.furnace.utilize", nickname).split("\\|"); - for (String line : parts) { - lorehook.add(Arconix.pl().getApi().format().formatText(line)); - } - } - - for (String line : accessList) { - lorehook.add(""); - lorehook.add(instance.getLocale().getMessage("interface.furnace.remotelist")); - String[] halfs = line.split(":"); - String name = halfs[1]; - Player player = Bukkit.getPlayer(halfs[0]); - if (player != null) { - name = player.getDisplayName(); - } - lorehook.add(Arconix.pl().getApi().format().formatText("&6" + name)); - } - hookmeta.setLore(lorehook); - hook.setItemMeta(hookmeta); - - if (instance.getConfig().getBoolean("Main.Access Furnaces Remotely") && p.hasPermission("EpicFurnaces.Remote")) { - i.setItem(4, hook); - } - - i.setItem(13, item); - - if (instance.getConfig().getBoolean("Main.Upgrade With XP") && p.hasPermission("EpicFurnaces.Upgrade.XP")) { - i.setItem(11, itemXP); - } - if (instance.getConfig().getBoolean("Main.Upgrade With Economy") && p.hasPermission("EpicFurnaces.Upgrade.ECO")) { - i.setItem(15, itemECO); - } - - p.openInventory(i); - playerData.setInOverview(true); - } catch (Exception e) { - Debugger.runReport(e); - } + if (!player.hasPermission("epicfurnaces.overview")) return; + new GUIOverview(plugin, this, player); } public void plus(FurnaceSmeltEvent e) { - try { - Block block = location.getBlock(); - if (block.getType() != Material.FURNACE) return; + Block block = location.getBlock(); + if (block.getType() != Material.FURNACE) return; - this.uses ++; - this.tolevel ++; + this.uses++; + this.tolevel++; - int multi = instance.getConfig().getInt("Main.Level Cost Multiplier"); + int multi = plugin.getConfig().getInt("Main.Level Cost Multiplier"); - if (level.getReward() == null) return; + if (level.getReward() == null) return; - String reward = level.getReward(); - String amt[] = {"1", "1"}; - if (reward.contains(":")) { - String[] rewardSplit = reward.split(":"); - reward = rewardSplit[0].substring(0, rewardSplit[0].length() - 1); - if (rewardSplit[1].contains("-")) - amt = rewardSplit[1].split("-"); - else { - amt[0] = rewardSplit[1]; - amt[1] = rewardSplit[0]; - } + String reward = level.getReward(); + String[] amt = {"1", "1"}; + if (reward.contains(":")) { + String[] rewardSplit = reward.split(":"); + reward = rewardSplit[0].substring(0, rewardSplit[0].length() - 1); + if (rewardSplit[1].contains("-")) + amt = rewardSplit[1].split("-"); + else { + amt[0] = rewardSplit[1]; + amt[1] = rewardSplit[0]; } - - - int needed = ((multi * level.getLevel()) - tolevel) - 1; - - if (instance.getConfig().getBoolean("Main.Upgrade By Smelting Materials") - && needed <= 0 - && instance.getConfig().contains("settings.levels.Level-" + (level.getLevel() + 1))) { - tolevel = 0; - level = instance.getLevelManager().getLevel(this.level.getLevel() + 1); - } - - this.updateCook(); - - FurnaceInventory i = (FurnaceInventory) ((InventoryHolder) block.getState()).getInventory(); - - int num = Integer.parseInt(reward); - double rand = Math.random() * 100; - if (rand >= num - || e.getResult().equals(Material.SPONGE) - || instance.getConfig().getBoolean("Main.No Rewards From Custom Recipes") - && instance.getFurnaceRecipeFile().getConfig().contains("Recipes." + i.getSmelting().getType().toString())) { - return; - } - - int r = Integer.parseInt(amt[0]); - if (Integer.parseInt(amt[0]) != - Integer.parseInt(amt[1].replace("%", ""))) - r = (int) (Math.random() * ((Integer.parseInt(amt[1].replace("%", "")) - Integer.parseInt(amt[0])))) + Integer.parseInt(amt[0]); - - BoostData boostData = instance.getBoostManager().getBoost(placedBy); - r = r * (boostData == null ? 1 : boostData.getMultiplier()); - - - if (e.getResult() != null) { - e.getResult().setAmount(e.getResult().getAmount() + r); - return; - } - - e.setResult(new ItemStack(e.getResult().getType(), r)); - } catch (Exception ex) { - Debugger.runReport(ex); } + + + int needed = ((multi * level.getLevel()) - tolevel) - 1; + + if (plugin.getConfig().getBoolean("Main.Upgrade By Smelting Materials") + && needed <= 0 + && plugin.getConfig().contains("settings.levels.Level-" + (level.getLevel() + 1))) { + tolevel = 0; + level = plugin.getLevelManager().getLevel(this.level.getLevel() + 1); + } + + this.updateCook(); + + FurnaceInventory i = (FurnaceInventory) ((InventoryHolder) block.getState()).getInventory(); + + int num = Integer.parseInt(reward); + double rand = Math.random() * 100; + if (rand >= num + || e.getResult().equals(Material.SPONGE) + || plugin.getConfig().getBoolean("Main.No Rewards From Custom Recipes") + && plugin.getFurnaceRecipeFile().getConfig().contains("Recipes." + i.getSmelting().getType().toString())) { + return; + } + + int r = Integer.parseInt(amt[0]); + if (Integer.parseInt(amt[0]) != + Integer.parseInt(amt[1].replace("%", ""))) + r = (int) (Math.random() * ((Integer.parseInt(amt[1].replace("%", "")) - Integer.parseInt(amt[0])))) + Integer.parseInt(amt[0]); + + BoostData boostData = plugin.getBoostManager().getBoost(placedBy); + r = r * (boostData == null ? 1 : boostData.getMultiplier()); + + + if (e.getResult() != null) { + e.getResult().setAmount(e.getResult().getAmount() + r); + return; + } + + e.setResult(new ItemStack(e.getResult().getType(), r)); } - public void upgrade(String type, Player player) { - try { - if (!instance.getLevelManager().getLevels().containsKey(this.level.getLevel() + 1)) - return; + public void upgrade(Player player, CostType type) { + if (plugin.getLevelManager().getLevels().containsKey(this.level.getLevel() + 1)) { - int cost; - if (type.equals("XP")) { - cost = level.getCostExperiance(); - } else { - cost = level.getCostEconomy(); - } - Level level = instance.getLevelManager().getLevel(this.level.getLevel() + 1); + Level level = plugin.getLevelManager().getLevel(this.level.getLevel() + 1); + int cost = type == CostType.ECONOMY ? level.getCostEconomy() : level.getCostExperience(); - if (type.equals("ECO")) { - if (instance.getServer().getPluginManager().getPlugin("Vault") != null) { - RegisteredServiceProvider rsp = instance.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); - net.milkbowl.vault.economy.Economy econ = rsp.getProvider(); - if (econ.has(player, cost)) { - econ.withdrawPlayer(player, cost); - upgradeFinal(level, player); - } else { - player.sendMessage(instance.getLocale().getMessage("event.upgrade.cannotafford")); - } - } else { - player.sendMessage("Vault is not installed."); + if (type == CostType.ECONOMY) { + if (plugin.getEconomy() == null) { + player.sendMessage("Economy not enabled."); + return; } - } else if (type.equals("XP")) { + if (!plugin.getEconomy().hasBalance(player, cost)) { + player.sendMessage(plugin.getReferences().getPrefix() + EpicFurnaces.getInstance().getLocale().getMessage("event.upgrade.cannotafford")); + return; + } + plugin.getEconomy().withdrawBalance(player, cost); + upgradeFinal(level, player); + } else if (type == CostType.EXPERIENCE) { if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) { if (player.getGameMode() != GameMode.CREATIVE) { player.setLevel(player.getLevel() - cost); } upgradeFinal(level, player); } else { - player.sendMessage(instance.getLocale().getMessage("event.upgrade.cannotafford")); + player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.upgrade.cannotafford")); } } - } catch (Exception ex) { - Debugger.runReport(ex); } } private void upgradeFinal(Level level, Player player) { - try { - this.level = level; - syncName(); - if (instance.getLevelManager().getHighestLevel() != level) { - player.sendMessage(instance.getLocale().getMessage("event.upgrade.success", level.getLevel())); - } else { - player.sendMessage(instance.getLocale().getMessage("event.upgrade.maxed", level.getLevel())); - } - Location loc = location.clone().add(.5, .5, .5); + this.level = level; + syncName(); + if (plugin.getLevelManager().getHighestLevel() != level) { + player.sendMessage(plugin.getLocale().getMessage("event.upgrade.success", level.getLevel())); + } else { + player.sendMessage(plugin.getLocale().getMessage("event.upgrade.maxed", level.getLevel())); + } + Location loc = location.clone().add(.5, .5, .5); - player.getWorld().spawnParticle(org.bukkit.Particle.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), loc, 200, .5, .5, .5); - if (instance.getConfig().getBoolean("Main.Use Sounds")) { - if (instance.getLevelManager().getHighestLevel() == level) { - player.playSound(player.getLocation(), org.bukkit.Sound.ENTITY_PLAYER_LEVELUP, 0.6F, 15.0F); - } else { - player.playSound(player.getLocation(), org.bukkit.Sound.ENTITY_PLAYER_LEVELUP, 2F, 25.0F); - player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_BLOCK_CHIME, 2F, 25.0F); - Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_BLOCK_CHIME, 1.2F, 35.0F), 5L); - Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_BLOCK_CHIME, 1.8F, 35.0F), 10L); - } - } - } catch (Exception ex) { - Debugger.runReport(ex); + if (!plugin.isServerVersionAtLeast(ServerVersion.V1_12)) return; + + player.getWorld().spawnParticle(org.bukkit.Particle.valueOf(plugin.getConfig().getString("Main.Upgrade Particle Type")), loc, 200, .5, .5, .5); + + if (plugin.getLevelManager().getHighestLevel() != level) { + player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.6F, 15.0F); + } else { + player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 2F, 25.0F); + + if (!plugin.isServerVersionAtLeast(ServerVersion.V1_13)) return; + + player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 2F, 25.0F); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1.2F, 35.0F), 5L); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1.8F, 35.0F), 10L); } } private void syncName() { if (!(location.getBlock() instanceof Furnace)) return; org.bukkit.block.Furnace furnace = (org.bukkit.block.Furnace) location.getBlock().getState(); - furnace.setCustomName(Methods.formatName(level.getLevel(), uses, false)); + if (EpicFurnaces.getInstance().isServerVersionAtLeast(ServerVersion.V1_10)) + furnace.setCustomName(Methods.formatName(level.getLevel(), uses, false)); furnace.update(true); } public void updateCook() { - try { - Block block = location.getBlock(); - if (block == null || block.getType() != Material.FURNACE) return; - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(instance, () -> { - int num = getPerformanceTotal(); + Block block = location.getBlock(); + if (block == null + || block.getType() != Material.FURNACE && !block.getType().name().equals("BURNING_FURNACE")) return; - if (num > 200) { - num = 200; - } + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { + int num = getPerformanceTotal(); - if (num != 0) { - BlockState bs = (block.getState()); // max is 200 - ((org.bukkit.block.Furnace) bs).setCookTime(Short.parseShort(Integer.toString(num))); - bs.update(); - } - }, 1L); - } catch (Exception e) { - Debugger.runReport(e); - } + if (num > 200) + num = 200; + + if (num != 0) { + BlockState bs = (block.getState()); // max is 200 + ((org.bukkit.block.Furnace) bs).setCookTime(Short.parseShort(Integer.toString(num))); + bs.update(); + } + }, 1L); } - + public Level getLevel() { return level; } - + public List getAccessList() { List list = new ArrayList<>(); for (String line : accessList) { @@ -502,7 +223,11 @@ public class EFurnace { return list; } - + public List getRawAccessList() { + return new ArrayList<>(accessList); + } + + public int getPerformanceTotal() { String equation = "(" + level.getPerformance() + " / 100) * 200"; try { @@ -516,52 +241,51 @@ public class EFurnace { return cache.get(equation); } } catch (ScriptException e) { - Debugger.runReport(e); + e.printStackTrace(); } return 0; } - + public List getOriginalAccessList() { return Collections.unmodifiableList(accessList); } - - public boolean addToAccessList(String string) { - return accessList.add(string); + + public boolean addToAccessList(Player player) { + String formatted = player.getUniqueId().toString() + ":" + player.getName(); + if (accessList.contains(formatted)) return false; + return accessList.add(formatted); } - + public boolean removeFromAccessList(String string) { return accessList.remove(string); } - + public void clearAccessList() { accessList.clear(); } - + public Location getLocation() { return location.clone(); } - + public String getNickname() { return nickname; } - - public UUID getPlacedBy() { - return placedBy; - } - - public void setNickname(String nickname) { this.nickname = nickname; } - + public UUID getPlacedBy() { + return placedBy; + } + public List getRadius(boolean overHeat) { if (overHeat) return radiusOverheat.isEmpty() ? null : Collections.unmodifiableList(radiusOverheat); @@ -570,7 +294,7 @@ public class EFurnace { } - + public void addToRadius(Location location, boolean overHeat) { if (overHeat) radiusOverheat.add(location); @@ -579,7 +303,7 @@ public class EFurnace { } - + public void clearRadius(boolean overHeat) { if (overHeat) radiusOverheat.clear(); @@ -587,7 +311,7 @@ public class EFurnace { radiusFuelshare.clear(); } - + public int getRadiusLast(boolean overHeat) { if (overHeat) return radiusOverheatLast; @@ -595,7 +319,7 @@ public class EFurnace { return radiusFuelshareLast; } - + public void setRadiusLast(int radiusLast, boolean overHeat) { if (overHeat) this.radiusOverheatLast = radiusLast; @@ -603,12 +327,12 @@ public class EFurnace { this.radiusFuelshareLast = radiusLast; } - + public int getUses() { return uses; } - + public int getTolevel() { return tolevel; } diff --git a/src/main/java/com/songoda/epicfurnaces/furnace/FurnaceManager.java b/src/main/java/com/songoda/epicfurnaces/furnace/FurnaceManager.java index 6135457..a1840e0 100644 --- a/src/main/java/com/songoda/epicfurnaces/furnace/FurnaceManager.java +++ b/src/main/java/com/songoda/epicfurnaces/furnace/FurnaceManager.java @@ -1,8 +1,6 @@ package com.songoda.epicfurnaces.furnace; import com.songoda.epicfurnaces.EpicFurnaces; -import com.songoda.epicfurnaces.api.furnace.Furnace; -import com.songoda.epicfurnaces.api.furnace.FurnaceManager; import org.bukkit.Location; import org.bukkit.block.Block; @@ -11,34 +9,30 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -public class EFurnaceManager implements FurnaceManager { +public class FurnaceManager { private final Map registeredFurnaces = new HashMap<>(); - @Override - public void addFurnace(Location location, Furnace furnace) { - registeredFurnaces.put(roundLocation(location), furnace); + + public Furnace addFurnace(Location location, Furnace furnace) { + return registeredFurnaces.put(roundLocation(location), furnace); } - @Override public Furnace removeFurnace(Location location) { return registeredFurnaces.remove(location); } - @Override public Furnace getFurnace(Location location) { if (!registeredFurnaces.containsKey(location)) { - addFurnace(location, new EFurnace(location, EpicFurnaces.getInstance().getLevelManager().getLowestLevel(), null, 0, 0, new ArrayList<>(), null)); + addFurnace(location, new Furnace(location, EpicFurnaces.getInstance().getLevelManager().getLowestLevel(), null, 0, 0, new ArrayList<>(), null)); } return registeredFurnaces.get(location); } - @Override public Furnace getFurnace(Block block) { return getFurnace(block.getLocation()); } - @Override public Map getFurnaces() { return Collections.unmodifiableMap(registeredFurnaces); } diff --git a/src/main/java/com/songoda/epicfurnaces/furnace/levels/Level.java b/src/main/java/com/songoda/epicfurnaces/furnace/levels/Level.java index b6256b5..2850356 100644 --- a/src/main/java/com/songoda/epicfurnaces/furnace/levels/Level.java +++ b/src/main/java/com/songoda/epicfurnaces/furnace/levels/Level.java @@ -1,22 +1,21 @@ -package com.songoda.epicfurnaces.furnace; +package com.songoda.epicfurnaces.furnace.levels; import com.songoda.epicfurnaces.EpicFurnaces; -import com.songoda.epicfurnaces.api.furnace.Level; import java.util.ArrayList; import java.util.List; -public class Level implements Level { +public class Level { - private int level, costExperiance, costEconomy, performance, fuelDuration, overheat, fuelShare; + private int level, costExperience, costEconomy, performance, fuelDuration, overheat, fuelShare; private String reward; private List description = new ArrayList<>(); - Level(int level, int costExperiance, int costEconomy, int performance, String reward, int fuelDuration, int overheat, int fuelShare) { + Level(int level, int costExperience, int costEconomy, int performance, String reward, int fuelDuration, int overheat, int fuelShare) { this.level = level; - this.costExperiance = costExperiance; + this.costExperience = costExperience; this.costEconomy = costEconomy; this.performance = performance; this.reward = reward; @@ -24,65 +23,65 @@ public class Level implements Level { this.overheat = overheat; this.fuelShare = fuelShare; - EpicFurnaces instance = EpicFurnaces.getInstance(); + EpicFurnaces plugin = EpicFurnaces.getInstance(); if (performance != 0) - description.add(instance.getLocale().getMessage("interface.furnace.performance", performance + "%")); + description.add(plugin.getLocale().getMessage("interface.furnace.performance", performance + "%")); if (reward != null) - description.add(instance.getLocale().getMessage("interface.furnace.reward", reward.split("%:")[0] + "%")); + description.add(plugin.getLocale().getMessage("interface.furnace.reward", reward.split("%:")[0] + "%")); if (fuelDuration != 0) - description.add(instance.getLocale().getMessage("interface.furnace.fuelduration", fuelDuration + "%")); + description.add(plugin.getLocale().getMessage("interface.furnace.fuelduration", fuelDuration + "%")); if (fuelShare != 0) - description.add(instance.getLocale().getMessage("interface.furnace.fuelshare", fuelShare)); + description.add(plugin.getLocale().getMessage("interface.furnace.fuelshare", fuelShare)); if (overheat != 0) - description.add(instance.getLocale().getMessage("interface.furnace.overheat", overheat)); + description.add(plugin.getLocale().getMessage("interface.furnace.overheat", overheat)); } - @Override + public List getDescription() { return new ArrayList<>(description); } - @Override + public int getLevel() { return level; } - @Override + public int getPerformance() { return performance; } - @Override + public String getReward() { return reward; } - @Override + public int getOverheat() { return overheat; } - @Override + public int getFuelShare() { return fuelShare; } - @Override + public int getFuelDuration() { return fuelDuration; } - @Override - public int getCostExperiance() { - return costExperiance; + + public int getCostExperience() { + return costExperience; } - @Override + public int getCostEconomy() { return costEconomy; } diff --git a/src/main/java/com/songoda/epicfurnaces/furnace/levels/LevelManager.java b/src/main/java/com/songoda/epicfurnaces/furnace/levels/LevelManager.java index 09420a5..90a1ddc 100644 --- a/src/main/java/com/songoda/epicfurnaces/furnace/levels/LevelManager.java +++ b/src/main/java/com/songoda/epicfurnaces/furnace/levels/LevelManager.java @@ -1,48 +1,45 @@ -package com.songoda.epicfurnaces.furnace; - -import com.songoda.epicfurnaces.api.furnace.Level; -import com.songoda.epicfurnaces.api.furnace.LevelManager; +package com.songoda.epicfurnaces.furnace.levels; import java.util.Collections; import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; -public class LevelManager implements LevelManager { +public class LevelManager { private final NavigableMap registeredLevels = new TreeMap<>(); - @Override + public void addLevel(int level, int costExperiance, int costEconomy, int performance, String reward, int fuelDuration, int overheat, int fuelShare) { registeredLevels.put(level, new Level(level, costExperiance, costEconomy, performance, reward, fuelDuration, overheat, fuelShare)); } - @Override + public Level getLevel(int level) { return registeredLevels.get(level); } - @Override + public Level getLowestLevel() { return registeredLevels.firstEntry().getValue(); } - @Override + public Level getHighestLevel() { return registeredLevels.lastEntry().getValue(); } - @Override + public boolean isLevel(int level) { return registeredLevels.containsKey(level); } - @Override + public Map getLevels() { return Collections.unmodifiableMap(registeredLevels); } - @Override + public void clear() { registeredLevels.clear(); } diff --git a/src/main/java/com/songoda/epicfurnaces/gui/GUIOverview.java b/src/main/java/com/songoda/epicfurnaces/gui/GUIOverview.java index d69ecbe..591eb40 100644 --- a/src/main/java/com/songoda/epicfurnaces/gui/GUIOverview.java +++ b/src/main/java/com/songoda/epicfurnaces/gui/GUIOverview.java @@ -1,16 +1,13 @@ -package com.songoda.epichoppers.gui; +package com.songoda.epicfurnaces.gui; -import com.songoda.epichoppers.EpicHoppers; -import com.songoda.epichoppers.boost.BoostData; -import com.songoda.epichoppers.hopper.Hopper; -import com.songoda.epichoppers.hopper.levels.Level; -import com.songoda.epichoppers.hopper.levels.modules.Module; -import com.songoda.epichoppers.player.SyncType; -import com.songoda.epichoppers.utils.CostType; -import com.songoda.epichoppers.utils.Methods; -import com.songoda.epichoppers.utils.ServerVersion; -import com.songoda.epichoppers.utils.TeleportTrigger; -import com.songoda.epichoppers.utils.gui.AbstractGUI; +import com.songoda.epicfurnaces.EpicFurnaces; +import com.songoda.epicfurnaces.boost.BoostData; +import com.songoda.epicfurnaces.furnace.Furnace; +import com.songoda.epicfurnaces.furnace.levels.Level; +import com.songoda.epicfurnaces.utils.CostType; +import com.songoda.epicfurnaces.utils.Methods; +import com.songoda.epicfurnaces.utils.gui.AbstractAnvilGUI; +import com.songoda.epicfurnaces.utils.gui.AbstractGUI; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -20,78 +17,60 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.stream.Collectors; public class GUIOverview extends AbstractGUI { - private final EpicHoppers plugin; - private final Hopper hopper; + private final EpicFurnaces plugin; + private final Furnace furnace; private int task; - public GUIOverview(EpicHoppers plugin, Hopper hopper, Player player) { + public GUIOverview(EpicFurnaces plugin, Furnace furnace, Player player) { super(player); this.plugin = plugin; - this.hopper = hopper; + this.furnace = furnace; - init(Methods.formatName(hopper.getLevel().getLevel(), false), 27); + init(Methods.formatName(furnace.getLevel().getLevel(), furnace.getUses(), false), 27); runTask(); } @Override - protected void constructGUI() { + public void constructGUI() { inventory.clear(); resetClickables(); registerClickables(); - plugin.getPlayerDataManager().getPlayerData(player).setLastHopper(hopper); - - Level level = hopper.getLevel(); - + Level level = furnace.getLevel(); Level nextLevel = plugin.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? plugin.getLevelManager().getLevel(level.getLevel() + 1) : null; - ItemStack perl = new ItemStack(Material.ENDER_PEARL, 1); - ItemMeta perlmeta = perl.getItemMeta(); - perlmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.perltitle")); - ArrayList loreperl = new ArrayList<>(); - String[] parts = plugin.getLocale().getMessage("interface.hopper.perllore2", hopper.getTeleportTrigger() == TeleportTrigger.DISABLED ? plugin.getLocale().getMessage("general.word.disabled") : hopper.getTeleportTrigger().name()).split("\\|"); - for (String line : parts) { - loreperl.add(Methods.formatText(line)); - } - perlmeta.setLore(loreperl); - perl.setItemMeta(perlmeta); + int multi = plugin.getConfig().getInt("Main.Level Cost Multiplier"); - ItemStack filter = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.COMPARATOR : Material.valueOf("REDSTONE_COMPARATOR"), 1); - ItemMeta filtermeta = filter.getItemMeta(); - filtermeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.filtertitle")); - ArrayList lorefilter = new ArrayList<>(); - parts = plugin.getLocale().getMessage("interface.hopper.filterlore").split("\\|"); - for (String line : parts) { - lorefilter.add(Methods.formatText(line)); - } - filtermeta.setLore(lorefilter); - filter.setItemMeta(filtermeta); + int needed = (multi * level.getLevel()) - furnace.getTolevel(); + ItemStack item = new ItemStack(Material.FURNACE, 1); - ItemStack item = new ItemStack(Material.HOPPER, 1); ItemMeta itemmeta = item.getItemMeta(); - itemmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.currentlevel", level.getLevel())); - List lore = level.getDescription(); - if (plugin.getConfig().getBoolean("Main.Allow hopper Upgrading")) { - lore.add(""); - if (nextLevel == null) lore.add(plugin.getLocale().getMessage("interface.hopper.alreadymaxed")); - else { - lore.add(plugin.getLocale().getMessage("interface.hopper.nextlevel", nextLevel.getLevel())); - lore.addAll(nextLevel.getDescription()); + itemmeta.setDisplayName(plugin.getLocale().getMessage("interface.furnace.currentlevel", level.getLevel())); + ArrayList lore = new ArrayList<>(); + lore.add(plugin.getLocale().getMessage("interface.furnace.smeltedx", furnace.getUses())); + lore.addAll(level.getDescription()); + lore.add(""); + if (nextLevel == null) + lore.add(plugin.getLocale().getMessage("interface.furnace.alreadymaxed")); + else { + lore.add(plugin.getLocale().getMessage("interface.furnace.level", nextLevel.getLevel())); + lore.addAll(nextLevel.getDescription()); + + if (plugin.getConfig().getBoolean("Main.Upgrade By Smelting Materials")) { + lore.add(plugin.getLocale().getMessage("interface.furnace.tolevel", needed, Methods.cleanString(plugin.getConfig().getString("Main.Furnace Upgrade Cost")))); } } - BoostData boostData = plugin.getBoostManager().getBoost(hopper.getPlacedBy()); + BoostData boostData = plugin.getBoostManager().getBoost(furnace.getPlacedBy()); if (boostData != null) { - parts = plugin.getLocale().getMessage("interface.hopper.boostedstats", Integer.toString(boostData.getMultiplier()), Methods.makeReadable(boostData.getEndTime() - System.currentTimeMillis())).split("\\|"); + String[] parts = plugin.getLocale().getMessage("interface.button.boostedstats", Integer.toString(boostData.getMultiplier()), Methods.makeReadable(boostData.getEndTime() - System.currentTimeMillis())).split("\\|"); lore.add(""); for (String line : parts) lore.add(Methods.formatText(line)); @@ -100,111 +79,100 @@ public class GUIOverview extends AbstractGUI { itemmeta.setLore(lore); item.setItemMeta(itemmeta); - ItemStack hook = new ItemStack(Material.TRIPWIRE_HOOK, 1); - ItemMeta hookmeta = hook.getItemMeta(); - hookmeta.setDisplayName(plugin.getLocale().getMessage("interface.hopper.synchopper")); - ArrayList lorehook = new ArrayList<>(); - parts = plugin.getLocale().getMessage("interface.hopper.synclore", hopper.getLinkedBlocks().stream().distinct().count()).split("\\|"); - for (String line : parts) { - lorehook.add(Methods.formatText(line)); - } - hookmeta.setLore(lorehook); - hook.setItemMeta(hookmeta); - int nu = 0; while (nu != 27) { inventory.setItem(nu, Methods.getGlass()); nu++; } - Map layouts = new HashMap<>(); - layouts.put(1, new Integer[]{22}); - layouts.put(2, new Integer[]{22, 4}); - layouts.put(3, new Integer[]{22, 3, 5}); - layouts.put(4, new Integer[]{23, 3, 5, 21}); - layouts.put(5, new Integer[]{23, 3, 5, 21, 22}); - layouts.put(6, new Integer[]{23, 3, 4, 5, 21, 22}); - layouts.put(7, new Integer[]{23, 3, 4, 5, 21, 22, 12}); - layouts.put(8, new Integer[]{23, 3, 4, 5, 21, 22, 12, 14}); - int amount = 1; + ItemStack item2 = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Performance Icon")), 1); + ItemMeta itemmeta2 = item2.getItemMeta(); + itemmeta2.setDisplayName(plugin.getLocale().getMessage("interface.furnace.performancetitle")); //greyed out until available + ArrayList lore2 = new ArrayList<>(); - boolean canFilter = level.isFilter() || player.hasPermission("EpicHoppers.Filter"); - boolean canTeleport = level.isTeleport() || player.hasPermission("EpicHoppers.Teleport"); - if (canFilter) amount++; - if (canTeleport) amount++; - - List modules = level.getRegisteredModules().stream().filter(module -> - module.getGUIButton(hopper) != null).collect(Collectors.toList()); - - amount += modules.size(); - - Integer[] layout = layouts.get(amount); - - for (int ii = 0; ii < amount; ii++) { - int slot = layout[ii]; - - if (ii == 0) { - inventory.setItem(slot, hook); - } else if (canTeleport) { - inventory.setItem(slot, perl); - canTeleport = false; - } else if (canFilter) { - inventory.setItem(slot, filter); - canFilter = false; - } else { - if (modules.isEmpty()) break; - Module module = modules.get(0); - modules.remove(module); - inventory.setItem(slot, module.getGUIButton(hopper)); - } + String[] parts = plugin.getLocale().getMessage("interface.furnace.performanceinfo", level.getPerformance()).split("\\|"); + lore.add(""); + for (String line : parts) { + lore2.add(Methods.formatText(line)); } + itemmeta2.setLore(lore2); + item2.setItemMeta(itemmeta2); - if (plugin.getConfig().getBoolean("Main.Allow hopper Upgrading")) { - ItemStack itemXP = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.XP Icon")), 1); - ItemMeta itemmetaXP = itemXP.getItemMeta(); - itemmetaXP.setDisplayName(plugin.getLocale().getMessage("interface.hopper.upgradewithxp")); - ArrayList loreXP = new ArrayList<>(); - if (nextLevel != null) - loreXP.add(plugin.getLocale().getMessage("interface.hopper.upgradewithxplore", nextLevel.getCostExperience())); - else - loreXP.add(plugin.getLocale().getMessage("interface.hopper.alreadymaxed")); - itemmetaXP.setLore(loreXP); - itemXP.setItemMeta(itemmetaXP); + ItemStack item3 = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Reward Icon")), 1); + ItemMeta itemmeta3 = item3.getItemMeta(); + itemmeta3.setDisplayName(plugin.getLocale().getMessage("interface.furnace.rewardtitle")); + ArrayList lore3 = new ArrayList<>(); - ItemStack itemECO = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Economy Icon")), 1); - ItemMeta itemmetaECO = itemECO.getItemMeta(); - itemmetaECO.setDisplayName(plugin.getLocale().getMessage("interface.hopper.upgradewitheconomy")); - ArrayList loreECO = new ArrayList<>(); - if (nextLevel != null) - loreECO.add(plugin.getLocale().getMessage("interface.hopper.upgradewitheconomylore", Methods.formatEconomy(nextLevel.getCostEconomy()))); - else - loreECO.add(plugin.getLocale().getMessage("interface.hopper.alreadymaxed")); - itemmetaECO.setLore(loreECO); - itemECO.setItemMeta(itemmetaECO); - - if (plugin.getConfig().getBoolean("Main.Upgrade With XP") - && player.hasPermission("EpicHoppers.Upgrade.XP") - && level.getCostExperience() != -1) { - inventory.setItem(11, itemXP); - - registerClickable(11, ((player, inventory, cursor, slot, type) -> { - hopper.upgrade(player, CostType.EXPERIENCE); - this.hopper.overview(player); - })); - } - - if (plugin.getConfig().getBoolean("Main.Upgrade With Economy") - && player.hasPermission("EpicHoppers.Upgrade.ECO") - && level.getCostEconomy() != -1) { - inventory.setItem(15, itemECO); - - registerClickable(15, ((player, inventory, cursor, slot, type) -> { - hopper.upgrade(player, CostType.ECONOMY); - this.hopper.overview(player); - })); - } + parts = plugin.getLocale().getMessage("interface.furnace.rewardinfo", level.getReward().split(":")[0].replace("%", "")).split("\\|"); + lore.add(""); + for (String line : parts) { + lore3.add(Methods.formatText(line)); } + itemmeta3.setLore(lore3); + item3.setItemMeta(itemmeta3); + + + ItemStack item4 = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.FuelDuration Icon")), 1); + ItemMeta itemmeta4 = item4.getItemMeta(); + itemmeta4.setDisplayName(plugin.getLocale().getMessage("interface.furnace.fueldurationtitle")); + ArrayList lore4 = new ArrayList<>(); + + parts = plugin.getLocale().getMessage("interface.furnace.fueldurationinfo", level.getFuelDuration()).split("\\|"); + lore.add(""); + for (String line : parts) { + lore4.add(Methods.formatText(line)); + } + itemmeta4.setLore(lore4); + item4.setItemMeta(itemmeta4); + + ItemStack item5 = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Overheat Icon")), 1); + ItemMeta itemmeta5 = item4.getItemMeta(); + itemmeta5.setDisplayName(plugin.getLocale().getMessage("interface.furnace.overheattitle")); + ArrayList lore5 = new ArrayList<>(); + + parts = plugin.getLocale().getMessage("interface.furnace.overheatinfo", level.getOverheat() * 3).split("\\|"); + lore.add(""); + for (String line : parts) { + lore5.add(Methods.formatText(line)); + } + itemmeta5.setLore(lore5); + item5.setItemMeta(itemmeta5); + + ItemStack item6 = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.FuelShare Icon")), 1); + ItemMeta itemmeta6 = item4.getItemMeta(); + itemmeta6.setDisplayName(plugin.getLocale().getMessage("interface.furnace.fuelsharetitle")); + ArrayList lore6 = new ArrayList<>(); + + parts = plugin.getLocale().getMessage("interface.furnace.fuelshareinfo", level.getOverheat() * 3).split("\\|"); + lore.add(""); + for (String line : parts) { + lore6.add(Methods.formatText(line)); + } + itemmeta6.setLore(lore6); + item6.setItemMeta(itemmeta6); + + ItemStack itemXP = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.XP Icon")), 1); + ItemMeta itemmetaXP = itemXP.getItemMeta(); + itemmetaXP.setDisplayName(plugin.getLocale().getMessage("interface.furnace.upgradewithxp")); + ArrayList loreXP = new ArrayList<>(); + if (nextLevel != null) + loreXP.add(plugin.getLocale().getMessage("interface.furnace.upgradewithxplore", level.getCostExperience())); + else + loreXP.add(plugin.getLocale().getMessage("interface.furnace.alreadymaxed")); + itemmetaXP.setLore(loreXP); + itemXP.setItemMeta(itemmetaXP); + + ItemStack itemECO = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Economy Icon")), 1); + ItemMeta itemmetaECO = itemECO.getItemMeta(); + itemmetaECO.setDisplayName(plugin.getLocale().getMessage("interface.furnace.upgradewitheconomy")); + ArrayList loreECO = new ArrayList<>(); + if (nextLevel != null) + loreECO.add(plugin.getLocale().getMessage("interface.furnace.upgradewitheconomylore", Methods.formatEconomy(level.getCostEconomy()))); + else + loreECO.add(plugin.getLocale().getMessage("interface.furnace.alreadymaxed")); + itemmetaECO.setLore(loreECO); + itemECO.setItemMeta(itemmetaECO); inventory.setItem(13, item); @@ -225,7 +193,156 @@ public class GUIOverview extends AbstractGUI { inventory.setItem(25, Methods.getBackgroundGlass(true)); inventory.setItem(26, Methods.getBackgroundGlass(true)); - hopper.setLastPlayer(player.getUniqueId()); + int num = -1; + Map spots = new HashMap(); + + int[] s1 = {22}; + spots.put(0, s1); + int[] s2 = {21, 23}; + spots.put(1, s2); + int[] s3 = {21, 22, 23}; + spots.put(2, s3); + int[] s4 = {20, 21, 23, 24}; + spots.put(3, s4); + int[] s5 = {20, 21, 22, 23, 24}; + spots.put(4, s5); + + if (level.getPerformance() != 0) { + num++; + } + if (level.getReward() != null) { + num++; + } + if (level.getFuelDuration() != 0) { + num++; + } + if (level.getFuelShare() != 0) { + num++; + } + if (level.getOverheat() != 0) { + num++; + } + + int[] order = spots.get(num); + + int current = 0; + + if (level.getPerformance() != 0) { + inventory.setItem(order[current], item2); + current++; + } + if (level.getReward() != null) { + inventory.setItem(order[current], item3); + current++; + } + if (level.getFuelDuration() != 0) { + inventory.setItem(order[current], item4); + current++; + } + if (level.getFuelShare() != 0) { + inventory.setItem(order[current], item6); + current++; + } + if (level.getOverheat() != 0) { + inventory.setItem(order[current], item5); + } + + ItemStack hook = new ItemStack(Material.TRIPWIRE_HOOK, 1); + ItemMeta hookmeta = hook.getItemMeta(); + hookmeta.setDisplayName(plugin.getLocale().getMessage("interface.furnace.remotefurnace")); + ArrayList lorehook = new ArrayList<>(); + + String nickname = furnace.getNickname(); + + parts = plugin.getLocale().getMessage("interface.furnace.remotefurnacelore", nickname == null ? "Unset" : nickname).split("\\|"); + + for (String line : parts) { + lorehook.add(Methods.formatText(line)); + } + if (nickname != null) { + parts = plugin.getLocale().getMessage("interface.furnace.utilize", nickname).split("\\|"); + for (String line : parts) { + lorehook.add(Methods.formatText(line)); + } + } + + lorehook.add(""); + lorehook.add(plugin.getLocale().getMessage("interface.furnace.remotelist")); + for (String line : furnace.getRawAccessList()) { + String[] halfs = line.split(":"); + String name = halfs[1]; + Player player = Bukkit.getPlayer(halfs[0]); + if (player != null) { + name = player.getDisplayName(); + } + lorehook.add(Methods.formatText("&6" + name)); + } + hookmeta.setLore(lorehook); + hook.setItemMeta(hookmeta); + + if (plugin.getConfig().getBoolean("Main.Access Furnaces Remotely") + && player.hasPermission("EpicFurnaces.Remote")) { + inventory.setItem(4, hook); + registerClickable(4, ((player1, inventory1, cursor, slot, type) -> { + if (type == ClickType.LEFT) { + + AbstractAnvilGUI gui = new AbstractAnvilGUI(player, anvilEvent -> { + for (Furnace other : plugin.getFurnaceManager().getFurnaces().values()) { + if (other.getNickname() == null) { + continue; + } + + if (other.getNickname().equalsIgnoreCase(anvilEvent.getName())) { + player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.remote.nicknameinuse")); + return; + } + } + + furnace.setNickname(anvilEvent.getName()); + player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.remote.nicknamesuccess")); + }); + + gui.setOnClose((player2, inventory2) -> init(setTitle, inventory.getSize())); + + ItemStack itemO = new ItemStack(Material.PAPER); + ItemMeta meta = itemO.getItemMeta(); + meta.setDisplayName(furnace.getNickname() == null ? "Enter a nickname" : furnace.getNickname()); + itemO.setItemMeta(meta); + gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, itemO); + gui.open(); + + player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.remote.enter")); + + + } else if (type == ClickType.RIGHT) { + furnace.addToAccessList(player); + constructGUI(); + } + })); + } + + inventory.setItem(13, item); + + if (plugin.getConfig().getBoolean("Main.Upgrade With XP") + && player.hasPermission("EpicFurnaces.Upgrade.XP") + && level.getCostExperience() != -1) { + inventory.setItem(11, itemXP); + + registerClickable(11, ((player, inventory, cursor, slot, type) -> { + furnace.upgrade(player, CostType.EXPERIENCE); + furnace.overview(player); + })); + } + if (plugin.getConfig().getBoolean("Main.Upgrade With Economy") + && player.hasPermission("EpicFurnaces.Upgrade.ECO") + && level.getCostEconomy() != -1) { + inventory.setItem(15, itemECO); + + registerClickable(15, ((player, inventory, cursor, slot, type) -> { + furnace.upgrade(player, CostType.ECONOMY); + furnace.overview(player); + })); + } } private void runTask() { @@ -235,52 +352,6 @@ public class GUIOverview extends AbstractGUI { @Override protected void registerClickables() { - registerClickable(3, 23, ((player, inventory, cursor, slot, type) -> { - for (Module module : hopper.getLevel().getRegisteredModules()) { - if (module.getGUIButton(hopper) != null && !module.getGUIButton(hopper).getItemMeta() - .getDisplayName().equalsIgnoreCase(inventory.getItem(slot).getItemMeta().getDisplayName())) - continue; - - module.runButtonPress(player, hopper); - } - if (inventory.getItem(slot).getItemMeta() - .getDisplayName().equals(plugin.getLocale().getMessage("interface.hopper.filtertitle"))) { - new GUIFilter(plugin, hopper, player); - } else if (inventory.getItem(slot).getItemMeta() - .getDisplayName().equals(plugin.getLocale().getMessage("interface.hopper.perltitle"))) { - if (type == ClickType.LEFT) { - if (hopper.getLinkedBlocks() != null) { - plugin.getTeleportHandler().tpEntity(player, hopper); - player.closeInventory(); - } - } else { - if (hopper.getTeleportTrigger() == TeleportTrigger.DISABLED) { - hopper.setTeleportTrigger(TeleportTrigger.SNEAK); - } else if (hopper.getTeleportTrigger() == TeleportTrigger.SNEAK) { - hopper.setTeleportTrigger(TeleportTrigger.WALK_ON); - } else if (hopper.getTeleportTrigger() == TeleportTrigger.WALK_ON) { - hopper.setTeleportTrigger(TeleportTrigger.DISABLED); - } - constructGUI(); - } - } else if (inventory.getItem(slot).getItemMeta() - .getDisplayName().equals(plugin.getLocale().getMessage("interface.hopper.synchopper"))) { - if (type == ClickType.RIGHT) { - player.sendMessage(plugin.references.getPrefix() + plugin.getLocale().getMessage("event.hopper.desync")); - hopper.clearLinkedBlocks(); - } else { - if (hopper.getLastPlayer() != null && !hopper.getLastPlayer().equals(player.getUniqueId())) { - player.sendMessage(plugin.references.getPrefix() + plugin.getLocale().getMessage("event.hopper.syncdidnotplace")); - return; - } - plugin.getPlayerDataManager().getPlayerData(player).setSyncType(SyncType.REGULAR); - hopper.clearLinkedBlocks(); - player.sendMessage(plugin.references.getPrefix() + plugin.getLocale().getMessage("event.hopper.syncnext")); - hopper.timeout(player); - } - player.closeInventory(); - } - })); } @Override diff --git a/src/main/java/com/songoda/epicfurnaces/handlers/BlacklistHandler.java b/src/main/java/com/songoda/epicfurnaces/handlers/BlacklistHandler.java index 47a42cf..9428522 100644 --- a/src/main/java/com/songoda/epicfurnaces/handlers/BlacklistHandler.java +++ b/src/main/java/com/songoda/epicfurnaces/handlers/BlacklistHandler.java @@ -1,8 +1,7 @@ package com.songoda.epicfurnaces.handlers; -import com.songoda.arconix.api.utils.ConfigWrapper; -import com.songoda.epicfurnaces.EpicFurnacesPlugin; -import com.songoda.epicfurnaces.utils.Debugger; +import com.songoda.epicfurnaces.EpicFurnaces; +import com.songoda.epicfurnaces.utils.ConfigWrapper; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -13,55 +12,38 @@ import java.util.List; */ public class BlacklistHandler { - private ConfigWrapper blackFile = new ConfigWrapper(EpicFurnacesPlugin.getInstance(), "", "blacklist.yml"); + private ConfigWrapper blackFile = new ConfigWrapper(EpicFurnaces.getInstance(), "", "blacklist.yml"); public BlacklistHandler() { - try { - blackFile.createNewFile("Loading language file", "EpicFurnaces blacklist file"); - loadBlacklistFile(); - } catch (Exception e) { - Debugger.runReport(e); - } + blackFile.createNewFile("Loading language file", "EpicFurnaces blacklist file"); + loadBlacklistFile(); } public boolean isBlacklisted(Player player) { - boolean blacklisted = false; - try { - List list = blackFile.getConfig().getStringList("settings.blacklist"); - String cWorld = player.getWorld().getName(); - for (String world : list) { - if (cWorld.equalsIgnoreCase(world)) { - blacklisted = true; - } + List list = blackFile.getConfig().getStringList("settings.blacklist"); + String cWorld = player.getWorld().getName(); + for (String world : list) { + if (cWorld.equalsIgnoreCase(world)) { + return true; } - } catch (Exception e) { - Debugger.runReport(e); } - return blacklisted; + return false; } private void loadBlacklistFile() { - try { - List list = new ArrayList<>(); - list.add("world2"); - list.add("world3"); - list.add("world4"); - list.add("world5"); - blackFile.getConfig().addDefault("settings.blacklist", list); + List list = new ArrayList<>(); + list.add("world2"); + list.add("world3"); + list.add("world4"); + list.add("world5"); + blackFile.getConfig().addDefault("settings.blacklist", list); - blackFile.getConfig().options().copyDefaults(true); - blackFile.saveConfig(); - } catch (Exception e) { - Debugger.runReport(e); - } + blackFile.getConfig().options().copyDefaults(true); + blackFile.saveConfig(); } public void reload() { - try { - blackFile.createNewFile("Loading blacklist file", "EpicFurnaces blacklist file"); - loadBlacklistFile(); - } catch (Exception e) { - Debugger.runReport(e); - } + blackFile.createNewFile("Loading blacklist file", "EpicFurnaces blacklist file"); + loadBlacklistFile(); } } \ No newline at end of file diff --git a/src/main/java/com/songoda/epicfurnaces/hologram/Hologram.java b/src/main/java/com/songoda/epicfurnaces/hologram/Hologram.java index 701370f..2f42cab 100644 --- a/src/main/java/com/songoda/epicfurnaces/hologram/Hologram.java +++ b/src/main/java/com/songoda/epicfurnaces/hologram/Hologram.java @@ -1,142 +1,96 @@ -package com.songoda.ultimatekits.hologram; +package com.songoda.epicfurnaces.hologram; -import com.songoda.ultimatekits.UltimateKits; -import com.songoda.ultimatekits.kit.Kit; -import com.songoda.ultimatekits.kit.KitBlockData; -import com.songoda.ultimatekits.kit.KitType; -import com.songoda.ultimatekits.utils.Methods; -import org.bukkit.Bukkit; +import com.songoda.epicfurnaces.EpicFurnaces; +import com.songoda.epicfurnaces.furnace.Furnace; +import com.songoda.epicfurnaces.utils.Methods; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.block.Block; import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; public abstract class Hologram { - protected final UltimateKits instance; + protected final EpicFurnaces plugin; - Hologram(UltimateKits instance) { - this.instance = instance; + Hologram(EpicFurnaces plugin) { + this.plugin = plugin; } public void loadHolograms() { - Collection kitBlocks = instance.getKitManager().getKitLocations().values(); - if (kitBlocks.size() == 0) return; + if (!plugin.getConfig().getBoolean("Main.Furnaces Have Holograms")) return; - for (KitBlockData data : kitBlocks) { - if (data.getWorld() == null) continue; - add(data); + for (Furnace furnace : plugin.getFurnaceManager().getFurnaces().values()) { + if (furnace.getLocation() == null || furnace.getLocation().getWorld() == null) + continue; + if (furnace.getLocation().getBlock().getType() != Material.FURNACE) continue; + + add(furnace); } } public void unloadHolograms() { - Collection kitBlocks = instance.getKitManager().getKitLocations().values(); - if (kitBlocks.size() == 0) return; + for (Furnace furnace : plugin.getFurnaceManager().getFurnaces().values()) { + if (furnace.getLocation() == null || furnace.getLocation().getWorld() == null) + continue; + if (furnace.getLocation().getBlock().getType() != Material.FURNACE) continue; - for (KitBlockData data : kitBlocks) { - if (data.getWorld() == null) continue; - remove(data); + remove(furnace); } } - public void add(KitBlockData data) { - format(data, Action.ADD); + public void add(Furnace furnace) { + format(furnace, Action.ADD); } - public void remove(KitBlockData data) { - format(data, Action.REMOVE); + public void remove(Furnace furnace) { + format(furnace, Action.REMOVE); } - public void remove(Kit kit) { - for (KitBlockData data : instance.getKitManager().getKitLocations().values()) { - if (data.getKit() != kit) continue; - remove(data); + public void update(Furnace furnace) { + format(furnace, Action.UPDATE); + } + + private void format(Furnace furnace, Action action) { + + org.bukkit.block.Furnace furnaceBlock = ((org.bukkit.block.Furnace) furnace.getLocation().getBlock().getState()); + + int performance = (furnaceBlock.getCookTime() - furnace.getPerformanceTotal()) <= 0 ? 0 : furnace.getPerformanceTotal(); + + float percent = (float) (furnaceBlock.getCookTime() - performance) / (200 - performance); + + int progressBars = (int) (6 * percent) + (percent == 0 ? 0 : 1); + int leftOver = (6 - progressBars); + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < progressBars; i++) { + sb.append("&a="); } - } - - public void update(KitBlockData data) { - format(data, Action.UPDATE); - } - - public void update(Kit kit) { - for (KitBlockData data : instance.getKitManager().getKitLocations().values()) { - if (data.getKit() != kit) continue; - update(data); + for (int i = 0; i < leftOver; i++) { + sb.append("&c="); } - } - - private void format(KitBlockData data, Action action) { - if (data == null) return; - KitType kitType = data.getType(); ArrayList lines = new ArrayList<>(); - List order = instance.getConfig().getStringList("Main.Hologram Layout"); + String progress = Methods.formatText(sb.toString()); - Kit kit = data.getKit(); - - for (String o : order) { - switch (o.toUpperCase()) { - case "{TITLE}": - String title = kit.getTitle(); - if (title == null) { - lines.add(Methods.formatText("&5" + Methods.formatText(kit.getName(), true))); - } else { - lines.add(Methods.formatText("&5" + Methods.formatText(title))); - } - break; - case "{RIGHT-CLICK}": - if (kitType == KitType.CRATE) { - lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.crate"))); - break; - } - if (kit.getLink() != null) { - lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.buylink"))); - break; - } - if (kit.getPrice() != 0) { - lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.buyeco", kit.getPrice() != 0 ? Methods.formatEconomy(kit.getPrice()) : instance.getLocale().getMessage("general.type.free")))); - } - break; - case "{LEFT-CLICK}": - if (kitType == KitType.CLAIM) { - lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.daily"))); - break; - } - if (kit.getLink() == null && kit.getPrice() == 0) { - lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.previewonly"))); - } else { - lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.preview"))); - } - break; - default: - lines.add(Methods.formatText(o)); - break; - - } + if (furnaceBlock.getInventory().getFuel() == null) { + progress = plugin.getLocale().getMessage("general.hologram.outoffuel"); } - double multi = .25 * lines.size(); - Location location = data.getLocation(); - Block b = location.getBlock(); - - if (data.isDisplayingItems()) multi += .40; - - if (b.getType() == Material.TRAPPED_CHEST - || b.getType() == Material.CHEST - || b.getType().name().contains("SIGN") - || b.getType() == Material.ENDER_CHEST) multi -= .15; - - location.add(0, multi, 0); - - if (!data.showHologram()) { - remove(location); - return; + int inAmt = 0; + int outAmt = 0; + if (furnaceBlock.getInventory().getSmelting() != null) { + inAmt = furnaceBlock.getInventory().getSmelting().getAmount(); } + if (furnaceBlock.getInventory().getResult() != null) { + outAmt = furnaceBlock.getInventory().getResult().getAmount(); + } + + String stats = plugin.getLocale().getMessage("general.hologram.stats", inAmt, outAmt > 64 ? 64 : outAmt); + lines.add(progress); + lines.add(stats); + + Location location = furnace.getLocation(); switch (action) { case UPDATE: diff --git a/src/main/java/com/songoda/epicfurnaces/hologram/HologramHolographicDisplays.java b/src/main/java/com/songoda/epicfurnaces/hologram/HologramHolographicDisplays.java index 0bd51f2..deb5a34 100644 --- a/src/main/java/com/songoda/epicfurnaces/hologram/HologramHolographicDisplays.java +++ b/src/main/java/com/songoda/epicfurnaces/hologram/HologramHolographicDisplays.java @@ -1,7 +1,7 @@ -package com.songoda.ultimatekits.hologram; +package com.songoda.epicfurnaces.hologram; import com.gmail.filoghost.holographicdisplays.api.HologramsAPI; -import com.songoda.ultimatekits.UltimateKits; +import com.songoda.epicfurnaces.EpicFurnaces; import org.bukkit.Location; import java.util.ArrayList; @@ -9,15 +9,15 @@ import java.util.ArrayList; public class HologramHolographicDisplays extends Hologram { - public HologramHolographicDisplays(UltimateKits instance) { - super(instance); + public HologramHolographicDisplays(EpicFurnaces plugin) { + super(plugin); } @Override public void add(Location location, ArrayList lines) { fixLocation(location); - com.gmail.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(instance, location); + com.gmail.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(plugin, location); for (String line : lines) { hologram.appendTextLine(line); } @@ -26,7 +26,7 @@ public class HologramHolographicDisplays extends Hologram { @Override public void remove(Location location) { fixLocation(location); - for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : HologramsAPI.getHolograms(instance)) { + for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : HologramsAPI.getHolograms(plugin)) { if (hologram.getX() != location.getX() || hologram.getY() != location.getY() || hologram.getZ() != location.getZ()) continue; @@ -36,7 +36,7 @@ public class HologramHolographicDisplays extends Hologram { @Override public void update(Location location, ArrayList lines) { - for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : HologramsAPI.getHolograms(instance)) { + for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : HologramsAPI.getHolograms(plugin)) { if (hologram.getX() != location.getX() || hologram.getY() != location.getY() || hologram.getZ() != location.getZ()) continue; @@ -51,6 +51,6 @@ public class HologramHolographicDisplays extends Hologram { } private void fixLocation(Location location) { - location.add(.5, 1.3, .5); + location.add(.5, 1.8, .5); } } diff --git a/src/main/java/com/songoda/epicfurnaces/listeners/BlockListeners.java b/src/main/java/com/songoda/epicfurnaces/listeners/BlockListeners.java index 2b3b61a..a180417 100644 --- a/src/main/java/com/songoda/epicfurnaces/listeners/BlockListeners.java +++ b/src/main/java/com/songoda/epicfurnaces/listeners/BlockListeners.java @@ -1,13 +1,7 @@ package com.songoda.epicfurnaces.listeners; -import com.mysql.jdbc.Buffer; -import com.songoda.arconix.api.methods.formatting.TextComponent; -import com.songoda.epicfurnaces.EpicFurnacesPlugin; -import com.songoda.epicfurnaces.api.furnace.Furnace; -import com.songoda.epicfurnaces.furnace.EFurnace; -import com.songoda.epicfurnaces.utils.Debugger; -import com.songoda.epicfurnaces.utils.Methods; -import org.bukkit.Bukkit; +import com.songoda.epicfurnaces.EpicFurnaces; +import com.songoda.epicfurnaces.furnace.Furnace; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -18,7 +12,6 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; @@ -27,10 +20,10 @@ import java.util.ArrayList; */ public class BlockListeners implements Listener { - private final EpicFurnacesPlugin instance; + private final EpicFurnaces plugin; - public BlockListeners(EpicFurnacesPlugin instance) { - this.instance = instance; + public BlockListeners(EpicFurnaces plugin) { + this.plugin = plugin; } @EventHandler @@ -39,10 +32,12 @@ public class BlockListeners implements Listener { if (material != Material.SNOW && material != Material.ICE) return; - for (Furnace furnace : instance.getFurnaceManager().getFurnaces().values()) { - if (furnace.getRadius(false) == null || ((org.bukkit.block.Furnace)furnace.getLocation().getBlock().getState()).getBurnTime() == 0) continue; + for (Furnace furnace : plugin.getFurnaceManager().getFurnaces().values()) { + if (furnace.getRadius(false) == null || ((org.bukkit.block.Furnace) furnace.getLocation().getBlock().getState()).getBurnTime() == 0) + continue; for (Location location : furnace.getRadius(false)) { - if (location.getX() != event.getNewState().getX() || location.getY() != event.getNewState().getY() || location.getZ() != event.getNewState().getZ()) continue; + if (location.getX() != event.getNewState().getX() || location.getY() != event.getNewState().getY() || location.getZ() != event.getNewState().getZ()) + continue; event.setCancelled(true); return; } @@ -50,59 +45,62 @@ public class BlockListeners implements Listener { } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { - try { - if (event.getBlock().getType() != Material.FURNACE || !event.getItemInHand().getItemMeta().hasDisplayName()) return; - ItemStack item = event.getItemInHand(); - Location location = event.getBlock().getLocation(); + if (plugin.getBlacklistHandler().isBlacklisted(event.getPlayer())) { + return; + } - if (instance.getFurnceLevel(item) != 1) { - if (instance.getBlacklistHandler().isBlacklisted(event.getPlayer())) { - event.setCancelled(true); - return; - } + if (event.getBlock().getType() != Material.FURNACE) + return; - instance.getFurnaceManager().addFurnace(location, new EFurnace(location, instance.getLevelManager().getLevel(instance.getFurnceLevel(item)), null, instance.getFurnaceUses(item), 0, new ArrayList<>(), event.getPlayer().getUniqueId())); - } + ItemStack item = event.getItemInHand(); - } catch (Exception ee) { - Debugger.runReport(ee); + Location location = event.getBlock().getLocation(); + + Furnace furnace; + + if (event.getItemInHand().getItemMeta().hasDisplayName() && plugin.getFurnceLevel(item) != 1) { + furnace = new Furnace(location, plugin.getLevelManager().getLevel(plugin.getFurnceLevel(item)), null, plugin.getFurnaceUses(item), 0, new ArrayList<>(), event.getPlayer().getUniqueId()); + } else { + furnace = new Furnace(location, plugin.getLevelManager().getLowestLevel(), null, 0, 0, new ArrayList<>(), event.getPlayer().getUniqueId()); + } + + plugin.getFurnaceManager().addFurnace(location, furnace); + + if (plugin.getHologram() != null) { + plugin.getHologram().add(furnace); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { - try { - if (!event.getPlayer().hasPermission("EpicFurnaces.overview") && !event.getPlayer().hasPermission("epicfurnaces.*")) { - return; - } - Block block = event.getBlock(); - if (block.getType() != Material.FURNACE) { - return; - } - instance.getHologramTask().despawn(block); - - if (instance.getBlacklistHandler().isBlacklisted(event.getPlayer())) { - return; - } - - Furnace furnace = instance.getFurnaceManager().getFurnace(block); - int level = instance.getFurnaceManager().getFurnace(block).getLevel().getLevel(); - - if (level != 0) { - event.setCancelled(true); - - ItemStack item = instance.createLeveledFurnace(level, furnace.getUses()); - - event.getBlock().setType(Material.AIR); - event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), item); - } - instance.getFurnaceManager().removeFurnace(block.getLocation()); - - } catch (Exception ee) { - Debugger.runReport(ee); + if (!event.getPlayer().hasPermission("EpicFurnaces.overview") && !event.getPlayer().hasPermission("epicfurnaces.*")) { + return; } + Block block = event.getBlock(); + if (block.getType() != Material.FURNACE) { + return; + } + if (plugin.getBlacklistHandler().isBlacklisted(event.getPlayer())) { + return; + } + + Furnace furnace = plugin.getFurnaceManager().getFurnace(block); + int level = plugin.getFurnaceManager().getFurnace(block).getLevel().getLevel(); + + if (plugin.getHologram() != null) + plugin.getHologram().remove(furnace); + + if (level != 0) { + event.setCancelled(true); + + ItemStack item = plugin.createLeveledFurnace(level, furnace.getUses()); + + event.getBlock().setType(Material.AIR); + event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), item); + } + plugin.getFurnaceManager().removeFurnace(block.getLocation()); } } \ No newline at end of file diff --git a/src/main/java/com/songoda/epicfurnaces/listeners/FurnaceListeners.java b/src/main/java/com/songoda/epicfurnaces/listeners/FurnaceListeners.java index e01e960..4fd88bd 100644 --- a/src/main/java/com/songoda/epicfurnaces/listeners/FurnaceListeners.java +++ b/src/main/java/com/songoda/epicfurnaces/listeners/FurnaceListeners.java @@ -1,10 +1,8 @@ package com.songoda.epicfurnaces.listeners; -import com.songoda.epicfurnaces.EpicFurnacesPlugin; -import com.songoda.epicfurnaces.api.furnace.Furnace; -import com.songoda.epicfurnaces.api.furnace.Level; -import com.songoda.epicfurnaces.furnace.EFurnace; -import com.songoda.epicfurnaces.utils.Debugger; +import com.songoda.epicfurnaces.EpicFurnaces; +import com.songoda.epicfurnaces.furnace.Furnace; +import com.songoda.epicfurnaces.furnace.levels.Level; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.event.EventHandler; @@ -17,44 +15,35 @@ import org.bukkit.event.inventory.FurnaceSmeltEvent; */ public class FurnaceListeners implements Listener { - private final EpicFurnacesPlugin instance; + private final EpicFurnaces plugin; - public FurnaceListeners(EpicFurnacesPlugin instance) { - this.instance = instance; + public FurnaceListeners(EpicFurnaces plugin) { + this.plugin = plugin; } @EventHandler public void onCook(FurnaceSmeltEvent e) { - try { - Block b = e.getBlock(); - if ((e.getBlock().isBlockPowered() && instance.getConfig().getBoolean("Main.Redstone Deactivates Furnaces")) || e.getResult() == null) { - e.setCancelled(true); - return; - } - Furnace furnace = instance.getFurnaceManager().getFurnace(b.getLocation()); - - if (furnace != null && e.getSource().getType() != Material.WET_SPONGE) - ((EFurnace) furnace).plus(e); - } catch (Exception ee) { - Debugger.runReport(ee); + Block b = e.getBlock(); + if ((e.getBlock().isBlockPowered() && plugin.getConfig().getBoolean("Main.Redstone Deactivates Furnaces")) || e.getResult() == null) { + e.setCancelled(true); + return; } + Furnace furnace = plugin.getFurnaceManager().getFurnace(b.getLocation()); + + if (furnace != null && e.getSource().getType() != Material.valueOf("WET_SPONGE")) + furnace.plus(e); } @EventHandler - public void onFuel(FurnaceBurnEvent e) { - try { - if (e.getFuel() == null) return; - Furnace furnace = instance.getFurnaceManager().getFurnace(e.getBlock().getLocation()); + public void onFuel(FurnaceBurnEvent event) { + Furnace furnace = plugin.getFurnaceManager().getFurnace(event.getBlock().getLocation()); - Level level = furnace != null ? furnace.getLevel() : instance.getLevelManager().getLowestLevel(); + Level level = furnace != null ? furnace.getLevel() : plugin.getLevelManager().getLowestLevel(); - if (level.getFuelDuration() != 0) return; + if (level.getFuelDuration() != 0) return; - int num = level.getFuelDuration(); - int per = (e.getBurnTime() / 100) * num; - e.setBurnTime(e.getBurnTime() + per); - } catch (Exception ee) { - Debugger.runReport(ee); - } + int num = level.getFuelDuration(); + int per = (event.getBurnTime() / 100) * num; + event.setBurnTime(event.getBurnTime() + per); } } \ No newline at end of file diff --git a/src/main/java/com/songoda/epicfurnaces/listeners/InteractListeners.java b/src/main/java/com/songoda/epicfurnaces/listeners/InteractListeners.java index 1a43091..dae732b 100644 --- a/src/main/java/com/songoda/epicfurnaces/listeners/InteractListeners.java +++ b/src/main/java/com/songoda/epicfurnaces/listeners/InteractListeners.java @@ -1,8 +1,7 @@ package com.songoda.epicfurnaces.listeners; -import com.songoda.epicfurnaces.EpicFurnacesPlugin; -import com.songoda.epicfurnaces.furnace.EFurnace; -import com.songoda.epicfurnaces.utils.Debugger; +import com.songoda.epicfurnaces.EpicFurnaces; +import com.songoda.epicfurnaces.furnace.Furnace; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -17,37 +16,31 @@ import org.bukkit.event.player.PlayerInteractEvent; */ public class InteractListeners implements Listener { - private final EpicFurnacesPlugin instance; + private final EpicFurnaces plugin; - public InteractListeners(EpicFurnacesPlugin instance) { - this.instance = instance; + public InteractListeners(EpicFurnaces plugin) { + this.plugin = plugin; } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onClick(PlayerInteractEvent event) { - try { - if (event.getClickedBlock() == null) return; + if (event.getClickedBlock() == null) return; - if (instance.getBlacklistHandler().isBlacklisted(event.getPlayer())) { - return; - } - Player player = event.getPlayer(); - Block block = event.getClickedBlock(); - if (!player.hasPermission("EpicFurnaces.overview") - || !instance.canBuild(player, event.getClickedBlock().getLocation()) - || event.getAction() != Action.LEFT_CLICK_BLOCK - || player.isSneaking() - || (block.getType() != Material.FURNACE) - || player.getInventory().getItemInMainHand().getType().name().contains("PICKAXE")) { - return; - } - - event.setCancelled(true); - - ((EFurnace) instance.getFurnaceManager().getFurnace(block.getLocation())).openOverview(player); - - } catch (Exception ee) { - Debugger.runReport(ee); + if (plugin.getBlacklistHandler().isBlacklisted(event.getPlayer())) { + return; } + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + if (!player.hasPermission("EpicFurnaces.overview") + || event.getAction() != Action.LEFT_CLICK_BLOCK + || player.isSneaking() + || (block.getType() != Material.FURNACE) + || player.getInventory().getItemInHand().getType().name().contains("PICKAXE")) { + return; + } + + event.setCancelled(true); + + plugin.getFurnaceManager().getFurnace(block.getLocation()).overview(player); } } \ No newline at end of file diff --git a/src/main/java/com/songoda/epicfurnaces/listeners/InventoryListeners.java b/src/main/java/com/songoda/epicfurnaces/listeners/InventoryListeners.java index f991618..df54038 100644 --- a/src/main/java/com/songoda/epicfurnaces/listeners/InventoryListeners.java +++ b/src/main/java/com/songoda/epicfurnaces/listeners/InventoryListeners.java @@ -1,119 +1,50 @@ package com.songoda.epicfurnaces.listeners; -import com.songoda.arconix.plugin.Arconix; -import com.songoda.epicfurnaces.EpicFurnacesPlugin; -import com.songoda.epicfurnaces.furnace.EFurnace; -import com.songoda.epicfurnaces.player.PlayerData; -import com.songoda.epicfurnaces.utils.Debugger; +import com.songoda.epicfurnaces.EpicFurnaces; import org.bukkit.Material; -import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.*; import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; -import java.util.List; - /** * Created by songoda on 2/26/2017. */ public class InventoryListeners implements Listener { - private final EpicFurnacesPlugin instance; + private final EpicFurnaces plugin; - public InventoryListeners(EpicFurnacesPlugin instance) { - this.instance = instance; + public InventoryListeners(EpicFurnaces plugin) { + this.plugin = plugin; } @EventHandler - public void onInventoryMove(InventoryMoveItemEvent e) { - if (!e.getDestination().getType().equals(InventoryType.FURNACE) - || e.getDestination().getItem(0) == null - || e.getDestination().getItem(0).getType() != e.getItem().getType() - || e.getDestination().getItem(0).getAmount() != 1) { + public void onInventoryMove(InventoryMoveItemEvent event) { + if (!event.getDestination().getType().equals(InventoryType.FURNACE) + || event.getDestination().getItem(0) == null + || event.getDestination().getItem(0).getType() != event.getItem().getType() + || event.getDestination().getItem(0).getAmount() != 1) { return; } - ((EFurnace) instance.getFurnaceManager().getFurnace(e.getDestination().getLocation())).updateCook(); + plugin.getFurnaceManager().getFurnace(((org.bukkit.block.Furnace) + event.getDestination().getHolder()).getLocation()).updateCook(); } @SuppressWarnings("unchecked") @EventHandler - public void onInventoryClick(InventoryClickEvent e) { - try { - Player p = (Player) e.getWhoClicked(); - PlayerData playerData = instance.getPlayerDataManager().getPlayerData(p); - - if (e.getInventory().getType().equals(InventoryType.FURNACE) - && e.getInventory().getHolder() != null - && e.getSlotType() == InventoryType.SlotType.CRAFTING) { - Block block; - block = e.getInventory().getLocation().getBlock(); - ((EFurnace) instance.getFurnaceManager().getFurnace(block)).updateCook(); - } else if (playerData.isInOverview()) { - e.setCancelled(true); - EFurnace furnace = playerData.getLastFurace(); - if (e.getSlot() == 11) { - if (!e.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) { - furnace.upgrade("XP", p); - p.closeInventory(); - } - } else if (e.getSlot() == 15) { - if (!e.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) { - furnace.upgrade("ECO", p); - p.closeInventory(); - } - } else if (e.getSlot() == 4) { - if (!e.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) { - if (e.getClick().isLeftClick()) { - p.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.remote.enter")); - playerData.setSettingNickname(true); - p.closeInventory(); - } else if (e.getClick().isRightClick()) { - List list = new ArrayList<>(); - String key = Arconix.pl().getApi().serialize().serializeLocation(furnace.getLocation()); - String id = p.getUniqueId().toString() + ":" + p.getName(); - if (instance.getDataFile().getConfig().contains("data.charged." + key + ".remoteAccessList")) { - list = (List) instance.getDataFile().getConfig().getList("data.charged." + key + ".remoteAccessList"); - for (String line : (List) instance.getDataFile().getConfig().getList("data.charged." + key + ".remoteAccessList")) { - if (id.equals(line)) { - e.setCancelled(true); - return; - } - } - } - list.add(id); - instance.getDataFile().getConfig().set("data.charged." + key + ".remoteAccessList", list); - furnace.openOverview(p); - } - } - } - if (e.getSlot() != 64537) { - if (e.getInventory().getType() == InventoryType.ANVIL) { - if (e.getAction() != InventoryAction.NOTHING) { - if (e.getCurrentItem().getType() != Material.AIR) { - ItemStack item = e.getCurrentItem(); - if (item.getType() == Material.FURNACE) { - e.setCancelled(true); - } - } + public void onInventoryClick(InventoryClickEvent event) { + if (event.getSlot() != 64537) { + if (event.getInventory().getType() == InventoryType.ANVIL) { + if (event.getAction() != InventoryAction.NOTHING) { + if (event.getCurrentItem().getType() != Material.AIR) { + ItemStack item = event.getCurrentItem(); + if (item.getType() == Material.FURNACE) { + event.setCancelled(true); } } } } - } catch (Exception ee) { - Debugger.runReport(ee); - } - } - - - @EventHandler - public void onClose(InventoryCloseEvent event) { - try { - instance.getPlayerDataManager().getPlayerData((Player) event.getPlayer()).setInOverview(false); - } catch (Exception e) { - Debugger.runReport(e); } } } \ No newline at end of file diff --git a/src/main/java/com/songoda/epicfurnaces/utils/gui/AbstractAnvilGUI.java b/src/main/java/com/songoda/epicfurnaces/utils/gui/AbstractAnvilGUI.java index aca7982..7b76502 100644 --- a/src/main/java/com/songoda/epicfurnaces/utils/gui/AbstractAnvilGUI.java +++ b/src/main/java/com/songoda/epicfurnaces/utils/gui/AbstractAnvilGUI.java @@ -1,7 +1,7 @@ -package com.songoda.epicspawners.utils.gui; +package com.songoda.epicfurnaces.utils.gui; -import com.songoda.epicspawners.EpicSpawners; -import com.songoda.epicspawners.utils.version.NMSUtil; +import com.songoda.epicfurnaces.EpicFurnaces; +import com.songoda.epicfurnaces.utils.version.NMSUtil; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -63,7 +63,7 @@ public class AbstractAnvilGUI { } public AbstractAnvilGUI(Player player, AnvilClickEventHandler handler) { - EpicSpawners instance = EpicSpawners.getInstance(); + EpicFurnaces instance = EpicFurnaces.getInstance(); this.player = player; this.listener = new Listener() { diff --git a/src/main/java/com/songoda/epicfurnaces/utils/gui/AbstractGUI.java b/src/main/java/com/songoda/epicfurnaces/utils/gui/AbstractGUI.java index 276a572..905e3dd 100644 --- a/src/main/java/com/songoda/epicfurnaces/utils/gui/AbstractGUI.java +++ b/src/main/java/com/songoda/epicfurnaces/utils/gui/AbstractGUI.java @@ -1,7 +1,7 @@ -package com.songoda.epicspawners.utils.gui; +package com.songoda.epicfurnaces.utils.gui; -import com.songoda.epicspawners.EpicSpawners; -import com.songoda.epicspawners.utils.Methods; +import com.songoda.epicfurnaces.EpicFurnaces; +import com.songoda.epicfurnaces.utils.Methods; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -125,7 +125,7 @@ public abstract class AbstractGUI implements Listener { registerOnCloses(); } constructGUI(); - initializeListeners(EpicSpawners.getInstance()); + initializeListeners(EpicFurnaces.getInstance()); player.openInventory(inventory); } diff --git a/src/main/java/com/songoda/epicfurnaces/utils/gui/Clickable.java b/src/main/java/com/songoda/epicfurnaces/utils/gui/Clickable.java index 7fd0335..b771fa7 100644 --- a/src/main/java/com/songoda/epicfurnaces/utils/gui/Clickable.java +++ b/src/main/java/com/songoda/epicfurnaces/utils/gui/Clickable.java @@ -1,4 +1,4 @@ -package com.songoda.epicspawners.utils.gui; +package com.songoda.epicfurnaces.utils.gui; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/src/main/java/com/songoda/epicfurnaces/utils/gui/OnClose.java b/src/main/java/com/songoda/epicfurnaces/utils/gui/OnClose.java index ad47c70..7e88460 100644 --- a/src/main/java/com/songoda/epicfurnaces/utils/gui/OnClose.java +++ b/src/main/java/com/songoda/epicfurnaces/utils/gui/OnClose.java @@ -1,4 +1,4 @@ -package com.songoda.epicspawners.utils.gui; +package com.songoda.epicfurnaces.utils.gui; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; diff --git a/src/main/java/com/songoda/epicfurnaces/utils/gui/Range.java b/src/main/java/com/songoda/epicfurnaces/utils/gui/Range.java index 115b672..af31885 100644 --- a/src/main/java/com/songoda/epicfurnaces/utils/gui/Range.java +++ b/src/main/java/com/songoda/epicfurnaces/utils/gui/Range.java @@ -1,7 +1,7 @@ -package com.songoda.epicspawners.utils.gui; +package com.songoda.epicfurnaces.utils.gui; -import com.songoda.epicspawners.EpicSpawners; -import com.songoda.epicspawners.utils.ServerVersion; +import com.songoda.epicfurnaces.EpicFurnaces; +import com.songoda.epicfurnaces.utils.ServerVersion; import org.bukkit.Sound; import org.bukkit.event.inventory.ClickType; @@ -18,7 +18,7 @@ public class Range { this.max = max; this.clickType = clickType; this.bottom = bottom; - if (EpicSpawners.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) onClickSound = Sound.UI_BUTTON_CLICK; + if (EpicFurnaces.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) onClickSound = Sound.UI_BUTTON_CLICK; } public Range(int min, int max, Sound onClickSound, ClickType clickType, boolean bottom) { diff --git a/src/main/resources/levels.yml b/src/main/resources/levels.yml index e69de29..080587e 100644 --- a/src/main/resources/levels.yml +++ b/src/main/resources/levels.yml @@ -0,0 +1,37 @@ +Level-1: + Performance: 10% + Reward: 10%:1 + Cost-xp: 20 + Cost-eco: 5000 +Level-2: + Performance: 25% + Reward: 20%:1-2 + Cost-xp: 25 + Cost-eco: 7500 +Level-3: + Performance: 40% + Reward: 35%:2-3 + Fuel-duration: 10% + Cost-xp: 30 + Cost-eco: 10000 +Level-4: + Performance: 55% + Reward: 50%:2-4 + Fuel-duration: 25% + Cost-xp: 35 + Cost-eco: 12000 +Level-5: + Performance: 75% + Reward: 70%:3-4 + Fuel-duration: 45% + Overheat: 1 + Cost-xp: 40 + Cost-eco: 15000 +Level-6: + Performance: 75% + Reward: 70%:3-4 + Fuel-duration: 45% + Overheat: 2 + Fuel-share: 1 + Cost-xp: 40 + Cost-eco: 15000 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0195a77..6eae01d 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,9 +1,8 @@ name: EpicFurnaces description: EpicFurnaces version: maven-version-number -depend: [Arconix] -softdepend: [PlotSquared, GriefPrevention, USkyBlock, SkyBlock, WorldGuard, Factions] -main: com.songoda.epicfurnaces.EpicFurnacesPlugin +softdepend: [HolographicDisplays, PlotSquared, GriefPrevention, USkyBlock, SkyBlock, WorldGuard, Factions] +main: com.songoda.epicfurnaces.EpicFurnaces author: songoda api-version: 1.13 commands: