use of com.plotsquared.core.location.Location in project Bookshelf by LOOHP.
the class PlotSquared6Events method onPlotSquaredCheck.
@SuppressWarnings("unchecked")
@EventHandler(priority = EventPriority.LOWEST)
public void onPlotSquaredCheck(PlayerOpenBookshelfEvent event) {
if (!Bookshelf.plotSquaredHook) {
return;
}
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(event.getLocation().getWorld().getName())) {
return;
}
org.bukkit.entity.Player bukkitPlayer = event.getPlayer();
PlotPlayer<?> player = PlotPlayer.from(bukkitPlayer);
if (player.hasPermission("plots.admin.interact.other")) {
return;
}
org.bukkit.Location bukkitLocation = event.getLocation();
Location location = Location.at(bukkitLocation.getWorld().getName(), bukkitLocation.getBlockX(), bukkitLocation.getBlockY(), bukkitLocation.getBlockZ());
PlotArea plotarea = PlotSquared.get().getPlotAreaManager().getApplicablePlotArea(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 {
plotPlayerSendMessageMethod.invoke(player, TranslatableCaption.of("permission.no_permission_event"), Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER)));
} catch (Exception ignore) {
}
event.setCancelled(true);
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class WorldUtil method upload.
public void upload(@NonNull final Plot plot, @Nullable final UUID uuid, @Nullable final String file, @NonNull final RunnableVal<URL> whenDone) {
plot.getHome(home -> SchematicHandler.upload(uuid, file, "zip", new RunnableVal<>() {
@Override
public void run(OutputStream output) {
try (final ZipOutputStream zos = new ZipOutputStream(output)) {
File dat = getDat(plot.getWorldName());
Location spawn = getSpawn(plot.getWorldName());
if (dat != null) {
ZipEntry ze = new ZipEntry("world" + File.separator + dat.getName());
zos.putNextEntry(ze);
try (NBTInputStream nis = new NBTInputStream(new GZIPInputStream(new FileInputStream(dat)))) {
Map<String, Tag> tag = ((CompoundTag) nis.readNamedTag().getTag()).getValue();
Map<String, Tag> newMap = new HashMap<>();
for (Map.Entry<String, Tag> entry : tag.entrySet()) {
if (!entry.getKey().equals("Data")) {
newMap.put(entry.getKey(), entry.getValue());
continue;
}
Map<String, Tag> data = new HashMap<>(((CompoundTag) entry.getValue()).getValue());
data.put("SpawnX", new IntTag(home.getX()));
data.put("SpawnY", new IntTag(home.getY()));
data.put("SpawnZ", new IntTag(home.getZ()));
newMap.put("Data", new CompoundTag(data));
}
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
try (NBTOutputStream out = new NBTOutputStream(new GZIPOutputStream(baos, true))) {
// TODO Find what this should be called
out.writeNamedTag("Schematic????", new CompoundTag(newMap));
}
zos.write(baos.toByteArray());
}
}
}
setSpawn(spawn);
byte[] buffer = new byte[1024];
Set<BlockVector2> added = new HashSet<>();
for (Plot current : plot.getConnectedPlots()) {
Location bot = current.getBottomAbs();
Location top = current.getTopAbs();
int brx = bot.getX() >> 9;
int brz = bot.getZ() >> 9;
int trx = top.getX() >> 9;
int trz = top.getZ() >> 9;
Set<BlockVector2> files = getChunkChunks(bot.getWorldName());
for (BlockVector2 mca : files) {
if (mca.getX() >= brx && mca.getX() <= trx && mca.getZ() >= brz && mca.getZ() <= trz && !added.contains(mca)) {
final File file = getMcr(plot.getWorldName(), mca.getX(), mca.getZ());
if (file != null) {
// final String name = "r." + (x - cx) + "." + (z - cz) + ".mca";
String name = file.getName();
final ZipEntry ze = new ZipEntry("world" + File.separator + "region" + File.separator + name);
zos.putNextEntry(ze);
added.add(mca);
try (FileInputStream in = new FileInputStream(file)) {
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
}
zos.closeEntry();
}
}
}
}
zos.closeEntry();
zos.flush();
zos.finish();
} catch (IOException e) {
e.printStackTrace();
}
}
}, whenDone));
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Middle method onCommand.
@Override
public boolean onCommand(PlotPlayer<?> player, String[] arguments) {
Location location = player.getLocation();
Plot plot = location.getPlot();
if (plot == null) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
return false;
}
plot.getCenter(center -> player.teleport(center, TeleportCause.COMMAND_MIDDLE));
player.sendMessage(TranslatableCaption.of("teleport.teleported_to_plot"));
return true;
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Remove method onCommand.
@Override
public boolean onCommand(PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
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.isOwner(player.getUUID()) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_REMOVE)) {
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return true;
}
PlayerManager.getUUIDsFromString(args[0], (uuids, throwable) -> {
int count = 0;
if (throwable instanceof TimeoutException) {
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
return;
} else if (throwable != null) {
player.sendMessage(TranslatableCaption.of("errors.invalid_player"), Template.of("value", args[0]));
return;
} else if (!uuids.isEmpty()) {
for (UUID uuid : uuids) {
if (plot.getTrusted().contains(uuid)) {
if (plot.removeTrusted(uuid)) {
this.eventDispatcher.callTrusted(player, plot, uuid, false);
count++;
}
} else if (plot.getMembers().contains(uuid)) {
if (plot.removeMember(uuid)) {
this.eventDispatcher.callMember(player, plot, uuid, false);
count++;
}
} else if (plot.getDenied().contains(uuid)) {
if (plot.removeDenied(uuid)) {
this.eventDispatcher.callDenied(player, plot, uuid, false);
count++;
}
} else if (uuid == DBFunc.EVERYONE) {
if (plot.removeTrusted(uuid)) {
this.eventDispatcher.callTrusted(player, plot, uuid, false);
count++;
} else if (plot.removeMember(uuid)) {
this.eventDispatcher.callMember(player, plot, uuid, false);
count++;
} else if (plot.removeDenied(uuid)) {
this.eventDispatcher.callDenied(player, plot, uuid, false);
count++;
}
}
}
}
if (count == 0) {
player.sendMessage(TranslatableCaption.of("errors.invalid_player"), Template.of("value", args[0]));
} else {
player.sendMessage(TranslatableCaption.of("member.removed_players"), Template.of("amount", count + ""));
}
});
return true;
}
use of com.plotsquared.core.location.Location in project PlotSquared by IntellectualSites.
the class Remove method tab.
@Override
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
Location location = player.getLocation();
Plot plot = location.getPlotAbs();
if (plot == null) {
return Collections.emptyList();
}
return TabCompletions.completeAddedPlayers(player, plot, String.join(",", args).trim(), Collections.singletonList(player.getName()));
}
Aggregations