Fix enderpearl moving.

This commit is contained in:
tastybento 2021-02-17 17:52:57 -08:00
parent 2446ed5340
commit 60b9b227b8

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@ -12,6 +13,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileHitEvent;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.boxed.Boxed;
@ -36,19 +38,24 @@ public class EnderPearlListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEnderPearlLand(ProjectileHitEvent e) {
BentoBox.getInstance().logDebug(e.getEventName());
if (!e.getEntityType().equals(EntityType.ENDER_PEARL)
|| e.getHitBlock() == null
|| !addon.getPlugin().getIWM().inWorld(e.getHitBlock().getLocation())) {
BentoBox.getInstance().logDebug("not right");
return;
}
Location l = e.getHitBlock().getLocation();
Location l = e.getHitBlock().getRelative(BlockFace.UP).getLocation();
EnderPearl ep = (EnderPearl)e.getEntity();
if (ep.getShooter() instanceof Player) {
BentoBox.getInstance().logDebug("Player");
User u = User.getInstance((Player)ep.getShooter());
addon.getIslands().getIslandAt(l).ifPresent(i -> {
BentoBox.getInstance().logDebug("Island found " + i.getMemberSet(RanksManager.OWNER_RANK).contains(u.getUniqueId()) + " " + addon.getIslands().isSafeLocation(l) );
// TODO make this a flag
if (i.getMemberSet(RanksManager.OWNER_RANK).contains(u.getUniqueId())
&& addon.getIslands().isSafeLocation(l)) {
BentoBox.getInstance().logDebug("Owner and safe");
// Reset home locations
i.getMemberSet().forEach(uuid -> {
addon.getPlayers().getPlayer(uuid).clearHomeLocations(l.getWorld());
@ -57,7 +64,7 @@ public class EnderPearlListener implements Listener {
try {
i.setProtectionCenter(l);
u.sendRawMessage("Moving Box!");
u.getPlayer().playSound(u.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 2F, 2F);
u.getPlayer().playSound(l, Sound.ENTITY_GENERIC_EXPLODE, 2F, 2F);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();