- localization

- xauth integration
 - beginning multiverse/creative world integration (not completed yet)
This commit is contained in:
Jascha Starke 2012-02-13 22:19:34 +01:00
parent d4ee873f77
commit 07fcabbd56
14 changed files with 288 additions and 32 deletions

View file

@ -67,6 +67,11 @@ limit:
# default: false # default: false
button: 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 # BlockDamageToMobs
# Prevents dealing damage to all creatures in creative (friendly sheeps as well as hostile creepers). # Prevents dealing damage to all creatures in creative (friendly sheeps as well as hostile creepers).
# default: false # 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. # When "PermissionsEnabled" is false, the KeepInventory-Option will act like disabled, even if you set it to true.
# default: false # default: false
keepinventory: 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

View file

@ -1,7 +1,7 @@
name: LimitedCreative name: LimitedCreative
main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore
version: 0.9.1-beta version: 0.9.2-beta
softdepend: [WorldGuard, WorldEdit, MultiInv, AuthMe] softdepend: [WorldGuard, WorldEdit, MultiInv]
dev-url: http://dev.bukkit.org/server-mods/limited-creative/ dev-url: http://dev.bukkit.org/server-mods/limited-creative/
commands: commands:
limitedcreative: limitedcreative:

View file

@ -17,6 +17,9 @@
*/ */
package de.jaschastarke.minecraft.integration; 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.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -26,9 +29,17 @@ public class Communicator extends AbstractCommunicator {
} }
public boolean isLoggedIn(Player player) { public boolean isLoggedIn(Player player) {
if (isPluginEnabled("AuthMe")) if (isPluginEnabled("AuthMe") && !AuthMe.isLoggedInComplete(player))
return AuthMe.isLoggedInComplete(player); return false;
//return getBridge(AuthMe.class).isLoggedIn(player);*/ if (isPluginEnabled("xAuth") && !xAuth.isLoggedInNotGuest(player))
return false;
return true; return true;
} }
public boolean isCreative(World world) {
boolean creative = Bukkit.getServer().getDefaultGameMode() == GameMode.CREATIVE;
if (isPluginEnabled("Multiverse-Core"))
creative = MultiVerse.isCreative(world);
return creative;
}
} }

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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");
}
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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");
}
}

View file

