Heavy code style changes and slight refactoring
This commit is contained in:
parent
a6acf326f8
commit
5347383f6b
|
@ -1,15 +1,15 @@
|
||||||
package com.songoda.epicenchants;
|
package com.songoda.epicenchants;
|
||||||
|
|
||||||
import com.songoda.epicenchants.utils.Methods;
|
import com.craftaro.core.utils.NumberUtils;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public class CommandCommons {
|
public class CommandCommons {
|
||||||
|
|
||||||
public static boolean isInt(String number, CommandSender sender) {
|
public static boolean isInt(String number, CommandSender sender) {
|
||||||
if (!Methods.isInt(number)) {
|
if (NumberUtils.isInt(number)) {
|
||||||
EpicEnchants.getInstance().getLocale().newMessage("Not a number.").sendPrefixedMessage(sender);
|
return true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
EpicEnchants.getPlugin(EpicEnchants.class).getLocale().newMessage("Not a number.").sendPrefixedMessage(sender);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.songoda.epicenchants;
|
||||||
import com.craftaro.core.SongodaCore;
|
import com.craftaro.core.SongodaCore;
|
||||||
import com.craftaro.core.SongodaPlugin;
|
import com.craftaro.core.SongodaPlugin;
|
||||||
import com.craftaro.core.commands.CommandManager;
|
import com.craftaro.core.commands.CommandManager;
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
|
||||||
import com.craftaro.core.configuration.Config;
|
import com.craftaro.core.configuration.Config;
|
||||||
import com.craftaro.core.gui.GuiManager;
|
import com.craftaro.core.gui.GuiManager;
|
||||||
import com.craftaro.core.hooks.EconomyManager;
|
import com.craftaro.core.hooks.EconomyManager;
|
||||||
|
@ -44,9 +43,6 @@ import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class EpicEnchants extends SongodaPlugin {
|
public class EpicEnchants extends SongodaPlugin {
|
||||||
|
|
||||||
private static EpicEnchants INSTANCE;
|
|
||||||
|
|
||||||
private final GuiManager guiManager = new GuiManager(this);
|
private final GuiManager guiManager = new GuiManager(this);
|
||||||
private EnchantManager enchantManager;
|
private EnchantManager enchantManager;
|
||||||
private InfoManager infoManager;
|
private InfoManager infoManager;
|
||||||
|
@ -58,21 +54,14 @@ public class EpicEnchants extends SongodaPlugin {
|
||||||
private EnchantUtils enchantUtils;
|
private EnchantUtils enchantUtils;
|
||||||
private ItemGroup itemGroup;
|
private ItemGroup itemGroup;
|
||||||
|
|
||||||
public static EpicEnchants getInstance() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginLoad() {
|
public void onPluginLoad() {
|
||||||
INSTANCE = this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginEnable() {
|
public void onPluginEnable() {
|
||||||
// Run Songoda Updater
|
|
||||||
SongodaCore.registerPlugin(this, 67, XMaterial.DIAMOND_SWORD);
|
SongodaCore.registerPlugin(this, 67, XMaterial.DIAMOND_SWORD);
|
||||||
|
|
||||||
// setup commands
|
|
||||||
this.commandManager = new com.craftaro.core.commands.CommandManager(this);
|
this.commandManager = new com.craftaro.core.commands.CommandManager(this);
|
||||||
this.commandManager.addMainCommand("ee")
|
this.commandManager.addMainCommand("ee")
|
||||||
.addSubCommand(new CommandReload(this))
|
.addSubCommand(new CommandReload(this))
|
||||||
|
@ -105,12 +94,12 @@ public class EpicEnchants extends SongodaPlugin {
|
||||||
this.commandManager = new CommandManager(this);
|
this.commandManager = new CommandManager(this);
|
||||||
this.itemGroup = new ItemGroup();
|
this.itemGroup = new ItemGroup();
|
||||||
|
|
||||||
groupManager.loadGroups();
|
this.groupManager.loadGroups();
|
||||||
enchantManager.loadEnchants();
|
this.enchantManager.loadEnchants();
|
||||||
infoManager.loadMenus();
|
this.infoManager.loadMenus();
|
||||||
|
|
||||||
// Listeners
|
// Listeners
|
||||||
guiManager.init();
|
this.guiManager.init();
|
||||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||||
pluginManager.registerEvents(new BookListener(this), this);
|
pluginManager.registerEvents(new BookListener(this), this);
|
||||||
pluginManager.registerEvents(new ArmorListener(), this);
|
pluginManager.registerEvents(new ArmorListener(), this);
|
||||||
|
@ -121,15 +110,15 @@ public class EpicEnchants extends SongodaPlugin {
|
||||||
pluginManager.registerEvents(new BlackScrollListener(this), this);
|
pluginManager.registerEvents(new BlackScrollListener(this), this);
|
||||||
pluginManager.registerEvents(new DustListener(this), this);
|
pluginManager.registerEvents(new DustListener(this), this);
|
||||||
|
|
||||||
if (!enchantManager.getValues().isEmpty()) {
|
if (!this.enchantManager.getValues().isEmpty()) {
|
||||||
getLogger().info("Successfully loaded enchants: " + enchantManager.getValues().stream().map(Enchant::getIdentifier).collect(Collectors.joining(", ")));
|
getLogger().info("Successfully loaded enchants: " + this.enchantManager.getValues().stream().map(Enchant::getIdentifier).collect(Collectors.joining(", ")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void preload() {
|
private void preload() {
|
||||||
FastInv.init(this);
|
FastInv.init(this);
|
||||||
this.fileManager = new FileManager(this);
|
this.fileManager = new FileManager(this);
|
||||||
fileManager.loadFiles();
|
this.fileManager.loadFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -142,17 +131,17 @@ public class EpicEnchants extends SongodaPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigReload() {
|
public void onConfigReload() {
|
||||||
fileManager.clear();
|
this.fileManager.clear();
|
||||||
fileManager.loadFiles();
|
this.fileManager.loadFiles();
|
||||||
|
|
||||||
groupManager.clear();
|
this.groupManager.clear();
|
||||||
groupManager.loadGroups();
|
this.groupManager.loadGroups();
|
||||||
|
|
||||||
enchantManager.clear();
|
this.enchantManager.clear();
|
||||||
enchantManager.loadEnchants();
|
this.enchantManager.loadEnchants();
|
||||||
|
|
||||||
infoManager.clear();
|
this.infoManager.clear();
|
||||||
infoManager.loadMenus();
|
this.infoManager.loadMenus();
|
||||||
|
|
||||||
this.setLocale(getConfig().getString("System.Language Mode"), true);
|
this.setLocale(getConfig().getString("System.Language Mode"), true);
|
||||||
this.locale.reloadMessages();
|
this.locale.reloadMessages();
|
||||||
|
@ -192,10 +181,18 @@ public class EpicEnchants extends SongodaPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandManager getCommandManager() {
|
public CommandManager getCommandManager() {
|
||||||
return commandManager;
|
return this.commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiManager getGuiManager() {
|
public GuiManager getGuiManager() {
|
||||||
return guiManager;
|
return this.guiManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link EpicEnchants#getPlugin(Class)} instead
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static EpicEnchants getInstance() {
|
||||||
|
return EpicEnchants.getPlugin(EpicEnchants.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,18 +9,17 @@ import org.bukkit.entity.Player;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandAlchemist extends AbstractCommand {
|
public class CommandAlchemist extends AbstractCommand {
|
||||||
|
|
||||||
private final EpicEnchants plugin;
|
private final EpicEnchants plugin;
|
||||||
|
|
||||||
public CommandAlchemist(EpicEnchants plugin) {
|
public CommandAlchemist(EpicEnchants plugin) {
|
||||||
super(true, "alchemist");
|
super(CommandType.PLAYER_ONLY, "alchemist");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
new AlchemistMenu(plugin, plugin.getFileManager().getConfiguration("menus/alchemist-menu")).open(player);
|
new AlchemistMenu(this.plugin, this.plugin.getFileManager().getConfiguration("menus/alchemist-menu")).open(player);
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,42 +20,45 @@ import static com.songoda.epicenchants.enums.EnchantResult.BROKEN_FAILURE;
|
||||||
import static com.songoda.epicenchants.utils.single.GeneralUtils.getMessageFromResult;
|
import static com.songoda.epicenchants.utils.single.GeneralUtils.getMessageFromResult;
|
||||||
|
|
||||||
public class CommandApply extends AbstractCommand {
|
public class CommandApply extends AbstractCommand {
|
||||||
|
|
||||||
private final EpicEnchants plugin;
|
private final EpicEnchants plugin;
|
||||||
|
|
||||||
public CommandApply(EpicEnchants plugin) {
|
public CommandApply(EpicEnchants plugin) {
|
||||||
super(true, "apply");
|
super(CommandType.PLAYER_ONLY, "apply");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
//apply [enchant] [level] <success-rate> <destroy-rate>
|
//apply [enchant] [level] <success-rate> <destroy-rate>
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
if (args.length < 2 || args.length > 4)
|
if (args.length < 2 || args.length > 4) {
|
||||||
return ReturnType.SYNTAX_ERROR;
|
return ReturnType.SYNTAX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
Optional<Enchant> optionalEnchant = plugin.getEnchantManager().getValue(args[0].replaceAll("_", " "));
|
Optional<Enchant> optionalEnchant = this.plugin.getEnchantManager().getValue(args[0].replaceAll("_", " "));
|
||||||
|
|
||||||
if (!optionalEnchant.isPresent()) {
|
if (!optionalEnchant.isPresent()) {
|
||||||
plugin.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
|
this.plugin.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CommandCommons.isInt(args[1], sender))
|
if (!CommandCommons.isInt(args[1], sender)) {
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
int successRate = 100;
|
int successRate = 100;
|
||||||
int destroyRate = 0;
|
int destroyRate = 0;
|
||||||
|
|
||||||
if (args.length > 2) {
|
if (args.length > 2) {
|
||||||
if (!CommandCommons.isInt(args[2], sender))
|
if (!CommandCommons.isInt(args[2], sender)) {
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
|
}
|
||||||
successRate = Integer.parseInt(args[2]);
|
successRate = Integer.parseInt(args[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 3) {
|
if (args.length > 3) {
|
||||||
if (!CommandCommons.isInt(args[3], sender))
|
if (!CommandCommons.isInt(args[3], sender)) {
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
|
}
|
||||||
destroyRate = Integer.parseInt(args[3]);
|
destroyRate = Integer.parseInt(args[3]);
|
||||||
}
|
}
|
||||||
Enchant enchant = optionalEnchant.get();
|
Enchant enchant = optionalEnchant.get();
|
||||||
|
@ -64,7 +67,7 @@ public class CommandApply extends AbstractCommand {
|
||||||
|
|
||||||
if (!enchant.getItemWhitelist().contains(CompatibleMaterial.getMaterial(player.getItemInHand().getType()).get())) {
|
if (!enchant.getItemWhitelist().contains(CompatibleMaterial.getMaterial(player.getItemInHand().getType()).get())) {
|
||||||
System.out.println("List = " + enchant.getItemWhitelist());
|
System.out.println("List = " + enchant.getItemWhitelist());
|
||||||
plugin.getLocale().getMessage("command.apply.invaliditem")
|
this.plugin.getLocale().getMessage("command.apply.invaliditem")
|
||||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||||
.sendPrefixedMessage(player);
|
.sendPrefixedMessage(player);
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
|
@ -72,10 +75,9 @@ public class CommandApply extends AbstractCommand {
|
||||||
|
|
||||||
int slot = player.getInventory().getHeldItemSlot();
|
int slot = player.getInventory().getHeldItemSlot();
|
||||||
ItemStack before = player.getItemInHand();
|
ItemStack before = player.getItemInHand();
|
||||||
Tuple<ItemStack, EnchantResult> result = plugin.getEnchantUtils().apply(before, enchant, level,
|
Tuple<ItemStack, EnchantResult> result = this.plugin.getEnchantUtils().apply(before, enchant, level, successRate, destroyRate);
|
||||||
successRate, destroyRate);
|
|
||||||
|
|
||||||
plugin.getLocale().getMessage(getMessageFromResult(result.getRight()))
|
this.plugin.getLocale().getMessage(getMessageFromResult(result.getRight()))
|
||||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||||
.sendPrefixedMessage(player);
|
.sendPrefixedMessage(player);
|
||||||
|
|
||||||
|
@ -91,21 +93,31 @@ public class CommandApply extends AbstractCommand {
|
||||||
@Override
|
@Override
|
||||||
protected List<String> onTab(CommandSender sender, String... args) {
|
protected List<String> onTab(CommandSender sender, String... args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
return plugin.getEnchantManager().getValues()
|
return this.plugin
|
||||||
.stream().map(Enchant::getIdentifier).collect(Collectors.toList());
|
.getEnchantManager()
|
||||||
|
.getValues()
|
||||||
|
.stream()
|
||||||
|
.map(Enchant::getIdentifier)
|
||||||
|
.collect(Collectors.toList());
|
||||||
} else if (args.length == 2) {
|
} else if (args.length == 2) {
|
||||||
Enchant enchant = plugin.getEnchantManager().getValues()
|
Enchant enchant = this.plugin
|
||||||
.stream().findFirst().orElse(null);
|
.getEnchantManager()
|
||||||
|
.getValues()
|
||||||
|
.stream()
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
List<String> levels = new ArrayList<>();
|
List<String> levels = new ArrayList<>();
|
||||||
if (enchant != null) {
|
if (enchant != null) {
|
||||||
for (int i = 1; i <= enchant.getMaxLevel(); i++)
|
for (int i = 1; i <= enchant.getMaxLevel(); i++) {
|
||||||
levels.add(String.valueOf(i));
|
levels.add(String.valueOf(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return levels;
|
return levels;
|
||||||
} else if (args.length == 3 || args.length == 4) {
|
} else if (args.length == 3 || args.length == 4) {
|
||||||
List<String> rates = new ArrayList<>();
|
List<String> rates = new ArrayList<>();
|
||||||
for (int i = 1; i <= 100; i++)
|
for (int i = 1; i <= 100; i++) {
|
||||||
rates.add(String.valueOf(i));
|
rates.add(String.valueOf(i));
|
||||||
|
}
|
||||||
return rates;
|
return rates;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -9,18 +9,17 @@ import org.bukkit.entity.Player;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandEnchanter extends AbstractCommand {
|
public class CommandEnchanter extends AbstractCommand {
|
||||||
|
|
||||||
private final EpicEnchants plugin;
|
private final EpicEnchants plugin;
|
||||||
|
|
||||||
public CommandEnchanter(EpicEnchants plugin) {
|
public CommandEnchanter(EpicEnchants plugin) {
|
||||||
super(true, "enchanter");
|
super(CommandType.PLAYER_ONLY, "enchanter");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
new EnchanterMenu(plugin, plugin.getFileManager().getConfiguration("menus/enchanter-menu"), player).open(player);
|
new EnchanterMenu(this.plugin, this.plugin.getFileManager().getConfiguration("menus/enchanter-menu"), player).open(player);
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,31 +15,31 @@ import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class CommandGiveBook extends AbstractCommand {
|
public class CommandGiveBook extends AbstractCommand {
|
||||||
|
|
||||||
private final EpicEnchants plugin;
|
private final EpicEnchants plugin;
|
||||||
|
|
||||||
public CommandGiveBook(EpicEnchants plugin) {
|
public CommandGiveBook(EpicEnchants plugin) {
|
||||||
super(false, "givebook");
|
super(CommandType.CONSOLE_OK, "givebook");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
//givebook <player> <enchant> [level] [success-rate] [destroy-rate]
|
//givebook <player> <enchant> [level] [success-rate] [destroy-rate]
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
if (args.length < 2 || args.length > 5)
|
if (args.length < 2 || args.length > 5) {
|
||||||
return ReturnType.SYNTAX_ERROR;
|
return ReturnType.SYNTAX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
OfflinePlayer target = Bukkit.getPlayer(args[0]);
|
OfflinePlayer target = Bukkit.getPlayer(args[0]);
|
||||||
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
this.plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Enchant> optionalEnchant = plugin.getEnchantManager().getValue(args[1].replaceAll("_", " "));
|
Optional<Enchant> optionalEnchant = this.plugin.getEnchantManager().getValue(args[1].replaceAll("_", " "));
|
||||||
|
|
||||||
if (!optionalEnchant.isPresent()) {
|
if (!optionalEnchant.isPresent()) {
|
||||||
plugin.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
|
this.plugin.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,25 +49,28 @@ public class CommandGiveBook extends AbstractCommand {
|
||||||
int destroyRate = -1;
|
int destroyRate = -1;
|
||||||
|
|
||||||
if (args.length > 2) {
|
if (args.length > 2) {
|
||||||
if (!CommandCommons.isInt(args[2], sender))
|
if (!CommandCommons.isInt(args[2], sender)) {
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
|
}
|
||||||
level = Integer.parseInt(args[2]);
|
level = Integer.parseInt(args[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 3) {
|
if (args.length > 3) {
|
||||||
if (!CommandCommons.isInt(args[3], sender))
|
if (!CommandCommons.isInt(args[3], sender)) {
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
|
}
|
||||||
successRate = Integer.parseInt(args[3]);
|
successRate = Integer.parseInt(args[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 4) {
|
if (args.length > 4) {
|
||||||
if (!CommandCommons.isInt(args[4], sender))
|
if (!CommandCommons.isInt(args[4], sender)) {
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
|
}
|
||||||
destroyRate = Integer.parseInt(args[4]);
|
destroyRate = Integer.parseInt(args[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level != -0 && (level > enchant.getMaxLevel() || level < 0)) {
|
if (level != -0 && (level > enchant.getMaxLevel() || level < 0)) {
|
||||||
plugin.getLocale().getMessage("command.book." + (level > enchant.getMaxLevel() ? "maxlevel" : "minlevel"))
|
this.plugin.getLocale().getMessage("command.book." + (level > enchant.getMaxLevel() ? "maxlevel" : "minlevel"))
|
||||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||||
.processPlaceholder("max_level", enchant.getMaxLevel())
|
.processPlaceholder("max_level", enchant.getMaxLevel())
|
||||||
.sendPrefixedMessage(sender);
|
.sendPrefixedMessage(sender);
|
||||||
|
@ -75,10 +78,10 @@ public class CommandGiveBook extends AbstractCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
target.getPlayer().getInventory().addItem(enchant.getBook().get(enchant, level, successRate, destroyRate));
|
target.getPlayer().getInventory().addItem(enchant.getBook().get(enchant, level, successRate, destroyRate));
|
||||||
plugin.getLocale().getMessage("command.book.received")
|
this.plugin.getLocale().getMessage("command.book.received")
|
||||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||||
.sendPrefixedMessage(target.getPlayer());
|
.sendPrefixedMessage(target.getPlayer());
|
||||||
plugin.getLocale().getMessage("command.book.gave")
|
this.plugin.getLocale().getMessage("command.book.gave")
|
||||||
.processPlaceholder("player", target.getPlayer().getName())
|
.processPlaceholder("player", target.getPlayer().getName())
|
||||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||||
.sendPrefixedMessage(sender);
|
.sendPrefixedMessage(sender);
|
||||||
|
@ -90,21 +93,27 @@ public class CommandGiveBook extends AbstractCommand {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||||
} else if (args.length == 2) {
|
} else if (args.length == 2) {
|
||||||
return plugin.getEnchantManager().getValues()
|
return this.plugin.getEnchantManager().getValues()
|
||||||
.stream().map(Enchant::getIdentifier).collect(Collectors.toList());
|
.stream().map(Enchant::getIdentifier).collect(Collectors.toList());
|
||||||
} else if (args.length == 3) {
|
} else if (args.length == 3) {
|
||||||
Enchant enchant = plugin.getEnchantManager().getValues()
|
Enchant enchant = this.plugin
|
||||||
.stream().findFirst().orElse(null);
|
.getEnchantManager()
|
||||||
|
.getValues()
|
||||||
|
.stream()
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
List<String> levels = new ArrayList<>();
|
List<String> levels = new ArrayList<>();
|
||||||
if (enchant != null) {
|
if (enchant != null) {
|
||||||
for (int i = 1; i <= enchant.getMaxLevel(); i++)
|
for (int i = 1; i <= enchant.getMaxLevel(); i++) {
|
||||||
levels.add(String.valueOf(i));
|
levels.add(String.valueOf(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return levels;
|
return levels;
|
||||||
} else if (args.length == 4 || args.length == 5) {
|
} else if (args.length == 4 || args.length == 5) {
|
||||||
List<String> rates = new ArrayList<>();
|
List<String> rates = new ArrayList<>();
|
||||||
for (int i = 1; i <= 100; i++)
|
for (int i = 1; i <= 100; i++) {
|
||||||
rates.add(String.valueOf(i));
|
rates.add(String.valueOf(i));
|
||||||
|
}
|
||||||
return rates;
|
return rates;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -15,32 +15,32 @@ import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class CommandGiveItemDust extends AbstractCommand {
|
public class CommandGiveItemDust extends AbstractCommand {
|
||||||
|
|
||||||
private final EpicEnchants plugin;
|
private final EpicEnchants plugin;
|
||||||
|
|
||||||
public CommandGiveItemDust(EpicEnchants plugin) {
|
public CommandGiveItemDust(EpicEnchants plugin) {
|
||||||
super(false, "giveitemdust");
|
super(CommandType.CONSOLE_OK, "giveitemdust");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
//giveitemdust <player> <group> [type] [percentage]
|
//giveitemdust <player> <group> [type] [percentage]
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
if (args.length < 2 || args.length > 5)
|
if (args.length < 2 || args.length > 5) {
|
||||||
return ReturnType.SYNTAX_ERROR;
|
return ReturnType.SYNTAX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
OfflinePlayer target = Bukkit.getPlayer(args[0]);
|
OfflinePlayer target = Bukkit.getPlayer(args[0]);
|
||||||
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
this.plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Group> groups = plugin.getGroupManager().getValues().stream()
|
List<Group> groups = this.plugin.getGroupManager().getValues().stream()
|
||||||
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[1])).collect(Collectors.toList());
|
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[1])).collect(Collectors.toList());
|
||||||
|
|
||||||
if (groups.isEmpty()) {
|
if (groups.isEmpty()) {
|
||||||
plugin.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
|
this.plugin.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,16 +54,17 @@ public class CommandGiveItemDust extends AbstractCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 3) {
|
if (args.length > 3) {
|
||||||
if (!CommandCommons.isInt(args[3], sender))
|
if (!CommandCommons.isInt(args[3], sender)) {
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
|
}
|
||||||
percentage = Integer.parseInt(args[3]);
|
percentage = Integer.parseInt(args[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getDust(group, dustType, percentage, true));
|
target.getPlayer().getInventory().addItem(this.plugin.getSpecialItems().getDust(group, dustType, percentage, true));
|
||||||
plugin.getLocale().getMessage("command.dust.received")
|
this.plugin.getLocale().getMessage("command.dust.received")
|
||||||
.processPlaceholder("group", group.getIdentifier())
|
.processPlaceholder("group", group.getIdentifier())
|
||||||
.sendPrefixedMessage(target.getPlayer());
|
.sendPrefixedMessage(target.getPlayer());
|
||||||
plugin.getLocale().getMessage("command.dust.gave")
|
this.plugin.getLocale().getMessage("command.dust.gave")
|
||||||
.processPlaceholder("player", target.getPlayer().getName())
|
.processPlaceholder("player", target.getPlayer().getName())
|
||||||
.processPlaceholder("group", group.getIdentifier())
|
.processPlaceholder("group", group.getIdentifier())
|
||||||
.sendPrefixedMessage(sender);
|
.sendPrefixedMessage(sender);
|
||||||
|
@ -75,18 +76,22 @@ public class CommandGiveItemDust extends AbstractCommand {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||||
} else if (args.length == 2) {
|
} else if (args.length == 2) {
|
||||||
return plugin.getGroupManager().getValues().stream()
|
return this.plugin.getGroupManager()
|
||||||
.map(Group::getIdentifier).collect(Collectors.toList());
|
.getValues()
|
||||||
|
.stream()
|
||||||
|
.map(Group::getIdentifier)
|
||||||
|
.collect(Collectors.toList());
|
||||||
} else if (args.length == 3) {
|
} else if (args.length == 3) {
|
||||||
List<String> dusts = new ArrayList<>();
|
List<String> dusts = new ArrayList<>();
|
||||||
|
|
||||||
FileConfiguration dustConfig = plugin.getFileManager().getConfiguration("items/dusts");
|
FileConfiguration dustConfig = this.plugin.getFileManager().getConfiguration("items/dusts");
|
||||||
dusts.addAll(dustConfig.getConfigurationSection("dusts").getKeys(false));
|
dusts.addAll(dustConfig.getConfigurationSection("dusts").getKeys(false));
|
||||||
return dusts;
|
return dusts;
|
||||||
} else if (args.length == 4) {
|
} else if (args.length == 4) {
|
||||||
List<String> rates = new ArrayList<>();
|
List<String> rates = new ArrayList<>();
|
||||||
for (int i = 1; i <= 100; i++)
|
for (int i = 1; i <= 100; i++) {
|
||||||
rates.add(String.valueOf(i));
|
rates.add(String.valueOf(i));
|
||||||
|
}
|
||||||
return rates;
|
return rates;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -16,37 +16,38 @@ public class CommandGiveRandomBook extends AbstractCommand {
|
||||||
private final EpicEnchants plugin;
|
private final EpicEnchants plugin;
|
||||||
|
|
||||||
public CommandGiveRandomBook(EpicEnchants plugin) {
|
public CommandGiveRandomBook(EpicEnchants plugin) {
|
||||||
super(false, "giverandombook");
|
super(CommandType.CONSOLE_OK, "giverandombook");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
//giverandombook <player> <group>
|
//giverandombook <player> <group>
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
if (args.length < 2 || args.length > 6)
|
if (args.length < 2 || args.length > 6) {
|
||||||
return ReturnType.SYNTAX_ERROR;
|
return ReturnType.SYNTAX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
OfflinePlayer target = Bukkit.getPlayer(args[0]);
|
OfflinePlayer target = Bukkit.getPlayer(args[0]);
|
||||||
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
this.plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Group> groups = plugin.getGroupManager().getValues().stream()
|
List<Group> groups = this.plugin.getGroupManager().getValues().stream()
|
||||||
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[1])).collect(Collectors.toList());
|
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[1])).collect(Collectors.toList());
|
||||||
|
|
||||||
if (groups.isEmpty()) {
|
if (groups.isEmpty()) {
|
||||||
plugin.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
|
this.plugin.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Group group = groups.get(0);
|
Group group = groups.get(0);
|
||||||
|
|
||||||
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getMysteryBook(group));
|
target.getPlayer().getInventory().addItem(this.plugin.getSpecialItems().getMysteryBook(group));
|
||||||
plugin.getLocale().getMessage("command.randombook.received")
|
this.plugin.getLocale().getMessage("command.randombook.received")
|
||||||
.sendPrefixedMessage(target.getPlayer());
|
.sendPrefixedMessage(target.getPlayer());
|
||||||
plugin.getLocale().getMessage("command.randombook.gave")
|
this.plugin.getLocale().getMessage("command.randombook.gave")
|
||||||
.processPlaceholder("player", target.getPlayer().getName())
|
.processPlaceholder("player", target.getPlayer().getName())
|
||||||
.sendPrefixedMessage(sender);
|
.sendPrefixedMessage(sender);
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
|
@ -55,10 +56,16 @@ public class CommandGiveRandomBook extends AbstractCommand {
|
||||||
@Override
|
@Override
|
||||||
protected List<String> onTab(CommandSender sender, String... args) {
|
protected List<String> onTab(CommandSender sender, String... args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
return Bukkit.getOnlinePlayers()
|
||||||
|
.stream()
|
||||||
|
.map(Player::getName)
|
||||||
|
.collect(Collectors.toList());
|
||||||
} else if (args.length == 2) {
|
} else if (args.length == 2) {
|
||||||
return plugin.getGroupManager().getValues().stream()
|
return this.plugin.getGroupManager()
|
||||||
.map(Group::getIdentifier).collect(Collectors.toList());
|
.getValues()
|
||||||
|
.stream()
|
||||||
|
.map(Group::getIdentifier)
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,25 +14,25 @@ import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class CommandGiveScroll extends AbstractCommand {
|
public class CommandGiveScroll extends AbstractCommand {
|
||||||
|
|
||||||
private final EpicEnchants plugin;
|
private final EpicEnchants plugin;
|
||||||
|
|
||||||
public CommandGiveScroll(EpicEnchants plugin) {
|
public CommandGiveScroll(EpicEnchants plugin) {
|
||||||
super(false, "givescroll");
|
super(CommandType.CONSOLE_OK, "givescroll");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
//givescroll <giveType> <player> [amount] [success-rate]
|
//givescroll <giveType> <player> [amount] [success-rate]
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
if (args.length < 2 || args.length > 5)
|
if (args.length < 2 || args.length > 5) {
|
||||||
return ReturnType.SYNTAX_ERROR;
|
return ReturnType.SYNTAX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
String giveType = args[0];
|
String giveType = args[0];
|
||||||
OfflinePlayer target = Bukkit.getPlayer(args[1]);
|
OfflinePlayer target = Bukkit.getPlayer(args[1]);
|
||||||
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
this.plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,37 +40,39 @@ public class CommandGiveScroll extends AbstractCommand {
|
||||||
int successRate = -1;
|
int successRate = -1;
|
||||||
|
|
||||||
if (args.length > 2) {
|
if (args.length > 2) {
|
||||||
if (!CommandCommons.isInt(args[2], sender))
|
if (!CommandCommons.isInt(args[2], sender)) {
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
|
}
|
||||||
amount = Integer.parseInt(args[2]);
|
amount = Integer.parseInt(args[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 3) {
|
if (args.length > 3) {
|
||||||
if (!CommandCommons.isInt(args[3], sender))
|
if (!CommandCommons.isInt(args[3], sender)) {
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
|
}
|
||||||
successRate = Integer.parseInt(args[3]);
|
successRate = Integer.parseInt(args[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
String messageKey;
|
String messageKey;
|
||||||
switch (giveType.toLowerCase()) {
|
switch (giveType.toLowerCase()) {
|
||||||
case "whitescroll":
|
case "whitescroll":
|
||||||
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getWhiteScroll(amount));
|
target.getPlayer().getInventory().addItem(this.plugin.getSpecialItems().getWhiteScroll(amount));
|
||||||
messageKey = "whitescroll";
|
messageKey = "whitescroll";
|
||||||
break;
|
break;
|
||||||
case "blackscroll":
|
case "blackscroll":
|
||||||
messageKey = "blackscroll";
|
messageKey = "blackscroll";
|
||||||
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getBlackScroll(amount, successRate));
|
target.getPlayer().getInventory().addItem(this.plugin.getSpecialItems().getBlackScroll(amount, successRate));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
plugin.getLocale().getMessage("command.giveunknown")
|
this.plugin.getLocale().getMessage("command.giveunknown")
|
||||||
.processPlaceholder("unknown", giveType)
|
.processPlaceholder("unknown", giveType)
|
||||||
.sendPrefixedMessage(sender);
|
.sendPrefixedMessage(sender);
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getLocale().getMessage("command." + messageKey + ".received")
|
this.plugin.getLocale().getMessage("command." + messageKey + ".received")
|
||||||
.sendPrefixedMessage(target.getPlayer());
|
.sendPrefixedMessage(target.getPlayer());
|
||||||
plugin.getLocale().getMessage("command." + messageKey + ".gave")
|
this.plugin.getLocale().getMessage("command." + messageKey + ".gave")
|
||||||
.processPlaceholder("player", target.getName())
|
.processPlaceholder("player", target.getName())
|
||||||
.sendPrefixedMessage(sender);
|
.sendPrefixedMessage(sender);
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
|
@ -81,11 +83,15 @@ public class CommandGiveScroll extends AbstractCommand {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
return Arrays.asList("whitescroll", "blackscroll");
|
return Arrays.asList("whitescroll", "blackscroll");
|
||||||
} else if (args.length == 2) {
|
} else if (args.length == 2) {
|
||||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
return Bukkit.getOnlinePlayers()
|
||||||
|
.stream()
|
||||||
|
.map(Player::getName)
|
||||||
|
.collect(Collectors.toList());
|
||||||
} else if (args.length == 3 || args.length == 4) {
|
} else if (args.length == 3 || args.length == 4) {
|
||||||
List<String> rates = new ArrayList<>();
|
List<String> rates = new ArrayList<>();
|
||||||
for (int i = 1; i <= (args.length == 3 ? 10 : 100); i++)
|
for (int i = 1; i <= (args.length == 3 ? 10 : 100); i++) {
|
||||||
rates.add(String.valueOf(i));
|
rates.add(String.valueOf(i));
|
||||||
|
}
|
||||||
return rates;
|
return rates;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -10,24 +10,23 @@ import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class CommandList extends AbstractCommand {
|
public class CommandList extends AbstractCommand {
|
||||||
|
|
||||||
private final EpicEnchants plugin;
|
private final EpicEnchants plugin;
|
||||||
|
|
||||||
public CommandList(EpicEnchants plugin) {
|
public CommandList(EpicEnchants plugin) {
|
||||||
super(true, "list");
|
super(CommandType.PLAYER_ONLY, "list");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
if (args.length > 1 && args[1].equalsIgnoreCase("chat")) {
|
if (args.length > 1 && args[1].equalsIgnoreCase("chat")) {
|
||||||
plugin.getLocale().newMessage(plugin.getEnchantManager().getValues().stream()
|
this.plugin.getLocale().newMessage(this.plugin.getEnchantManager().getValues().stream()
|
||||||
.sorted(Comparator.comparing(enchant -> enchant.getGroup().getOrder()))
|
.sorted(Comparator.comparing(enchant -> enchant.getGroup().getOrder()))
|
||||||
.map(enchant -> enchant.getColoredIdentifier(true)).collect(Collectors.joining("&7, ")))
|
.map(enchant -> enchant.getColoredIdentifier(true)).collect(Collectors.joining("&7, ")))
|
||||||
.sendPrefixedMessage(sender);
|
.sendPrefixedMessage(sender);
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
}
|
}
|
||||||
plugin.getInfoManager().getMainInfoMenu().open((Player) sender);
|
this.plugin.getInfoManager().getMainInfoMenu().open((Player) sender);
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,18 +7,17 @@ import org.bukkit.command.CommandSender;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandReload extends AbstractCommand {
|
public class CommandReload extends AbstractCommand {
|
||||||
|
|
||||||
private final EpicEnchants plugin;
|
private final EpicEnchants plugin;
|
||||||
|
|
||||||
public CommandReload(EpicEnchants plugin) {
|
public CommandReload(EpicEnchants plugin) {
|
||||||
super(false, "reload");
|
super(CommandType.CONSOLE_OK, "reload");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
plugin.reloadConfig();
|
this.plugin.reloadConfig();
|
||||||
plugin.getLocale().getMessage("command.reload").sendPrefixedMessage(sender);
|
this.plugin.getLocale().getMessage("command.reload").sendPrefixedMessage(sender);
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,17 +9,16 @@ import org.bukkit.entity.Player;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandSettings extends AbstractCommand {
|
public class CommandSettings extends AbstractCommand {
|
||||||
|
|
||||||
private final EpicEnchants plugin;
|
private final EpicEnchants plugin;
|
||||||
|
|
||||||
public CommandSettings(EpicEnchants plugin) {
|
public CommandSettings(EpicEnchants plugin) {
|
||||||
super(true, "Settings");
|
super(CommandType.PLAYER_ONLY, "Settings");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
plugin.getGuiManager().showGUI((Player) sender, new PluginConfigGui(plugin));
|
this.plugin.getGuiManager().showGUI((Player) sender, new PluginConfigGui(this.plugin));
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,18 +9,17 @@ import org.bukkit.entity.Player;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandTinkerer extends AbstractCommand {
|
public class CommandTinkerer extends AbstractCommand {
|
||||||
|
|
||||||
private final EpicEnchants plugin;
|
private final EpicEnchants plugin;
|
||||||
|
|
||||||
public CommandTinkerer(EpicEnchants plugin) {
|
public CommandTinkerer(EpicEnchants plugin) {
|
||||||
super(true, "tinkerer");
|
super(CommandType.PLAYER_ONLY, "tinkerer");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
new TinkererMenu(plugin, plugin.getFileManager().getConfiguration("menus/tinkerer-menu")).open(player);
|
new TinkererMenu(this.plugin, this.plugin.getFileManager().getConfiguration("menus/tinkerer-menu")).open(player);
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,15 +45,15 @@ public abstract class EffectExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAndRun(@NotNull Player user, @Nullable LivingEntity opponent, int level, TriggerType type, Event event, EventType eventType, boolean simul) {
|
public void testAndRun(@NotNull Player user, @Nullable LivingEntity opponent, int level, TriggerType type, Event event, EventType eventType, boolean simul) {
|
||||||
if (!simul && !triggerTypes.contains(type)) {
|
if (!simul && !this.triggerTypes.contains(type)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section.isString("chance") && !GeneralUtils.chance(LeveledModifier.of(section.getString("chance")).get(level, 100, user, opponent))) {
|
if (this.section.isString("chance") && !GeneralUtils.chance(LeveledModifier.of(this.section.getString("chance")).get(level, 100, user, opponent))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!condition.get(user, opponent, level, event, false)) {
|
if (!this.condition.get(user, opponent, level, event, false)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,25 +63,31 @@ public abstract class EffectExecutor {
|
||||||
execute(user, opponent, level, eventType);
|
execute(user, opponent, level, eventType);
|
||||||
}
|
}
|
||||||
|
|
||||||
simultaneous.forEach(e -> e.testAndRun(user, opponent, level, type, event, eventType, true));
|
this.simultaneous.forEach(e -> e.testAndRun(user, opponent, level, type, event, eventType, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType);
|
public abstract void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType);
|
||||||
|
|
||||||
protected Who who() {
|
protected Who who() {
|
||||||
if (section.isString("who")) {
|
if (this.section.isString("who")) {
|
||||||
if (section.getString("who").equalsIgnoreCase("user")) return USER;
|
if (this.section.getString("who").equalsIgnoreCase("user")) {
|
||||||
else if (section.getString("who").equalsIgnoreCase("opponent")) return OPPONENT;
|
return USER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.section.getString("who").equalsIgnoreCase("opponent")) {
|
||||||
|
return OPPONENT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return USER;
|
return USER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LeveledModifier getAmount() {
|
public LeveledModifier getAmount() {
|
||||||
return LeveledModifier.of(section.getString("amount"));
|
return LeveledModifier.of(this.section.getString("amount"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void consume(Consumer<LivingEntity> playerConsumer, Player user, @Nullable LivingEntity opponent) {
|
public void consume(Consumer<LivingEntity> playerConsumer, Player user, @Nullable LivingEntity opponent) {
|
||||||
if (triggerTypes.contains(TriggerType.HELD_ITEM) || triggerTypes.contains(TriggerType.STATIC_EFFECT)) {
|
if (this.triggerTypes.contains(TriggerType.HELD_ITEM) || this.triggerTypes.contains(TriggerType.STATIC_EFFECT)) {
|
||||||
playerConsumer.accept(user);
|
playerConsumer.accept(user);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -91,8 +97,9 @@ public abstract class EffectExecutor {
|
||||||
playerConsumer.accept(user);
|
playerConsumer.accept(user);
|
||||||
break;
|
break;
|
||||||
case OPPONENT:
|
case OPPONENT:
|
||||||
if (opponent != null)
|
if (opponent != null) {
|
||||||
playerConsumer.accept(opponent);
|
playerConsumer.accept(opponent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,12 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static com.google.common.base.CaseFormat.UPPER_CAMEL;
|
import static com.google.common.base.CaseFormat.UPPER_CAMEL;
|
||||||
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
|
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
|
||||||
|
|
||||||
public class EffectManager {
|
public class EffectManager {
|
||||||
|
|
||||||
public static Optional<EffectExecutor> getEffect(ConfigurationSection section) {
|
public static Optional<EffectExecutor> getEffect(ConfigurationSection section) {
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
@ -23,8 +21,8 @@ public class EffectManager {
|
||||||
Constructor<?> constructor = clazz.getConstructor(ConfigurationSection.class);
|
Constructor<?> constructor = clazz.getConstructor(ConfigurationSection.class);
|
||||||
Object object = constructor.newInstance(section);
|
Object object = constructor.newInstance(section);
|
||||||
return Optional.of((EffectExecutor) object);
|
return Optional.of((EffectExecutor) object);
|
||||||
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | ClassCastException e) {
|
} catch (ReflectiveOperationException | ClassCastException ex) {
|
||||||
e.printStackTrace();
|
ex.printStackTrace();
|
||||||
Bukkit.getLogger().severe("Invalid effect: " + section.getName());
|
Bukkit.getLogger().severe("Invalid effect: " + section.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class CancelEvent extends EffectEventExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player player, LivingEntity opponent, int level, Event event, EventType eventType) {
|
public void execute(Player user, LivingEntity opponent, int level, Event event, EventType eventType) {
|
||||||
if (event instanceof Cancellable) {
|
if (event instanceof Cancellable) {
|
||||||
((Cancellable) event).setCancelled(true);
|
((Cancellable) event).setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,8 @@ public class ConsoleCommand extends EffectExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
|
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
|
||||||
GeneralUtils.getString(getSection(), "command").stream()
|
GeneralUtils.getString(getSection(), "command")
|
||||||
|
.stream()
|
||||||
.map(s -> Placeholders.setPlaceholders(s, user, opponent, level))
|
.map(s -> Placeholders.setPlaceholders(s, user, opponent, level))
|
||||||
.forEach(s -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s));
|
.forEach(s -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s));
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,7 @@ public class DropHeld extends EffectExecutor {
|
||||||
consume(entity -> {
|
consume(entity -> {
|
||||||
Player player = ((Player) entity);
|
Player player = ((Player) entity);
|
||||||
if (player.getItemInHand().getType() != Material.AIR) {
|
if (player.getItemInHand().getType() != Material.AIR) {
|
||||||
entity.getLocation().getWorld().dropItemNaturally(entity.getLocation(), new ItemBuilder(player
|
entity.getLocation().getWorld().dropItemNaturally(entity.getLocation(), new ItemBuilder(player.getItemInHand()).build());
|
||||||
.getItemInHand()).build());
|
|
||||||
player.setItemInHand(null);
|
player.setItemInHand(null);
|
||||||
}
|
}
|
||||||
}, user, opponent);
|
}, user, opponent);
|
||||||
|
|
|
@ -16,7 +16,6 @@ public class DropItem extends EffectExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) {
|
public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) {
|
||||||
consume(entity -> entity.getLocation().getWorld().dropItemNaturally(entity.getLocation(),
|
consume(entity -> entity.getLocation().getWorld().dropItemNaturally(entity.getLocation(), new ItemBuilder(getSection(), ((Player) entity)).build()), user, opponent);
|
||||||
new ItemBuilder(getSection(), ((Player) entity)).build()), user, opponent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,8 @@ public class Message extends EffectExecutor {
|
||||||
@Override
|
@Override
|
||||||
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
|
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
|
||||||
if (eventType == EventType.ON || eventType == EventType.NONE) {
|
if (eventType == EventType.ON || eventType == EventType.NONE) {
|
||||||
consume(entity -> GeneralUtils.getString(getSection(), "message").stream()
|
consume(entity -> GeneralUtils.getString(getSection(), "message")
|
||||||
|
.stream()
|
||||||
.map(s -> Placeholders.setPlaceholders(s, user, opponent, level))
|
.map(s -> Placeholders.setPlaceholders(s, user, opponent, level))
|
||||||
.forEach(entity::sendMessage), user, opponent);
|
.forEach(entity::sendMessage), user, opponent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ public class ModifyBlock extends EffectEventExecutor {
|
||||||
block.breakNaturally();
|
block.breakNaturally();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
block.setType(Material.getMaterial(getSection().getString("material")));
|
block.setType(Material.getMaterial(getSection().getString("material")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,8 @@ public class MoreDrops extends EffectEventExecutor {
|
||||||
|
|
||||||
EntityDeathEvent deathEvent = (EntityDeathEvent) event;
|
EntityDeathEvent deathEvent = (EntityDeathEvent) event;
|
||||||
LeveledModifier modifier = getAmount();
|
LeveledModifier modifier = getAmount();
|
||||||
List<ItemStack> newDrops = deathEvent.getDrops().stream()
|
List<ItemStack> newDrops = deathEvent.getDrops()
|
||||||
|
.stream()
|
||||||
.peek(itemStack -> itemStack.setAmount(((int) (itemStack.getAmount() * modifier.get(level, 1, user, opponent)))))
|
.peek(itemStack -> itemStack.setAmount(((int) (itemStack.getAmount() * modifier.get(level, 1, user, opponent)))))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,8 @@ public class PlayerCommand extends EffectExecutor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
consume(entity -> GeneralUtils.getString(getSection(), "message").stream()
|
consume(entity -> GeneralUtils.getString(getSection(), "message")
|
||||||
|
.stream()
|
||||||
.map(s -> Placeholders.setPlaceholders(s, user, opponent, level))
|
.map(s -> Placeholders.setPlaceholders(s, user, opponent, level))
|
||||||
.forEach(((Player) entity)::performCommand), user, opponent);
|
.forEach(((Player) entity)::performCommand), user, opponent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,17 +31,24 @@ public class Potion extends EffectExecutor {
|
||||||
|
|
||||||
if (getTriggerTypes().contains(TriggerType.STATIC_EFFECT) || getTriggerTypes().contains(TriggerType.HELD_ITEM)) {
|
if (getTriggerTypes().contains(TriggerType.STATIC_EFFECT) || getTriggerTypes().contains(TriggerType.HELD_ITEM)) {
|
||||||
if (eventType == EventType.ON) {
|
if (eventType == EventType.ON) {
|
||||||
consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, Integer.MAX_VALUE, (int) amplifier.get(level - 1, 0, user, opponent),
|
consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, Integer.MAX_VALUE, (int) amplifier.get(level - 1, 0, user, opponent), false, false)), user, opponent);
|
||||||
false, false)), user, opponent);
|
|
||||||
} else if (eventType == EventType.OFF) {
|
} else if (eventType == EventType.OFF) {
|
||||||
consume(entity -> entity.removePotionEffect(effectType), user, opponent);
|
consume(entity -> entity.removePotionEffect(effectType), user, opponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LeveledModifier duration = LeveledModifier.of(getSection().getString("duration"));
|
LeveledModifier duration = LeveledModifier.of(getSection().getString("duration"));
|
||||||
|
|
||||||
consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, (int) duration.get(level, 60, user, opponent) * 20,
|
consume(
|
||||||
(int) amplifier.get(level - 1, 0, user, opponent), false, false)), user, opponent);
|
entity -> entity.addPotionEffect(new PotionEffect(effectType,
|
||||||
|
(int) duration.get(level, 60, user, opponent) * 20,
|
||||||
|
(int) amplifier.get(level - 1, 0, user, opponent),
|
||||||
|
false,
|
||||||
|
false)),
|
||||||
|
user,
|
||||||
|
opponent
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,9 @@ public class Repair extends EffectExecutor {
|
||||||
@Override
|
@Override
|
||||||
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
|
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
|
||||||
consume(livingEntity -> {
|
consume(livingEntity -> {
|
||||||
if (livingEntity instanceof Player)
|
if (livingEntity instanceof Player) {
|
||||||
((Player) livingEntity).getItemInHand().setDurability((short) 0);
|
((Player) livingEntity).getItemInHand().setDurability((short) 0);
|
||||||
|
}
|
||||||
}, user, opponent);
|
}, user, opponent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,37 +19,41 @@ import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
|
||||||
import static java.util.concurrent.ThreadLocalRandom.current;
|
import static java.util.concurrent.ThreadLocalRandom.current;
|
||||||
|
|
||||||
public class SpawnMob extends EffectExecutor {
|
public class SpawnMob extends EffectExecutor {
|
||||||
private LeveledModifier attackDamage;
|
private final LeveledModifier attackDamage;
|
||||||
private String displayName;
|
private final String displayName;
|
||||||
private EntityType entityType;
|
private final EntityType entityType;
|
||||||
private LeveledModifier equipmentDropChance;
|
private final LeveledModifier equipmentDropChance;
|
||||||
private LeveledModifier health;
|
private final LeveledModifier health;
|
||||||
private ItemBuilder helmet, chestPlate, leggings, boots, handItem;
|
private final ItemBuilder helmet;
|
||||||
private boolean hostile;
|
private final ItemBuilder chestPlate;
|
||||||
private LeveledModifier amount;
|
private final ItemBuilder leggings;
|
||||||
|
private final ItemBuilder boots;
|
||||||
|
private final ItemBuilder handItem;
|
||||||
|
private final boolean hostile;
|
||||||
|
private final LeveledModifier amount;
|
||||||
|
|
||||||
public SpawnMob(ConfigurationSection section) {
|
public SpawnMob(ConfigurationSection section) {
|
||||||
super(section);
|
super(section);
|
||||||
|
|
||||||
entityType = EntityType.valueOf(section.getString("mob-type"));
|
this.entityType = EntityType.valueOf(section.getString("mob-type"));
|
||||||
amount = of(section.getString("amount"));
|
this.amount = of(section.getString("amount"));
|
||||||
health = of(section.getString("health"));
|
this.health = of(section.getString("health"));
|
||||||
attackDamage = of(section.getString("attack-damage"));
|
this.attackDamage = of(section.getString("attack-damage"));
|
||||||
equipmentDropChance = LeveledModifier.of(section.getString("equipment-drop-chance"));
|
this.equipmentDropChance = LeveledModifier.of(section.getString("equipment-drop-chance"));
|
||||||
hostile = section.getBoolean("hostile", false);
|
this.hostile = section.getBoolean("hostile", false);
|
||||||
displayName = section.isString("display-name") ? color(section.getString("display-name")) : "";
|
this.displayName = section.isString("display-name") ? color(section.getString("display-name")) : "";
|
||||||
helmet = section.isConfigurationSection("equipment.helmet") ? new ItemBuilder(section.getConfigurationSection("equipment.helmet")) : null;
|
this.helmet = section.isConfigurationSection("equipment.helmet") ? new ItemBuilder(section.getConfigurationSection("equipment.helmet")) : null;
|
||||||
chestPlate = section.isConfigurationSection("equipment.chestplate") ? new ItemBuilder(section.getConfigurationSection("equipment.chestplate")) : null;
|
this.chestPlate = section.isConfigurationSection("equipment.chestplate") ? new ItemBuilder(section.getConfigurationSection("equipment.chestplate")) : null;
|
||||||
leggings = section.isConfigurationSection("equipment.leggings") ? new ItemBuilder(section.getConfigurationSection("equipment.leggings")) : null;
|
this.leggings = section.isConfigurationSection("equipment.leggings") ? new ItemBuilder(section.getConfigurationSection("equipment.leggings")) : null;
|
||||||
boots = section.isConfigurationSection("equipment.boots") ? new ItemBuilder(section.getConfigurationSection("equipment.boots")) : null;
|
this.boots = section.isConfigurationSection("equipment.boots") ? new ItemBuilder(section.getConfigurationSection("equipment.boots")) : null;
|
||||||
handItem = section.isConfigurationSection("equipment.hand-item") ? new ItemBuilder(section.getConfigurationSection("equipment.hand-item")) : null;
|
this.handItem = section.isConfigurationSection("equipment.hand-item") ? new ItemBuilder(section.getConfigurationSection("equipment.hand-item")) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) {
|
public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) {
|
||||||
Location location = user.getLocation();
|
Location location = user.getLocation();
|
||||||
|
|
||||||
for (int i = 0; i < amount.get(level, 1, user, opponent); i++) {
|
for (int i = 0; i < this.amount.get(level, 1, user, opponent); i++) {
|
||||||
Location spawnLocation = location.clone().add(current().nextInt(-3, 3), 0, current().nextInt(-3, 3));
|
Location spawnLocation = location.clone().add(current().nextInt(-3, 3), 0, current().nextInt(-3, 3));
|
||||||
int y = location.getWorld().getHighestBlockAt(spawnLocation).getY();
|
int y = location.getWorld().getHighestBlockAt(spawnLocation).getY();
|
||||||
|
|
||||||
|
@ -57,34 +61,40 @@ public class SpawnMob extends EffectExecutor {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity entity = location.getWorld().spawnEntity(spawnLocation, entityType);
|
Entity entity = location.getWorld().spawnEntity(spawnLocation, this.entityType);
|
||||||
|
|
||||||
entity.setCustomName(displayName.replace("{level}", "" + level));
|
entity.setCustomName(this.displayName.replace("{level}", "" + level));
|
||||||
entity.setCustomNameVisible(true);
|
entity.setCustomNameVisible(true);
|
||||||
|
|
||||||
if (entity instanceof LivingEntity) {
|
if (entity instanceof LivingEntity) {
|
||||||
LivingEntity livingEntity = (LivingEntity) entity;
|
LivingEntity livingEntity = (LivingEntity) entity;
|
||||||
livingEntity.setRemoveWhenFarAway(true);
|
livingEntity.setRemoveWhenFarAway(true);
|
||||||
int dropChance = (int) equipmentDropChance.get(level, 0, user, opponent);
|
int dropChance = (int) this.equipmentDropChance.get(level, 0, user, opponent);
|
||||||
|
|
||||||
if (helmet != null)
|
if (this.helmet != null) {
|
||||||
livingEntity.getEquipment().setHelmet(helmet.buildWithWrappers(level, user, opponent));
|
livingEntity.getEquipment().setHelmet(this.helmet.buildWithWrappers(level, user, opponent));
|
||||||
if (chestPlate != null)
|
}
|
||||||
livingEntity.getEquipment().setChestplate(chestPlate.buildWithWrappers(level, user, opponent));
|
if (this.chestPlate != null) {
|
||||||
if (leggings != null)
|
livingEntity.getEquipment().setChestplate(this.chestPlate.buildWithWrappers(level, user, opponent));
|
||||||
livingEntity.getEquipment().setLeggings(leggings.buildWithWrappers(level, user, opponent));
|
}
|
||||||
if (boots != null) livingEntity.getEquipment().setBoots(boots.buildWithWrappers(level, user, opponent));
|
if (this.leggings != null) {
|
||||||
|
livingEntity.getEquipment().setLeggings(this.leggings.buildWithWrappers(level, user, opponent));
|
||||||
|
}
|
||||||
|
if (this.boots != null) {
|
||||||
|
livingEntity.getEquipment().setBoots(this.boots.buildWithWrappers(level, user, opponent));
|
||||||
|
}
|
||||||
livingEntity.getEquipment().setHelmetDropChance(dropChance);
|
livingEntity.getEquipment().setHelmetDropChance(dropChance);
|
||||||
livingEntity.getEquipment().setLeggingsDropChance(dropChance);
|
livingEntity.getEquipment().setLeggingsDropChance(dropChance);
|
||||||
livingEntity.getEquipment().setHelmetDropChance(dropChance);
|
livingEntity.getEquipment().setHelmetDropChance(dropChance);
|
||||||
livingEntity.getEquipment().setChestplateDropChance(dropChance);
|
livingEntity.getEquipment().setChestplateDropChance(dropChance);
|
||||||
|
|
||||||
if (handItem != null)
|
if (this.handItem != null) {
|
||||||
livingEntity.getEquipment().setItemInHand(handItem.buildWithWrappers(level, user, opponent));
|
livingEntity.getEquipment().setItemInHand(this.handItem.buildWithWrappers(level, user, opponent));
|
||||||
|
}
|
||||||
livingEntity.getEquipment().setItemInHandDropChance(dropChance);
|
livingEntity.getEquipment().setItemInHandDropChance(dropChance);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostile && entity instanceof Monster && opponent != null) {
|
if (this.hostile && entity instanceof Monster && opponent != null) {
|
||||||
((Monster) entity).setTarget(opponent);
|
((Monster) entity).setTarget(opponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +105,7 @@ public class SpawnMob extends EffectExecutor {
|
||||||
// attack.setBaseValue(attackDamage.get(level, (int) Math.round(attack.getBaseValue()), user, opponent));
|
// attack.setBaseValue(attackDamage.get(level, (int) Math.round(attack.getBaseValue()), user, opponent));
|
||||||
|
|
||||||
double maxHealth = livingEntity.getMaxHealth();
|
double maxHealth = livingEntity.getMaxHealth();
|
||||||
livingEntity.setMaxHealth(health.get(level, (int) Math.round(maxHealth), user, opponent));
|
livingEntity.setMaxHealth(this.health.get(level, (int) Math.round(maxHealth), user, opponent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,14 @@ public class StealFood extends EffectExecutor {
|
||||||
|
|
||||||
if (opponentFood <= 0) {
|
if (opponentFood <= 0) {
|
||||||
opponentPlayer.setFoodLevel(0);
|
opponentPlayer.setFoodLevel(0);
|
||||||
} else opponentPlayer.setFoodLevel(Math.min(opponentFood, 20));
|
} else {
|
||||||
|
opponentPlayer.setFoodLevel(Math.min(opponentFood, 20));
|
||||||
|
}
|
||||||
|
|
||||||
if (userFood <= 0) {
|
if (userFood <= 0) {
|
||||||
user.setFoodLevel(0);
|
user.setFoodLevel(0);
|
||||||
} else user.setFoodLevel(Math.min(userFood, 20));
|
} else {
|
||||||
|
user.setFoodLevel(Math.min(userFood, 20));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@ import org.bukkit.event.player.PlayerEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
|
public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private boolean cancel = false;
|
private boolean cancel = false;
|
||||||
private final EquipMethod equipType;
|
private final EquipMethod equipType;
|
||||||
private final ArmorType type;
|
private final ArmorType type;
|
||||||
|
@ -18,36 +18,27 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
|
||||||
/**
|
/**
|
||||||
* Constructor for the ArmorEquipEvent.
|
* Constructor for the ArmorEquipEvent.
|
||||||
*
|
*
|
||||||
* @param player The player who put on / removed the armor.
|
* @param who The player who put on / removed the armor.
|
||||||
* @param type The ArmorType of the armor added
|
* @param type The ArmorType of the armor added
|
||||||
* @param oldArmorPiece The ItemStack of the armor removed.
|
* @param oldArmorPiece The ItemStack of the armor removed.
|
||||||
* @param newArmorPiece The ItemStack of the armor added.
|
* @param newArmorPiece The ItemStack of the armor added.
|
||||||
*/
|
*/
|
||||||
public ArmorEquipEvent(final Player player, final EquipMethod equipType, final ArmorType type, final ItemStack oldArmorPiece, final ItemStack newArmorPiece) {
|
public ArmorEquipEvent(final Player who, final EquipMethod equipType, final ArmorType type, final ItemStack oldArmorPiece, final ItemStack newArmorPiece) {
|
||||||
super(player);
|
super(who);
|
||||||
this.equipType = equipType;
|
this.equipType = equipType;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.oldArmorPiece = oldArmorPiece;
|
this.oldArmorPiece = oldArmorPiece;
|
||||||
this.newArmorPiece = newArmorPiece;
|
this.newArmorPiece = newArmorPiece;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a list of handlers handling this event.
|
|
||||||
*
|
|
||||||
* @return A list of handlers handling this event.
|
|
||||||
*/
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a list of handlers handling this event.
|
* Gets a list of handlers handling this event.
|
||||||
*
|
*
|
||||||
* @return A list of handlers handling this event.
|
* @return A list of handlers handling this event.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +46,7 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
|
||||||
*
|
*
|
||||||
* @param cancel If this event should be cancelled.
|
* @param cancel If this event should be cancelled.
|
||||||
*/
|
*/
|
||||||
public final void setCancelled(final boolean cancel) {
|
public void setCancelled(final boolean cancel) {
|
||||||
this.cancel = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,33 +55,33 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
|
||||||
*
|
*
|
||||||
* @return If this event is cancelled
|
* @return If this event is cancelled
|
||||||
*/
|
*/
|
||||||
public final boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancel;
|
return this.cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final ArmorType getType() {
|
public ArmorType getType() {
|
||||||
return type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the last equipped armor piece, could be a piece of armor, {@link Material#AIR}, or null.
|
* Returns the last equipped armor piece, could be a piece of armor, {@link Material#AIR}, or null.
|
||||||
*/
|
*/
|
||||||
public final ItemStack getOldArmorPiece() {
|
public ItemStack getOldArmorPiece() {
|
||||||
return oldArmorPiece;
|
return this.oldArmorPiece;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setOldArmorPiece(final ItemStack oldArmorPiece) {
|
public void setOldArmorPiece(final ItemStack oldArmorPiece) {
|
||||||
this.oldArmorPiece = oldArmorPiece;
|
this.oldArmorPiece = oldArmorPiece;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the newly equipped armor, could be a piece of armor, {@link Material#AIR}, or null.
|
* Returns the newly equipped armor, could be a piece of armor, {@link Material#AIR}, or null.
|
||||||
*/
|
*/
|
||||||
public final ItemStack getNewArmorPiece() {
|
public ItemStack getNewArmorPiece() {
|
||||||
return newArmorPiece;
|
return this.newArmorPiece;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setNewArmorPiece(final ItemStack newArmorPiece) {
|
public void setNewArmorPiece(final ItemStack newArmorPiece) {
|
||||||
this.newArmorPiece = newArmorPiece;
|
this.newArmorPiece = newArmorPiece;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,12 +89,21 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
|
||||||
* Gets the method used to either equip or unequip an armor piece.
|
* Gets the method used to either equip or unequip an armor piece.
|
||||||
*/
|
*/
|
||||||
public EquipMethod getMethod() {
|
public EquipMethod getMethod() {
|
||||||
return equipType;
|
return this.equipType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of handlers handling this event.
|
||||||
|
*
|
||||||
|
* @return A list of handlers handling this event.
|
||||||
|
*/
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum EquipMethod {// These have got to be the worst documentations ever.
|
public enum EquipMethod {// These have got to be the worst documentations ever.
|
||||||
/**
|
/**
|
||||||
* When you shift click an armor piece to equip or unequip
|
* When you shift-click an armor piece to equip or unequip
|
||||||
*/
|
*/
|
||||||
SHIFT_CLICK,
|
SHIFT_CLICK,
|
||||||
/**
|
/**
|
||||||
|
@ -115,7 +115,7 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
|
||||||
*/
|
*/
|
||||||
PICK_DROP,
|
PICK_DROP,
|
||||||
/**
|
/**
|
||||||
* When you right click an armor piece in the hotbar without the inventory open to equip.
|
* When you right-click an armor piece in the hotbar without the inventory open to equip.
|
||||||
*/
|
*/
|
||||||
HOTBAR,
|
HOTBAR,
|
||||||
/**
|
/**
|
||||||
|
@ -123,18 +123,17 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
|
||||||
*/
|
*/
|
||||||
HOTBAR_SWAP,
|
HOTBAR_SWAP,
|
||||||
/**
|
/**
|
||||||
* When in range of a dispenser that shoots an armor piece to equip.
|
* When in range of a dispenser that shoots an armor piece to equip
|
||||||
*/
|
*/
|
||||||
DISPENSER,
|
DISPENSER,
|
||||||
/**
|
/**
|
||||||
* When an armor piece is removed due to it losing all durability.
|
* When an armor piece is removed due to it losing all durability
|
||||||
*/
|
*/
|
||||||
BROKE,
|
BROKE,
|
||||||
/**
|
/**
|
||||||
* When you die causing all armor to unequip
|
* When you die causing all armor to unequip
|
||||||
*/
|
*/
|
||||||
DEATH,
|
DEATH,
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ArmorType {
|
public enum ArmorType {
|
||||||
|
@ -154,17 +153,26 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
|
||||||
* @return The parsed ArmorType. (null if none were found.)
|
* @return The parsed ArmorType. (null if none were found.)
|
||||||
*/
|
*/
|
||||||
public static ArmorType matchType(final ItemStack itemStack) {
|
public static ArmorType matchType(final ItemStack itemStack) {
|
||||||
if (itemStack == null || itemStack.getType().equals(Material.AIR)) return null;
|
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
String type = itemStack.getType().name();
|
String type = itemStack.getType().name();
|
||||||
if (type.endsWith("_HELMET") || type.endsWith("_SKULL")) return HELMET;
|
if (type.endsWith("_HELMET") || type.endsWith("_SKULL")) {
|
||||||
else if (type.endsWith("_CHESTPLATE") || type.equals("ELYTRA")) return CHESTPLATE;
|
return HELMET;
|
||||||
else if (type.endsWith("_LEGGINGS")) return LEGGINGS;
|
} else if (type.endsWith("_CHESTPLATE") || type.equals("ELYTRA")) {
|
||||||
else if (type.endsWith("_BOOTS")) return BOOTS;
|
return CHESTPLATE;
|
||||||
else return null;
|
} else if (type.endsWith("_LEGGINGS")) {
|
||||||
|
return LEGGINGS;
|
||||||
|
} else if (type.endsWith("_BOOTS")) {
|
||||||
|
return BOOTS;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSlot() {
|
public int getSlot() {
|
||||||
return slot;
|
return this.slot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,8 @@ import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class EnchantApplyEvent extends Event implements Cancellable {
|
public class EnchantApplyEvent extends Event implements Cancellable {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
private final ItemStack toEnchant;
|
private final ItemStack toEnchant;
|
||||||
private final Enchant enchant;
|
private final Enchant enchant;
|
||||||
private final int level;
|
private final int level;
|
||||||
|
@ -23,23 +24,19 @@ public class EnchantApplyEvent extends Event implements Cancellable {
|
||||||
this.destroyRate = destroyRate;
|
this.destroyRate = destroyRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancelled) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getToEnchant() {
|
public ItemStack getToEnchant() {
|
||||||
|
@ -61,4 +58,8 @@ public class EnchantApplyEvent extends Event implements Cancellable {
|
||||||
public int getDestroyRate() {
|
public int getDestroyRate() {
|
||||||
return this.destroyRate;
|
return this.destroyRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@ import org.bukkit.event.player.PlayerEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public final class HeldItemChangedEvent extends PlayerEvent implements Cancellable {
|
public final class HeldItemChangedEvent extends PlayerEvent implements Cancellable {
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private boolean cancel = false;
|
private boolean cancel = false;
|
||||||
private final EquipMethod equipType;
|
private final EquipMethod equipType;
|
||||||
private final ItemStack oldItem, newItem;
|
private final ItemStack oldItem, newItem;
|
||||||
|
@ -17,47 +17,38 @@ public final class HeldItemChangedEvent extends PlayerEvent implements Cancellab
|
||||||
/**
|
/**
|
||||||
* Constructor for the HeldItemChangedEvent.
|
* Constructor for the HeldItemChangedEvent.
|
||||||
*
|
*
|
||||||
* @param player The player who put (un)equipped an item.
|
* @param who The player who put (un)equipped an item.
|
||||||
* @param oldItem The ItemStack removed.
|
* @param oldItem The ItemStack removed.
|
||||||
* @param newItem The ItemStack added.
|
* @param newItem The ItemStack added.
|
||||||
*/
|
*/
|
||||||
public HeldItemChangedEvent(final Player player, final EquipMethod equipType, final ItemStack oldItem, final ItemStack newItem) {
|
public HeldItemChangedEvent(final Player who, final EquipMethod equipType, final ItemStack oldItem, final ItemStack newItem) {
|
||||||
super(player);
|
super(who);
|
||||||
this.equipType = equipType;
|
this.equipType = equipType;
|
||||||
this.oldItem = oldItem;
|
this.oldItem = oldItem;
|
||||||
this.newItem = newItem;
|
this.newItem = newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a list of handlers handling this event.
|
* Gets a list of handlers handling this event
|
||||||
*
|
*
|
||||||
* @return A list of handlers handling this event.
|
* @return A list of handlers handling this event
|
||||||
*/
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a list of handlers handling this event.
|
|
||||||
*
|
|
||||||
* @return A list of handlers handling this event.
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final HandlerList getHandlers() {
|
public final HandlerList getHandlers() {
|
||||||
return handlers;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets if this event should be cancelled.
|
* Sets if this event should be cancelled
|
||||||
*
|
*
|
||||||
* @param cancel If this event should be cancelled.
|
* @param cancel If this event should be cancelled
|
||||||
*/
|
*/
|
||||||
public final void setCancelled(final boolean cancel) {
|
public final void setCancelled(final boolean cancel) {
|
||||||
this.cancel = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets if this event is cancelled.
|
* Gets if this event is cancelled
|
||||||
*
|
*
|
||||||
* @return If this event is cancelled
|
* @return If this event is cancelled
|
||||||
*/
|
*/
|
||||||
|
@ -86,9 +77,18 @@ public final class HeldItemChangedEvent extends PlayerEvent implements Cancellab
|
||||||
return equipType;
|
return equipType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of handlers handling this event.
|
||||||
|
*
|
||||||
|
* @return A list of handlers handling this event.
|
||||||
|
*/
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
public enum EquipMethod {// These have got to be the worst documentations ever.
|
public enum EquipMethod {// These have got to be the worst documentations ever.
|
||||||
/**
|
/**
|
||||||
* When you shift click an armor piece to equip or unequip
|
* When you shift-click an armor piece to equip or unequip
|
||||||
*/
|
*/
|
||||||
SHIFT_CLICK,
|
SHIFT_CLICK,
|
||||||
/**
|
/**
|
||||||
|
@ -108,7 +108,7 @@ public final class HeldItemChangedEvent extends PlayerEvent implements Cancellab
|
||||||
*/
|
*/
|
||||||
OFFHAND_SWAP,
|
OFFHAND_SWAP,
|
||||||
/**
|
/**
|
||||||
* When an item, e.g. tool, is removed due to it losing all durability.
|
* When an item, e.g., tool, is removed due to it losing all durability
|
||||||
*/
|
*/
|
||||||
BROKE,
|
BROKE,
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,7 +24,6 @@ import org.bukkit.inventory.ItemStack;
|
||||||
import static org.bukkit.event.EventPriority.HIGHEST;
|
import static org.bukkit.event.EventPriority.HIGHEST;
|
||||||
|
|
||||||
public class ArmorListener implements Listener {
|
public class ArmorListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public final void onInventoryClick(final InventoryClickEvent e) {
|
public final void onInventoryClick(final InventoryClickEvent e) {
|
||||||
boolean shift = false, numberKey = false;
|
boolean shift = false, numberKey = false;
|
||||||
|
@ -194,9 +193,9 @@ public class ArmorListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void playerDeathEvent(PlayerDeathEvent event) {
|
public void playerDeathEvent(PlayerDeathEvent event) {
|
||||||
for (ItemStack i : event.getEntity().getInventory().getArmorContents()) {
|
for (ItemStack item : event.getEntity().getInventory().getArmorContents()) {
|
||||||
if (!isAirOrNull(i)) {
|
if (!isAirOrNull(item)) {
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new ArmorEquipEvent(event.getEntity(), EquipMethod.DEATH, ArmorType.matchType(i), i, null));
|
Bukkit.getServer().getPluginManager().callEvent(new ArmorEquipEvent(event.getEntity(), EquipMethod.DEATH, ArmorType.matchType(item), item, null));
|
||||||
// No way to cancel a death event.
|
// No way to cancel a death event.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.songoda.epicenchants.listeners;
|
package com.songoda.epicenchants.listeners;
|
||||||
|
|
||||||
import com.craftaro.core.nms.NmsManager;
|
import com.craftaro.core.nms.Nms;
|
||||||
import com.songoda.epicenchants.EpicEnchants;
|
import com.songoda.epicenchants.EpicEnchants;
|
||||||
import com.songoda.epicenchants.enums.TriggerType;
|
import com.songoda.epicenchants.enums.TriggerType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
@ -17,20 +17,7 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
|
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
|
||||||
import org.bukkit.projectiles.ProjectileSource;
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
|
|
||||||
import static com.songoda.epicenchants.enums.TriggerType.ATTACK_MOB_MELEE;
|
import static com.songoda.epicenchants.enums.TriggerType.*;
|
||||||
import static com.songoda.epicenchants.enums.TriggerType.ATTACK_MOB_RANGE;
|
|
||||||
import static com.songoda.epicenchants.enums.TriggerType.ATTACK_PLAYER_MELEE;
|
|
||||||
import static com.songoda.epicenchants.enums.TriggerType.ATTACK_PLAYER_RANGE;
|
|
||||||
import static com.songoda.epicenchants.enums.TriggerType.DEFENSE_MOB_MELEE;
|
|
||||||
import static com.songoda.epicenchants.enums.TriggerType.DEFENSE_MOB_RANGE;
|
|
||||||
import static com.songoda.epicenchants.enums.TriggerType.DEFENSE_PLAYER_MELEE;
|
|
||||||
import static com.songoda.epicenchants.enums.TriggerType.DEFENSE_PLAYER_RANGE;
|
|
||||||
import static com.songoda.epicenchants.enums.TriggerType.EXPLOSION_DAMAGE;
|
|
||||||
import static com.songoda.epicenchants.enums.TriggerType.FALL_DAMAGE;
|
|
||||||
import static com.songoda.epicenchants.enums.TriggerType.FIRE_DAMAGE;
|
|
||||||
import static com.songoda.epicenchants.enums.TriggerType.KILLED_MOB;
|
|
||||||
import static com.songoda.epicenchants.enums.TriggerType.LAVA_DAMAGE;
|
|
||||||
import static com.songoda.epicenchants.enums.TriggerType.POISON_DAMAGE;
|
|
||||||
|
|
||||||
public class EntityListener implements Listener {
|
public class EntityListener implements Listener {
|
||||||
private final EpicEnchants instance;
|
private final EpicEnchants instance;
|
||||||
|
@ -42,7 +29,7 @@ public class EntityListener implements Listener {
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
public void onEntityDeath(EntityDeathEvent event) {
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
if (event.getEntity() instanceof Monster && event.getEntity().getKiller() != null) {
|
if (event.getEntity() instanceof Monster && event.getEntity().getKiller() != null) {
|
||||||
instance.getEnchantUtils().handlePlayer(event.getEntity().getKiller(), event.getEntity(), event, KILLED_MOB);
|
this.instance.getEnchantUtils().handlePlayer(event.getEntity().getKiller(), event.getEntity(), event, KILLED_MOB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,12 +48,12 @@ public class EntityListener implements Listener {
|
||||||
if (hitEntity instanceof Player) {
|
if (hitEntity instanceof Player) {
|
||||||
LivingEntity opponent = source instanceof LivingEntity ? ((LivingEntity) source) : null;
|
LivingEntity opponent = source instanceof LivingEntity ? ((LivingEntity) source) : null;
|
||||||
TriggerType type = source instanceof Player ? DEFENSE_PLAYER_RANGE : DEFENSE_MOB_RANGE;
|
TriggerType type = source instanceof Player ? DEFENSE_PLAYER_RANGE : DEFENSE_MOB_RANGE;
|
||||||
instance.getEnchantUtils().handlePlayer(((Player) hitEntity), opponent, event, type);
|
this.instance.getEnchantUtils().handlePlayer(((Player) hitEntity), opponent, event, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source instanceof Player) {
|
if (source instanceof Player) {
|
||||||
TriggerType type = event.getEntity() instanceof Player ? ATTACK_PLAYER_RANGE : ATTACK_MOB_RANGE;
|
TriggerType type = event.getEntity() instanceof Player ? ATTACK_PLAYER_RANGE : ATTACK_MOB_RANGE;
|
||||||
instance.getEnchantUtils().handlePlayer(((Player) source), hitEntity, event, type);
|
this.instance.getEnchantUtils().handlePlayer(((Player) source), hitEntity, event, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +72,7 @@ public class EntityListener implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (triggerType != null) {
|
if (triggerType != null) {
|
||||||
instance.getEnchantUtils().handlePlayer(defender, opponent, event, triggerType);
|
this.instance.getEnchantUtils().handlePlayer(defender, opponent, event, triggerType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +88,7 @@ public class EntityListener implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (triggerType != null) {
|
if (triggerType != null) {
|
||||||
instance.getEnchantUtils().handlePlayer(attacker, ((LivingEntity) event.getEntity()), event, triggerType);
|
this.instance.getEnchantUtils().handlePlayer(attacker, ((LivingEntity) event.getEntity()), event, triggerType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,31 +100,32 @@ public class EntityListener implements Listener {
|
||||||
}
|
}
|
||||||
switch (event.getCause()) {
|
switch (event.getCause()) {
|
||||||
case FALL:
|
case FALL:
|
||||||
instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, FALL_DAMAGE);
|
this.instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, FALL_DAMAGE);
|
||||||
break;
|
break;
|
||||||
case FIRE:
|
case FIRE:
|
||||||
case FIRE_TICK:
|
case FIRE_TICK:
|
||||||
instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, FIRE_DAMAGE);
|
this.instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, FIRE_DAMAGE);
|
||||||
break;
|
break;
|
||||||
case LAVA:
|
case LAVA:
|
||||||
instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, LAVA_DAMAGE);
|
this.instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, LAVA_DAMAGE);
|
||||||
break;
|
break;
|
||||||
case BLOCK_EXPLOSION:
|
case BLOCK_EXPLOSION:
|
||||||
case ENTITY_EXPLOSION:
|
case ENTITY_EXPLOSION:
|
||||||
instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, EXPLOSION_DAMAGE);
|
this.instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, EXPLOSION_DAMAGE);
|
||||||
break;
|
break;
|
||||||
case POISON:
|
case POISON:
|
||||||
instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, POISON_DAMAGE);
|
this.instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, POISON_DAMAGE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
public void onEntityTargetLivingEntity(EntityTargetLivingEntityEvent event) {
|
public void onEntityTargetLivingEntity(EntityTargetLivingEntityEvent event) {
|
||||||
if (event.getTarget() == null)
|
if (event.getTarget() == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (NmsManager.getNbt().of(event.getEntity()).has(event.getTarget().getUniqueId().toString())) {
|
if (Nms.getImplementations().getNbt().of(event.getEntity()).has(event.getTarget().getUniqueId().toString())) {
|
||||||
//TODO: Add team support.
|
//TODO: Add team support.
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ import java.util.OptionalInt;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class HeldItemListener implements Listener {
|
public class HeldItemListener implements Listener {
|
||||||
|
|
||||||
private static final boolean SWAP_OFFHAND_SUPPORTED = Arrays.stream(ClickType.values()).anyMatch(e -> e.name().equals("SWAP_OFFHAND"));
|
private static final boolean SWAP_OFFHAND_SUPPORTED = Arrays.stream(ClickType.values()).anyMatch(e -> e.name().equals("SWAP_OFFHAND"));
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
|
@ -190,8 +189,9 @@ public class HeldItemListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void playerDeathEvent(PlayerDeathEvent event) {
|
public void playerDeathEvent(PlayerDeathEvent event) {
|
||||||
ItemStack i = event.getEntity().getInventory().getItem(event.getEntity().getInventory().getHeldItemSlot());
|
ItemStack i = event.getEntity().getInventory().getItem(event.getEntity().getInventory().getHeldItemSlot());
|
||||||
if (!isAirOrNull(i))
|
if (!isAirOrNull(i)) {
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new HeldItemChangedEvent(event.getEntity(), EquipMethod.DEATH, i, null));
|
Bukkit.getServer().getPluginManager().callEvent(new HeldItemChangedEvent(event.getEntity(), EquipMethod.DEATH, i, null));
|
||||||
|
}
|
||||||
// No way to cancel a death event.
|
// No way to cancel a death event.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,8 @@ public class PlayerListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
public void onArmorEquip(ArmorEquipEvent event) {
|
public void onArmorEquip(ArmorEquipEvent event) {
|
||||||
Map<Enchant, Integer> oldArmorMap = instance.getEnchantUtils().getEnchants(event.getOldArmorPiece());
|
Map<Enchant, Integer> oldArmorMap = this.instance.getEnchantUtils().getEnchants(event.getOldArmorPiece());
|
||||||
Map<Enchant, Integer> newArmorMap = instance.getEnchantUtils().getEnchants(event.getNewArmorPiece());
|
Map<Enchant, Integer> newArmorMap = this.instance.getEnchantUtils().getEnchants(event.getNewArmorPiece());
|
||||||
|
|
||||||
oldArmorMap.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, STATIC_EFFECT, OFF));
|
oldArmorMap.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, STATIC_EFFECT, OFF));
|
||||||
newArmorMap.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, STATIC_EFFECT, ON));
|
newArmorMap.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, STATIC_EFFECT, ON));
|
||||||
|
@ -41,8 +41,8 @@ public class PlayerListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
public void onHeldItemChanged(HeldItemChangedEvent event) {
|
public void onHeldItemChanged(HeldItemChangedEvent event) {
|
||||||
Map<Enchant, Integer> oldItemMap = instance.getEnchantUtils().getEnchants(event.getOldItem());
|
Map<Enchant, Integer> oldItemMap = this.instance.getEnchantUtils().getEnchants(event.getOldItem());
|
||||||
Map<Enchant, Integer> newItemMap = instance.getEnchantUtils().getEnchants(event.getNewItem());
|
Map<Enchant, Integer> newItemMap = this.instance.getEnchantUtils().getEnchants(event.getNewItem());
|
||||||
|
|
||||||
oldItemMap.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, OFF));
|
oldItemMap.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, OFF));
|
||||||
newItemMap.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, ON));
|
newItemMap.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, ON));
|
||||||
|
@ -50,56 +50,64 @@ public class PlayerListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||||
instance.getEnchantUtils().getEnchants(event.getPlayer().getInventory().getItem(event.getPreviousSlot()))
|
this.instance.getEnchantUtils().getEnchants(event.getPlayer().getInventory().getItem(event.getPreviousSlot()))
|
||||||
.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, OFF));
|
.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, OFF));
|
||||||
|
|
||||||
instance.getEnchantUtils().getEnchants(event.getPlayer().getInventory().getItem(event.getNewSlot()))
|
this.instance.getEnchantUtils().getEnchants(event.getPlayer().getInventory().getItem(event.getNewSlot()))
|
||||||
.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, ON));
|
.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, ON));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||||
instance.getEnchantUtils().handlePlayer(event.getEntity(), event.getEntity().getKiller(), event, DEATH);
|
this.instance.getEnchantUtils().handlePlayer(event.getEntity(), event.getEntity().getKiller(), event, DEATH);
|
||||||
|
|
||||||
if (event.getEntity().getKiller() != null) {
|
if (event.getEntity().getKiller() != null) {
|
||||||
instance.getEnchantUtils().handlePlayer(event.getEntity().getKiller(), event.getEntity(), event, KILLED_PLAYER);
|
this.instance.getEnchantUtils().handlePlayer(event.getEntity().getKiller(), event.getEntity(), event, KILLED_PLAYER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_AIR) {
|
if (event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||||
instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, RIGHT_CLICK);
|
this.instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, RIGHT_CLICK);
|
||||||
} else if (event.getAction() == Action.LEFT_CLICK_AIR) {
|
} else if (event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||||
instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, LEFT_CLICK);
|
this.instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, LEFT_CLICK);
|
||||||
}
|
}
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, RIGHT_CLICK_BLOCK);
|
this.instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, RIGHT_CLICK_BLOCK);
|
||||||
} else if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
} else if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||||
instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, LEFT_CLICK_BLOCK);
|
this.instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, LEFT_CLICK_BLOCK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, BLOCK_BREAK);
|
this.instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, BLOCK_BREAK);
|
||||||
if (event.getExpToDrop() != 0)
|
if (event.getExpToDrop() != 0) {
|
||||||
instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, EXPERIENCE_BLOCK_BREAK);
|
this.instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, EXPERIENCE_BLOCK_BREAK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
event.getPlayer().getActivePotionEffects().stream().filter(potion -> potion.getDuration() >= 32760)
|
event.getPlayer()
|
||||||
|
.getActivePotionEffects()
|
||||||
|
.stream()
|
||||||
|
.filter(potion -> potion.getDuration() >= 32760)
|
||||||
.forEach(potionEffect -> event.getPlayer().removePotionEffect(potionEffect.getType()));
|
.forEach(potionEffect -> event.getPlayer().removePotionEffect(potionEffect.getType()));
|
||||||
|
|
||||||
Arrays.stream(event.getPlayer().getInventory().getArmorContents()).forEach(itemStack -> {
|
Arrays.stream(event.getPlayer().getInventory().getArmorContents())
|
||||||
instance.getEnchantUtils().getEnchants(itemStack).forEach((enchant, level)
|
.forEach(itemStack -> this.instance
|
||||||
-> enchant.onAction(event.getPlayer(), null, event, level, STATIC_EFFECT, ON));
|
.getEnchantUtils()
|
||||||
});
|
.getEnchants(itemStack)
|
||||||
ItemStack mainhand = event.getPlayer().getInventory().getItem(event.getPlayer().getInventory().getHeldItemSlot());
|
.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, STATIC_EFFECT, ON)));
|
||||||
if (isItem(mainhand))
|
ItemStack mainHand = event.getPlayer().getInventory().getItem(event.getPlayer().getInventory().getHeldItemSlot());
|
||||||
instance.getEnchantUtils().getEnchants(mainhand).forEach((enchant, level)
|
if (isItem(mainHand)) {
|
||||||
-> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, ON));
|
this.instance
|
||||||
|
.getEnchantUtils()
|
||||||
|
.getEnchants(mainHand)
|
||||||
|
.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, ON));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isItem(ItemStack is) {
|
private boolean isItem(ItemStack is) {
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class BlackScrollListener extends ItemListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
|
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
|
||||||
if (!cursor.hasKey("black-scroll") || !cursor.getBoolean("black-scroll")) {
|
if (!cursor.hasTag("black-scroll") || !cursor.getBoolean("black-scroll")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,20 +25,20 @@ public class BlackScrollListener extends ItemListener {
|
||||||
NBTCompound compound = current.getCompound("enchants");
|
NBTCompound compound = current.getCompound("enchants");
|
||||||
|
|
||||||
if (compound == null || compound.getKeys().isEmpty()) {
|
if (compound == null || compound.getKeys().isEmpty()) {
|
||||||
instance.getLocale().getMessage("blackscroll.noenchants")
|
this.instance.getLocale().getMessage("blackscroll.noenchants")
|
||||||
.sendPrefixedMessage(event.getWhoClicked());
|
.sendPrefixedMessage(event.getWhoClicked());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String id = getRandomElement(compound.getKeys());
|
String id = getRandomElement(compound.getKeys());
|
||||||
int level = compound.getInteger(id);
|
int level = compound.getInteger(id);
|
||||||
Enchant enchant = instance.getEnchantManager().getValueUnsafe(id);
|
Enchant enchant = this.instance.getEnchantManager().getValueUnsafe(id);
|
||||||
ItemStack toSet = instance.getEnchantUtils().removeEnchant(event.getCurrentItem(), enchant);
|
ItemStack toSet = this.instance.getEnchantUtils().removeEnchant(event.getCurrentItem(), enchant);
|
||||||
|
|
||||||
event.getWhoClicked().getInventory().addItem(enchant.getBook().get(enchant, level, cursor.getInteger("success-rate"), 100));
|
event.getWhoClicked().getInventory().addItem(enchant.getBook().get(enchant, level, cursor.getInteger("success-rate"), 100));
|
||||||
event.setCurrentItem(toSet);
|
event.setCurrentItem(toSet);
|
||||||
|
|
||||||
instance.getLocale().getMessage("blackscroll.success")
|
this.instance.getLocale().getMessage("blackscroll.success")
|
||||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||||
.processPlaceholder("group_color", enchant.getGroup().getColor())
|
.processPlaceholder("group_color", enchant.getGroup().getColor())
|
||||||
.processPlaceholder("group_name", enchant.getGroup().getName())
|
.processPlaceholder("group_name", enchant.getGroup().getName())
|
||||||
|
|
|
@ -30,26 +30,26 @@ public class BookListener extends ItemListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
|
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
|
||||||
if (!cursor.hasKey("book-item") || !cursor.getBoolean("book-item")) {
|
if (!cursor.hasTag("book-item") || !cursor.getBoolean("book-item")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
ItemStack toApply = event.getCurrentItem();
|
ItemStack toApply = event.getCurrentItem();
|
||||||
Enchant enchant = instance.getEnchantManager().getValue(cursor.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
|
Enchant enchant = this.instance.getEnchantManager().getValue(cursor.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
|
||||||
|
|
||||||
if (!enchant.getItemWhitelist().contains(CompatibleMaterial.getMaterial(current.getItem().getType()).get())) {
|
if (!enchant.getItemWhitelist().contains(CompatibleMaterial.getMaterial(current.getItem().getType()).get())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// get total amount of enchantments on item
|
// get total amount of enchantments on item
|
||||||
int currentEnchantmentTotal = instance.getEnchantUtils().getEnchants(toApply).size();
|
int currentEnchantmentTotal = this.instance.getEnchantUtils().getEnchants(toApply).size();
|
||||||
int maxAllowedOverride = instance.getEnchantUtils().getMaximumEnchantsCanApply((Player) event.getWhoClicked());
|
int maxAllowedOverride = this.instance.getEnchantUtils().getMaximumEnchantsCanApply((Player) event.getWhoClicked());
|
||||||
int maxAllowedApply = instance.getEnchantUtils().getMaximumEnchantsCanApplyItem(toApply, (Player) event.getWhoClicked());
|
int maxAllowedApply = this.instance.getEnchantUtils().getMaximumEnchantsCanApplyItem(toApply, (Player) event.getWhoClicked());
|
||||||
maxAllowedApply = Math.min(maxAllowedApply, maxAllowedOverride);
|
maxAllowedApply = Math.min(maxAllowedApply, maxAllowedOverride);
|
||||||
// item is at max enchantments
|
// item is at max enchantments
|
||||||
if (currentEnchantmentTotal >= maxAllowedApply) {
|
if (currentEnchantmentTotal >= maxAllowedApply) {
|
||||||
instance.getLocale().getMessage("enchants.maxallowed").processPlaceholder("max_enchants", maxAllowedApply).sendPrefixedMessage(event.getWhoClicked());
|
this.instance.getLocale().getMessage("enchants.maxallowed").processPlaceholder("max_enchants", maxAllowedApply).sendPrefixedMessage(event.getWhoClicked());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,9 +64,9 @@ public class BookListener extends ItemListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tuple<ItemStack, EnchantResult> result = instance.getEnchantUtils().apply(toApply, enchant, enchantEvent.getLevel(), enchantEvent.getSuccessRate(), enchantEvent.getDestroyRate());
|
Tuple<ItemStack, EnchantResult> result = this.instance.getEnchantUtils().apply(toApply, enchant, enchantEvent.getLevel(), enchantEvent.getSuccessRate(), enchantEvent.getDestroyRate());
|
||||||
|
|
||||||
instance.getLocale().getMessage(GeneralUtils.getMessageFromResult(result.getRight()))
|
this.instance.getLocale().getMessage(GeneralUtils.getMessageFromResult(result.getRight()))
|
||||||
.processPlaceholder("enchant", enchant.getIdentifier())
|
.processPlaceholder("enchant", enchant.getIdentifier())
|
||||||
.sendPrefixedMessage(event.getWhoClicked());
|
.sendPrefixedMessage(event.getWhoClicked());
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public class BookListener extends ItemListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onClick(PlayerInteractEvent event, NBTItem clicked) {
|
void onClick(PlayerInteractEvent event, NBTItem clicked) {
|
||||||
if (!clicked.hasKey("mystery-book") || !clicked.getBoolean("mystery-book")) {
|
if (!clicked.hasTag("mystery-book") || !clicked.getBoolean("mystery-book")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,9 +93,9 @@ public class BookListener extends ItemListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Group group = instance.getGroupManager().getValue(clicked.getString("group")).orElseThrow(() -> new IllegalStateException("Book without group!"));
|
Group group = this.instance.getGroupManager().getValue(clicked.getString("group")).orElseThrow(() -> new IllegalStateException("Book without group!"));
|
||||||
|
|
||||||
Optional<Enchant> enchant = instance.getEnchantManager().getRandomEnchant(group);
|
Optional<Enchant> enchant = this.instance.getEnchantManager().getRandomEnchant(group);
|
||||||
|
|
||||||
if (!enchant.isPresent()) {
|
if (!enchant.isPresent()) {
|
||||||
throw new IllegalStateException("The " + group.getName() + " group does not have any enchants.");
|
throw new IllegalStateException("The " + group.getName() + " group does not have any enchants.");
|
||||||
|
@ -106,7 +106,7 @@ public class BookListener extends ItemListener {
|
||||||
useItem(event);
|
useItem(event);
|
||||||
event.getPlayer().getInventory().addItem(enchant.get().getBook().get(enchant.get(), level));
|
event.getPlayer().getInventory().addItem(enchant.get().getBook().get(enchant.get(), level));
|
||||||
|
|
||||||
event.getPlayer().sendMessage(instance.getLocale().getMessage("book.discover")
|
event.getPlayer().sendMessage(this.instance.getLocale().getMessage("book.discover")
|
||||||
.processPlaceholder("group_name", group.getName())
|
.processPlaceholder("group_name", group.getName())
|
||||||
.processPlaceholder("group_color", group.getColor())
|
.processPlaceholder("group_color", group.getColor())
|
||||||
.processPlaceholder("enchant_format", enchant.get().getFormat())
|
.processPlaceholder("enchant_format", enchant.get().getFormat())
|
||||||
|
|
|
@ -16,17 +16,17 @@ public class DustListener extends ItemListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
|
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
|
||||||
if (!cursor.hasKey("dust") || !cursor.getBoolean("dust")) {
|
if (!cursor.hasTag("dust") || !cursor.getBoolean("dust")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!current.hasKey("book-item") || !current.getBoolean("book-item")) {
|
if (!current.hasTag("book-item") || !current.getBoolean("book-item")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Enchant enchant = instance.getEnchantManager().getValue(current.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
|
Enchant enchant = this.instance.getEnchantManager().getValue(current.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
|
||||||
|
|
||||||
if (!enchant.getGroup().equals(instance.getGroupManager().getValue(cursor.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!")))) {
|
if (!enchant.getGroup().equals(this.instance.getGroupManager().getValue(cursor.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!")))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class DustListener extends ItemListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onClick(PlayerInteractEvent event, NBTItem clicked) {
|
void onClick(PlayerInteractEvent event, NBTItem clicked) {
|
||||||
if (!clicked.hasKey("secret-dust") || !clicked.getBoolean("secret-dust")) {
|
if (!clicked.hasTag("secret-dust") || !clicked.getBoolean("secret-dust")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,10 +55,10 @@ public class DustListener extends ItemListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Group group = instance.getGroupManager().getValueUnsafe(clicked.getString("group"));
|
Group group = this.instance.getGroupManager().getValueUnsafe(clicked.getString("group"));
|
||||||
int rate = ThreadLocalRandom.current().nextInt(clicked.getInteger("min-rate"), clicked.getInteger("max-rate"));
|
int rate = ThreadLocalRandom.current().nextInt(clicked.getInteger("min-rate"), clicked.getInteger("max-rate"));
|
||||||
|
|
||||||
useItem(event);
|
useItem(event);
|
||||||
event.getPlayer().getInventory().addItem(instance.getSpecialItems().getDust(group, null, rate, false));
|
event.getPlayer().getInventory().addItem(this.instance.getSpecialItems().getDust(group, null, rate, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,32 +8,32 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class WhiteScrollListener extends ItemListener {
|
public class WhiteScrollListener extends ItemListener {
|
||||||
|
|
||||||
public WhiteScrollListener(EpicEnchants instance) {
|
public WhiteScrollListener(EpicEnchants instance) {
|
||||||
super(instance);
|
super(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
|
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
|
||||||
if (!cursor.hasKey("white-scroll") || !cursor.getBoolean("white-scroll")) {
|
if (!cursor.hasTag("white-scroll") || !cursor.getBoolean("white-scroll")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
if (current.hasKey("protected")) {
|
if (current.hasTag("protected")) {
|
||||||
instance.getLocale().getMessage("whitescroll.alreadyapplied")
|
this.instance.getLocale().getMessage("whitescroll.alreadyapplied")
|
||||||
.sendPrefixedMessage(event.getWhoClicked());
|
.sendPrefixedMessage(event.getWhoClicked());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!instance.getItemGroup().isValid(CompatibleMaterial.getMaterial(event.getCurrentItem().getType()).get()))
|
if (!this.instance.getItemGroup().isValid(CompatibleMaterial.getMaterial(event.getCurrentItem().getType()).get())) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
current.setBoolean("protected", true);
|
current.setBoolean("protected", true);
|
||||||
instance.getLocale().getMessage("whitescrollapplied").sendPrefixedMessage(event.getWhoClicked());
|
this.instance.getLocale().getMessage("whitescrollapplied").sendPrefixedMessage(event.getWhoClicked());
|
||||||
|
|
||||||
ItemStack toSet = new ItemBuilder(current.getItem()).addLore(instance.getSpecialItems().getWhiteScrollLore()).build();
|
ItemStack toSet = new ItemBuilder(current.getItem()).addLore(this.instance.getSpecialItems().getWhiteScrollLore()).build();
|
||||||
|
|
||||||
event.getClickedInventory().setItem(event.getSlot(), toSet);
|
event.getClickedInventory().setItem(event.getSlot(), toSet);
|
||||||
useItem(event);
|
useItem(event);
|
||||||
|
|
|
@ -15,7 +15,6 @@ import java.util.stream.Collectors;
|
||||||
import static com.songoda.epicenchants.utils.single.ConfigParser.parseEnchant;
|
import static com.songoda.epicenchants.utils.single.ConfigParser.parseEnchant;
|
||||||
|
|
||||||
public class EnchantManager extends Manager<String, Enchant> {
|
public class EnchantManager extends Manager<String, Enchant> {
|
||||||
|
|
||||||
public EnchantManager(EpicEnchants instance) {
|
public EnchantManager(EpicEnchants instance) {
|
||||||
super(instance);
|
super(instance);
|
||||||
}
|
}
|
||||||
|
@ -30,7 +29,7 @@ public class EnchantManager extends Manager<String, Enchant> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadEnchants() {
|
public void loadEnchants() {
|
||||||
instance.getFileManager().getYmlFiles("enchants").forEach(file -> {
|
this.instance.getFileManager().getYmlFiles("enchants").forEach(file -> {
|
||||||
try {
|
try {
|
||||||
loadEnchant(file);
|
loadEnchant(file);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -41,10 +40,8 @@ public class EnchantManager extends Manager<String, Enchant> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadEnchant(File file) throws Exception {
|
public void loadEnchant(File file) {
|
||||||
Enchant enchant = parseEnchant(instance, YamlConfiguration.loadConfiguration(file));
|
Enchant enchant = parseEnchant(this.instance, YamlConfiguration.loadConfiguration(file));
|
||||||
add(enchant.getIdentifier(), enchant);
|
add(enchant.getIdentifier(), enchant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ import static java.io.File.separator;
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
public class FileManager extends Manager<String, FileConfiguration> {
|
public class FileManager extends Manager<String, FileConfiguration> {
|
||||||
|
|
||||||
private final String directory;
|
private final String directory;
|
||||||
private final LinkedHashSet<FileLocation> files = new LinkedHashSet<>(asList(
|
private final LinkedHashSet<FileLocation> files = new LinkedHashSet<>(asList(
|
||||||
of("menus/main-info-menu.yml", true, true),
|
of("menus/main-info-menu.yml", true, true),
|
||||||
|
@ -89,13 +88,13 @@ public class FileManager extends Manager<String, FileConfiguration> {
|
||||||
|
|
||||||
public FileManager(EpicEnchants instance) {
|
public FileManager(EpicEnchants instance) {
|
||||||
super(instance);
|
super(instance);
|
||||||
directory = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? "master" : "legacy";
|
this.directory = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? "master" : "legacy";
|
||||||
Bukkit.getConsoleSender().sendMessage("Using the " + directory + " configurations because version is " + ServerVersion.getServerVersion().name());
|
Bukkit.getConsoleSender().sendMessage("Using the " + this.directory + " configurations because version is " + ServerVersion.getServerVersion().name());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadFiles() {
|
public void loadFiles() {
|
||||||
files.forEach(fileLocation -> {
|
this.files.forEach(fileLocation -> {
|
||||||
File file = new File(instance.getDataFolder() + separator + fileLocation.getPath());
|
File file = new File(this.instance.getDataFolder() + separator + fileLocation.getPath());
|
||||||
|
|
||||||
if (!file.exists() && (fileLocation.isRequired() || Settings.FIRST_LOAD.getBoolean())) {
|
if (!file.exists() && (fileLocation.isRequired() || Settings.FIRST_LOAD.getBoolean())) {
|
||||||
Bukkit.getConsoleSender().sendMessage("Creating file: " + fileLocation.getPath());
|
Bukkit.getConsoleSender().sendMessage("Creating file: " + fileLocation.getPath());
|
||||||
|
@ -103,7 +102,7 @@ public class FileManager extends Manager<String, FileConfiguration> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// System.out.println(fileLocation.getResourcePath(directory) + " : " + file.toPath());
|
// System.out.println(fileLocation.getResourcePath(directory) + " : " + file.toPath());
|
||||||
copy(instance.getResource(fileLocation.getResourcePath(directory)), Files.newOutputStream(file.toPath()));
|
copy(this.instance.getResource(fileLocation.getResourcePath(this.directory)), Files.newOutputStream(file.toPath()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -120,8 +119,8 @@ public class FileManager extends Manager<String, FileConfiguration> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.getConfig().set("System.First Load", false);
|
this.instance.getConfig().set("System.First Load", false);
|
||||||
instance.saveConfig();
|
this.instance.saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration getConfiguration(String key) {
|
public FileConfiguration getConfiguration(String key) {
|
||||||
|
@ -129,7 +128,7 @@ public class FileManager extends Manager<String, FileConfiguration> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<File> getYmlFiles(String directory) {
|
public List<File> getYmlFiles(String directory) {
|
||||||
File dir = new File(instance.getDataFolder() + separator + directory + separator);
|
File dir = new File(this.instance.getDataFolder() + separator + directory + separator);
|
||||||
File[] allFiles = dir.listFiles();
|
File[] allFiles = dir.listFiles();
|
||||||
List<File> output = new ArrayList<>();
|
List<File> output = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -143,8 +142,8 @@ public class FileManager extends Manager<String, FileConfiguration> {
|
||||||
|
|
||||||
Arrays.stream(allFiles)
|
Arrays.stream(allFiles)
|
||||||
.filter(File::isDirectory)
|
.filter(File::isDirectory)
|
||||||
.filter(s -> !s.getName().equalsIgnoreCase("old"))
|
.filter(file -> !file.getName().equalsIgnoreCase("old"))
|
||||||
.forEach(f -> output.addAll(getYmlFiles(directory + separator + f.getName())));
|
.forEach(file -> output.addAll(getYmlFiles(directory + separator + file.getName())));
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,10 @@ public class GroupManager extends Manager<String, Group> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadGroups() {
|
public void loadGroups() {
|
||||||
ConfigurationSection config = instance.getFileManager().getConfiguration("groups").getConfigurationSection("groups");
|
ConfigurationSection config = this.instance.getFileManager().getConfiguration("groups").getConfigurationSection("groups");
|
||||||
config.getKeys(false).forEach(key -> {
|
config.getKeys(false).forEach(key -> {
|
||||||
Group group = ConfigParser.parseGroup(instance, config.getConfigurationSection(key));
|
Group group = ConfigParser.parseGroup(this.instance, config.getConfigurationSection(key));
|
||||||
add(group.getIdentifier().toUpperCase(), group);
|
add(group.getIdentifier().toUpperCase(), group);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,15 @@ public class InfoManager extends Manager<Group, InfoMenu> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadMenus() {
|
public void loadMenus() {
|
||||||
mainInfoMenu = new MainInfoMenu(instance, instance.getFileManager().getConfiguration("menus/main-info-menu"));
|
this.mainInfoMenu = new MainInfoMenu(this.instance, this.instance.getFileManager().getConfiguration("menus/main-info-menu"));
|
||||||
instance.getFileManager().getYmlFiles("menus/groups").forEach(file -> {
|
this.instance.getFileManager().getYmlFiles("menus/groups").forEach(file -> {
|
||||||
try {
|
try {
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||||
add(instance.getGroupManager().getValue(config.getString("group"))
|
add(this.instance
|
||||||
.orElseThrow(() -> new IllegalArgumentException("Invalid group: " + config.getString("group"))), new InfoMenu(instance, config));
|
.getGroupManager()
|
||||||
|
.getValue(config.getString("group"))
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("Invalid group: " + config.getString("group"))),
|
||||||
|
new InfoMenu(this.instance, config));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Bukkit.getConsoleSender().sendMessage("Something went wrong loading the menu from file " + file.getName());
|
Bukkit.getConsoleSender().sendMessage("Something went wrong loading the menu from file " + file.getName());
|
||||||
Bukkit.getConsoleSender().sendMessage("Please check to make sure there are no errors in the file.");
|
Bukkit.getConsoleSender().sendMessage("Please check to make sure there are no errors in the file.");
|
||||||
|
|
|
@ -9,7 +9,6 @@ import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public abstract class Manager<K, V> {
|
public abstract class Manager<K, V> {
|
||||||
|
|
||||||
final EpicEnchants instance;
|
final EpicEnchants instance;
|
||||||
private final Map<K, V> map;
|
private final Map<K, V> map;
|
||||||
|
|
||||||
|
@ -19,15 +18,16 @@ public abstract class Manager<K, V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<V> getValue(K key) {
|
public Optional<V> getValue(K key) {
|
||||||
for (Object k : map.keySet()) {
|
for (Object k : this.map.keySet()) {
|
||||||
if (k.toString().equalsIgnoreCase(key.toString()))
|
if (k.toString().equalsIgnoreCase(key.toString())) {
|
||||||
return Optional.ofNullable(map.get(k));
|
return Optional.ofNullable(this.map.get(k));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(K key, V value) {
|
public void add(K key, V value) {
|
||||||
map.put(key, value);
|
this.map.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public V getValueUnsafe(K key) {
|
public V getValueUnsafe(K key) {
|
||||||
|
@ -35,14 +35,14 @@ public abstract class Manager<K, V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<V> getValues() {
|
public Collection<V> getValues() {
|
||||||
return Collections.unmodifiableCollection(map.values());
|
return Collections.unmodifiableCollection(this.map.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<K> getKeys() {
|
public Collection<K> getKeys() {
|
||||||
return Collections.unmodifiableCollection(map.keySet());
|
return Collections.unmodifiableCollection(this.map.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
map.clear();
|
this.map.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,13 +36,13 @@ public class AlchemistMenu extends FastInv {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
LEFT_SLOT = config.getInt("left-slot");
|
this.LEFT_SLOT = config.getInt("left-slot");
|
||||||
RIGHT_SLOT = config.getInt("right-slot");
|
this.RIGHT_SLOT = config.getInt("right-slot");
|
||||||
PREVIEW_SLOT = config.getInt("preview-slot");
|
this.PREVIEW_SLOT = config.getInt("preview-slot");
|
||||||
ACCEPT_SLOT = config.getInt("accept-slot");
|
this.ACCEPT_SLOT = config.getInt("accept-slot");
|
||||||
|
|
||||||
PREVIEW_ITEM = new ItemBuilder(config.getConfigurationSection("contents.preview")).build();
|
this.PREVIEW_ITEM = new ItemBuilder(config.getConfigurationSection("contents.preview")).build();
|
||||||
ACCEPT_ITEM = new ItemBuilder(config.getConfigurationSection("contents.accept-before")).build();
|
this.ACCEPT_ITEM = new ItemBuilder(config.getConfigurationSection("contents.accept-before")).build();
|
||||||
|
|
||||||
if (config.isConfigurationSection("fill")) {
|
if (config.isConfigurationSection("fill")) {
|
||||||
fill(new ItemBuilder(config.getConfigurationSection("fill")).build());
|
fill(new ItemBuilder(config.getConfigurationSection("fill")).build());
|
||||||
|
@ -61,8 +61,8 @@ public class AlchemistMenu extends FastInv {
|
||||||
.map(config::getConfigurationSection)
|
.map(config::getConfigurationSection)
|
||||||
.forEach(section -> addItem(getSlots(section.getString("slot")), new ItemBuilder(section).build()));
|
.forEach(section -> addItem(getSlots(section.getString("slot")), new ItemBuilder(section).build()));
|
||||||
|
|
||||||
clear(RIGHT_SLOT);
|
clear(this.RIGHT_SLOT);
|
||||||
clear(LEFT_SLOT);
|
clear(this.LEFT_SLOT);
|
||||||
|
|
||||||
updateSlots();
|
updateSlots();
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ public class AlchemistMenu extends FastInv {
|
||||||
|
|
||||||
int slot = event.getSlot();
|
int slot = event.getSlot();
|
||||||
|
|
||||||
if (slot != RIGHT_SLOT && slot != LEFT_SLOT) {
|
if (slot != this.RIGHT_SLOT && slot != this.LEFT_SLOT) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,10 +107,10 @@ public class AlchemistMenu extends FastInv {
|
||||||
|
|
||||||
// Player closed inventory
|
// Player closed inventory
|
||||||
onClose(event -> {
|
onClose(event -> {
|
||||||
if (getInventory().getItem(RIGHT_SLOT) != null)
|
if (getInventory().getItem(this.RIGHT_SLOT) != null)
|
||||||
event.getPlayer().getInventory().addItem(getInventory().getItem(RIGHT_SLOT));
|
event.getPlayer().getInventory().addItem(getInventory().getItem(this.RIGHT_SLOT));
|
||||||
if (getInventory().getItem(LEFT_SLOT) != null)
|
if (getInventory().getItem(this.LEFT_SLOT) != null)
|
||||||
event.getPlayer().getInventory().addItem(getInventory().getItem(LEFT_SLOT));
|
event.getPlayer().getInventory().addItem(getInventory().getItem(this.LEFT_SLOT));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,65 +124,65 @@ public class AlchemistMenu extends FastInv {
|
||||||
|
|
||||||
NBTItem nbtItem = new NBTItem(toHandle);
|
NBTItem nbtItem = new NBTItem(toHandle);
|
||||||
|
|
||||||
if (!nbtItem.hasKey("book-item") && !nbtItem.hasKey("dust")) {
|
if (!nbtItem.hasTag("book-item") && !nbtItem.hasTag("dust")) {
|
||||||
instance.getLocale().getMessage("alchemist.notinterested").sendPrefixedMessage(player);
|
this.instance.getLocale().getMessage("alchemist.notinterested").sendPrefixedMessage(player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Both slots occupied
|
// Both slots occupied
|
||||||
if (getInventory().getItem(LEFT_SLOT) != null && getInventory().getItem(RIGHT_SLOT) != null) {
|
if (getInventory().getItem(this.LEFT_SLOT) != null && getInventory().getItem(this.RIGHT_SLOT) != null) {
|
||||||
instance.getLocale().getMessage("alchemist.maxtwoitems").sendPrefixedMessage(player);
|
this.instance.getLocale().getMessage("alchemist.maxtwoitems").sendPrefixedMessage(player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int successRate = nbtItem.getInteger("success-rate");
|
int successRate = nbtItem.getInteger("success-rate");
|
||||||
|
|
||||||
// Both slots empty
|
// Both slots empty
|
||||||
if (getInventory().getItem(LEFT_SLOT) == null && getInventory().getItem(RIGHT_SLOT) == null) {
|
if (getInventory().getItem(this.LEFT_SLOT) == null && getInventory().getItem(this.RIGHT_SLOT) == null) {
|
||||||
if (nbtItem.hasKey("book-item")) {
|
if (nbtItem.hasTag("book-item")) {
|
||||||
Enchant enchant = instance.getEnchantManager().getValue(nbtItem.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
|
Enchant enchant = this.instance.getEnchantManager().getValue(nbtItem.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
|
||||||
int level = nbtItem.getInteger("level");
|
int level = nbtItem.getInteger("level");
|
||||||
|
|
||||||
if (enchant.getMaxLevel() == level) {
|
if (enchant.getMaxLevel() == level) {
|
||||||
instance.getLocale().getMessage("alchemist.maxlevelbook")
|
this.instance.getLocale().getMessage("alchemist.maxlevelbook")
|
||||||
.sendPrefixedMessage(player);
|
.sendPrefixedMessage(player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Group group = instance.getGroupManager().getValue(nbtItem.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!"));
|
Group group = this.instance.getGroupManager().getValue(nbtItem.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!"));
|
||||||
|
|
||||||
if (group.getOrder() == instance.getGroupManager().getValues().stream().mapToInt(Group::getOrder).max().orElse(0) || successRate == 100) {
|
if (group.getOrder() == this.instance.getGroupManager().getValues().stream().mapToInt(Group::getOrder).max().orElse(0) || successRate == 100) {
|
||||||
instance.getLocale().getMessage("alchemist." + (successRate == 100 ? "maxpercentagedust" : "highestgroupdust"))
|
this.instance.getLocale().getMessage("alchemist." + (successRate == 100 ? "maxpercentagedust" : "highestgroupdust"))
|
||||||
.sendPrefixedMessage(player);
|
.sendPrefixedMessage(player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getInventory().setItem(LEFT_SLOT, toHandle);
|
getInventory().setItem(this.LEFT_SLOT, toHandle);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
NBTItem other = new NBTItem(getInventory().getItem(getInventory().getItem(LEFT_SLOT) == null ? RIGHT_SLOT : LEFT_SLOT));
|
NBTItem other = new NBTItem(getInventory().getItem(getInventory().getItem(this.LEFT_SLOT) == null ? this.RIGHT_SLOT : this.LEFT_SLOT));
|
||||||
int emptySlot = getInventory().getItem(LEFT_SLOT) == null ? LEFT_SLOT : RIGHT_SLOT;
|
int emptySlot = getInventory().getItem(this.LEFT_SLOT) == null ? this.LEFT_SLOT : this.RIGHT_SLOT;
|
||||||
|
|
||||||
if (other.hasKey("book-item")) {
|
if (other.hasTag("book-item")) {
|
||||||
if (!nbtItem.getString("enchant").equals(other.getString("enchant"))) {
|
if (!nbtItem.getString("enchant").equals(other.getString("enchant"))) {
|
||||||
instance.getLocale().getMessage("alchemist.differentenchantment").sendPrefixedMessage(player);
|
this.instance.getLocale().getMessage("alchemist.differentenchantment").sendPrefixedMessage(player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nbtItem.getInteger("level") != other.getInteger("level")) {
|
if (nbtItem.getInteger("level") != other.getInteger("level")) {
|
||||||
instance.getLocale().getMessage("alchemist.differentlevels").sendPrefixedMessage(player);
|
this.instance.getLocale().getMessage("alchemist.differentlevels").sendPrefixedMessage(player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!nbtItem.getString("group").equals(other.getString("group"))) {
|
if (!nbtItem.getString("group").equals(other.getString("group"))) {
|
||||||
instance.getLocale().getMessage("alchemist.differentgroups").sendPrefixedMessage(player);
|
this.instance.getLocale().getMessage("alchemist.differentgroups").sendPrefixedMessage(player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (successRate >= 100) {
|
if (successRate >= 100) {
|
||||||
instance.getLocale().getMessage("alchemist.maxpercentagedust").sendPrefixedMessage(player);
|
this.instance.getLocale().getMessage("alchemist.maxpercentagedust").sendPrefixedMessage(player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,20 +193,20 @@ public class AlchemistMenu extends FastInv {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSlots() {
|
private void updateSlots() {
|
||||||
if (getInventory().getItem(LEFT_SLOT) == null || getInventory().getItem(RIGHT_SLOT) == null) {
|
if (getInventory().getItem(this.LEFT_SLOT) == null || getInventory().getItem(this.RIGHT_SLOT) == null) {
|
||||||
addItem(ACCEPT_SLOT, ACCEPT_ITEM);
|
addItem(this.ACCEPT_SLOT, this.ACCEPT_ITEM);
|
||||||
addItem(PREVIEW_SLOT, PREVIEW_ITEM);
|
addItem(this.PREVIEW_SLOT, this.PREVIEW_ITEM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NBTItem leftItem = new NBTItem(getInventory().getItem(LEFT_SLOT));
|
NBTItem leftItem = new NBTItem(getInventory().getItem(this.LEFT_SLOT));
|
||||||
NBTItem rightItem = new NBTItem(getInventory().getItem(RIGHT_SLOT));
|
NBTItem rightItem = new NBTItem(getInventory().getItem(this.RIGHT_SLOT));
|
||||||
int ecoCost;
|
int ecoCost;
|
||||||
int expCost;
|
int expCost;
|
||||||
|
|
||||||
if (leftItem.hasKey("book-item")) {
|
if (leftItem.hasTag("book-item")) {
|
||||||
int level = leftItem.getInteger("level");
|
int level = leftItem.getInteger("level");
|
||||||
Enchant enchant = instance.getEnchantManager().getValue(leftItem.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
|
Enchant enchant = this.instance.getEnchantManager().getValue(leftItem.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
|
||||||
int leftSuccess = leftItem.getInteger("success-rate");
|
int leftSuccess = leftItem.getInteger("success-rate");
|
||||||
int rightSuccess = rightItem.getInteger("success-rate");
|
int rightSuccess = rightItem.getInteger("success-rate");
|
||||||
int leftDestroy = leftItem.getInteger("destroy-rate");
|
int leftDestroy = leftItem.getInteger("destroy-rate");
|
||||||
|
@ -235,9 +235,9 @@ public class AlchemistMenu extends FastInv {
|
||||||
ecoCost = getFromFormula("book.eco-cost-formula", costPlaceholders);
|
ecoCost = getFromFormula("book.eco-cost-formula", costPlaceholders);
|
||||||
expCost = getFromFormula("book.exp-cost-formula", costPlaceholders);
|
expCost = getFromFormula("book.exp-cost-formula", costPlaceholders);
|
||||||
|
|
||||||
getInventory().setItem(PREVIEW_SLOT, enchant.getBook().get(enchant, level + 1, successRate, destroyRate));
|
getInventory().setItem(this.PREVIEW_SLOT, enchant.getBook().get(enchant, level + 1, successRate, destroyRate));
|
||||||
} else {
|
} else {
|
||||||
Group group = instance.getGroupManager().getValue(leftItem.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!"));
|
Group group = this.instance.getGroupManager().getValue(leftItem.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!"));
|
||||||
|
|
||||||
Placeholder[] placeholders = new Placeholder[] {
|
Placeholder[] placeholders = new Placeholder[] {
|
||||||
of("left_percentage", leftItem.getInteger("percentage")),
|
of("left_percentage", leftItem.getInteger("percentage")),
|
||||||
|
@ -254,39 +254,42 @@ public class AlchemistMenu extends FastInv {
|
||||||
ecoCost = getFromFormula("dust.eco-cost-formula", costPlaceholders);
|
ecoCost = getFromFormula("dust.eco-cost-formula", costPlaceholders);
|
||||||
expCost = getFromFormula("dust.exp-cost-formula", costPlaceholders);
|
expCost = getFromFormula("dust.exp-cost-formula", costPlaceholders);
|
||||||
|
|
||||||
Group newGroup = instance.getGroupManager().getValues().stream()
|
Group newGroup = this.instance
|
||||||
|
.getGroupManager()
|
||||||
|
.getValues()
|
||||||
|
.stream()
|
||||||
.filter(s -> s.getOrder() == group.getOrder() + 1)
|
.filter(s -> s.getOrder() == group.getOrder() + 1)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseThrow(() -> new IllegalStateException("No group higher than: " + group.getIdentifier()));
|
.orElseThrow(() -> new IllegalStateException("No group higher than: " + group.getIdentifier()));
|
||||||
|
|
||||||
getInventory().setItem(PREVIEW_SLOT, instance.getSpecialItems().getDust(newGroup, "magic", successRate, true));
|
getInventory().setItem(this.PREVIEW_SLOT, this.instance.getSpecialItems().getDust(newGroup, "magic", successRate, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
addItem(ACCEPT_SLOT, new ItemBuilder(config.getConfigurationSection("contents.accept-after"),
|
addItem(this.ACCEPT_SLOT, new ItemBuilder(this.config.getConfigurationSection("contents.accept-after"),
|
||||||
of("eco_cost", ecoCost),
|
of("eco_cost", ecoCost),
|
||||||
of("exp_cost", expCost)
|
of("exp_cost", expCost)
|
||||||
).build(), event -> {
|
).build(), event -> {
|
||||||
if (!EconomyManager.hasBalance(event.getPlayer(), ecoCost) || getExp(event.getPlayer()) < expCost) {
|
if (!EconomyManager.hasBalance(event.getPlayer(), ecoCost) || getExp(event.getPlayer()) < expCost) {
|
||||||
instance.getLocale().getMessage("alchemist.cannotafford").sendPrefixedMessage(event.getPlayer());
|
this.instance.getLocale().getMessage("alchemist.cannotafford").sendPrefixedMessage(event.getPlayer());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
EconomyManager.withdrawBalance(event.getPlayer(), ecoCost);
|
EconomyManager.withdrawBalance(event.getPlayer(), ecoCost);
|
||||||
changeExp(event.getPlayer(), -expCost);
|
changeExp(event.getPlayer(), -expCost);
|
||||||
instance.getLocale().getMessage("alchemist.success")
|
this.instance.getLocale().getMessage("alchemist.success")
|
||||||
.processPlaceholder("eco_cost", ecoCost)
|
.processPlaceholder("eco_cost", ecoCost)
|
||||||
.processPlaceholder("exp_cost", expCost)
|
.processPlaceholder("exp_cost", expCost)
|
||||||
.sendPrefixedMessage(event.getPlayer());
|
.sendPrefixedMessage(event.getPlayer());
|
||||||
|
|
||||||
event.getPlayer().getInventory().addItem(getInventory().getItem(PREVIEW_SLOT));
|
event.getPlayer().getInventory().addItem(getInventory().getItem(this.PREVIEW_SLOT));
|
||||||
clear(RIGHT_SLOT);
|
clear(this.RIGHT_SLOT);
|
||||||
clear(LEFT_SLOT);
|
clear(this.LEFT_SLOT);
|
||||||
event.getPlayer().closeInventory();
|
event.getPlayer().closeInventory();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getFromFormula(String path, Placeholder... placeholders) {
|
private int getFromFormula(String path, Placeholder... placeholders) {
|
||||||
String toTest = config.getString(path);
|
String toTest = this.config.getString(path);
|
||||||
|
|
||||||
for (Placeholder placeholder : placeholders)
|
for (Placeholder placeholder : placeholders)
|
||||||
toTest = toTest.replace(placeholder.getPlaceholder(), placeholder.getToReplace().toString());
|
toTest = toTest.replace(placeholder.getPlaceholder(), placeholder.getToReplace().toString());
|
||||||
|
|
|
@ -20,7 +20,7 @@ import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
|
||||||
import static com.songoda.epicenchants.utils.single.GeneralUtils.getSlots;
|
import static com.songoda.epicenchants.utils.single.GeneralUtils.getSlots;
|
||||||
|
|
||||||
public class EnchanterMenu extends FastInv {
|
public class EnchanterMenu extends FastInv {
|
||||||
private final Map<UUID, Long> DELAY = new HashMap<>();
|
private final Map<UUID, Long> delay = new HashMap<>();
|
||||||
|
|
||||||
public EnchanterMenu(EpicEnchants instance, FileConfiguration config, Player player) {
|
public EnchanterMenu(EpicEnchants instance, FileConfiguration config, Player player) {
|
||||||
super(config.getInt("rows") * 9, color(config.getString("title")));
|
super(config.getInt("rows") * 9, color(config.getString("title")));
|
||||||
|
@ -33,7 +33,7 @@ public class EnchanterMenu extends FastInv {
|
||||||
.stream()
|
.stream()
|
||||||
.map(s -> "contents." + s)
|
.map(s -> "contents." + s)
|
||||||
.map(config::getConfigurationSection)
|
.map(config::getConfigurationSection)
|
||||||
.filter(s -> s.get("group") != null)
|
.filter(section -> section.get("group") != null)
|
||||||
.forEach(section -> {
|
.forEach(section -> {
|
||||||
int expCost = section.getInt("exp-cost");
|
int expCost = section.getInt("exp-cost");
|
||||||
int ecoCost = section.getInt("eco-cost");
|
int ecoCost = section.getInt("eco-cost");
|
||||||
|
@ -51,7 +51,7 @@ public class EnchanterMenu extends FastInv {
|
||||||
|
|
||||||
addItem(getSlots(section.getString("slot")), itemStack, event -> {
|
addItem(getSlots(section.getString("slot")), itemStack, event -> {
|
||||||
// Todo: wanna change this
|
// Todo: wanna change this
|
||||||
if (DELAY.getOrDefault(player.getUniqueId(), 0L) > System.currentTimeMillis()) {
|
if (this.delay.getOrDefault(player.getUniqueId(), 0L) > System.currentTimeMillis()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public class EnchanterMenu extends FastInv {
|
||||||
|
|
||||||
changeExp(player, -expCost);
|
changeExp(player, -expCost);
|
||||||
player.getInventory().addItem(instance.getSpecialItems().getMysteryBook(group));
|
player.getInventory().addItem(instance.getSpecialItems().getMysteryBook(group));
|
||||||
DELAY.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + 120);
|
this.delay.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + 120);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ public class EnchanterMenu extends FastInv {
|
||||||
.stream()
|
.stream()
|
||||||
.map(s -> "contents." + s)
|
.map(s -> "contents." + s)
|
||||||
.map(config::getConfigurationSection)
|
.map(config::getConfigurationSection)
|
||||||
.filter(s -> s.get("group") == null)
|
.filter(section -> section.get("group") == null)
|
||||||
.forEach(section -> addItem(getSlots(section.getString("slot")), new ItemBuilder(section).build()));
|
.forEach(section -> addItem(getSlots(section.getString("slot")), new ItemBuilder(section).build()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,12 @@ public class InfoMenu extends FastInv {
|
||||||
of("max_level", enchant.getMaxLevel()),
|
of("max_level", enchant.getMaxLevel()),
|
||||||
of("applicable_to", whitelist),
|
of("applicable_to", whitelist),
|
||||||
of("enchant", enchant.getIdentifier()),
|
of("enchant", enchant.getIdentifier()),
|
||||||
of("description", enchant.getDescription().stream().map(s -> config.getString("enchant-item.description-color") + s).collect(Collectors.toList()))).build());
|
of("description", enchant
|
||||||
|
.getDescription()
|
||||||
|
.stream()
|
||||||
|
.map(s -> config.getString("enchant-item.description-color") + s)
|
||||||
|
.collect(Collectors.toList())))
|
||||||
|
.build());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
|
||||||
import static com.songoda.epicenchants.utils.single.GeneralUtils.getSlots;
|
import static com.songoda.epicenchants.utils.single.GeneralUtils.getSlots;
|
||||||
|
|
||||||
public class MainInfoMenu extends FastInv implements Listener {
|
public class MainInfoMenu extends FastInv implements Listener {
|
||||||
|
|
||||||
public MainInfoMenu(EpicEnchants instance, FileConfiguration config) {
|
public MainInfoMenu(EpicEnchants instance, FileConfiguration config) {
|
||||||
super(config.getInt("rows") * 9, color(config.getString("title")));
|
super(config.getInt("rows") * 9, color(config.getString("title")));
|
||||||
config.getConfigurationSection("contents").getKeys(false)
|
config.getConfigurationSection("contents").getKeys(false)
|
||||||
|
@ -19,10 +18,18 @@ public class MainInfoMenu extends FastInv implements Listener {
|
||||||
.map(s -> "contents." + s)
|
.map(s -> "contents." + s)
|
||||||
.map(config::getConfigurationSection)
|
.map(config::getConfigurationSection)
|
||||||
.forEach(section -> addItem(getSlots(section.getString("slot")), new ItemBuilder(section).build(), event -> {
|
.forEach(section -> addItem(getSlots(section.getString("slot")), new ItemBuilder(section).build(), event -> {
|
||||||
if (section.getString("group") == null) return;
|
if (section.getString("group") == null) {
|
||||||
Group group = instance.getGroupManager().getValue(section.getString("group"))
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Group group = instance
|
||||||
|
.getGroupManager()
|
||||||
|
.getValue(section.getString("group"))
|
||||||
.orElseThrow(() -> new IllegalArgumentException("Invalid group: " + section.getString("group")));
|
.orElseThrow(() -> new IllegalArgumentException("Invalid group: " + section.getString("group")));
|
||||||
instance.getInfoManager().getMenu(group).ifPresent(menu -> menu.open(event.getPlayer()));
|
|
||||||
|
instance.getInfoManager()
|
||||||
|
.getMenu(group)
|
||||||
|
.ifPresent(menu -> menu.open(event.getPlayer()));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,8 +54,8 @@ public class TinkererMenu extends FastInv {
|
||||||
.forEach(section -> {
|
.forEach(section -> {
|
||||||
addItem(getSlots(section.getString("slot")), new ItemBuilder(section).build(), event -> {
|
addItem(getSlots(section.getString("slot")), new ItemBuilder(section).build(), event -> {
|
||||||
if (section.getName().equalsIgnoreCase("accept-left") || section.getName().equalsIgnoreCase("accept-right")) {
|
if (section.getName().equalsIgnoreCase("accept-left") || section.getName().equalsIgnoreCase("accept-right")) {
|
||||||
slotMap.values().stream().map(slot -> getInventory().getItem(slot)).filter(Objects::nonNull).forEach(event.getPlayer().getInventory()::addItem);
|
this.slotMap.values().stream().map(slot -> getInventory().getItem(slot)).filter(Objects::nonNull).forEach(event.getPlayer().getInventory()::addItem);
|
||||||
slotMap.keySet().forEach(slot -> getInventory().clear(slot));
|
this.slotMap.keySet().forEach(slot -> getInventory().clear(slot));
|
||||||
accepted.set(true);
|
accepted.set(true);
|
||||||
event.getPlayer().closeInventory();
|
event.getPlayer().closeInventory();
|
||||||
instance.getLocale().getMessage("tinkerer.accepted").sendPrefixedMessage(event.getPlayer());
|
instance.getLocale().getMessage("tinkerer.accepted").sendPrefixedMessage(event.getPlayer());
|
||||||
|
@ -118,14 +118,14 @@ public class TinkererMenu extends FastInv {
|
||||||
|
|
||||||
int slot = event.getSlot();
|
int slot = event.getSlot();
|
||||||
|
|
||||||
if (!slotMap.keySet().contains(slot)) {
|
if (!this.slotMap.keySet().contains(slot)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getInventory().getItem(slot) != null && getInventory().getItem(slot).getType() != Material.AIR) {
|
if (getInventory().getItem(slot) != null && getInventory().getItem(slot).getType() != Material.AIR) {
|
||||||
event.getPlayer().getInventory().addItem(getInventory().getItem(slot));
|
event.getPlayer().getInventory().addItem(getInventory().getItem(slot));
|
||||||
getInventory().clear(slot);
|
getInventory().clear(slot);
|
||||||
getInventory().clear(slotMap.get(slot));
|
getInventory().clear(this.slotMap.get(slot));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ public class TinkererMenu extends FastInv {
|
||||||
|
|
||||||
// Player closed inventory
|
// Player closed inventory
|
||||||
onClose(event -> {
|
onClose(event -> {
|
||||||
slotMap.keySet().stream().filter(s -> getInventory().getItem(s) != null).forEach(s -> {
|
this.slotMap.keySet().stream().filter(s -> getInventory().getItem(s) != null).forEach(s -> {
|
||||||
event.getPlayer().getInventory().addItem(getInventory().getItem(s));
|
event.getPlayer().getInventory().addItem(getInventory().getItem(s));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ public class TinkererMenu extends FastInv {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleItem(ItemStack itemStack, ItemType itemType) {
|
private boolean handleItem(ItemStack itemStack, ItemType itemType) {
|
||||||
Optional<Map.Entry<Integer, Integer>> emptySlot = slotMap.entrySet().stream()
|
Optional<Map.Entry<Integer, Integer>> emptySlot = this.slotMap.entrySet().stream()
|
||||||
.filter(slot -> getInventory().getItem(slot.getKey()) == null || getInventory().getItem(slot.getKey()).getType() == Material.AIR)
|
.filter(slot -> getInventory().getItem(slot.getKey()) == null || getInventory().getItem(slot.getKey()).getType() == Material.AIR)
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ public class TinkererMenu extends FastInv {
|
||||||
addItem(emptySlot.get().getKey(), finalItemStack);
|
addItem(emptySlot.get().getKey(), finalItemStack);
|
||||||
|
|
||||||
if (itemType == BOOK) {
|
if (itemType == BOOK) {
|
||||||
getInventory().setItem(emptySlot.get().getValue(), instance.getSpecialItems().getSecretDust(new NBTItem(finalItemStack)));
|
getInventory().setItem(emptySlot.get().getValue(), this.instance.getSpecialItems().getSecretDust(new NBTItem(finalItemStack)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -220,7 +220,7 @@ public class TinkererMenu extends FastInv {
|
||||||
|
|
||||||
private int getExpAmount(ItemStack itemStack) {
|
private int getExpAmount(ItemStack itemStack) {
|
||||||
AtomicInteger total = new AtomicInteger();
|
AtomicInteger total = new AtomicInteger();
|
||||||
ConfigurationSection section = config.getConfigurationSection("exp-table-per-level");
|
ConfigurationSection section = this.config.getConfigurationSection("exp-table-per-level");
|
||||||
|
|
||||||
itemStack.getEnchantments().forEach((enchantment, level) -> {
|
itemStack.getEnchantments().forEach((enchantment, level) -> {
|
||||||
total.addAndGet(section.getInt(enchantment.getName(), section.getInt("DEFAULT")) * level);
|
total.addAndGet(section.getInt(enchantment.getName(), section.getInt("DEFAULT")) * level);
|
||||||
|
@ -239,7 +239,7 @@ public class TinkererMenu extends FastInv {
|
||||||
}
|
}
|
||||||
|
|
||||||
enchantments.getKeys().forEach(key -> {
|
enchantments.getKeys().forEach(key -> {
|
||||||
Enchant enchant = instance.getEnchantManager().getValueUnsafe(key);
|
Enchant enchant = this.instance.getEnchantManager().getValueUnsafe(key);
|
||||||
total.addAndGet(section.getInt(enchant.getIdentifier(), enchant.getGroup().getTinkererExp()) * enchantments.getInteger(key));
|
total.addAndGet(section.getInt(enchant.getIdentifier(), enchant.getGroup().getTinkererExp()) * enchantments.getInteger(key));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,10 @@ import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
|
||||||
import static java.util.concurrent.ThreadLocalRandom.current;
|
import static java.util.concurrent.ThreadLocalRandom.current;
|
||||||
|
|
||||||
public class BookItem {
|
public class BookItem {
|
||||||
private EpicEnchants instance;
|
private final EpicEnchants instance;
|
||||||
private Material material;
|
private final Material material;
|
||||||
private String displayName;
|
private final String displayName;
|
||||||
private List<String> lore;
|
private final List<String> lore;
|
||||||
|
|
||||||
BookItem(EpicEnchants instance, Material material, String displayName, List<String> lore) {
|
BookItem(EpicEnchants instance, Material material, String displayName, List<String> lore) {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
|
@ -52,7 +52,7 @@ public class BookItem {
|
||||||
int finalSuccessRate = successRate;
|
int finalSuccessRate = successRate;
|
||||||
int finalDestroyRate = destroyRate;
|
int finalDestroyRate = destroyRate;
|
||||||
|
|
||||||
List<String> toSet = new ArrayList<>(lore);
|
List<String> toSet = new ArrayList<>(this.lore);
|
||||||
|
|
||||||
for (int i = toSet.size() - 1; i >= 0; i--) {
|
for (int i = toSet.size() - 1; i >= 0; i--) {
|
||||||
String string = toSet.get(i);
|
String string = toSet.get(i);
|
||||||
|
@ -64,17 +64,17 @@ public class BookItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
string = string
|
string = string
|
||||||
.replace("{item_group}", "" + instance.getItemGroup().getGroup(enchant.getItemWhitelist()).map(ItemGroup.Group::getName).orElse("N/A"))
|
.replace("{item_group}", this.instance.getItemGroup().getGroup(enchant.getItemWhitelist()).map(ItemGroup.Group::getName).orElse("N/A"))
|
||||||
.replace("{success_rate}", "" + finalSuccessRate)
|
.replace("{success_rate}", String.valueOf(finalSuccessRate))
|
||||||
.replace("{destroy_rate}", "" + finalDestroyRate);
|
.replace("{destroy_rate}", String.valueOf(finalDestroyRate));
|
||||||
|
|
||||||
toSet.set(i, string);
|
toSet.set(i, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemBuilder itemBuilder = new ItemBuilder(material)
|
ItemBuilder itemBuilder = new ItemBuilder(this.material)
|
||||||
.name(color(displayName
|
.name(color(this.displayName
|
||||||
.replace("{level}", "" + (Settings.ROMAN.getBoolean() ? RomanNumber.toRoman(level) : level))
|
.replace("{level}", String.valueOf(Settings.ROMAN.getBoolean() ? RomanNumber.toRoman(level) : level))
|
||||||
.replace("{enchant}", "" + enchant.getIdentifier())
|
.replace("{enchant}", enchant.getIdentifier())
|
||||||
.replace("{group_color}", enchant.getGroup().getColor())
|
.replace("{group_color}", enchant.getGroup().getColor())
|
||||||
.replace("{group_name}", enchant.getGroup().getName())
|
.replace("{group_name}", enchant.getGroup().getName())
|
||||||
))
|
))
|
||||||
|
@ -120,7 +120,7 @@ public class BookItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
public BookItem build() {
|
public BookItem build() {
|
||||||
return new BookItem(instance, material, displayName, lore);
|
return new BookItem(this.instance, this.material, this.displayName, this.lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -20,11 +20,11 @@ public class Condition {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean get(Player user, @Nullable LivingEntity attacker, int level, @Nullable Event event, boolean def) {
|
public boolean get(Player user, @Nullable LivingEntity attacker, int level, @Nullable Event event, boolean def) {
|
||||||
if (string == null || string.isEmpty()) {
|
if (this.string == null || this.string.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String toValidate = ChatColor.stripColor(Placeholders.setPlaceholders(string, user, attacker, level, event));
|
String toValidate = ChatColor.stripColor(Placeholders.setPlaceholders(this.string, user, attacker, level, event));
|
||||||
|
|
||||||
return (boolean) GeneralUtils.parseJS(toValidate, "condition", def);
|
return (boolean) GeneralUtils.parseJS(toValidate, "condition", def);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.songoda.epicenchants.objects;
|
package com.songoda.epicenchants.objects;
|
||||||
|
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
|
||||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||||
import com.songoda.epicenchants.effect.EffectExecutor;
|
import com.songoda.epicenchants.effect.EffectExecutor;
|
||||||
import com.songoda.epicenchants.enums.EventType;
|
import com.songoda.epicenchants.enums.EventType;
|
||||||
|
@ -19,19 +18,18 @@ import java.util.Set;
|
||||||
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
|
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
|
||||||
|
|
||||||
public class Enchant {
|
public class Enchant {
|
||||||
private String author;
|
private final String author;
|
||||||
private String identifier;
|
private final String identifier;
|
||||||
private Group group;
|
private final Group group;
|
||||||
private int maxLevel;
|
private final int maxLevel;
|
||||||
private Set<String> conflict;
|
private final Set<String> conflict;
|
||||||
private Set<XMaterial> itemWhitelist;
|
private final Set<XMaterial> itemWhitelist;
|
||||||
private Set<EffectExecutor> effectExecutors;
|
private final Set<EffectExecutor> effectExecutors;
|
||||||
private List<String> description;
|
private final List<String> description;
|
||||||
private String format;
|
private final String format;
|
||||||
@Nullable
|
private final @Nullable BookItem bookItem;
|
||||||
private BookItem bookItem;
|
|
||||||
|
|
||||||
Enchant(String author, String identifier, Group group, int maxLevel, Set<String> conflict, Set<XMaterial> itemWhitelist, Set<EffectExecutor> effectExecutors, List<String> description, String format, BookItem bookItem) {
|
Enchant(String author, String identifier, Group group, int maxLevel, Set<String> conflict, Set<XMaterial> itemWhitelist, Set<EffectExecutor> effectExecutors, List<String> description, String format, @Nullable BookItem bookItem) {
|
||||||
this.author = author;
|
this.author = author;
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
this.group = group;
|
this.group = group;
|
||||||
|
@ -49,26 +47,26 @@ public class Enchant {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAction(@NotNull Player user, @Nullable LivingEntity opponent, Event event, int level, TriggerType triggerType, EventType eventType) {
|
public void onAction(@NotNull Player user, @Nullable LivingEntity opponent, Event event, int level, TriggerType triggerType, EventType eventType) {
|
||||||
effectExecutors.forEach(effect -> effect.testAndRun(user, opponent, level, triggerType, event, eventType));
|
this.effectExecutors.forEach(effect -> effect.testAndRun(user, opponent, level, triggerType, event, eventType));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BookItem getBook() {
|
public BookItem getBook() {
|
||||||
return bookItem != null ? bookItem : group.getBookItem();
|
return this.bookItem != null ? this.bookItem : this.group.getBookItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFormat(int level, boolean roman) {
|
public String getFormat(int level, boolean roman) {
|
||||||
String output = format.isEmpty() ? group.getFormat() : format;
|
String output = this.format.isEmpty() ? this.group.getFormat() : this.format;
|
||||||
|
|
||||||
output = output
|
output = output
|
||||||
.replace("{level}", "" + (roman ? RomanNumber.toRoman(level) : level))
|
.replace("{level}", String.valueOf(roman ? RomanNumber.toRoman(level) : level))
|
||||||
.replace("{enchant}", "" + identifier)
|
.replace("{enchant}", this.identifier)
|
||||||
.replace("{group_color}", "" + group.getColor());
|
.replace("{group_color}", this.group.getColor());
|
||||||
|
|
||||||
return color(output);
|
return color(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthor() {
|
public String getAuthor() {
|
||||||
return author;
|
return this.author;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdentifier() {
|
public String getIdentifier() {
|
||||||
|
@ -184,7 +182,7 @@ public class Enchant {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Enchant build() {
|
public Enchant build() {
|
||||||
return new Enchant(author, identifier, group, maxLevel, conflict, itemWhitelist, effectExecutors, description, format, bookItem);
|
return new Enchant(this.author, this.identifier, this.group, this.maxLevel, this.conflict, this.itemWhitelist, this.effectExecutors, this.description, this.format, this.bookItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
package com.songoda.epicenchants.objects;
|
package com.songoda.epicenchants.objects;
|
||||||
|
|
||||||
public class Group {
|
public class Group {
|
||||||
private String identifier;
|
private final String identifier;
|
||||||
private String name;
|
private final String name;
|
||||||
private String format;
|
private final String format;
|
||||||
private String color;
|
private final String color;
|
||||||
private String descriptionColor;
|
private final String descriptionColor;
|
||||||
private int slotsUsed;
|
private final int slotsUsed;
|
||||||
private BookItem bookItem;
|
private final BookItem bookItem;
|
||||||
private int destroyRateMin, destroyRateMax, successRateMin, successRateMax;
|
private final int destroyRateMin;
|
||||||
private int tinkererExp;
|
private final int destroyRateMax;
|
||||||
private int order;
|
private final int successRateMin;
|
||||||
|
private final int successRateMax;
|
||||||
|
private final int tinkererExp;
|
||||||
|
private final int order;
|
||||||
|
|
||||||
Group(String identifier, String name, String format, String color, String descriptionColor, int slotsUsed, BookItem bookItem, int destroyRateMin, int destroyRateMax, int successRateMin, int successRateMax, int tinkererExp, int order) {
|
Group(String identifier, String name, String format, String color, String descriptionColor, int slotsUsed, BookItem bookItem, int destroyRateMin, int destroyRateMax, int successRateMin, int successRateMax, int tinkererExp, int order) {
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
|
@ -168,7 +171,7 @@ public class Group {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Group build() {
|
public Group build() {
|
||||||
return new Group(identifier, name, format, color, descriptionColor, slotsUsed, bookItem, destroyRateMin, destroyRateMax, successRateMin, successRateMax, tinkererExp, order);
|
return new Group(this.identifier, this.name, this.format, this.color, this.descriptionColor, this.slotsUsed, this.bookItem, this.destroyRateMin, this.destroyRateMax, this.successRateMin, this.successRateMax, this.tinkererExp, this.order);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -17,15 +17,15 @@ public class LeveledModifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
public double get(int level, double def, Player user, LivingEntity opponent) {
|
public double get(int level, double def, Player user, LivingEntity opponent) {
|
||||||
if (string == null || string.isEmpty()) {
|
if (this.string == null || this.string.isEmpty()) {
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.equalsIgnoreCase("MAX")) {
|
if (this.string.equalsIgnoreCase("MAX")) {
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
String toTest = Placeholders.setPlaceholders(string, user, opponent, level);
|
String toTest = Placeholders.setPlaceholders(this.string, user, opponent, level);
|
||||||
|
|
||||||
Object value = GeneralUtils.parseJS(toTest, "LeveledModifier", def);
|
Object value = GeneralUtils.parseJS(toTest, "LeveledModifier", def);
|
||||||
return value instanceof Double ? (double) value : (int) value;
|
return value instanceof Double ? (double) value : (int) value;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.songoda.epicenchants.objects;
|
package com.songoda.epicenchants.objects;
|
||||||
|
|
||||||
public class Placeholder {
|
public class Placeholder {
|
||||||
private String placeholder;
|
private final String placeholder;
|
||||||
private Object toReplace;
|
private final Object toReplace;
|
||||||
|
|
||||||
private Placeholder(String placeholder, Object toReplace) {
|
private Placeholder(String placeholder, Object toReplace) {
|
||||||
this.placeholder = "{" + placeholder + "}";
|
this.placeholder = "{" + placeholder + "}";
|
||||||
|
@ -14,10 +14,10 @@ public class Placeholder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPlaceholder() {
|
public String getPlaceholder() {
|
||||||
return placeholder;
|
return this.placeholder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getToReplace() {
|
public Object getToReplace() {
|
||||||
return toReplace;
|
return this.toReplace;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.songoda.epicenchants.utils;
|
||||||
|
|
||||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTCompound;
|
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTCompound;
|
||||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
|
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
|
||||||
|
import com.craftaro.core.utils.NumberUtils;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
import com.songoda.epicenchants.EpicEnchants;
|
import com.songoda.epicenchants.EpicEnchants;
|
||||||
import com.songoda.epicenchants.enums.EnchantResult;
|
import com.songoda.epicenchants.enums.EnchantResult;
|
||||||
|
@ -48,7 +49,7 @@ public class EnchantUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tuple<ItemStack, EnchantResult> apply(ItemStack itemStack, Enchant enchant, int level, int successRate, int destroyRate) {
|
public Tuple<ItemStack, EnchantResult> apply(ItemStack itemStack, Enchant enchant, int level, int successRate, int destroyRate) {
|
||||||
boolean hasProtection = new NBTItem(itemStack).hasKey("protected");
|
boolean hasProtection = new NBTItem(itemStack).hasTag("protected");
|
||||||
|
|
||||||
Map<Enchant, Integer> currentEnchantMap = getEnchants(itemStack);
|
Map<Enchant, Integer> currentEnchantMap = getEnchants(itemStack);
|
||||||
Set<String> currentIds = currentEnchantMap.keySet().stream().map(Enchant::getIdentifier).collect(Collectors.toSet());
|
Set<String> currentIds = currentEnchantMap.keySet().stream().map(Enchant::getIdentifier).collect(Collectors.toSet());
|
||||||
|
@ -69,7 +70,7 @@ public class EnchantUtils {
|
||||||
if (!GeneralUtils.chance(successRate)) {
|
if (!GeneralUtils.chance(successRate)) {
|
||||||
if (GeneralUtils.chance(destroyRate)) {
|
if (GeneralUtils.chance(destroyRate)) {
|
||||||
if (hasProtection) {
|
if (hasProtection) {
|
||||||
NBTItem nbtItem = new ItemBuilder(itemStack).removeLore(instance.getSpecialItems().getWhiteScrollLore()).nbt();
|
NBTItem nbtItem = new ItemBuilder(itemStack).removeLore(this.instance.getSpecialItems().getWhiteScrollLore()).nbt();
|
||||||
nbtItem.removeKey("protected");
|
nbtItem.removeKey("protected");
|
||||||
return Tuple.of(nbtItem.getItem(), PROTECTED);
|
return Tuple.of(nbtItem.getItem(), PROTECTED);
|
||||||
}
|
}
|
||||||
|
@ -81,14 +82,14 @@ public class EnchantUtils {
|
||||||
ItemBuilder itemBuilder = new ItemBuilder(itemStack);
|
ItemBuilder itemBuilder = new ItemBuilder(itemStack);
|
||||||
|
|
||||||
if (hasProtection) {
|
if (hasProtection) {
|
||||||
itemBuilder.removeLore(instance.getSpecialItems().getWhiteScrollLore());
|
itemBuilder.removeLore(this.instance.getSpecialItems().getWhiteScrollLore());
|
||||||
}
|
}
|
||||||
|
|
||||||
itemBuilder.removeLore(enchant.getFormat(-1, Settings.ROMAN.getBoolean()).replace("-1", "").trim());
|
itemBuilder.removeLore(enchant.getFormat(-1, Settings.ROMAN.getBoolean()).replace("-1", "").trim());
|
||||||
itemBuilder.addLore(enchant.getFormat(level, Settings.ROMAN.getBoolean()));
|
itemBuilder.addLore(enchant.getFormat(level, Settings.ROMAN.getBoolean()));
|
||||||
|
|
||||||
if (hasProtection) {
|
if (hasProtection) {
|
||||||
itemBuilder.addLore(instance.getSpecialItems().getWhiteScrollLore());
|
itemBuilder.addLore(this.instance.getSpecialItems().getWhiteScrollLore());
|
||||||
}
|
}
|
||||||
|
|
||||||
NBTItem nbtItem = itemBuilder.nbt();
|
NBTItem nbtItem = itemBuilder.nbt();
|
||||||
|
@ -105,7 +106,7 @@ public class EnchantUtils {
|
||||||
}
|
}
|
||||||
NBTItem nbtItem = new NBTItem(itemStack);
|
NBTItem nbtItem = new NBTItem(itemStack);
|
||||||
|
|
||||||
if (!nbtItem.hasKey("enchants")) {
|
if (!nbtItem.hasTag("enchants")) {
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,8 +116,8 @@ public class EnchantUtils {
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
return compound.getKeys().stream().filter(key -> instance.getEnchantManager().getValueUnsafe(key) != null)
|
return compound.getKeys().stream().filter(key -> this.instance.getEnchantManager().getValueUnsafe(key) != null)
|
||||||
.collect(Collectors.toMap(key -> instance.getEnchantManager().getValueUnsafe(key), compound::getInteger));
|
.collect(Collectors.toMap(key -> this.instance.getEnchantManager().getValueUnsafe(key), compound::getInteger));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handlePlayer(@NotNull Player player, @Nullable LivingEntity opponent, Event event, TriggerType triggerType) {
|
public void handlePlayer(@NotNull Player player, @Nullable LivingEntity opponent, Event event, TriggerType triggerType) {
|
||||||
|
@ -155,26 +156,34 @@ public class EnchantUtils {
|
||||||
|
|
||||||
public int getMaximumEnchantsCanApplyItem(ItemStack itemStack, Player p) {
|
public int getMaximumEnchantsCanApplyItem(ItemStack itemStack, Player p) {
|
||||||
int max;
|
int max;
|
||||||
if (p.isOp()) return 100; // in theory no single item will have 100 enchantments at a time.
|
if (p.isOp()) {
|
||||||
if (instance.getFileManager().getConfiguration("items/item-limits").contains("limits." + itemStack.getType().toString())) {
|
return 100; // in theory, no single item will have 100 enchantments at a time.
|
||||||
max = instance.getFileManager().getConfiguration("items/item-limits").getInt("limits." + itemStack.getType().toString());
|
}
|
||||||
|
if (this.instance.getFileManager().getConfiguration("items/item-limits").contains("limits." + itemStack.getType().toString())) {
|
||||||
|
max = this.instance.getFileManager().getConfiguration("items/item-limits").getInt("limits." + itemStack.getType().toString());
|
||||||
} else {
|
} else {
|
||||||
max = instance.getFileManager().getConfiguration("items/item-limits").getInt("default");
|
max = this.instance.getFileManager().getConfiguration("items/item-limits").getInt("default");
|
||||||
}
|
}
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaximumEnchantsCanApply(Player p) {
|
public int getMaximumEnchantsCanApply(Player p) {
|
||||||
int max = 0;
|
int max = 0;
|
||||||
if (p.isOp()) return 100; // in theory no single item will have 100 enchantments at a time.
|
if (p.isOp()) {
|
||||||
|
return 100; // in theory, no single item will have 100 enchantments at a time.
|
||||||
|
}
|
||||||
for (PermissionAttachmentInfo effectivePermission : p.getEffectivePermissions()) {
|
for (PermissionAttachmentInfo effectivePermission : p.getEffectivePermissions()) {
|
||||||
if (!effectivePermission.getPermission().startsWith("epicenchants.maxapply.")) continue;
|
if (!effectivePermission.getPermission().startsWith("epicenchants.maxapply.")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
String node[] = effectivePermission.getPermission().split("\\.");
|
String[] node = effectivePermission.getPermission().split("\\.");
|
||||||
|
|
||||||
if (Methods.isInt(node[node.length - 1])) {
|
if (NumberUtils.isInt(node[node.length - 1])) {
|
||||||
int num = Integer.parseInt(node[node.length - 1]);
|
int num = Integer.parseInt(node[node.length - 1]);
|
||||||
if (num > max) max = num;
|
if (num > max) {
|
||||||
|
max = num;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return max;
|
return max;
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
package com.songoda.epicenchants.utils;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
|
|
||||||
public class Methods {
|
|
||||||
public static boolean isInt(String number) {
|
|
||||||
if (number == null || number.equals(""))
|
|
||||||
return false;
|
|
||||||
try {
|
|
||||||
Integer.parseInt(number);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String formatText(String text) {
|
|
||||||
if (text == null || text.equals(""))
|
|
||||||
return "";
|
|
||||||
return formatText(text, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String formatText(String text, boolean cap) {
|
|
||||||
if (text == null || text.equals(""))
|
|
||||||
return "";
|
|
||||||
if (cap)
|
|
||||||
text = text.substring(0, 1).toUpperCase() + text.substring(1);
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', text);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -23,7 +23,7 @@ public class SpecialItems {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getWhiteScroll(int amount) {
|
public ItemStack getWhiteScroll(int amount) {
|
||||||
NBTItem nbtItem = new ItemBuilder(instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("white-scroll")).nbt();
|
NBTItem nbtItem = new ItemBuilder(this.instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("white-scroll")).nbt();
|
||||||
nbtItem.setBoolean("white-scroll", true);
|
nbtItem.setBoolean("white-scroll", true);
|
||||||
ItemStack itemStack = nbtItem.getItem();
|
ItemStack itemStack = nbtItem.getItem();
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public class SpecialItems {
|
||||||
|
|
||||||
public ItemStack getBlackScroll(int amount, int chance) {
|
public ItemStack getBlackScroll(int amount, int chance) {
|
||||||
int successRate = chance == -1 ? ThreadLocalRandom.current().nextInt(Settings.BLACK_MIN.getInt(), Settings.BLACK_MAX.getInt() + 1) : chance;
|
int successRate = chance == -1 ? ThreadLocalRandom.current().nextInt(Settings.BLACK_MIN.getInt(), Settings.BLACK_MAX.getInt() + 1) : chance;
|
||||||
NBTItem nbtItem = new ItemBuilder(instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("black-scroll"), of("success-rate", successRate)).nbt();
|
NBTItem nbtItem = new ItemBuilder(this.instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("black-scroll"), of("success-rate", successRate)).nbt();
|
||||||
|
|
||||||
nbtItem.setBoolean("black-scroll", true);
|
nbtItem.setBoolean("black-scroll", true);
|
||||||
nbtItem.setInteger("success-rate", successRate);
|
nbtItem.setInteger("success-rate", successRate);
|
||||||
|
@ -47,7 +47,7 @@ public class SpecialItems {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getMysteryBook(Group group) {
|
public ItemStack getMysteryBook(Group group) {
|
||||||
NBTItem nbtItem = new ItemBuilder(instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("mystery-book"),
|
NBTItem nbtItem = new ItemBuilder(this.instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("mystery-book"),
|
||||||
of("group-color", group.getColor()),
|
of("group-color", group.getColor()),
|
||||||
of("group-name", group.getName())).nbt();
|
of("group-name", group.getName())).nbt();
|
||||||
|
|
||||||
|
@ -57,12 +57,12 @@ public class SpecialItems {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getSecretDust(NBTItem book) {
|
public ItemStack getSecretDust(NBTItem book) {
|
||||||
Group group = instance.getEnchantManager().getValueUnsafe(book.getString("enchant")).getGroup();
|
Group group = this.instance.getEnchantManager().getValueUnsafe(book.getString("enchant")).getGroup();
|
||||||
return getSecretDust(group, (int) Math.floor(book.getInteger("success-rate") / 10.0));
|
return getSecretDust(group, (int) Math.floor(book.getInteger("success-rate") / 10.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getSecretDust(Group group, int max) {
|
public ItemStack getSecretDust(Group group, int max) {
|
||||||
NBTItem nbtItem = new ItemBuilder(instance.getFileManager().getConfiguration("items/dusts").getConfigurationSection("secret-dust"),
|
NBTItem nbtItem = new ItemBuilder(this.instance.getFileManager().getConfiguration("items/dusts").getConfigurationSection("secret-dust"),
|
||||||
of("group-color", group.getColor()),
|
of("group-color", group.getColor()),
|
||||||
of("group-name", group.getName()),
|
of("group-name", group.getName()),
|
||||||
of("max-rate", max),
|
of("max-rate", max),
|
||||||
|
@ -76,7 +76,7 @@ public class SpecialItems {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getDust(Group group, @Nullable String type, int percentage, boolean command) {
|
public ItemStack getDust(Group group, @Nullable String type, int percentage, boolean command) {
|
||||||
FileConfiguration dustConfig = instance.getFileManager().getConfiguration("items/dusts");
|
FileConfiguration dustConfig = this.instance.getFileManager().getConfiguration("items/dusts");
|
||||||
int random = ThreadLocalRandom.current().nextInt(101);
|
int random = ThreadLocalRandom.current().nextInt(101);
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
|
@ -119,6 +119,6 @@ public class SpecialItems {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWhiteScrollLore() {
|
public String getWhiteScrollLore() {
|
||||||
return color(instance.getFileManager().getConfiguration("items/special-items").getString("white-scroll.format"));
|
return color(this.instance.getFileManager().getConfiguration("items/special-items").getString("white-scroll.format"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.songoda.epicenchants.utils;
|
package com.songoda.epicenchants.utils;
|
||||||
|
|
||||||
public class Tuple<key, value> {
|
public class Tuple<key, value> {
|
||||||
private key x;
|
private final key x;
|
||||||
private value y;
|
private final value y;
|
||||||
|
|
||||||
public Tuple(key x, value y) {
|
public Tuple(key x, value y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
|
@ -18,6 +18,6 @@ public class Tuple<key, value> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <key, value> Tuple of(key x, value y) {
|
public static <key, value> Tuple of(key x, value y) {
|
||||||
return new Tuple(x, y);
|
return new Tuple<>(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,9 +55,9 @@ public class FastInv implements InventoryHolder {
|
||||||
|
|
||||||
runSync(() -> {
|
runSync(() -> {
|
||||||
if (type == InventoryType.CHEST && size > 0) {
|
if (type == InventoryType.CHEST && size > 0) {
|
||||||
inventory = Bukkit.createInventory(this, size, title);
|
this.inventory = Bukkit.createInventory(this, size, title);
|
||||||
} else {
|
} else {
|
||||||
inventory = Bukkit.createInventory(this, type, title);
|
this.inventory = Bukkit.createInventory(this, type, title);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ public class FastInv implements InventoryHolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryClickEvent getEvent() {
|
public InventoryClickEvent getEvent() {
|
||||||
return event;
|
return this.event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ public class FastInv implements InventoryHolder {
|
||||||
*/
|
*/
|
||||||
public FastInv addItem(ItemStack item, FastInvClickListener listener) {
|
public FastInv addItem(ItemStack item, FastInvClickListener listener) {
|
||||||
runSync(() -> {
|
runSync(() -> {
|
||||||
int slot = inventory.firstEmpty();
|
int slot = this.inventory.firstEmpty();
|
||||||
if (slot >= 0) {
|
if (slot >= 0) {
|
||||||
addItem(slot, item, listener);
|
addItem(slot, item, listener);
|
||||||
}
|
}
|
||||||
|
@ -180,12 +180,12 @@ public class FastInv implements InventoryHolder {
|
||||||
*/
|
*/
|
||||||
public FastInv addItem(int slot, ItemStack item, FastInvClickListener listener) {
|
public FastInv addItem(int slot, ItemStack item, FastInvClickListener listener) {
|
||||||
runSync(() -> {
|
runSync(() -> {
|
||||||
inventory.setItem(slot, item);
|
this.inventory.setItem(slot, item);
|
||||||
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
itemListeners.put(slot, listener);
|
this.itemListeners.put(slot, listener);
|
||||||
} else {
|
} else {
|
||||||
itemListeners.remove(slot);
|
this.itemListeners.remove(slot);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -253,10 +253,10 @@ public class FastInv implements InventoryHolder {
|
||||||
* @return This FastInv instance, for chaining.
|
* @return This FastInv instance, for chaining.
|
||||||
*/
|
*/
|
||||||
public FastInv edge(ItemStack item) {
|
public FastInv edge(ItemStack item) {
|
||||||
int height = inventory.getSize() / 9;
|
int height = this.inventory.getSize() / 9;
|
||||||
|
|
||||||
addItem(0, 9, item);
|
addItem(0, 9, item);
|
||||||
addItem(inventory.getSize() - 9, inventory.getSize() - 1, item);
|
addItem(this.inventory.getSize() - 9, this.inventory.getSize() - 1, item);
|
||||||
|
|
||||||
for (int i = 0; i < height; i++) {
|
for (int i = 0; i < height; i++) {
|
||||||
addItem(i * 9, item);
|
addItem(i * 9, item);
|
||||||
|
@ -284,8 +284,8 @@ public class FastInv implements InventoryHolder {
|
||||||
|
|
||||||
public FastInv fill(ItemStack itemStack) {
|
public FastInv fill(ItemStack itemStack) {
|
||||||
runSync(() -> {
|
runSync(() -> {
|
||||||
for (int i = 0; i < inventory.getSize(); i++) {
|
for (int i = 0; i < this.inventory.getSize(); i++) {
|
||||||
if (inventory.getItem(i) == null) {
|
if (this.inventory.getItem(i) == null) {
|
||||||
addItem(i, itemStack);
|
addItem(i, itemStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ public class FastInv implements InventoryHolder {
|
||||||
* @return This FastInv instance, for chaining.
|
* @return This FastInv instance, for chaining.
|
||||||
*/
|
*/
|
||||||
public FastInv onClose(FastInvCloseListener listener) {
|
public FastInv onClose(FastInvCloseListener listener) {
|
||||||
closeListeners.add(listener);
|
this.closeListeners.add(listener);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,7 +313,7 @@ public class FastInv implements InventoryHolder {
|
||||||
* @return This FastInv instance, for chaining.
|
* @return This FastInv instance, for chaining.
|
||||||
*/
|
*/
|
||||||
public FastInv onClick(FastInvClickListener listener) {
|
public FastInv onClick(FastInvClickListener listener) {
|
||||||
clickListeners.add(listener);
|
this.clickListeners.add(listener);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ public class FastInv implements InventoryHolder {
|
||||||
* @return This FastInv instance, for chaining
|
* @return This FastInv instance, for chaining
|
||||||
*/
|
*/
|
||||||
public FastInv onUpdate(long delay, long period, Runnable runnable) {
|
public FastInv onUpdate(long delay, long period, Runnable runnable) {
|
||||||
tasks.add(Bukkit.getScheduler().runTaskTimer(plugin, runnable, delay, period));
|
this.tasks.add(Bukkit.getScheduler().runTaskTimer(plugin, runnable, delay, period));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,15 +349,15 @@ public class FastInv implements InventoryHolder {
|
||||||
* @param player The player to open the menu.
|
* @param player The player to open the menu.
|
||||||
*/
|
*/
|
||||||
public void open(Player player) {
|
public void open(Player player) {
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> player.openInventory(inventory));
|
Bukkit.getScheduler().runTask(plugin, () -> player.openInventory(this.inventory));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel all tasks.
|
* Cancel all tasks.
|
||||||
*/
|
*/
|
||||||
public void cancelTasks() {
|
public void cancelTasks() {
|
||||||
tasks.forEach(BukkitTask::cancel);
|
this.tasks.forEach(BukkitTask::cancel);
|
||||||
tasks.clear();
|
this.tasks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -380,13 +380,13 @@ public class FastInv implements InventoryHolder {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Inventory getInventory() {
|
public Inventory getInventory() {
|
||||||
return inventory;
|
return this.inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set if the tasks will be cancel on menus close.
|
* Set if the tasks will be canceled on menus close.
|
||||||
*
|
*
|
||||||
* @param cancelTasksOnClose Set if the tasks will be cancel
|
* @param cancelTasksOnClose Set if the tasks will be canceled
|
||||||
*
|
*
|
||||||
* @return This FastInv instance, for chaining.
|
* @return This FastInv instance, for chaining.
|
||||||
*/
|
*/
|
||||||
|
@ -420,7 +420,7 @@ public class FastInv implements InventoryHolder {
|
||||||
* @return This associated FastInv instance.
|
* @return This associated FastInv instance.
|
||||||
*/
|
*/
|
||||||
public FastInv getInventory() {
|
public FastInv getInventory() {
|
||||||
return inventory;
|
return this.inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -429,7 +429,7 @@ public class FastInv implements InventoryHolder {
|
||||||
* @return the player who clicked.
|
* @return the player who clicked.
|
||||||
*/
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return player;
|
return this.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -438,11 +438,11 @@ public class FastInv implements InventoryHolder {
|
||||||
* @return Whether the event was cancelled.
|
* @return Whether the event was cancelled.
|
||||||
*/
|
*/
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set if the event will be cancel or not.
|
* Set if the event will be canceled or not.
|
||||||
*
|
*
|
||||||
* @param cancel Whether the event should be cancelled.
|
* @param cancel Whether the event should be cancelled.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -19,22 +19,22 @@ public class FileLocation {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getResourcePath(String dir) {
|
public String getResourcePath(String dir) {
|
||||||
return (versionDependent ? "version-dependent/" + dir + "/" : "") + path;
|
return (this.versionDependent ? "version-dependent/" + dir + "/" : "") + this.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDirectory() {
|
public boolean isDirectory() {
|
||||||
return path.endsWith("/");
|
return this.path.endsWith("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRequired() {
|
public boolean isRequired() {
|
||||||
return required;
|
return this.required;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVersionDependent() {
|
public boolean isVersionDependent() {
|
||||||
return versionDependent;
|
return this.versionDependent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return path;
|
return this.path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ import java.util.stream.Collectors;
|
||||||
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
|
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
|
||||||
|
|
||||||
public class ItemBuilder {
|
public class ItemBuilder {
|
||||||
|
|
||||||
private final ItemStack item;
|
private final ItemStack item;
|
||||||
private ItemMeta meta;
|
private ItemMeta meta;
|
||||||
private final Set<EnchantmentWrapper> enchantmentWrappers;
|
private final Set<EnchantmentWrapper> enchantmentWrappers;
|
||||||
|
@ -54,8 +53,8 @@ public class ItemBuilder {
|
||||||
public ItemBuilder(ConfigurationSection section, Player player, Placeholder... placeholders) {
|
public ItemBuilder(ConfigurationSection section, Player player, Placeholder... placeholders) {
|
||||||
this(section, placeholders);
|
this(section, placeholders);
|
||||||
|
|
||||||
if (XMaterial.PLAYER_HEAD.isSimilar(item)) {
|
if (XMaterial.PLAYER_HEAD.isSimilar(this.item)) {
|
||||||
((SkullMeta) item.getItemMeta()).setOwner(player.getName());
|
((SkullMeta) this.item.getItemMeta()).setOwner(player.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,11 +119,11 @@ public class ItemBuilder {
|
||||||
* Name:
|
* Name:
|
||||||
*/
|
*/
|
||||||
public boolean hasName() {
|
public boolean hasName() {
|
||||||
return meta.hasDisplayName();
|
return this.meta.hasDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder name(String name) {
|
public ItemBuilder name(String name) {
|
||||||
meta.setDisplayName(name);
|
this.meta.setDisplayName(name);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +131,7 @@ public class ItemBuilder {
|
||||||
* Lore:
|
* Lore:
|
||||||
*/
|
*/
|
||||||
public boolean hasLore() {
|
public boolean hasLore() {
|
||||||
return meta.hasLore();
|
return this.meta.hasLore();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder lore(String... lore) {
|
public ItemBuilder lore(String... lore) {
|
||||||
|
@ -140,37 +139,37 @@ public class ItemBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder lore(List<String> lore) {
|
public ItemBuilder lore(List<String> lore) {
|
||||||
meta.setLore(lore);
|
this.meta.setLore(lore);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder addLore(List<String> lore) {
|
public ItemBuilder addLore(List<String> lore) {
|
||||||
if (!meta.hasLore()) {
|
if (!this.meta.hasLore()) {
|
||||||
meta.setLore(lore);
|
this.meta.setLore(lore);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> toAdd = meta.getLore();
|
List<String> toAdd = this.meta.getLore();
|
||||||
toAdd.addAll(lore);
|
toAdd.addAll(lore);
|
||||||
meta.setLore(toAdd);
|
this.meta.setLore(toAdd);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder removeLore(String string) {
|
public ItemBuilder removeLore(String string) {
|
||||||
if (meta == null || !meta.hasLore()) {
|
if (this.meta == null || !this.meta.hasLore()) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
meta.setLore(meta.getLore().stream().filter(s -> !s.startsWith(string)).collect(Collectors.toList()));
|
this.meta.setLore(this.meta.getLore().stream().filter(s -> !s.startsWith(string)).collect(Collectors.toList()));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder removeLore(int index) {
|
public ItemBuilder removeLore(int index) {
|
||||||
if (!meta.hasLore()) {
|
if (!this.meta.hasLore()) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> lore = meta.getLore();
|
List<String> lore = this.meta.getLore();
|
||||||
|
|
||||||
if (index >= lore.size()) {
|
if (index >= lore.size()) {
|
||||||
return this;
|
return this;
|
||||||
|
@ -178,7 +177,7 @@ public class ItemBuilder {
|
||||||
|
|
||||||
lore.remove(index);
|
lore.remove(index);
|
||||||
|
|
||||||
meta.setLore(lore);
|
this.meta.setLore(lore);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,29 +189,29 @@ public class ItemBuilder {
|
||||||
* Enchantments:
|
* Enchantments:
|
||||||
*/
|
*/
|
||||||
public boolean hasEnchants() {
|
public boolean hasEnchants() {
|
||||||
return meta.hasEnchants();
|
return this.meta.hasEnchants();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasEnchant(Enchantment enchantment) {
|
public boolean hasEnchant(Enchantment enchantment) {
|
||||||
return meta.hasEnchant(enchantment);
|
return this.meta.hasEnchant(enchantment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasConflictingEnchant(Enchantment enchantment) {
|
public boolean hasConflictingEnchant(Enchantment enchantment) {
|
||||||
return meta.hasConflictingEnchant(enchantment);
|
return this.meta.hasConflictingEnchant(enchantment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder addEnchant(Enchantment enchantment, int level) {
|
public ItemBuilder addEnchant(Enchantment enchantment, int level) {
|
||||||
meta.addEnchant(enchantment, level, true);
|
this.meta.addEnchant(enchantment, level, true);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder removeEnchant(Enchantment enchantment) {
|
public ItemBuilder removeEnchant(Enchantment enchantment) {
|
||||||
meta.removeEnchant(enchantment);
|
this.meta.removeEnchant(enchantment);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder addEnchantWrapper(EnchantmentWrapper enchantmentWrapper) {
|
public ItemBuilder addEnchantWrapper(EnchantmentWrapper enchantmentWrapper) {
|
||||||
enchantmentWrappers.add(enchantmentWrapper);
|
this.enchantmentWrappers.add(enchantmentWrapper);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,21 +219,21 @@ public class ItemBuilder {
|
||||||
* Skulls:
|
* Skulls:
|
||||||
*/
|
*/
|
||||||
public boolean hasSkullOwner() {
|
public boolean hasSkullOwner() {
|
||||||
return ((SkullMeta) meta).hasOwner();
|
return ((SkullMeta) this.meta).hasOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSkullOwner() {
|
public String getSkullOwner() {
|
||||||
return ((SkullMeta) meta).getOwner();
|
return ((SkullMeta) this.meta).getOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder skullOwner(String owner) {
|
public ItemBuilder skullOwner(String owner) {
|
||||||
item.setDurability((short) 3);
|
this.item.setDurability((short) 3);
|
||||||
((SkullMeta) meta).setOwner(owner);
|
((SkullMeta) this.meta).setOwner(owner);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder durability(int durability) {
|
public ItemBuilder durability(int durability) {
|
||||||
item.setDurability((short) durability);
|
this.item.setDurability((short) durability);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,16 +241,16 @@ public class ItemBuilder {
|
||||||
* Flags:
|
* Flags:
|
||||||
*/
|
*/
|
||||||
public boolean hasFlag(ItemFlag flag) {
|
public boolean hasFlag(ItemFlag flag) {
|
||||||
return meta.hasItemFlag(flag);
|
return this.meta.hasItemFlag(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder addFlags(ItemFlag... flags) {
|
public ItemBuilder addFlags(ItemFlag... flags) {
|
||||||
meta.addItemFlags(flags);
|
this.meta.addItemFlags(flags);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder removeFlags(ItemFlag... flags) {
|
public ItemBuilder removeFlags(ItemFlag... flags) {
|
||||||
meta.removeItemFlags(flags);
|
this.meta.removeItemFlags(flags);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,30 +262,30 @@ public class ItemBuilder {
|
||||||
* Build the ItemStack.
|
* Build the ItemStack.
|
||||||
*/
|
*/
|
||||||
public ItemStack build() {
|
public ItemStack build() {
|
||||||
item.setItemMeta(meta);
|
this.item.setItemMeta(this.meta);
|
||||||
return item;
|
return this.item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack buildWithWrappers(int level, Player user, LivingEntity opponent) {
|
public ItemStack buildWithWrappers(int level, Player user, LivingEntity opponent) {
|
||||||
item.setItemMeta(meta);
|
this.item.setItemMeta(this.meta);
|
||||||
enchantmentWrappers.forEach(enchant -> item.addUnsafeEnchantment(enchant.getEnchantment(), enchant.getAmplifier(level, user, opponent)));
|
this.enchantmentWrappers.forEach(enchant -> this.item.addUnsafeEnchantment(enchant.getEnchantment(), enchant.getAmplifier(level, user, opponent)));
|
||||||
return item;
|
return this.item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Enchantment, Integer> getEnchants() {
|
public Map<Enchantment, Integer> getEnchants() {
|
||||||
return meta.getEnchants();
|
return this.meta.getEnchants();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<ItemFlag> getFlags() {
|
public Set<ItemFlag> getFlags() {
|
||||||
return meta.getItemFlags();
|
return this.meta.getItemFlags();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getLore() {
|
public List<String> getLore() {
|
||||||
return meta.getLore();
|
return this.meta.getLore();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemMeta getMeta() {
|
public ItemMeta getMeta() {
|
||||||
return meta;
|
return this.meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -294,6 +293,6 @@ public class ItemBuilder {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return meta.getDisplayName();
|
return this.meta.getDisplayName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,25 +8,24 @@ import com.songoda.epicenchants.EpicEnchants;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Settings {
|
public class Settings {
|
||||||
|
static final Config CONFIG = EpicEnchants.getPlugin(EpicEnchants.class).getCoreConfig();
|
||||||
|
|
||||||
static final Config config = EpicEnchants.getInstance().getCoreConfig();
|
public static final ConfigSetting ROMAN = new ConfigSetting(CONFIG, "Main.Roman Numerals", true);
|
||||||
|
|
||||||
public static final ConfigSetting ROMAN = new ConfigSetting(config, "Main.Roman Numerals", true);
|
public static final ConfigSetting BLACK_MIN = new ConfigSetting(CONFIG, "Main.Black Scroll Min", 20);
|
||||||
|
public static final ConfigSetting BLACK_MAX = new ConfigSetting(CONFIG, "Main.Black Scroll Max", 100);
|
||||||
|
|
||||||
public static final ConfigSetting BLACK_MIN = new ConfigSetting(config, "Main.Black Scroll Min", 20);
|
public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(CONFIG, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(),
|
||||||
public static final ConfigSetting BLACK_MAX = new ConfigSetting(config, "Main.Black Scroll Max", 100);
|
|
||||||
|
|
||||||
public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(config, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(),
|
|
||||||
"Which economy plugin should be used?",
|
"Which economy plugin should be used?",
|
||||||
"Supported plugins you have installed: \"" + EconomyManager.getManager().getRegisteredPlugins().stream().collect(Collectors.joining("\", \"")) + "\".");
|
"Supported plugins you have installed: \"" + EconomyManager.getManager().getRegisteredPlugins().stream().collect(Collectors.joining("\", \"")) + "\".");
|
||||||
|
|
||||||
public static final ConfigSetting GLASS_TYPE_1 = new ConfigSetting(config, "Interfaces.Glass Type 1", 7);
|
public static final ConfigSetting GLASS_TYPE_1 = new ConfigSetting(CONFIG, "Interfaces.Glass Type 1", 7);
|
||||||
public static final ConfigSetting GLASS_TYPE_2 = new ConfigSetting(config, "Interfaces.Glass Type 2", 11);
|
public static final ConfigSetting GLASS_TYPE_2 = new ConfigSetting(CONFIG, "Interfaces.Glass Type 2", 11);
|
||||||
public static final ConfigSetting GLASS_TYPE_3 = new ConfigSetting(config, "Interfaces.Glass Type 3", 3);
|
public static final ConfigSetting GLASS_TYPE_3 = new ConfigSetting(CONFIG, "Interfaces.Glass Type 3", 3);
|
||||||
|
|
||||||
public static final ConfigSetting FIRST_LOAD = new ConfigSetting(config, "System.First Load", true);
|
public static final ConfigSetting FIRST_LOAD = new ConfigSetting(CONFIG, "System.First Load", true);
|
||||||
|
|
||||||
public static final ConfigSetting LANGUGE_MODE = new ConfigSetting(config, "System.Language Mode", "en_US",
|
public static final ConfigSetting LANGUGE_MODE = new ConfigSetting(CONFIG, "System.Language Mode", "en_US",
|
||||||
"The enabled language file.",
|
"The enabled language file.",
|
||||||
"More language files (if available) can be found in the plugins data folder.");
|
"More language files (if available) can be found in the plugins data folder.");
|
||||||
|
|
||||||
|
@ -35,18 +34,18 @@ public class Settings {
|
||||||
* called after EconomyManager load
|
* called after EconomyManager load
|
||||||
*/
|
*/
|
||||||
public static void setupConfig() {
|
public static void setupConfig() {
|
||||||
config.load();
|
CONFIG.load();
|
||||||
config.setAutoremove(true).setAutosave(true);
|
CONFIG.setAutoremove(true).setAutosave(true);
|
||||||
|
|
||||||
// convert economy settings
|
// convert economy settings
|
||||||
if (config.getBoolean("Economy.Use Vault Economy") && EconomyManager.getManager().isEnabled("Vault")) {
|
if (CONFIG.getBoolean("Economy.Use Vault Economy") && EconomyManager.getManager().isEnabled("Vault")) {
|
||||||
config.set("Main.Economy", "Vault");
|
CONFIG.set("Main.Economy", "Vault");
|
||||||
} else if (config.getBoolean("Economy.Use Reserve Economy") && EconomyManager.getManager().isEnabled("Reserve")) {
|
} else if (CONFIG.getBoolean("Economy.Use Reserve Economy") && EconomyManager.getManager().isEnabled("Reserve")) {
|
||||||
config.set("Main.Economy", "Reserve");
|
CONFIG.set("Main.Economy", "Reserve");
|
||||||
} else if (config.getBoolean("Economy.Use Player Points Economy") && EconomyManager.getManager().isEnabled("PlayerPoints")) {
|
} else if (CONFIG.getBoolean("Economy.Use Player Points Economy") && EconomyManager.getManager().isEnabled("PlayerPoints")) {
|
||||||
config.set("Main.Economy", "PlayerPoints");
|
CONFIG.set("Main.Economy", "PlayerPoints");
|
||||||
}
|
}
|
||||||
|
|
||||||
config.saveChanges();
|
CONFIG.saveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.util.stream.Collectors;
|
||||||
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
|
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
|
||||||
|
|
||||||
public class ConfigParser {
|
public class ConfigParser {
|
||||||
public static Enchant parseEnchant(EpicEnchants instance, FileConfiguration config) throws Exception {
|
public static Enchant parseEnchant(EpicEnchants instance, FileConfiguration config) {
|
||||||
return Enchant.builder()
|
return Enchant.builder()
|
||||||
.author("author")
|
.author("author")
|
||||||
.identifier(config.getString("identifier"))
|
.identifier(config.getString("identifier"))
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
package com.songoda.epicenchants.utils.single;
|
package com.songoda.epicenchants.utils.single;
|
||||||
|
|
||||||
|
import com.craftaro.core.compatibility.CompatibleMaterial;
|
||||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||||
import com.google.common.collect.HashMultimap;
|
import com.google.common.collect.HashMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -15,36 +17,35 @@ import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial.*;
|
import static com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial.*;
|
||||||
import static com.songoda.epicenchants.utils.single.ItemGroup.Group.*;
|
|
||||||
|
|
||||||
public class ItemGroup {
|
public class ItemGroup {
|
||||||
|
|
||||||
private final Multimap<Group, XMaterial> groupMap;
|
private final Multimap<Group, XMaterial> groupMap;
|
||||||
|
|
||||||
public ItemGroup() {
|
public ItemGroup() {
|
||||||
groupMap = HashMultimap.create();
|
this.groupMap = HashMultimap.create();
|
||||||
|
|
||||||
groupMap.putAll(AXES, Arrays.asList(NETHERITE_AXE, DIAMOND_AXE, GOLDEN_AXE, IRON_AXE, STONE_AXE, WOODEN_AXE));
|
this.groupMap.putAll(ItemGroup.Group.AXES, Arrays.asList(NETHERITE_AXE, DIAMOND_AXE, GOLDEN_AXE, IRON_AXE, STONE_AXE, WOODEN_AXE));
|
||||||
|
|
||||||
groupMap.putAll(PICKAXES, Arrays.asList(NETHERITE_PICKAXE, DIAMOND_PICKAXE, GOLDEN_PICKAXE, IRON_PICKAXE, STONE_PICKAXE, WOODEN_PICKAXE));
|
this.groupMap.putAll(ItemGroup.Group.PICKAXES, Arrays.asList(NETHERITE_PICKAXE, DIAMOND_PICKAXE, GOLDEN_PICKAXE, IRON_PICKAXE, STONE_PICKAXE, WOODEN_PICKAXE));
|
||||||
|
|
||||||
groupMap.putAll(HOES, Arrays.asList(NETHERITE_HOE, DIAMOND_HOE, GOLDEN_HOE, IRON_HOE, STONE_HOE, WOODEN_HOE));
|
this.groupMap.putAll(ItemGroup.Group.HOES, Arrays.asList(NETHERITE_HOE, DIAMOND_HOE, GOLDEN_HOE, IRON_HOE, STONE_HOE, WOODEN_HOE));
|
||||||
|
|
||||||
groupMap.putAll(SHOVELS, Arrays.asList(NETHERITE_SHOVEL, DIAMOND_SHOVEL, GOLDEN_SHOVEL, IRON_SHOVEL, STONE_SHOVEL, WOODEN_SHOVEL));
|
this.groupMap.putAll(ItemGroup.Group.SHOVELS, Arrays.asList(NETHERITE_SHOVEL, DIAMOND_SHOVEL, GOLDEN_SHOVEL, IRON_SHOVEL, STONE_SHOVEL, WOODEN_SHOVEL));
|
||||||
|
|
||||||
groupMap.putAll(SWORDS, Arrays.asList(NETHERITE_SWORD, DIAMOND_SWORD, GOLDEN_SWORD, IRON_SWORD, STONE_SWORD, WOODEN_SWORD));
|
this.groupMap.putAll(ItemGroup.Group.SWORDS, Arrays.asList(NETHERITE_SWORD, DIAMOND_SWORD, GOLDEN_SWORD, IRON_SWORD, STONE_SWORD, WOODEN_SWORD));
|
||||||
|
|
||||||
groupMap.put(BOWS, BOW);
|
this.groupMap.put(ItemGroup.Group.BOWS, BOW);
|
||||||
|
|
||||||
groupMap.putAll(BOOTS, Arrays.asList(NETHERITE_BOOTS, DIAMOND_BOOTS, GOLDEN_BOOTS, IRON_BOOTS, LEATHER_BOOTS));
|
this.groupMap.putAll(ItemGroup.Group.BOOTS, Arrays.asList(NETHERITE_BOOTS, DIAMOND_BOOTS, GOLDEN_BOOTS, IRON_BOOTS, LEATHER_BOOTS));
|
||||||
|
|
||||||
groupMap.putAll(LEGGINGS, Arrays.asList(NETHERITE_LEGGINGS, DIAMOND_LEGGINGS, GOLDEN_LEGGINGS, IRON_LEGGINGS, LEATHER_LEGGINGS));
|
this.groupMap.putAll(ItemGroup.Group.LEGGINGS, Arrays.asList(NETHERITE_LEGGINGS, DIAMOND_LEGGINGS, GOLDEN_LEGGINGS, IRON_LEGGINGS, LEATHER_LEGGINGS));
|
||||||
|
|
||||||
groupMap.putAll(CHESTPLATES, Arrays.asList(NETHERITE_CHESTPLATE, DIAMOND_CHESTPLATE, GOLDEN_CHESTPLATE, IRON_CHESTPLATE, LEATHER_CHESTPLATE));
|
this.groupMap.putAll(ItemGroup.Group.CHESTPLATES, Arrays.asList(NETHERITE_CHESTPLATE, DIAMOND_CHESTPLATE, GOLDEN_CHESTPLATE, IRON_CHESTPLATE, LEATHER_CHESTPLATE));
|
||||||
|
|
||||||
groupMap.putAll(HELMETS, Arrays.asList(NETHERITE_HELMET, DIAMOND_HELMET, GOLDEN_HELMET, IRON_HELMET, LEATHER_HELMET));
|
this.groupMap.putAll(ItemGroup.Group.HELMETS, Arrays.asList(NETHERITE_HELMET, DIAMOND_HELMET, GOLDEN_HELMET, IRON_HELMET, LEATHER_HELMET));
|
||||||
|
|
||||||
groupMap.put(TRIDENTS, TRIDENT);
|
this.groupMap.put(ItemGroup.Group.TRIDENTS, TRIDENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<XMaterial> get(String key) {
|
public Set<XMaterial> get(String key) {
|
||||||
|
@ -60,9 +61,11 @@ public class ItemGroup {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValid(XMaterial material) {
|
public boolean isValid(XMaterial material) {
|
||||||
for (Group group : groupMap.keys())
|
for (Group group : this.groupMap.keys()) {
|
||||||
if (getMaterials(group).contains(material))
|
if (getMaterials(group).contains(material)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +75,7 @@ public class ItemGroup {
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
getGroup(materials).ifPresent(group -> {
|
getGroup(materials).ifPresent(group -> {
|
||||||
groups.add(group.getName());
|
groups.add(group.getName());
|
||||||
materials.removeAll(getMaterials(group).stream().collect(Collectors.toList()));
|
new ArrayList<>(getMaterials(group)).forEach(materials::remove);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,25 +84,29 @@ public class ItemGroup {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Group> getGroup(Set<XMaterial> materials) {
|
public Optional<Group> getGroup(Set<XMaterial> materials) {
|
||||||
Optional<Group> group = Arrays.stream(Group.values())
|
for (Group group : Group.values()) {
|
||||||
.filter(s -> !s.getChildren().isEmpty() && s.getChildren().stream().allMatch(child -> materials.containsAll(groupMap.get(child))))
|
if (!group.getChildren().isEmpty() && group.getChildren().stream().allMatch(child -> materials.containsAll(this.groupMap.get(child)))) {
|
||||||
.findFirst();
|
return Optional.of(group);
|
||||||
|
}
|
||||||
if (group.isPresent()) {
|
|
||||||
return group;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return groupMap.asMap().entrySet().stream().filter(s -> materials.containsAll(s.getValue())).map(Map.Entry::getKey).findFirst();
|
for (Map.Entry<Group, Collection<XMaterial>> entry : this.groupMap.asMap().entrySet()) {
|
||||||
|
if (materials.containsAll(entry.getValue())) {
|
||||||
|
return Optional.of(entry.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<XMaterial> getMaterials(Group group) {
|
public Set<XMaterial> getMaterials(Group group) {
|
||||||
Set<XMaterial> out = new HashSet<>();
|
Set<XMaterial> out = new HashSet<>();
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
if (group.getChildren().isEmpty())
|
if (group.getChildren().isEmpty()) {
|
||||||
out.addAll(groupMap.get(group));
|
out.addAll(this.groupMap.get(group));
|
||||||
else
|
} else {
|
||||||
out.addAll(group.getChildren().stream().map(this::getMaterials).flatMap(Collection::stream).collect(Collectors.toSet()));
|
out.addAll(group.getChildren().stream().map(this::getMaterials).flatMap(Collection::stream).collect(Collectors.toSet()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
@ -126,11 +133,16 @@ public class ItemGroup {
|
||||||
private final Set<Group> children;
|
private final Set<Group> children;
|
||||||
|
|
||||||
Group(Group... child) {
|
Group(Group... child) {
|
||||||
children = child == null ? new HashSet<>() : new HashSet<>(Arrays.asList(child));
|
this.children = child == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(child));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<Group> from(String key) {
|
public static Optional<Group> from(String key) {
|
||||||
return Arrays.stream(values()).filter(s -> s.toString().equalsIgnoreCase(key)).findFirst();
|
for (Group group : values()) {
|
||||||
|
if (group.toString().equalsIgnoreCase(key)) {
|
||||||
|
return Optional.of(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
|
@ -30,7 +30,6 @@ import java.util.stream.Collectors;
|
||||||
import static com.songoda.epicenchants.utils.single.GeneralUtils.getHeldItem;
|
import static com.songoda.epicenchants.utils.single.GeneralUtils.getHeldItem;
|
||||||
|
|
||||||
public class Placeholders {
|
public class Placeholders {
|
||||||
|
|
||||||
private static final Map<String, Function<Event, String>> EVENT_FUNCTIONS = new HashMap<String, Function<Event, String>>() {{
|
private static final Map<String, Function<Event, String>> EVENT_FUNCTIONS = new HashMap<String, Function<Event, String>>() {{
|
||||||
put("{block_type}", event -> {
|
put("{block_type}", event -> {
|
||||||
if (event instanceof BlockBreakEvent) {
|
if (event instanceof BlockBreakEvent) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.songoda.epicenchants.utils.single;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class RomanNumber {
|
public class RomanNumber {
|
||||||
private final static TreeMap<Integer, String> TREE_MAP = new TreeMap<Integer, String>() {{
|
private static final TreeMap<Integer, String> TREE_MAP = new TreeMap<Integer, String>() {{
|
||||||
put(1000, "M");
|
put(1000, "M");
|
||||||
put(900, "CM");
|
put(900, "CM");
|
||||||
put(500, "D");
|
put(500, "D");
|
||||||
|
|
|
@ -8,8 +8,8 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class EnchantmentWrapper {
|
public class EnchantmentWrapper {
|
||||||
private LeveledModifier amplifier;
|
private final LeveledModifier amplifier;
|
||||||
private Enchantment enchantment;
|
private final Enchantment enchantment;
|
||||||
|
|
||||||
EnchantmentWrapper(LeveledModifier amplifier, Enchantment enchantment) {
|
EnchantmentWrapper(LeveledModifier amplifier, Enchantment enchantment) {
|
||||||
this.amplifier = amplifier;
|
this.amplifier = amplifier;
|
||||||
|
@ -21,11 +21,11 @@ public class EnchantmentWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAmplifier(int level, @NotNull Player user, @Nullable LivingEntity opponent) {
|
public int getAmplifier(int level, @NotNull Player user, @Nullable LivingEntity opponent) {
|
||||||
return (int) amplifier.get(level, 0, user, opponent);
|
return (int) this.amplifier.get(level, 0, user, opponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Enchantment getEnchantment() {
|
public Enchantment getEnchantment() {
|
||||||
return enchantment;
|
return this.enchantment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EnchantmentWrapperBuilder {
|
public static class EnchantmentWrapperBuilder {
|
||||||
|
@ -46,7 +46,7 @@ public class EnchantmentWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnchantmentWrapper build() {
|
public EnchantmentWrapper build() {
|
||||||
return new EnchantmentWrapper(amplifier, enchantment);
|
return new EnchantmentWrapper(this.amplifier, this.enchantment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# each item that's not specified in limits category will use default value
|
# each item that's not specified in the 'limits' category will use default value
|
||||||
default: 5
|
default: 5
|
||||||
|
|
||||||
# Example of some of the items
|
# Example of some of the items
|
||||||
|
@ -6,4 +6,3 @@ limits:
|
||||||
DIAMOND_SWORD: 5
|
DIAMOND_SWORD: 5
|
||||||
IRON_SWORD: 2
|
IRON_SWORD: 2
|
||||||
STONE_SWORD: 1
|
STONE_SWORD: 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue