v0.9.5: (in work)

- major code rework
 - survival areas in creative worlds
 - multiverse support
 - better inventory storage
 - removed give-item-back-on-creative-death, as not needed and causes
more trouble then usage
This commit is contained in:
Jascha Starke 2012-02-20 21:06:20 +01:00
parent 07fcabbd56
commit 3bdca1cdb1
37 changed files with 1362 additions and 601 deletions

View file

@ -47,7 +47,7 @@ exception:
storage:
load: Failed to load your Inventory. Ask your Admin to enable "UnsafeStorage" for LimitedCreative to allow invalid enchants on items
region:
no_survival: You can not be survival in an creative area
not_optional: You can not be {0} in that area
blocked:
chest: Access to chests is not allowed in creative mode
sign: To interact with signs is not allowed in creative mode
@ -56,6 +56,8 @@ blocked:
survival_flying: You should stay on ground, when leaving a creative-area
outside_creative: You can not place blocks outside of the creative-area
outside_creative_break: You can not destroy blocks outside of the creative-area
inside_survival: You can not place blocks inside of the survival-area
inside_survival_break: You can not destroy blocks inside of the survival-area
use: You are not allowed to use this type of item
place: You are not allowed to place this type of block
break: You are not allowed to break this type of block

View file

@ -1,6 +1,6 @@
name: LimitedCreative
main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore
version: 0.9.2-beta
main: de.jaschastarke.minecraft.limitedcreative.Core
version: 0.9.5-dev
softdepend: [WorldGuard, WorldEdit, MultiInv]
dev-url: http://dev.bukkit.org/server-mods/limited-creative/
commands:
@ -23,8 +23,14 @@ permissions:
description: Allows switching of own game mode to creative and back
default: op
limitedcreative.switch_gamemode.backonly:
description: Allows switching of own game mode to default of the not world he is in, but not back
default: false
limitedcreative.switch_gamemode.survival:
description: Allows switching of own game mode to survival, but not to creative
default: true
default: false
limitedcreative.switch_gamemode.creative:
description: Allows switching of own game mode to creative, but not to survival
default: false
limitedcreative.switch_gamemode.other:
description: Allows switching of other users game mode
default: op

View file

@ -19,14 +19,20 @@ package de.jaschastarke.minecraft.integration;
import org.bukkit.entity.Player;
import de.jaschastarke.minecraft.limitedcreative.Core;
import uk.org.whoami.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.cache.limbo.LimboCache;
public class AuthMe implements CommunicationBridge {
public static boolean isLoggedIn(Player player) {
return PlayerCache.getInstance().isAuthenticated(player.getName());
boolean li = PlayerCache.getInstance().isAuthenticated(player.getName());
Core.debug("AuthMe: "+player.getName()+": logged in: "+li);
return li;
}
public static boolean isLoggedInComplete(Player player) {
return isLoggedIn(player) && LimboCache.getInstance().getLimboPlayer(player.getName()) == null;
boolean li = isLoggedIn(player) && LimboCache.getInstance().getLimboPlayer(player.getName()) == null;
Core.debug("AuthMe: "+player.getName()+": logged in complete: "+li);
return li;
}
}

View file

