Cleaned up BiomeCommands and made better use of new command framework.

Dieser Commit ist enthalten in:
sk89q 2014-06-27 18:04:34 -07:00
Ursprung b7e0821b97
Commit 1431cd2a67

Datei anzeigen

@ -24,6 +24,8 @@ import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.masks.BiomeTypeMask; import com.sk89q.worldedit.masks.BiomeTypeMask;
import com.sk89q.worldedit.masks.InvertedMask; import com.sk89q.worldedit.masks.InvertedMask;
import com.sk89q.worldedit.masks.Mask; import com.sk89q.worldedit.masks.Mask;
@ -35,14 +37,24 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
/**
* Implements biome-related commands such as "/biomelist".
*/
public class BiomeCommands { public class BiomeCommands {
private WorldEdit we; private final WorldEdit worldEdit;
public BiomeCommands(WorldEdit we) { /**
this.we = we; * Create a new instance.
*
* @param worldEdit reference to WorldEdit
*/
public BiomeCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
} }
@Command( @Command(
@ -52,9 +64,7 @@ public class BiomeCommands {
max = 1 max = 1
) )
@CommandPermissions("worldedit.biome.list") @CommandPermissions("worldedit.biome.list")
public void biomeList(CommandContext args, LocalSession session, LocalPlayer player, public void biomeList(Actor actor, CommandContext args) throws WorldEditException {
EditSession editSession) throws WorldEditException {
int page; int page;
int offset; int offset;
int count = 0; int count = 0;
@ -66,14 +76,14 @@ public class BiomeCommands {
offset = (page - 1) * 19; offset = (page - 1) * 19;
} }
List<BiomeType> biomes = we.getServer().getBiomes().all(); List<BiomeType> biomes = worldEdit.getServer().getBiomes().all();
int totalPages = biomes.size() / 19 + 1; int totalPages = biomes.size() / 19 + 1;
player.print("Available Biomes (page " + page + "/" + totalPages + ") :"); actor.print("Available Biomes (page " + page + "/" + totalPages + ") :");
for (BiomeType biome : biomes) { for (BiomeType biome : biomes) {
if (offset > 0) { if (offset > 0) {
offset--; offset--;
} else { } else {
player.print(" " + biome.getName()); actor.print(" " + biome.getName());
if (++count == 19) { if (++count == 19) {
break; break;
} }
@ -93,9 +103,7 @@ public class BiomeCommands {
max = 0 max = 0
) )
@CommandPermissions("worldedit.biome.info") @CommandPermissions("worldedit.biome.info")
public void biomeInfo(CommandContext args, LocalSession session, LocalPlayer player, public void biomeInfo(CommandContext args, Player player, LocalSession session) throws WorldEditException {
EditSession editSession) throws WorldEditException {
if (args.hasFlag('t')) { if (args.hasFlag('t')) {
Vector blockPosition = player.getBlockTrace(300); Vector blockPosition = player.getBlockTrace(300);
if (blockPosition == null) { if (blockPosition == null) {
@ -144,10 +152,8 @@ public class BiomeCommands {
) )
@Logging(REGION) @Logging(REGION)
@CommandPermissions("worldedit.biome.set") @CommandPermissions("worldedit.biome.set")
public void setBiome(CommandContext args, LocalSession session, LocalPlayer player, public void setBiome(CommandContext args, Player player, LocalSession session, EditSession editSession) throws WorldEditException {
EditSession editSession) throws WorldEditException { final BiomeType target = worldEdit.getServer().getBiomes().get(args.getString(0));
final BiomeType target = we.getServer().getBiomes().get(args.getString(0));
if (target == null) { if (target == null) {
player.printError("Biome '" + args.getString(0) + "' does not exist!"); player.printError("Biome '" + args.getString(0) + "' does not exist!");
return; return;
@ -199,4 +205,5 @@ public class BiomeCommands {
player.print("Biome changed to " + target.getName() + ". " + affected + " columns affected."); player.print("Biome changed to " + target.getName() + ". " + affected + " columns affected.");
} }
} }
} }