use of org.bukkit.Chunk in project Essentials by EssentialsX.
the class Commandremove method removeHandler.
private void removeHandler(CommandSource sender, List<String> types, List<String> customTypes, World world, int radius) {
int removed = 0;
if (radius > 0) {
radius *= radius;
}
ArrayList<ToRemove> removeTypes = new ArrayList<>();
ArrayList<Mob> customRemoveTypes = new ArrayList<>();
for (String s : types) {
removeTypes.add(ToRemove.valueOf(s));
}
boolean warnUser = false;
for (String s : customTypes) {
Mob mobType = Mob.fromName(s);
if (mobType == null) {
warnUser = true;
} else {
customRemoveTypes.add(mobType);
}
}
if (warnUser) {
sender.sendMessage(tl("invalidMob"));
}
for (Chunk chunk : world.getLoadedChunks()) {
for (Entity e : chunk.getEntities()) {
if (radius > 0) {
if (sender.getPlayer().getLocation().distanceSquared(e.getLocation()) > radius) {
continue;
}
}
if (e instanceof HumanEntity) {
continue;
}
for (ToRemove toRemove : removeTypes) {
// We should skip any TAMED animals unless we are specifially targetting them.
if (e instanceof Tameable && ((Tameable) e).isTamed() && !removeTypes.contains(ToRemove.TAMED)) {
continue;
}
// We should skip any NAMED animals unless we are specifially targetting them.
if (e instanceof LivingEntity && e.getCustomName() != null && !removeTypes.contains(ToRemove.NAMED)) {
continue;
}
switch(toRemove) {
case TAMED:
if (e instanceof Tameable && ((Tameable) e).isTamed()) {
e.remove();
removed++;
}
break;
case NAMED:
if (e instanceof LivingEntity && e.getCustomName() != null) {
e.remove();
removed++;
}
break;
case DROPS:
if (e instanceof Item) {
e.remove();
removed++;
}
break;
case ARROWS:
if (e instanceof Projectile) {
e.remove();
removed++;
}
break;
case BOATS:
if (e instanceof Boat) {
e.remove();
removed++;
}
break;
case MINECARTS:
if (e instanceof Minecart) {
e.remove();
removed++;
}
break;
case XP:
if (e instanceof ExperienceOrb) {
e.remove();
removed++;
}
break;
case PAINTINGS:
if (e instanceof Painting) {
e.remove();
removed++;
}
break;
case ITEMFRAMES:
if (e instanceof ItemFrame) {
e.remove();
removed++;
}
break;
case ENDERCRYSTALS:
if (e instanceof EnderCrystal) {
e.remove();
removed++;
}
break;
case AMBIENT:
if (e instanceof Flying) {
e.remove();
removed++;
}
break;
case HOSTILE:
case MONSTERS:
if (e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime) {
e.remove();
removed++;
}
break;
case PASSIVE:
case ANIMALS:
if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Ambient) {
e.remove();
removed++;
}
break;
case MOBS:
if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime || e instanceof Ambient) {
e.remove();
removed++;
}
break;
case ENTITIES:
case ALL:
if (e instanceof Entity) {
e.remove();
removed++;
}
break;
case CUSTOM:
for (Mob type : customRemoveTypes) {
if (e.getType() == type.getType()) {
e.remove();
removed++;
}
}
break;
}
}
}
}
sender.sendMessage(tl("removed", removed));
}
use of org.bukkit.Chunk in project LandLord by SpatiumPrinceps.
the class LandMap method buildMap.
private String[] buildMap(Player p) {
final int radius = 3;
String[][] mapBoard = getMapDir(getPlayerDirection(p));
String[] mapRows = new String[mapBoard.length + 3];
if (!currChunk.equals(mapViewer.getLocation().getChunk())) {
updateMap();
}
Map<Chunk, OwnedLand> nearby = plugin.getWgHandler().getNearbyLands(p.getLocation(), radius, radius);
for (int z = 0; z < mapBoard.length; z++) {
StringBuilder row = new StringBuilder();
for (int x = 0; x < mapBoard[z].length; x++) {
int xx = x - radius;
int zz = z - radius;
OwnedLand land = nearby.get(p.getWorld().getChunkAt(xx + p.getLocation().getChunk().getX(), zz + p.getLocation().getChunk().getZ()));
String currSpot = mapBoard[z][x];
if (land != null) {
if (land.getWGLand().getOwners().getUniqueIds().contains(p.getUniqueId())) {
currSpot = ChatColor.GREEN + currSpot;
} else if (land.getWGLand().getMembers().getUniqueIds().contains(p.getUniqueId())) {
currSpot = ChatColor.YELLOW + currSpot;
} else {
currSpot = ChatColor.RED + currSpot;
}
} else {
if (currSpot.equals("∞") || currSpot.equals("\u2062")) {
currSpot = ChatColor.RESET + currSpot;
} else {
currSpot = ChatColor.GRAY + currSpot;
}
}
row.append(currSpot);
}
mapRows[z] = row.toString();
}
LangManager messages = plugin.getLangManager();
final String yours = messages.getRawString("Commands.LandMap.yours");
final String friends = messages.getRawString("Commands.LandMap.friends");
final String others = messages.getRawString("Commands.LandMap.others");
if (yours.length() <= 25) {
mapRows[mapRows.length - 3] = ChatColor.GREEN + "█- " + yours;
} else {
mapRows[mapRows.length - 3] = ChatColor.GREEN + "█- " + yours.substring(0, 25);
}
if (friends.length() <= 25) {
mapRows[mapRows.length - 2] = ChatColor.YELLOW + "█- " + friends;
} else {
mapRows[mapRows.length - 2] = ChatColor.YELLOW + "█- " + friends.substring(0, 25);
}
if (others.length() <= 25) {
mapRows[mapRows.length - 1] = ChatColor.RED + "█- " + others;
} else {
mapRows[mapRows.length - 1] = ChatColor.RED + "█- " + others.substring(0, 25);
}
return mapRows;
}
use of org.bukkit.Chunk in project LandLord by SpatiumPrinceps.
the class RemoveAdvertise method onAdvertise.
public void onAdvertise(Player player, String landname) {
if (this.worldDisabled(player)) {
player.sendMessage(lm.getString("Disabled-World"));
return;
}
Chunk chunk = null;
if (landname.equals("this")) {
chunk = player.getWorld().getChunkAt(player.getLocation());
} else {
String[] split = landname.split("_");
try {
int x = Integer.valueOf(split[1]);
int z = Integer.valueOf(split[2]);
chunk = Bukkit.getWorld(split[0]).getChunkAt(x, z);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
OwnedLand pr = plugin.getWgHandler().getRegion(chunk);
if (pr == null) {
player.sendMessage(lm.getString("Commands.Advertise.notOwnFreeLand"));
return;
}
if (!pr.isOwner(player.getUniqueId())) {
player.sendMessage(lm.getString("Commands.Advertise.notOwn").replace("%owner%", pr.printOwners()));
return;
}
Offers offer = plugin.getPlayerManager().getOffer(pr.getName());
if (offer == null) {
player.sendMessage(lm.getString("Commands.RemoveAdvertise.noAdvertise").replace("%landname%", pr.getName()));
} else {
plugin.getPlayerManager().removeOffer(offer.getLandname());
player.sendMessage(lm.getString("Commands.RemoveAdvertise.success").replace("%landname%", landname));
}
}
use of org.bukkit.Chunk in project LandLord by SpatiumPrinceps.
the class Unfriend method onUnfriend.
public void onUnfriend(Player player, String[] names) {
if (this.worldDisabled(player)) {
player.sendMessage(lm.getString("Disabled-World"));
return;
}
Chunk chunk = player.getWorld().getChunkAt(player.getLocation());
OwnedLand land = plugin.getWgHandler().getRegion(chunk);
if (land != null) {
if (!land.isOwner(player.getUniqueId()) && !player.hasPermission("landlord.admin.modifyfriends")) {
player.sendMessage(lm.getString("Commands.Unfriend.notOwn").replace("%owner%", land.printOwners()));
return;
}
for (String target : names) {
plugin.getPlayerManager().getOfflinePlayer(target, lPlayer -> {
if (lPlayer == null) {
// Failure
player.sendMessage(lm.getString("Commands.Unfriend.noPlayer").replace("%players%", Arrays.asList(names).toString()));
} else {
// Success
land.removeFriend(lPlayer.getUuid());
player.sendMessage(lm.getString("Commands.Unfriend.success").replace("%players%", Arrays.asList(names).toString()));
}
});
}
new BukkitRunnable() {
@Override
public void run() {
plugin.getMapManager().updateAll();
}
}.runTaskLater(plugin, 60L);
}
}
use of org.bukkit.Chunk in project LandLord by SpatiumPrinceps.
the class SetHome method onSetHome.
// requires permission landlord.player.home
public void onSetHome(Player player) {
if (!Options.enabled_homes()) {
player.sendMessage(lm.getString("Commands.SetHome.disabled"));
return;
}
if (this.worldDisabled(player)) {
player.sendMessage(lm.getString("Disabled-World"));
return;
}
Chunk chunk = player.getWorld().getChunkAt(player.getLocation());
OwnedLand land = plugin.getWgHandler().getRegion(chunk);
if (land == null) {
player.sendMessage(lm.getString("Commands.SetHome.nullLand"));
return;
}
if (!land.isOwner(player.getUniqueId())) {
player.sendMessage(lm.getString("Commands.SetHome.notOwn").replace("%owner%", land.printOwners()));
return;
}
plugin.getPlayerManager().get(player.getUniqueId()).setHome(player.getLocation());
player.sendMessage(lm.getString("Commands.SetHome.success"));
}
Aggregations