- invalid enchants allowed (by config)
 - optional switch to survival in creative regions
 - fixed initial config create (ticket #6)
 - added teleport listener (ticket 3)
 - misc bugfixes/improvements
This commit is contained in:
Jascha Starke 2012-01-24 21:02:27 +01:00
parent 2c9e4b80a3
commit 85602d4922
11 changed files with 280 additions and 75 deletions

View file

@ -17,6 +17,14 @@ store:
# default: true
creative: true
# UnsafeStore (for storing invalid enchants)
# By default the new and upgrade-safe storage method for items is used. This method doesn't allow the use
# of "invalid" enchants, like given by different plugins. Enable it, to allow invalid enchants (not recommended).
# This option can only changed by reloading the plugin (not via ingame commands).
# default: false
unsafe: false
# InventoryFolder
# The folder inside the datadir-folder (plugin/LimitedCreative) where the inventories are saved to.
# By default the inventories are saved to "plugin/LimitedCreative/inventories".
@ -41,6 +49,25 @@ limit:
# Attention: this will also block useful signs, like Lifts.
# default: true
sign: true
# UseBlackList
# Prevents using or placing of the given blocks in creative mode (and only in creative).
# You can use the technical name (see http://jd.bukkit.org/doxygen/d7/dd9/namespaceorg_1_1bukkit.html#ab7fa290bb19b9a830362aa88028ec80a)
# or the id of the block/item (better use the id, if you're not sure).
# To prevent Lava you need to add "LAVA_BUCKET", because lava-blocks aren't "placed", therefore Lava-Buckets are
# "used".
# This option can only changed by reloading the plugin (not via ingame commands).
# default: []
use: []
# BreakBlackList
# Prevents destroying of the given blocks in creative mode (and only in creative).
# You can use the technical name (see http://jd.bukkit.org/doxygen/d7/dd9/namespaceorg_1_1bukkit.html#ab7fa290bb19b9a830362aa88028ec80a)
# or the id of the block/item (better use the id, if you're not sure).
# This option can only changed by reloading the plugin (not via ingame commands).
# default: [bedrock]
break:
- bedrock
region:
# RegionsEnabled
@ -49,13 +76,19 @@ region:
# This option can only changed by reloading the plugin (not via ingame commands).
# default: true
enabled: true
# RegionOptional
# Allows Players to use /lc creative|survival to switch between GameModes in creative-regions, even if they
# have no global permission to those commands
# default: true
optional: true
permissions:
# PermissionsEnabled
# When enabled, the Permissions will allow selected users to ignore limitations like PvP, Chest-Block, etc.
# When not enabled, all users are treated equally.
# Note: The Permission needed for commands, are not affected by this option. So you still need the defined
# permissions or op, to use commands, even if this options is disabled!
# Note: Not all Permission, are affected by this option. So you still need the defined permissions or op, to use
# commands, even if this options is disabled!
# default: false
enabled: false

View file

@ -7,6 +7,7 @@ command:
overview: storecreative|blockpickup|blocksign|permissions|perm_keepinventory
gamemode:
changed: "{0}'s game mode has been changed"
no_change: Already in that game mode.
option:
done: Option changed.
worldguard:
@ -28,8 +29,14 @@ exception:
invalidoption: Unknown option
config:
savefail: Failed to write modified configuration to disk
material_not_found: (Config) Material with name/id "{0}" was not found.
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
blocked:
chest: Access to chests is not allowed in creative mode
sign: To interact with signs is not allowed in creative mode
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: You can not place blocks outside of the creative-area
outside_creative_break: You can not destroy blocks outside of the creative-area

View file

@ -1,7 +1,8 @@
name: LimitedCreative
main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore
version: 0.5.1-alpha
version: 0.6-beta
softdepend: [WorldGuard]
dev-url: http://dev.bukkit.org/server-mods/limited-creative/
commands:
limitedcreative:
description: Main LimitedCreative-Controlling-Commands
@ -44,4 +45,10 @@ permissions:
default: false
limitedcreative.nolimit.pvp:
description: Allows bypassing the "no pvp"-limitation
default: false
limitedcreative.nolimit.use:
description: Allows bypassing the "block place/item use"-limitation
default: false
limitedcreative.nolimit.break:
description: Allows bypassing the "block break"-limitation
default: false

View file

@ -81,20 +81,18 @@ public class Commands {
}
String c = label;
String message = "";
if (sender.hasPermission("limitedcreative.switch_gamemode") || sender.hasPermission("limitedcreative.switch_gamemode.backonly"))
message += "/"+c+" s[urvival] ["+L("command.player")+"] - "+L("command.switch.survival")+"\n";
if (sender.hasPermission("limitedcreative.switch_gamemode"))
message += "/"+c+" c[reative] ["+L("command.player")+"] - "+L("command.switch.creative")+"\n";
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 (sender.hasPermission("limitedcreative.config"))
message += "/"+c+" e[nable] "+L("command.config.overview")+"\n";
message.append("/"+c+" e[nable] "+L("command.config.overview")+"\n");
if (sender.hasPermission("limitedcreative.config"))
message += "/"+c+" d[isable] "+L("command.config.overview")+"\n";
if (sender.hasPermission("limitedcreative.config"))
message += "/"+c+" r[egion] "+L("command.worldguard.alias")+"\n";
message.append("/"+c+" d[isable] "+L("command.config.overview")+"\n");
if (sender.hasPermission("limitedcreative.regions"))
message.append("/"+c+" r[egion] "+L("command.worldguard.alias")+"\n");
if (message.length() > 0) {
sender.sendMessage("Usage:");
for (String m : message.split("\n")) {
for (String m : message.toString().split("\n")) {
sender.sendMessage(m);
}
return true;
@ -155,25 +153,22 @@ public class Commands {
target = plugin.getServer().getPlayer(args[1]);
else if (sender instanceof Player)
target = (Player) sender;
if (sender instanceof Player && !sender.isOp()) {
if (!sender.hasPermission("limitedcreative.switch_gamemode")) {
if (gm != GameMode.SURVIVAL || !sender.hasPermission("limitedcreative.switch_gamemode.backonly")) {
throw new LackingPermissionException();
}
}
if (sender != target && !sender.hasPermission("limitedcreative.switch_gamemode.other")) {
throw new LackingPermissionException();
}
}
if (target == null) {
throw new InvalidCommandException("exception.command.playernotfound");
}
if (target.getGameMode() != gm) {
target.setGameMode(gm);
if (target != sender) {
sender.sendMessage(L("commands.gamemode.changed", target.getName()));
} else if (sender instanceof Player && sender != target && !sender.hasPermission("limitedcreative.switch_gamemode.other")) {
throw new LackingPermissionException();
} else if (target.getGameMode() != gm) {
if (sender == target) {
LCPlayer.get(target).changeGameMode(gm);
} else {
target.setGameMode(gm);
}
if (target != sender) {
sender.sendMessage(L("command.gamemode.changed", target.getName()));
}
} else {
sender.sendMessage(L("command.gamemode.no_change"));
}
}

View file

@ -18,10 +18,14 @@
package de.jaschastarke.minecraft.limitedcreative;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import static de.jaschastarke.minecraft.utils.Util.copyFile;
import static de.jaschastarke.minecraft.utils.Locale.L;
public class Configuration {
private FileConfiguration c;
@ -52,6 +56,9 @@ public class Configuration {
public boolean getStoreCreative() {
return c.getBoolean("store.creative", true);
}
public boolean getUnsafeStorage() {
return c.getBoolean("store.unsafe", false);
}
public String getInventoryFolder() {
return c.getString("store.folder", "inventories");
}
@ -67,6 +74,9 @@ public class Configuration {
public boolean getPermissionToKeepInventory() {
return this.getPermissionsEnabled() && c.getBoolean("permissions.keepinventory", false);
}
public boolean getRegionOptional() {
return c.getBoolean("region.optional", true);
}
public void setStoreCreative(boolean value) {
@ -96,17 +106,49 @@ public class Configuration {
c.set("permissions.keepinventory", value);
this.save();
}
protected void reload() {
_block_break = null;
_block_use = null;
plugin.reloadConfig();
c = plugin.getConfig();
}
protected void save() {
plugin.saveConfig();
/*try {
c.save(file);
} catch (IOException e) {
plugin.logger.severe(L("exception.config.savefail"));
e.printStackTrace();
}*/
}
private List<Material> _block_break = null;
private List<Material> _block_use = null;
public List<Material> getBlockedBreaks() {
if (_block_break == null)
_block_break = parseMaterialList(c.getStringList("limit.break"));
return _block_break;
}
public List<Material> getBlockedUse() {
if (_block_use == null)
_block_use = parseMaterialList(c.getStringList("limit.use"));
return _block_use;
}
private List<Material> parseMaterialList(List<String> s) {
List<Material> list = new ArrayList<Material>();
if (s != null) {
for (String m : s) {
Material e = null;
try {
e = Material.getMaterial(Integer.parseInt(m));
} catch (NumberFormatException ex) {
e = Material.matchMaterial(m);
}
if (e == null) {
plugin.logger.warning("["+plugin.getDescription().getName()+"] "+L("exception.config.material_not_found", m));
} else {
list.add(e);
}
}
}
return list;
}
}

View file

@ -20,6 +20,7 @@ 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;
@ -28,6 +29,7 @@ import org.bukkit.inventory.PlayerInventory;
import de.jaschastarke.minecraft.limitedcreative.serialize.Armor;
import de.jaschastarke.minecraft.limitedcreative.serialize.Items;
import static de.jaschastarke.minecraft.utils.Locale.L;
public class Inventory {
protected Player player;
@ -45,7 +47,15 @@ public class Inventory {
public void load(GameMode gm) {
File f = new File(LimitedCreativeCore.plugin.getDataFolder(), getFileName(player, gm));
restoreInventory(inv, f);
try {
restoreInventory(inv, f);
} catch (IllegalArgumentException e) {
if (LimitedCreativeCore.plugin.config.getUnsafeStorage()) {
throw e;
} else {
player.sendMessage(ChatColor.DARK_RED + L("exception.storage.load"));
}
}
}
public void load() {
load(player.getGameMode());

View file

@ -24,6 +24,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
@ -41,6 +42,7 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import de.jaschastarke.minecraft.limitedcreative.Commands.LackingPermissionException;
import de.jaschastarke.minecraft.limitedcreative.serialize.Items;
public class LCPlayer {
@ -52,14 +54,14 @@ public class LCPlayer {
private static File _store_file = new File(plugin.getDataFolder(), "players.yml");
public static YamlConfiguration store = YamlConfiguration.loadConfiguration(_store_file);
private boolean isPermanentCreative = false;
private boolean _isPermanentCreative = false;
private boolean _isRegionCreative = false;
private LCPlayer(Player pplayer) {
player = pplayer;
_isRegionCreative = store.getBoolean(player.getName()+".region_creative", false) && player.getGameMode() == GameMode.CREATIVE;
if (player.getGameMode() == GameMode.CREATIVE && !this.getRegionCreative())
isPermanentCreative = true;
if (player.getGameMode() == GameMode.CREATIVE && !this.isRegionCreative())
setPermanentCreative(true);
}
public Player getRaw() {
@ -76,9 +78,18 @@ public class LCPlayer {
}
}
public boolean getRegionCreative() {
public boolean isRegionCreative() {
return _isRegionCreative;
}
public void changeGameMode(GameMode gm) throws LackingPermissionException {
if (!isRegionCreative() && !getRaw().hasPermission("limitedcreative.switch_gamemode")) {
if (gm != GameMode.SURVIVAL || !getRaw().hasPermission("limitedcreative.switch_gamemode.backonly")) {
throw new Commands.LackingPermissionException();
}
}
getRaw().setGameMode(gm);
}
public void setRegionCreative(boolean b) {
if (b) {
store.set(player.getName()+".region_creative", true);
@ -93,13 +104,21 @@ public class LCPlayer {
}
_isRegionCreative = b;
}
public boolean isPermanentCreative() {
return _isPermanentCreative;
}
public void setPermanentCreative(boolean b) {
_isPermanentCreative = b;
if (b)
setRegionCreative(false);
}
public void onSetCreative() {
if (!this.getRegionCreative())
isPermanentCreative = true;
public boolean onSetCreative() {
if (!this.isRegionCreative())
setPermanentCreative(true);
if (plugin.config.getStoreEnabled()) {
if (plugin.config.getPermissionToKeepInventory() && player.hasPermission("limitedcreative.keepinventory"))
return;
return true;
Inventory inv = new Inventory(player);
inv.save();
if (plugin.config.getStoreCreative() && inv.isStored(GameMode.CREATIVE)) {
@ -108,13 +127,19 @@ public class LCPlayer {
inv.clear();
}
}
return true;
}
public void onSetSurvival() {
isPermanentCreative = false;
setRegionCreative(false);
public boolean onSetSurvival() {
if (isRegionCreative()) {
if (!plugin.config.getRegionOptional()) {
getRaw().sendMessage(ChatColor.RED + L("exception.region.no_survival"));
return false;
}
}
setPermanentCreative(false);
if (plugin.config.getStoreEnabled()) {
if (plugin.config.getPermissionToKeepInventory() && player.hasPermission("limitedcreative.keepinventory"))
return;
return true;
Inventory inv = new Inventory(player);
if (plugin.config.getStoreCreative()) {
inv.save();
@ -122,6 +147,7 @@ public class LCPlayer {
if (inv.isStored(GameMode.SURVIVAL))
inv.load(GameMode.SURVIVAL);
}
return true;
}
public void onDropItem(PlayerDropItemEvent event) {
if (player.getGameMode() == GameMode.CREATIVE) {
@ -201,19 +227,27 @@ public class LCPlayer {
private long lastFloatingTimeWarning = 0;
public void setRegionCreativeAllowed(boolean rcreative, PlayerMoveEvent event) {
if (rcreative && player.getGameMode() == GameMode.SURVIVAL) {
if (rcreative && player.getGameMode() == GameMode.SURVIVAL && !isRegionCreative()) {
setRegionCreative(true); // have to be set, before setGameMode
player.setGameMode(GameMode.CREATIVE);
} else if (!rcreative && player.getGameMode() == GameMode.CREATIVE && !isPermanentCreative) {
} else if (!rcreative && player.getGameMode() == GameMode.CREATIVE && !isPermanentCreative()) {
if (getFloatingHeight() > 3) {
if (System.currentTimeMillis() - lastFloatingTimeWarning > 10000) {// 10 sec. limit
player.sendMessage(L("blocked.survival_flying"));
lastFloatingTimeWarning = System.currentTimeMillis();
}
event.setTo(event.getFrom());
Location newloc = event.getTo().clone();
newloc.setX(event.getFrom().getX());
//newloc.setY(event.getFrom().getY());
newloc.setZ(event.getFrom().getZ());
event.setTo(newloc);
} else {
setRegionCreative(false);
player.setGameMode(GameMode.SURVIVAL); // also unsets isRegionCreative;
}
} else if (!rcreative && isRegionCreative()) {
setRegionCreative(false); // we have left, while in optional survival
}
}

View file

@ -32,6 +32,7 @@ import org.bukkit.event.Event.Priority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
@ -54,9 +55,11 @@ public final class Listener {
@Override
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
if (event.getNewGameMode() == GameMode.CREATIVE) {
LCPlayer.get(event.getPlayer()).onSetCreative();
if (!LCPlayer.get(event.getPlayer()).onSetCreative())
event.setCancelled(true);
} else if (event.getNewGameMode() == GameMode.SURVIVAL) {
LCPlayer.get(event.getPlayer()).onSetSurvival();
if (!LCPlayer.get(event.getPlayer()).onSetSurvival())
event.setCancelled(true);
}
}
@ -79,7 +82,18 @@ public final class Listener {
@Override
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.isCancelled() || event.getAction() != Action.RIGHT_CLICK_BLOCK)
if (isCancelled(event) || event.getPlayer().getGameMode() != GameMode.CREATIVE)
return;
if (!plugin.config.getPermissionsEnabled() || event.getPlayer().hasPermission("limitedcreative.nolimit.use")) {
if (event.getItem() != null && plugin.config.getBlockedUse().contains(event.getItem().getType())) {
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
return;
}
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
Block block = event.getClickedBlock();
@ -91,12 +105,28 @@ public final class Listener {
LCPlayer.get(event.getPlayer()).onSignAccess(event);
}
}
/**
* The isCancelled in PlayerInteractEvent doesn't check useItemInHand, even this decides (when clicking on
* entity with e.g. a bucket)
* @param event
* @return The relevant "isCancelled"
*/
public static boolean isCancelled(PlayerInteractEvent event) {
return event.useInteractedBlock() == Event.Result.DENY && event.useItemInHand() == Event.Result.DENY;
}
@Override
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (event.isCancelled() || event.getPlayer().getGameMode() == GameMode.SURVIVAL)
if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
return;
if (!plugin.config.getPermissionsEnabled() || event.getPlayer().hasPermission("limitedcreative.nolimit.use")) {
if (event.getPlayer().getItemInHand() != null && plugin.config.getBlockedUse().contains(event.getPlayer().getItemInHand().getType())) {
event.setCancelled(true);
return;
}
}
Entity entity = event.getRightClicked();
if (entity instanceof StorageMinecart) {
@ -145,8 +175,10 @@ public final class Listener {
}
private void register() {
if (plugin.config.getLimitEnabled() || plugin.worldguard != null) {
pm.registerEvent(Event.Type.ITEM_SPAWN, this, Priority.Normal, plugin);
}
if (plugin.config.getLimitEnabled()) {
plugin.getServer().getPluginManager().registerEvent(Event.Type.ITEM_SPAWN, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.ENTITY_DEATH, this, Priority.Low, plugin);
}
@ -159,9 +191,15 @@ public final class Listener {
if (event.isCancelled())
return;
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
// Prevent dropping of doors and beds when destroying the wrong part
if (!plugin.config.getPermissionsEnabled() || event.getPlayer().hasPermission("limitedcreative.nolimit.break")) {
if (plugin.config.getBlockedBreaks().contains(event.getBlock().getType())) {
event.setCancelled(true);
}
}
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.drop"))
return;
// Prevent dropping of doors and beds when destroying the wrong part
Block block = event.getBlock();
Material mat = block.getType();
switch (event.getBlock().getType()) {
@ -185,9 +223,22 @@ public final class Listener {
}
}
}
@Override
public void onBlockPlace(BlockPlaceEvent event) {
if (event.isCancelled())
return;
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
if (!plugin.config.getPermissionsEnabled() || event.getPlayer().hasPermission("limitedcreative.nolimit.use")) {
if (plugin.config.getBlockedUse().contains(event.getBlock().getType())) {
event.setCancelled(true);
}
}
}
}
private void register() {
if (plugin.config.getLimitEnabled()) {
pm.registerEvent(Event.Type.BLOCK_BREAK, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.BLOCK_PLACE, this, Priority.Normal, plugin);
}
}
}

View file

@ -23,11 +23,11 @@ import org.bukkit.GameMode;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import com.sk89q.worldedit.Vector;
@ -88,10 +88,11 @@ public class WorldGuardIntegration {
RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld());
Vector pt = new Vector(event.getBlock().getLocation().getBlockX(), event.getBlock().getLocation().getBlockY(), event.getBlock().getLocation().getBlockZ());
ApplicableRegions set = new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(event.getPlayer().getWorld()));
boolean creative_region = set.allows(CREATIVE);
plugin.logger.info("in creative region: "+Boolean.toString(creative_region)+" - "+event.getBlock().getLocation());
if (creative_region && player.getRaw().getGameMode() != GameMode.CREATIVE) {
if (player.isRegionCreative() && !set.allows(CREATIVE, player)) {
event.getPlayer().sendMessage(L("blocked.outside_creative_break"));
event.setCancelled(true);
} else if (set.allows(CREATIVE) && player.getRaw().getGameMode() != GameMode.CREATIVE) {
plugin.spawnblock.block(event.getBlock(), player);
}
}
@ -101,7 +102,7 @@ public class WorldGuardIntegration {
if (event.isCancelled())
return;
LCPlayer player = LCPlayer.get(event.getPlayer());
if (player.getRegionCreative()) {
if (player.isRegionCreative()) {
// do not build outside of creative regions, when in the region
RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld());
Vector pt = new Vector(event.getBlock().getLocation().getBlockX(), event.getBlock().getLocation().getBlockY(), event.getBlock().getLocation().getBlockZ());
@ -113,15 +114,9 @@ public class WorldGuardIntegration {
}
}
@Override
public void onBlockDispense(BlockDispenseEvent event) {
plugin.logger.info("Block dispense: "+event.getBlock().getType()+" - "+event.getItem().getType());
}
private void register() {
plugin.getServer().getPluginManager().registerEvent(Event.Type.BLOCK_BREAK, this, Priority.Normal, plugin);
plugin.getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACE, this, Priority.Normal, plugin);
plugin.getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DISPENSE, this, Priority.Normal, plugin);
}
}
public class WGIPlayerListen extends PlayerListener {
@ -142,8 +137,26 @@ public class WorldGuardIntegration {
}
}
@Override
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()) {
LCPlayer player = LCPlayer.get(event.getPlayer());
RegionManager mgr = wg.getGlobalRegionManager().get(event.getPlayer().getWorld());
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
ApplicableRegions set = new ApplicableRegions(mgr.getApplicableRegions(pt), rm.world(event.getPlayer().getWorld()));
player.setRegionCreativeAllowed(set.allows(CREATIVE, player), event);
}
}
private void register() {
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_MOVE, this, Priority.Normal, plugin);
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_TELEPORT, this, Priority.Normal, plugin);
}
}
}

View file

@ -22,6 +22,7 @@ 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;
@ -51,7 +52,7 @@ public class Items implements Storeable {
}
public static void sectionSetItem(ConfigurationSection section, String path, ItemStack item) {
if (!LimitedCreativeCore.serializeFallBack) {
if (!LimitedCreativeCore.serializeFallBack && !LimitedCreativeCore.plugin.config.getUnsafeStorage()) {
section.set(path, item);
} else { // compatibility fallback
Map<String, Object> serialize = item.serialize();
@ -63,14 +64,24 @@ public class Items implements Storeable {
public static ItemStack sectionGetItem(ConfigurationSection section, String path) {
if (section.isItemStack(path)) {
return section.getItemStack(path);
} else { // compatibility fallback
} else {
ConfigurationSection s = section.getConfigurationSection(path);
Map<String, Object> serialize = s.getValues(false);
if (s.contains("enchantments"))
serialize.put("enchantments", s.getConfigurationSection("enchantments").getValues(false));
serialize.remove("enchantments");
if (s.contains("damage") && LimitedCreativeCore.serializeFallBack)
serialize.put("damage", new Integer(s.getInt("damage")).shortValue());
return ItemStack.deserialize(serialize);
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) {

View file

@ -42,6 +42,8 @@ final public class Util {
public static void copyFile(InputStream is, File to) {
try {
if (to.getParentFile() != null && !to.getParentFile().exists())
to.getParentFile().mkdirs();
OutputStream os;
os = new FileOutputStream(to);
byte[] buffer = new byte[512];