Moved BukkitRunnables into internal runnable factory

This commit is contained in:
Auxilor 2020-12-22 19:43:40 +00:00
parent f9a186f58f
commit 07e1848054
66 changed files with 360 additions and 334 deletions

View File

@ -31,82 +31,82 @@ public class CommandEcodebug extends AbstractCommand {
@Override
public void onExecute(CommandSender sender, List<String> 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<String, Enchantment> byName = (Map<String, Enchantment>) 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<Enchantment> 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<Enchantment> 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<Enchantment> 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<EcoEnchant> 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 ----------------");
}
}

View File

@ -14,7 +14,7 @@ public class CommandEcoreload extends AbstractCommand {
@Override
public void onExecute(CommandSender sender, List<String> args) {
this.plugin.reload();
this.getPlugin().reload();
sender.sendMessage(Configs.LANG.getMessage("reloaded"));
}
}

View File

@ -26,7 +26,7 @@ public class CommandEnchantinfo extends AbstractCommand {
@Override
public AbstractTabCompleter getTab() {
return new TabCompleterEnchantinfo(this.plugin);
return new TabCompleterEnchantinfo(this.getPlugin());
}
@Override

View File

@ -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();

View File

@ -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

View File

@ -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);

View File

@ -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);
});

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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);
});
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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)));
}
}

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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));
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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<LivingEntity> nearbyEntities = (List<LivingEntity>)(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<LivingEntity> nearbyEntities = (List<LivingEntity>)(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);
}
}

View File

@ -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);
});
}
}

View File

@ -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);
});

View File

@ -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);
}

View File

@ -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

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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))) {

View File

@ -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

View File

@ -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);

View File

@ -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<Enchantment, Integer> 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

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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());
}

View File

@ -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);
}

View File

@ -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<LivingEntity> nearbyEntities = (List<LivingEntity>)(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<LivingEntity> nearbyEntities = (List<LivingEntity>)(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);
}
}

View File

@ -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

View File

@ -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);
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -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));
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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());
}
}

View File

@ -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<EcoBukkitRunnable> callable) {
return new EcoBukkitRunnable(this.getPlugin()) {
@Override
public void run() {
callable.call(this);
}
};
}
}

View File

@ -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<EntityDeathByEntityBuilder> atomicBuiltEvent = new AtomicReference<>(null);
EntityDeathByEntityBuilder builtEvent;
events.forEach((deathByEntityEvent) -> {
events.forEach(deathByEntityEvent -> {
if (deathByEntityEvent.getVictim().equals(victim)) {
atomicBuiltEvent.set(deathByEntityEvent);
}

View File

@ -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
* <p>

View File

@ -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");

View File

@ -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;
}
}

View File

@ -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);

View File

@ -0,0 +1,11 @@
package com.willfp.eco.util.lambda;
/**
* Functional Interface that requires an object
*
* @param <A> The type of the object to require
*/
@FunctionalInterface
public interface InputCallable<A> {
void call(A object);
}

View File

@ -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;
}