Optimised Magnetic

This commit is contained in:
BuildTools 2020-10-03 12:23:02 +01:00
parent 8e313ec94e
commit 8f70b21cde
2 changed files with 129 additions and 108 deletions

View File

@ -5,12 +5,20 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.events.armorequip.ArmorEquipEvent;
import com.willfp.ecoenchants.util.EcoRunnable; import com.willfp.ecoenchants.util.EcoRunnable;
import com.willfp.ecoenchants.util.VectorUtils; import com.willfp.ecoenchants.util.VectorUtils;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.HashMap;
public class Magnetic extends EcoEnchant implements EcoRunnable { public class Magnetic extends EcoEnchant implements EcoRunnable {
public Magnetic() { public Magnetic() {
super( super(
@ -18,13 +26,37 @@ public class Magnetic extends EcoEnchant implements EcoRunnable {
); );
} }
private HashMap<Player, Integer> players = new HashMap<>();
private double initialDistance = 1;
private double bonus = 1;
@EventHandler
public void onArmorEquip(ArmorEquipEvent event) {
refresh();
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
refresh();
}
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
refresh();
}
private void refresh() {
players.clear();
EcoEnchantsPlugin.getInstance().getServer().getOnlinePlayers().forEach(player -> {
players.put(player, EnchantChecks.getArmorPoints(player, this, 0));
});
initialDistance = EcoEnchants.MAGNETIC.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "initial-distance");
bonus = EcoEnchants.MAGNETIC.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-level");
}
@Override @Override
public void run() { public void run() {
EcoEnchantsPlugin.getInstance().getServer().getOnlinePlayers().stream().filter(player -> EnchantChecks.getArmorPoints(player, EcoEnchants.MAGNETIC, 0) > 0).forEach((player -> { players.forEach((player, level) -> {
int level = EnchantChecks.getArmorPoints(player, EcoEnchants.MAGNETIC, 0);
double initialDistance = EcoEnchants.MAGNETIC.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "initial-distance");
double bonus = EcoEnchants.MAGNETIC.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-level");
double distance = initialDistance + (level * bonus); double distance = initialDistance + (level * bonus);
for (Entity e : player.getWorld().getNearbyEntities(player.getLocation(), distance, 2.0d, distance)) { for (Entity e : player.getWorld().getNearbyEntities(player.getLocation(), distance, 2.0d, distance)) {
@ -42,7 +74,7 @@ public class Magnetic extends EcoEnchant implements EcoRunnable {
e.setVelocity(vector); e.setVelocity(vector);
} }
} }
})); });
} }
@Override @Override

View File

