Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-05 11:00:05 +01:00
Improved messages for tools.
Dieser Commit ist enthalten in:
Ursprung
1fe6f09066
Commit
7d661844ad
35
src/com/sk89q/worldedit/InvalidToolBindException.java
Normale Datei
35
src/com/sk89q/worldedit/InvalidToolBindException.java
Normale Datei
@ -0,0 +1,35 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit;
|
||||
|
||||
public class InvalidToolBindException extends WorldEditException {
|
||||
private static final long serialVersionUID = -1865311004052447699L;
|
||||
|
||||
private int itemId;
|
||||
|
||||
public InvalidToolBindException(int itemId, String msg) {
|
||||
super(msg);
|
||||
this.itemId = itemId;
|
||||
}
|
||||
|
||||
public int getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
}
|
@ -431,8 +431,9 @@ public class LocalSession {
|
||||
*
|
||||
* @param item
|
||||
* @return the tool
|
||||
* @throws InvalidToolBindException
|
||||
*/
|
||||
public Brush getBrushTool(int item) {
|
||||
public Brush getBrushTool(int item) throws InvalidToolBindException {
|
||||
Tool tool = getTool(item);
|
||||
|
||||
if (tool == null || !(tool instanceof Brush)) {
|
||||
@ -448,8 +449,17 @@ public class LocalSession {
|
||||
*
|
||||
* @param item
|
||||
* @param tool the tool to set
|
||||
* @throws InvalidToolBindException
|
||||
*/
|
||||
public void setTool(int item, Tool tool) {
|
||||
public void setTool(int item, Tool tool) throws InvalidToolBindException {
|
||||
if (item > 0 && item < 255) {
|
||||
throw new InvalidToolBindException(item, "Blocks can't be used");
|
||||
} else if (item == 263 || item == 348) {
|
||||
throw new InvalidToolBindException(item, "Item is not usuable");
|
||||
} else if (item == config.wandItem) {
|
||||
throw new InvalidToolBindException(item, "Already used for the wand");
|
||||
}
|
||||
|
||||
this.tools.put(item, tool);
|
||||
}
|
||||
|
||||
|
@ -946,6 +946,9 @@ public class WorldEdit {
|
||||
} catch (FilenameResolutionException e) {
|
||||
player.printError("File '" + e.getFilename() + "' resolution error: "
|
||||
+ e.getMessage());
|
||||
} catch (InvalidToolBindException e) {
|
||||
player.printError("Can't bind tool to "
|
||||
+ ItemType.toHeldName(e.getItemId()) + ": " + e.getMessage());
|
||||
} catch (FileSelectionAbortedException e) {
|
||||
player.printError("File selection aborted.");
|
||||
} catch (WorldEditException e) {
|
||||
|
@ -291,6 +291,39 @@ public enum ItemType {
|
||||
return ids.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a name for the item.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static String toName(int id) {
|
||||
ItemType type = ids.get(id);
|
||||
if (type != null) {
|
||||
return type.getName();
|
||||
} else {
|
||||
return "#" + id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a name for a held item.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static String toHeldName(int id) {
|
||||
if (id == 0) {
|
||||
return "Hand";
|
||||
}
|
||||
ItemType type = ids.get(id);
|
||||
if (type != null) {
|
||||
return type.getName();
|
||||
} else {
|
||||
return "#" + id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type from name. May return null.
|
||||
*
|
||||
|
@ -25,6 +25,7 @@ import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.minecraft.util.commands.NestedCommand;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldedit.tools.*;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
|
||||
@ -41,7 +42,7 @@ public class ToolCommands {
|
||||
throws WorldEditException {
|
||||
|
||||
session.setTool(player.getItemInHand(), null);
|
||||
player.print("Now no longer equipping a tool.");
|
||||
player.print("Tool unbound from your current item.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -57,7 +58,8 @@ public class ToolCommands {
|
||||
throws WorldEditException {
|
||||
|
||||
session.setTool(player.getItemInHand(), new QueryTool());
|
||||
player.print("Info tool equipped. Right click with a pickaxe.");
|
||||
player.print("Info tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -82,7 +84,8 @@ public class ToolCommands {
|
||||
}
|
||||
|
||||
session.setTool(player.getItemInHand(), new TreePlanter(new TreeGenerator(type)));
|
||||
player.print("Tree tool equipped. Right click grass with a pickaxe.");
|
||||
player.print("Tree tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -99,7 +102,8 @@ public class ToolCommands {
|
||||
|
||||
BaseBlock targetBlock = we.getBlock(player, args.getString(0));
|
||||
session.setTool(player.getItemInHand(), new BlockReplacer(targetBlock));
|
||||
player.print("Block replacer tool equipped. Right click with a pickaxe.");
|
||||
player.print("Block replacer tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -115,7 +119,8 @@ public class ToolCommands {
|
||||
throws WorldEditException {
|
||||
|
||||
session.setTool(player.getItemInHand(), new BlockDataCyler());
|
||||
player.print("Block cycler tool equipped. Right click with a pickaxe.");
|
||||
player.print("Block data cycler tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren