use of com.sk89q.worldedit.function.pattern.Pattern in project PlotSquared by IntellectualSites.
the class ComponentPresetManager method buildInventory.
/**
* Build the component inventory for a player. This also checks
* if the player is in a compatible plot, and sends appropriate
* error messages if not
*
* @param player player
* @return Build inventory, if it could be created
*/
@Nullable
public PlotInventory buildInventory(final PlotPlayer<?> player) {
final Plot plot = player.getCurrentPlot();
if (plot == null) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
return null;
} else if (!plot.hasOwner()) {
player.sendMessage(TranslatableCaption.of("info.plot_unowned"));
return null;
} else if (!plot.isOwner(player.getUUID()) && !plot.getTrusted().contains(player.getUUID()) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMPONENTS_OTHER)) {
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return null;
} else if (plot.getVolume() > Integer.MAX_VALUE) {
player.sendMessage(TranslatableCaption.of("schematics.schematic_too_large"));
return null;
}
final List<ComponentPreset> allowedPresets = new ArrayList<>(this.presets.size());
for (final ComponentPreset componentPreset : this.presets) {
if (!componentPreset.getPermission().isEmpty() && !Permissions.hasPermission(player, componentPreset.getPermission())) {
continue;
}
allowedPresets.add(componentPreset);
}
if (allowedPresets.isEmpty()) {
player.sendMessage(TranslatableCaption.of("preset.empty"));
return null;
}
final int size = (int) Math.ceil((double) allowedPresets.size() / 9.0D);
final PlotInventory plotInventory = new PlotInventory(this.inventoryUtil, player, size, TranslatableCaption.of("preset.title").getComponent(player)) {
@Override
public boolean onClick(final int index) {
if (!getPlayer().getCurrentPlot().equals(plot)) {
return false;
}
if (index < 0 || index >= allowedPresets.size()) {
return false;
}
final ComponentPreset componentPreset = allowedPresets.get(index);
if (componentPreset == null) {
return false;
}
if (plot.getRunning() > 0) {
getPlayer().sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
return false;
}
final Pattern pattern = PatternUtil.parse(null, componentPreset.getPattern(), false);
if (pattern == null) {
getPlayer().sendMessage(TranslatableCaption.of("preset.preset_invalid"));
return false;
}
if (componentPreset.getCost() > 0.0D) {
if (!econHandler.isEnabled(plot.getArea())) {
getPlayer().sendMessage(TranslatableCaption.of("preset.economy_disabled"), Template.of("preset", componentPreset.getDisplayName()));
return false;
}
if (econHandler.getMoney(getPlayer()) < componentPreset.getCost()) {
getPlayer().sendMessage(TranslatableCaption.of("preset.preset_cannot_afford"));
return false;
} else {
econHandler.withdrawMoney(getPlayer(), componentPreset.getCost());
getPlayer().sendMessage(TranslatableCaption.of("economy.removed_balance"), Template.of("money", econHandler.format(componentPreset.getCost())));
}
}
BackupManager.backup(getPlayer(), plot, () -> {
plot.addRunning();
QueueCoordinator queue = plot.getArea().getQueue();
queue.setCompleteTask(plot::removeRunning);
for (Plot current : plot.getConnectedPlots()) {
current.getPlotModificationManager().setComponent(componentPreset.getComponent().name(), pattern, player, queue);
}
queue.enqueue();
getPlayer().sendMessage(TranslatableCaption.of("working.generating_component"));
});
return false;
}
};
for (int i = 0; i < allowedPresets.size(); i++) {
final ComponentPreset preset = allowedPresets.get(i);
final List<String> lore = new ArrayList<>();
if (preset.getCost() > 0) {
if (!this.econHandler.isEnabled(plot.getArea())) {
lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("preset.preset_lore_economy_disabled").getComponent(player))));
} else {
lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("preset.preset_lore_cost").getComponent(player), Template.of("cost", String.format("%.2f", preset.getCost())))));
}
}
lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("preset.preset_lore_component").getComponent(player), Template.of("component", preset.getComponent().name().toLowerCase()), Template.of("prefix", TranslatableCaption.of("core.prefix").getComponent(player)))));
lore.removeIf(String::isEmpty);
lore.addAll(preset.getDescription());
plotInventory.setItem(i, new PlotItemStack(preset.getIcon().getId().replace("minecraft:", ""), 1, preset.getDisplayName(), lore.toArray(new String[0])));
}
return plotInventory;
}
use of com.sk89q.worldedit.function.pattern.Pattern in project PlotSquared by IntellectualSites.
the class HybridPlotManager method clearPlot.
@Override
public boolean clearPlot(@NonNull final Plot plot, @Nullable final Runnable whenDone, @Nullable PlotPlayer<?> actor, @Nullable QueueCoordinator queue) {
if (this.regionManager.notifyClear(this)) {
// If this returns false, the clear didn't work
if (this.regionManager.handleClear(plot, whenDone, this, actor)) {
return true;
}
}
final Location pos1 = plot.getBottomAbs();
final Location pos2 = plot.getExtendedTopAbs();
// If augmented
final boolean canRegen = (hybridPlotWorld.getType() == PlotAreaType.AUGMENTED) && (hybridPlotWorld.getTerrain() != PlotAreaTerrainType.NONE) && REGENERATIVE_CLEAR;
// The component blocks
final Pattern plotfloor = hybridPlotWorld.TOP_BLOCK.toPattern();
final Pattern filling = hybridPlotWorld.MAIN_BLOCK.toPattern();
final Pattern bedrock;
if (hybridPlotWorld.PLOT_BEDROCK) {
bedrock = BlockTypes.BEDROCK.getDefaultState();
} else {
bedrock = hybridPlotWorld.MAIN_BLOCK.toPattern();
}
final BiomeType biome = hybridPlotWorld.getPlotBiome();
boolean enqueue = false;
if (queue == null) {
enqueue = true;
queue = hybridPlotWorld.getQueue();
}
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
queue.addProgressSubscriber(subscriberFactory.createWithActor(actor));
}
if (whenDone != null) {
queue.setCompleteTask(whenDone);
}
if (!canRegen) {
queue.setCuboid(pos1.withY(hybridPlotWorld.getMinGenHeight()), pos2.withY(hybridPlotWorld.getMinGenHeight()), hybridPlotWorld.PLOT_BEDROCK ? bedrock : filling);
// Each component has a different layer
queue.setCuboid(pos1.withY(hybridPlotWorld.getMinGenHeight() + 1), pos2.withY(hybridPlotWorld.PLOT_HEIGHT - 1), filling);
queue.setCuboid(pos1.withY(hybridPlotWorld.PLOT_HEIGHT), pos2.withY(hybridPlotWorld.PLOT_HEIGHT), plotfloor);
queue.setCuboid(pos1.withY(hybridPlotWorld.PLOT_HEIGHT + 1), pos2.withY(hybridPlotWorld.getMaxGenHeight()), BlockTypes.AIR.getDefaultState());
queue.setBiomeCuboid(pos1, pos2, biome);
} else {
queue.setRegenRegion(new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()));
}
pastePlotSchematic(queue, pos1, pos2);
return !enqueue || queue.enqueue();
}
use of com.sk89q.worldedit.function.pattern.Pattern in project PrivateMinesOOP by UntouchedOdin0.
the class WE7Adapter method fillRegion.
@Override
public void fillRegion(CuboidRegion region, Map<Material, Double> materials) {
World world = new BukkitWorld(region.getWorld());
Utils utils = new Utils();
try (final EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder().world(world).build()) {
editSession.setReorderMode(EditSession.ReorderMode.MULTI_STAGE);
final RandomPattern randomPattern = new RandomPattern();
materials.forEach((material, chance) -> {
Pattern pattern = BukkitAdapter.adapt(material.createBlockData()).toBaseBlock();
randomPattern.add(pattern, chance);
});
final com.sk89q.worldedit.regions.CuboidRegion worldEditRegion = new com.sk89q.worldedit.regions.CuboidRegion(BukkitAdapter.asBlockVector(region.getStart()), BukkitAdapter.asBlockVector(region.getEnd()));
editSession.setBlocks((Region) worldEditRegion, randomPattern);
editSession.flushQueue();
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
// this shouldn't happen
}
}
Aggregations