@ -111,91 +111,6 @@ public class Loader {
new PacketSetSlot().register(); new PacketSetSlot().register();
new PacketWindowItems().register(); new PacketWindowItems().register();
/*
Load land management support
*/
Logger.info("Scheduling Integration Loading...");
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
Logger.info("Loading Integrations...");
if(Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) {
AntigriefManager.registerAntigrief(new AntigriefWorldGuard());
Logger.info("WorldGuard: §aENABLED");
} else {
Logger.info("WorldGuard: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("GriefPrevention")) {
AntigriefManager.registerAntigrief(new AntigriefGriefPrevention());
Logger.info("GriefPrevention: §aENABLED");
} else {
Logger.info("GriefPrevention: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("FactionsUUID")) {
AntigriefManager.registerAntigrief(new AntigriefFactionsUUID());
Logger.info("FactionsUUID: §aENABLED");
} else {
Logger.info("FactionsUUID: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Towny")) {
AntigriefManager.registerAntigrief(new AntigriefTowny());
Logger.info("Towny: §aENABLED");
} else {
Logger.info("Towny: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Lands")) {
AntigriefManager.registerAntigrief(new AntigriefLands());
Logger.info("Lands: §aENABLED");
} else {
Logger.info("Lands: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
EssentialsManager.registerEssentials(new IntegrationEssentials());
Logger.info("Essentials: §aENABLED");
EssentialsManager.registerEnchantments();
} else {
Logger.info("Essentials: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("AAC")) {
AnticheatManager.registerAnticheat(new AnticheatAAC());
Logger.info("AAC: §aENABLED");
} else {
Logger.info("AAC: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Matrix")) {
AnticheatManager.registerAnticheat(new AnticheatMatrix());
Logger.info("Matrix: §aENABLED");
} else {
Logger.info("Matrix: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("NoCheatPlus")) {
AnticheatManager.registerAnticheat(new AnticheatNCP());
Logger.info("NCP: §aENABLED");
} else {
Logger.info("NCP: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Spartan")) {
AnticheatManager.registerAnticheat(new AnticheatSpartan());
Logger.info("Spartan: §aENABLED");
} else {
Logger.info("Spartan: §9DISABLED");
}
Logger.info("");
}, 1);
Logger.info(""); Logger.info("");
/* /*
@ -248,18 +163,6 @@ public class Loader {
Bukkit.getPluginManager().registerEvents(new WatcherTriggers(), EcoEnchantsPlugin.getInstance()); Bukkit.getPluginManager().registerEvents(new WatcherTriggers(), EcoEnchantsPlugin.getInstance());
Logger.info(""); Logger.info("");
/*
Add Block Populators
*/
Logger.info("Scheduling Adding Block Populators...");
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
Bukkit.getServer().getWorlds().forEach((world -> {
world.getPopulators().add(new LootPopulator());
}));
}, 1);
Logger.info("");
/* /*
Load Extensions Load Extensions
*/ */
@ -390,9 +293,25 @@ public class Loader {
Logger.info(""); Logger.info("");
/* /*
Start update checker Finish
*/ */
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), Loader::postLoad, 1);
Logger.info("Loaded §aEcoEnchants!");
}
/**
* Called after server is loaded
*/
public static void postLoad() {
Logger.info("Adding block populators...");
Bukkit.getServer().getWorlds().forEach((world -> {
world.getPopulators().add(new LootPopulator());
}));
Logger.info("");
new UpdateChecker(EcoEnchantsPlugin.getInstance(), 79573).getVersion((version) -> { new UpdateChecker(EcoEnchantsPlugin.getInstance(), 79573).getVersion((version) -> {
DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(EcoEnchantsPlugin.getInstance().getDescription().getVersion()); DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(EcoEnchantsPlugin.getInstance().getDescription().getVersion());
@ -417,11 +336,81 @@ public class Loader {
Logger.info("----------------------------"); Logger.info("----------------------------");
}); });
/* Logger.info("");
Finish Logger.info("Loading Integrations...");
*/
Logger.info("Loaded §aEcoEnchants!"); if(Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) {
AntigriefManager.registerAntigrief(new AntigriefWorldGuard());
Logger.info("WorldGuard: §aENABLED");
} else {
Logger.info("WorldGuard: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("GriefPrevention")) {
AntigriefManager.registerAntigrief(new AntigriefGriefPrevention());
Logger.info("GriefPrevention: §aENABLED");
} else {
Logger.info("GriefPrevention: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("FactionsUUID")) {
AntigriefManager.registerAntigrief(new AntigriefFactionsUUID());
Logger.info("FactionsUUID: §aENABLED");
} else {
Logger.info("FactionsUUID: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Towny")) {
AntigriefManager.registerAntigrief(new AntigriefTowny());
Logger.info("Towny: §aENABLED");
} else {
Logger.info("Towny: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Lands")) {
AntigriefManager.registerAntigrief(new AntigriefLands());
Logger.info("Lands: §aENABLED");
} else {
Logger.info("Lands: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
EssentialsManager.registerEssentials(new IntegrationEssentials());
Logger.info("Essentials: §aENABLED");
EssentialsManager.registerEnchantments();
} else {
Logger.info("Essentials: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("AAC")) {
AnticheatManager.registerAnticheat(new AnticheatAAC());
Logger.info("AAC: §aENABLED");
} else {
Logger.info("AAC: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Matrix")) {
AnticheatManager.registerAnticheat(new AnticheatMatrix());
Logger.info("Matrix: §aENABLED");
} else {
Logger.info("Matrix: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("NoCheatPlus")) {
AnticheatManager.registerAnticheat(new AnticheatNCP());
Logger.info("NCP: §aENABLED");
} else {
Logger.info("NCP: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("Spartan")) {
AnticheatManager.registerAnticheat(new AnticheatSpartan());
Logger.info("Spartan: §aENABLED");
} else {
Logger.info("Spartan: §9DISABLED");
}
Logger.info("");
} }
/** /**