diff --git a/Plugin/build.gradle b/Plugin/build.gradle index 81595ed5..9d8b0645 100644 --- a/Plugin/build.gradle +++ b/Plugin/build.gradle @@ -1,5 +1,7 @@ plugins { id 'com.github.johnrengelman.shadow' version '5.2.0' + id 'maven-publish' + id 'maven' } dependencies { @@ -60,3 +62,12 @@ build.dependsOn shadowJar description = 'EcoEnchants' compileJava.options.encoding = 'UTF-8' + + +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + } + } +} \ No newline at end of file diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java index d6e1a2d7..e81b4921 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java @@ -326,6 +326,15 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist return Bukkit.getWorlds().stream().filter(world -> disabledExistingWorldNames.contains(world.getName().toLowerCase())).collect(Collectors.toList()); } + /** + * Get world names that the enchantment is disabled in + * + * @return A list of all disabled world names + */ + public Set getDisabledWorldNames() { + return disabledWorldNames; + } + /** * Get display name of enchantment. * Not deprecated, unlike {@link Enchantment#getName()} @@ -370,6 +379,9 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist } /** + * Treasure enchantments do not exist in EcoEnchants + * @see EnchantmentType#SPECIAL + * * @return false * * @deprecated Treasure enchantments do not exist. Use {@link EcoEnchant#getType()} instead. @@ -381,6 +393,9 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist } /** + * While this method works, it is not recommended to use it. + * @see EnchantmentType#CURSE + * * @return Returns if enchantment is cursed. * * @deprecated Use {@link EcoEnchant#getType()} instead. diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Telekinesis.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Telekinesis.java index 3161f8e2..1239e7c1 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Telekinesis.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Telekinesis.java @@ -1,5 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; +import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.ecoenchants.special.Soulbound; @@ -8,7 +9,9 @@ import com.willfp.ecoenchants.events.entitydeathbyentity.EntityDeathByEntityEven import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.nms.TridentStack; import com.willfp.ecoenchants.util.internal.DropQueue; +import org.bukkit.Bukkit; import org.bukkit.GameMode; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Arrow; @@ -21,10 +24,15 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; -import java.util.stream.Collectors; +import java.util.Map; public class Telekinesis extends EcoEnchant { public Telekinesis() { @@ -33,26 +41,55 @@ public class Telekinesis extends EcoEnchant { ); } + private static boolean collate = false; + private static final HashMap COLLATED_MAP = new HashMap<>(); + private static final BukkitRunnable COLLATED_RUNNABLE = new BukkitRunnable() { + @Override + public void run() { + for(Map.Entry entry : COLLATED_MAP.entrySet()) { + new DropQueue(entry.getKey()) + .setLocation(entry.getValue().getLocation()) + .addItems(entry.getValue().getDrops()) + .push(); + } + } + }; + + private static BukkitTask collatedRunnableTask = null; + + public void update() { + collate = this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "collate"); + if(collate) collatedRunnableTask = COLLATED_RUNNABLE.runTaskTimer(EcoEnchantsPlugin.getInstance(), 0, 1); + else if(collatedRunnableTask != null) Bukkit.getScheduler().cancelTask(collatedRunnableTask.getTaskId()); + } + // START OF LISTENERS // For block drops - @EventHandler(priority = EventPriority.HIGH) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void telekinesisDropItem(BlockDropItemEvent event) { Player player = event.getPlayer(); if (!EnchantChecks.mainhand(player, this)) return; - if(this.getDisabledWorlds().contains(player.getWorld())) return; + if(this.getDisabledWorldNames().contains(player.getWorld().getName())) return; + //if(this.getDisabledWorlds().contains(player.getWorld())) return; if (event.isCancelled()) return; Block block = event.getBlock(); - if (!AntigriefManager.canBreakBlock(player, block)) return; + //if (!AntigriefManager.canBreakBlock(player, block)) return; - List drops = event.getItems().stream().map(Item::getItemStack).collect(Collectors.toList()); + List drops = new ArrayList<>(); + for(Item item : event.getItems()) drops.add(item.getItemStack()); event.getItems().clear(); + if(collate) collateDropItem(event, player, drops, block); + else defaultDropItem(event, player, drops, block); + } + + private void collateDropItem(BlockDropItemEvent event, Player player, List drops, Block block) { new DropQueue(player) .setLocation(block.getLocation()) .addItems(drops) @@ -61,6 +98,19 @@ public class Telekinesis extends EcoEnchant { player.updateInventory(); } + private void defaultDropItem(BlockDropItemEvent event, Player player, List drops, Block block) { + CollatedDrops collatedDrops; + if(COLLATED_MAP.containsKey(player)) { + HashSet dropSet = COLLATED_MAP.get(player).getDrops(); + dropSet.addAll(drops); + collatedDrops = new CollatedDrops(dropSet, block.getLocation()); + } else { + collatedDrops = new CollatedDrops(new HashSet<>(drops), block.getLocation()); + } + + COLLATED_MAP.put(player, collatedDrops); + } + // For exp drops, blockdropitemevent doesn't cover xp @EventHandler(priority = EventPriority.HIGH) public void telekinesisBreak(BlockBreakEvent event) { @@ -136,4 +186,26 @@ public class Telekinesis extends EcoEnchant { event.getDeathEvent().setDroppedExp(0); event.getDeathEvent().getDrops().clear(); } + + static { + EcoEnchants.TELEKINESIS.update(); + } + + private static class CollatedDrops { + private final HashSet drops; + private final Location location; + + private CollatedDrops(HashSet drops, Location location) { + this.drops = drops; + this.location = location; + } + + public HashSet getDrops() { + return drops; + } + + public Location getLocation() { + return location; + } + } } diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/util/internal/Loader.java b/Plugin/src/main/java/com/willfp/ecoenchants/util/internal/Loader.java index 0f73e1da..6d6fc36a 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/util/internal/Loader.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/util/internal/Loader.java @@ -370,6 +370,7 @@ public class Loader { DropQueue.update(); EnchantDisplay.update(); TabCompleterEnchantinfo.reload(); + EcoEnchants.TELEKINESIS.update(); EcoEnchant.EnchantmentType.update(); EcoEnchants.getAll().forEach((ecoEnchant -> { diff --git a/Plugin/src/main/resources/enchants/normal/telekinesis.yml b/Plugin/src/main/resources/enchants/normal/telekinesis.yml index 503b0b1b..fc189858 100644 --- a/Plugin/src/main/resources/enchants/normal/telekinesis.yml +++ b/Plugin/src/main/resources/enchants/normal/telekinesis.yml @@ -28,4 +28,6 @@ general-config: config: use-orb: true # Use experience orb above player to give xp. Use if you need mending interaction. - not-on-players: false # Disallow getting drops from players \ No newline at end of file + not-on-players: false # Disallow getting drops from players + + collate: false # Experimental feature - may help performance on larger servers. Stores all drops temporarily and only pushes them at the end of this tick. This should reduce the DropQueue calls from thousands a second to about 10 \ No newline at end of file diff --git a/build.gradle b/build.gradle index e8c60b0b..5e3af32d 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,6 @@ allprojects { options.encoding = 'UTF-8' } compileJava.options.encoding = 'UTF-8' - compileJava.dependsOn clean }