diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcodebug.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcodebug.java index 1ba2d703..10f4f9db 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcodebug.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcodebug.java @@ -31,82 +31,82 @@ public class CommandEcodebug extends AbstractCommand { @Override public void onExecute(CommandSender sender, List args) { - this.plugin.getLog().info("--------------- BEGIN DEBUG ----------------"); + this.getPlugin().getLog().info("--------------- BEGIN DEBUG ----------------"); if (sender instanceof Player) { Player player = (Player) sender; player.sendMessage("Held Item: " + player.getInventory().getItemInMainHand().toString()); - this.plugin.getLog().info(""); + this.getPlugin().getLog().info(""); - this.plugin.getLog().info("Held Item: " + player.getInventory().getItemInMainHand().toString()); - this.plugin.getLog().info(""); + this.getPlugin().getLog().info("Held Item: " + player.getInventory().getItemInMainHand().toString()); + this.getPlugin().getLog().info(""); } - this.plugin.getLog().info("Running Version: " + this.plugin.getDescription().getVersion()); - this.plugin.getLog().info(""); + this.getPlugin().getLog().info("Running Version: " + this.getPlugin().getDescription().getVersion()); + this.getPlugin().getLog().info(""); - this.plugin.getLog().info("Loaded Extensions: " + this.plugin.getExtensionLoader().getLoadedExtensions().stream().map(extension -> extension.getName() + " v" + extension.getVersion()).collect(Collectors.joining())); - this.plugin.getLog().info(""); + this.getPlugin().getLog().info("Loaded Extensions: " + this.getPlugin().getExtensionLoader().getLoadedExtensions().stream().map(extension -> extension.getName() + " v" + extension.getVersion()).collect(Collectors.joining())); + this.getPlugin().getLog().info(""); - this.plugin.getLog().info("EcoEnchants.getAll(): " + EcoEnchants.values().toString()); - this.plugin.getLog().info(""); + this.getPlugin().getLog().info("EcoEnchants.getAll(): " + EcoEnchants.values().toString()); + this.getPlugin().getLog().info(""); - this.plugin.getLog().info("Enchantment.values(): " + Arrays.toString(Enchantment.values())); - this.plugin.getLog().info(""); + this.getPlugin().getLog().info("Enchantment.values(): " + Arrays.toString(Enchantment.values())); + this.getPlugin().getLog().info(""); - this.plugin.getLog().info("Enchantment Cache: " + EnchantmentCache.getCache().toString()); - this.plugin.getLog().info(""); + this.getPlugin().getLog().info("Enchantment Cache: " + EnchantmentCache.getCache().toString()); + this.getPlugin().getLog().info(""); try { Field byNameField = Enchantment.class.getDeclaredField("byName"); byNameField.setAccessible(true); Map byName = (Map) byNameField.get(null); - this.plugin.getLog().info("Enchantment.byName: " + byName.toString()); + this.getPlugin().getLog().info("Enchantment.byName: " + byName.toString()); } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } - this.plugin.getLog().info(""); + this.getPlugin().getLog().info(""); List extern = Arrays.stream(Enchantment.values()).collect(Collectors.toList()); extern.removeAll(EcoEnchants.values().stream().map(EcoEnchant::getEnchantment).collect(Collectors.toList())); - this.plugin.getLog().info("External/Vanilla Enchantments: " + extern.toString()); - this.plugin.getLog().info(""); + this.getPlugin().getLog().info("External/Vanilla Enchantments: " + extern.toString()); + this.getPlugin().getLog().info(""); List uncached = Arrays.stream(Enchantment.values()).collect(Collectors.toList()); uncached.removeAll(EnchantmentCache.getCache().stream().map(EnchantmentCache.CacheEntry::getEnchantment).collect(Collectors.toList())); - this.plugin.getLog().info("Uncached Enchantments: " + uncached.toString()); - this.plugin.getLog().info(""); + this.getPlugin().getLog().info("Uncached Enchantments: " + uncached.toString()); + this.getPlugin().getLog().info(""); List brokenCache = Arrays.stream(Enchantment.values()).collect(Collectors.toList()); brokenCache.removeIf(enchantment -> !( EnchantmentCache.getEntry(enchantment).getName().equalsIgnoreCase("null") || EnchantmentCache.getEntry(enchantment).getRawName().equalsIgnoreCase("null") || EnchantmentCache.getEntry(enchantment).getStringDescription().equalsIgnoreCase("null"))); - this.plugin.getLog().info("Enchantments with broken cache: " + brokenCache.toString()); - this.plugin.getLog().info(""); + this.getPlugin().getLog().info("Enchantments with broken cache: " + brokenCache.toString()); + this.getPlugin().getLog().info(""); - this.plugin.getLog().info("Installed Plugins: " + Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toList()).toString()); - this.plugin.getLog().info(""); + this.getPlugin().getLog().info("Installed Plugins: " + Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toList()).toString()); + this.getPlugin().getLog().info(""); Set withIssues = new HashSet<>(); EcoEnchants.values().forEach(enchant -> { if (enchant.getRarity() == null) withIssues.add(enchant); if (enchant.getRawTargets().isEmpty()) withIssues.add(enchant); }); - this.plugin.getLog().info("Enchantments with evident issues: " + withIssues.toString()); - this.plugin.getLog().info(""); + this.getPlugin().getLog().info("Enchantments with evident issues: " + withIssues.toString()); + this.getPlugin().getLog().info(""); - this.plugin.getLog().info("Drop Type: " + DropManager.getType()); - this.plugin.getLog().info(""); + this.getPlugin().getLog().info("Drop Type: " + DropManager.getType()); + this.getPlugin().getLog().info(""); - this.plugin.getLog().info("Packets: " + ProtocolLibrary.getProtocolManager().getPacketListeners().stream().filter(packetListener -> packetListener.getSendingWhitelist().getPriority().equals(ListenerPriority.MONITOR)).collect(Collectors.toList()).toString()); - this.plugin.getLog().info(""); + this.getPlugin().getLog().info("Packets: " + ProtocolLibrary.getProtocolManager().getPacketListeners().stream().filter(packetListener -> packetListener.getSendingWhitelist().getPriority().equals(ListenerPriority.MONITOR)).collect(Collectors.toList()).toString()); + this.getPlugin().getLog().info(""); - this.plugin.getLog().info("Server Information: "); - this.plugin.getLog().info("Players Online: " + Bukkit.getServer().getOnlinePlayers().size()); - this.plugin.getLog().info("Bukkit IP: " + Bukkit.getIp()); - this.plugin.getLog().info("Running Version: " + Bukkit.getVersion() + ", Bukkit Version: " + Bukkit.getBukkitVersion() + ", Alt Version: " + Bukkit.getServer().getVersion() + ", NMS: " + ProxyConstants.NMS_VERSION); - this.plugin.getLog().info("Motd: " + Bukkit.getServer().getMotd()); - this.plugin.getLog().info("--------------- END DEBUG ----------------"); + this.getPlugin().getLog().info("Server Information: "); + this.getPlugin().getLog().info("Players Online: " + Bukkit.getServer().getOnlinePlayers().size()); + this.getPlugin().getLog().info("Bukkit IP: " + Bukkit.getIp()); + this.getPlugin().getLog().info("Running Version: " + Bukkit.getVersion() + ", Bukkit Version: " + Bukkit.getBukkitVersion() + ", Alt Version: " + Bukkit.getServer().getVersion() + ", NMS: " + ProxyConstants.NMS_VERSION); + this.getPlugin().getLog().info("Motd: " + Bukkit.getServer().getMotd()); + this.getPlugin().getLog().info("--------------- END DEBUG ----------------"); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcoreload.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcoreload.java index e7a2d638..83fe5756 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcoreload.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcoreload.java @@ -14,7 +14,7 @@ public class CommandEcoreload extends AbstractCommand { @Override public void onExecute(CommandSender sender, List args) { - this.plugin.reload(); + this.getPlugin().reload(); sender.sendMessage(Configs.LANG.getMessage("reloaded")); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java index 08fd10b5..259a44b7 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java @@ -26,7 +26,7 @@ public class CommandEnchantinfo extends AbstractCommand { @Override public AbstractTabCompleter getTab() { - return new TabCompleterEnchantinfo(this.plugin); + return new TabCompleterEnchantinfo(this.getPlugin()); } @Override diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EnchantmentYamlConfig.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EnchantmentYamlConfig.java index 6e8c243b..fadff59f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EnchantmentYamlConfig.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/EnchantmentYamlConfig.java @@ -39,7 +39,7 @@ public abstract class EnchantmentYamlConfig extends PluginDependent { this.source = source; this.type = type; - File basedir = new File(this.plugin.getDataFolder(), "enchants/"); + File basedir = new File(this.getPlugin().getDataFolder(), "enchants/"); if (!basedir.exists()) basedir.mkdirs(); File dir = new File(basedir, type.getName() + "/"); @@ -67,9 +67,9 @@ public abstract class EnchantmentYamlConfig extends PluginDependent { InputStream in = source.getResourceAsStream(resourcePath); - File outFile = new File(this.plugin.getDataFolder(), resourcePath); + File outFile = new File(this.getPlugin().getDataFolder(), resourcePath); int lastIndex = resourcePath.lastIndexOf('/'); - File outDir = new File(this.plugin.getDataFolder(), resourcePath.substring(0, Math.max(lastIndex, 0))); + File outDir = new File(this.getPlugin().getDataFolder(), resourcePath.substring(0, Math.max(lastIndex, 0))); if (!outDir.exists()) { outDir.mkdirs(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java index 8c82c011..28ca796e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java @@ -23,6 +23,7 @@ import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Field; @@ -38,7 +39,7 @@ import java.util.stream.Collectors; @SuppressWarnings({"unchecked", "deprecation"}) public abstract class EcoEnchant extends Enchantment implements Listener, Registerable, Watcher { - protected final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance(); + private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance(); private String name; private String description; @@ -136,6 +137,11 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist // Unused as some enchantments may have postUpdate tasks, however most won't. } + @ApiStatus.Internal + protected AbstractEcoPlugin getPlugin() { + return this.plugin; + } + /** * Register the enchantment with spigot * Only used internally diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/CallingCurse.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/CallingCurse.java index 832f2958..3afdbc8e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/CallingCurse.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/CallingCurse.java @@ -44,7 +44,7 @@ public class CallingCurse extends EcoEnchant implements EcoRunnable { private void refresh() { players.clear(); - this.plugin.getServer().getOnlinePlayers().forEach(player -> { + this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { int level = EnchantChecks.getArmorPoints(player, this, 0); if (level > 0) { players.put(player, level); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/DecayCurse.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/DecayCurse.java index 2382e474..c0d020dd 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/DecayCurse.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/DecayCurse.java @@ -63,7 +63,7 @@ public class DecayCurse extends EcoEnchant implements EcoRunnable { private void refresh() { players.clear(); - this.plugin.getServer().getOnlinePlayers().forEach(player -> { + this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { if (Arrays.stream(player.getInventory().getContents()).parallel().anyMatch(item -> EnchantChecks.item(item, this))) players.add(player); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Aerial.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Aerial.java index 536a317d..c72a653e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Aerial.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Aerial.java @@ -25,7 +25,7 @@ public class Aerial extends EcoEnchant { if (shooter.isOnGround()) return; - event.getProjectile().setMetadata("shot-in-air", new FixedMetadataValue(this.plugin, true)); + event.getProjectile().setMetadata("shot-in-air", new FixedMetadataValue(this.getPlugin(), true)); } @Override diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Atmospheric.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Atmospheric.java index 3bca7bde..e881010d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Atmospheric.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Atmospheric.java @@ -22,7 +22,7 @@ public class Atmospheric extends EcoEnchant { public void onTridentLaunch(LivingEntity shooter, Trident trident, int level, ProjectileLaunchEvent event) { if(shooter.isOnGround()) return; - trident.setMetadata("shot-in-air", new FixedMetadataValue(this.plugin, true)); + trident.setMetadata("shot-in-air", new FixedMetadataValue(this.getPlugin(), true)); } @Override diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlastMining.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlastMining.java index a9e2a6dd..01b53eb5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlastMining.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlastMining.java @@ -63,9 +63,9 @@ public class BlastMining extends EcoEnchant { } toBreak.forEach((block1 -> { - block1.setMetadata("block-ignore", new FixedMetadataValue(this.plugin, true)); + block1.setMetadata("block-ignore", new FixedMetadataValue(this.getPlugin(), true)); ProxyUtils.getProxy(BlockBreakProxy.class).breakBlock(player, block1); - block1.removeMetadata("block-ignore", this.plugin); + block1.removeMetadata("block-ignore", this.getPlugin()); })); AnticheatManager.unexemptPlayer(player); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Bleed.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Bleed.java index ac3f2f20..79b169ba 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Bleed.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Bleed.java @@ -9,7 +9,6 @@ import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.scheduler.BukkitRunnable; import java.util.concurrent.atomic.AtomicInteger; @@ -39,15 +38,12 @@ public class Bleed extends EcoEnchant { AtomicInteger currentBleedCount = new AtomicInteger(0); - new BukkitRunnable() { - @Override - public void run() { - currentBleedCount.addAndGet(1); + this.getPlugin().getRunnableFactory().create(bukkitRunnable -> { + currentBleedCount.addAndGet(1); - victim.damage(bleedDamage); + victim.damage(bleedDamage); - if (currentBleedCount.get() >= finalBleedCount) this.cancel(); - } - }.runTaskTimer(this.plugin, 0, 10); + if (currentBleedCount.get() >= finalBleedCount) bukkitRunnable.cancel(); + }).runTaskTimer(0, 10); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Cleave.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Cleave.java index 146d72e6..8b874941 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Cleave.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Cleave.java @@ -38,9 +38,9 @@ public class Cleave extends EcoEnchant { .filter(entity -> entity instanceof LivingEntity) .filter(entity -> !entity.equals(attacker)) .forEach(entity -> { - entity.setMetadata("cleaved", new FixedMetadataValue(this.plugin, true)); + entity.setMetadata("cleaved", new FixedMetadataValue(this.getPlugin(), true)); ((LivingEntity) entity).damage(damage, attacker); - this.plugin.getScheduler().runLater(() -> entity.removeMetadata("cleaved", this.plugin), 5); + this.getPlugin().getScheduler().runLater(() -> entity.removeMetadata("cleaved", this.getPlugin()), 5); }); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Disappear.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Disappear.java index 3d6857b7..03b4d500 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Disappear.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Disappear.java @@ -19,7 +19,7 @@ public class Disappear extends EcoEnchant { @Override public void onDamageWearingArmor(LivingEntity victim, int level, EntityDamageEvent event) { - this.plugin.getScheduler().runLater(() -> { + this.getPlugin().getScheduler().runLater(() -> { if(victim.getHealth() > EcoEnchants.DISAPPEAR.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "threshold")) return; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Drill.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Drill.java index 81149149..c41c8cc6 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Drill.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Drill.java @@ -37,7 +37,7 @@ public class Drill extends EcoEnchant { for (int i = 1; i <= blocks; i++) { Vector simplified = VectorUtils.simplifyVector(player.getLocation().getDirection().normalize()).multiply(i); Block block1 = block.getWorld().getBlockAt(block.getLocation().clone().add(simplified)); - block1.setMetadata("block-ignore", new FixedMetadataValue(this.plugin, true)); + block1.setMetadata("block-ignore", new FixedMetadataValue(this.getPlugin(), true)); if (this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blacklisted-blocks").contains(block1.getType().name().toLowerCase())) { continue; @@ -49,7 +49,7 @@ public class Drill extends EcoEnchant { if (!AntigriefManager.canBreakBlock(player, block1)) continue; ProxyUtils.getProxy(BlockBreakProxy.class).breakBlock(player, block1); - block1.removeMetadata("block-ignore", this.plugin); + block1.removeMetadata("block-ignore", this.getPlugin()); } AnticheatManager.unexemptPlayer(player); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Forcefield.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Forcefield.java index e2740400..8b835975 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Forcefield.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Forcefield.java @@ -42,7 +42,7 @@ public class Forcefield extends EcoEnchant implements EcoRunnable { private void refresh() { players.clear(); - this.plugin.getServer().getOnlinePlayers().forEach(player -> { + this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { int level = EnchantChecks.getArmorPoints(player, this, 0); if(level > 0) { players.put(player, level); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Frozen.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Frozen.java index 159d21b7..2fd5de07 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Frozen.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Frozen.java @@ -46,7 +46,7 @@ public class Frozen extends EcoEnchant { int divisor = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "points-per-level"); final int level = (int) Math.ceil((double) points / divisor); - this.plugin.getScheduler().runLater(() -> { + this.getPlugin().getScheduler().runLater(() -> { victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, points * 5, level)); victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, points * 5, level)); }, 1); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Incandescence.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Incandescence.java index 5aa429be..e61dc935 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Incandescence.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Incandescence.java @@ -35,7 +35,7 @@ public class Incandescence extends EcoEnchant { return; if(this.getDisabledWorlds().contains(player.getWorld())) return; - this.plugin.getScheduler().runLater(() -> { + this.getPlugin().getScheduler().runLater(() -> { victim.setFireTicks(totalIncandescencePoints * this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-point") + this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "initial-ticks")); }, 1); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Launch.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Launch.java index bee6c902..6827ff53 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Launch.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Launch.java @@ -41,6 +41,6 @@ public class Launch extends EcoEnchant { double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier"); double boost = 1 + (multiplier * level); - this.plugin.getScheduler().run(() -> player.setVelocity(player.getVelocity().multiply(boost))); + this.getPlugin().getScheduler().run(() -> player.setVelocity(player.getVelocity().multiply(boost))); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lesion.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lesion.java index 34c5f3a4..79c8b376 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lesion.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lesion.java @@ -7,7 +7,6 @@ import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Trident; import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.scheduler.BukkitRunnable; import java.util.concurrent.atomic.AtomicInteger; @@ -34,15 +33,12 @@ public class Lesion extends EcoEnchant { AtomicInteger currentBleedCount = new AtomicInteger(0); - new BukkitRunnable() { - @Override - public void run() { - currentBleedCount.addAndGet(1); + this.getPlugin().getRunnableFactory().create(bukkitRunnable -> { + currentBleedCount.addAndGet(1); - victim.damage(bleedDamage); + victim.damage(bleedDamage); - if(currentBleedCount.get() >= finalBleedCount) this.cancel(); - } - }.runTaskTimer(this.plugin, 0, 10); + if(currentBleedCount.get() >= finalBleedCount) bukkitRunnable.cancel(); + }).runTaskTimer(0, 10); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lumberjack.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lumberjack.java index 4d7ef341..4e77259a 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lumberjack.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lumberjack.java @@ -50,12 +50,12 @@ public class Lumberjack extends EcoEnchant { AnticheatManager.exemptPlayer(player); for(Block treeBlock : treeBlocks) { - treeBlock.setMetadata("block-ignore", new FixedMetadataValue(this.plugin, true)); + treeBlock.setMetadata("block-ignore", new FixedMetadataValue(this.getPlugin(), true)); if(!AntigriefManager.canBreakBlock(player, treeBlock)) continue; ProxyUtils.getProxy(BlockBreakProxy.class).breakBlock(player, treeBlock); - this.plugin.getScheduler().runLater(() -> treeBlock.removeMetadata("block-ignore", this.plugin),1); + this.getPlugin().getScheduler().runLater(() -> treeBlock.removeMetadata("block-ignore", this.getPlugin()),1); } AnticheatManager.unexemptPlayer(player); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/MagmaWalker.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/MagmaWalker.java index ed5f7078..cdb1a01d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/MagmaWalker.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/MagmaWalker.java @@ -1,13 +1,12 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.eco.util.VectorUtils; -import com.willfp.eco.util.bukkit.scheduling.EcoBukkitRunnable; +import com.willfp.eco.util.integrations.anticheat.AnticheatManager; +import com.willfp.eco.util.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; -import com.willfp.eco.util.integrations.anticheat.AnticheatManager; -import com.willfp.eco.util.integrations.antigrief.AntigriefManager; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -57,28 +56,25 @@ public class MagmaWalker extends EcoEnchant { block.setType(Material.OBSIDIAN); - block.setMetadata("byMagmaWalker", new FixedMetadataValue(this.plugin, true)); + block.setMetadata("byMagmaWalker", new FixedMetadataValue(this.getPlugin(), true)); long afterTicks = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "remove-after-ticks"); - BukkitRunnable replace = new EcoBukkitRunnable(this.plugin) { - @Override - public void run() { - if (block.getType().equals(Material.OBSIDIAN) && !player.getWorld().getBlockAt(player.getLocation().add(0, -1, 0)).equals(block)) { - block.setType(Material.LAVA); - block.removeMetadata("byMagmaWalker", this.plugin); - this.cancel(); - } + BukkitRunnable replace = this.getPlugin().getRunnableFactory().create(bukkitRunnable -> { + if (block.getType().equals(Material.OBSIDIAN) && !player.getWorld().getBlockAt(player.getLocation().add(0, -1, 0)).equals(block)) { + block.setType(Material.LAVA); + block.removeMetadata("byMagmaWalker", this.getPlugin()); + bukkitRunnable.cancel(); } - }; + }); - this.plugin.getScheduler().runLater(() -> { + this.getPlugin().getScheduler().runLater(() -> { if (block.getType().equals(Material.OBSIDIAN)) { if(!player.getWorld().getBlockAt(player.getLocation().add(0, -1, 0)).equals(block)) { block.setType(Material.LAVA); - block.removeMetadata("byMagmaWalker", this.plugin); + block.removeMetadata("byMagmaWalker", this.getPlugin()); } else { - replace.runTaskTimer(this.plugin, afterTicks, afterTicks); + replace.runTaskTimer(this.getPlugin(), afterTicks, afterTicks); } } }, afterTicks); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Magnetic.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Magnetic.java index 722dfffb..4b26efb0 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Magnetic.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Magnetic.java @@ -46,7 +46,7 @@ public class Magnetic extends EcoEnchant implements EcoRunnable { private void refresh() { players.clear(); - this.plugin.getServer().getOnlinePlayers().forEach(player -> { + this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { int level = EnchantChecks.getArmorPoints(player, this, 0); if(level > 0) { players.put(player, level); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Marking.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Marking.java index 7265c610..bf1dcc17 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Marking.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Marking.java @@ -26,10 +26,10 @@ public class Marking extends EcoEnchant { int ticksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level"); int ticks = ticksPerLevel * level; - victim.setMetadata("marked", new FixedMetadataValue(this.plugin, true)); + victim.setMetadata("marked", new FixedMetadataValue(this.getPlugin(), true)); - this.plugin.getScheduler().runLater(() -> { - victim.removeMetadata("marked", this.plugin); + this.getPlugin().getScheduler().runLater(() -> { + victim.removeMetadata("marked", this.getPlugin()); }, ticks); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Marksman.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Marksman.java index 7e171cf7..189c9d90 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Marksman.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Marksman.java @@ -9,7 +9,6 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.ProjectileLaunchEvent; -import org.bukkit.scheduler.BukkitRunnable; public class Marksman extends EcoEnchant { public Marksman() { super( @@ -30,7 +29,7 @@ public class Marksman extends EcoEnchant { Player player = (Player) event.getEntity().getShooter(); if (!EnchantChecks.mainhand(player, this)) return; - if(this.getDisabledWorlds().contains(player.getWorld())) return; + if (this.getDisabledWorlds().contains(player.getWorld())) return; if (!(event.getEntity() instanceof Arrow)) return; Arrow a = (Arrow) event.getEntity(); @@ -38,13 +37,10 @@ public class Marksman extends EcoEnchant { int ticks = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "remove-arrow-after-ticks"); - new BukkitRunnable() { - @Override - public void run() { - if (!a.isOnGround()) { - a.remove(); - } + this.getPlugin().getScheduler().runLater(() -> { + if (!a.isOnGround()) { + a.remove(); } - }.runTaskLater(this.plugin, ticks); + }, ticks); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Replenish.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Replenish.java index f0686dc8..05f8135c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Replenish.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Replenish.java @@ -7,7 +7,6 @@ import org.bukkit.block.Block; import org.bukkit.block.data.Ageable; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.scheduler.BukkitRunnable; public class Replenish extends EcoEnchant { public Replenish() { super( @@ -34,23 +33,17 @@ public class Replenish extends EcoEnchant { data.setAge(0); - new BukkitRunnable() { - @Override - public void run() { - block.setType(type); - block.setBlockData(data); - } - }.runTaskLater(this.plugin, 1); + this.getPlugin().getScheduler().runLater(() -> { + block.setType(type); + block.setBlockData(data); + }, 1); } data.setAge(0); - new BukkitRunnable() { - @Override - public void run() { - block.setType(type); - block.setBlockData(data); - } - }.runTaskLater(this.plugin, 1); + this.getPlugin().getScheduler().runLater(() -> { + block.setType(type); + block.setBlockData(data); + }, 1); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Shockwave.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Shockwave.java index 36d7f90d..ad2c181a 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Shockwave.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Shockwave.java @@ -2,12 +2,10 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.eco.core.proxy.proxies.TridentStackProxy; import com.willfp.eco.util.ProxyUtils; -import com.willfp.eco.util.bukkit.scheduling.EcoBukkitRunnable; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; -import org.bukkit.Bukkit; import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -49,23 +47,20 @@ public class Shockwave extends EcoEnchant { damage *= level; final double finalDamage = damage; - new EcoBukkitRunnable(this.plugin) { - @Override - public void run() { - if(entity.isOnGround() || entity.isInBlock() || entity.isDead()) this.cancel(); - entity.getNearbyEntities(1.5, 1.5, 1.5).stream() - .filter(entity1 -> entity1 instanceof LivingEntity) - .filter(entity1 -> entity1 != player) - .filter(entity1 -> !entity1.hasMetadata("shockwaved")) - .forEach((mob -> { - ((LivingEntity) mob).damage(finalDamage, player); - mob.setMetadata("shockwaved", new FixedMetadataValue(this.plugin, true)); - this.plugin.getScheduler().runLater(() -> { - mob.removeMetadata("shockwaved", this.plugin); - }, 10); - } - )); - } - }.runTaskTimer(this.plugin, 4, ticks); + this.getPlugin().getRunnableFactory().create(runnable -> { + if(entity.isOnGround() || entity.isInBlock() || entity.isDead()) runnable.cancel(); + entity.getNearbyEntities(1.5, 1.5, 1.5).stream() + .filter(entity1 -> entity1 instanceof LivingEntity) + .filter(entity1 -> entity1 != player) + .filter(entity1 -> !entity1.hasMetadata("shockwaved")) + .forEach((mob -> { + ((LivingEntity) mob).damage(finalDamage, player); + mob.setMetadata("shockwaved", new FixedMetadataValue(this.getPlugin(), true)); + this.getPlugin().getScheduler().runLater(() -> { + mob.removeMetadata("shockwaved", this.getPlugin()); + }, 10); + } + )); + }).runTaskTimer(4, ticks); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Slicing.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Slicing.java index 0254cdb7..b076b5c8 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Slicing.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Slicing.java @@ -50,7 +50,7 @@ public class Slicing extends EcoEnchant { victim.damage(level * damage, player); entities.add(victim); - Bukkit.getServer().getScheduler().runTaskLater(this.plugin, () -> entities.remove(victim), this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "cooldown")); + Bukkit.getServer().getScheduler().runTaskLater(this.getPlugin(), () -> entities.remove(victim), this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "cooldown")); if (this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "damage-elytra")) { DurabilityUtils.damageItem(player, player.getInventory().getChestplate(), 1, 38); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Succession.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Succession.java index 5fa04937..8571b8fe 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Succession.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Succession.java @@ -28,7 +28,7 @@ public class Succession extends EcoEnchant { boolean fire = EnchantChecks.mainhand(shooter, Enchantment.ARROW_FIRE); for (int i = 1; i <= number; i++) { - this.plugin.getScheduler().runLater(() -> { + this.getPlugin().getScheduler().runLater(() -> { Arrow arrow1 = shooter.launchProjectile(Arrow.class, event.getProjectile().getVelocity()); arrow1.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); if(fire) arrow1.setFireTicks(Integer.MAX_VALUE); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thrive.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thrive.java index dc64c909..98ce7563 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thrive.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thrive.java @@ -23,7 +23,7 @@ public class Thrive extends EcoEnchant { public void onArmorEquip(ArmorEquipEvent event) { final Player player = event.getPlayer(); - this.plugin.getScheduler().runLater(() -> { + this.getPlugin().getScheduler().runLater(() -> { int totalProsperityPoints = EnchantChecks.getArmorPoints(player, EcoEnchants.PROSPERITY, 0); int totalThrivePoints = EnchantChecks.getArmorPoints(player, EcoEnchants.THRIVE, 0); if (totalThrivePoints == 0 && totalProsperityPoints == 0) { @@ -42,7 +42,7 @@ public class Thrive extends EcoEnchant { player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue() + bonus); boolean finalOnMaxHealth = onMaxHealth; - this.plugin.getScheduler().runLater(() -> { + this.getPlugin().getScheduler().runLater(() -> { if (finalOnMaxHealth) { player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 255, false, false, false)); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tornado.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tornado.java index 2fbf65ff..094c6bcc 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tornado.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tornado.java @@ -24,7 +24,7 @@ public class Tornado extends EcoEnchant { Vector toAdd = new Vector(0, yVelocity, 0); - this.plugin.getScheduler().runLater(() -> { + this.getPlugin().getScheduler().runLater(() -> { victim.setVelocity(victim.getVelocity().clone().add(toAdd)); }, 1); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Vein.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Vein.java index 398c1f12..a526463b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Vein.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Vein.java @@ -50,12 +50,12 @@ public class Vein extends EcoEnchant { AnticheatManager.exemptPlayer(player); for (Block veinBlock : blockSet) { - veinBlock.setMetadata("block-ignore", new FixedMetadataValue(this.plugin, true)); + veinBlock.setMetadata("block-ignore", new FixedMetadataValue(this.getPlugin(), true)); if (!AntigriefManager.canBreakBlock(player, veinBlock)) continue; ProxyUtils.getProxy(BlockBreakProxy.class).breakBlock(player, veinBlock); - this.plugin.getScheduler().runLater(() -> veinBlock.removeMetadata("block-ignore", this.plugin), 1); + this.getPlugin().getScheduler().runLater(() -> veinBlock.removeMetadata("block-ignore", this.getPlugin()), 1); } AnticheatManager.unexemptPlayer(player); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Weakening.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Weakening.java index 217dce97..793ca266 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Weakening.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Weakening.java @@ -25,10 +25,10 @@ public class Weakening extends EcoEnchant { int ticksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level"); int ticks = ticksPerLevel * level; - victim.setMetadata("weak", new FixedMetadataValue(this.plugin, true)); + victim.setMetadata("weak", new FixedMetadataValue(this.getPlugin(), true)); - this.plugin.getScheduler().runLater(() -> { - victim.removeMetadata("weak", this.plugin); + this.getPlugin().getScheduler().runLater(() -> { + victim.removeMetadata("weak", this.getPlugin()); }, ticks); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wound.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wound.java index 4ac41f4e..b61c8c7b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wound.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wound.java @@ -7,7 +7,6 @@ import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import org.bukkit.entity.Arrow; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.scheduler.BukkitRunnable; import java.util.concurrent.atomic.AtomicInteger; @@ -34,15 +33,12 @@ public class Wound extends EcoEnchant { AtomicInteger currentBleedCount = new AtomicInteger(0); - new BukkitRunnable() { - @Override - public void run() { - currentBleedCount.addAndGet(1); + this.getPlugin().getRunnableFactory().create(bukkitRunnable -> { + currentBleedCount.addAndGet(1); - victim.damage(bleedDamage); + victim.damage(bleedDamage); - if (currentBleedCount.get() >= finalBleedCount) this.cancel(); - } - }.runTaskTimer(this.plugin, 0, 10); + if (currentBleedCount.get() >= finalBleedCount) bukkitRunnable.cancel(); + }).runTaskTimer(0, 10); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Aiming.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Aiming.java index a333634d..f45d0cec 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Aiming.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Aiming.java @@ -1,7 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.special; import com.willfp.eco.util.NumberUtils; -import com.willfp.eco.util.bukkit.scheduling.EcoBukkitRunnable; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; @@ -13,7 +12,6 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.ProjectileLaunchEvent; -import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; import java.util.Arrays; @@ -64,48 +62,43 @@ public class Aiming extends EcoEnchant { } final double finalDistance = distance; - Runnable runnable = new BukkitRunnable() { - @Override - public void run() { - List nearbyEntities = (List)(List) Arrays.asList(arrow.getNearbyEntities(finalDistance, finalDistance, finalDistance).stream() - .filter(entity -> entity instanceof LivingEntity) - .filter(entity -> !entity.equals(player)) - .filter(entity -> !(entity instanceof Enderman)) - .filter(entity -> { - if (entity instanceof Player) { - return ((Player) entity).getGameMode().equals(GameMode.SURVIVAL) || ((Player) entity).getGameMode().equals(GameMode.ADVENTURE); - } - return true; - }).toArray()); - if(nearbyEntities.isEmpty()) return; - LivingEntity entity = nearbyEntities.get(0); - double distance = Double.MAX_VALUE; - for(LivingEntity livingEntity : nearbyEntities) { - double currentDistance = livingEntity.getLocation().distance(arrow.getLocation()); - if(currentDistance >= distance) continue; - distance = currentDistance; - entity = livingEntity; - } - if(entity != null) { - Vector vector = entity.getEyeLocation().toVector().clone().subtract(arrow.getLocation().toVector()).normalize(); - arrow.setVelocity(vector); - } + Runnable runnable = this.getPlugin().getRunnableFactory().create(bukkitRunnable -> { + List nearbyEntities = (List)(List) Arrays.asList(arrow.getNearbyEntities(finalDistance, finalDistance, finalDistance).stream() + .filter(entity -> entity instanceof LivingEntity) + .filter(entity -> !entity.equals(player)) + .filter(entity -> !(entity instanceof Enderman)) + .filter(entity -> { + if (entity instanceof Player) { + return ((Player) entity).getGameMode().equals(GameMode.SURVIVAL) || ((Player) entity).getGameMode().equals(GameMode.ADVENTURE); + } + return true; + }).toArray()); + if(nearbyEntities.isEmpty()) return; + LivingEntity entity = nearbyEntities.get(0); + double dist = Double.MAX_VALUE; + for(LivingEntity livingEntity : nearbyEntities) { + double currentDistance = livingEntity.getLocation().distance(arrow.getLocation()); + if(currentDistance >= dist) continue; + + dist = currentDistance; + entity = livingEntity; } - }; + if(entity != null) { + Vector vector = entity.getEyeLocation().toVector().clone().subtract(arrow.getLocation().toVector()).normalize(); + arrow.setVelocity(vector); + } + }); final int period = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "check-ticks"); final int checks = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "checks-per-level") * level; AtomicInteger checksPerformed = new AtomicInteger(0); - new EcoBukkitRunnable(this.plugin) { - @Override - public void run() { - checksPerformed.addAndGet(1); - if(checksPerformed.get() > checks) this.cancel(); - if(arrow.isDead() || arrow.isInBlock() || arrow.isOnGround()) this.cancel(); - this.plugin.getScheduler().run(runnable); - } - }.runTaskTimer(this.plugin, 3, period); + this.getPlugin().getRunnableFactory().create(bukkitRunnable -> { + checksPerformed.addAndGet(1); + if(checksPerformed.get() > checks) bukkitRunnable.cancel(); + if(arrow.isDead() || arrow.isInBlock() || arrow.isOnGround()) bukkitRunnable.cancel(); + this.getPlugin().getScheduler().run(runnable); + }).runTaskTimer(3, period); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Carve.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Carve.java index 2bdf3743..309a33a8 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Carve.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Carve.java @@ -39,9 +39,9 @@ public class Carve extends EcoEnchant { .filter(entity -> entity instanceof LivingEntity) .filter(entity -> !entity.equals(attacker)) .forEach(entity -> { - entity.setMetadata("carved", new FixedMetadataValue(this.plugin, true)); + entity.setMetadata("carved", new FixedMetadataValue(this.getPlugin(), true)); ((LivingEntity) entity).damage(damage, attacker); - this.plugin.getScheduler().runLater(() -> entity.removeMetadata("carved", this.plugin), 20); + this.getPlugin().getScheduler().runLater(() -> entity.removeMetadata("carved", this.getPlugin()), 20); }); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Repairing.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Repairing.java index 66ded18e..b727ee4b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Repairing.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Repairing.java @@ -63,7 +63,7 @@ public class Repairing extends EcoEnchant implements EcoRunnable { private void refresh() { players.clear(); - this.plugin.getServer().getOnlinePlayers().forEach(player -> { + this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { if(Arrays.stream(player.getInventory().getContents()).parallel().anyMatch(item -> EnchantChecks.item(item, this))) players.add(player); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java index e969062f..a22fa1e3 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java @@ -64,7 +64,7 @@ public class Soulbound extends EcoEnchant { event.getPlayer().getInventory().addItem(itemStack); })); - this.plugin.getScheduler().runLater(() -> { + this.getPlugin().getScheduler().runLater(() -> { soulboundItemsMap.remove(event.getPlayer()); }, 1); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Ascend.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Ascend.java index ed2aa741..4b0a210a 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Ascend.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Ascend.java @@ -22,8 +22,8 @@ public class Ascend extends Spell { public void onUse(Player player, int level, PlayerInteractEvent event) { int ticks = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level") * level; player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, ticks, this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "power") - 1,false,false)); - player.setMetadata(IGNORE_FALL_KEY, new FixedMetadataValue(this.plugin, true)); - this.plugin.getScheduler().runLater(() -> player.removeMetadata(IGNORE_FALL_KEY, this.plugin), ticks * 4L); + player.setMetadata(IGNORE_FALL_KEY, new FixedMetadataValue(this.getPlugin(), true)); + this.getPlugin().getScheduler().runLater(() -> player.removeMetadata(IGNORE_FALL_KEY, this.getPlugin()), ticks * 4L); } @EventHandler diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Dynamite.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Dynamite.java index c249e916..4c3958b3 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Dynamite.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Dynamite.java @@ -66,9 +66,9 @@ public class Dynamite extends Spell { } toBreak.forEach((block1 -> { - block1.setMetadata("block-ignore", new FixedMetadataValue(this.plugin, true)); + block1.setMetadata("block-ignore", new FixedMetadataValue(this.getPlugin(), true)); ProxyUtils.getProxy(BlockBreakProxy.class).breakBlock(player, block1); - block1.removeMetadata("block-ignore", this.plugin); + block1.removeMetadata("block-ignore", this.getPlugin()); })); AnticheatManager.unexemptPlayer(player); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Missile.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Missile.java index 99b20a66..de76a09b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Missile.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Missile.java @@ -22,8 +22,8 @@ public class Missile extends Spell { WitherSkull skull = player.launchProjectile(WitherSkull.class, player.getEyeLocation().getDirection().multiply(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity"))); skull.setCharged(true); skull.setIsIncendiary(false); - skull.setMetadata("eco-damage", new FixedMetadataValue(this.plugin, this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level") * level)); - skull.setMetadata("nobreak", new FixedMetadataValue(this.plugin, true)); + skull.setMetadata("eco-damage", new FixedMetadataValue(this.getPlugin(), this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level") * level)); + skull.setMetadata("nobreak", new FixedMetadataValue(this.getPlugin(), true)); skull.setShooter(player); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java index 554458ca..451a55b9 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java @@ -23,7 +23,6 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; /** @@ -106,21 +105,18 @@ public abstract class Artifact extends EcoEnchant { double radiusMultiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "radius-multiplier"); double offset = NumberUtils.randFloat(0, 0.75); - new BukkitRunnable() { - @Override - public void run() { - for (int i = 0; i < 3; i++) { - if (yAtomic.get() > entity.getHeight()) this.cancel(); - yAtomic.addAndGet(yDelta); - double y = yAtomic.get(); - double x = radius * Math.cos((y + offset) * radiusMultiplier); - double z = radius * Math.sin((y + offset) * radiusMultiplier); - Location particleLocation = entity.getLocation(); - particleLocation.add(x, y, z); - entity.getWorld().spawnParticle(particle, particleLocation, 1, 0, 0, 0, 0, extra, false); - } + this.getPlugin().getRunnableFactory().create(bukkitRunnable -> { + for (int i = 0; i < 3; i++) { + if (yAtomic.get() > entity.getHeight()) bukkitRunnable.cancel(); + yAtomic.addAndGet(yDelta); + double y = yAtomic.get(); + double x = radius * Math.cos((y + offset) * radiusMultiplier); + double z = radius * Math.sin((y + offset) * radiusMultiplier); + Location particleLocation = entity.getLocation(); + particleLocation.add(x, y, z); + entity.getWorld().spawnParticle(particle, particleLocation, 1, 0, 0, 0, 0, extra, false); } - }.runTaskTimer(this.plugin, 0, 1); + }).runTaskTimer(0, 1); } @EventHandler @@ -149,12 +145,9 @@ public abstract class Artifact extends EcoEnchant { } final double finalColor = color.get(); - new BukkitRunnable() { - @Override - public void run() { - if (entity.isOnGround() || entity.isInBlock() || entity.isDead()) this.cancel(); - entity.getLocation().getWorld().spawnParticle(particle, entity.getLocation(), 1, 0, 0, 0, finalColor, extra, true); - } - }.runTaskTimer(this.plugin, 4, ticks); + this.getPlugin().getRunnableFactory().create(bukkitRunnable -> { + if (entity.isOnGround() || entity.isInBlock() || entity.isDead()) bukkitRunnable.cancel(); + entity.getLocation().getWorld().spawnParticle(particle, entity.getLocation(), 1, 0, 0, 0, finalColor, extra, true); + }).runTaskTimer(4, ticks); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java index a5a2b9e6..241c8153 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java @@ -53,7 +53,7 @@ public abstract class Spell extends EcoEnchant { if (runningSpell.contains(player.getUniqueId())) return; runningSpell.add(player.getUniqueId()); - this.plugin.getScheduler().runLater(() -> runningSpell.remove(player.getUniqueId()), 5); + this.getPlugin().getScheduler().runLater(() -> runningSpell.remove(player.getUniqueId()), 5); if (leftClickItems.contains(player.getInventory().getItemInMainHand().getType())) { if (!(event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK))) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java index 017853b7..df7603ce 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java @@ -58,7 +58,7 @@ public class AnvilListeners extends PluginDependent implements Listener { modCost = newOut.getSecond(); } - this.plugin.getScheduler().run(() -> { + this.getPlugin().getScheduler().run(() -> { // This is a disgusting bodge if (!noIncreaseXpMap.containsKey(player.getUniqueId())) @@ -68,7 +68,7 @@ public class AnvilListeners extends PluginDependent implements Listener { num += 1; noIncreaseXpMap.put(player.getUniqueId(), num); - this.plugin.getScheduler().runLater(() -> noIncreaseXpMap.remove(player.getUniqueId()), 1); + this.getPlugin().getScheduler().runLater(() -> noIncreaseXpMap.remove(player.getUniqueId()), 1); // End pain diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/grindstone/GrindstoneListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/grindstone/GrindstoneListeners.java index fb4992ca..9d01a1b8 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/grindstone/GrindstoneListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/grindstone/GrindstoneListeners.java @@ -30,7 +30,7 @@ public class GrindstoneListeners extends PluginDependent implements Listener { GrindstoneInventory inventory = (GrindstoneInventory) player.getOpenInventory().getTopInventory(); - this.plugin.getScheduler().runLater(() -> { + this.getPlugin().getScheduler().runLater(() -> { ItemStack top = inventory.getItem(0); ItemStack bottom = inventory.getItem(1); ItemStack out = inventory.getItem(2); @@ -59,7 +59,7 @@ public class GrindstoneListeners extends PluginDependent implements Listener { final ItemStack finalOut = newOut; - this.plugin.getScheduler().run(() -> { + this.getPlugin().getScheduler().run(() -> { inventory.setItem(2, finalOut); }); }, 1); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java index ad01460a..5d3b51b4 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java @@ -19,7 +19,6 @@ import org.bukkit.event.enchantment.PrepareItemEnchantEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; -import org.bukkit.scheduler.BukkitRunnable; import java.util.ArrayList; import java.util.Collections; @@ -55,7 +54,7 @@ public class EnchantingListeners extends PluginDependent implements Listener { Map toAdd = event.getEnchantsToAdd(); if (!Configs.CONFIG.getBool("enchanting-table.enabled")) { - this.plugin.getScheduler().runLater(() -> { + this.getPlugin().getScheduler().runLater(() -> { ItemStack item0 = event.getInventory().getItem(0); event.getInventory().setItem(0, item0); @@ -155,24 +154,21 @@ public class EnchantingListeners extends PluginDependent implements Listener { } // Ew - new BukkitRunnable() { - @Override - public void run() { - ItemStack item = event.getInventory().getItem(0); - assert item != null; - if (item.getItemMeta() instanceof EnchantmentStorageMeta) { - EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta(); - for (Enchantment enchantment : meta.getStoredEnchants().keySet()) { - meta.removeStoredEnchant(enchantment); - } - event.getEnchantsToAdd().forEach(((enchantment, integer) -> { - meta.addStoredEnchant(enchantment, integer, false); - })); - item.setItemMeta(meta); + this.getPlugin().getScheduler().runLater(() -> { + ItemStack item0 = event.getInventory().getItem(0); + assert item0 != null; + if (item0.getItemMeta() instanceof EnchantmentStorageMeta) { + EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item0.getItemMeta(); + for (Enchantment enchantment : meta.getStoredEnchants().keySet()) { + meta.removeStoredEnchant(enchantment); } - event.getInventory().setItem(0, item); + event.getEnchantsToAdd().forEach(((enchantment, integer) -> { + meta.addStoredEnchant(enchantment, integer, false); + })); + item0.setItemMeta(meta); } - }.runTaskLater(this.plugin, 1); + event.getInventory().setItem(0, item0); + }, 1); } @EventHandler diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java index 9b8abdd5..0bac8489 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java @@ -291,7 +291,7 @@ public class WatcherTriggers extends PluginDependent implements Listener { return; Player player = event.getPlayer(); - this.plugin.getScheduler().runLater(() -> { + this.getPlugin().getScheduler().runLater(() -> { EcoEnchants.values().forEach((enchant -> { if (event.isCancelled()) return; if (!enchant.isEnabled()) return; diff --git a/eco-extensions/alchemy/src/main/java/com/willfp/ecoenchants/alchemy/Alchemy.java b/eco-extensions/alchemy/src/main/java/com/willfp/ecoenchants/alchemy/Alchemy.java index c8cf7d39..53cae67d 100644 --- a/eco-extensions/alchemy/src/main/java/com/willfp/ecoenchants/alchemy/Alchemy.java +++ b/eco-extensions/alchemy/src/main/java/com/willfp/ecoenchants/alchemy/Alchemy.java @@ -5,7 +5,6 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; -import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityPotionEffectEvent; @@ -17,7 +16,7 @@ public class Alchemy extends EcoEnchant { super("alchemy", EnchantmentType.NORMAL); } - private final FixedMetadataValue metaKeyTrue = this.plugin.getMetadataValueFactory().create(true); + private final FixedMetadataValue metaKeyTrue = this.getPlugin().getMetadataValueFactory().create(true); @EventHandler public void onPotionEffect(EntityPotionEffectEvent event) { @@ -51,8 +50,8 @@ public class Alchemy extends EcoEnchant { entity.removePotionEffect(effect.getType()); - this.plugin.getScheduler().run(() -> newEffect.apply(entity)); + this.getPlugin().getScheduler().run(() -> newEffect.apply(entity)); - this.plugin.getScheduler().runLater(() -> entity.removeMetadata(newEffect.toString(), this.plugin), 1); + this.getPlugin().getScheduler().runLater(() -> entity.removeMetadata(newEffect.toString(), this.getPlugin()), 1); } } diff --git a/eco-extensions/effects/src/main/java/com/willfp/ecoenchants/effects/EffectsEnchantment.java b/eco-extensions/effects/src/main/java/com/willfp/ecoenchants/effects/EffectsEnchantment.java index ea626126..63e1bb65 100644 --- a/eco-extensions/effects/src/main/java/com/willfp/ecoenchants/effects/EffectsEnchantment.java +++ b/eco-extensions/effects/src/main/java/com/willfp/ecoenchants/effects/EffectsEnchantment.java @@ -23,7 +23,7 @@ public abstract class EffectsEnchantment extends EcoEnchant { public void onEquip(ArmorEquipEvent event) { final Player player = event.getPlayer(); - this.plugin.getScheduler().runLater(() -> { + this.getPlugin().getScheduler().runLater(() -> { if (player.hasPotionEffect(this.getPotionEffect()) && player.getPotionEffect(this.getPotionEffect()).getDuration() >= 1639) { player.removePotionEffect(this.getPotionEffect()); } diff --git a/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/Firewand.java b/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/Firewand.java index f95fef0d..0d39d1a9 100644 --- a/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/Firewand.java +++ b/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/Firewand.java @@ -21,9 +21,9 @@ public class Firewand extends Spell { public void onUse(Player player, int level, PlayerInteractEvent event) { SmallFireball fireball = player.launchProjectile(SmallFireball.class, player.getEyeLocation().getDirection().multiply(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity"))); fireball.setIsIncendiary(this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "fire")); - fireball.setMetadata("eco-damage", new FixedMetadataValue(this.plugin, this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level") * level)); + fireball.setMetadata("eco-damage", new FixedMetadataValue(this.getPlugin(), this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level") * level)); if(this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "no-explode")) { - fireball.setMetadata("nobreak", new FixedMetadataValue(this.plugin, true)); + fireball.setMetadata("nobreak", new FixedMetadataValue(this.getPlugin(), true)); } fireball.setShooter(player); } diff --git a/eco-extensions/precision/src/main/java/com/willfp/ecoenchants/precision/Precision.java b/eco-extensions/precision/src/main/java/com/willfp/ecoenchants/precision/Precision.java index 8068cd00..682a6cfa 100644 --- a/eco-extensions/precision/src/main/java/com/willfp/ecoenchants/precision/Precision.java +++ b/eco-extensions/precision/src/main/java/com/willfp/ecoenchants/precision/Precision.java @@ -3,12 +3,10 @@ package com.willfp.ecoenchants.precision; import com.willfp.eco.core.proxy.proxies.TridentStackProxy; import com.willfp.eco.util.ProxyUtils; -import com.willfp.eco.util.bukkit.scheduling.EcoBukkitRunnable; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.entity.Enderman; import org.bukkit.entity.LivingEntity; @@ -17,7 +15,6 @@ import org.bukkit.entity.Trident; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; import java.util.Arrays; @@ -56,48 +53,42 @@ public class Precision extends EcoEnchant { double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance-per-level"); final double finalDistance = level * multiplier; - Runnable runnable = new BukkitRunnable() { - @Override - public void run() { - List nearbyEntities = (List)(List) Arrays.asList(trident.getNearbyEntities(finalDistance, finalDistance, finalDistance).stream() - .filter(entity -> entity instanceof LivingEntity) - .filter(entity -> !entity.equals(player)) - .filter(entity -> !(entity instanceof Enderman)) - .filter(entity -> { - if (entity instanceof Player) { - return ((Player) entity).getGameMode().equals(GameMode.SURVIVAL) || ((Player) entity).getGameMode().equals(GameMode.ADVENTURE); - } - return true; - }).toArray()); - if(nearbyEntities.isEmpty()) return; - LivingEntity entity = nearbyEntities.get(0); - double distance = Double.MAX_VALUE; - for(LivingEntity livingEntity : nearbyEntities) { - double currentDistance = livingEntity.getLocation().distance(trident.getLocation()); - if(currentDistance >= distance) continue; + Runnable runnable = this.getPlugin().getRunnableFactory().create(bukkitRunnable -> { + List nearbyEntities = (List)(List) Arrays.asList(trident.getNearbyEntities(finalDistance, finalDistance, finalDistance).stream() + .filter(entity -> entity instanceof LivingEntity) + .filter(entity -> !entity.equals(player)) + .filter(entity -> !(entity instanceof Enderman)) + .filter(entity -> { + if (entity instanceof Player) { + return ((Player) entity).getGameMode().equals(GameMode.SURVIVAL) || ((Player) entity).getGameMode().equals(GameMode.ADVENTURE); + } + return true; + }).toArray()); + if(nearbyEntities.isEmpty()) return; + LivingEntity entity = nearbyEntities.get(0); + double dist = Double.MAX_VALUE; + for(LivingEntity livingEntity : nearbyEntities) { + double currentDistance = livingEntity.getLocation().distance(trident.getLocation()); + if(currentDistance >= dist) continue; - distance = currentDistance; - entity = livingEntity; - } - if(entity != null) { - Vector vector = entity.getEyeLocation().toVector().clone().subtract(trident.getLocation().toVector()).normalize(); - trident.setVelocity(vector); - } + dist = currentDistance; + entity = livingEntity; } - }; + if(entity != null) { + Vector vector = entity.getEyeLocation().toVector().clone().subtract(trident.getLocation().toVector()).normalize(); + trident.setVelocity(vector); + } + }); final int period = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "check-ticks"); final int checks = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "checks-per-level") * level; AtomicInteger checksPerformed = new AtomicInteger(0); - new EcoBukkitRunnable(this.plugin) { - @Override - public void run() { - checksPerformed.addAndGet(1); - if(checksPerformed.get() > checks) this.cancel(); - if(trident.isDead() || trident.isInBlock() || trident.isOnGround()) this.cancel(); - this.plugin.getScheduler().run(runnable); - } - }.runTaskTimer(this.plugin, 3, period); + this.getPlugin().getRunnableFactory().create(bukkitRunnable -> { + checksPerformed.addAndGet(1); + if(checksPerformed.get() > checks) bukkitRunnable.cancel(); + if(trident.isDead() || trident.isInBlock() || trident.isOnGround()) bukkitRunnable.cancel(); + this.getPlugin().getScheduler().run(runnable); + }).runTaskTimer(3, period); } } diff --git a/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsMain.java b/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsMain.java index fdf6f8cc..ad44422a 100644 --- a/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsMain.java +++ b/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsMain.java @@ -6,7 +6,7 @@ import org.bukkit.Bukkit; public class SprintArtifactsMain extends Extension { @Override public void onEnable() { - Bukkit.getPluginManager().registerEvents(new SprintArtifactsListener(), this.plugin); + Bukkit.getPluginManager().registerEvents(new SprintArtifactsListener(), this.getPlugin()); } @Override diff --git a/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java b/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java index cbe790aa..48d9e087 100644 --- a/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java +++ b/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java @@ -82,9 +82,9 @@ public abstract class SummoningEnchantment extends EcoEnchant { entity.setTarget(victim); if(health > entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) health = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); entity.setHealth(health); - entity.setMetadata("eco-target", new FixedMetadataValue(this.plugin, victim)); + entity.setMetadata("eco-target", new FixedMetadataValue(this.getPlugin(), victim)); - this.plugin.getScheduler().runLater(entity::remove, ticksToLive); + this.getPlugin().getScheduler().runLater(entity::remove, ticksToLive); } } diff --git a/eco-util/src/main/java/com/willfp/eco/util/bukkit/events/EcoEventManager.java b/eco-util/src/main/java/com/willfp/eco/util/bukkit/events/EcoEventManager.java index 21ca0a7c..b1a2f18d 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/bukkit/events/EcoEventManager.java +++ b/eco-util/src/main/java/com/willfp/eco/util/bukkit/events/EcoEventManager.java @@ -13,7 +13,7 @@ public class EcoEventManager extends PluginDependent implements EventManager { @Override public void registerEvents(Listener listener) { - Bukkit.getPluginManager().registerEvents(listener, this.plugin); + Bukkit.getPluginManager().registerEvents(listener, this.getPlugin()); } @Override @@ -23,6 +23,6 @@ public class EcoEventManager extends PluginDependent implements EventManager { @Override public void unregisterAllEvents() { - HandlerList.unregisterAll(this.plugin); + HandlerList.unregisterAll(this.getPlugin()); } } diff --git a/eco-util/src/main/java/com/willfp/eco/util/bukkit/keys/NamespacedKeyFactory.java b/eco-util/src/main/java/com/willfp/eco/util/bukkit/keys/NamespacedKeyFactory.java index 5e3744a9..42df25e5 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/bukkit/keys/NamespacedKeyFactory.java +++ b/eco-util/src/main/java/com/willfp/eco/util/bukkit/keys/NamespacedKeyFactory.java @@ -10,6 +10,6 @@ public class NamespacedKeyFactory extends PluginDependentFactory { } public NamespacedKey create(String key) { - return new NamespacedKey(this.plugin, key); + return new NamespacedKey(this.getPlugin(), key); } } diff --git a/eco-util/src/main/java/com/willfp/eco/util/bukkit/logging/EcoLogger.java b/eco-util/src/main/java/com/willfp/eco/util/bukkit/logging/EcoLogger.java index cbed27d8..a4d3a91b 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/bukkit/logging/EcoLogger.java +++ b/eco-util/src/main/java/com/willfp/eco/util/bukkit/logging/EcoLogger.java @@ -11,16 +11,16 @@ public class EcoLogger extends PluginDependent implements Logger { @Override public void info(String message) { - this.plugin.getLogger().info(StringUtils.translate(message)); + this.getPlugin().getLogger().info(StringUtils.translate(message)); } @Override public void warn(String message) { - this.plugin.getLogger().warning(StringUtils.translate(message)); + this.getPlugin().getLogger().warning(StringUtils.translate(message)); } @Override public void error(String message) { - this.plugin.getLogger().severe(StringUtils.translate(message)); + this.getPlugin().getLogger().severe(StringUtils.translate(message)); } } diff --git a/eco-util/src/main/java/com/willfp/eco/util/bukkit/meta/MetadataValueFactory.java b/eco-util/src/main/java/com/willfp/eco/util/bukkit/meta/MetadataValueFactory.java index 21b9d6b7..226cb61a 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/bukkit/meta/MetadataValueFactory.java +++ b/eco-util/src/main/java/com/willfp/eco/util/bukkit/meta/MetadataValueFactory.java @@ -10,6 +10,6 @@ public class MetadataValueFactory extends PluginDependentFactory { } public FixedMetadataValue create(Object value) { - return new FixedMetadataValue(this.plugin, value); + return new FixedMetadataValue(this.getPlugin(), value); } } diff --git a/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/EcoBukkitRunnable.java b/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/EcoBukkitRunnable.java index 47ab0786..b87e2b0f 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/EcoBukkitRunnable.java +++ b/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/EcoBukkitRunnable.java @@ -2,11 +2,47 @@ package com.willfp.eco.util.bukkit.scheduling; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.jetbrains.annotations.NotNull; public abstract class EcoBukkitRunnable extends BukkitRunnable { - protected final AbstractEcoPlugin plugin; + private final AbstractEcoPlugin plugin; - protected EcoBukkitRunnable(AbstractEcoPlugin plugin) { + EcoBukkitRunnable(AbstractEcoPlugin plugin) { this.plugin = plugin; } + + protected AbstractEcoPlugin getPlugin() { + return this.plugin; + } + + @NotNull + public synchronized BukkitTask runTask() { + return super.runTask(plugin); + } + + @NotNull + public synchronized BukkitTask runTaskAsynchronously() { + return super.runTaskAsynchronously(plugin); + } + + @NotNull + public synchronized BukkitTask runTaskLater(long delay) { + return super.runTaskLater(plugin, delay); + } + + @NotNull + public synchronized BukkitTask runTaskLaterAsynchronously(long delay) { + return super.runTaskLaterAsynchronously(plugin, delay); + } + + @NotNull + public synchronized BukkitTask runTaskTimer(long delay, long period) { + return super.runTaskTimer(plugin, delay, period); + } + + @NotNull + public synchronized BukkitTask runTaskTimerAsynchronously(long delay, long period) { + return super.runTaskTimerAsynchronously(plugin, delay, period); + } } diff --git a/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/EcoScheduler.java b/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/EcoScheduler.java index 78f8aec1..9d27b0fd 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/EcoScheduler.java +++ b/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/EcoScheduler.java @@ -13,36 +13,36 @@ public class EcoScheduler extends PluginDependent implements Scheduler { @Override public BukkitTask runLater(Callable callable, long ticksLater) { - return Bukkit.getServer().getScheduler().runTaskLater(this.plugin, callable::call, ticksLater); + return Bukkit.getServer().getScheduler().runTaskLater(this.getPlugin(), callable::call, ticksLater); } @Override public BukkitTask runTimer(Callable callable, long delay, long repeat) { - return Bukkit.getServer().getScheduler().runTaskTimer(this.plugin, callable::call, delay, repeat); + return Bukkit.getServer().getScheduler().runTaskTimer(this.getPlugin(), callable::call, delay, repeat); } @Override public BukkitTask runAsyncTimer(Callable callable, long delay, long repeat) { - return Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, callable::call, delay, repeat); + return Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(this.getPlugin(), callable::call, delay, repeat); } @Override public BukkitTask run(Runnable runnable) { - return Bukkit.getServer().getScheduler().runTask(this.plugin, runnable::run); + return Bukkit.getServer().getScheduler().runTask(this.getPlugin(), runnable::run); } @Override public BukkitTask runAsync(Callable callable) { - return Bukkit.getServer().getScheduler().runTaskAsynchronously(this.plugin, callable::call); + return Bukkit.getServer().getScheduler().runTaskAsynchronously(this.getPlugin(), callable::call); } @Override public int syncRepeating(Runnable runnable, long delay, long repeat) { - return Bukkit.getScheduler().scheduleSyncRepeatingTask(this.plugin, runnable, delay, repeat); + return Bukkit.getScheduler().scheduleSyncRepeatingTask(this.getPlugin(), runnable, delay, repeat); } @Override public void cancelAll() { - Bukkit.getScheduler().cancelTasks(this.plugin); + Bukkit.getScheduler().cancelTasks(this.getPlugin()); } } diff --git a/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/RunnableFactory.java b/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/RunnableFactory.java new file mode 100644 index 00000000..55039def --- /dev/null +++ b/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/RunnableFactory.java @@ -0,0 +1,20 @@ +package com.willfp.eco.util.bukkit.scheduling; + +import com.willfp.eco.util.factory.PluginDependentFactory; +import com.willfp.eco.util.lambda.InputCallable; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; + +public class RunnableFactory extends PluginDependentFactory { + public RunnableFactory(AbstractEcoPlugin plugin) { + super(plugin); + } + + public EcoBukkitRunnable create(InputCallable callable) { + return new EcoBukkitRunnable(this.getPlugin()) { + @Override + public void run() { + callable.call(this); + } + }; + } +} diff --git a/eco-util/src/main/java/com/willfp/eco/util/events/entitydeathbyentity/EntityDeathByEntityListeners.java b/eco-util/src/main/java/com/willfp/eco/util/events/entitydeathbyentity/EntityDeathByEntityListeners.java index 8590bb05..b877b133 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/events/entitydeathbyentity/EntityDeathByEntityListeners.java +++ b/eco-util/src/main/java/com/willfp/eco/util/events/entitydeathbyentity/EntityDeathByEntityListeners.java @@ -9,7 +9,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; import java.util.HashSet; import java.util.List; @@ -36,12 +35,7 @@ public class EntityDeathByEntityListeners extends PluginDependent implements Lis builtEvent.setDamager(event.getDamager()); events.add(builtEvent); - new BukkitRunnable() { - @Override - public void run() { - events.remove(builtEvent); - } - }.runTaskLater(this.plugin, 1); + this.getPlugin().getScheduler().runLater(() -> events.remove(builtEvent), 1); } @EventHandler @@ -54,7 +48,7 @@ public class EntityDeathByEntityListeners extends PluginDependent implements Lis AtomicReference atomicBuiltEvent = new AtomicReference<>(null); EntityDeathByEntityBuilder builtEvent; - events.forEach((deathByEntityEvent) -> { + events.forEach(deathByEntityEvent -> { if (deathByEntityEvent.getVictim().equals(victim)) { atomicBuiltEvent.set(deathByEntityEvent); } diff --git a/eco-util/src/main/java/com/willfp/eco/util/extensions/Extension.java b/eco-util/src/main/java/com/willfp/eco/util/extensions/Extension.java index a5b3ec74..cd8dfc34 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/extensions/Extension.java +++ b/eco-util/src/main/java/com/willfp/eco/util/extensions/Extension.java @@ -6,11 +6,11 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; /** - * Extensions are a way of interfacing with EcoEnchants + * Extensions are a way of interfacing with the base plugin * Syntactically similar to Bukkit Plugins. */ public abstract class Extension { - protected final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance(); + private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance(); /** * Metadata containing version and name @@ -42,6 +42,14 @@ public abstract class Extension { */ protected abstract void onDisable(); + /** + * Get instance of the owning plugin + * @return The instance to interface with + */ + protected final AbstractEcoPlugin getPlugin() { + return plugin; + } + /** * Set the metadata of the extension *

diff --git a/eco-util/src/main/java/com/willfp/eco/util/extensions/loader/EcoExtensionLoader.java b/eco-util/src/main/java/com/willfp/eco/util/extensions/loader/EcoExtensionLoader.java index d0df45a0..05336b82 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/extensions/loader/EcoExtensionLoader.java +++ b/eco-util/src/main/java/com/willfp/eco/util/extensions/loader/EcoExtensionLoader.java @@ -30,7 +30,7 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad @Override public void loadExtensions() { - File dir = new File(this.plugin.getDataFolder(), "/extensions"); + File dir = new File(this.getPlugin().getDataFolder(), "/extensions"); if (!dir.exists()) { dir.mkdirs(); } @@ -46,7 +46,7 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad try { loadExtension(extensionJar); } catch (MalformedExtensionException e) { - plugin.getLog().error(extensionJar.getName() + " caused MalformedExtensionException: " + e.getMessage()); + this.getPlugin().getLog().error(extensionJar.getName() + " caused MalformedExtensionException: " + e.getMessage()); } } } @@ -59,7 +59,7 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad e.printStackTrace(); } - ClassLoader cl = new URLClassLoader(new URL[]{url}, this.plugin.getClass().getClassLoader()); + ClassLoader cl = new URLClassLoader(new URL[]{url}, this.getPlugin().getClass().getClassLoader()); InputStream ymlIn = cl.getResourceAsStream("extension.yml"); diff --git a/eco-util/src/main/java/com/willfp/eco/util/injection/PluginDependent.java b/eco-util/src/main/java/com/willfp/eco/util/injection/PluginDependent.java index f8de5565..35db9cb7 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/injection/PluginDependent.java +++ b/eco-util/src/main/java/com/willfp/eco/util/injection/PluginDependent.java @@ -3,9 +3,13 @@ package com.willfp.eco.util.injection; import com.willfp.eco.util.plugin.AbstractEcoPlugin; public abstract class PluginDependent { - protected final AbstractEcoPlugin plugin; + private final AbstractEcoPlugin plugin; protected PluginDependent(AbstractEcoPlugin plugin) { this.plugin = plugin; } + + protected final AbstractEcoPlugin getPlugin() { + return this.plugin; + } } diff --git a/eco-util/src/main/java/com/willfp/eco/util/integrations/antigrief/plugins/AntigriefLands.java b/eco-util/src/main/java/com/willfp/eco/util/integrations/antigrief/plugins/AntigriefLands.java index e91b1837..2b41c203 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/integrations/antigrief/plugins/AntigriefLands.java +++ b/eco-util/src/main/java/com/willfp/eco/util/integrations/antigrief/plugins/AntigriefLands.java @@ -12,7 +12,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; public class AntigriefLands extends PluginDependent implements AntigriefWrapper { - private final LandsIntegration landsIntegration = new LandsIntegration(this.plugin); + private final LandsIntegration landsIntegration = new LandsIntegration(this.getPlugin()); public AntigriefLands(AbstractEcoPlugin plugin) { super(plugin); diff --git a/eco-util/src/main/java/com/willfp/eco/util/lambda/InputCallable.java b/eco-util/src/main/java/com/willfp/eco/util/lambda/InputCallable.java new file mode 100644 index 00000000..5f87f58f --- /dev/null +++ b/eco-util/src/main/java/com/willfp/eco/util/lambda/InputCallable.java @@ -0,0 +1,11 @@ +package com.willfp.eco.util.lambda; + +/** + * Functional Interface that requires an object + * + * @param The type of the object to require + */ +@FunctionalInterface +public interface InputCallable { + void call(A object); +} diff --git a/eco-util/src/main/java/com/willfp/eco/util/plugin/AbstractEcoPlugin.java b/eco-util/src/main/java/com/willfp/eco/util/plugin/AbstractEcoPlugin.java index 1c6254ff..a179f8bf 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/plugin/AbstractEcoPlugin.java +++ b/eco-util/src/main/java/com/willfp/eco/util/plugin/AbstractEcoPlugin.java @@ -8,6 +8,7 @@ import com.willfp.eco.util.bukkit.logging.EcoLogger; import com.willfp.eco.util.bukkit.logging.Logger; import com.willfp.eco.util.bukkit.meta.MetadataValueFactory; import com.willfp.eco.util.bukkit.scheduling.EcoScheduler; +import com.willfp.eco.util.bukkit.scheduling.RunnableFactory; import com.willfp.eco.util.bukkit.scheduling.Scheduler; import com.willfp.eco.util.command.AbstractCommand; import com.willfp.eco.util.config.Configs; @@ -69,6 +70,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin { private final EventManager eventManager; private final NamespacedKeyFactory namespacedKeyFactory; private final MetadataValueFactory metadataValueFactory; + private final RunnableFactory runnableFactory; private final ExtensionLoader extensionLoader; protected boolean outdated = false; @@ -83,6 +85,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin { this.eventManager = new EcoEventManager(this); this.namespacedKeyFactory = new NamespacedKeyFactory(this); this.metadataValueFactory = new MetadataValueFactory(this); + this.runnableFactory = new RunnableFactory(this); this.extensionLoader = new EcoExtensionLoader(this); if (!Bukkit.getServicesManager().isProvidedFor(TelekinesisTests.class)) { @@ -266,6 +269,10 @@ public abstract class AbstractEcoPlugin extends JavaPlugin { return metadataValueFactory; } + public final RunnableFactory getRunnableFactory() { + return runnableFactory; + } + public final ExtensionLoader getExtensionLoader() { return extensionLoader; }