@ -40,6 +40,7 @@ public class Configuration {
BLOCKSIGN("limit.sign", true), BLOCKSIGN("limit.sign", true),
BLOCKBUTTON("limit.button", false), BLOCKBUTTON("limit.button", false),
BLOCKDAMAGEMOB("limit.damagemob", false), BLOCKDAMAGEMOB("limit.damagemob", false),
BLOCKBENCHES("limit.workbench", false),
REMOVEDROP("limit.remove_drops", true), REMOVEDROP("limit.remove_drops", true),
REMOVEPICKUP("limit.remove_pickup", false), REMOVEPICKUP("limit.remove_pickup", false),
PERMISSIONS("permissions.enabled", false), PERMISSIONS("permissions.enabled", false),
@ -122,6 +123,9 @@ public class Configuration {
public boolean getSignBlock() { public boolean getSignBlock() {
return this.getBoolean(Option.BLOCKSIGN); return this.getBoolean(Option.BLOCKSIGN);
} }
public boolean getBenchBlock() {
return this.getBoolean(Option.BLOCKBENCHES);
}
public boolean getButtonBlock() { public boolean getButtonBlock() {
return this.getBoolean(Option.BLOCKBUTTON); return this.getBoolean(Option.BLOCKBUTTON);
} }
@ -145,6 +149,11 @@ public class Configuration {
return this.getBoolean(Option.REGION_OPTIONAL); 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() { protected void reload() {
_block_break = null; _block_break = null;

View file

@ -31,6 +31,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Creature; import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
@ -240,8 +241,8 @@ public class LCPlayer {
tempinv = null; tempinv = null;
} }
public void onDamage(EntityDamageByEntityEvent event) { // receives damage public void onDamage(Entity from, EntityDamageByEntityEvent event) { // receives damage
if (event.getDamager() instanceof Player) { if (from instanceof Player) {
// its PVP // its PVP
Player attacker = (Player) event.getDamager(); Player attacker = (Player) event.getDamager();
if (attacker.getGameMode() == GameMode.CREATIVE) { if (attacker.getGameMode() == GameMode.CREATIVE) {
@ -296,6 +297,14 @@ public class LCPlayer {
event.getPlayer().sendMessage(L("blocked.chest")); event.getPlayer().sendMessage(L("blocked.chest"));
event.setCancelled(true); 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) { public void onSignAccess(PlayerInteractEvent event) {
if (!plugin.config.getSignBlock() || player.getGameMode() != GameMode.CREATIVE) if (!plugin.config.getSignBlock() || player.getGameMode() != GameMode.CREATIVE)
return; return;
@ -323,10 +332,13 @@ public class LCPlayer {
private long lastFloatingTimeWarning = 0; private long lastFloatingTimeWarning = 0;
public void setRegionCreativeAllowed(boolean rcreative, PlayerMoveEvent event) { 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 setRegionCreative(true); // have to be set, before setGameMode
player.setGameMode(GameMode.CREATIVE); player.setGameMode(TEMPORARY_GAMEMODE);
} else if (!rcreative && player.getGameMode() == GameMode.CREATIVE && !isPermanentCreative()) { } else if (!rcreative && player.getGameMode() == TEMPORARY_GAMEMODE && !isPermanentCreative()) {
if (getFloatingHeight() > 3) { if (getFloatingHeight() > 3) {
if (System.currentTimeMillis() - lastFloatingTimeWarning > 10000) {// 10 sec. limit if (System.currentTimeMillis() - lastFloatingTimeWarning > 10000) {// 10 sec. limit
player.sendMessage(L("blocked.survival_flying")); player.sendMessage(L("blocked.survival_flying"));
@ -375,4 +387,5 @@ public class LCPlayer {
public boolean hasPermission(String permission) { public boolean hasPermission(String permission) {
return plugin.perm.hasPermission(this.getRaw(), permission); return plugin.perm.hasPermission(this.getRaw(), permission);
} }
} }

View file

@ -42,14 +42,16 @@ public class LimitedCreativeCore extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
plugin.getServer().getScheduler().cancelTasks(this); plugin.getServer().getScheduler().cancelTasks(this);
try {
worldguard.unload();
Locale.unload();
} catch (NoClassDefFoundError e) {} // prevent unload issue
plugin = null; plugin = null;
worldguard = null; worldguard = null;
config = null; config = null;
spawnblock = null; spawnblock = null;
com = null; com = null;
try {
Locale.unload();
} catch (NoClassDefFoundError e) {} // prevent unload issue
} }
@Override @Override
@ -59,7 +61,7 @@ public class LimitedCreativeCore extends JavaPlugin {
perm = new Permissions(this); perm = new Permissions(this);
com = new Communicator(this); com = new Communicator(this);
new Locale(this); new Locale(this, config.getLocale());
spawnblock = new NoBlockItemSpawn(); spawnblock = new NoBlockItemSpawn();

View file

@ -25,6 +25,7 @@ import org.bukkit.block.ContainerBlock;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.StorageMinecart; import org.bukkit.entity.StorageMinecart;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -98,6 +99,8 @@ public class LimitListener implements Listener {
player.onSignAccess(event); player.onSignAccess(event);
} else if (block.getState() instanceof Lever || block.getState() instanceof Button) { } else if (block.getState() instanceof Lever || block.getState() instanceof Button) {
player.onButtonAccess(event); player.onButtonAccess(event);
} else if (block.getType() == Material.WORKBENCH) {
player.onBenchAccess(event);
} }
} }
@ -128,11 +131,16 @@ public class LimitListener implements Listener {
return; return;
if (meta_event instanceof EntityDamageByEntityEvent) { if (meta_event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) meta_event; EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) meta_event;
Entity source = event.getDamager();
if (source instanceof Projectile)
source = ((Projectile) source).getShooter();
if (event.getEntity() instanceof Player) { 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){ if (!event.isCancelled() && source instanceof Player) {
LCPlayer.get((Player) event.getDamager()).onDealDamage(event); LCPlayer.get((Player) source).onDealDamage(event);
} }
} }
} }

View file

@ -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<GameModeFlag.State> {
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;
}
}
}

View file

@ -57,4 +57,8 @@ public class WorldGuardIntegration implements Integration {
public List<Flag<?>> getFlags() { public List<Flag<?>> getFlags() {
return Flags.getList(); return Flags.getList();
} }
public void unload() {
Interface.unload();
}
} }

View file

@ -24,43 +24,70 @@ import java.util.List;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
public class Locale { public class Locale {
protected YamlConfiguration lang; protected YamlConfiguration lang;
private YamlConfiguration fallback_lang;
private static Locale inst = null; private static Locale inst = null;
private JavaPlugin plugin;
private final static String DEFAULT_LANG = "en_US";
public Locale(JavaPlugin plugin) { 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); File localefile = new File(plugin.getDataFolder(), fn);
if (localefile.exists()) if (localefile.exists())
lang = YamlConfiguration.loadConfiguration(localefile); this.lang = YamlConfiguration.loadConfiguration(localefile);
else else if (plugin.getResource(fn) != null)
lang = YamlConfiguration.loadConfiguration(plugin.getResource(fn)); this.lang = YamlConfiguration.loadConfiguration(plugin.getResource(fn));
inst = this;
} }
private String getFilename(String locale) { private String getFilename(String locale) {
return "lang/"+locale+".yml"; 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.contains(msg)) {
if (lang.isList(msg)) { if (lang.isList(msg)) {
List<String> list = lang.getStringList(msg); List<String> list = lang.getStringList(msg);
String[] lines = new String[list.size()]; String[] lines = new String[list.size()];
list.toArray(lines); list.toArray(lines);
return Util.join(lines, "\n"); msg = Util.join(lines, "\n");
} else { } 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) { public static String L(String msg, Object... objects) {
if (inst != null) return (inst != null) ? inst.get(msg, objects) : msg;
msg = inst.get(msg);
if (objects.length > 0)
return MessageFormat.format(msg, objects);
else
return msg;
} }
public static void unload() { public static void unload() {
inst = null; inst = null;

View file

@ -55,4 +55,7 @@ public class Interface {
public CRegionManager getRegionManager() { public CRegionManager getRegionManager() {
return mgr; return mgr;
} }
public static void unload() {
_instance = null;
}
} }