mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Some random bukkitutil/worldutil improvements
This commit is contained in:
parent
932052772c
commit
d077fafd29
@ -49,7 +49,7 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String commandLabel,
|
||||
String[] args) {
|
||||
if (commandSender instanceof Player) {
|
||||
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), args);
|
||||
return MainCommand.onCommand(BukkitUtil.adapt((Player) commandSender), args);
|
||||
}
|
||||
if (commandSender instanceof ConsoleCommandSender
|
||||
|| commandSender instanceof ProxiedCommandSender
|
||||
@ -65,7 +65,7 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
if (!(commandSender instanceof Player)) {
|
||||
return null;
|
||||
}
|
||||
PlotPlayer player = BukkitUtil.getPlayer((Player) commandSender);
|
||||
PlotPlayer player = BukkitUtil.adapt((Player) commandSender);
|
||||
if (args.length == 0) {
|
||||
return Collections.singletonList("plots");
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
}
|
||||
|
||||
// Stuff that needs to be created before the PlotSquared instance
|
||||
PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer);
|
||||
PlotPlayer.registerConverter(Player.class, BukkitUtil::adapt);
|
||||
TaskManager.setPlatformImplementation(new BukkitTaskManager(this, timeConverter));
|
||||
|
||||
final PlotSquared plotSquared = new PlotSquared(this, "Bukkit");
|
||||
@ -772,7 +772,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
case "BOAT":
|
||||
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||
com.plotsquared.core.location.Location location =
|
||||
BukkitUtil.getLocation(entity.getLocation());
|
||||
BukkitUtil.adapt(entity.getLocation());
|
||||
Plot plot = location.getPlot();
|
||||
if (plot == null) {
|
||||
if (location.isPlotArea()) {
|
||||
@ -803,7 +803,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
case "DRAGON_FIREBALL":
|
||||
case "DROPPED_ITEM":
|
||||
if (Settings.Enabled_Components.KILL_ROAD_ITEMS && plotArea
|
||||
.getOwnedPlotAbs(BukkitUtil.getLocation(entity.getLocation()))
|
||||
.getOwnedPlotAbs(BukkitUtil.adapt(entity.getLocation()))
|
||||
== null) {
|
||||
entity.remove();
|
||||
}
|
||||
@ -829,7 +829,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
PlotId originalPlotId = (PlotId) meta.get(0).value();
|
||||
if (originalPlotId != null) {
|
||||
com.plotsquared.core.location.Location pLoc =
|
||||
BukkitUtil.getLocation(entity.getLocation());
|
||||
BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = pLoc.getPlotArea();
|
||||
if (area != null) {
|
||||
PlotId currentPlotId = PlotId.of(area.getPlotAbs(pLoc));
|
||||
@ -848,7 +848,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
} else {
|
||||
//This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java)
|
||||
com.plotsquared.core.location.Location pLoc =
|
||||
BukkitUtil.getLocation(entity.getLocation());
|
||||
BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = pLoc.getPlotArea();
|
||||
if (area != null) {
|
||||
PlotId currentPlotId = PlotId.of(area.getPlotAbs(pLoc));
|
||||
@ -933,7 +933,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
default: {
|
||||
if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
|
||||
Location location = entity.getLocation();
|
||||
if (BukkitUtil.getLocation(location).isPlotRoad()) {
|
||||
if (BukkitUtil.adapt(location).isPlotRoad()) {
|
||||
if (entity instanceof LivingEntity) {
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
if (!livingEntity.isLeashed() || !entity
|
||||
@ -1037,8 +1037,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
"WorldEdit"));
|
||||
}
|
||||
|
||||
@Override public void unregister(@Nonnull final PlotPlayer player) {
|
||||
BukkitUtil.removePlayer(player.getUUID());
|
||||
@Override public void unregister(@Nonnull final PlotPlayer<?> player) {
|
||||
PlotSquared.platform().getPlayerManager().removePlayer(player.getUUID());
|
||||
}
|
||||
|
||||
@Override public void setGenerator(@Nonnull final String worldName) {
|
||||
@ -1094,10 +1094,10 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
*/
|
||||
@Override @Nullable public PlotPlayer<Player> wrapPlayer(final Object player) {
|
||||
if (player instanceof Player) {
|
||||
return BukkitUtil.getPlayer((Player) player);
|
||||
return BukkitUtil.adapt((Player) player);
|
||||
}
|
||||
if (player instanceof OfflinePlayer) {
|
||||
return BukkitUtil.getPlayer((OfflinePlayer) player);
|
||||
return BukkitUtil.adapt((OfflinePlayer) player);
|
||||
}
|
||||
if (player instanceof String) {
|
||||
return (PlotPlayer<Player>) PlotSquared.platform().getPlayerManager()
|
||||
|
@ -126,7 +126,7 @@ public class EntitySpawnListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void creatureSpawnEvent(EntitySpawnEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
Location location = BukkitUtil.getLocation(entity.getLocation());
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (!location.isPlotArea()) {
|
||||
return;
|
||||
|
@ -49,7 +49,7 @@ public class ForceFieldListener {
|
||||
for (Player nearPlayer : Iterables
|
||||
.filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
|
||||
PlotPlayer plotPlayer;
|
||||
if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot
|
||||
if ((plotPlayer = BukkitUtil.adapt(nearPlayer)) == null || !plot
|
||||
.equals(plotPlayer.getCurrentPlot())) {
|
||||
continue;
|
||||
}
|
||||
@ -64,7 +64,7 @@ public class ForceFieldListener {
|
||||
for (Player nearPlayer : Iterables
|
||||
.filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
|
||||
PlotPlayer plotPlayer;
|
||||
if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot
|
||||
if ((plotPlayer = BukkitUtil.adapt(nearPlayer)) == null || !plot
|
||||
.equals(plotPlayer.getCurrentPlot())) {
|
||||
continue;
|
||||
}
|
||||
|
@ -84,8 +84,8 @@ public class PaperListener implements Listener {
|
||||
if (!Settings.Paper_Components.ENTITY_PATHING) {
|
||||
return;
|
||||
}
|
||||
Location toLoc = BukkitUtil.getLocation(event.getLoc());
|
||||
Location fromLoc = BukkitUtil.getLocation(event.getEntity().getLocation());
|
||||
Location toLoc = BukkitUtil.adapt(event.getLoc());
|
||||
Location fromLoc = BukkitUtil.adapt(event.getEntity().getLocation());
|
||||
PlotArea tarea = toLoc.getPlotArea();
|
||||
if (tarea == null) {
|
||||
return;
|
||||
@ -124,8 +124,8 @@ public class PaperListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Location toLoc = BukkitUtil.getLocation(b.getLocation());
|
||||
Location fromLoc = BukkitUtil.getLocation(event.getEntity().getLocation());
|
||||
Location toLoc = BukkitUtil.adapt(b.getLocation());
|
||||
Location fromLoc = BukkitUtil.adapt(event.getEntity().getLocation());
|
||||
PlotArea tarea = toLoc.getPlotArea();
|
||||
if (tarea == null) {
|
||||
return;
|
||||
@ -158,7 +158,7 @@ public class PaperListener implements Listener {
|
||||
if (!Settings.Paper_Components.CREATURE_SPAWN) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(event.getSpawnLocation());
|
||||
Location location = BukkitUtil.adapt(event.getSpawnLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (!location.isPlotArea()) {
|
||||
return;
|
||||
@ -253,7 +253,7 @@ public class PaperListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerNaturallySpawnCreaturesEvent(PlayerNaturallySpawnCreaturesEvent event) {
|
||||
if (Settings.Paper_Components.CANCEL_CHUNK_SPAWN) {
|
||||
Location location = BukkitUtil.getLocation(event.getPlayer().getLocation());
|
||||
Location location = BukkitUtil.adapt(event.getPlayer().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area != null && !area.isMobSpawning()) {
|
||||
event.setCancelled(true);
|
||||
@ -263,7 +263,7 @@ public class PaperListener implements Listener {
|
||||
|
||||
@EventHandler public void onPreSpawnerSpawnEvent(PreSpawnerSpawnEvent event) {
|
||||
if (Settings.Paper_Components.SPAWNER_SPAWN) {
|
||||
Location location = BukkitUtil.getLocation(event.getSpawnerLocation());
|
||||
Location location = BukkitUtil.adapt(event.getSpawnerLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area != null && !area.isMobSpawnerSpawning()) {
|
||||
event.setCancelled(true);
|
||||
@ -279,14 +279,14 @@ public class PaperListener implements Listener {
|
||||
if (!(event.getBlock().getState(false) instanceof TileState)) {
|
||||
return;
|
||||
}
|
||||
final Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
|
||||
final Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
||||
final PlotArea plotArea = location.getPlotArea();
|
||||
if (plotArea == null) {
|
||||
return;
|
||||
}
|
||||
final int tileEntityCount = event.getBlock().getChunk().getTileEntities(false).length;
|
||||
if (tileEntityCount >= Settings.Chunk_Processor.MAX_TILES) {
|
||||
final PlotPlayer<?> plotPlayer = BukkitUtil.getPlayer(event.getPlayer());
|
||||
final PlotPlayer<?> plotPlayer = BukkitUtil.adapt(event.getPlayer());
|
||||
Captions.TILE_ENTITY_CAP_REACHED.send(plotPlayer, Settings.Chunk_Processor.MAX_TILES);
|
||||
event.setCancelled(true);
|
||||
event.setBuild(false);
|
||||
@ -311,11 +311,11 @@ public class PaperListener implements Listener {
|
||||
if (!(shooter instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer<?> pp = BukkitUtil.getPlayer((Player) shooter);
|
||||
PlotPlayer<?> pp = BukkitUtil.adapt((Player) shooter);
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot != null && !plot.isAdded(pp.getUUID())) {
|
||||
entity.remove();
|
||||
@ -347,7 +347,7 @@ public class PaperListener implements Listener {
|
||||
final String[] args = new String[unprocessedArgs.length - 1];
|
||||
System.arraycopy(unprocessedArgs, 1, args, 0, args.length);
|
||||
try {
|
||||
final PlotPlayer<?> player = BukkitUtil.getPlayer((Player) event.getSender());
|
||||
final PlotPlayer<?> player = BukkitUtil.adapt((Player) event.getSender());
|
||||
final Collection<Command> objects = MainCommand.getInstance().tab(player, args, buffer.endsWith(" "));
|
||||
if (objects == null) {
|
||||
return;
|
||||
|
@ -329,10 +329,10 @@ import java.util.regex.Pattern;
|
||||
|
||||
@EventHandler public void onVehicleEntityCollision(VehicleEntityCollisionEvent e) {
|
||||
if (e.getVehicle().getType() == EntityType.BOAT) {
|
||||
Location location = BukkitUtil.getLocation(e.getEntity());
|
||||
Location location = BukkitUtil.adapt(e.getEntity().getLocation());
|
||||
if (location.isPlotArea()) {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
PlotPlayer<Player> player = BukkitUtil.getPlayer((Player) e.getEntity());
|
||||
PlotPlayer<Player> player = BukkitUtil.adapt((Player) e.getEntity());
|
||||
Plot plot = player.getCurrentPlot();
|
||||
if (plot != null) {
|
||||
if (!plot.isAdded(player.getUUID())) {
|
||||
@ -354,7 +354,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
@EventHandler public void onRedstoneEvent(BlockRedstoneEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -420,7 +420,7 @@ import java.util.regex.Pattern;
|
||||
switch (event.getChangedType()) {
|
||||
case COMPARATOR: {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
if (location.isPlotArea()) {
|
||||
return;
|
||||
}
|
||||
@ -442,7 +442,7 @@ import java.util.regex.Pattern;
|
||||
case TURTLE_HELMET:
|
||||
case TURTLE_SPAWN_EGG: {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -465,7 +465,7 @@ import java.util.regex.Pattern;
|
||||
case STICKY_PISTON:
|
||||
org.bukkit.block.data.Directional piston =
|
||||
(org.bukkit.block.data.Directional) block.getBlockData();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -510,11 +510,11 @@ import java.util.regex.Pattern;
|
||||
if (!(shooter instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer<Player> pp = BukkitUtil.getPlayer((Player) shooter);
|
||||
PlotPlayer<Player> pp = BukkitUtil.adapt((Player) shooter);
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot != null && !plot.isAdded(pp.getUUID())) {
|
||||
entity.remove();
|
||||
@ -524,7 +524,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
@EventHandler public boolean onProjectileHit(ProjectileHitEvent event) {
|
||||
Projectile entity = event.getEntity();
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return true;
|
||||
}
|
||||
@ -535,7 +535,7 @@ import java.util.regex.Pattern;
|
||||
Plot plot = area.getPlot(location);
|
||||
ProjectileSource shooter = entity.getShooter();
|
||||
if (shooter instanceof Player) {
|
||||
PlotPlayer<?> pp = BukkitUtil.getPlayer((Player) shooter);
|
||||
PlotPlayer<?> pp = BukkitUtil.adapt((Player) shooter);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Captions.PERMISSION_PROJECTILE_UNOWNED)) {
|
||||
entity.remove();
|
||||
@ -556,7 +556,7 @@ import java.util.regex.Pattern;
|
||||
return false;
|
||||
}
|
||||
Location sLoc =
|
||||
BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||
BukkitUtil.adapt(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||
if (!area.contains(sLoc.getX(), sLoc.getZ())) {
|
||||
entity.remove();
|
||||
return false;
|
||||
@ -577,7 +577,7 @@ import java.util.regex.Pattern;
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer<Player> plotPlayer = BukkitUtil.getPlayer(player);
|
||||
PlotPlayer<Player> plotPlayer = BukkitUtil.adapt(player);
|
||||
Location location = plotPlayer.getLocation();
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
@ -683,8 +683,8 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onConnect(PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
BukkitUtil.removePlayer(player.getUniqueId());
|
||||
final PlotPlayer<Player> pp = BukkitUtil.getPlayer(player);
|
||||
PlotSquared.platform().getPlayerManager().removePlayer(player.getUniqueId());
|
||||
final PlotPlayer<Player> pp = BukkitUtil.adapt(player);
|
||||
|
||||
Location location = pp.getLocation();
|
||||
PlotArea area = location.getPlotArea();
|
||||
@ -723,19 +723,19 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void playerRespawn(PlayerRespawnEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer<Player> pp = BukkitUtil.getPlayer(player);
|
||||
PlotPlayer<Player> pp = BukkitUtil.adapt(player);
|
||||
this.eventDispatcher.doRespawnTask(pp);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onTeleport(PlayerTeleportEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||
Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT);
|
||||
org.bukkit.Location to = event.getTo();
|
||||
//noinspection ConstantConditions
|
||||
if (to != null) {
|
||||
Location location = BukkitUtil.getLocation(to);
|
||||
Location location = BukkitUtil.adapt(to);
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
if (lastPlot != null) {
|
||||
@ -753,7 +753,7 @@ import java.util.regex.Pattern;
|
||||
// i.e. untrusted-visit can override deny-teleport
|
||||
// this is acceptable, because otherwise it wouldn't make sense to have both flags set
|
||||
if (!result && !(plot.getFlag(UntrustedVisitFlag.class) && plot.getHomeSynchronous()
|
||||
.equals(BukkitUtil.getLocationFull(to)))) {
|
||||
.equals(BukkitUtil.adaptComplete(to)))) {
|
||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
||||
Captions.PERMISSION_ADMIN_ENTRY_DENIED);
|
||||
event.setCancelled(true);
|
||||
@ -816,7 +816,7 @@ import java.util.regex.Pattern;
|
||||
if (EntityCategories.VEHICLE.contains(entityType) && !EntityCategories.ANIMAL
|
||||
.contains(entityType)) {
|
||||
List<MetadataValue> meta = vehicle.getMetadata("plot");
|
||||
Plot toPlot = BukkitUtil.getLocation(to).getPlot();
|
||||
Plot toPlot = BukkitUtil.adapt(to).getPlot();
|
||||
if (!meta.isEmpty()) {
|
||||
Plot origin = (Plot) meta.get(0).value();
|
||||
if (origin != null && !origin.getBasePlot(false).equals(toPlot)) {
|
||||
@ -840,13 +840,13 @@ import java.util.regex.Pattern;
|
||||
int x2;
|
||||
if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
|
||||
Player player = event.getPlayer();
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||
// Cancel teleport
|
||||
if (TaskManager.removeFromTeleportQueue(pp.getName())) {
|
||||
MainUtil.sendMessage(pp, Captions.TELEPORT_FAILED);
|
||||
}
|
||||
// Set last location
|
||||
Location location = BukkitUtil.getLocation(to);
|
||||
Location location = BukkitUtil.adapt(to);
|
||||
pp.setMeta(PlotPlayer.META_LOCATION, location);
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
@ -861,7 +861,7 @@ import java.util.regex.Pattern;
|
||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
||||
Captions.PERMISSION_ADMIN_EXIT_DENIED);
|
||||
this.tmpTeleport = false;
|
||||
if (lastPlot.equals(BukkitUtil.getLocation(from).getPlot())) {
|
||||
if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) {
|
||||
player.teleport(from);
|
||||
} else {
|
||||
player.teleport(player.getWorld().getSpawnLocation());
|
||||
@ -902,13 +902,13 @@ import java.util.regex.Pattern;
|
||||
int z2;
|
||||
if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) {
|
||||
Player player = event.getPlayer();
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||
// Cancel teleport
|
||||
if (TaskManager.removeFromTeleportQueue(pp.getName())) {
|
||||
MainUtil.sendMessage(pp, Captions.TELEPORT_FAILED);
|
||||
}
|
||||
// Set last location
|
||||
Location location = BukkitUtil.getLocation(to);
|
||||
Location location = BukkitUtil.adapt(to);
|
||||
pp.setMeta(PlotPlayer.META_LOCATION, location);
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
@ -923,7 +923,7 @@ import java.util.regex.Pattern;
|
||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
||||
Captions.PERMISSION_ADMIN_EXIT_DENIED);
|
||||
this.tmpTeleport = false;
|
||||
if (lastPlot.equals(BukkitUtil.getLocation(from).getPlot())) {
|
||||
if (lastPlot.equals(BukkitUtil.adapt(from).getPlot())) {
|
||||
player.teleport(from);
|
||||
} else {
|
||||
player.teleport(player.getWorld().getSpawnLocation());
|
||||
@ -968,7 +968,7 @@ import java.util.regex.Pattern;
|
||||
return;
|
||||
}
|
||||
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(event.getPlayer());
|
||||
BukkitPlayer plotPlayer = BukkitUtil.adapt(event.getPlayer());
|
||||
Location location = plotPlayer.getLocation();
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
@ -1027,14 +1027,14 @@ import java.util.regex.Pattern;
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST) public void blockDestroy(BlockBreakEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
|
||||
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot != null) {
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
||||
if (event.getBlock().getY() == 0) {
|
||||
if (!Permissions
|
||||
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL)) {
|
||||
@ -1083,7 +1083,7 @@ import java.util.regex.Pattern;
|
||||
}
|
||||
return;
|
||||
}
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||
if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) {
|
||||
return;
|
||||
}
|
||||
@ -1100,7 +1100,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBigBoom(EntityExplodeEvent event) {
|
||||
Location location = BukkitUtil.getLocation(event.getLocation());
|
||||
Location location = BukkitUtil.adapt(event.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
boolean plotArea = location.isPlotArea();
|
||||
if (!plotArea) {
|
||||
@ -1136,7 +1136,7 @@ import java.util.regex.Pattern;
|
||||
Iterator<Block> iterator = event.blockList().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Block block = iterator.next();
|
||||
location = BukkitUtil.getLocation(block.getLocation());
|
||||
location = BukkitUtil.adapt(block.getLocation());
|
||||
if (!area.contains(location.getX(), location.getZ()) || !origin
|
||||
.equals(area.getOwnedPlot(location))) {
|
||||
iterator.remove();
|
||||
@ -1153,7 +1153,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onWorldChanged(PlayerChangedWorldEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||
// Delete last location
|
||||
Plot plot = (Plot) pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
|
||||
pp.deleteMeta(PlotPlayer.META_LOCATION);
|
||||
@ -1184,7 +1184,7 @@ import java.util.regex.Pattern;
|
||||
public void onPeskyMobsChangeTheWorldLikeWTFEvent(EntityChangeBlockEvent event) {
|
||||
Entity e = event.getEntity();
|
||||
if (!(e instanceof FallingBlock)) {
|
||||
Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
|
||||
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area != null) {
|
||||
Plot plot = area.getOwnedPlot(location);
|
||||
@ -1203,7 +1203,7 @@ import java.util.regex.Pattern;
|
||||
if (!this.plotAreaManager.hasPlotArea(world)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
|
||||
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -1217,7 +1217,7 @@ import java.util.regex.Pattern;
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
if (!plot.hasOwner()) {
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
||||
if (plot.getFlag(IceFormFlag.class)) {
|
||||
plot.debug("Ice could not be formed because ice-form = false");
|
||||
return;
|
||||
@ -1225,7 +1225,7 @@ import java.util.regex.Pattern;
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
||||
if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||
if (plot.getFlag(IceFormFlag.class)) {
|
||||
plot.debug("Ice could not be formed because ice-form = false");
|
||||
@ -1244,7 +1244,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockSpread(BlockSpreadEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
if (location.isPlotRoad()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -1288,7 +1288,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockForm(BlockFormEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
if (location.isPlotRoad()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -1322,7 +1322,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
|
||||
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -1345,7 +1345,7 @@ import java.util.regex.Pattern;
|
||||
return;
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
||||
if (Permissions
|
||||
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
|
||||
return;
|
||||
@ -1353,7 +1353,7 @@ import java.util.regex.Pattern;
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
||||
if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||
List<BlockTypeWrapper> destroy = plot.getFlag(BreakFlag.class);
|
||||
Block block = event.getBlock();
|
||||
@ -1370,7 +1370,7 @@ import java.util.regex.Pattern;
|
||||
}
|
||||
return;
|
||||
}
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
||||
if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) {
|
||||
return;
|
||||
}
|
||||
@ -1380,7 +1380,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onFade(BlockFadeEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -1442,7 +1442,7 @@ import java.util.regex.Pattern;
|
||||
Block from = event.getBlock();
|
||||
|
||||
// Check liquid flow flag inside of origin plot too
|
||||
final Location fLocation = BukkitUtil.getLocation(from.getLocation());
|
||||
final Location fLocation = BukkitUtil.adapt(from.getLocation());
|
||||
final PlotArea fromArea = fLocation.getPlotArea();
|
||||
if (fromArea != null) {
|
||||
final Plot plot = fromArea.getOwnedPlot(fLocation);
|
||||
@ -1456,7 +1456,7 @@ import java.util.regex.Pattern;
|
||||
}
|
||||
|
||||
Block to = event.getToBlock();
|
||||
Location tLocation = BukkitUtil.getLocation(to.getLocation());
|
||||
Location tLocation = BukkitUtil.adapt(to.getLocation());
|
||||
PlotArea area = tLocation.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -1501,14 +1501,14 @@ import java.util.regex.Pattern;
|
||||
v
|
||||
<-----O-----> x
|
||||
*/
|
||||
if (BukkitUtil.getPlot(location.clone().add(-1, 0, 1) /* A */) != null
|
||||
|| BukkitUtil.getPlot(location.clone().add(1, 0, 0) /* B */) != null
|
||||
|| BukkitUtil.getPlot(location.clone().add(1, 0, 1) /* C */) != null
|
||||
|| BukkitUtil.getPlot(location.clone().add(-1, 0, 0) /* D */) != null
|
||||
|| BukkitUtil.getPlot(location.clone().add(1, 0, 0) /* E */) != null
|
||||
|| BukkitUtil.getPlot(location.clone().add(-1, 0, -1) /* F */) != null
|
||||
|| BukkitUtil.getPlot(location.clone().add(0, 0, -1) /* G */) != null
|
||||
|| BukkitUtil.getPlot(location.clone().add(1, 0, 1) /* H */) != null) {
|
||||
if (BukkitUtil.adapt(location.clone().add(-1, 0, 1) /* A */).getPlot() != null
|
||||
|| BukkitUtil.adapt(location.clone().add(1, 0, 0) /* B */).getPlot() != null
|
||||
|| BukkitUtil.adapt(location.clone().add(1, 0, 1) /* C */).getPlot() != null
|
||||
|| BukkitUtil.adapt(location.clone().add(-1, 0, 0) /* D */).getPlot() != null
|
||||
|| BukkitUtil.adapt(location.clone().add(1, 0, 0) /* E */).getPlot() != null
|
||||
|| BukkitUtil.adapt(location.clone().add(-1, 0, -1) /* F */).getPlot() != null
|
||||
|| BukkitUtil.adapt(location.clone().add(0, 0, -1) /* G */).getPlot() != null
|
||||
|| BukkitUtil.adapt(location.clone().add(1, 0, 1) /* H */).getPlot() != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -1517,7 +1517,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onGrow(BlockGrowEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
if (location.isUnownedPlotArea()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@ -1526,7 +1526,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
BlockFace face = event.getDirection();
|
||||
Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ());
|
||||
PlotArea area = location.getPlotArea();
|
||||
@ -1535,7 +1535,7 @@ import java.util.regex.Pattern;
|
||||
return;
|
||||
}
|
||||
for (Block block1 : event.getBlocks()) {
|
||||
Location bloc = BukkitUtil.getLocation(block1.getLocation());
|
||||
Location bloc = BukkitUtil.adapt(block1.getLocation());
|
||||
if (bloc.isPlotArea() || bloc
|
||||
.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())
|
||||
.isPlotArea()) {
|
||||
@ -1557,7 +1557,7 @@ import java.util.regex.Pattern;
|
||||
return;
|
||||
}
|
||||
for (Block block1 : event.getBlocks()) {
|
||||
Location bloc = BukkitUtil.getLocation(block1.getLocation());
|
||||
Location bloc = BukkitUtil.adapt(block1.getLocation());
|
||||
if (!area.contains(bloc.getX(), bloc.getZ()) || !area
|
||||
.contains(bloc.getX() + relative.getBlockX(), bloc.getZ() + relative.getBlockZ())) {
|
||||
event.setCancelled(true);
|
||||
@ -1581,7 +1581,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
BlockFace face = event.getDirection();
|
||||
Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ());
|
||||
PlotArea area = location.getPlotArea();
|
||||
@ -1590,7 +1590,7 @@ import java.util.regex.Pattern;
|
||||
return;
|
||||
}
|
||||
for (Block block1 : event.getBlocks()) {
|
||||
Location bloc = BukkitUtil.getLocation(block1.getLocation());
|
||||
Location bloc = BukkitUtil.adapt(block1.getLocation());
|
||||
if (bloc.isPlotArea() || bloc
|
||||
.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())
|
||||
.isPlotArea()) {
|
||||
@ -1606,7 +1606,7 @@ import java.util.regex.Pattern;
|
||||
return;
|
||||
}
|
||||
for (Block block1 : event.getBlocks()) {
|
||||
Location bloc = BukkitUtil.getLocation(block1.getLocation());
|
||||
Location bloc = BukkitUtil.adapt(block1.getLocation());
|
||||
if (!area.contains(bloc.getX(), bloc.getZ()) || !area
|
||||
.contains(bloc.getX() + relative.getBlockX(), bloc.getZ() + relative.getBlockZ())) {
|
||||
event.setCancelled(true);
|
||||
@ -1661,7 +1661,7 @@ import java.util.regex.Pattern;
|
||||
BlockFace targetFace =
|
||||
((Directional) event.getBlock().getState().getData()).getFacing();
|
||||
Location location =
|
||||
BukkitUtil.getLocation(event.getBlock().getRelative(targetFace).getLocation());
|
||||
BukkitUtil.adapt(event.getBlock().getRelative(targetFace).getLocation());
|
||||
if (location.isPlotRoad()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@ -1678,11 +1678,11 @@ import java.util.regex.Pattern;
|
||||
if (blocks.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(blocks.get(0).getLocation());
|
||||
Location location = BukkitUtil.adapt(blocks.get(0).getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
for (int i = blocks.size() - 1; i >= 0; i--) {
|
||||
location = BukkitUtil.getLocation(blocks.get(i).getLocation());
|
||||
location = BukkitUtil.adapt(blocks.get(i).getLocation());
|
||||
if (location.isPlotArea()) {
|
||||
blocks.remove(i);
|
||||
}
|
||||
@ -1695,7 +1695,7 @@ import java.util.regex.Pattern;
|
||||
return;
|
||||
}
|
||||
for (int i = blocks.size() - 1; i >= 0; i--) {
|
||||
location = BukkitUtil.getLocation(blocks.get(i).getLocation());
|
||||
location = BukkitUtil.adapt(blocks.get(i).getLocation());
|
||||
if (!area.contains(location.getX(), location.getZ())) {
|
||||
blocks.remove(i);
|
||||
continue;
|
||||
@ -1712,7 +1712,7 @@ import java.util.regex.Pattern;
|
||||
return;
|
||||
}
|
||||
for (int i = blocks.size() - 1; i >= 0; i--) {
|
||||
location = BukkitUtil.getLocation(blocks.get(i).getLocation());
|
||||
location = BukkitUtil.adapt(blocks.get(i).getLocation());
|
||||
Plot plot = area.getOwnedPlot(location);
|
||||
/*
|
||||
* plot → the base plot of the merged area
|
||||
@ -1744,7 +1744,7 @@ import java.util.regex.Pattern;
|
||||
return;
|
||||
}
|
||||
Player player = (Player) clicker;
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||
final PlotInventory inventory = PlotInventory.getOpenPlotInventory(pp);
|
||||
if (inventory != null && event.getRawSlot() == event.getSlot()) {
|
||||
if (!inventory.onClick(event.getSlot())) {
|
||||
@ -1831,7 +1831,7 @@ import java.util.regex.Pattern;
|
||||
return;
|
||||
}
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(state.getLocation());
|
||||
Location location = BukkitUtil.adapt(state.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -1875,7 +1875,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPotionSplash(LingeringPotionSplashEvent event) {
|
||||
Projectile entity = event.getEntity();
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
@ -1890,14 +1890,14 @@ import java.util.regex.Pattern;
|
||||
if (!(entity instanceof ArmorStand) && !(entity instanceof ItemFrame)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(e.getRightClicked().getLocation());
|
||||
Location location = BukkitUtil.adapt(e.getRightClicked().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
EntitySpawnListener.testNether(entity);
|
||||
Plot plot = location.getPlotAbs();
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
|
||||
BukkitPlayer pp = BukkitUtil.adapt(e.getPlayer());
|
||||
if (plot == null) {
|
||||
if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class) && !Permissions
|
||||
.hasPermission(pp, "plots.admin.interact.road")) {
|
||||
@ -1941,7 +1941,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBigBoom(BlockExplodeEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
String world = location.getWorldName();
|
||||
if (!this.plotAreaManager.hasPlotArea(world)) {
|
||||
return;
|
||||
@ -1950,7 +1950,7 @@ import java.util.regex.Pattern;
|
||||
if (area == null) {
|
||||
Iterator<Block> iterator = event.blockList().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
location = BukkitUtil.getLocation(iterator.next().getLocation());
|
||||
location = BukkitUtil.adapt(iterator.next().getLocation());
|
||||
if (location.isPlotArea()) {
|
||||
iterator.remove();
|
||||
}
|
||||
@ -1965,14 +1965,14 @@ import java.util.regex.Pattern;
|
||||
}
|
||||
}
|
||||
event.blockList().removeIf(
|
||||
blox -> !plot.equals(area.getOwnedPlot(BukkitUtil.getLocation(blox.getLocation()))));
|
||||
blox -> !plot.equals(area.getOwnedPlot(BukkitUtil.adapt(blox.getLocation()))));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onCancelledInteract(PlayerInteractEvent event) {
|
||||
if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
Player player = event.getPlayer();
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||
PlotArea area = pp.getPlotAreaAbs();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -1994,7 +1994,7 @@ import java.util.regex.Pattern;
|
||||
if (type.toString().toLowerCase().endsWith("_egg")) {
|
||||
Block block = player.getTargetBlockExact(5, FluidCollisionMode.SOURCE_ONLY);
|
||||
if (block != null && block.getType() != Material.AIR) {
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
if (!this.eventDispatcher
|
||||
.checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, null,
|
||||
true)) {
|
||||
@ -2009,7 +2009,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||
PlotArea area = pp.getPlotAreaAbs();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -2017,7 +2017,7 @@ import java.util.regex.Pattern;
|
||||
PlayerBlockEventType eventType = null;
|
||||
BlockType blocktype1;
|
||||
Block block = event.getClickedBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
Action action = event.getAction();
|
||||
outer:
|
||||
switch (action) {
|
||||
@ -2106,14 +2106,14 @@ import java.util.regex.Pattern;
|
||||
break outer;
|
||||
case ARMOR_STAND:
|
||||
location = BukkitUtil
|
||||
.getLocation(block.getRelative(event.getBlockFace()).getLocation());
|
||||
.adapt(block.getRelative(event.getBlockFace()).getLocation());
|
||||
eventType = PlayerBlockEventType.PLACE_MISC;
|
||||
break outer;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LEFT_CLICK_BLOCK: {
|
||||
location = BukkitUtil.getLocation(block.getLocation());
|
||||
location = BukkitUtil.adapt(block.getLocation());
|
||||
//eventType = PlayerBlockEventType.BREAK_BLOCK;
|
||||
blocktype1 = BukkitAdapter.asBlockType(block.getType());
|
||||
if (block.getType() == Material.DRAGON_EGG) {
|
||||
@ -2142,7 +2142,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void creatureSpawnEvent(CreatureSpawnEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
Location location = BukkitUtil.getLocation(entity.getLocation());
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -2220,7 +2220,7 @@ import java.util.regex.Pattern;
|
||||
if (!this.plotAreaManager.hasPlotArea(worldName)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -2255,7 +2255,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
@ -2278,7 +2278,7 @@ import java.util.regex.Pattern;
|
||||
Entity ignitingEntity = event.getIgnitingEntity();
|
||||
Block block = event.getBlock();
|
||||
BlockIgniteEvent.IgniteCause igniteCause = event.getCause();
|
||||
Location location1 = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location1 = BukkitUtil.adapt(block.getLocation());
|
||||
PlotArea area = location1.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -2290,7 +2290,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
Plot plot = area.getOwnedPlot(location1);
|
||||
if (player != null) {
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
|
||||
@ -2329,11 +2329,11 @@ import java.util.regex.Pattern;
|
||||
Location location = null;
|
||||
if (fireball.getShooter() instanceof Entity) {
|
||||
Entity shooter = (Entity) fireball.getShooter();
|
||||
location = BukkitUtil.getLocation(shooter.getLocation());
|
||||
location = BukkitUtil.adapt(shooter.getLocation());
|
||||
} else if (fireball.getShooter() instanceof BlockProjectileSource) {
|
||||
Block shooter =
|
||||
((BlockProjectileSource) fireball.getShooter()).getBlock();
|
||||
location = BukkitUtil.getLocation(shooter.getLocation());
|
||||
location = BukkitUtil.adapt(shooter.getLocation());
|
||||
}
|
||||
if (location != null && !plot.equals(location.getPlot())) {
|
||||
event.setCancelled(true);
|
||||
@ -2343,7 +2343,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
} else if (event.getIgnitingBlock() != null) {
|
||||
Block ignitingBlock = event.getIgnitingBlock();
|
||||
Plot plotIgnited = BukkitUtil.getLocation(ignitingBlock.getLocation()).getPlot();
|
||||
Plot plotIgnited = BukkitUtil.adapt(ignitingBlock.getLocation()).getPlot();
|
||||
if (igniteCause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL && (
|
||||
!plot.getFlag(BlockIgnitionFlag.class) || plotIgnited == null || !plotIgnited
|
||||
.equals(plot)) || (igniteCause == BlockIgniteEvent.IgniteCause.SPREAD
|
||||
@ -2362,12 +2362,12 @@ import java.util.regex.Pattern;
|
||||
Block block =
|
||||
event.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ())
|
||||
.getBlock();
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
|
||||
BukkitPlayer pp = BukkitUtil.adapt(event.getPlayer());
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null) {
|
||||
if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||
@ -2413,12 +2413,12 @@ import java.util.regex.Pattern;
|
||||
return;
|
||||
}
|
||||
Player player = (Player) closer;
|
||||
PlotInventory.removePlotInventoryOpen(BukkitUtil.getPlayer(player));
|
||||
PlotInventory.removePlotInventoryOpen(BukkitUtil.adapt(player));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR) public void onLeave(PlayerQuitEvent event) {
|
||||
TaskManager.removeFromTeleportQueue(event.getPlayer().getName());
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
|
||||
BukkitPlayer pp = BukkitUtil.adapt(event.getPlayer());
|
||||
pp.unregister();
|
||||
this.logout(pp.getUUID());
|
||||
}
|
||||
@ -2426,13 +2426,13 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBucketFill(PlayerBucketFillEvent event) {
|
||||
Block blockClicked = event.getBlockClicked();
|
||||
Location location = BukkitUtil.getLocation(blockClicked.getLocation());
|
||||
Location location = BukkitUtil.adapt(blockClicked.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null) {
|
||||
if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||
@ -2475,7 +2475,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onVehicleCreate(VehicleCreateEvent event) {
|
||||
Vehicle entity = event.getVehicle();
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -2494,7 +2494,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onHangingPlace(HangingPlaceEvent event) {
|
||||
Block block = event.getBlock().getRelative(event.getBlockFace());
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -2504,7 +2504,7 @@ import java.util.regex.Pattern;
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(p);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(p);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
|
||||
@ -2543,12 +2543,12 @@ import java.util.regex.Pattern;
|
||||
Entity remover = event.getRemover();
|
||||
if (remover instanceof Player) {
|
||||
Player p = (Player) remover;
|
||||
Location location = BukkitUtil.getLocation(event.getEntity());
|
||||
Location location = BukkitUtil.adapt(event.getEntity().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(p);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(p);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) {
|
||||
@ -2578,13 +2578,13 @@ import java.util.regex.Pattern;
|
||||
Projectile p = (Projectile) remover;
|
||||
if (p.getShooter() instanceof Player) {
|
||||
Player shooter = (Player) p.getShooter();
|
||||
Location location = BukkitUtil.getLocation(event.getEntity());
|
||||
Location location = BukkitUtil.adapt(event.getEntity().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
BukkitPlayer player = BukkitUtil.getPlayer(shooter);
|
||||
Plot plot = area.getPlot(BukkitUtil.getLocation(event.getEntity()));
|
||||
BukkitPlayer player = BukkitUtil.adapt(shooter);
|
||||
Plot plot = area.getPlot(BukkitUtil.adapt(event.getEntity().getLocation()));
|
||||
if (plot != null) {
|
||||
if (!plot.hasOwner()) {
|
||||
if (!Permissions
|
||||
@ -2614,13 +2614,13 @@ import java.util.regex.Pattern;
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
Location location = BukkitUtil.getLocation(event.getRightClicked().getLocation());
|
||||
Location location = BukkitUtil.adapt(event.getRightClicked().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Player p = event.getPlayer();
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(p);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(p);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null && !area.isRoadFlags()) {
|
||||
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_ROAD)) {
|
||||
@ -2695,7 +2695,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onVehicleDestroy(VehicleDestroyEvent event) {
|
||||
Location location = BukkitUtil.getLocation(event.getVehicle());
|
||||
Location location = BukkitUtil.adapt(event.getVehicle().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -2703,7 +2703,7 @@ import java.util.regex.Pattern;
|
||||
Entity attacker = event.getAttacker();
|
||||
if (attacker instanceof Player) {
|
||||
Player p = (Player) attacker;
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(p);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(p);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.road")) {
|
||||
@ -2740,7 +2740,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPotionSplash(PotionSplashEvent event) {
|
||||
ThrownPotion damager = event.getPotion();
|
||||
Location location = BukkitUtil.getLocation(damager);
|
||||
Location location = BukkitUtil.adapt(damager.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
@ -2770,7 +2770,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||
Entity damager = event.getDamager();
|
||||
Location location = BukkitUtil.getLocation(damager);
|
||||
Location location = BukkitUtil.adapt(damager.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
@ -2804,8 +2804,8 @@ import java.util.regex.Pattern;
|
||||
|
||||
private boolean entityDamage(Entity damager, Entity victim,
|
||||
EntityDamageEvent.DamageCause cause) {
|
||||
Location dloc = BukkitUtil.getLocation(damager);
|
||||
Location vloc = BukkitUtil.getLocation(victim);
|
||||
Location dloc = BukkitUtil.adapt(damager.getLocation());
|
||||
Location vloc = BukkitUtil.adapt(victim.getLocation());
|
||||
PlotArea dArea = dloc.getPlotArea();
|
||||
PlotArea vArea;
|
||||
if (dArea != null && dArea.contains(vloc.getX(), vloc.getZ())) {
|
||||
@ -2883,7 +2883,7 @@ import java.util.regex.Pattern;
|
||||
} else { // shooter is not player
|
||||
if (shooter instanceof BlockProjectileSource) {
|
||||
Location sLoc = BukkitUtil
|
||||
.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||
.adapt(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||
dplot = dArea.getPlot(sLoc);
|
||||
}
|
||||
player = null;
|
||||
@ -2892,7 +2892,7 @@ import java.util.regex.Pattern;
|
||||
player = null;
|
||||
}
|
||||
if (player != null) {
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
||||
|
||||
final com.sk89q.worldedit.world.entity.EntityType entityType;
|
||||
|
||||
@ -3051,13 +3051,13 @@ import java.util.regex.Pattern;
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerEggThrow(PlayerEggThrowEvent event) {
|
||||
Location location = BukkitUtil.getLocation(event.getEgg().getLocation());
|
||||
Location location = BukkitUtil.adapt(event.getEgg().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.road")) {
|
||||
@ -3082,13 +3082,13 @@ import java.util.regex.Pattern;
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void blockCreate(BlockPlaceEvent event) {
|
||||
Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
|
||||
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot != null) {
|
||||
if ((location.getY() > area.getMaxBuildHeight() || location.getY() < area
|
||||
@ -3149,7 +3149,7 @@ import java.util.regex.Pattern;
|
||||
if (event.getEntityType() != EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(event.getEntity());
|
||||
Location location = BukkitUtil.adapt(event.getEntity().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
@ -3170,7 +3170,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
@EventHandler public void onItemDrop(PlayerDropItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||
Location location = pp.getLocation();
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
@ -3196,7 +3196,7 @@ import java.util.regex.Pattern;
|
||||
LivingEntity ent = event.getEntity();
|
||||
if (ent instanceof Player) {
|
||||
Player player = (Player) ent;
|
||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||
Location location = pp.getLocation();
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
@ -3219,7 +3219,7 @@ import java.util.regex.Pattern;
|
||||
}
|
||||
|
||||
@EventHandler public void onDeath(final PlayerDeathEvent event) {
|
||||
Location location = BukkitUtil.getLocation(event.getEntity());
|
||||
Location location = BukkitUtil.adapt(event.getEntity().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
|
@ -112,11 +112,6 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
@Nonnull @Override public Location getLocation() {
|
||||
final Location location = super.getLocation();
|
||||
return location == null ? BukkitUtil.getLocation(this.player) : location;
|
||||
}
|
||||
|
||||
@Nonnull @Override public UUID getUUID() {
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
if (Settings.UUID.FORCE_LOWERCASE) {
|
||||
@ -135,7 +130,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
}
|
||||
|
||||
@Override public boolean canTeleport(@Nonnull final Location location) {
|
||||
final org.bukkit.Location to = BukkitUtil.getLocation(location);
|
||||
final org.bukkit.Location to = BukkitUtil.adapt(location);
|
||||
final org.bukkit.Location from = player.getLocation();
|
||||
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
|
||||
callEvent(event);
|
||||
@ -276,7 +271,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
}
|
||||
|
||||
@Override public Location getLocationFull() {
|
||||
return BukkitUtil.getLocationFull(this.player);
|
||||
return BukkitUtil.adaptComplete(this.player.getLocation());
|
||||
}
|
||||
|
||||
@Override public void setWeather(@Nonnull final PlotWeather weather) {
|
||||
@ -347,7 +342,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
||||
// this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, Material.AIR);
|
||||
} else {
|
||||
// this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, id.to(Material.class));
|
||||
this.player.playSound(BukkitUtil.getLocation(location),
|
||||
this.player.playSound(BukkitUtil.adapt(location),
|
||||
Sound.valueOf(BukkitAdapter.adapt(id).name()), Float.MAX_VALUE, 1f);
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||
if (X > bx && X < tx && Z > bz && Z < tz) {
|
||||
count(count, entity);
|
||||
} else {
|
||||
Plot other = area.getPlot(BukkitUtil.getLocation(location));
|
||||
Plot other = area.getPlot(BukkitUtil.adapt(location));
|
||||
if (plot.equals(other)) {
|
||||
count(count, entity);
|
||||
}
|
||||
@ -186,7 +186,7 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||
Entity[] entities1 = chunk.getEntities();
|
||||
for (Entity entity : entities1) {
|
||||
if (X == bx || X == tx || Z == bz || Z == tz) {
|
||||
Plot other = area.getPlot(BukkitUtil.getLocation(entity));
|
||||
Plot other = area.getPlot(BukkitUtil.adapt(entity.getLocation()));
|
||||
if (plot.equals(other)) {
|
||||
count(count, entity);
|
||||
}
|
||||
@ -411,7 +411,15 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||
|
||||
@Override public void clearAllEntities(Location pos1, Location pos2) {
|
||||
String world = pos1.getWorldName();
|
||||
List<Entity> entities = BukkitUtil.getEntities(world);
|
||||
|
||||
final World bukkitWorld = BukkitUtil.getWorld(world);
|
||||
final List<Entity> entities;
|
||||
if (bukkitWorld != null) {
|
||||
entities = new ArrayList<>(bukkitWorld.getEntities());
|
||||
} else {
|
||||
entities = new ArrayList<>();
|
||||
}
|
||||
|
||||
int bx = pos1.getX();
|
||||
int bz = pos1.getZ();
|
||||
int tx = pos2.getX();
|
||||
|
@ -31,12 +31,9 @@ import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.BlockUtil;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
@ -97,12 +94,11 @@ import org.bukkit.entity.WaterMob;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -114,27 +110,23 @@ import java.util.stream.Stream;
|
||||
@Singleton public class BukkitUtil extends WorldUtil {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitUtil.class.getSimpleName());
|
||||
|
||||
private static String lastString = null;
|
||||
private static World lastWorld = null;
|
||||
|
||||
private static Player lastPlayer = null;
|
||||
private static BukkitPlayer lastPlotPlayer = null;
|
||||
private final Collection<BlockType> tileEntityTypes = new HashSet<>();
|
||||
|
||||
@Inject public BukkitUtil(@Nonnull final RegionManager regionManager) {
|
||||
super(regionManager);
|
||||
}
|
||||
|
||||
public static void removePlayer(UUID uuid) {
|
||||
lastPlayer = null;
|
||||
lastPlotPlayer = null;
|
||||
// Make sure that it's removed internally
|
||||
PlotSquared.platform().getPlayerManager().removePlayer(uuid);
|
||||
}
|
||||
|
||||
public static PlotPlayer<Player> getPlayer(@Nonnull final OfflinePlayer op) {
|
||||
/**
|
||||
* Get a {@link PlotPlayer} from an {@link OfflinePlayer}. If the player is
|
||||
* online, it returns a complete player. If the player is offline, it creates
|
||||
* a fake player
|
||||
*
|
||||
* @param op Offline player
|
||||
* @return Plot player instance
|
||||
*/
|
||||
@Nonnull public static PlotPlayer<Player> adapt(@Nonnull final OfflinePlayer op) {
|
||||
if (op.isOnline()) {
|
||||
return getPlayer(op.getPlayer());
|
||||
return adapt(Objects.requireNonNull(op.getPlayer()));
|
||||
}
|
||||
final Player player = OfflinePlayerUtil.loadPlayer(op);
|
||||
player.loadData();
|
||||
@ -143,55 +135,83 @@ import java.util.stream.Stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the location.
|
||||
* Turn a Bukkit {@link Player} into a PlotSquared {@link PlotPlayer}
|
||||
*
|
||||
* @param location the location to check
|
||||
* @return plot if found, otherwise it creates a temporary plot
|
||||
* @see Plot
|
||||
* @param player Bukkit player
|
||||
* @return PlotSquared player
|
||||
*/
|
||||
public static Plot getPlot(org.bukkit.Location location) {
|
||||
if (location == null) {
|
||||
return null;
|
||||
@Nonnull public static BukkitPlayer adapt(@Nonnull final Player player) {
|
||||
final PlayerManager<?, ?> playerManager = PlotSquared.platform().getPlayerManager();
|
||||
return ((BukkitPlayerManager) playerManager).getPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a Bukkit {@link org.bukkit.Location} into a PlotSquared {@link Location}.
|
||||
* This only copies the 4-tuple (world,x,y,z) and does not include the yaw and the pitch
|
||||
*
|
||||
* @param location Bukkit location
|
||||
* @return PlotSquared location
|
||||
*/
|
||||
@Nonnull public static Location adapt(@Nonnull final org.bukkit.Location location) {
|
||||
return Location.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()),
|
||||
MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a Bukkit {@link org.bukkit.Location} into a PlotSquared {@link Location}.
|
||||
* This copies the entire 6-tuple (world,x,y,z,yaw,pitch).
|
||||
*
|
||||
* @param location Bukkit location
|
||||
* @return PlotSquared location
|
||||
*/
|
||||
@Nonnull public static Location adaptComplete(@Nonnull final org.bukkit.Location location) {
|
||||
return Location.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()),
|
||||
MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), location.getYaw(),
|
||||
location.getPitch());
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a PlotSquared {@link Location} into a Bukkit {@link org.bukkit.Location}.
|
||||
* This only copies the 4-tuple (world,x,y,z) and does not include the yaw and the pitch
|
||||
*
|
||||
* @param location PlotSquared location
|
||||
* @return Bukkit location
|
||||
*/
|
||||
@Nonnull public static org.bukkit.Location adapt(@Nonnull final Location location) {
|
||||
return new org.bukkit.Location((World) location.getWorld().getPlatformWorld(), location.getX(),
|
||||
location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Bukkit {@link World} from its name
|
||||
*
|
||||
* @param string World name
|
||||
* @return World if it exists, or {@code null}
|
||||
*/
|
||||
@Nullable public static World getWorld(@Nonnull final String string) {
|
||||
return Bukkit.getWorld(string);
|
||||
}
|
||||
|
||||
private static void ensureLoaded(@Nonnull final String world, final int x, final int z,
|
||||
@Nonnull final Consumer<Chunk> chunkConsumer) {
|
||||
PaperLib.getChunkAtAsync(Objects.requireNonNull(getWorld(world)),
|
||||
x >> 4, z >> 4, true)
|
||||
.thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
|
||||
}
|
||||
|
||||
private static void ensureLoaded(@Nonnull final Location location, @Nonnull final Consumer<Chunk> chunkConsumer) {
|
||||
PaperLib.getChunkAtAsync(adapt(location), true)
|
||||
.thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
|
||||
}
|
||||
|
||||
private static <T> void ensureMainThread(@Nonnull final Consumer<T> consumer,
|
||||
@Nonnull final T value) {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
consumer.accept(value);
|
||||
} else {
|
||||
Bukkit.getScheduler()
|
||||
.runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> consumer.accept(value));
|
||||
}
|
||||
return getLocation(location).getPlot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the player location.
|
||||
*
|
||||
* @param player the player to check
|
||||
* @return plot if found, otherwise it creates a temporary plot
|
||||
* @see #getPlot(org.bukkit.Location)
|
||||
* @see Plot
|
||||
*/
|
||||
public static Plot getPlot(Player player) {
|
||||
return getPlot(player.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotPlayer for an offline player.
|
||||
*
|
||||
* <p>Note that this will work if the player is offline, however not all
|
||||
* functionality will work.
|
||||
*
|
||||
* @param player the player to wrap
|
||||
* @return a {@code PlotPlayer}
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*/
|
||||
public static PlotPlayer<?> wrapPlayer(OfflinePlayer player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PlotPlayer for a player. The PlotPlayer is usually cached and
|
||||
* will provide useful functions relating to players.
|
||||
*
|
||||
* @param player the player to wrap
|
||||
* @return a {@code PlotPlayer}
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*/
|
||||
public static PlotPlayer<?> wrapPlayer(Player player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,145 +222,17 @@ import java.util.stream.Stream;
|
||||
* @return a {@code PlotPlayer}
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*/
|
||||
@Override public PlotPlayer<?> wrapPlayer(UUID uuid) {
|
||||
@Override @Nonnull public PlotPlayer<?> getPlayer(@Nonnull final UUID uuid) {
|
||||
return PlotPlayer.wrap(Bukkit.getOfflinePlayer(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of plots, which the player is able to build in.
|
||||
*
|
||||
* @param player player, for whom we're getting the plots
|
||||
* @return the number of allowed plots
|
||||
*/
|
||||
public static int getAllowedPlots(Player player) {
|
||||
PlotPlayer<?> plotPlayer = PlotPlayer.wrap(player);
|
||||
return plotPlayer.getAllowedPlots();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not a player is in a plot.
|
||||
*
|
||||
* @param player who we're checking for
|
||||
* @return true if the player is in a plot, false if not-
|
||||
*/
|
||||
public static boolean isInPlot(Player player) {
|
||||
return getPlot(player) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a collection containing the players plots.
|
||||
*
|
||||
* @param world Specify the world we want to select the plots from
|
||||
* @param player Player, for whom we're getting the plots
|
||||
* @return a set containing the players plots
|
||||
* @see Plot
|
||||
*/
|
||||
public static Set<Plot> getPlayerPlots(String world, Player player) {
|
||||
if (world == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
return BukkitPlayer.wrap(player).getPlots(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a player. The message supports color codes.
|
||||
*
|
||||
* @param player the recipient of the message
|
||||
* @param string the message
|
||||
* @see MainUtil#sendMessage(PlotPlayer, String)
|
||||
*/
|
||||
public static void sendMessage(Player player, String string) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player plot count.
|
||||
*
|
||||
* @param world Specify the world we want to select the plots from
|
||||
* @param player Player, for whom we're getting the plot count
|
||||
* @return the number of plots the player has
|
||||
*/
|
||||
public static int getPlayerPlotCount(String world, Player player) {
|
||||
if (world == null) {
|
||||
return 0;
|
||||
}
|
||||
return BukkitUtil.getPlayer(player).getPlotCount(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a player.
|
||||
*
|
||||
* @param player the recipient of the message
|
||||
* @param caption the message
|
||||
*/
|
||||
public static void sendMessage(Player player, Captions caption) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), caption);
|
||||
}
|
||||
|
||||
public static BukkitPlayer getPlayer(@Nonnull final Player player) {
|
||||
if (player == lastPlayer) {
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
final PlayerManager<?, ?> playerManager = PlotSquared.platform().getPlayerManager();
|
||||
return ((BukkitPlayerManager) playerManager).getPlayer(player);
|
||||
}
|
||||
|
||||
public static Location getLocation(final org.bukkit.Location location) {
|
||||
return Location.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()),
|
||||
MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()));
|
||||
}
|
||||
|
||||
public static Location getLocationFull(final org.bukkit.Location location) {
|
||||
return Location.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()),
|
||||
MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), location.getYaw(),
|
||||
location.getPitch());
|
||||
}
|
||||
|
||||
public static org.bukkit.Location getLocation(@Nonnull final Location location) {
|
||||
return new org.bukkit.Location((World) location.getWorld().getPlatformWorld(), location.getX(),
|
||||
location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
public static World getWorld(@Nonnull final String string) {
|
||||
return Bukkit.getWorld(string);
|
||||
}
|
||||
|
||||
public static String getWorld(@Nonnull final Entity entity) {
|
||||
return entity.getWorld().getName();
|
||||
}
|
||||
|
||||
public static List<Entity> getEntities(@Nonnull final String worldName) {
|
||||
World world = getWorld(worldName);
|
||||
if (world != null) {
|
||||
return world.getEntities();
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
public static Location getLocation(@Nonnull final Entity entity) {
|
||||
final org.bukkit.Location location = entity.getLocation();
|
||||
String world = location.getWorld().getName();
|
||||
return Location.at(world, location.getBlockX(), location.getBlockY(),
|
||||
location.getBlockZ());
|
||||
}
|
||||
|
||||
@Nonnull public static Location getLocationFull(@Nonnull final Entity entity) {
|
||||
final org.bukkit.Location location = entity.getLocation();
|
||||
return Location.at(location.getWorld().getName(), MathMan.roundInt(location.getX()),
|
||||
MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), location.getYaw(),
|
||||
location.getPitch());
|
||||
}
|
||||
|
||||
public static Material getMaterial(@Nonnull final BlockState plotBlock) {
|
||||
return BukkitAdapter.adapt(plotBlock.getBlockType());
|
||||
}
|
||||
|
||||
@Override public boolean isBlockSame(BlockState block1, BlockState block2) {
|
||||
@Override public boolean isBlockSame(@Nonnull final BlockState block1,
|
||||
@Nonnull final BlockState block2) {
|
||||
if (block1.equals(block2)) {
|
||||
return true;
|
||||
}
|
||||
Material mat1 = getMaterial(block1), mat2 = getMaterial(block2);
|
||||
final Material mat1 = BukkitAdapter.adapt(block1.getBlockType());
|
||||
final Material mat2 = BukkitAdapter.adapt(block2.getBlockType());
|
||||
return mat1 == mat2;
|
||||
}
|
||||
|
||||
@ -348,20 +240,22 @@ import java.util.stream.Stream;
|
||||
return getWorld(worldName) != null;
|
||||
}
|
||||
|
||||
@Override public void getBiome(String world, int x, int z, final Consumer<BiomeType> result) {
|
||||
@Override public void getBiome(@Nonnull final String world, final int x,
|
||||
final int z, @Nonnull final Consumer<BiomeType> result) {
|
||||
ensureLoaded(world, x, z,
|
||||
chunk -> result.accept(BukkitAdapter.adapt(getWorld(world).getBiome(x, z))));
|
||||
}
|
||||
|
||||
@Override public BiomeType getBiomeSynchronous(String world, int x, int z) {
|
||||
return BukkitAdapter.adapt(getWorld(world).getBiome(x, z));
|
||||
@Override @Nonnull public BiomeType getBiomeSynchronous(@Nonnull final String world,
|
||||
final int x, final int z) {
|
||||
return BukkitAdapter.adapt(Objects.requireNonNull(getWorld(world)).getBiome(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getHighestBlock(@Nonnull final String world, final int x, final int z,
|
||||
final IntConsumer result) {
|
||||
@Nonnull final IntConsumer result) {
|
||||
ensureLoaded(world, x, z, chunk -> {
|
||||
final World bukkitWorld = getWorld(world);
|
||||
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
|
||||
// Skip top and bottom block
|
||||
int air = 1;
|
||||
for (int y = bukkitWorld.getMaxHeight() - 1; y >= 0; y--) {
|
||||
@ -385,8 +279,10 @@ import java.util.stream.Stream;
|
||||
});
|
||||
}
|
||||
|
||||
@Override public int getHighestBlockSynchronous(String world, int x, int z) {
|
||||
final World bukkitWorld = getWorld(world);
|
||||
@Override @Nonnegative
|
||||
public int getHighestBlockSynchronous(@Nonnull final String world,
|
||||
final int x, final int z) {
|
||||
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
|
||||
// Skip top and bottom block
|
||||
int air = 1;
|
||||
for (int y = bukkitWorld.getMaxHeight() - 1; y >= 0; y--) {
|
||||
@ -407,19 +303,9 @@ import java.util.stream.Stream;
|
||||
return bukkitWorld.getMaxHeight() - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSign(@Nonnull final Location location, final Consumer<String[]> result) {
|
||||
ensureLoaded(location, chunk -> {
|
||||
final Block block = chunk.getWorld().getBlockAt(getLocation(location));
|
||||
if (block.getState() instanceof Sign) {
|
||||
Sign sign = (Sign) block.getState();
|
||||
result.accept(sign.getLines());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override @Nullable public String[] getSignSynchronous(@Nonnull final Location location) {
|
||||
Block block = getWorld(location.getWorldName())
|
||||
@Override @Nonnull
|
||||
public String[] getSignSynchronous(@Nonnull final Location location) {
|
||||
Block block = Objects.requireNonNull(getWorld(location.getWorldName()))
|
||||
.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
try {
|
||||
return TaskManager.getPlatformImplementation().sync(() -> {
|
||||
@ -435,7 +321,8 @@ import java.util.stream.Stream;
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override public Location getSpawn(@Nonnull final String world) {
|
||||
@Override @Nonnull
|
||||
public Location getSpawn(@Nonnull final String world) {
|
||||
final org.bukkit.Location temp = getWorld(world).getSpawnLocation();
|
||||
return Location.at(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(),
|
||||
temp.getYaw(), temp.getPitch());
|
||||
@ -495,27 +382,16 @@ import java.util.stream.Stream;
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean isBlockSolid(@Nonnull final BlockState block) {
|
||||
return block.getBlockType().getMaterial().isSolid();
|
||||
}
|
||||
|
||||
@Override public String getClosestMatchingName(@Nonnull final BlockState block) {
|
||||
try {
|
||||
return getMaterial(block).name();
|
||||
} catch (Exception ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override @Nullable
|
||||
public StringComparison<BlockState>.ComparisonResult getClosestBlock(String name) {
|
||||
@Override @Nonnull
|
||||
public StringComparison<BlockState>.ComparisonResult getClosestBlock(@Nonnull String name) {
|
||||
BlockState state = BlockUtil.get(name);
|
||||
return new StringComparison<BlockState>().new ComparisonResult(1, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiomes(@Nonnull final String worldName, @Nonnull final CuboidRegion region,
|
||||
@Nonnull final BiomeType biomeType) {
|
||||
public void setBiomes(@Nonnull final String worldName,
|
||||
@Nonnull final CuboidRegion region,
|
||||
@Nonnull final BiomeType biomeType) {
|
||||
final World world = getWorld(worldName);
|
||||
if (world == null) {
|
||||
logger.warn("[P2] An error occured while setting the biome because the world was null", new RuntimeException());
|
||||
@ -532,48 +408,54 @@ import java.util.stream.Stream;
|
||||
}
|
||||
}
|
||||
|
||||
public com.sk89q.worldedit.world.World getWeWorld(String world) {
|
||||
@Override @Nonnull public com.sk89q.worldedit.world.World getWeWorld(@Nonnull final String world) {
|
||||
return new BukkitWorld(Bukkit.getWorld(world));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBlock(@Nonnull final Location location, final Consumer<BlockState> result) {
|
||||
public void getBlock(@Nonnull final Location location,
|
||||
@Nonnull final Consumer<BlockState> result) {
|
||||
ensureLoaded(location, chunk -> {
|
||||
final World world = getWorld(location.getWorldName());
|
||||
final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
result.accept(BukkitAdapter.asBlockType(block.getType()).getDefaultState());
|
||||
final Block block = Objects.requireNonNull(world)
|
||||
.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
result.accept(Objects.requireNonNull(BukkitAdapter
|
||||
.asBlockType(block.getType())).getDefaultState());
|
||||
});
|
||||
}
|
||||
|
||||
@Override public BlockState getBlockSynchronous(@Nonnull final Location location) {
|
||||
@Override @Nonnull public BlockState getBlockSynchronous(@Nonnull final Location location) {
|
||||
final World world = getWorld(location.getWorldName());
|
||||
final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
return BukkitAdapter.asBlockType(block.getType()).getDefaultState();
|
||||
final Block block = Objects.requireNonNull(world)
|
||||
.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
return Objects.requireNonNull(BukkitAdapter
|
||||
.asBlockType(block.getType())).getDefaultState();
|
||||
}
|
||||
|
||||
@Override public String getMainWorld() {
|
||||
return Bukkit.getWorlds().get(0).getName();
|
||||
@Override @Nonnegative public double getHealth(@Nonnull final PlotPlayer player) {
|
||||
return Objects.requireNonNull(Bukkit
|
||||
.getPlayer(player.getUUID())).getHealth();
|
||||
}
|
||||
|
||||
@Override public double getHealth(PlotPlayer player) {
|
||||
return Bukkit.getPlayer(player.getUUID()).getHealth();
|
||||
@Override @Nonnegative public int getFoodLevel(@Nonnull final PlotPlayer<?> player) {
|
||||
return Objects.requireNonNull(Bukkit.getPlayer(player.getUUID()))
|
||||
.getFoodLevel();
|
||||
}
|
||||
|
||||
@Override public int getFoodLevel(PlotPlayer player) {
|
||||
return Bukkit.getPlayer(player.getUUID()).getFoodLevel();
|
||||
@Override public void setHealth(@Nonnull final PlotPlayer<?> player,
|
||||
@Nonnegative final double health) {
|
||||
Objects.requireNonNull(Bukkit.getPlayer(player.getUUID()))
|
||||
.setHealth(health);
|
||||
}
|
||||
|
||||
@Override public void setHealth(PlotPlayer player, double health) {
|
||||
Bukkit.getPlayer(player.getUUID()).setHealth(health);
|
||||
}
|
||||
|
||||
@Override public void setFoodLevel(PlotPlayer player, int foodLevel) {
|
||||
@Override public void setFoodLevel(@Nonnull final PlotPlayer<?> player,
|
||||
@Nonnegative final int foodLevel) {
|
||||
Bukkit.getPlayer(player.getUUID()).setFoodLevel(foodLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override @Nonnull
|
||||
public Set<com.sk89q.worldedit.world.entity.EntityType> getTypesInCategory(
|
||||
final String category) {
|
||||
@Nonnull final String category) {
|
||||
final Collection<Class<?>> allowedInterfaces = new HashSet<>();
|
||||
switch (category) {
|
||||
case "animal": {
|
||||
@ -653,8 +535,7 @@ import java.util.stream.Stream;
|
||||
return types;
|
||||
}
|
||||
|
||||
private final Collection<BlockType> tileEntityTypes = new HashSet<>();
|
||||
@Override public Collection<BlockType> getTileEntityTypes() {
|
||||
@Override @Nonnull public Collection<BlockType> getTileEntityTypes() {
|
||||
if (this.tileEntityTypes.isEmpty()) {
|
||||
// Categories
|
||||
tileEntityTypes.addAll(BlockCategories.BANNERS.getAll());
|
||||
@ -679,30 +560,12 @@ import java.util.stream.Stream;
|
||||
return this.tileEntityTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileEntityCount(String world, BlockVector2 chunk) {
|
||||
return Bukkit.getWorld(world).getChunkAt(chunk.getBlockX(), chunk.getBlockZ())
|
||||
@Override @Nonnegative
|
||||
public int getTileEntityCount(@Nonnull final String world,
|
||||
@Nonnull final BlockVector2 chunk) {
|
||||
return Objects.requireNonNull(getWorld(world)).
|
||||
getChunkAt(chunk.getBlockX(), chunk.getBlockZ())
|
||||
.getTileEntities().length;
|
||||
}
|
||||
|
||||
private static void ensureLoaded(final String world, final int x, final int z,
|
||||
final Consumer<Chunk> chunkConsumer) {
|
||||
PaperLib.getChunkAtAsync(getWorld(world), x >> 4, z >> 4, true)
|
||||
.thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
|
||||
}
|
||||
|
||||
private static void ensureLoaded(final Location location, final Consumer<Chunk> chunkConsumer) {
|
||||
PaperLib.getChunkAtAsync(getLocation(location), true)
|
||||
.thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
|
||||
}
|
||||
|
||||
private static <T> void ensureMainThread(final Consumer<T> consumer, final T value) {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
consumer.accept(value);
|
||||
} else {
|
||||
Bukkit.getScheduler()
|
||||
.runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> consumer.accept(value));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class ContentMap {
|
||||
|
||||
void saveEntitiesOut(Chunk chunk, CuboidRegion region) {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
int x = location.getX();
|
||||
int z = location.getZ();
|
||||
if (BukkitChunkManager.isIn(region, x, z)) {
|
||||
@ -99,7 +99,7 @@ public class ContentMap {
|
||||
void saveEntitiesIn(Chunk chunk, CuboidRegion region, int offsetX, int offsetZ,
|
||||
boolean delete) {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
int x = location.getX();
|
||||
int z = location.getZ();
|
||||
if (!BukkitChunkManager.isIn(region, x, z)) {
|
||||
|
@ -137,7 +137,7 @@ public interface PlotPlatform<P> extends ILogger {
|
||||
*
|
||||
* @param player the player to remove
|
||||
*/
|
||||
void unregister(PlotPlayer player);
|
||||
void unregister(PlotPlayer<?> player);
|
||||
|
||||
/**
|
||||
* Gets the generator wrapper for a world (world) and generator (name).
|
||||
|
@ -114,7 +114,7 @@ public class PlotListener {
|
||||
++value.count;
|
||||
if (value.count == value.interval) {
|
||||
value.count = 0;
|
||||
PlotPlayer<?> player = PlotSquared.platform().getWorldUtil().wrapPlayer(entry.getKey());
|
||||
PlotPlayer<?> player = PlotSquared.platform().getWorldUtil().getPlayer(entry.getKey());
|
||||
if (player == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
|
@ -1827,7 +1827,7 @@ public class Plot {
|
||||
DBFunc.createPlotAndSettings(this, () -> {
|
||||
PlotArea plotworld = Plot.this.area;
|
||||
if (notify && plotworld.isAutoMerge()) {
|
||||
PlotPlayer player = this.worldUtil.wrapPlayer(uuid);
|
||||
PlotPlayer player = this.worldUtil.getPlayer(uuid);
|
||||
PlotMergeEvent event = this.eventDispatcher
|
||||
.callMerge(this, Direction.ALL, Integer.MAX_VALUE, player);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
|
@ -55,11 +55,11 @@ import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@ -154,8 +154,9 @@ public class MainUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void upload(UUID uuid, String file, String extension,
|
||||
final RunnableVal<OutputStream> writeTask, final RunnableVal<URL> whenDone) {
|
||||
public static void upload(@Nullable UUID uuid, @Nullable final String file,
|
||||
@Nonnull final String extension, @Nullable final RunnableVal<OutputStream> writeTask,
|
||||
@Nonnull final RunnableVal<URL> whenDone) {
|
||||
if (writeTask == null) {
|
||||
TaskManager.runTask(whenDone);
|
||||
return;
|
||||
|
@ -41,8 +41,10 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -68,58 +70,149 @@ public abstract class WorldUtil {
|
||||
this.regionManager = regionManager;
|
||||
}
|
||||
|
||||
public abstract String getMainWorld();
|
||||
|
||||
public abstract boolean isWorld(String worldName);
|
||||
|
||||
public abstract void getSign(Location location, Consumer<String[]> result);
|
||||
/**
|
||||
* Check if a given world name corresponds to a real world
|
||||
*
|
||||
* @param worldName World name
|
||||
* @return {@code true} if there exists a world with the given world name,
|
||||
* {@code false} if not
|
||||
*/
|
||||
public abstract boolean isWorld(@Nonnull String worldName);
|
||||
|
||||
/**
|
||||
* @param location Sign location
|
||||
* @return Sign content (or an empty string array if the block is not a sign)
|
||||
* @deprecated May result in synchronous chunk loading
|
||||
*/
|
||||
@Deprecated public abstract String[] getSignSynchronous(Location location);
|
||||
|
||||
public abstract Location getSpawn(String world);
|
||||
|
||||
public abstract void setSpawn(Location location);
|
||||
|
||||
public abstract void saveWorld(String world);
|
||||
|
||||
public abstract String getClosestMatchingName(BlockState plotBlock);
|
||||
|
||||
public abstract boolean isBlockSolid(BlockState block);
|
||||
|
||||
public abstract StringComparison<BlockState>.ComparisonResult getClosestBlock(String name);
|
||||
|
||||
public abstract void getBiome(String world, int x, int z, Consumer<BiomeType> result);
|
||||
@Deprecated @Nonnull public abstract String[] getSignSynchronous(@Nonnull Location location);
|
||||
|
||||
/**
|
||||
* @deprecated May result in synchronous chunk loading
|
||||
* Get the world spawn location
|
||||
*
|
||||
* @param world World name
|
||||
* @return World spawn location
|
||||
*/
|
||||
@Deprecated public abstract BiomeType getBiomeSynchronous(String world, int x, int z);
|
||||
|
||||
public abstract void getBlock(Location location, Consumer<BlockState> result);
|
||||
@Nonnull public abstract Location getSpawn(@Nonnull String world);
|
||||
|
||||
/**
|
||||
* @deprecated May result in synchronous chunk loading
|
||||
* Set the world spawn location
|
||||
*
|
||||
* @param location New spawn
|
||||
*/
|
||||
@Deprecated public abstract BlockState getBlockSynchronous(Location location);
|
||||
|
||||
public abstract void getHighestBlock(String world, int x, int z, final IntConsumer result);
|
||||
public abstract void setSpawn(@Nonnull Location location);
|
||||
|
||||
/**
|
||||
* @deprecated May result in synchronous chunk loading
|
||||
* Save a world
|
||||
*
|
||||
* @param world World name
|
||||
*/
|
||||
@Deprecated public abstract int getHighestBlockSynchronous(String world, int x, int z);
|
||||
public abstract void saveWorld(@Nonnull String world);
|
||||
|
||||
public abstract void setSign(String world, int x, int y, int z, String[] lines);
|
||||
/**
|
||||
* Get a string comparison with the closets block state matching a given string
|
||||
*
|
||||
* @param name Block name
|
||||
* @return Comparison result containing the closets matching block
|
||||
*/
|
||||
@Nonnull public abstract StringComparison<BlockState>.ComparisonResult getClosestBlock(
|
||||
@Nonnull String name);
|
||||
|
||||
public abstract void setBiomes(String world, CuboidRegion region, BiomeType biome);
|
||||
/**
|
||||
* Get the biome in a given chunk, asynchronously
|
||||
*
|
||||
* @param world World
|
||||
* @param x Chunk X coordinate
|
||||
* @param z Chunk Z coordinate
|
||||
* @param result Result consumer
|
||||
*/
|
||||
public abstract void getBiome(@Nonnull String world, int x, int z,
|
||||
@Nonnull Consumer<BiomeType> result);
|
||||
|
||||
public abstract com.sk89q.worldedit.world.World getWeWorld(String world);
|
||||
/**
|
||||
* Get the biome in a given chunk, asynchronously
|
||||
*
|
||||
* @param world World
|
||||
* @param x Chunk X coordinate
|
||||
* @param z Chunk Z coordinate
|
||||
* @return Biome
|
||||
* @deprecated Use {@link #getBiome(String, int, int, Consumer)}
|
||||
*/
|
||||
@Deprecated @Nonnull public abstract BiomeType getBiomeSynchronous(@Nonnull String world, int x,
|
||||
int z);
|
||||
|
||||
public void upload(@Nonnull final Plot plot, UUID uuid, String file,
|
||||
RunnableVal<URL> whenDone) {
|
||||
/**
|
||||
* Get the block at a given location (asynchronously)
|
||||
*
|
||||
* @param location Block location
|
||||
* @param result Result consumer
|
||||
*/
|
||||
public abstract void getBlock(@Nonnull Location location, @Nonnull Consumer<BlockState> result);
|
||||
|
||||
/**
|
||||
* Get the block at a given location (synchronously)
|
||||
*
|
||||
* @param location Block location
|
||||
* @return Result
|
||||
* @deprecated Use {@link #getBlock(Location, Consumer)}
|
||||
*/
|
||||
@Deprecated @Nonnull public abstract BlockState getBlockSynchronous(@Nonnull Location location);
|
||||
|
||||
/**
|
||||
* Get the Y coordinate of the highest non-air block in the world, asynchronously
|
||||
*
|
||||
* @param world World name
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
* @param result Result consumer
|
||||
*/
|
||||
public abstract void getHighestBlock(@Nonnull String world, int x, int z,
|
||||
@Nonnull IntConsumer result);
|
||||
|
||||
|
||||
/**
|
||||
* Get the Y coordinate of the highest non-air block in the world, synchronously
|
||||
*
|
||||
* @param world World name
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
* @return Result
|
||||
* @deprecated Use {@link #getHighestBlock(String, int, int, IntConsumer)}
|
||||
*/
|
||||
@Deprecated @Nonnegative
|
||||
public abstract int getHighestBlockSynchronous(@Nonnull String world, int x, int z);
|
||||
|
||||
/**
|
||||
* Set the text in a sign
|
||||
*
|
||||
* @param world World name
|
||||
* @param x X coordinate
|
||||
* @param y Y coordinate
|
||||
* @param z Z coordinate
|
||||
* @param lines Sign text
|
||||
*/
|
||||
public abstract void setSign(@Nonnull String world, int x, int y, int z,
|
||||
@Nonnull String[] lines);
|
||||
|
||||
/**
|
||||
* Set the biome in a region
|
||||
*
|
||||
* @param world World name
|
||||
* @param region Region
|
||||
* @param biome New biome
|
||||
*/
|
||||
public abstract void setBiomes(@Nonnull String world, @Nonnull CuboidRegion region,
|
||||
@Nonnull BiomeType biome);
|
||||
|
||||
/**
|
||||
* Get the WorldEdit {@link com.sk89q.worldedit.world.World} corresponding to a world name
|
||||
*
|
||||
* @param world World name
|
||||
* @return World object
|
||||
*/
|
||||
@Nonnull public abstract com.sk89q.worldedit.world.World getWeWorld(@Nonnull String world);
|
||||
|
||||
public void upload(@Nonnull final Plot plot, @Nullable final UUID uuid,
|
||||
@Nullable final String file, @Nonnull final RunnableVal<URL> whenDone) {
|
||||
plot.getHome(home -> MainUtil.upload(uuid, file, "zip", new RunnableVal<OutputStream>() {
|
||||
@Override public void run(OutputStream output) {
|
||||
try (final ZipOutputStream zos = new ZipOutputStream(output)) {
|
||||
@ -189,7 +282,7 @@ public abstract class WorldUtil {
|
||||
}, whenDone));
|
||||
}
|
||||
|
||||
public File getDat(String world) {
|
||||
@Nullable final File getDat(@Nonnull final String world) {
|
||||
File file = new File(
|
||||
PlotSquared.platform().getWorldContainer() + File.separator + world + File.separator
|
||||
+ "level.dat");
|
||||
@ -199,8 +292,8 @@ public abstract class WorldUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public File getMcr(String world, int x, int z) {
|
||||
File file = new File(PlotSquared.platform().getWorldContainer(),
|
||||
@Nullable private File getMcr(@Nonnull final String world, final int x, final int z) {
|
||||
final File file = new File(PlotSquared.platform().getWorldContainer(),
|
||||
world + File.separator + "region" + File.separator + "r." + x + '.' + z + ".mca");
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
@ -208,22 +301,78 @@ public abstract class WorldUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract boolean isBlockSame(BlockState block1, BlockState block2);
|
||||
/**
|
||||
* Check if two blocks are the same type)
|
||||
*
|
||||
* @param block1 First block
|
||||
* @param block2 Second block
|
||||
* @return {@code true} if the blocks have the same type, {@code false} if not
|
||||
*/
|
||||
public abstract boolean isBlockSame(@Nonnull BlockState block1, @Nonnull BlockState block2);
|
||||
|
||||
public abstract PlotPlayer wrapPlayer(UUID uuid);
|
||||
/**
|
||||
* Get a player object for the player with the given UUID
|
||||
*
|
||||
* @param uuid Player UUID
|
||||
* @return Player object
|
||||
*/
|
||||
@Nonnull public abstract PlotPlayer<?> getPlayer(@Nonnull UUID uuid);
|
||||
|
||||
public abstract double getHealth(PlotPlayer player);
|
||||
/**
|
||||
* Get the player health
|
||||
*
|
||||
* @param player Player
|
||||
* @return Non-negative health
|
||||
*/
|
||||
@Nonnegative public abstract double getHealth(@Nonnull PlotPlayer<?> player);
|
||||
|
||||
public abstract void setHealth(PlotPlayer player, double health);
|
||||
/**
|
||||
* Set the player health
|
||||
*
|
||||
* @param player Player health
|
||||
* @param health Non-negative health
|
||||
*/
|
||||
public abstract void setHealth(@Nonnull PlotPlayer<?> player, @Nonnegative double health);
|
||||
|
||||
public abstract int getFoodLevel(PlotPlayer player);
|
||||
/**
|
||||
* Get the player food level
|
||||
*
|
||||
* @param player Player
|
||||
* @return Non-negative food level
|
||||
*/
|
||||
@Nonnegative public abstract int getFoodLevel(@Nonnull PlotPlayer<?> player);
|
||||
|
||||
public abstract void setFoodLevel(PlotPlayer player, int foodLevel);
|
||||
/**
|
||||
* Set the player food level
|
||||
*
|
||||
* @param player Player food level
|
||||
* @param foodLevel Non-negative food level
|
||||
*/
|
||||
public abstract void setFoodLevel(@Nonnull PlotPlayer<?> player, @Nonnegative int foodLevel);
|
||||
|
||||
public abstract Set<EntityType> getTypesInCategory(final String category);
|
||||
/**
|
||||
* Get all entity types belonging to an entity category
|
||||
*
|
||||
* @param category Entity category
|
||||
* @return Set containing all entities belonging to the given category
|
||||
*/
|
||||
@Nonnull public abstract Set<EntityType> getTypesInCategory(@Nonnull String category);
|
||||
|
||||
public abstract Collection<BlockType> getTileEntityTypes();
|
||||
/**
|
||||
* Get all recognized tile entity types
|
||||
*
|
||||
* @return Collection containing all known tile entity types
|
||||
*/
|
||||
@Nonnull public abstract Collection<BlockType> getTileEntityTypes();
|
||||
|
||||
public abstract int getTileEntityCount(String world, BlockVector2 chunk);
|
||||
/**
|
||||
* Get the tile entity count in a chunk
|
||||
*
|
||||
* @param world World
|
||||
* @param chunk Chunk coordinates
|
||||
* @return Tile entity count
|
||||
*/
|
||||
@Nonnegative public abstract int getTileEntityCount(@Nonnull String world,
|
||||
@Nonnull BlockVector2 chunk);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user