diff --git a/pom.xml b/pom.xml
index 3f1269d..69cdc6b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -146,6 +146,7 @@
de.jaschastarke.minecraft.limitedcreative.limits.NoLimitPermissions:PARENT
de.jaschastarke.minecraft.limitedcreative.cmdblocker.CmdBlockPermissions:CONTAINER
de.jaschastarke.minecraft.limitedcreative.regions.RegionPermissions:REGION
+ de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStatePermissions:PARENT
de.jaschastarke.minecraft.limitedcreative.MainCommand
diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java
index a87f09d..0949827 100644
--- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java
+++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java
@@ -20,7 +20,7 @@ public class ModBlockStates extends CoreModule {
}
@Override
public String getName() {
- return "GameModePerm";
+ return "BlockState";
}
@Override
diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java
index 543e611..dcea994 100644
--- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java
+++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java
@@ -31,7 +31,10 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub
@Override
public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException {
- super.setValue(node, pValue);
+ if (node.getName().equals("tool"))
+ setTool(pValue);
+ else
+ super.setValue(node, pValue);
if (node.getName().equals("enabled")) {
if (getEnabled()) {
if (entry.initialState != ModuleState.NOT_INITIALIZED)
@@ -75,10 +78,10 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub
* The id or technical name (http://tinyurl.com/bukkit-material) of an item that displays information about the
* right-clicked block.
*
- * default: WOOD_AXE
+ * default: WOOD_PICKAXE
*/
@IsConfigurationNode(order = 200)
- public Material getToolType() {
+ public Material getTool() {
if (config.isString("tool")) {
Material v = Material.getMaterial(config.getString("tool"));
if (v != null)
@@ -88,12 +91,40 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub
if (v != null)
return v;
} else {
- Object v = config.get("tool", Material.WOOD_AXE);
+ Object v = config.get("tool", Material.WOOD_PICKAXE);
if (v instanceof Material)
return (Material) v;
}
mod.getLog().warn("Unknown BlockStateTool: " + config.get("tool"));
- return Material.WOOD_AXE;
+ return Material.WOOD_PICKAXE;
}
+ protected void setTool(Object val) throws InvalidValueException {
+ String v = (String) val;
+ Material m = null;
+ try {
+ int i = Integer.parseInt(v);
+ if (i > 0)
+ m = Material.getMaterial(i);
+ } catch (NumberFormatException e) {
+ m = null;
+ }
+ if (m == null)
+ m = Material.getMaterial(v);
+ if (m == null)
+ throw new InvalidValueException("Material '" + v + "' not found");
+ else
+ config.set("tool", m);
+ }
+
+
+ @Override
+ public Object getValue(final IConfigurationNode node) {
+ Object val = super.getValue(node);
+ if (node.getName().equals("tool") && val != null) {
+ return val.toString();
+ } else {
+ return val;
+ }
+ }
}
diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStatePermissions.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStatePermissions.java
new file mode 100644
index 0000000..4a1f5f6
--- /dev/null
+++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStatePermissions.java
@@ -0,0 +1,43 @@
+/*
+ * Limited Creative - (Bukkit Plugin)
+ * Copyright (C) 2012 jascha@ja-s.de
+ *
+ * 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 .
+ */
+package de.jaschastarke.minecraft.limitedcreative.blockstate;
+
+import org.bukkit.permissions.PermissionDefault;
+
+import de.jaschastarke.maven.ArchiveDocComments;
+import de.jaschastarke.minecraft.lib.permissions.BasicPermission;
+import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
+import de.jaschastarke.minecraft.lib.permissions.IPermission;
+import de.jaschastarke.minecraft.lib.permissions.IPermissionContainer;
+import de.jaschastarke.minecraft.lib.permissions.SimplePermissionContainerNode;
+import de.jaschastarke.minecraft.limitedcreative.Permissions;
+
+@ArchiveDocComments
+public class BlockStatePermissions extends SimplePermissionContainerNode {
+ public BlockStatePermissions(IAbstractPermission parent, String name) {
+ super(parent, name);
+ }
+
+
+ public static final IPermissionContainer PARENT = new BlockStatePermissions(Permissions.CONTAINER, "blockstate");
+
+ /**
+ * Grants ability to use the configured tool to get info about placed blocks.
+ */
+ public static final IPermission TOOL = new BasicPermission(PARENT, "tool", PermissionDefault.OP);
+}
diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java
index 93111ff..51896d3 100644
--- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java
+++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/PlayerListener.java
@@ -1,5 +1,6 @@
package de.jaschastarke.minecraft.limitedcreative.blockstate;
+import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -8,7 +9,7 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import de.jaschastarke.bukkit.lib.chat.ChatFormattings;
-import de.jaschastarke.bukkit.lib.chat.NullFormatter;
+import de.jaschastarke.bukkit.lib.chat.InGameFormatter;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source;
@@ -22,17 +23,32 @@ public class PlayerListener implements Listener {
public void onInteract(PlayerInteractEvent event) {
if (event.isCancelled())
return;
- if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
+ if (event.getAction() == Action.RIGHT_CLICK_BLOCK && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) {
Block b = event.getClickedBlock();
- if (b != null && event.getPlayer().getItemInHand().getType().equals(mod.getConfig().getToolType())) {
+ if (b != null && event.getPlayer().getItemInHand().getType().equals(mod.getConfig().getTool())) {
BlockState s = mod.getDB().find(BlockState.class, new BlockLocation(b.getLocation()));
- NullFormatter f = new NullFormatter();
+ InGameFormatter f = new InGameFormatter(mod.getPlugin().getLang());
String ret = null;
if (s == null || s.getSource() == Source.UNKNOWN) {
- ret = f.formatString(ChatFormattings.ERROR, f.getString("block_state.tool_info.unknown"));
+ ret = f.formatString(ChatFormattings.ERROR, f.getString("block_state.tool_info.unknown", b.getType().toString()));
} else {
String k = "block_state.tool_info." + s.getSource().name().toLowerCase();
- ret = f.formatString(ChatFormattings.INFO, f.getString(k, b.getType(), s.getPlayerName(), s.getDate()));
+ String gm = s.getGameMode().toString().toLowerCase();
+ switch (s.getGameMode()) {
+ case CREATIVE:
+ gm = ChatColor.GOLD + gm + ChatColor.RESET;
+ case SURVIVAL:
+ gm = ChatColor.GREEN + gm + ChatColor.RESET;
+ case ADVENTURE:
+ gm = ChatColor.DARK_GREEN + gm + ChatColor.RESET;
+ default:
+ break;
+ }
+
+ ret = f.formatString(ChatFormattings.INFO, f.getString(k, b.getType().toString(),
+ s.getPlayerName(),
+ gm,
+ s.getDate()));
}
if (ret != null)
event.getPlayer().sendMessage(ret);