use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class BukkitRegionManager method regenerateRegion.
@Override
public boolean regenerateRegion(@NonNull final Location pos1, @NonNull final Location pos2, final boolean ignoreAugment, @Nullable final Runnable whenDone) {
final BukkitWorld world = (BukkitWorld) worldUtil.getWeWorld(pos1.getWorldName());
final int p1x = pos1.getX();
final int p1z = pos1.getZ();
final int p2x = pos2.getX();
final int p2z = pos2.getZ();
final int bcx = p1x >> 4;
final int bcz = p1z >> 4;
final int tcx = p2x >> 4;
final int tcz = p2z >> 4;
final QueueCoordinator queue = blockQueue.getNewQueue(world);
final QueueCoordinator regenQueue = blockQueue.getNewQueue(world);
queue.addReadChunks(new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()).getChunks());
queue.setChunkConsumer(chunk -> {
int x = chunk.getX();
int z = chunk.getZ();
int xxb = x << 4;
int zzb = z << 4;
int xxt = xxb + 15;
int zzt = zzb + 15;
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
AugmentedUtils.bypass(ignoreAugment, () -> regenQueue.regenChunk(chunk.getX(), chunk.getZ()));
return;
}
boolean checkX1 = false;
int xxb2;
if (x == bcx) {
xxb2 = p1x - 1;
checkX1 = true;
} else {
xxb2 = xxb;
}
boolean checkX2 = false;
int xxt2;
if (x == tcx) {
xxt2 = p2x + 1;
checkX2 = true;
} else {
xxt2 = xxt;
}
boolean checkZ1 = false;
int zzb2;
if (z == bcz) {
zzb2 = p1z - 1;
checkZ1 = true;
} else {
zzb2 = zzb;
}
boolean checkZ2 = false;
int zzt2;
if (z == tcz) {
zzt2 = p2z + 1;
checkZ2 = true;
} else {
zzt2 = zzt;
}
final ContentMap map = new ContentMap();
if (checkX1) {
//
map.saveRegion(world, xxb, xxb2, zzb2, zzt2);
}
if (checkX2) {
//
map.saveRegion(world, xxt2, xxt, zzb2, zzt2);
}
if (checkZ1) {
//
map.saveRegion(world, xxb2, xxt2, zzb, zzb2);
}
if (checkZ2) {
//
map.saveRegion(world, xxb2, xxt2, zzt2, zzt);
}
if (checkX1 && checkZ1) {
//
map.saveRegion(world, xxb, xxb2, zzb, zzb2);
}
if (checkX2 && checkZ1) {
// ?
map.saveRegion(world, xxt2, xxt, zzb, zzb2);
}
if (checkX1 && checkZ2) {
// ?
map.saveRegion(world, xxb, xxb2, zzt2, zzt);
}
if (checkX2 && checkZ2) {
//
map.saveRegion(world, xxt2, xxt, zzt2, zzt);
}
CuboidRegion currentPlotClear = new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3());
map.saveEntitiesOut(Bukkit.getWorld(world.getName()).getChunkAt(x, z), currentPlotClear);
AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager.setChunkInPlotArea(null, new RunnableVal<ScopedQueueCoordinator>() {
@Override
public void run(ScopedQueueCoordinator value) {
Location min = value.getMin();
int bx = min.getX();
int bz = min.getZ();
for (int x1 = 0; x1 < 16; x1++) {
for (int z1 = 0; z1 < 16; z1++) {
PlotLoc plotLoc = new PlotLoc(bx + x1, bz + z1);
BaseBlock[] ids = map.allBlocks.get(plotLoc);
if (ids != null) {
int minY = value.getMin().getY();
for (int yIndex = 0; yIndex < ids.length; yIndex++) {
int y = yIndex + minY;
BaseBlock id = ids[yIndex];
if (id != null) {
value.setBlock(x1, y, z1, id);
} else {
value.setBlock(x1, y, z1, BlockTypes.AIR.getDefaultState());
}
}
}
}
}
}
}, world.getName(), chunk));
// map.restoreBlocks(worldObj, 0, 0);
map.restoreEntities(Bukkit.getWorld(world.getName()));
});
regenQueue.setCompleteTask(whenDone);
queue.setCompleteTask(regenQueue::enqueue);
queue.enqueue();
return true;
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class ProjectileEventListener method onProjectileLaunch.
@EventHandler
public void onProjectileLaunch(ProjectileLaunchEvent event) {
Projectile entity = event.getEntity();
ProjectileSource shooter = entity.getShooter();
if (!(shooter instanceof Player)) {
return;
}
Location location = BukkitUtil.adapt(entity.getLocation());
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
PlotPlayer<Player> pp = BukkitUtil.adapt((Player) shooter);
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) {
pp.sendMessage(TranslatableCaption.of("permission.no_permission_event"), Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)));
entity.remove();
event.setCancelled(true);
}
} else if (!plot.hasOwner()) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) {
pp.sendMessage(TranslatableCaption.of("permission.no_permission_event"), Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)));
entity.remove();
event.setCancelled(true);
}
} else if (!plot.isAdded(pp.getUUID())) {
if (!plot.getFlag(ProjectilesFlag.class)) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) {
pp.sendMessage(TranslatableCaption.of("permission.no_permission_event"), Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)));
entity.remove();
event.setCancelled(true);
}
}
}
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Plot method getDistanceFromOrigin.
public int getDistanceFromOrigin() {
Location bot = getManager().getPlotBottomLocAbs(id);
Location top = getManager().getPlotTopLocAbs(id);
return Math.max(Math.max(Math.abs(bot.getX()), Math.abs(bot.getZ())), Math.max(Math.abs(top.getX()), Math.abs(top.getZ())));
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Plot method getCenter.
public void getCenter(final Consumer<Location> result) {
Location[] corners = getCorners();
Location top = corners[0];
Location bot = corners[1];
Location location = Location.at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()), MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ()));
this.worldUtil.getHighestBlock(getWorldName(), location.getX(), location.getZ(), y -> {
int height = y;
if (area.allowSigns()) {
height = Math.max(y, getManager().getSignLoc(this).getY());
}
result.accept(location.withY(1 + height));
});
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Plot method format.
public CompletableFuture<Caption> format(final Caption iInfo, PlotPlayer<?> player, final boolean full) {
final CompletableFuture<Caption> future = new CompletableFuture<>();
int num = this.getConnectedPlots().size();
String alias = !this.getAlias().isEmpty() ? this.getAlias() : TranslatableCaption.of("info.none").getComponent(player);
Location bot = this.getCorners()[0];
PlotSquared.platform().worldUtil().getBiome(Objects.requireNonNull(this.getWorldName()), bot.getX(), bot.getZ(), biome -> {
Component trusted = PlayerManager.getPlayerList(this.getTrusted(), player);
Component members = PlayerManager.getPlayerList(this.getMembers(), player);
Component denied = PlayerManager.getPlayerList(this.getDenied(), player);
String seen;
if (Settings.Enabled_Components.PLOT_EXPIRY && ExpireManager.IMP != null) {
if (this.isOnline()) {
seen = TranslatableCaption.of("info.now").getComponent(player);
} else {
int time = (int) (ExpireManager.IMP.getAge(this, false) / 1000);
if (time != 0) {
seen = TimeUtil.secToTime(time);
} else {
seen = TranslatableCaption.of("info.unknown").getComponent(player);
}
}
} else {
seen = TranslatableCaption.of("info.never").getComponent(player);
}
String description = this.getFlag(DescriptionFlag.class);
if (description.isEmpty()) {
description = TranslatableCaption.of("info.plot_no_description").getComponent(player);
}
Component flags;
Collection<PlotFlag<?, ?>> flagCollection = this.getApplicableFlags(true);
if (flagCollection.isEmpty()) {
flags = MINI_MESSAGE.parse(TranslatableCaption.of("info.none").getComponent(player));
} else {
TextComponent.Builder flagBuilder = Component.text();
String prefix = "";
for (final PlotFlag<?, ?> flag : flagCollection) {
Object value;
if (flag instanceof DoubleFlag && !Settings.General.SCIENTIFIC) {
value = FLAG_DECIMAL_FORMAT.format(flag.getValue());
} else {
value = flag.toString();
}
Component snip = MINI_MESSAGE.parse(prefix + CaptionUtility.format(player, TranslatableCaption.of("info.plot_flag_list").getComponent(player)), Template.of("flag", flag.getName()), Template.of("value", CaptionUtility.formatRaw(player, value.toString())));
flagBuilder.append(snip);
prefix = ", ";
}
flags = flagBuilder.build();
}
boolean build = this.isAdded(player.getUUID());
Component owner;
if (this.getOwner() == null) {
owner = Component.text("unowned");
} else if (this.getOwner().equals(DBFunc.SERVER)) {
owner = Component.text(MINI_MESSAGE.stripTokens(TranslatableCaption.of("info.server").getComponent(player)));
} else {
owner = PlayerManager.getPlayerList(this.getOwners(), player);
}
Template headerTemplate = Template.of("header", TranslatableCaption.of("info.plot_info_header").getComponent(player));
Template footerTemplate = Template.of("footer", TranslatableCaption.of("info.plot_info_footer").getComponent(player));
Template areaTemplate;
if (this.getArea() != null) {
areaTemplate = Template.of("area", this.getArea().getWorldName() + (this.getArea().getId() == null ? "" : "(" + this.getArea().getId() + ")"));
} else {
areaTemplate = Template.of("area", TranslatableCaption.of("info.none").getComponent(player));
}
long creationDate = Long.parseLong(String.valueOf(timestamp));
SimpleDateFormat sdf = new SimpleDateFormat(Settings.Timeformat.DATE_FORMAT);
sdf.setTimeZone(TimeZone.getTimeZone(Settings.Timeformat.TIME_ZONE));
String newDate = sdf.format(creationDate);
Template idTemplate = Template.of("id", this.getId().toString());
Template aliasTemplate = Template.of("alias", alias);
Template numTemplate = Template.of("num", String.valueOf(num));
Template descTemplate = Template.of("desc", description);
Template biomeTemplate = Template.of("biome", biome.toString().toLowerCase());
Template ownerTemplate = Template.of("owner", owner);
Template membersTemplate = Template.of("members", members);
Template playerTemplate = Template.of("player", player.getName());
Template trustedTemplate = Template.of("trusted", trusted);
Template helpersTemplate = Template.of("helpers", members);
Template deniedTemplate = Template.of("denied", denied);
Template seenTemplate = Template.of("seen", seen);
Template flagsTemplate = Template.of("flags", flags);
Template creationTemplate = Template.of("creationdate", newDate);
Template buildTemplate = Template.of("build", String.valueOf(build));
Template sizeTemplate = Template.of("size", String.valueOf(getConnectedPlots().size()));
String component = iInfo.getComponent(player);
if (component.contains("<rating>") || component.contains("<likes>")) {
TaskManager.runTaskAsync(() -> {
Template ratingTemplate;
Template likesTemplate;
if (Settings.Ratings.USE_LIKES) {
ratingTemplate = Template.of("rating", String.format("%.0f%%", Like.getLikesPercentage(this) * 100D));
likesTemplate = Template.of("likes", String.format("%.0f%%", Like.getLikesPercentage(this) * 100D));
} else {
int max = 10;
if (Settings.Ratings.CATEGORIES != null && !Settings.Ratings.CATEGORIES.isEmpty()) {
max = 8;
}
if (full && Settings.Ratings.CATEGORIES != null && Settings.Ratings.CATEGORIES.size() > 1) {
double[] ratings = this.getAverageRatings();
StringBuilder rating = new StringBuilder();
String prefix = "";
for (int i = 0; i < ratings.length; i++) {
rating.append(prefix).append(Settings.Ratings.CATEGORIES.get(i)).append('=').append(String.format("%.1f", ratings[i]));
prefix = ",";
}
ratingTemplate = Template.of("rating", rating.toString());
} else {
double rating = this.getAverageRating();
if (Double.isFinite(rating)) {
ratingTemplate = Template.of("rating", String.format("%.1f", rating) + '/' + max);
} else {
ratingTemplate = Template.of("rating", TranslatableCaption.of("info.none").getComponent(player));
}
}
likesTemplate = Template.of("likes", "N/A");
}
future.complete(StaticCaption.of(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(iInfo.getComponent(player), headerTemplate, areaTemplate, idTemplate, aliasTemplate, numTemplate, descTemplate, biomeTemplate, ownerTemplate, membersTemplate, playerTemplate, trustedTemplate, helpersTemplate, deniedTemplate, seenTemplate, flagsTemplate, buildTemplate, ratingTemplate, creationTemplate, sizeTemplate, likesTemplate, footerTemplate))));
});
return;
}
future.complete(StaticCaption.of(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(iInfo.getComponent(player), headerTemplate, areaTemplate, idTemplate, aliasTemplate, numTemplate, descTemplate, biomeTemplate, ownerTemplate, membersTemplate, playerTemplate, trustedTemplate, helpersTemplate, deniedTemplate, seenTemplate, flagsTemplate, buildTemplate, creationTemplate, sizeTemplate, footerTemplate))));
});
return future;
}
Aggregations