use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Plot method getRegions.
/**
* This will combine each plot into effective rectangular regions<br>
* - This result is cached globally<br>
* - Useful for handling non rectangular shapes
*
* @return all regions within the plot
*/
@NonNull
public Set<CuboidRegion> getRegions() {
if (regions_cache != null && connected_cache != null && connected_cache.contains(this)) {
return regions_cache;
}
if (!this.isMerged()) {
Location pos1 = this.getBottomAbs().withY(getArea().getMinBuildHeight());
Location pos2 = this.getTopAbs().withY(getArea().getMaxBuildHeight());
connected_cache = Sets.newHashSet(this);
CuboidRegion rg = new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3());
regions_cache = Collections.singleton(rg);
return regions_cache;
}
Set<Plot> plots = this.getConnectedPlots();
Set<CuboidRegion> regions = regions_cache = new HashSet<>();
Set<PlotId> visited = new HashSet<>();
for (Plot current : plots) {
if (visited.contains(current.getId())) {
continue;
}
boolean merge = true;
PlotId bot = current.getId();
PlotId top = current.getId();
while (merge) {
merge = false;
Iterable<PlotId> ids = PlotId.PlotRangeIterator.range(PlotId.of(bot.getX(), bot.getY() - 1), PlotId.of(top.getX(), bot.getY() - 1));
boolean tmp = true;
for (PlotId id : ids) {
Plot plot = this.area.getPlotAbs(id);
if (plot == null || !plot.isMerged(Direction.SOUTH) || visited.contains(plot.getId())) {
tmp = false;
}
}
if (tmp) {
merge = true;
bot = PlotId.of(bot.getX(), bot.getY() - 1);
}
ids = PlotId.PlotRangeIterator.range(PlotId.of(top.getX() + 1, bot.getY()), PlotId.of(top.getX() + 1, top.getY()));
tmp = true;
for (PlotId id : ids) {
Plot plot = this.area.getPlotAbs(id);
if (plot == null || !plot.isMerged(Direction.WEST) || visited.contains(plot.getId())) {
tmp = false;
}
}
if (tmp) {
merge = true;
top = PlotId.of(top.getX() + 1, top.getY());
}
ids = PlotId.PlotRangeIterator.range(PlotId.of(bot.getX(), top.getY() + 1), PlotId.of(top.getX(), top.getY() + 1));
tmp = true;
for (PlotId id : ids) {
Plot plot = this.area.getPlotAbs(id);
if (plot == null || !plot.isMerged(Direction.NORTH) || visited.contains(plot.getId())) {
tmp = false;
}
}
if (tmp) {
merge = true;
top = PlotId.of(top.getX(), top.getY() + 1);
}
ids = PlotId.PlotRangeIterator.range(PlotId.of(bot.getX() - 1, bot.getY()), PlotId.of(bot.getX() - 1, top.getY()));
tmp = true;
for (PlotId id : ids) {
Plot plot = this.area.getPlotAbs(id);
if (plot == null || !plot.isMerged(Direction.EAST) || visited.contains(plot.getId())) {
tmp = false;
}
}
if (tmp) {
merge = true;
bot = PlotId.of(bot.getX() - 1, bot.getY());
}
}
int minHeight = getArea().getMinBuildHeight();
int maxHeight = getArea().getMaxBuildHeight();
Location gtopabs = this.area.getPlotAbs(top).getTopAbs();
Location gbotabs = this.area.getPlotAbs(bot).getBottomAbs();
visited.addAll(Lists.newArrayList((Iterable<? extends PlotId>) PlotId.PlotRangeIterator.range(bot, top)));
for (int x = bot.getX(); x <= top.getX(); x++) {
Plot plot = this.area.getPlotAbs(PlotId.of(x, top.getY()));
if (plot.isMerged(Direction.SOUTH)) {
// south wedge
Location toploc = plot.getExtendedTopAbs();
Location botabs = plot.getBottomAbs();
Location topabs = plot.getTopAbs();
BlockVector3 pos1 = BlockVector3.at(botabs.getX(), minHeight, topabs.getZ() + 1);
BlockVector3 pos2 = BlockVector3.at(topabs.getX(), maxHeight, toploc.getZ());
regions.add(new CuboidRegion(pos1, pos2));
if (plot.isMerged(Direction.SOUTHEAST)) {
pos1 = BlockVector3.at(topabs.getX() + 1, minHeight, topabs.getZ() + 1);
pos2 = BlockVector3.at(toploc.getX(), maxHeight, toploc.getZ());
regions.add(new CuboidRegion(pos1, pos2));
// intersection
}
}
}
for (int y = bot.getY(); y <= top.getY(); y++) {
Plot plot = this.area.getPlotAbs(PlotId.of(top.getX(), y));
if (plot.isMerged(Direction.EAST)) {
// east wedge
Location toploc = plot.getExtendedTopAbs();
Location botabs = plot.getBottomAbs();
Location topabs = plot.getTopAbs();
BlockVector3 pos1 = BlockVector3.at(topabs.getX() + 1, minHeight, botabs.getZ());
BlockVector3 pos2 = BlockVector3.at(toploc.getX(), maxHeight, topabs.getZ());
regions.add(new CuboidRegion(pos1, pos2));
if (plot.isMerged(Direction.SOUTHEAST)) {
pos1 = BlockVector3.at(topabs.getX() + 1, minHeight, topabs.getZ() + 1);
pos2 = BlockVector3.at(toploc.getX(), maxHeight, toploc.getZ());
regions.add(new CuboidRegion(pos1, pos2));
// intersection
}
}
}
BlockVector3 pos1 = BlockVector3.at(gbotabs.getX(), minHeight, gbotabs.getZ());
BlockVector3 pos2 = BlockVector3.at(gtopabs.getX(), maxHeight, gtopabs.getZ());
regions.add(new CuboidRegion(pos1, pos2));
}
return regions;
}
use of com.plotsquared.core.location.Location in project Bookshelf by LOOHP.
the class PlotSquared5Events method onPlotSquaredCheck.
@SuppressWarnings("unchecked")
@EventHandler(priority = EventPriority.LOWEST)
public void onPlotSquaredCheck(PlayerOpenBookshelfEvent event) {
try {
if (!Bookshelf.plotSquaredHook) {
return;
}
if (!(boolean) hasPlotAreaMethod.invoke(PlotSquared.get(), event.getLocation().getWorld().getName())) {
return;
}
org.bukkit.entity.Player bukkitPlayer = event.getPlayer();
PlotPlayer<?> player = (PlotPlayer<?>) wrap.invoke(null, bukkitPlayer);
if (player.hasPermission("plots.admin.interact.other")) {
return;
}
org.bukkit.Location bukkitLocation = event.getLocation();
Location location = locationConstructor.newInstance(bukkitLocation.getWorld().getName(), bukkitLocation.getBlockX(), bukkitLocation.getBlockY(), bukkitLocation.getBlockZ());
PlotArea plotarea = (PlotArea) getApplicablePlotAreaMethod.invoke(PlotSquared.get(), location);
if (plotarea == null) {
return;
}
Plot plot = plotarea.getPlot(location);
if (plot == null) {
return;
}
for (PlotFlag<?, ?> flag : plot.getFlags()) {
if (flag instanceof UseFlag) {
for (BlockTypeWrapper blockTypeWarpper : (List<BlockTypeWrapper>) flag.getValue()) {
if (blockTypeWarpper.accepts(ADAPTED_BOOKSHELF_TYPE)) {
return;
}
}
}
}
if (plot.getOwners().contains(player.getUUID())) {
return;
}
if (plot.getTrusted().contains(player.getUUID())) {
return;
}
if (plot.getOwners().stream().anyMatch(each -> Bukkit.getPlayer(each) != null)) {
if (plot.getMembers().contains(player.getUUID())) {
return;
}
}
try {
sendMessage.invoke(null, player, FLAG_TUTORIAL_USAGE, FLAG_USE);
} catch (Exception ignore) {
}
event.setCancelled(true);
} catch (Exception e) {
event.setCancelled(true);
}
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Trim method getTrimRegions.
/**
* Runs the result task with the parameters (viable, nonViable).
*
* @param world The world
* @param result (viable = .mcr to trim, nonViable = .mcr keep)
* @return success or not
*/
public static boolean getTrimRegions(String world, final RunnableVal2<Set<BlockVector2>, Set<BlockVector2>> result) {
if (result == null) {
return false;
}
TranslatableCaption.of("trim.trim_starting");
final List<Plot> plots = PlotQuery.newQuery().inWorld(world).asList();
if (ExpireManager.IMP != null) {
plots.removeAll(ExpireManager.IMP.getPendingExpired());
}
result.value1 = new HashSet<>(PlotSquared.platform().worldUtil().getChunkChunks(world));
result.value2 = new HashSet<>();
StaticCaption.of(" - MCA #: " + result.value1.size());
StaticCaption.of(" - CHUNKS: " + (result.value1.size() * 1024) + " (max)");
StaticCaption.of(" - TIME ESTIMATE: 12 Parsecs");
TaskManager.getPlatformImplementation().objectTask(plots, new RunnableVal<>() {
@Override
public void run(Plot plot) {
Location pos1 = plot.getCorners()[0];
Location pos2 = plot.getCorners()[1];
int ccx1 = pos1.getX() >> 9;
int ccz1 = pos1.getZ() >> 9;
int ccx2 = pos2.getX() >> 9;
int ccz2 = pos2.getZ() >> 9;
for (int x = ccx1; x <= ccx2; x++) {
for (int z = ccz1; z <= ccz2; z++) {
BlockVector2 loc = BlockVector2.at(x, z);
if (result.value1.remove(loc)) {
result.value2.add(loc);
}
}
}
}
}).thenAccept(ignore -> TaskManager.getPlatformImplementation().taskLater(result, TaskTime.ticks(1L)));
return true;
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Music method onCommand.
@Override
public boolean onCommand(PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
final Plot plot = location.getPlotAbs();
if (plot == null) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
return false;
}
if (!plot.hasOwner()) {
player.sendMessage(TranslatableCaption.of("info.plot_unowned"));
return false;
}
if (!plot.isAdded(player.getUUID()) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_MUSIC_OTHER)) {
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_MUSIC_OTHER)));
return true;
}
PlotInventory inv = new PlotInventory(this.inventoryUtil, player, 2, TranslatableCaption.of("plotjukebox.jukebox_header").getComponent(player)) {
@Override
public boolean onClick(int index) {
PlotItemStack item = getItem(index);
if (item == null) {
return true;
}
if (item.getType() == ItemTypes.BEDROCK) {
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(MusicFlag.class).createFlagInstance(item.getType());
PlotFlagRemoveEvent event = eventDispatcher.callFlagRemove(plotFlag, plot);
if (event.getEventResult() == Result.DENY) {
getPlayer().sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Music removal"));
return true;
}
plot.removeFlag(event.getFlag());
getPlayer().sendMessage(TranslatableCaption.of("flag.flag_removed"), Template.of("flag", "music"), Template.of("value", "music_disc"));
} else if (item.getName().toLowerCase(Locale.ENGLISH).contains("disc")) {
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(MusicFlag.class).createFlagInstance(item.getType());
PlotFlagAddEvent event = eventDispatcher.callFlagAdd(plotFlag, plot);
if (event.getEventResult() == Result.DENY) {
getPlayer().sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Music addition"));
return true;
}
plot.setFlag(event.getFlag());
getPlayer().sendMessage(TranslatableCaption.of("flag.flag_added"), Template.of("flag", "music"), Template.of("value", String.valueOf(event.getFlag().getValue())));
} else {
getPlayer().sendMessage(TranslatableCaption.of("flag.flag_not_added"));
}
return false;
}
};
int index = 0;
for (final String disc : DISCS) {
final String name = String.format("<gold>%s</gold>", disc);
final String[] lore = { TranslatableCaption.of("plotjukebox.click_to_play").getComponent(player) };
ItemType type = ItemTypes.get(disc);
if (type == null) {
continue;
}
final PlotItemStack item = new PlotItemStack(type, 1, name, lore);
if (inv.setItemChecked(index, item)) {
index++;
}
}
// Always add the cancel button
// if (player.getMeta("music") != null) {
String name = TranslatableCaption.of("plotjukebox.cancel_music").getComponent(player);
String[] lore = { TranslatableCaption.of("plotjukebox.reset_music").getComponent(player) };
inv.setItem(index, new PlotItemStack("bedrock", 1, name, lore));
// }
inv.openInventory();
return true;
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Swap method execute.
@Override
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
Location location = player.getLocation();
Plot plot1 = location.getPlotAbs();
if (plot1 == null) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
return CompletableFuture.completedFuture(false);
}
if (!plot1.isOwner(player.getUUID()) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN)) {
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return CompletableFuture.completedFuture(false);
}
if (args.length != 1) {
sendUsage(player);
return CompletableFuture.completedFuture(false);
}
Plot plot2 = Plot.getPlotFromString(player, args[0], true);
if (plot2 == null) {
return CompletableFuture.completedFuture(false);
}
if (plot1.equals(plot2)) {
player.sendMessage(TranslatableCaption.of("invalid.origin_cant_be_target"));
return CompletableFuture.completedFuture(false);
}
if (!plot1.getArea().isCompatible(plot2.getArea())) {
player.sendMessage(TranslatableCaption.of("errors.plotworld_incompatible"));
return CompletableFuture.completedFuture(false);
}
if (plot1.isMerged() || plot2.isMerged()) {
player.sendMessage(TranslatableCaption.of("swap.swap_merged"));
return CompletableFuture.completedFuture(false);
}
// Set strings here as the plot objects are mutable (the PlotID changes after being moved).
String p1 = plot1.toString();
String p2 = plot2.toString();
return plot1.getPlotModificationManager().move(plot2, player, () -> {
}, true).thenApply(result -> {
if (result) {
player.sendMessage(TranslatableCaption.of("swap.swap_success"), Template.of("origin", p1), Template.of("target", p2));
return true;
} else {
player.sendMessage(TranslatableCaption.of("swap.swap_overlap"));
return false;
}
});
}
Aggregations