From 9391e7dd3d2f326366d00bc3bf5e3ad16b86bc12 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 29 Dec 2020 16:24:22 +0000 Subject: [PATCH] Tweaks to arborist and xray --- .../enchantments/ecoenchants/spell/Xray.java | 31 ++++++++++++++++++- .../resources/enchants/normal/arborist.yml | 2 +- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Xray.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Xray.java index adcdd670..d783f745 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Xray.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Xray.java @@ -3,13 +3,17 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.spell; import com.willfp.eco.util.TeamUtils; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.itemtypes.Spell; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.entity.Shulker; +import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.scoreboard.Team; import org.jetbrains.annotations.NotNull; @@ -18,6 +22,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.UUID; public class Xray extends Spell { public Xray() { @@ -88,12 +93,36 @@ public class Xray extends Spell { shulker.setGlowing(true); shulker.setInvisible(true); + block1.setMetadata("xray-uuid", this.getPlugin().getMetadataValueFactory().create(shulker.getUniqueId())); + if (this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "color-glow")) { Team team = TeamUtils.getMaterialColorTeam(block1.getType()); team.addEntry(shulker.getUniqueId().toString()); } - this.getPlugin().getScheduler().runLater(shulker::remove, ticks); + this.getPlugin().getScheduler().runLater(() -> { + shulker.remove(); + block1.removeMetadata("xray-uuid", this.getPlugin()); + }, ticks); }); } + + @EventHandler + public void onBlockBreak(@NotNull final BlockBreakEvent event) { + Block block = event.getBlock(); + + if (!block.hasMetadata("xray-uuid")) { + return; + } + + UUID uuid = (UUID) block.getMetadata("xray-uuid").get(0).value(); + + assert uuid != null; + + Entity entity = Bukkit.getServer().getEntity(uuid); + + if (entity != null) { + entity.remove(); + } + } } diff --git a/eco-core/core-plugin/src/main/resources/enchants/normal/arborist.yml b/eco-core/core-plugin/src/main/resources/enchants/normal/arborist.yml index 25ac5809..a764c172 100644 --- a/eco-core/core-plugin/src/main/resources/enchants/normal/arborist.yml +++ b/eco-core/core-plugin/src/main/resources/enchants/normal/arborist.yml @@ -32,4 +32,4 @@ config: - jungle_sapling - oak_sapling - spruce_sapling - chance-per-level: 0.03 # Chance to drop item. \ No newline at end of file + chance-per-level: 3 # Chance to drop item. \ No newline at end of file