Added basic enderpearl island moving.

This commit is contained in:
tastybento 2021-02-15 15:58:15 -08:00
parent 92c4c05e04
commit f022d072c3
5 changed files with 77 additions and 3 deletions

View File

@ -59,7 +59,7 @@
<powermock.version>2.0.2</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.16.5-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.15.5</bentobox.version>
<bentobox.version>1.16.0-SNAPSHOT</bentobox.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. -->

View File

@ -18,6 +18,7 @@ import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.boxed.generators.BasicWorldGenerator;
import world.bentobox.boxed.generators.DeleteGen;
import world.bentobox.boxed.listeners.AdvancementListener;
import world.bentobox.boxed.listeners.EnderPearlListener;
/**
* Main BSkyBlock class - provides an island minigame in the sky
@ -66,6 +67,7 @@ public class Boxed extends GameModeAddon {
// Register listeners
this.registerListener(new AdvancementListener(this));
this.registerListener(new EnderPearlListener(this));
//this.registerListener(new JoinListener(this));
}

View File

@ -2,6 +2,7 @@ package world.bentobox.boxed.listeners;
import org.bukkit.Sound;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerAdvancementDoneEvent;
@ -27,7 +28,7 @@ public class AdvancementListener implements Listener {
}
@EventHandler
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onAdvancement(PlayerAdvancementDoneEvent e) {
if (e.getPlayer().getWorld().equals(addon.getOverWorld())) {
int score = addon.getAdvManager().addAvancement(e.getPlayer(), e.getAdvancement());

View File

@ -0,0 +1,70 @@
package world.bentobox.boxed.listeners;
import java.io.IOException;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileHitEvent;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.boxed.Boxed;
/**
* Listens for Ender Pearl throws and moves the island center
* @author tastybento
*
*/
public class EnderPearlListener implements Listener {
private final Boxed addon;
/**
* @param addon
*/
public EnderPearlListener(Boxed addon) {
this.addon = addon;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEnderPearlLand(ProjectileHitEvent e) {
if (!e.getEntityType().equals(EntityType.ENDER_PEARL)
|| e.getHitBlock() == null
|| !addon.getPlugin().getIWM().inWorld(e.getHitBlock().getLocation())) {
return;
}
Location l = e.getHitBlock().getLocation();
EnderPearl ep = (EnderPearl)e.getEntity();
if (ep.getShooter() instanceof Player) {
User u = User.getInstance((Player)ep.getShooter());
addon.getIslands().getIslandAt(l).ifPresent(i -> {
// TODO make this a flag
if (i.getMemberSet(RanksManager.OWNER_RANK).contains(u.getUniqueId())
&& addon.getIslands().isSafeLocation(l)) {
// Reset home locations
i.getMemberSet().forEach(uuid -> {
addon.getPlayers().getPlayer(uuid).clearHomeLocations(l.getWorld());
addon.getPlayers().getPlayer(uuid).setHomeLocation(l);
});
try {
i.setProtectionCenter(l);
u.sendRawMessage("Moving Box!");
u.getPlayer().playSound(u.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 2F, 2F);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
}
}

View File

@ -6,6 +6,7 @@ import org.bukkit.Bukkit;
import org.bukkit.advancement.Advancement;
import org.bukkit.advancement.AdvancementProgress;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
@ -25,7 +26,7 @@ public class JoinListener implements Listener {
this.addon = addon;
}
@EventHandler
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onJoinEvent(PlayerJoinEvent e) {
Iterator<Advancement> it = Bukkit.advancementIterator();
while (it.hasNext()) {