diff --git a/config.yml b/config.yml
index 694512e..fbbb036 100644
--- a/config.yml
+++ b/config.yml
@@ -67,6 +67,11 @@ limit:
# default: false
button: false
+ # BlockWorkbenches
+ # When enabled also blocks usage of workbenches like chests (so the creative player never can see his inventar).
+ # default: false
+ workbench: false
+
# BlockDamageToMobs
# Prevents dealing damage to all creatures in creative (friendly sheeps as well as hostile creepers).
# default: false
@@ -132,3 +137,10 @@ permissions:
# When "PermissionsEnabled" is false, the KeepInventory-Option will act like disabled, even if you set it to true.
# default: false
keepinventory: false
+
+
+# Locale (Language)
+# Uncomment the "locale: en_US"-Line, to override the locale which be used for localized messages. By default the
+# System-Locale is used (selected by Java depending on LC_LANG-Environment-Variable
+# default: none (Use System-Default Locale)
+#locale: en_US
\ No newline at end of file
diff --git a/lang/default.yml b/lang/en_US.yml
similarity index 100%
rename from lang/default.yml
rename to lang/en_US.yml
diff --git a/plugin.yml b/plugin.yml
index 2ab6c99..c11cfa0 100644
--- a/plugin.yml
+++ b/plugin.yml
@@ -1,7 +1,7 @@
name: LimitedCreative
main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore
-version: 0.9.1-beta
-softdepend: [WorldGuard, WorldEdit, MultiInv, AuthMe]
+version: 0.9.2-beta
+softdepend: [WorldGuard, WorldEdit, MultiInv]
dev-url: http://dev.bukkit.org/server-mods/limited-creative/
commands:
limitedcreative:
diff --git a/src/de/jaschastarke/minecraft/integration/Communicator.java b/src/de/jaschastarke/minecraft/integration/Communicator.java
index d3f17cc..760bf1a 100644
--- a/src/de/jaschastarke/minecraft/integration/Communicator.java
+++ b/src/de/jaschastarke/minecraft/integration/Communicator.java
@@ -17,6 +17,9 @@
*/
package de.jaschastarke.minecraft.integration;
+import org.bukkit.Bukkit;
+import org.bukkit.GameMode;
+import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@@ -26,9 +29,17 @@ public class Communicator extends AbstractCommunicator {
}
public boolean isLoggedIn(Player player) {
- if (isPluginEnabled("AuthMe"))
- return AuthMe.isLoggedInComplete(player);
- //return getBridge(AuthMe.class).isLoggedIn(player);*/
+ if (isPluginEnabled("AuthMe") && !AuthMe.isLoggedInComplete(player))
+ return false;
+ if (isPluginEnabled("xAuth") && !xAuth.isLoggedInNotGuest(player))
+ return false;
return true;
}
+
+ public boolean isCreative(World world) {
+ boolean creative = Bukkit.getServer().getDefaultGameMode() == GameMode.CREATIVE;
+ if (isPluginEnabled("Multiverse-Core"))
+ creative = MultiVerse.isCreative(world);
+ return creative;
+ }
}
diff --git a/src/de/jaschastarke/minecraft/integration/MultiVerse.java b/src/de/jaschastarke/minecraft/integration/MultiVerse.java
new file mode 100644
index 0000000..a0ff121
--- /dev/null
+++ b/src/de/jaschastarke/minecraft/integration/MultiVerse.java
@@ -0,0 +1,35 @@
+/*
+ * 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.integration;
+
+import org.bukkit.Bukkit;
+import org.bukkit.GameMode;
+import org.bukkit.World;
+
+import com.onarandombox.MultiverseCore.MultiverseCore;
+
+public class MultiVerse implements CommunicationBridge {
+
+ public static boolean isCreative(World world) {
+ return getMV().getMVWorldManager().getMVWorld(world).getGameMode() == GameMode.CREATIVE;
+ }
+
+ private static MultiverseCore getMV() {
+ return (MultiverseCore) Bukkit.getServer().getPluginManager().getPlugin("Multiverse-Core");
+ }
+}
diff --git a/src/de/jaschastarke/minecraft/integration/xAuth.java b/src/de/jaschastarke/minecraft/integration/xAuth.java
new file mode 100644
index 0000000..7e923ad
--- /dev/null
+++ b/src/de/jaschastarke/minecraft/integration/xAuth.java
@@ -0,0 +1,38 @@
+/*
+ * 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.integration;
+
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+
+import com.cypherx.xauth.xAuthPlayer;
+
+public class xAuth implements CommunicationBridge {
+ public static boolean isLoggedInNotGuest(Player player) {
+ xAuthPlayer xpl = getAuth().getPlayer(player.getName());
+ if (!xpl.isAuthenticated())
+ return false;
+ if (xpl.isGuest())
+ return false;
+ return true;
+ }
+
+ private static com.cypherx.xauth.xAuth getAuth() {
+ return (com.cypherx.xauth.xAuth) Bukkit.getServer().getPluginManager().getPlugin("xAuth");
+ }
+}
diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java b/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java
index 70a6e02..beb2b83 100644
--- a/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java
+++ b/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java
@@ -40,6 +40,7 @@ public class Configuration {
BLOCKSIGN("limit.sign", true),
BLOCKBUTTON("limit.button", false),
BLOCKDAMAGEMOB("limit.damagemob", false),
+ BLOCKBENCHES("limit.workbench", false),
REMOVEDROP("limit.remove_drops", true),
REMOVEPICKUP("limit.remove_pickup", false),
PERMISSIONS("permissions.enabled", false),
@@ -122,6 +123,9 @@ public class Configuration {
public boolean getSignBlock() {
return this.getBoolean(Option.BLOCKSIGN);
}
+ public boolean getBenchBlock() {
+ return this.getBoolean(Option.BLOCKBENCHES);
+ }
public boolean getButtonBlock() {
return this.getBoolean(Option.BLOCKBUTTON);
}
@@ -145,6 +149,11 @@ public class Configuration {
return this.getBoolean(Option.REGION_OPTIONAL);
}
+ public String getLocale() {
+ if (c.contains("locale") && c.getString("locale") != "none")
+ return c.getString("locale");
+ return null;
+ }
protected void reload() {
_block_break = null;
diff --git a/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java b/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java
index 307e36f..5f07ec7 100644
--- a/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java
+++ b/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java
@@ -31,6 +31,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Creature;
+import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
@@ -240,8 +241,8 @@ public class LCPlayer {
tempinv = null;
}
- public void onDamage(EntityDamageByEntityEvent event) { // receives damage
- if (event.getDamager() instanceof Player) {
+ public void onDamage(Entity from, EntityDamageByEntityEvent event) { // receives damage
+ if (from instanceof Player) {
// its PVP
Player attacker = (Player) event.getDamager();
if (attacker.getGameMode() == GameMode.CREATIVE) {
@@ -296,6 +297,14 @@ public class LCPlayer {
event.getPlayer().sendMessage(L("blocked.chest"));
event.setCancelled(true);
}
+ public void onBenchAccess(PlayerInteractEvent event) {
+ if (!plugin.config.getBenchBlock() || player.getGameMode() != GameMode.CREATIVE)
+ return;
+ if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.chest"))
+ return;
+ event.getPlayer().sendMessage(L("blocked.chest"));
+ event.setCancelled(true);
+ }
public void onSignAccess(PlayerInteractEvent event) {
if (!plugin.config.getSignBlock() || player.getGameMode() != GameMode.CREATIVE)
return;
@@ -323,10 +332,13 @@ public class LCPlayer {
private long lastFloatingTimeWarning = 0;
public void setRegionCreativeAllowed(boolean rcreative, PlayerMoveEvent event) {
- if (rcreative && player.getGameMode() == GameMode.SURVIVAL && !isRegionCreative()) {
+ GameMode DEFAULT_GAMEMODE = plugin.com.isCreative(event.getTo().getWorld()) ? GameMode.CREATIVE : GameMode.SURVIVAL;
+ GameMode TEMPORARY_GAMEMODE = DEFAULT_GAMEMODE == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL;
+
+ if (rcreative && player.getGameMode() == DEFAULT_GAMEMODE && !isRegionCreative()) {
setRegionCreative(true); // have to be set, before setGameMode
- player.setGameMode(GameMode.CREATIVE);
- } else if (!rcreative && player.getGameMode() == GameMode.CREATIVE && !isPermanentCreative()) {
+ player.setGameMode(TEMPORARY_GAMEMODE);
+ } else if (!rcreative && player.getGameMode() == TEMPORARY_GAMEMODE && !isPermanentCreative()) {
if (getFloatingHeight() > 3) {
if (System.currentTimeMillis() - lastFloatingTimeWarning > 10000) {// 10 sec. limit
player.sendMessage(L("blocked.survival_flying"));
@@ -375,4 +387,5 @@ public class LCPlayer {
public boolean hasPermission(String permission) {
return plugin.perm.hasPermission(this.getRaw(), permission);
}
+
}
diff --git a/src/de/jaschastarke/minecraft/limitedcreative/LimitedCreativeCore.java b/src/de/jaschastarke/minecraft/limitedcreative/LimitedCreativeCore.java
index 5c4d026..bcb8903 100644
--- a/src/de/jaschastarke/minecraft/limitedcreative/LimitedCreativeCore.java
+++ b/src/de/jaschastarke/minecraft/limitedcreative/LimitedCreativeCore.java
@@ -42,14 +42,16 @@ public class LimitedCreativeCore extends JavaPlugin {
@Override
public void onDisable() {
plugin.getServer().getScheduler().cancelTasks(this);
+ try {
+ worldguard.unload();
+ Locale.unload();
+ } catch (NoClassDefFoundError e) {} // prevent unload issue
+
plugin = null;
worldguard = null;
config = null;
spawnblock = null;
com = null;
- try {
- Locale.unload();
- } catch (NoClassDefFoundError e) {} // prevent unload issue
}
@Override
@@ -59,7 +61,7 @@ public class LimitedCreativeCore extends JavaPlugin {
perm = new Permissions(this);
com = new Communicator(this);
- new Locale(this);
+ new Locale(this, config.getLocale());
spawnblock = new NoBlockItemSpawn();
diff --git a/src/de/jaschastarke/minecraft/limitedcreative/listeners/LimitListener.java b/src/de/jaschastarke/minecraft/limitedcreative/listeners/LimitListener.java
index d7d52be..9b2a227 100644
--- a/src/de/jaschastarke/minecraft/limitedcreative/listeners/LimitListener.java
+++ b/src/de/jaschastarke/minecraft/limitedcreative/listeners/LimitListener.java
@@ -25,6 +25,7 @@ import org.bukkit.block.ContainerBlock;
import org.bukkit.block.Sign;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
+import org.bukkit.entity.Projectile;
import org.bukkit.entity.StorageMinecart;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
@@ -98,6 +99,8 @@ public class LimitListener implements Listener {
player.onSignAccess(event);
} else if (block.getState() instanceof Lever || block.getState() instanceof Button) {
player.onButtonAccess(event);
+ } else if (block.getType() == Material.WORKBENCH) {
+ player.onBenchAccess(event);
}
}
@@ -128,11 +131,16 @@ public class LimitListener implements Listener {
return;
if (meta_event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) meta_event;
+
+ Entity source = event.getDamager();
+ if (source instanceof Projectile)
+ source = ((Projectile) source).getShooter();
+
if (event.getEntity() instanceof Player) {
- LCPlayer.get((Player) event.getEntity()).onDamage(event);
+ LCPlayer.get((Player) event.getEntity()).onDamage(source, event);
}
- if (!event.isCancelled() && event.getDamager() instanceof Player){
- LCPlayer.get((Player) event.getDamager()).onDealDamage(event);
+ if (!event.isCancelled() && source instanceof Player) {
+ LCPlayer.get((Player) source).onDealDamage(event);
}
}
}
diff --git a/src/de/jaschastarke/minecraft/limitedcreative/regions/GameModeFlag.java b/src/de/jaschastarke/minecraft/limitedcreative/regions/GameModeFlag.java
new file mode 100644
index 0000000..d53ced9
--- /dev/null
+++ b/src/de/jaschastarke/minecraft/limitedcreative/regions/GameModeFlag.java
@@ -0,0 +1,94 @@
+package de.jaschastarke.minecraft.limitedcreative.regions;
+
+import org.bukkit.GameMode;
+import org.bukkit.command.CommandSender;
+
+import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
+import com.sk89q.worldguard.protection.flags.Flag;
+import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
+import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
+
+/**
+ * Well, that was an interesting idea, but it doesn't work.
+ */
+public class GameModeFlag extends Flag {
+ private State def;
+ private RegionGroupFlag groupFlag;
+
+ public enum State {
+ CREATIVE,
+ SURVIVAL,
+ NONE;
+
+ public GameMode getGameMode() {
+ return getBukkitGameMode(this);
+ }
+ public boolean equals (GameMode gm) {
+ return gm == this.getGameMode();
+ }
+ public static GameMode getBukkitGameMode(State gm) {
+ switch (gm) {
+ case CREATIVE:
+ return GameMode.CREATIVE;
+ case SURVIVAL:
+ return GameMode.SURVIVAL;
+ default:
+ return null;
+ }
+ }
+ }
+
+ public GameModeFlag(String name, State def) {
+ super(name);
+ this.def = def;
+ }
+
+ public State getDefault() {
+ return def;
+ }
+
+ public RegionGroupFlag getGroupFlag() {
+ return groupFlag;
+ }
+
+ public void setGroupFlag(RegionGroupFlag groupFlag) {
+ this.groupFlag = groupFlag;
+ }
+
+ @Override
+ public State parseInput(WorldGuardPlugin plugin, CommandSender sender, String input) throws InvalidFlagFormat {
+ input = input.trim();
+ if (input.equalsIgnoreCase("creative")) {
+ return State.CREATIVE;
+ } else if (input.equalsIgnoreCase("survival")) {
+ return State.SURVIVAL;
+ } else if (input.equalsIgnoreCase("none")) {
+ return null;
+ } else {
+ throw new InvalidFlagFormat("Expected none/allow/deny but got '" + input + "'");
+ }
+ }
+
+ @Override
+ public State unmarshal(Object o) {
+ String input = o.toString();
+ if (input.equalsIgnoreCase("creative")) {
+ return State.CREATIVE;
+ } else if (input.equalsIgnoreCase("survival")) {
+ return State.SURVIVAL;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Object marshal(State o) {
+ if (o == State.CREATIVE) {
+ return "allow";
+ } else if (o == State.SURVIVAL) {
+ return "deny";
+ } else {
+ return null;
+ }
+ }
+}
diff --git a/src/de/jaschastarke/minecraft/limitedcreative/regions/WorldGuardIntegration.java b/src/de/jaschastarke/minecraft/limitedcreative/regions/WorldGuardIntegration.java
index e52b286..203abf4 100644
--- a/src/de/jaschastarke/minecraft/limitedcreative/regions/WorldGuardIntegration.java
+++ b/src/de/jaschastarke/minecraft/limitedcreative/regions/WorldGuardIntegration.java
@@ -57,4 +57,8 @@ public class WorldGuardIntegration implements Integration {
public List> getFlags() {
return Flags.getList();
}
+
+ public void unload() {
+ Interface.unload();
+ }
}
diff --git a/src/de/jaschastarke/minecraft/utils/Locale.java b/src/de/jaschastarke/minecraft/utils/Locale.java
index ece0d4c..19f1c8b 100644
--- a/src/de/jaschastarke/minecraft/utils/Locale.java
+++ b/src/de/jaschastarke/minecraft/utils/Locale.java
@@ -24,43 +24,70 @@ import java.util.List;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
+import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
+
public class Locale {
protected YamlConfiguration lang;
+ private YamlConfiguration fallback_lang;
private static Locale inst = null;
+ private JavaPlugin plugin;
+ private final static String DEFAULT_LANG = "en_US";
public Locale(JavaPlugin plugin) {
- String fn = getFilename("default");
+ this(plugin, null);
+ }
+
+ public Locale(JavaPlugin plugin, String lang) {
+ if (inst == null)
+ inst = this;
+ this.plugin = plugin;
+ if (lang == null)
+ lang = java.util.Locale.getDefault().toString();
+
+ String fn = getFilename(lang);
+
+ LimitedCreativeCore.debug("Using Locale: " + lang);
File localefile = new File(plugin.getDataFolder(), fn);
if (localefile.exists())
- lang = YamlConfiguration.loadConfiguration(localefile);
- else
- lang = YamlConfiguration.loadConfiguration(plugin.getResource(fn));
- inst = this;
+ this.lang = YamlConfiguration.loadConfiguration(localefile);
+ else if (plugin.getResource(fn) != null)
+ this.lang = YamlConfiguration.loadConfiguration(plugin.getResource(fn));
}
private String getFilename(String locale) {
return "lang/"+locale+".yml";
}
- public String get(String msg) {
+ private YamlConfiguration getLang(String msg) {
+ if (lang != null && lang.contains(msg)) {
+ return lang;
+ } else {
+ if (fallback_lang == null)
+ fallback_lang = YamlConfiguration.loadConfiguration(plugin.getResource(getFilename(DEFAULT_LANG)));
+ return fallback_lang;
+ }
+ }
+ public String get(String msg, Object... objects) {
+ YamlConfiguration lang = getLang(msg);
if (lang.contains(msg)) {
if (lang.isList(msg)) {
List list = lang.getStringList(msg);
String[] lines = new String[list.size()];
list.toArray(lines);
- return Util.join(lines, "\n");
+ msg = Util.join(lines, "\n");
} else {
- return lang.getString(msg);
+ msg = lang.getString(msg);
}
}
- return msg;
+ if (objects.length > 0)
+ msg = MessageFormat.format(msg, objects);
+ return msg.replaceAll("&([0-9a-f])", "\u00A7$1");
}
+ /**
+ * Static localization-access only works for first locale instance. if used by another plugin, you need to
+ * access the Locale-Instance get-Method
+ */
public static String L(String msg, Object... objects) {
- if (inst != null)
- msg = inst.get(msg);
- if (objects.length > 0)
- return MessageFormat.format(msg, objects);
- else
- return msg;
+ return (inst != null) ? inst.get(msg, objects) : msg;
}
public static void unload() {
inst = null;
diff --git a/src/de/jaschastarke/minecraft/worldguard/Interface.java b/src/de/jaschastarke/minecraft/worldguard/Interface.java
index a38438a..9acac40 100644
--- a/src/de/jaschastarke/minecraft/worldguard/Interface.java
+++ b/src/de/jaschastarke/minecraft/worldguard/Interface.java
@@ -55,4 +55,7 @@ public class Interface {
public CRegionManager getRegionManager() {
return mgr;
}
+ public static void unload() {
+ _instance = null;
+ }
}