Added User#spawnParticle(Particle, Particle.DustOptions, int, int, int)

This commit is contained in:
Florian CUNY 2018-09-03 15:53:16 +02:00
parent 1c24619450
commit a7d001d578
2 changed files with 45 additions and 39 deletions

View File

@ -86,15 +86,15 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
getIslands().getIslandAt(user.getLocation()).ifPresent(island -> { getIslands().getIslandAt(user.getLocation()).ifPresent(island -> {
// Draw the island protected area // Draw the island protected area
drawZone(user.getPlayer(), Particle.BARRIER, null, island.getCenter(), island.getProtectionRange()); drawZone(user, Particle.BARRIER, null, island.getCenter(), island.getProtectionRange());
// Draw the default protected area if island protected zone is different // Draw the default protected area if island protected zone is different
if (island.getProtectionRange() != getPlugin().getIWM().getIslandProtectionRange(getWorld())) { if (island.getProtectionRange() != getPlugin().getIWM().getIslandProtectionRange(getWorld())) {
drawZone(user.getPlayer(), Particle.VILLAGER_HAPPY, null, island.getCenter(), getPlugin().getIWM().getIslandProtectionRange(getWorld())); drawZone(user, Particle.VILLAGER_HAPPY, null, island.getCenter(), getPlugin().getIWM().getIslandProtectionRange(getWorld()));
} }
// Draw the island area // Draw the island area
drawZone(user.getPlayer(), Particle.REDSTONE, new Particle.DustOptions(Color.GRAY, 1.0F),island.getCenter(), island.getRange()); drawZone(user, Particle.REDSTONE, new Particle.DustOptions(Color.GRAY, 1.0F),island.getCenter(), island.getRange());
}); });
}, 20, 30)); }, 20, 30));
} }
@ -105,33 +105,17 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
display.remove(user); display.remove(user);
} }
private void drawZone(Player player, Particle particle, Particle.DustOptions dustOptions, Location center, int range) { private void drawZone(User user, Particle particle, Particle.DustOptions dustOptions, Location center, int range) {
if (particle.equals(Particle.REDSTONE) && dustOptions == null) {
// Security check that will avoid later unexpected exceptions.
throw new IllegalArgumentException("A non-null Particle.DustOptions must be provided when using Particle.REDSTONE.");
}
// Get player Y coordinate // Get player Y coordinate
int playerY = player.getLocation().getBlockY() + 1; int playerY = user.getPlayer().getLocation().getBlockY() + 1;
// Draw 3 "stages" (one line below, at and above player's y coordinate) // Draw 3 "stages" (one line below, at and above player's y coordinate)
for (int stage = -1 ; stage <= 1 ; stage++) { for (int stage = -1 ; stage <= 1 ; stage++) {
for (int i = -range ; i <= range ; i++) { for (int i = -range ; i <= range ; i++) {
spawnParticle(player, particle, dustOptions, center.getBlockX() + i, playerY + stage, center.getBlockZ() + range); user.spawnParticle(particle, dustOptions, center.getBlockX() + i, playerY + stage, center.getBlockZ() + range);
spawnParticle(player, particle, dustOptions, center.getBlockX() + i, playerY + stage, center.getBlockZ() - range); user.spawnParticle(particle, dustOptions, center.getBlockX() + i, playerY + stage, center.getBlockZ() - range);
spawnParticle(player, particle, dustOptions, center.getBlockX() + range, playerY + stage, center.getBlockZ() + i); user.spawnParticle(particle, dustOptions, center.getBlockX() + range, playerY + stage, center.getBlockZ() + i);
spawnParticle(player, particle, dustOptions, center.getBlockX() - range, playerY + stage, center.getBlockZ() + i); user.spawnParticle(particle, dustOptions, center.getBlockX() - range, playerY + stage, center.getBlockZ() + i);
}
}
}
private void spawnParticle(Player player, Particle particle, Particle.DustOptions dustOptions, int x, int y, int z) {
// Check if this particle is beyond the viewing distance of the server
if (player.getLocation().toVector().distanceSquared(new Vector(x,y,z)) < (Bukkit.getServer().getViewDistance()*256*Bukkit.getServer().getViewDistance())) {
if (particle.equals(Particle.REDSTONE)) {
player.spawnParticle(particle, x, y, z, 1, 0, 0, 0, 1, dustOptions);
} else {
player.spawnParticle(particle, x, y, z, 1);
} }
} }
} }

View File

@ -6,17 +6,13 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.*;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.util.Vector;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
/** /**
@ -329,6 +325,40 @@ public class User {
return player.performCommand(command); return player.performCommand(command);
} }
/**
* Checks if a user is in one of the game worlds
* @return true if user is, false if not
*/
public boolean inWorld() {
return plugin.getIWM().inWorld(getLocation());
}
/**
* Spawn particles to the player.
* They are only displayed if they are within the server's view distance.
* @param particle Particle to display.
* @param dustOptions Particle.DustOptions for the particle to display.
* Cannot be null when particle is {@link Particle#REDSTONE}.
* @param x X coordinate of the particle to display.
* @param y Y coordinate of the particle to display.
* @param z Z coordinate of the particle to display.
*/
public void spawnParticle(Particle particle, Particle.DustOptions dustOptions, int x, int y, int z) {
if (particle.equals(Particle.REDSTONE) && dustOptions == null) {
// Security check that will avoid later unexpected exceptions.
throw new IllegalArgumentException("A non-null Particle.DustOptions must be provided when using Particle.REDSTONE as particle.");
}
// Check if this particle is beyond the viewing distance of the server
if (player.getLocation().toVector().distanceSquared(new Vector(x,y,z)) < (Bukkit.getServer().getViewDistance()*256*Bukkit.getServer().getViewDistance())) {
if (particle.equals(Particle.REDSTONE)) {
player.spawnParticle(particle, x, y, z, 1, 0, 0, 0, 1, dustOptions);
} else {
player.spawnParticle(particle, x, y, z, 1);
}
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.Object#hashCode() * @see java.lang.Object#hashCode()
*/ */
@ -358,12 +388,4 @@ public class User {
return other.playerUUID == null; return other.playerUUID == null;
} else return playerUUID.equals(other.playerUUID); } else return playerUUID.equals(other.playerUUID);
} }
/**
* Checks if a user is in one of the game worlds
* @return true if user is, false if not
*/
public boolean inWorld() {
return plugin.getIWM().inWorld(getLocation());
}
} }