Skip to content
Permalink
Browse files

Added a //world command to set the override

  • Loading branch information...
me4502 committed Jul 27, 2019
1 parent ab25732 commit 2dc1d11c3ffdb319316f08426498c6422d6a8de7
@@ -159,6 +159,11 @@ public String getName() {
return getWorld().getName();
}

@Override
public String getId() {
return getWorld().getName().replace(" ", "_").toLowerCase();
}

@Override
public Path getStoragePath() {
return getWorld().getWorldFolder().toPath();
@@ -39,6 +39,7 @@
import com.sk89q.worldedit.world.block.BlockStateHolder;

import java.util.List;
import java.util.Locale;

import javax.annotation.Nullable;

@@ -57,6 +58,11 @@ public String getName() {
return this.name;
}

@Override
public String getId() {
return getName().replace(" ", "_").toLowerCase(Locale.ROOT);
}

@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight)
throws WorldEditException {
@@ -33,6 +33,7 @@
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.util.formatting.component.PaginationBox;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.item.ItemType;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
@@ -182,6 +183,21 @@ public void drawSelection(Player player, LocalSession session,
}
}

@Command(
name = "/world",
desc = "Sets the world override"
)
@CommandPermissions("worldedit.world")
public void world(Actor actor, LocalSession session,
@Arg(desc = "The world override", def = "") World world) {
session.setWorldOverride(world);
if (world == null) {
actor.print("Removed world override.");
} else {
actor.print("Set the world override to " + world.getId() + ". (Use //world to go back to default)");
}
}

@Command(
name = "gmask",
aliases = {"/gmask"},
@@ -0,0 +1,77 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.command.argument;

import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.world.World;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.converter.ArgumentConverter;
import org.enginehub.piston.converter.ConversionResult;
import org.enginehub.piston.converter.FailedConversion;
import org.enginehub.piston.converter.SuccessfulConversion;
import org.enginehub.piston.inject.InjectedValueAccess;
import org.enginehub.piston.inject.Key;

import java.util.List;
import java.util.stream.Collectors;

public class WorldConverter implements ArgumentConverter<World> {

public static void register(CommandManager commandManager) {
commandManager.registerConverter(Key.of(World.class),
new WorldConverter()
);
}

private final TextComponent choices;

private WorldConverter() {
this.choices = TextComponent.of("any world");
}

@Override
public Component describeAcceptableArguments() {
return this.choices;
}

@Override
public List<String> getSuggestions(String input) {
return WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getWorlds().stream()
.map(World::getId)
.filter(world -> world.startsWith(input))
.collect(Collectors.toList());
}

@Override
public ConversionResult<World> convert(String s, InjectedValueAccess injectedValueAccess) {
World result = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getWorlds().stream()
.filter(world -> world.getId().equals(s))
.findAny().orElse(null);
return result == null
? FailedConversion.from(new IllegalArgumentException(
"Not a valid world: " + s))
: SuccessfulConversion.fromSingle(result);
}
}
@@ -82,6 +82,7 @@
import com.sk89q.worldedit.command.argument.RegionFactoryConverter;
import com.sk89q.worldedit.command.argument.RegistryConverter;
import com.sk89q.worldedit.command.argument.VectorConverter;
import com.sk89q.worldedit.command.argument.WorldConverter;
import com.sk89q.worldedit.command.argument.ZonedDateTimeConverter;
import com.sk89q.worldedit.command.util.PermissionCondition;
import com.sk89q.worldedit.command.util.SubCommandPermissionCondition;
@@ -219,6 +220,7 @@ private void registerArgumentConverters() {
BooleanConverter.register(commandManager);
EntityRemoverConverter.register(commandManager);
RegionFactoryConverter.register(commandManager);
WorldConverter.register(commandManager);
}

private void registerAlwaysInjectedValues() {
@@ -61,6 +61,11 @@ public String getName() {
return "null";
}

@Override
public String getId() {
return "null";
}

@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException {
return false;
@@ -31,6 +31,7 @@
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.registry.Keyed;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.world.block.BlockState;
@@ -44,7 +45,7 @@
/**
* Represents a world (dimension).
*/
public interface World extends Extent {
public interface World extends Extent, Keyed {

/**
* Get the name of the world.
@@ -100,6 +100,7 @@
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Random;
@@ -168,6 +169,13 @@ public String getName() {
return getWorld().getLevelProperties().getLevelName();
}

@Override
public String getId() {
return getWorld().getLevelProperties().getLevelName()
.replace(" ", "_").toLowerCase(Locale.ROOT)
+ getWorld().dimension.getType().getSuffix();
}

@Override
public Path getStoragePath() {
final World world = getWorld();
@@ -93,6 +93,7 @@
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.storage.SaveHandler;
import net.minecraft.world.storage.WorldInfo;
import net.minecraftforge.common.DimensionManager;

import javax.annotation.Nullable;
import java.io.File;
@@ -169,6 +170,11 @@ public String getName() {
return getWorld().getWorldInfo().getWorldName();
}

@Override
public String getId() {
return DimensionManager.getRegistry().getKey(getWorld().dimension.getType()).toString();
}

@Override
public Path getStoragePath() {
final World world = getWorld();
@@ -60,6 +60,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;

@@ -117,6 +118,12 @@ public String getName() {
return getWorld().getName();
}

@Override
public String getId() {
return getName().replace(" ", "_").toLowerCase(Locale.ROOT) +
getWorld().getDimension().getType().getName().toLowerCase(Locale.ROOT);
}

@Override
public Path getStoragePath() {
return getWorld().getDirectory();

0 comments on commit 2dc1d11

Please sign in to comment.
You can’t perform that action at this time.