@ -23,6 +23,8 @@ import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import de.jaschastarke.minecraft.limitedcreative.Core;
public class Communicator extends AbstractCommunicator {
public Communicator(JavaPlugin plugin) {
super(plugin);
@ -40,6 +42,14 @@ public class Communicator extends AbstractCommunicator {
boolean creative = Bukkit.getServer().getDefaultGameMode() == GameMode.CREATIVE;
if (isPluginEnabled("Multiverse-Core"))
creative = MultiVerse.isCreative(world);
Core.debug("com: "+world.getName()+": is creative: "+creative);
return creative;
}
public GameMode getDefaultGameMode(World world) {
GameMode def = Bukkit.getServer().getDefaultGameMode();
if (isPluginEnabled("Multiverse-Core"))
def = MultiVerse.getGameMode(world);
Core.debug("com: "+world.getName()+": game mode: "+def);
return def;
}
}

View file

@ -23,10 +23,20 @@ import org.bukkit.World;
import com.onarandombox.MultiverseCore.MultiverseCore;
import de.jaschastarke.minecraft.limitedcreative.Core;
public class MultiVerse implements CommunicationBridge {
public static boolean isCreative(World world) {
return getMV().getMVWorldManager().getMVWorld(world).getGameMode() == GameMode.CREATIVE;
boolean ic = getMV().getMVWorldManager().getMVWorld(world).getGameMode() == GameMode.CREATIVE;
Core.debug("Multiverse: "+world.getName()+": is creative: "+ic);
return ic;
}
public static GameMode getGameMode(World world) {
GameMode gm = getMV().getMVWorldManager().getMVWorld(world).getGameMode();
Core.debug("Multiverse: "+world.getName()+": game mode: "+gm);
return gm;
}
private static MultiverseCore getMV() {

View file

@ -22,14 +22,18 @@ import org.bukkit.entity.Player;
import com.cypherx.xauth.xAuthPlayer;
import de.jaschastarke.minecraft.limitedcreative.Core;
public class xAuth implements CommunicationBridge {
public static boolean isLoggedInNotGuest(Player player) {
xAuthPlayer xpl = getAuth().getPlayer(player.getName());
boolean li = true;
if (!xpl.isAuthenticated())
return false;
if (xpl.isGuest())
return false;
return true;
li = false;
else if (xpl.isGuest())
li = false;
Core.debug("xAuth: "+player.getName()+": logged in not guest: "+li);
return li;
}
private static com.cypherx.xauth.xAuth getAuth() {

View file

@ -27,11 +27,12 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import de.jaschastarke.minecraft.utils.IPermission;
import de.jaschastarke.minecraft.utils.Util;
import static de.jaschastarke.minecraft.utils.Locale.L;
public class Commands {
private static LimitedCreativeCore plugin;
private static Core plugin;
public static class MainCommandExecutor implements CommandExecutor {
public enum Action {
@ -45,7 +46,7 @@ public class Commands {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
LimitedCreativeCore.debug(sender.getName() + ": /" + label + " " + Util.join(args));
Core.debug(sender.getName() + ": /" + label + " " + Util.join(args));
if (args.length > 0) {
Action act = null;
try {
@ -76,12 +77,13 @@ public class Commands {
plugin.getCommand("/region").execute(sender, "/region", args);
return true;
case RELOAD:
plugin.getServer().getPluginManager().disablePlugin(plugin);
plugin.getServer().getPluginManager().enablePlugin(plugin);
//plugin.getServer().getPluginManager().disablePlugin(plugin); // disable removes classloader, so re-enabling causes problems
//plugin.getServer().getPluginManager().enablePlugin(plugin);
plugin.reload();
return true;
}
} catch (CommandException e) {
LimitedCreativeCore.debug("CommandException: "+e.getMessage());
Core.debug("CommandException: "+e.getMessage());
sender.sendMessage(ChatColor.DARK_RED + e.getLocalizedMessage());
return true;
}
@ -92,12 +94,12 @@ public class Commands {
StringBuilder message = new StringBuilder();
message.append("/"+c+" s[urvival] ["+L("command.player")+"] - "+L("command.switch.survival")+"\n");
message.append("/"+c+" c[reative] ["+L("command.player")+"] - "+L("command.switch.creative")+"\n");
if (plugin.perm.hasPermission(sender, "limitedcreative.config")) {
if (hasPermission(sender, Perms.CONFIG)) {
message.append("/"+c+" e[nable] "+L("command.config.overview")+"\n");
message.append("/"+c+" d[isable] "+L("command.config.overview")+"\n");
message.append("/"+c+" reload "+L("command.config.reload")+"\n");
}
if (plugin.perm.hasPermission(sender, "limitedcreative.regions"))
if (hasPermission(sender, Perms.REGIONS))
message.append("/"+c+" r[egion] "+L("command.worldguard.alias")+"\n");
if (message.length() > 0) {
sender.sendMessage("Usage:");
@ -110,7 +112,7 @@ public class Commands {
}
private void setOption(CommandSender sender, String[] args, boolean b) throws CommandException {
if (sender instanceof Player && !plugin.perm.hasPermission(sender, "limitedcreative.config")) {
if (sender instanceof Player && !hasPermission(sender, Perms.CONFIG)) {
throw new LackingPermissionException();
}
if (args.length > 2)
@ -154,13 +156,17 @@ public class Commands {
if (target == null) {
throw new InvalidCommandException("exception.command.playernotfound");
} else if (sender instanceof Player && sender != target && !plugin.perm.hasPermission(sender, "limitedcreative.switch_gamemode.other")) {
} else if (sender instanceof Player && sender != target && !hasPermission(sender, Perms.GM_OTHER)) {
throw new LackingPermissionException();
} else if (target.getGameMode() != gm) {
if (sender == target) {
LCPlayer.get(target).changeGameMode(gm);
} else {
if ((hasPermission(sender, Perms.GM)) ||
Players.get(target).isGameModeAllowed(gm) ||
(gm == plugin.com.getDefaultGameMode(target.getWorld()) && hasPermission(sender, Perms.GM_BACKONLY)) ||
(gm == GameMode.CREATIVE && hasPermission(sender, Perms.GM_CREATIVE)) ||
(gm == GameMode.SURVIVAL && hasPermission(sender, Perms.GM_SURVIVAL))) {
target.setGameMode(gm);
} else {
throw new LackingPermissionException();
}
if (target != sender) {
sender.sendMessage(L("command.gamemode.changed", target.getName()));
@ -181,13 +187,16 @@ public class Commands {
}
public static void register(LimitedCreativeCore pplugin) {
public static void register(Core pplugin) {
plugin = pplugin;
plugin.getCommand("limitedcreative").setExecutor(new MainCommandExecutor());
if (plugin.worldguard == null) {
plugin.getCommand("/region").setExecutor(new NotAvailableCommandExecutor());
}
}
private static boolean hasPermission(CommandSender sender, IPermission permission) {
return plugin.perm.hasPermission(sender, permission);
}
abstract static public class CommandException extends Exception {
private static final long serialVersionUID = 1L;

View file

@ -25,13 +25,16 @@ import java.util.List;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import de.jaschastarke.minecraft.limitedcreative.store.InvYamlStorage;
import de.jaschastarke.minecraft.limitedcreative.store.PlayerInventoryStorage;
import static de.jaschastarke.minecraft.utils.Util.copyFile;
import static de.jaschastarke.minecraft.utils.Locale.L;
public class Configuration {
private FileConfiguration c;
private File file;
public static LimitedCreativeCore plugin;
public static Core plugin;
public enum Option {
STORECREATIVE("store.creative", true),
@ -66,7 +69,7 @@ public class Configuration {
}
}
public Configuration(LimitedCreativeCore pplugin) {
public Configuration(Core pplugin) {
plugin = pplugin;
file = new File(plugin.getDataFolder(), "config.yml");
@ -225,4 +228,23 @@ public class Configuration {
public boolean getTempStoreEnabled() {
return _store_enabled;
}
/**
* @return Milliseconds
*/
public long getRepeatingMessageTimeout() {
return 10000; // 10 sec. limit
}
/**
* The maximum height a player may fall down by leaving creative gamemode
* @return Block-Height
*/
public int getMaximumFloatingHeight() {
return 3;
}
public PlayerInventoryStorage getInvetoryStorage() {
return new InvYamlStorage(new File(plugin.getDataFolder(), getInventoryFolder()));
}
}

View file

@ -18,6 +18,7 @@
package de.jaschastarke.minecraft.limitedcreative;
import java.util.logging.Logger;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
@ -30,13 +31,13 @@ import de.jaschastarke.minecraft.utils.Locale;
import de.jaschastarke.minecraft.utils.Permissions;
public class LimitedCreativeCore extends JavaPlugin {
public class Core extends JavaPlugin {
public final Logger logger = Logger.getLogger("Minecraft");
public Configuration config;
public Permissions perm;
public WorldGuardIntegration worldguard;
public Communicator com;
public static LimitedCreativeCore plugin;
public static Core plugin;
public NoBlockItemSpawn spawnblock;
@Override
@ -89,12 +90,12 @@ public class LimitedCreativeCore extends JavaPlugin {
Commands.register(this);
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
/*plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override
public void run() {
LCPlayer.cleanUp();
Players.cleanUp();
}
}, LCPlayer.CLEANUP_TIMEOUT / 50L, LCPlayer.CLEANUP_TIMEOUT / 50L); // 50 = 1000ms / 20ticks
}, Players.CLEANUP_TIMEOUT / 50L, Players.CLEANUP_TIMEOUT / 50L); // 50 = 1000ms / 20ticks*/
PluginDescriptionFile df = this.getDescription();
if (worldguard != null)
@ -103,14 +104,27 @@ public class LimitedCreativeCore extends JavaPlugin {
logger.info("["+df.getName() + " v" + df.getVersion() + "] "+L("basic.loaded.no_worldguard"));
}
public void reload() {
getServer().getScheduler().cancelTasks(this);
getServer().getServicesManager().unregisterAll(this);
HandlerList.unregisterAll(this);
setEnabled(false);
setEnabled(true);
}
public void info(String s) {
logger.info("["+this.getDescription().getName()+"] " + s);
}
public void warn(String s) {
logger.warning("["+this.getDescription().getName()+"] " + s);
}
public void error(String s) {
logger.severe("["+this.getDescription().getName()+"] " + s);
}
public static void debug(String s) {
if (plugin.config.getDebug())
if (isDebug())
plugin.info("DEBUG: " + s);
}
public static boolean isDebug() {
return plugin.config.getDebug();
}
}

View file

@ -17,94 +17,85 @@
*/
package de.jaschastarke.minecraft.limitedcreative;
import java.io.File;
import java.io.IOException;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import de.jaschastarke.minecraft.limitedcreative.serialize.Armor;
import de.jaschastarke.minecraft.limitedcreative.serialize.Items;
import de.jaschastarke.minecraft.limitedcreative.store.PlayerInventoryStorage;
import static de.jaschastarke.minecraft.utils.Locale.L;
public class Inventory {
protected Player player;
protected PlayerInventory inv;
private static PlayerInventoryStorage storage = Core.plugin.config.getInvetoryStorage();
//private static InvMemStorage tempinvs = new InvMemStorage();
public Inventory(Player p) {
player = p;
protected LCPlayer player;
public enum Target {
SURVIVAL,
CREATIVE;
public static Target getTarget(GameMode gm) {
return gm == GameMode.CREATIVE ? Target.CREATIVE : Target.SURVIVAL;
}
}
public Inventory(LCPlayer player) {
this.player = player;
}
public LCPlayer getLCPlayer() {
return player;
}
public Player getPlayer() {
return player.getPlayer();
}
private PlayerInventory inv() {
return player.getInventory();
return player.getPlayer().getInventory();
}
public void save() {
LimitedCreativeCore.debug(player.getName() + " storing inventory "+player.getGameMode().toString());
File f = new File(LimitedCreativeCore.plugin.getDataFolder(), getFileName(player, player.getGameMode()));
storeInventory(inv(), f);
Core.debug(getPlayer().getName()+": store inventory: "+getPlayer().getGameMode());
storage.store(this, Target.getTarget(getPlayer().getGameMode()));
}
public void load() {
load(getPlayer().getGameMode());
}
public boolean isStored(GameMode gm) {
return storage.contains(this, Target.getTarget(gm));
}
public void load(GameMode gm) {
LimitedCreativeCore.debug(player.getName() + " loading inventory "+gm.toString());
File f = new File(LimitedCreativeCore.plugin.getDataFolder(), getFileName(player, gm));
Core.debug(getPlayer().getName()+": load inventory: "+gm);
try {
restoreInventory(inv(), f);
storage.load(this, Target.getTarget(gm));
} catch (IllegalArgumentException e) {
if (LimitedCreativeCore.plugin.config.getUnsafeStorage()) {
if (Core.plugin.config.getUnsafeStorage()) {
throw e;
} else {
player.sendMessage(ChatColor.DARK_RED + L("exception.storage.load"));
getPlayer().sendMessage(ChatColor.DARK_RED + L("exception.storage.load"));
}
}
}
public void load() {
load(player.getGameMode());
/*public void storeTemp() {
Core.debug(getPlayer().getName()+": temp store inventory");
tempinvs.store(this);
}
public void restoreTemp() {
Core.debug(getPlayer().getName()+": temp restore inventory");
tempinvs.load(this);
}
public void clearTemp() {
Core.debug(getPlayer().getName()+": temp clear inventory");
tempinvs.remove(this);
}*/
public void clear() {
inv().setArmorContents(new ItemStack[]{
new ItemStack(0),
new ItemStack(0),
new ItemStack(0),
new ItemStack(0),
});
inv().setArmorContents(new ItemStack[0]);
inv().clear();
}
private String getFileName(Player player, GameMode gm) {
if (gm != GameMode.SURVIVAL) {
return LimitedCreativeCore.plugin.config.getInventoryFolder() + File.separator + player.getName()+"_"+gm.toString()+".yml";
} else {
return LimitedCreativeCore.plugin.config.getInventoryFolder() + File.separator + player.getName()+".yml";
}
}
protected static void storeInventory(PlayerInventory pinv, File file) {
YamlConfiguration yml = new YamlConfiguration();
new Armor(pinv).store(yml.createSection("armor"));
new Items(pinv).store(yml.createSection("inv"));
try {
yml.save(file);
} catch (IOException e) {
LimitedCreativeCore.plugin.logger.severe(e.getMessage());
}
}
protected static void restoreInventory(PlayerInventory pinv, File file) {
YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
new Armor(pinv).restore(yml.getConfigurationSection("armor"));
new Items(pinv).restore(yml.getConfigurationSection("inv"));
}
public boolean isStored(GameMode gm) {
File f = new File(LimitedCreativeCore.plugin.getDataFolder(), getFileName(player, gm));
return f.exists();
}
}

View file

@ -17,8 +17,6 @@
*/
package de.jaschastarke.minecraft.limitedcreative;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@ -29,7 +27,6 @@ import org.bukkit.Location;
import org.bukkit.Material;
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;
@ -41,168 +38,174 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Lever;
import de.jaschastarke.minecraft.limitedcreative.Commands.LackingPermissionException;
import de.jaschastarke.minecraft.limitedcreative.serialize.Items;
import de.jaschastarke.minecraft.utils.IPermission;
import de.jaschastarke.minecraft.worldguard.events.PlayerChangedAreaEvent;
import static de.jaschastarke.minecraft.utils.Locale.L;
public class LCPlayer {
private static LimitedCreativeCore plugin = LimitedCreativeCore.plugin;
private static Map<String, LCPlayer> players = new HashMap<String, LCPlayer>();
private Player player;
private Map<Integer, ItemStack> tempinv = null;
private static Core plugin = Core.plugin;
//private Player player;
private String name;
private Inventory _inv;
private boolean _isPermanentCreative = false;
private boolean _isRegionCreative = false;
private GameMode _permanent_gamemode = null;
private long _timestamp;
public static final long CLEANUP_TIMEOUT = 300000; // 300s = 5m
private static File _store_file = new File(plugin.getDataFolder(), "players.yml");
public static YamlConfiguration store = YamlConfiguration.loadConfiguration(_store_file);
private LCPlayer(Player player) {
this.player = player;
_isRegionCreative = store.getBoolean(player.getName()+".region_creative", false) && player.getGameMode() == GameMode.CREATIVE;
if (player.getGameMode() == GameMode.CREATIVE && !this.isRegionCreative()) {
LimitedCreativeCore.debug(player.getName() + " was already creative");
setPermanentCreative(true);
public LCPlayer(Player player) {
//this.player = player;
name = player.getName();
touch();
if (!this.isRegionGameMode(player.getGameMode())) {
setPermanentGameMode(player.getGameMode());
}
}
private void updatePlayer(Player player) {
/*private void updatePlayer(Player player) {
this.player = player;
_inv = null;
}*/
public Player getPlayer() {
//return player;
return plugin.getServer().getPlayerExact(name);
}
public String getName() {
return name;
}
public Player getRaw() {
return player;
public Inventory getInv() {
if (_inv == null)
_inv = new Inventory(this);
return _inv;
}
public void touch() {
_timestamp = System.currentTimeMillis();
}
public boolean isOutdated() {
return !getRaw().isOnline() && _timestamp < (System.currentTimeMillis() - CLEANUP_TIMEOUT);
}
public static LCPlayer get(Player player) {
LimitedCreativeCore.debug("player: " + player.getName() + " - " + ((Object)player).hashCode() + " - " + player.getEntityId() + " - " + player.getUniqueId());
if (!players.containsKey(player.getName())) {
LCPlayer p = new LCPlayer(player);
players.put(player.getName(), p);
p.touch();
return p;
} else {
LCPlayer p = players.get(player.getName());
if (player != p.getRaw())
p.updatePlayer(player);
p.touch();
return p;
}
}
public static void cleanUp() {
int count = players.size();
Iterator<Map.Entry<String, LCPlayer>> i = players.entrySet().iterator();
while (i.hasNext()) {
Map.Entry<String, LCPlayer> entry = i.next();
if (entry.getValue().isOutdated()) {
LimitedCreativeCore.debug("removing "+entry.getValue().getRaw().getName());
i.remove();
}
}
LimitedCreativeCore.debug("cleanup done: player count: "+count+" / "+players.size());
}
public boolean isRegionCreative() {
return _isRegionCreative;
return (getPlayer() == null || !getPlayer().isOnline()) &&
_timestamp < (System.currentTimeMillis() - Players.CLEANUP_TIMEOUT);
}
public void changeGameMode(GameMode gm) throws LackingPermissionException {
if (!isRegionCreative() && !hasPermission("limitedcreative.switch_gamemode")) {
if (gm != GameMode.SURVIVAL || !hasPermission("limitedcreative.switch_gamemode.backonly")) {
LimitedCreativeCore.debug(player.getName() + " lacking permission /lc [cs]");
throw new Commands.LackingPermissionException();
}
}
getRaw().setGameMode(gm);
}
public void setRegionCreative(boolean b) {
LimitedCreativeCore.debug(player.getName() + " region creative: " + b);
if (b) {
store.set(player.getName()+".region_creative", true);
} else {
store.set(player.getName(), null);
}
try {
store.save(_store_file);
} catch (IOException e) {
plugin.logger.severe("Failed to save players.yml");
e.printStackTrace();
}
_isRegionCreative = b;
}
public boolean isPermanentCreative() {
return _isPermanentCreative;
}
public void setPermanentCreative(boolean b) {
LimitedCreativeCore.debug(player.getName() + " permanent creative: " + b);
_isPermanentCreative = b;
if (b)
setRegionCreative(false);
private Map<String, Object> options = new HashMap<String, Object>();
public void setRegionGameMode(final GameMode gm) {
options.remove("region");
Core.debug(getName()+": set region game mode: " + gm);
Players.getOptions().setRegionGameMode(getName(), gm);
}
public boolean onSetCreative() {
LimitedCreativeCore.debug(player.getName() + " going into creative");
if (!this.isRegionCreative())
setPermanentCreative(true);
if (plugin.config.getStoreEnabled()) {
if (plugin.config.getPermissionToKeepInventory() && hasPermission("limitedcreative.keepinventory"))
return true;
inv().save();
if (plugin.config.getStoreCreative() && inv().isStored(GameMode.CREATIVE)) {
inv().load(GameMode.CREATIVE);
private GameMode getRegionGameMode() {
if (!options.containsKey("region")) {
options.put("region", Players.getOptions().getRegionGameMode(getName()));
}
Core.debug(getName()+": get region game mode: " + options.get("region"));
return (GameMode) options.get("region");
}
public boolean isRegionGameMode(final GameMode gm) {
return gm.equals(getRegionGameMode());
}
public boolean isRegionGameMode() {
return getRegionGameMode() != null;
}
public boolean isOptionalRegionGameMode() {
return getOptionalRegionGameMode() != null;
}
/*private boolean isOptionalRegionGameMode(final GameMode gm) {
return gm.equals(getOptionalRegionGameMode());
}*/
public boolean isOptionalRegionGameMode(final String region, final GameMode gm) {
return gm.equals(getOptionalRegionGameMode(region));
}
private GameMode getOptionalRegionGameMode() {
String region = plugin.worldguard.getRegionManager().getRegionsHash(getPlayer().getLocation());
return getOptionalRegionGameMode(region);
}
private GameMode getOptionalRegionGameMode(String region) {
if (!options.containsKey("region_opt#"+region)) {
options.put("region_opt#"+region, Players.getOptions().getOptionalRegionGameMode(getName(), region));
}
Core.debug(getName()+": get optional region game mode: "+region+" - " + options.get("region_opt#"+region));
return (GameMode) options.get("region_opt#"+region);
}
public void setOptionalRegionGameMode(GameMode gm) {
String region = plugin.worldguard.getRegionManager().getRegionsHash(getPlayer().getLocation());
setOptionalRegionGameMode(region, gm);
}
public void setOptionalRegionGameMode(String region, GameMode gm) {
options.remove("region_opt#"+region);
Core.debug(getName()+": set optional region game mode: "+region+" - " + gm);
Players.getOptions().setOptionalRegionGameMode(getName(), region, gm);
}
public void setPermanentGameMode(GameMode temp) {
Core.debug(getName()+": set permanent game mode: " + temp);
if (temp != null) {
if (temp.equals(plugin.com.getDefaultGameMode(getPlayer().getWorld()))) {
temp = null;
} else {
inv().clear();
setRegionGameMode(null);
}
}
return true;
_permanent_gamemode = temp;
}
private Inventory inv() {
if (_inv == null)
_inv = new Inventory(player);
return _inv;
public boolean isPermanentGameMode(GameMode temp) {
Core.debug(getName()+": get permanent game mode: " + _permanent_gamemode);
return temp.equals(_permanent_gamemode);
}
public boolean onSetSurvival() {
LimitedCreativeCore.debug(player.getName() + " going into survival");
if (isRegionCreative()) {
if (!plugin.config.getRegionOptional()) {
getRaw().sendMessage(ChatColor.RED + L("exception.region.no_survival"));
LimitedCreativeCore.debug("... denied");
return false;
public boolean onSetGameMode(GameMode gm) {
Core.debug(getName() + " going into " + gm);
if (isRegionGameMode()) { // change to the other gamemode as the area defines
if (!isRegionGameMode(gm)) { // only when we are not switching to the mode the region allows
if (!plugin.config.getRegionOptional()) {
getPlayer().sendMessage(ChatColor.RED + L("exception.region.not_optional", gm.toString().toLowerCase()));
Core.debug("... denied");
return false;
} else {
setOptionalRegionGameMode(gm);
}
} else {
// we are changing to the mode the region defines, thats not permanent
setOptionalRegionGameMode(null);
setPermanentGameMode(null);
}
} else {
setPermanentGameMode(gm); // we are not in a region, so the mode change is permanent
}
setPermanentCreative(false);
/*
* Feature 1: Separated Inventories / Storage
*/
if (plugin.config.getStoreEnabled()) {
if (plugin.config.getPermissionToKeepInventory() && hasPermission("limitedcreative.keepinventory"))
if (plugin.config.getPermissionToKeepInventory() && hasPermission(Perms.KEEPINVENTORY))
return true;
if (plugin.config.getStoreCreative()) {
inv().save();
if (gm != GameMode.CREATIVE || plugin.config.getStoreCreative())
getInv().save();
if (gm == GameMode.CREATIVE) {
if (plugin.config.getStoreCreative() && getInv().isStored(GameMode.CREATIVE)) {
getInv().load(GameMode.CREATIVE);
} else {
getInv().clear();
}
} else if (gm == GameMode.SURVIVAL) {
if (getInv().isStored(GameMode.SURVIVAL))
getInv().load(GameMode.SURVIVAL);
}
if (inv().isStored(GameMode.SURVIVAL))
inv().load(GameMode.SURVIVAL);
}
return true;
}
public void onDropItem(PlayerDropItemEvent event) {
LimitedCreativeCore.debug(player.getName() + " ("+player.getGameMode()+") drops items " + event.getItemDrop().getItemStack().getType());
if (player.getGameMode() == GameMode.CREATIVE) {
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.drop"))
Core.debug(getName() + " ("+getPlayer().getGameMode()+") drops items " + event.getItemDrop().getItemStack().getType());
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.DROP))
return;
LimitedCreativeCore.debug("removed");
Core.debug("removed");
if (plugin.config.getRemoveDrop())
event.getItemDrop().remove();
else
@ -210,8 +213,8 @@ public class LCPlayer {
}
}
public void onPickupItem(PlayerPickupItemEvent event) {
if (player.getGameMode() == GameMode.CREATIVE) {
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.pickup"))
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.PICKUP))
return;
if (plugin.config.getBlockPickupInCreative()) {
event.setCancelled(true);
@ -223,36 +226,35 @@ public class LCPlayer {
}
public void onDie(EntityDeathEvent event) {
if (player.getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.drop")) {
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.NoLimit.DROP)) {
event.getDrops().clear();
tempinv = Items.storeInventory(player.getInventory());
//getInv().storeTemp();
}
}
}
/* removed, because much to insecure. also we can save memory with out this
public void onRespawn(PlayerRespawnEvent event) {
if (player.getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.drop")) {
if (tempinv != null) {
Items.restoreInventory(player.getInventory(), tempinv);
}
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.NoLimit.DROP)) {
getInv().restoreTemp();
}
}
tempinv = null;
}
getInv().clearTemp();
}*/
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) {
if (!plugin.config.getPermissionsEnabled() || !get(attacker).hasPermission("limitedcreative.nolimit.pvp")) {
if (!plugin.config.getPermissionsEnabled() || !Players.get(attacker).hasPermission(Perms.NoLimit.PVP)) {
event.setCancelled(true);
return; // skip next check
}
}
if (player.getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.pvp")) {
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.NoLimit.PVP)) {
event.setCancelled(true);
}
}
@ -260,8 +262,8 @@ public class LCPlayer {
}
public void onDealDamage(EntityDamageByEntityEvent event) { // deals damage
if (event.getEntity() instanceof Creature) {
if (player.getGameMode() == GameMode.CREATIVE && plugin.config.getMobDamageBlock()) {
if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.mob_damage")) {
if (getPlayer().getGameMode() == GameMode.CREATIVE && plugin.config.getMobDamageBlock()) {
if (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.NoLimit.MOB_DAMAGE)) {
event.setCancelled(true);
}
}
@ -273,8 +275,8 @@ public class LCPlayer {
*/
public void onTarget(EntityTargetEvent event) {
if (event.getEntity() instanceof Creature) {
if (player.getGameMode() == GameMode.CREATIVE && plugin.config.getMobDamageBlock()) {
if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.mob_damage")) {
if (((Player) event.getTarget()).getGameMode() == GameMode.CREATIVE && plugin.config.getMobDamageBlock()) {
if (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.NoLimit.MOB_DAMAGE)) {
event.setCancelled(true);
}
}
@ -282,68 +284,83 @@ public class LCPlayer {
}
public void onChestAccess(PlayerInteractEvent event) {
if (player.getGameMode() != GameMode.CREATIVE)
if (event.getPlayer().getGameMode() != GameMode.CREATIVE)
return;
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.chest"))
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.CHEST))
return;
event.getPlayer().sendMessage(L("blocked.chest"));
event.setCancelled(true);
}
public void onChestAccess(PlayerInteractEntityEvent event) { // chest-minecarts are different events
if (player.getGameMode() != GameMode.CREATIVE)
if (getPlayer().getGameMode() != GameMode.CREATIVE)
return;
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.chest"))
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.CHEST))
return;
event.getPlayer().sendMessage(L("blocked.chest"));
event.setCancelled(true);
}
public void onBenchAccess(PlayerInteractEvent event) {
if (!plugin.config.getBenchBlock() || player.getGameMode() != GameMode.CREATIVE)
if (!plugin.config.getBenchBlock() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
return;
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.chest"))
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.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)
if (!plugin.config.getSignBlock() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
return;
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.sign"))
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.SIGN))
return;
event.getPlayer().sendMessage(L("blocked.sign"));
event.setCancelled(true);
}
public void onButtonAccess(PlayerInteractEvent event) {
if (!plugin.config.getButtonBlock() || player.getGameMode() != GameMode.CREATIVE)
if (!plugin.config.getButtonBlock() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
return;
if (event.getClickedBlock().getState() instanceof Lever) {
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.lever"))
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.LEVER))
return;
event.getPlayer().sendMessage(L("blocked.lever"));
event.setCancelled(true);
} else {
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.button"))
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.BUTTON))
return;
event.getPlayer().sendMessage(L("blocked.button"));
event.setCancelled(true);
}
}
private long lastFloatingTimeWarning = 0;
public void setRegionCreativeAllowed(boolean rcreative, PlayerMoveEvent event) {
GameMode DEFAULT_GAMEMODE = plugin.com.isCreative(event.getTo().getWorld()) ? GameMode.CREATIVE : GameMode.SURVIVAL;
GameMode TEMPORARY_GAMEMODE = DEFAULT_GAMEMODE == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL;
/*
* Attention: "Creative" stands for "the other gamemode". So true may mean, "be survival in creative world".
*/
public void setRegionCreativeAllowed(boolean rcreative, PlayerChangedAreaEvent changearea_event) {
Core.debug(getName()+": changed region: "+rcreative+": "+changearea_event.toString());
if (rcreative && player.getGameMode() == DEFAULT_GAMEMODE && !isRegionCreative()) {
setRegionCreative(true); // have to be set, before setGameMode
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"));
lastFloatingTimeWarning = System.currentTimeMillis();
}
PlayerMoveEvent event = changearea_event.getMoveEvent();
GameMode CURRENT_GAMEMODE = event.getPlayer().getGameMode();
GameMode DEFAULT_GAMEMODE = plugin.com.getDefaultGameMode(event.getTo().getWorld());
GameMode TEMPORARY_GAMEMODE = DEFAULT_GAMEMODE == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL; // the opposite
if (rcreative && CURRENT_GAMEMODE != TEMPORARY_GAMEMODE && !this.isRegionGameMode(TEMPORARY_GAMEMODE)) {
Core.debug(getName()+": entering creative area");
// 1. the region allows "the other (temporary) gamemode"
// 2. but the player is not in that mode
// 3. and the player is not aware of that
// result: change him to that mode
setRegionGameMode(TEMPORARY_GAMEMODE); // have to be set, before setGameMode
if (!isOptionalRegionGameMode(changearea_event.getNewRegionHash(), CURRENT_GAMEMODE)) {
event.getPlayer().setGameMode(TEMPORARY_GAMEMODE);
}
} else if (!rcreative && event.getPlayer().getGameMode() == TEMPORARY_GAMEMODE && !isPermanentGameMode(TEMPORARY_GAMEMODE)) {
Core.debug(getName()+": leaving creative area");
// 1. the region doesn't allow "the other gamemode"
// 2. but the player is in that mode
// 3. and the player isn't global (permanent) in that mode
// result: change him back to default mode
if (CURRENT_GAMEMODE == GameMode.CREATIVE && getFloatingHeight() > plugin.config.getMaximumFloatingHeight()) {
// but not if he is too high
this.sendTimeoutMessage(L("blocked.survival_flying"));
Location newloc = event.getTo().clone();
newloc.setX(event.getFrom().getX());
@ -351,16 +368,39 @@ public class LCPlayer {
newloc.setZ(event.getFrom().getZ());
event.setTo(newloc);
} else {
setRegionCreative(false);
player.setGameMode(GameMode.SURVIVAL); // also unsets isRegionCreative;
setRegionGameMode(null);
if (event.getTo().getWorld() == event.getFrom().getWorld()) {
// do not enforce the game mode change, on world teleport, as multiverse may cancel the event afterwards
// the world-change game-mode change is done by multiworld
event.getPlayer().setGameMode(DEFAULT_GAMEMODE);
}
}
} else if (!rcreative && isRegionCreative()) {
setRegionCreative(false); // we have left, while in optional survival
} else if (!rcreative && this.isRegionGameMode(TEMPORARY_GAMEMODE)) {
Core.debug(getName()+": leaving creative area (while already in default gamemode)");
// 1. the region doesn't allow "the other gamemode"
// 2. but he thinks he is still allowed
// 3. (because of else) we are not longer in that mode
// result: advise him to not longer allowed to that region
setRegionGameMode(null);
}
}
private Map<String, Long> timeout_msgs = new HashMap<String, Long>();
public void sendTimeoutMessage(String msg) {
Iterator<Map.Entry<String, Long>> i = timeout_msgs.entrySet().iterator();
while (i.hasNext()) {
Map.Entry<String, Long> entry = i.next();
if (entry.getValue() < (System.currentTimeMillis() - plugin.config.getRepeatingMessageTimeout())) {
i.remove();
}
}
if (!timeout_msgs.containsKey(msg)) {
timeout_msgs.put(msg, System.currentTimeMillis());
getPlayer().sendMessage(msg);
}
}
public int getFloatingHeight() {
Block b = player.getLocation().getBlock();
Block b = getPlayer().getLocation().getBlock();
int steps = 0;
while (b.getType() == Material.AIR) {
steps++;
@ -370,22 +410,28 @@ public class LCPlayer {
}
public void goToFloor() {
Block b = player.getLocation().getBlock();
Block b = getPlayer().getLocation().getBlock();
int steps = 0;
while (b.getType() == Material.AIR) {
steps++;
b = b.getRelative(BlockFace.DOWN);
}
if (steps > 2) {
player.teleport(new Location(player.getWorld(),
player.getLocation().getX(),
getPlayer().teleport(new Location(getPlayer().getWorld(),
getPlayer().getLocation().getX(),
b.getY()+1,
player.getLocation().getZ()));
getPlayer().getLocation().getZ()));
}
}
public boolean hasPermission(String permission) {
return plugin.perm.hasPermission(this.getRaw(), permission);
public boolean hasPermission(IPermission permission) {
return plugin.perm.hasPermission(this.getPlayer(), permission);
}
public boolean isGameModeAllowed(GameMode gm) {
if (plugin.config.getRegionOptional() && isRegionGameMode()) {
return true;
}
return false;
}
}

View file

@ -28,6 +28,10 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
/**
* The "Block" means a Minecraft-Block, not "blocking". So this Class is used to prevent ItemSpawn which are Drops from
* specified Blocks.
*/
public class NoBlockItemSpawn {
public final static long TIME_OFFSET = 250;
@ -71,11 +75,11 @@ public class NoBlockItemSpawn {
}
public void block(Block block, LCPlayer player) {
if (player.getRaw().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
if (player.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
block(block.getLocation(), block.getType());
} else {
// doesn't include silktouch
for (ItemStack i : block.getDrops(player.getRaw().getItemInHand())) {
for (ItemStack i : block.getDrops(player.getPlayer().getItemInHand())) {
block(block.getLocation(), i.getType());
}
}

View file

@ -0,0 +1,66 @@
/*
* 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.limitedcreative;
import de.jaschastarke.minecraft.utils.IPermission;
public enum Perms implements IPermission {
CONFIG("config"),
REGIONS("regions"),
GM("switch_gamemode"),
GM_BACKONLY("switch_gamemode.backonly"),
GM_SURVIVAL("switch_gamemode.survival"),
GM_CREATIVE("switch_gamemode.creative"),
GM_OTHER("switch_gamemode.other"),
KEEPINVENTORY("keepinventory");
private static final String NS = "limitedcreative";
private String perm;
private Perms(String permission) {
perm = permission;
}
@Override
public String toString() {
return NS + SEP + perm;
}
public enum NoLimit implements IPermission {
DROP("drop"),
PICKUP("pickup"),
CHEST("chest"),
SIGN("sign"),
BUTTON("button"),
LEVER("lever"),
PVP("pvp"),
MOB_DAMAGE("mob_damage"),
USE("use"),
BREAK("break");
private static final String NS = "nolimit";
private String perm;
private NoLimit(String permission) {
perm = permission;
}
@Override
public String toString() {
return Perms.NS + SEP + NoLimit.NS + SEP + perm;
}
}
}

View file

@ -0,0 +1,82 @@
/*
* 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.limitedcreative;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Player;
import de.jaschastarke.minecraft.limitedcreative.store.PlayerOptions;
public class Players {
public static final long CLEANUP_TIMEOUT = 300000; // 300s = 5m
private static Map<String, LCPlayer> players = new HashMap<String, LCPlayer>();
private static PlayerOptions options = new PlayerOptions();
public static LCPlayer get(Player player) {
Core.debug("player: " + player.getName() + " - " + ((Object)player).hashCode() + " - " + player.getEntityId() + " - " + player.getUniqueId());
if (!players.containsKey(player.getName())) {
LCPlayer p = new LCPlayer(player);
players.put(player.getName(), p);
return p;
} else {
LCPlayer p = players.get(player.getName());
/*if (player != p.getPlayer())
p.updatePlayer(player);*/
p.touch();
return p;
}
}
public static LCPlayer get(String player) {
if (players.containsKey(player)) {
return players.get(player);
}
return null;
}
public static void remove(String player) {
players.remove(player);
}
/*public static void clear(String player) {
if (players.containsKey(player)) {
LCPlayer p = players.get(player);
p.updatePlayer(null);
p.touch(); // keep meta data alive till cleanup, but remove player bukkit assoc.
}
}*/
/*public static void cleanUp() {
int count = players.size();
Iterator<Map.Entry<String, LCPlayer>> i = players.entrySet().iterator();
while (i.hasNext()) {
Map.Entry<String, LCPlayer> entry = i.next();
if (entry.getValue().isOutdated()) {
Core.debug("removing "+entry.getValue().getName());
i.remove();
}
}
Core.debug("cleanup done: player count: "+count+" / "+players.size());
}*/
public static PlayerOptions getOptions() {
return options;
}
}

View file

@ -42,35 +42,31 @@ import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.material.Button;
import org.bukkit.material.Lever;
import de.jaschastarke.minecraft.limitedcreative.BlackList;
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
import de.jaschastarke.minecraft.limitedcreative.Core;
import de.jaschastarke.minecraft.limitedcreative.Perms;
import de.jaschastarke.minecraft.limitedcreative.Players;
import static de.jaschastarke.minecraft.utils.Locale.L;
public class LimitListener implements Listener {
private LimitedCreativeCore plugin;
public LimitListener(LimitedCreativeCore plugin) {
private Core plugin;
public LimitListener(Core plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event) {
LCPlayer.get(event.getPlayer()).onRespawn(event);
}
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
LCPlayer.get(event.getPlayer()).onDropItem(event);
Players.get(event.getPlayer()).onDropItem(event);
}
@EventHandler
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
LCPlayer.get(event.getPlayer()).onPickupItem(event);
Players.get(event.getPlayer()).onPickupItem(event);
}
@EventHandler(priority=EventPriority.LOWEST)
@ -78,8 +74,8 @@ public class LimitListener implements Listener {
if (MainListener.isCancelled(event) || event.getPlayer().getGameMode() != GameMode.CREATIVE)
return;
LCPlayer player = LCPlayer.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) {
LCPlayer player = Players.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.USE)) {
if (event.getItem() != null && BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getItem())) {
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
@ -109,8 +105,8 @@ public class LimitListener implements Listener {
if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
return;
LCPlayer player = LCPlayer.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) {
LCPlayer player = Players.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.USE)) {
if (event.getPlayer().getItemInHand() != null && BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getPlayer().getItemInHand())) {
event.setCancelled(true);
event.getPlayer().sendMessage(L("blocked.use"));
@ -126,22 +122,28 @@ public class LimitListener implements Listener {
}
@EventHandler
public void onEntityDamage(EntityDamageEvent meta_event) {
if (meta_event.isCancelled())
public void onEntityDamage(EntityDamageEvent event) {
if (event instanceof EntityDamageByEntityEvent)
onEntityDamageByEntity((EntityDamageByEntityEvent) event);
}
/*
* Registering to that event works, but causes a SEVERE:
* Plugin attempted to register delegated event class class org.bukkit.event.entity.EntityDamageByEntityEvent.
* It should be using class org.bukkit.event.entity.EntityDamageEvent!
*/
protected void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.isCancelled())
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(source, event);
}
if (!event.isCancelled() && source instanceof Player) {
LCPlayer.get((Player) source).onDealDamage(event);
}
Entity source = event.getDamager();
if (source instanceof Projectile)
source = ((Projectile) source).getShooter();
if (event.getEntity() instanceof Player) {
Players.get((Player) event.getEntity()).onDamage(source, event);
}
if (!event.isCancelled() && source instanceof Player) {
Players.get((Player) source).onDealDamage(event);
}
}
@EventHandler
@ -149,7 +151,7 @@ public class LimitListener implements Listener {
if (event.isCancelled())
return;
if (event.getTarget() instanceof Player) {
LCPlayer.get((Player) event.getTarget()).onTarget(event);
Players.get((Player) event.getTarget()).onTarget(event);
}
}
@ -157,24 +159,28 @@ public class LimitListener implements Listener {
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
LCPlayer.get(player).onDie(event);
Players.get(player).onDie(event);
}
}
/*@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event) {
Players.get(event.getPlayer()).onRespawn(event);
}*/
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled())
return;
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
LCPlayer player = LCPlayer.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.break")) {
LCPlayer player = Players.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.BREAK)) {
if (BlackList.isBlackListed(plugin.config.getBlockedBreaks(), event.getBlock())) {
event.setCancelled(true);
event.getPlayer().sendMessage(L("blocked.break"));
}
}
if (plugin.config.getPermissionsEnabled() && player.hasPermission("limitedcreative.nolimit.drop"))
if (plugin.config.getPermissionsEnabled() && player.hasPermission(Perms.NoLimit.DROP))
return;
// Prevent dropping of doors and beds when destroying the wrong part
Block block = event.getBlock();
@ -205,8 +211,8 @@ public class LimitListener implements Listener {
if (event.isCancelled())
return;
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
LCPlayer player = LCPlayer.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) {
LCPlayer player = Players.get(event.getPlayer());
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.USE)) {
if (BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getBlock())) {
event.setCancelled(true);
event.getPlayer().sendMessage(L("blocked.place"));

View file

@ -17,7 +17,6 @@
*/
package de.jaschastarke.minecraft.limitedcreative.listeners;
import org.bukkit.GameMode;
import org.bukkit.entity.Item;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
@ -25,13 +24,14 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
import de.jaschastarke.minecraft.limitedcreative.Core;
import de.jaschastarke.minecraft.limitedcreative.Players;
public class MainListener implements Listener {
private LimitedCreativeCore plugin;
public MainListener(LimitedCreativeCore plugin) {
private Core plugin;
public MainListener(Core plugin) {
this.plugin = plugin;
}
@ -47,20 +47,18 @@ public class MainListener implements Listener {
@EventHandler
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
LimitedCreativeCore.debug("onPlayerGameModeChange: "+event.getPlayer().getName());
LimitedCreativeCore.debug("Current GameMode: "+event.getPlayer().getGameMode());
LimitedCreativeCore.debug("New GameMode: "+event.getNewGameMode());
LimitedCreativeCore.debug("isLoggedin: "+plugin.com.isLoggedIn(event.getPlayer()));
LimitedCreativeCore.debug("isCancelled: "+event.isCancelled());
if (Core.isDebug()) {
Core.debug("onPlayerGameModeChange: "+event.getPlayer().getName());
Core.debug("Current GameMode: "+event.getPlayer().getGameMode());
Core.debug("New GameMode: "+event.getNewGameMode());
Core.debug("isLoggedin: "+plugin.com.isLoggedIn(event.getPlayer()));
Core.debug("isCancelled: "+event.isCancelled());
}
if (!plugin.com.isLoggedIn(event.getPlayer()))
return;
if (event.getNewGameMode() == GameMode.CREATIVE) {
if (!LCPlayer.get(event.getPlayer()).onSetCreative())
event.setCancelled(true);
} else if (event.getNewGameMode() == GameMode.SURVIVAL) {
if (!LCPlayer.get(event.getPlayer()).onSetSurvival())
event.setCancelled(true);
}
if (!Players.get(event.getPlayer()).onSetGameMode(event.getNewGameMode()))
event.setCancelled(true);
}
/**
@ -77,27 +75,8 @@ public class MainListener implements Listener {
}
}
/*
public static class VehicleListen extends VehicleListener {
@EventHandler
public void onVehicleDestroy(VehicleDestroyEvent event) {
if (event.isCancelled())
return;
if (event.getAttacker() instanceof Player) {
Player player = (Player) event.getAttacker();
if (player.getGameMode() == GameMode.CREATIVE) {
if (plugin.config.getPermissionsEnabled() && player.hasPermission("limitedcreative.nolimit.drop"))
return;
plugin.logger.info("Vehicle destroy: "+event.getVehicle() + " - "+event.getVehicle().getEntityId());
}
}
}
private void register() {
if (plugin.config.getLimitEnabled()) {
pm.registerEvent(Event.Type.VEHICLE_DESTROY, this, Priority.Normal, plugin);
}
}
}*/
public void onLogout(PlayerQuitEvent event) {
// what? i can't cancel a logout event? but how to chain the user to the server than? xD
Players.remove(event.getPlayer().getName());
}
}

View file

@ -16,14 +16,15 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
import de.jaschastarke.minecraft.limitedcreative.Core;
import de.jaschastarke.minecraft.limitedcreative.Players;
import de.jaschastarke.minecraft.utils.Util;
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
import de.jaschastarke.minecraft.worldguard.CRegionManager;
import de.jaschastarke.minecraft.worldguard.events.PlayerChangedAreaEvent;
public class RegionListener implements Listener {
private static LimitedCreativeCore plugin = WorldGuardIntegration.plugin;
private static Core plugin = WorldGuardIntegration.plugin;
private CRegionManager rm;
public RegionListener(WorldGuardIntegration wgi) {
rm = wgi.getRegionManager();
@ -39,14 +40,29 @@ public class RegionListener implements Listener {
public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled())
return;
LCPlayer player = LCPlayer.get(event.getPlayer());
ApplicableRegions set = rm.getRegionSet(event.getBlock());
if (player.isRegionCreative() && !set.allows(Flags.CREATIVE, player)) {
event.getPlayer().sendMessage(L("blocked.outside_creative_break"));
event.setCancelled(true);
} else if (player.getRaw().getGameMode() != GameMode.CREATIVE && set.allows(Flags.CREATIVE)) {
plugin.spawnblock.block(event.getBlock(), player);
LCPlayer player = Players.get(event.getPlayer());
boolean diffrent_region = rm.isDiffrentRegion(event.getPlayer(), event.getBlock().getLocation());
boolean creative_world = plugin.com.isCreative(event.getBlock().getWorld());
if (player.isRegionGameMode() && diffrent_region) {
// do not break outside of "gamemod-change-region" when in the region
if (!rm.getRegionSet(event.getBlock()).allows(Flags.CREATIVE, event.getPlayer())) {
event.getPlayer().sendMessage(L("blocked.outside_creative_break"));
event.setCancelled(true);
}
} else if (diffrent_region) {
// do not break inside of "survial-region in creative world" when outside
if (rm.getRegionSet(event.getBlock()).allows(Flags.CREATIVE)) {
event.getPlayer().sendMessage(L("blocked.inside_survival_break"));
event.setCancelled(true);
}
}
if (!creative_world) { // in survival world
// prevent any drops for survival players in creative regions in survival worlds
if (event.getPlayer().getGameMode() != GameMode.CREATIVE && rm.getRegionSet(event.getBlock()).allows(Flags.CREATIVE)) {
plugin.spawnblock.block(event.getBlock(), player);
}
}
}
@ -54,20 +70,28 @@ public class RegionListener implements Listener {
public void onBlockPlace(BlockPlaceEvent event) {
if (event.isCancelled())
return;
LCPlayer player = LCPlayer.get(event.getPlayer());
if (player.isRegionCreative() && rm.isDiffrentRegion(event.getPlayer(), event.getBlock().getLocation())) {
// do not build outside of creative regions, when in the region
ApplicableRegions set = rm.getRegionSet(event.getBlock());
if (!set.allows(Flags.CREATIVE, player)) {
LCPlayer player = Players.get(event.getPlayer());
boolean diffrent_region = rm.isDiffrentRegion(event.getPlayer(), event.getBlock().getLocation());
if (player.isRegionGameMode() && diffrent_region) {
// do not build outside of "gamemod-change-region" when in the region
if (!rm.getRegionSet(event.getBlock()).allows(Flags.CREATIVE, event.getPlayer())) {
event.getPlayer().sendMessage(L("blocked.outside_creative"));
event.setCancelled(true);
}
} else if (diffrent_region) {
// do not build inside of "survial-region in creative world" when outside
if (rm.getRegionSet(event.getBlock()).allows(Flags.CREATIVE)) {
event.getPlayer().sendMessage(L("blocked.inside_survival"));
event.setCancelled(true);
}
}
}
@EventHandler
public void onPlayerChangedArea(PlayerChangedAreaEvent event) {
LCPlayer.get(event.getPlayer()).setRegionCreativeAllowed(event.getNewRegionSet().allows(Flags.CREATIVE), event.getMoveEvent());
Players.get(event.getPlayer()).setRegionCreativeAllowed(event.getNewRegionSet().allows(Flags.CREATIVE, event.getPlayer()), event);
}
@EventHandler
@ -76,12 +100,12 @@ public class RegionListener implements Listener {
return;
Block source = event.getBlock().getRelative(event.getDirection());
LimitedCreativeCore.debug("PistonExtend "+source.getType()+" "+event.getDirection());
Core.debug("PistonExtend "+source.getType()+" "+event.getDirection());
if (source.getType() != Material.AIR) {
if (regionSet(source).allows(Flags.CREATIVE)) {
for (int i = 1; i <= 12; i++) {
Block dest = source.getRelative(event.getDirection(), i);
LimitedCreativeCore.debug("dest "+i+": "+dest.getType());
Core.debug("dest "+i+": "+dest.getType());
if (!regionSet(dest).allows(Flags.CREATIVE)) {
plugin.logger.warning(L("blocked.piston", source.getRelative(event.getDirection(), i - 1).getType().toString(), Util.toString(source.getLocation())));
event.setCancelled(true);
@ -100,9 +124,9 @@ public class RegionListener implements Listener {
return;
Block source = event.getBlock().getRelative(event.getDirection(), 2);
Block dest = source.getRelative(event.getDirection().getOppositeFace());
LimitedCreativeCore.debug("PistonRetract "+source.getType()+" "+event.getDirection() + " " + event.isSticky());
Core.debug("PistonRetract "+source.getType()+" "+event.getDirection() + " " + event.isSticky());
if (event.isSticky() && source.getType() != Material.AIR) {
LimitedCreativeCore.debug("dest "+dest.getType());
Core.debug("dest "+dest.getType());
if (regionSet(source).allows(Flags.CREATIVE)) {
if (!regionSet(dest).allows(Flags.CREATIVE)) {
plugin.logger.warning(L("blocked.piston", source.getType().toString(), Util.toString(source.getLocation())));

View file

@ -22,16 +22,16 @@ import java.util.List;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flag;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
import de.jaschastarke.minecraft.limitedcreative.Core;
import de.jaschastarke.minecraft.worldguard.CRegionManager;
import de.jaschastarke.minecraft.worldguard.Integration;
import de.jaschastarke.minecraft.worldguard.Interface;
public class WorldGuardIntegration implements Integration {
public static LimitedCreativeCore plugin;
public static Core plugin;
public static WorldGuardPlugin wg;
public WorldGuardIntegration(LimitedCreativeCore plugin) {
public WorldGuardIntegration(Core plugin) {
WorldGuardIntegration.plugin = plugin;
wg = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard");

View file

@ -1,64 +0,0 @@
/*
* 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.limitedcreative.serialize;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.PlayerInventory;
public class Armor implements Storeable {
private PlayerInventory inv;
public Armor(PlayerInventory pi) {
inv = pi;
}
@Override
public void store(ConfigurationSection section) {
if (inv.getHelmet() != null && inv.getHelmet().getTypeId() != 0)
Items.sectionSetItem(section, "helmet", inv.getHelmet());
if (inv.getChestplate() != null && inv.getChestplate().getTypeId() != 0)
Items.sectionSetItem(section, "chestplate", inv.getChestplate());
if (inv.getLeggings() != null && inv.getLeggings().getTypeId() != 0)
Items.sectionSetItem(section, "leggins", inv.getLeggings());
if (inv.getBoots() != null && inv.getBoots().getTypeId() != 0)
Items.sectionSetItem(section, "boots", inv.getBoots());
}
@Override
public void restore(ConfigurationSection section) {
if (section.contains("helmet"))
inv.setHelmet(Items.sectionGetItem(section, "helmet"));
else
inv.setHelmet(null);
if (section.contains("chestplate"))
inv.setChestplate(Items.sectionGetItem(section, "chestplate"));
else
inv.setChestplate(null);
if (section.contains("leggins"))
inv.setLeggings(Items.sectionGetItem(section, "leggins"));
else
inv.setLeggings(null);
if (section.contains("boots"))
inv.setBoots(Items.sectionGetItem(section, "boots"));
else
inv.setBoots(null);
}
}

View file

@ -1,114 +0,0 @@
/*
* 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.limitedcreative.serialize;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
public class Items implements Storeable {
private PlayerInventory inv;
public Items(PlayerInventory pi) {
inv = pi;
}
@Override
public void store(ConfigurationSection section) {
for (int i = 0; i < inv.getSize(); i++) {
if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0)
sectionSetItem(section, String.valueOf(i), inv.getItem(i));
}
}
@Override
public void restore(ConfigurationSection section) {
inv.clear();
for (int i = 0; i < inv.getSize(); i++) {
if (section.contains(String.valueOf(i)))
inv.setItem(i, sectionGetItem(section, String.valueOf(i)));
}
}
public static void sectionSetItem(ConfigurationSection section, String path, ItemStack item) {
if (!LimitedCreativeCore.plugin.config.getUnsafeStorage()) {
section.set(path, item);
} else { // unsafe enchants fallback
Map<String, Object> serialize = item.serialize();
if (serialize.containsKey("type") && serialize.get("type") instanceof Material)
serialize.put("type", serialize.get("type").toString());
section.createSection(path, serialize);
};
}
public static ItemStack sectionGetItem(ConfigurationSection section, String path) {
if (section.isItemStack(path)) {
return section.getItemStack(path);
} else {
ConfigurationSection s = section.getConfigurationSection(path);
Map<String, Object> serialize = s.getValues(false);
serialize.remove("enchantments");
ItemStack result = ItemStack.deserialize(serialize);
Map<String, Object> item = section.getConfigurationSection(path).getValues(false);
item.remove("enchantments");
if (s.contains("enchantments")) {
for (Map.Entry<String, Object> entry : s.getConfigurationSection("enchantments").getValues(false).entrySet()) {
Enchantment enchantment = Enchantment.getByName(entry.getKey().toString());
if ((enchantment != null) && (entry.getValue() instanceof Integer)) {
result.addUnsafeEnchantment(enchantment, (Integer) entry.getValue());
}
}
}
return result;
}
}
public static Map<Integer, ItemStack> storeInventory(PlayerInventory inv) {
Map<Integer, ItemStack> map = new HashMap<Integer, ItemStack>();
for (int i = 0; i < inv.getSize(); i++) {
if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0) {
map.put(i, inv.getItem(i));
}
}
for (int i = 0; i < inv.getArmorContents().length; i++) {
map.put((i * -1) - 1, inv.getArmorContents()[i]);
}
return map;
}
public static void restoreInventory(PlayerInventory inv, Map<Integer, ItemStack> map) {
for (int i = 0; i < inv.getSize(); i++) {
if (map.containsKey(i)) {
inv.setItem(i, map.get(i));
} else {
inv.setItem(i, null);
}
}
for (int i = 0; i < inv.getArmorContents().length; i++) {
int _i = (i * -1) - 1;
if (map.containsKey(_i)) {
inv.getArmorContents()[i] = map.get(_i);
} else {
inv.getArmorContents()[i] = null;
}
}
}
}

View file

@ -0,0 +1,170 @@
/*
* 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.limitedcreative.store;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import de.jaschastarke.minecraft.limitedcreative.Core;
public class Fallback {
public static void loadVersion1(PlayerInventory inv, ConfigurationSection sect) {
new Armor(inv).restore(sect.getConfigurationSection("armor"));
new Items(inv).restore(sect.getConfigurationSection("inv"));
}
public static interface Storeable {
public void store(ConfigurationSection section);
public void restore(ConfigurationSection section);
}
public static class Items implements Storeable {
private PlayerInventory inv;
public Items(PlayerInventory pi) {
inv = pi;
}
@Override
public void store(ConfigurationSection section) {
for (int i = 0; i < inv.getSize(); i++) {
if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0)
sectionSetItem(section, String.valueOf(i), inv.getItem(i));
}
}
@Override
public void restore(ConfigurationSection section) {
inv.clear();
for (int i = 0; i < inv.getSize(); i++) {
if (section.contains(String.valueOf(i)))
inv.setItem(i, sectionGetItem(section, String.valueOf(i)));
}
}
public static void sectionSetItem(ConfigurationSection section, String path, ItemStack item) {
if (!Core.plugin.config.getUnsafeStorage()) {
section.set(path, item);
} else { // unsafe enchants fallback
Map<String, Object> serialize = item.serialize();
if (serialize.containsKey("type") && serialize.get("type") instanceof Material)
serialize.put("type", serialize.get("type").toString());
section.createSection(path, serialize);
};
}
public static ItemStack sectionGetItem(ConfigurationSection section, String path) {
if (section.isItemStack(path)) {
return section.getItemStack(path);
} else {
ConfigurationSection s = section.getConfigurationSection(path);
Map<String, Object> serialize = s.getValues(false);
serialize.remove("enchantments");
ItemStack result = ItemStack.deserialize(serialize);
Map<String, Object> item = section.getConfigurationSection(path).getValues(false);
item.remove("enchantments");
if (s.contains("enchantments")) {
for (Map.Entry<String, Object> entry : s.getConfigurationSection("enchantments").getValues(false).entrySet()) {
Enchantment enchantment = Enchantment.getByName(entry.getKey().toString());
if ((enchantment != null) && (entry.getValue() instanceof Integer)) {
result.addUnsafeEnchantment(enchantment, (Integer) entry.getValue());
}
}
}
return result;
}
}
public static Map<Integer, ItemStack> storeInventory(PlayerInventory inv) {
Map<Integer, ItemStack> map = new HashMap<Integer, ItemStack>();
for (int i = 0; i < inv.getSize(); i++) {
if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0) {
map.put(i, inv.getItem(i));
}
}
for (int i = 0; i < inv.getArmorContents().length; i++) {
map.put((i * -1) - 1, inv.getArmorContents()[i]);
}
return map;
}
public static void restoreInventory(PlayerInventory inv, Map<Integer, ItemStack> map) {
for (int i = 0; i < inv.getSize(); i++) {
if (map.containsKey(i)) {
inv.setItem(i, map.get(i));
} else {
inv.setItem(i, null);
}
}
for (int i = 0; i < inv.getArmorContents().length; i++) {
int _i = (i * -1) - 1;
if (map.containsKey(_i)) {
inv.getArmorContents()[i] = map.get(_i);
} else {
inv.getArmorContents()[i] = null;
}
}
}
}
public static class Armor implements Storeable {
private PlayerInventory inv;
public Armor(PlayerInventory pi) {
inv = pi;
}
@Override
public void store(ConfigurationSection section) {
if (inv.getHelmet() != null && inv.getHelmet().getTypeId() != 0)
Items.sectionSetItem(section, "helmet", inv.getHelmet());
if (inv.getChestplate() != null && inv.getChestplate().getTypeId() != 0)
Items.sectionSetItem(section, "chestplate", inv.getChestplate());
if (inv.getLeggings() != null && inv.getLeggings().getTypeId() != 0)
Items.sectionSetItem(section, "leggins", inv.getLeggings());
if (inv.getBoots() != null && inv.getBoots().getTypeId() != 0)
Items.sectionSetItem(section, "boots", inv.getBoots());
}
@Override
public void restore(ConfigurationSection section) {
if (section.contains("helmet"))
inv.setHelmet(Items.sectionGetItem(section, "helmet"));
else
inv.setHelmet(null);
if (section.contains("chestplate"))
inv.setChestplate(Items.sectionGetItem(section, "chestplate"));
else
inv.setChestplate(null);
if (section.contains("leggins"))
inv.setLeggings(Items.sectionGetItem(section, "leggins"));
else
inv.setLeggings(null);
if (section.contains("boots"))
inv.setBoots(Items.sectionGetItem(section, "boots"));
else
inv.setBoots(null);
}
}
}

View file

@ -0,0 +1,111 @@
/*
* 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.limitedcreative.store;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import de.jaschastarke.minecraft.limitedcreative.Core;
import de.jaschastarke.minecraft.limitedcreative.Inventory;
abstract public class InvConfStorage extends PlayerInventoryStorage {
private static final int ARMOR_SIZE = 4;
public void store(Inventory pinv, ConfigurationSection sect) {
PlayerInventory inv = pinv.getPlayer().getInventory();
sect.set("version", 2);
if (Core.plugin.config.getUnsafeStorage())
sect.set("unsafe", true);
storeItems(sect.createSection("armor"), inv.getArmorContents());
storeItems(sect.createSection("inv"), inv.getContents());
}
public void load(Inventory pinv, ConfigurationSection sect) {
PlayerInventory inv = pinv.getPlayer().getInventory();
if (!sect.contains("version")) {
Fallback.loadVersion1(inv, sect);
} else {
inv.setArmorContents(restoreItems(sect.getConfigurationSection("armor"), ARMOR_SIZE));
inv.setContents(restoreItems(sect.getConfigurationSection("inv"), inv.getSize()));
}
}
protected void storeItems(ConfigurationSection sect, ItemStack[] items) {
for (int i = 0; i < items.length; i++) {
ItemStack is = items[i];
if (is != null && is.getType() != Material.AIR) {
sect.set(String.valueOf(i), serialize(is));
}
}
}
protected ItemStack[] restoreItems(ConfigurationSection sect, int size) {
ItemStack[] items = new ItemStack[size];
if (sect != null) {
for (int i = 0; i < size; i++) {
if (sect.contains(String.valueOf(i))) {
if (sect.isItemStack(String.valueOf(i))) {
items[i] = sect.getItemStack(String.valueOf(i));
} else {
items[i] = deserializeItemStack(sect.get(String.valueOf(i)));
}
} else {
items[i] = null;
}
}
}
return items;
}
protected Object serialize(ItemStack is) {
if (Core.plugin.config.getUnsafeStorage())
return is.serialize();
return is;
}
@SuppressWarnings("unchecked")
protected ItemStack deserializeItemStack(Object is) {
if (is instanceof ConfigurationSection) {
ConfigurationSection sect = (ConfigurationSection) is;
Material type = Material.getMaterial(sect.getString("type"));
short damage = new Integer(sect.getInt("damage", 0)).shortValue();
int amount = sect.getInt("amaount", 1);
ItemStack result = new ItemStack(type, amount, damage);
if (sect.contains("enchantments")) {
for (Map.Entry<String, Object> entry : sect.getConfigurationSection("enchantments").getValues(false).entrySet()) {
Enchantment enchantment = Enchantment.getByName(entry.getKey().toString());
if ((enchantment != null) && (entry.getValue() instanceof Integer)) {
result.addUnsafeEnchantment(enchantment, (Integer) entry.getValue());
}
}
}
return result;
} else if (is instanceof Map) {
return ItemStack.deserialize((Map<String, Object>) is);
} else {
Core.plugin.warn("Failed to restore Item: "+is.toString());
return null;
}
}
}

View file

@ -0,0 +1,47 @@
/*
* 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.limitedcreative.store;
import org.bukkit.configuration.MemoryConfiguration;
import de.jaschastarke.minecraft.limitedcreative.Inventory;
import de.jaschastarke.minecraft.limitedcreative.Inventory.Target;
public class InvMemStorage extends InvConfStorage {
private MemoryConfiguration storage = new MemoryConfiguration();
@Override
public void store(Inventory pinv, Target target) {
store(pinv, storage.createSection(pinv.getPlayer().getName()));
}
@Override
public void load(Inventory pinv, Target target) {
load(pinv, storage.getConfigurationSection(pinv.getPlayer().getName()));
}
@Override
public void remove(Inventory pinv, Target target) {
storage.set(pinv.getPlayer().getName(), null);
}
@Override
public boolean contains(Inventory pinv, Target target) {
return storage.contains(pinv.getPlayer().getName());
}
}

View file

@ -0,0 +1,72 @@
/*
* 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.limitedcreative.store;
import java.io.File;
import java.io.IOException;
import org.bukkit.configuration.file.YamlConfiguration;
import de.jaschastarke.minecraft.limitedcreative.Core;
import de.jaschastarke.minecraft.limitedcreative.Inventory;
import de.jaschastarke.minecraft.limitedcreative.Inventory.Target;
public class InvYamlStorage extends InvConfStorage {
private static final String SUFFIX = ".yml";
private File dir;
public InvYamlStorage(File file) {
dir = file;
}
@Override
public void load(Inventory pinv, Target target) {
load(pinv, YamlConfiguration.loadConfiguration(getFile(pinv, target)));
}
@Override
public void store(Inventory pinv, Target target) {
YamlConfiguration yml = new YamlConfiguration();
yml.options().header("DO NOT MODIFY THIS FILE");
store(pinv, yml);
try {
yml.save(getFile(pinv, target));
} catch (IOException e) {
Core.plugin.warn("Failed to save Inventory for Player " + pinv.getPlayer().getName());
e.printStackTrace();
}
}
@Override
public void remove(Inventory pinv, Target target) {
getFile(pinv, target).delete();
}
@Override
public boolean contains(Inventory pinv, Target target) {
return getFile(pinv, target).exists();
}
protected File getFile(Inventory pinv, Target target) {
if (target != default_target) {
return new File(dir, pinv.getPlayer().getName() + "_" + target.toString().toLowerCase() + SUFFIX);
} else {
return new File(dir, pinv.getPlayer().getName() + SUFFIX);
}
}
}

View file

@ -0,0 +1,41 @@
/*
* 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.limitedcreative.store;
import de.jaschastarke.minecraft.limitedcreative.Inventory;
import de.jaschastarke.minecraft.limitedcreative.Inventory.Target;
public abstract class PlayerInventoryStorage {
protected Target default_target = Target.SURVIVAL;
final public void store(Inventory pinv) {
store(pinv, default_target);
}
final public void load(Inventory pinv) {
load(pinv, default_target);
}
final public void remove(Inventory pinv) {
remove(pinv, default_target);
}
final public boolean contains(Inventory pinv) {
return contains(pinv, default_target);
}
abstract public void store(Inventory pinv, Target target);
abstract public void load(Inventory pinv, Target target);
abstract public void remove(Inventory pinv, Target target);
abstract public boolean contains(Inventory pinv, Target target);
}

View file

@ -0,0 +1,79 @@
/*
* 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.limitedcreative.store;
import java.io.File;
import java.io.IOException;
import org.bukkit.GameMode;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import de.jaschastarke.minecraft.limitedcreative.Core;
public class PlayerOptions {
private File _store_file = new File(Core.plugin.getDataFolder(), "players.yml");
private YamlConfiguration store = YamlConfiguration.loadConfiguration(_store_file);
{
store.options().header("DO NOT MODIFY THIS FILE");
}
public void setRegionGameMode(String player, GameMode gm) {
if (gm == null)
store.set(player + ".region_gamemode", null);
else
store.set(player + ".region_gamemode", gm.name());
save();
}
public GameMode getRegionGameMode(String player) {
if (store.contains(player + ".region_gamemode")) {
return GameMode.valueOf(store.getString(player + ".region_gamemode"));
} else if (store.contains(player + ".region_creative")) { // compatibility fallback
return store.getBoolean(player + ".region_creative") ? GameMode.CREATIVE : null;
}
return null;
}
public GameMode getOptionalRegionGameMode(String player, String region) {
if (store.contains(player+".region")) {
ConfigurationSection sect = store.getConfigurationSection(player+".region");
if (sect.contains(region)) {
return GameMode.valueOf(sect.getString(region));
}
}
return null;
}
public void setOptionalRegionGameMode(String player, String region, GameMode gm) {
ConfigurationSection sect = store.contains(player+".region") ? store.getConfigurationSection(player+".region") : store.createSection(player+".region");
String mode = gm == null ? null : gm.name();
sect.set(region, mode);
if (sect.getKeys(true).size() == 0)
store.set(sect.getCurrentPath(), null);
save();
}
protected void save() {
try {
store.save(_store_file);
} catch (IOException e) {
Core.plugin.logger.severe("Failed to save players.yml");
e.printStackTrace();
}
}
}

View file

@ -15,11 +15,9 @@
* 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.limitedcreative.serialize;
package de.jaschastarke.minecraft.utils;
import org.bukkit.configuration.ConfigurationSection;
public interface IPermission {
public static final String SEP = ".";
public interface Storeable {
public void store(ConfigurationSection section);
public void restore(ConfigurationSection section);
}

View file

@ -24,7 +24,7 @@ import java.util.List;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
import de.jaschastarke.minecraft.limitedcreative.Core;
public class Locale {
protected YamlConfiguration lang;
@ -46,7 +46,7 @@ public class Locale {
String fn = getFilename(lang);
LimitedCreativeCore.debug("Using Locale: " + lang);
Core.debug("Using Locale: " + lang);
File localefile = new File(plugin.getDataFolder(), fn);
if (localefile.exists())
this.lang = YamlConfiguration.loadConfiguration(localefile);

View file

@ -1,10 +1,27 @@
/*
* 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.utils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
import de.jaschastarke.minecraft.limitedcreative.Core;
import de.jaschastarke.minecraft.worldedit.PermissionsBridge;
public class Permissions {
@ -31,6 +48,10 @@ public class Permissions {
debug(player, permission, ret);
return ret;
}
public boolean hasPermission(CommandSender player, IPermission permission) {
return hasPermission(player, permission.toString());
}
public boolean hasPermission(CommandSender sender, String permission) {
if (sender instanceof Player) {
@ -42,7 +63,7 @@ public class Permissions {
}
private void debug(CommandSender player, String permission, boolean result) {
if (plugin instanceof LimitedCreativeCore && ((LimitedCreativeCore) plugin).config.getDebug())
LimitedCreativeCore.debug("hasPermission: " + player.getName() + " - " + permission + " - " + result);
if (plugin instanceof Core && ((Core) plugin).config.getDebug())
Core.debug("hasPermission: " + player.getName() + " - " + permission + " - " + result);
}
}

View file

@ -1,3 +1,20 @@
/*
* 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.worldedit;
import org.bukkit.OfflinePlayer;

View file

@ -23,6 +23,7 @@ import org.bukkit.plugin.java.JavaPlugin;
* This Namespace may be used as a Standalone-Plugin just providing the WorldGuard-API
* TODO: Not done yet
*/
@Deprecated // NOT READY YET
public class API extends JavaPlugin {
@Override
public void onDisable() {

View file

@ -17,12 +17,13 @@
*/
package de.jaschastarke.minecraft.worldguard;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration;
public class ApplicableRegions {
@ -42,9 +43,9 @@ public class ApplicableRegions {
return r;
}
public boolean allows(StateFlag flag, LCPlayer player) {
public boolean allows(StateFlag flag, Player player) {
extendRegionFlags();
boolean r = regions.allows(flag, WorldGuardIntegration.wg.wrapPlayer(player.getRaw()));
boolean r = regions.allows(flag, WorldGuardIntegration.wg.wrapPlayer(player));
contractRegionFlags();
return r;
}
@ -58,6 +59,13 @@ public class ApplicableRegions {
pr.setFlag(flag, value);
}
}
if (mgr.getGlobalRegion() != null) {
for (FlagValue data : mgr.region(mgr.getGlobalRegion()).getFlags()) {
T flag = (T) data.getFlag();
V value = (V) data.getValue();
mgr.getGlobalRegion().setFlag(flag, value);
}
}
}
@SuppressWarnings("unchecked")
private <T extends Flag<V>, V> void contractRegionFlags() {
@ -67,6 +75,12 @@ public class ApplicableRegions {
pr.setFlag(flag, null);
}
}
if (mgr.getGlobalRegion() != null) {
for (FlagValue data : mgr.region(mgr.getGlobalRegion()).getFlags()) {
T flag = (T) data.getFlag();
mgr.getGlobalRegion().setFlag(flag, null);
}
}
}
}

View file

@ -27,6 +27,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
@ -104,18 +106,36 @@ public class CCommand implements CommandExecutor {
CRegion reg = rm.world(world).region(region);
switch (act) {
case INFO:
onInfo(sender, player, reg);
return true;
case FLAG:
onFlag(sender, player, reg, args);
return true;
try {
switch (act) {
case INFO:
onInfo(sender, player, reg);
return true;
case FLAG:
onFlag(sender, player, reg, args);
return true;
}
} catch (CommandException ex) { // worldedit command exception!
sender.sendMessage(ChatColor.DARK_RED + ex.getMessage());
return true;
}
return false;
}
private void onInfo(CommandSender sender, Player player, CRegion region) {
private void onInfo(CommandSender sender, Player player, CRegion region) throws CommandPermissionsException {
/* not optimal yet
if (player != null) {
if (region.getProtectedRegion().isOwner(wg.wrapPlayer(player))) {
hasPermission(sender, Perms.INFO_OWN);
} else if (region.getProtectedRegion().isMember(wg.wrapPlayer(player))) {
hasPermission(sender, Perms.INFO_MEMBER);
} else {
hasPermission(sender, Perms.INFO);
}
} else {
hasPermission(sender, Perms.INFO);
}*/
String[] args = new String[]{"info", region.getWorld().getName(), region.getProtectedRegion().getId()};
wg.onCommand(sender, wg.getCommand("region"), "region", args);
@ -159,5 +179,10 @@ public class CCommand implements CommandExecutor {
}
sender.sendMessage(L("command.worldguard.flag_set", flag.getName()));
}
/*private boolean hasPermission(CommandSender sender, IPermission permission) throws CommandPermissionsException {
wg.checkPermission(sender, permission.toString());
return true;
}*/
}

View file

@ -19,6 +19,7 @@ package de.jaschastarke.minecraft.worldguard;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
@ -33,34 +34,27 @@ public class CListener implements Listener {
this.com = com;
}
@EventHandler
@EventHandler(priority=EventPriority.HIGHEST) // run very late, because the event may be cancelled
public void onPlayerMove(PlayerMoveEvent event) {
if (event.isCancelled())
return;
//if (event.isCoarse()) { // next bukkit release will shortcut that
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) { // he really moved, and not just looked around
if (com.getRegionManager().isDiffrentRegion(event.getPlayer(), event.getTo())) {
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangedAreaEvent(event));
CPlayer.get(event.getPlayer()).setHash(com.getRegionManager().getRegionsHash(event.getTo()));
String current_hash = CPlayer.get(event.getPlayer()).getHash();
String new_hash = com.getRegionManager().getRegionsHash(event.getTo());
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangedAreaEvent(event, current_hash, new_hash));
CPlayer.get(event.getPlayer()).setHash(new_hash);
}
}
}
@EventHandler
@EventHandler(priority=EventPriority.HIGHEST) // run very late, because the event may be cancelled
public void onPlayerTeleport(PlayerTeleportEvent event) {
if (event.isCancelled())
return;
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) { // he really moved, and not just looked around
if (com.getRegionManager().isDiffrentRegion(event.getPlayer(), event.getTo())) {
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangedAreaEvent(event));
CPlayer.get(event.getPlayer()).setHash(com.getRegionManager().getRegionsHash(event.getTo()));
}
}
onPlayerMove(event);
}
@EventHandler

View file

@ -82,6 +82,10 @@ public class CRegionManager {
public World getWorld() {
return world;
}
public ProtectedRegion getGlobalRegion() {
return getWGManager(world).getRegion("__global__");
}
@SuppressWarnings("unchecked")
public <V> void storeFlag(CRegion region, Flag<V> flag, Object value) {
if (wc == null) {
@ -136,10 +140,17 @@ public class CRegionManager {
}
public String getRegionsHash(Location loc) {
StringBuilder hash = new StringBuilder(loc.getWorld().getName());
List<String> idlist = getWGGlobalManager().get(loc.getWorld()).getApplicableRegionsIDs(BukkitUtil.toVector(loc));
String[] ids = idlist.toArray(new String[idlist.size()]);
Arrays.sort(ids);
return Util.join(ids, "|");
if (idlist.size() > 0) {
hash.append("#");
String[] ids = idlist.toArray(new String[idlist.size()]);
if (ids.length > 1) {
Arrays.sort(ids);
}
hash.append(Util.join(ids, ","));
}
return hash.toString();
}
public ApplicableRegions getRegionSet(Location loc) {

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.worldguard;
import de.jaschastarke.minecraft.utils.IPermission;
@Deprecated // NOT USED YET
public enum Perms implements IPermission {
INFO("info"),
INFO_OWN("info.own"),
INFO_MEMBER("info.member");
private static final String NS = "worldguard.region";
private String perm;
private Perms(String permission) {
perm = permission;
}
@Override
public String toString() {
return NS + SEP + perm;
}
}

View file

@ -23,17 +23,23 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
import de.jaschastarke.minecraft.worldguard.Interface;
@SuppressWarnings("serial")
public class PlayerChangedAreaEvent extends Event {
private PlayerMoveEvent event;
private String _previous_hash;
private String _new_hash;
public PlayerChangedAreaEvent(PlayerMoveEvent moveevent) {
event = moveevent;
}
public PlayerChangedAreaEvent(PlayerMoveEvent moveevent, String previous_hash, String new_hash) {
event = moveevent;
_previous_hash = previous_hash;
_new_hash = new_hash;
}
public Player getPlayer() {
return event.getPlayer();
@ -50,19 +56,32 @@ public class PlayerChangedAreaEvent extends Event {
return Interface.getInstance().getRegionManager().getRegionSet(event.getTo());
}
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
LimitedCreativeCore.debug("getHandlers");
return handlers;
public String getPreviousRegionHash() {
if (_previous_hash == null)
_previous_hash = Interface.getInstance().getRegionManager().getRegionsHash(event.getFrom());
return _previous_hash;
}
public static HandlerList getHandlerList() {
LimitedCreativeCore.debug("getHandlerList");
return handlers;
public String getNewRegionHash() {
if (_new_hash == null)
_new_hash = Interface.getInstance().getRegionManager().getRegionsHash(event.getTo());
return _new_hash;
}
public PlayerMoveEvent getMoveEvent() {
return event;
}
public String toString() {
return getClass().getSimpleName()+"["+getPreviousRegionHash()+" -> "+getNewRegionHash()+"]";
}
private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}