mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-12-25 20:17:38 +01:00
Added experimental Telekinesis item collation
This commit is contained in:
parent
999739306f
commit
7a705d5218
@ -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
|
||||
}
|
||||
}
|
||||
}
|
@ -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<String> 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.
|
||||
|
@ -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<Player, CollatedDrops> COLLATED_MAP = new HashMap<>();
|
||||
private static final BukkitRunnable COLLATED_RUNNABLE = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for(Map.Entry<Player, CollatedDrops> 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<ItemStack> drops = event.getItems().stream().map(Item::getItemStack).collect(Collectors.toList());
|
||||
List<ItemStack> 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<ItemStack> 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<ItemStack> drops, Block block) {
|
||||
CollatedDrops collatedDrops;
|
||||
if(COLLATED_MAP.containsKey(player)) {
|
||||
HashSet<ItemStack> 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<ItemStack> drops;
|
||||
private final Location location;
|
||||
|
||||
private CollatedDrops(HashSet<ItemStack> drops, Location location) {
|
||||
this.drops = drops;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public HashSet<ItemStack> getDrops() {
|
||||
return drops;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -370,6 +370,7 @@ public class Loader {
|
||||
DropQueue.update();
|
||||
EnchantDisplay.update();
|
||||
TabCompleterEnchantinfo.reload();
|
||||
EcoEnchants.TELEKINESIS.update();
|
||||
EcoEnchant.EnchantmentType.update();
|
||||
|
||||
EcoEnchants.getAll().forEach((ecoEnchant -> {
|
||||
|
@ -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
|
||||
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
|
@ -42,7 +42,6 @@ allprojects {
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
|
||||
compileJava.dependsOn clean
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user