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:
parent
07fcabbd56
commit
3bdca1cdb1
37 changed files with 1362 additions and 601 deletions
|
@ -47,7 +47,7 @@ exception:
|
||||||
storage:
|
storage:
|
||||||
load: Failed to load your Inventory. Ask your Admin to enable "UnsafeStorage" for LimitedCreative to allow invalid enchants on items
|
load: Failed to load your Inventory. Ask your Admin to enable "UnsafeStorage" for LimitedCreative to allow invalid enchants on items
|
||||||
region:
|
region:
|
||||||
no_survival: You can not be survival in an creative area
|
not_optional: You can not be {0} in that area
|
||||||
blocked:
|
blocked:
|
||||||
chest: Access to chests is not allowed in creative mode
|
chest: Access to chests is not allowed in creative mode
|
||||||
sign: To interact with signs 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
|
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
|
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
|
use: You are not allowed to use this type of item
|
||||||
place: You are not allowed to place this type of block
|
place: You are not allowed to place this type of block
|
||||||
break: You are not allowed to break this type of block
|
break: You are not allowed to break this type of block
|
||||||
|
|
12
plugin.yml
12
plugin.yml
|
@ -1,6 +1,6 @@
|
||||||
name: LimitedCreative
|
name: LimitedCreative
|
||||||
main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore
|
main: de.jaschastarke.minecraft.limitedcreative.Core
|
||||||
version: 0.9.2-beta
|
version: 0.9.5-dev
|
||||||
softdepend: [WorldGuard, WorldEdit, MultiInv]
|
softdepend: [WorldGuard, WorldEdit, MultiInv]
|
||||||
dev-url: http://dev.bukkit.org/server-mods/limited-creative/
|
dev-url: http://dev.bukkit.org/server-mods/limited-creative/
|
||||||
commands:
|
commands:
|
||||||
|
@ -23,8 +23,14 @@ permissions:
|
||||||
description: Allows switching of own game mode to creative and back
|
description: Allows switching of own game mode to creative and back
|
||||||
default: op
|
default: op
|
||||||
limitedcreative.switch_gamemode.backonly:
|
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
|
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:
|
limitedcreative.switch_gamemode.other:
|
||||||
description: Allows switching of other users game mode
|
description: Allows switching of other users game mode
|
||||||
default: op
|
default: op
|
||||||
|
|
|
@ -19,14 +19,20 @@ package de.jaschastarke.minecraft.integration;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
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.auth.PlayerCache;
|
||||||
import uk.org.whoami.authme.cache.limbo.LimboCache;
|
import uk.org.whoami.authme.cache.limbo.LimboCache;
|
||||||
|
|
||||||
public class AuthMe implements CommunicationBridge {
|
public class AuthMe implements CommunicationBridge {
|
||||||
public static boolean isLoggedIn(Player player) {
|
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) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||||
|
|
||||||
public class Communicator extends AbstractCommunicator {
|
public class Communicator extends AbstractCommunicator {
|
||||||
public Communicator(JavaPlugin plugin) {
|
public Communicator(JavaPlugin plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
|
@ -40,6 +42,14 @@ public class Communicator extends AbstractCommunicator {
|
||||||
boolean creative = Bukkit.getServer().getDefaultGameMode() == GameMode.CREATIVE;
|
boolean creative = Bukkit.getServer().getDefaultGameMode() == GameMode.CREATIVE;
|
||||||
if (isPluginEnabled("Multiverse-Core"))
|
if (isPluginEnabled("Multiverse-Core"))
|
||||||
creative = MultiVerse.isCreative(world);
|
creative = MultiVerse.isCreative(world);
|
||||||
|
Core.debug("com: "+world.getName()+": is creative: "+creative);
|
||||||
return 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,20 @@ import org.bukkit.World;
|
||||||
|
|
||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
|
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||||
|
|
||||||
public class MultiVerse implements CommunicationBridge {
|
public class MultiVerse implements CommunicationBridge {
|
||||||
|
|
||||||
public static boolean isCreative(World world) {
|
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() {
|
private static MultiverseCore getMV() {
|
||||||
|
|
|
@ -22,14 +22,18 @@ import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.cypherx.xauth.xAuthPlayer;
|
import com.cypherx.xauth.xAuthPlayer;
|
||||||
|
|
||||||
|
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||||
|
|
||||||
public class xAuth implements CommunicationBridge {
|
public class xAuth implements CommunicationBridge {
|
||||||
public static boolean isLoggedInNotGuest(Player player) {
|
public static boolean isLoggedInNotGuest(Player player) {
|
||||||
xAuthPlayer xpl = getAuth().getPlayer(player.getName());
|
xAuthPlayer xpl = getAuth().getPlayer(player.getName());
|
||||||
|
boolean li = true;
|
||||||
if (!xpl.isAuthenticated())
|
if (!xpl.isAuthenticated())
|
||||||
return false;
|
li = false;
|
||||||
if (xpl.isGuest())
|
else if (xpl.isGuest())
|
||||||
return false;
|
li = false;
|
||||||
return true;
|
Core.debug("xAuth: "+player.getName()+": logged in not guest: "+li);
|
||||||
|
return li;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static com.cypherx.xauth.xAuth getAuth() {
|
private static com.cypherx.xauth.xAuth getAuth() {
|
||||||
|
|
|
@ -27,11 +27,12 @@ import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import de.jaschastarke.minecraft.utils.IPermission;
|
||||||
import de.jaschastarke.minecraft.utils.Util;
|
import de.jaschastarke.minecraft.utils.Util;
|
||||||
import static de.jaschastarke.minecraft.utils.Locale.L;
|
import static de.jaschastarke.minecraft.utils.Locale.L;
|
||||||
|
|
||||||
public class Commands {
|
public class Commands {
|
||||||
private static LimitedCreativeCore plugin;
|
private static Core plugin;
|
||||||
public static class MainCommandExecutor implements CommandExecutor {
|
public static class MainCommandExecutor implements CommandExecutor {
|
||||||
|
|
||||||
public enum Action {
|
public enum Action {
|
||||||
|
@ -45,7 +46,7 @@ public class Commands {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
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) {
|
if (args.length > 0) {
|
||||||
Action act = null;
|
Action act = null;
|
||||||
try {
|
try {
|
||||||
|
@ -76,12 +77,13 @@ public class Commands {
|
||||||
plugin.getCommand("/region").execute(sender, "/region", args);
|
plugin.getCommand("/region").execute(sender, "/region", args);
|
||||||
return true;
|
return true;
|
||||||
case RELOAD:
|
case RELOAD:
|
||||||
plugin.getServer().getPluginManager().disablePlugin(plugin);
|
//plugin.getServer().getPluginManager().disablePlugin(plugin); // disable removes classloader, so re-enabling causes problems
|
||||||
plugin.getServer().getPluginManager().enablePlugin(plugin);
|
//plugin.getServer().getPluginManager().enablePlugin(plugin);
|
||||||
|
plugin.reload();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (CommandException e) {
|
} catch (CommandException e) {
|
||||||
LimitedCreativeCore.debug("CommandException: "+e.getMessage());
|
Core.debug("CommandException: "+e.getMessage());
|
||||||
sender.sendMessage(ChatColor.DARK_RED + e.getLocalizedMessage());
|
sender.sendMessage(ChatColor.DARK_RED + e.getLocalizedMessage());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -92,12 +94,12 @@ public class Commands {
|
||||||
StringBuilder message = new StringBuilder();
|
StringBuilder message = new StringBuilder();
|
||||||
message.append("/"+c+" s[urvival] ["+L("command.player")+"] - "+L("command.switch.survival")+"\n");
|
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");
|
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+" e[nable] "+L("command.config.overview")+"\n");
|
||||||
message.append("/"+c+" d[isable] "+L("command.config.overview")+"\n");
|
message.append("/"+c+" d[isable] "+L("command.config.overview")+"\n");
|
||||||
message.append("/"+c+" reload "+L("command.config.reload")+"\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");
|
message.append("/"+c+" r[egion] "+L("command.worldguard.alias")+"\n");
|
||||||
if (message.length() > 0) {
|
if (message.length() > 0) {
|
||||||
sender.sendMessage("Usage:");
|
sender.sendMessage("Usage:");
|
||||||
|
@ -110,7 +112,7 @@ public class Commands {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOption(CommandSender sender, String[] args, boolean b) throws CommandException {
|
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();
|
throw new LackingPermissionException();
|
||||||
}
|
}
|
||||||
if (args.length > 2)
|
if (args.length > 2)
|
||||||
|
@ -154,13 +156,17 @@ public class Commands {
|
||||||
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
throw new InvalidCommandException("exception.command.playernotfound");
|
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();
|
throw new LackingPermissionException();
|
||||||
} else if (target.getGameMode() != gm) {
|
} else if (target.getGameMode() != gm) {
|
||||||
if (sender == target) {
|
if ((hasPermission(sender, Perms.GM)) ||
|
||||||
LCPlayer.get(target).changeGameMode(gm);
|
Players.get(target).isGameModeAllowed(gm) ||
|
||||||
} else {
|
(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);
|
target.setGameMode(gm);
|
||||||
|
} else {
|
||||||
|
throw new LackingPermissionException();
|
||||||
}
|
}
|
||||||
if (target != sender) {
|
if (target != sender) {
|
||||||
sender.sendMessage(L("command.gamemode.changed", target.getName()));
|
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 = pplugin;
|
||||||
plugin.getCommand("limitedcreative").setExecutor(new MainCommandExecutor());
|
plugin.getCommand("limitedcreative").setExecutor(new MainCommandExecutor());
|
||||||
if (plugin.worldguard == null) {
|
if (plugin.worldguard == null) {
|
||||||
plugin.getCommand("/region").setExecutor(new NotAvailableCommandExecutor());
|
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 {
|
abstract static public class CommandException extends Exception {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
|
@ -25,13 +25,16 @@ import java.util.List;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
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.Util.copyFile;
|
||||||
import static de.jaschastarke.minecraft.utils.Locale.L;
|
import static de.jaschastarke.minecraft.utils.Locale.L;
|
||||||
|
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
private FileConfiguration c;
|
private FileConfiguration c;
|
||||||
private File file;
|
private File file;
|
||||||
public static LimitedCreativeCore plugin;
|
public static Core plugin;
|
||||||
|
|
||||||
public enum Option {
|
public enum Option {
|
||||||
STORECREATIVE("store.creative", true),
|
STORECREATIVE("store.creative", true),
|
||||||
|
@ -66,7 +69,7 @@ public class Configuration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Configuration(LimitedCreativeCore pplugin) {
|
public Configuration(Core pplugin) {
|
||||||
plugin = pplugin;
|
plugin = pplugin;
|
||||||
|
|
||||||
file = new File(plugin.getDataFolder(), "config.yml");
|
file = new File(plugin.getDataFolder(), "config.yml");
|
||||||
|
@ -225,4 +228,23 @@ public class Configuration {
|
||||||
public boolean getTempStoreEnabled() {
|
public boolean getTempStoreEnabled() {
|
||||||
return _store_enabled;
|
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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package de.jaschastarke.minecraft.limitedcreative;
|
package de.jaschastarke.minecraft.limitedcreative;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
@ -30,13 +31,13 @@ import de.jaschastarke.minecraft.utils.Locale;
|
||||||
import de.jaschastarke.minecraft.utils.Permissions;
|
import de.jaschastarke.minecraft.utils.Permissions;
|
||||||
|
|
||||||
|
|
||||||
public class LimitedCreativeCore extends JavaPlugin {
|
public class Core extends JavaPlugin {
|
||||||
public final Logger logger = Logger.getLogger("Minecraft");
|
public final Logger logger = Logger.getLogger("Minecraft");
|
||||||
public Configuration config;
|
public Configuration config;
|
||||||
public Permissions perm;
|
public Permissions perm;
|
||||||
public WorldGuardIntegration worldguard;
|
public WorldGuardIntegration worldguard;
|
||||||
public Communicator com;
|
public Communicator com;
|
||||||
public static LimitedCreativeCore plugin;
|
public static Core plugin;
|
||||||
public NoBlockItemSpawn spawnblock;
|
public NoBlockItemSpawn spawnblock;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -89,12 +90,12 @@ public class LimitedCreativeCore extends JavaPlugin {
|
||||||
|
|
||||||
Commands.register(this);
|
Commands.register(this);
|
||||||
|
|
||||||
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
/*plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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();
|
PluginDescriptionFile df = this.getDescription();
|
||||||
if (worldguard != null)
|
if (worldguard != null)
|
||||||
|
@ -103,14 +104,27 @@ public class LimitedCreativeCore extends JavaPlugin {
|
||||||
logger.info("["+df.getName() + " v" + df.getVersion() + "] "+L("basic.loaded.no_worldguard"));
|
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) {
|
public void info(String s) {
|
||||||
logger.info("["+this.getDescription().getName()+"] " + s);
|
logger.info("["+this.getDescription().getName()+"] " + s);
|
||||||
}
|
}
|
||||||
public void warn(String s) {
|
public void warn(String s) {
|
||||||
logger.warning("["+this.getDescription().getName()+"] " + s);
|
logger.warning("["+this.getDescription().getName()+"] " + s);
|
||||||
}
|
}
|
||||||
|
public void error(String s) {
|
||||||
|
logger.severe("["+this.getDescription().getName()+"] " + s);
|
||||||
|
}
|
||||||
public static void debug(String s) {
|
public static void debug(String s) {
|
||||||
if (plugin.config.getDebug())
|
if (isDebug())
|
||||||
plugin.info("DEBUG: " + s);
|
plugin.info("DEBUG: " + s);
|
||||||
}
|
}
|
||||||
|
public static boolean isDebug() {
|
||||||
|
return plugin.config.getDebug();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -17,94 +17,85 @@
|
||||||
*/
|
*/
|
||||||
package de.jaschastarke.minecraft.limitedcreative;
|
package de.jaschastarke.minecraft.limitedcreative;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.serialize.Armor;
|
import de.jaschastarke.minecraft.limitedcreative.store.PlayerInventoryStorage;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.serialize.Items;
|
|
||||||
import static de.jaschastarke.minecraft.utils.Locale.L;
|
import static de.jaschastarke.minecraft.utils.Locale.L;
|
||||||
|
|
||||||
public class Inventory {
|
public class Inventory {
|
||||||
protected Player player;
|
private static PlayerInventoryStorage storage = Core.plugin.config.getInvetoryStorage();
|
||||||
protected PlayerInventory inv;
|
//private static InvMemStorage tempinvs = new InvMemStorage();
|
||||||
|
|
||||||
public Inventory(Player p) {
|
protected LCPlayer player;
|
||||||
player = p;
|
|
||||||
|
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() {
|
private PlayerInventory inv() {
|
||||||
return player.getInventory();
|
return player.getPlayer().getInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
LimitedCreativeCore.debug(player.getName() + " storing inventory "+player.getGameMode().toString());
|
Core.debug(getPlayer().getName()+": store inventory: "+getPlayer().getGameMode());
|
||||||
File f = new File(LimitedCreativeCore.plugin.getDataFolder(), getFileName(player, player.getGameMode()));
|
storage.store(this, Target.getTarget(getPlayer().getGameMode()));
|
||||||
storeInventory(inv(), f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load(GameMode gm) {
|
|
||||||
LimitedCreativeCore.debug(player.getName() + " loading inventory "+gm.toString());
|
|
||||||
File f = new File(LimitedCreativeCore.plugin.getDataFolder(), getFileName(player, gm));
|
|
||||||
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() {
|
public void load() {
|
||||||
load(player.getGameMode());
|
load(getPlayer().getGameMode());
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
inv().setArmorContents(new ItemStack[]{
|
|
||||||
new ItemStack(0),
|
|
||||||
new ItemStack(0),
|
|
||||||
new ItemStack(0),
|
|
||||||
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) {
|
public boolean isStored(GameMode gm) {
|
||||||
File f = new File(LimitedCreativeCore.plugin.getDataFolder(), getFileName(player, gm));
|
return storage.contains(this, Target.getTarget(gm));
|
||||||
return f.exists();
|
}
|
||||||
|
|
||||||
|
public void load(GameMode gm) {
|
||||||
|
Core.debug(getPlayer().getName()+": load inventory: "+gm);
|
||||||
|
try {
|
||||||
|
storage.load(this, Target.getTarget(gm));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
if (Core.plugin.config.getUnsafeStorage()) {
|
||||||
|
throw e;
|
||||||
|
} else {
|
||||||
|
getPlayer().sendMessage(ChatColor.DARK_RED + L("exception.storage.load"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*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[0]);
|
||||||
|
inv().clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
*/
|
*/
|
||||||
package de.jaschastarke.minecraft.limitedcreative;
|
package de.jaschastarke.minecraft.limitedcreative;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -29,7 +27,6 @@ import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.entity.Creature;
|
import org.bukkit.entity.Creature;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
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.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.material.Lever;
|
import org.bukkit.material.Lever;
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.Commands.LackingPermissionException;
|
import de.jaschastarke.minecraft.utils.IPermission;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.serialize.Items;
|
import de.jaschastarke.minecraft.worldguard.events.PlayerChangedAreaEvent;
|
||||||
import static de.jaschastarke.minecraft.utils.Locale.L;
|
import static de.jaschastarke.minecraft.utils.Locale.L;
|
||||||
|
|
||||||
public class LCPlayer {
|
public class LCPlayer {
|
||||||
private static LimitedCreativeCore plugin = LimitedCreativeCore.plugin;
|
private static Core plugin = Core.plugin;
|
||||||
private static Map<String, LCPlayer> players = new HashMap<String, LCPlayer>();
|
|
||||||
private Player player;
|
//private Player player;
|
||||||
private Map<Integer, ItemStack> tempinv = null;
|
private String name;
|
||||||
private Inventory _inv;
|
private Inventory _inv;
|
||||||
private boolean _isPermanentCreative = false;
|
private GameMode _permanent_gamemode = null;
|
||||||
private boolean _isRegionCreative = false;
|
|
||||||
private long _timestamp;
|
private long _timestamp;
|
||||||
public static final long CLEANUP_TIMEOUT = 300000; // 300s = 5m
|
|
||||||
|
|
||||||
private static File _store_file = new File(plugin.getDataFolder(), "players.yml");
|
public LCPlayer(Player player) {
|
||||||
public static YamlConfiguration store = YamlConfiguration.loadConfiguration(_store_file);
|
//this.player = player;
|
||||||
|
name = player.getName();
|
||||||
|
touch();
|
||||||
|
|
||||||
private LCPlayer(Player player) {
|
if (!this.isRegionGameMode(player.getGameMode())) {
|
||||||
this.player = player;
|
setPermanentGameMode(player.getGameMode());
|
||||||
_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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void updatePlayer(Player player) {
|
/*private void updatePlayer(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
_inv = null;
|
_inv = null;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
//return player;
|
||||||
|
return plugin.getServer().getPlayerExact(name);
|
||||||
|
}
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getRaw() {
|
public Inventory getInv() {
|
||||||
return player;
|
if (_inv == null)
|
||||||
|
_inv = new Inventory(this);
|
||||||
|
return _inv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void touch() {
|
public void touch() {
|
||||||
_timestamp = System.currentTimeMillis();
|
_timestamp = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOutdated() {
|
public boolean isOutdated() {
|
||||||
return !getRaw().isOnline() && _timestamp < (System.currentTimeMillis() - CLEANUP_TIMEOUT);
|
return (getPlayer() == null || !getPlayer().isOnline()) &&
|
||||||
|
_timestamp < (System.currentTimeMillis() - Players.CLEANUP_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LCPlayer get(Player player) {
|
private Map<String, Object> options = new HashMap<String, Object>();
|
||||||
LimitedCreativeCore.debug("player: " + player.getName() + " - " + ((Object)player).hashCode() + " - " + player.getEntityId() + " - " + player.getUniqueId());
|
public void setRegionGameMode(final GameMode gm) {
|
||||||
if (!players.containsKey(player.getName())) {
|
options.remove("region");
|
||||||
LCPlayer p = new LCPlayer(player);
|
Core.debug(getName()+": set region game mode: " + gm);
|
||||||
players.put(player.getName(), p);
|
Players.getOptions().setRegionGameMode(getName(), gm);
|
||||||
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() {
|
private GameMode getRegionGameMode() {
|
||||||
return _isRegionCreative;
|
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 void changeGameMode(GameMode gm) throws LackingPermissionException {
|
public boolean isOptionalRegionGameMode() {
|
||||||
if (!isRegionCreative() && !hasPermission("limitedcreative.switch_gamemode")) {
|
return getOptionalRegionGameMode() != null;
|
||||||
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) {
|
/*private boolean isOptionalRegionGameMode(final GameMode gm) {
|
||||||
LimitedCreativeCore.debug(player.getName() + " region creative: " + b);
|
return gm.equals(getOptionalRegionGameMode());
|
||||||
if (b) {
|
}*/
|
||||||
store.set(player.getName()+".region_creative", true);
|
public boolean isOptionalRegionGameMode(final String region, final GameMode gm) {
|
||||||
} else {
|
return gm.equals(getOptionalRegionGameMode(region));
|
||||||
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() {
|
private GameMode getOptionalRegionGameMode() {
|
||||||
return _isPermanentCreative;
|
String region = plugin.worldguard.getRegionManager().getRegionsHash(getPlayer().getLocation());
|
||||||
|
return getOptionalRegionGameMode(region);
|
||||||
}
|
}
|
||||||
public void setPermanentCreative(boolean b) {
|
private GameMode getOptionalRegionGameMode(String region) {
|
||||||
LimitedCreativeCore.debug(player.getName() + " permanent creative: " + b);
|
if (!options.containsKey("region_opt#"+region)) {
|
||||||
_isPermanentCreative = b;
|
options.put("region_opt#"+region, Players.getOptions().getOptionalRegionGameMode(getName(), region));
|
||||||
if (b)
|
}
|
||||||
setRegionCreative(false);
|
Core.debug(getName()+": get optional region game mode: "+region+" - " + options.get("region_opt#"+region));
|
||||||
|
return (GameMode) options.get("region_opt#"+region);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onSetCreative() {
|
public void setOptionalRegionGameMode(GameMode gm) {
|
||||||
LimitedCreativeCore.debug(player.getName() + " going into creative");
|
String region = plugin.worldguard.getRegionManager().getRegionsHash(getPlayer().getLocation());
|
||||||
if (!this.isRegionCreative())
|
setOptionalRegionGameMode(region, gm);
|
||||||
setPermanentCreative(true);
|
}
|
||||||
if (plugin.config.getStoreEnabled()) {
|
public void setOptionalRegionGameMode(String region, GameMode gm) {
|
||||||
if (plugin.config.getPermissionToKeepInventory() && hasPermission("limitedcreative.keepinventory"))
|
options.remove("region_opt#"+region);
|
||||||
return true;
|
Core.debug(getName()+": set optional region game mode: "+region+" - " + gm);
|
||||||
inv().save();
|
Players.getOptions().setOptionalRegionGameMode(getName(), region, gm);
|
||||||
if (plugin.config.getStoreCreative() && inv().isStored(GameMode.CREATIVE)) {
|
}
|
||||||
inv().load(GameMode.CREATIVE);
|
|
||||||
|
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 {
|
} else {
|
||||||
inv().clear();
|
setRegionGameMode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
_permanent_gamemode = temp;
|
||||||
}
|
}
|
||||||
private Inventory inv() {
|
public boolean isPermanentGameMode(GameMode temp) {
|
||||||
if (_inv == null)
|
Core.debug(getName()+": get permanent game mode: " + _permanent_gamemode);
|
||||||
_inv = new Inventory(player);
|
return temp.equals(_permanent_gamemode);
|
||||||
return _inv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onSetSurvival() {
|
public boolean onSetGameMode(GameMode gm) {
|
||||||
LimitedCreativeCore.debug(player.getName() + " going into survival");
|
Core.debug(getName() + " going into " + gm);
|
||||||
if (isRegionCreative()) {
|
if (isRegionGameMode()) { // change to the other gamemode as the area defines
|
||||||
if (!plugin.config.getRegionOptional()) {
|
if (!isRegionGameMode(gm)) { // only when we are not switching to the mode the region allows
|
||||||
getRaw().sendMessage(ChatColor.RED + L("exception.region.no_survival"));
|
if (!plugin.config.getRegionOptional()) {
|
||||||
LimitedCreativeCore.debug("... denied");
|
getPlayer().sendMessage(ChatColor.RED + L("exception.region.not_optional", gm.toString().toLowerCase()));
|
||||||
return false;
|
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.getStoreEnabled()) {
|
||||||
if (plugin.config.getPermissionToKeepInventory() && hasPermission("limitedcreative.keepinventory"))
|
if (plugin.config.getPermissionToKeepInventory() && hasPermission(Perms.KEEPINVENTORY))
|
||||||
return true;
|
return true;
|
||||||
if (plugin.config.getStoreCreative()) {
|
if (gm != GameMode.CREATIVE || plugin.config.getStoreCreative())
|
||||||
inv().save();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDropItem(PlayerDropItemEvent event) {
|
public void onDropItem(PlayerDropItemEvent event) {
|
||||||
LimitedCreativeCore.debug(player.getName() + " ("+player.getGameMode()+") drops items " + event.getItemDrop().getItemStack().getType());
|
Core.debug(getName() + " ("+getPlayer().getGameMode()+") drops items " + event.getItemDrop().getItemStack().getType());
|
||||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||||
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.drop"))
|
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.DROP))
|
||||||
return;
|
return;
|
||||||
LimitedCreativeCore.debug("removed");
|
Core.debug("removed");
|
||||||
if (plugin.config.getRemoveDrop())
|
if (plugin.config.getRemoveDrop())
|
||||||
event.getItemDrop().remove();
|
event.getItemDrop().remove();
|
||||||
else
|
else
|
||||||
|
@ -210,8 +213,8 @@ public class LCPlayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void onPickupItem(PlayerPickupItemEvent event) {
|
public void onPickupItem(PlayerPickupItemEvent event) {
|
||||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||||
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.pickup"))
|
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.PICKUP))
|
||||||
return;
|
return;
|
||||||
if (plugin.config.getBlockPickupInCreative()) {
|
if (plugin.config.getBlockPickupInCreative()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
@ -223,36 +226,35 @@ public class LCPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDie(EntityDeathEvent event) {
|
public void onDie(EntityDeathEvent event) {
|
||||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||||
if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.drop")) {
|
if (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.NoLimit.DROP)) {
|
||||||
event.getDrops().clear();
|
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) {
|
public void onRespawn(PlayerRespawnEvent event) {
|
||||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||||
if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.drop")) {
|
if (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.NoLimit.DROP)) {
|
||||||
if (tempinv != null) {
|
getInv().restoreTemp();
|
||||||
Items.restoreInventory(player.getInventory(), tempinv);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tempinv = null;
|
getInv().clearTemp();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void onDamage(Entity from, EntityDamageByEntityEvent event) { // receives damage
|
public void onDamage(Entity from, EntityDamageByEntityEvent event) { // receives damage
|
||||||
if (from instanceof Player) {
|
if (from instanceof Player) {
|
||||||
// its PVP
|
// its PVP
|
||||||
Player attacker = (Player) event.getDamager();
|
Player attacker = (Player) event.getDamager();
|
||||||
if (attacker.getGameMode() == GameMode.CREATIVE) {
|
if (attacker.getGameMode() == GameMode.CREATIVE) {
|
||||||
if (!plugin.config.getPermissionsEnabled() || !get(attacker).hasPermission("limitedcreative.nolimit.pvp")) {
|
if (!plugin.config.getPermissionsEnabled() || !Players.get(attacker).hasPermission(Perms.NoLimit.PVP)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return; // skip next check
|
return; // skip next check
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
if (getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||||
if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.pvp")) {
|
if (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.NoLimit.PVP)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,8 +262,8 @@ public class LCPlayer {
|
||||||
}
|
}
|
||||||
public void onDealDamage(EntityDamageByEntityEvent event) { // deals damage
|
public void onDealDamage(EntityDamageByEntityEvent event) { // deals damage
|
||||||
if (event.getEntity() instanceof Creature) {
|
if (event.getEntity() instanceof Creature) {
|
||||||
if (player.getGameMode() == GameMode.CREATIVE && plugin.config.getMobDamageBlock()) {
|
if (getPlayer().getGameMode() == GameMode.CREATIVE && plugin.config.getMobDamageBlock()) {
|
||||||
if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.mob_damage")) {
|
if (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.NoLimit.MOB_DAMAGE)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,8 +275,8 @@ public class LCPlayer {
|
||||||
*/
|
*/
|
||||||
public void onTarget(EntityTargetEvent event) {
|
public void onTarget(EntityTargetEvent event) {
|
||||||
if (event.getEntity() instanceof Creature) {
|
if (event.getEntity() instanceof Creature) {
|
||||||
if (player.getGameMode() == GameMode.CREATIVE && plugin.config.getMobDamageBlock()) {
|
if (((Player) event.getTarget()).getGameMode() == GameMode.CREATIVE && plugin.config.getMobDamageBlock()) {
|
||||||
if (!plugin.config.getPermissionsEnabled() || !hasPermission("limitedcreative.nolimit.mob_damage")) {
|
if (!plugin.config.getPermissionsEnabled() || !hasPermission(Perms.NoLimit.MOB_DAMAGE)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,68 +284,83 @@ public class LCPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onChestAccess(PlayerInteractEvent event) {
|
public void onChestAccess(PlayerInteractEvent event) {
|
||||||
if (player.getGameMode() != GameMode.CREATIVE)
|
if (event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||||
return;
|
return;
|
||||||
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.chest"))
|
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.CHEST))
|
||||||
return;
|
return;
|
||||||
event.getPlayer().sendMessage(L("blocked.chest"));
|
event.getPlayer().sendMessage(L("blocked.chest"));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
public void onChestAccess(PlayerInteractEntityEvent event) { // chest-minecarts are different events
|
public void onChestAccess(PlayerInteractEntityEvent event) { // chest-minecarts are different events
|
||||||
if (player.getGameMode() != GameMode.CREATIVE)
|
if (getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||||
return;
|
return;
|
||||||
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.chest"))
|
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.CHEST))
|
||||||
return;
|
return;
|
||||||
event.getPlayer().sendMessage(L("blocked.chest"));
|
event.getPlayer().sendMessage(L("blocked.chest"));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
public void onBenchAccess(PlayerInteractEvent event) {
|
public void onBenchAccess(PlayerInteractEvent event) {
|
||||||
if (!plugin.config.getBenchBlock() || player.getGameMode() != GameMode.CREATIVE)
|
if (!plugin.config.getBenchBlock() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||||
return;
|
return;
|
||||||
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.chest"))
|
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.CHEST))
|
||||||
return;
|
return;
|
||||||
event.getPlayer().sendMessage(L("blocked.chest"));
|
event.getPlayer().sendMessage(L("blocked.chest"));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
public void onSignAccess(PlayerInteractEvent event) {
|
public void onSignAccess(PlayerInteractEvent event) {
|
||||||
if (!plugin.config.getSignBlock() || player.getGameMode() != GameMode.CREATIVE)
|
if (!plugin.config.getSignBlock() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||||
return;
|
return;
|
||||||
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.sign"))
|
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.SIGN))
|
||||||
return;
|
return;
|
||||||
event.getPlayer().sendMessage(L("blocked.sign"));
|
event.getPlayer().sendMessage(L("blocked.sign"));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
public void onButtonAccess(PlayerInteractEvent event) {
|
public void onButtonAccess(PlayerInteractEvent event) {
|
||||||
if (!plugin.config.getButtonBlock() || player.getGameMode() != GameMode.CREATIVE)
|
if (!plugin.config.getButtonBlock() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||||
return;
|
return;
|
||||||
if (event.getClickedBlock().getState() instanceof Lever) {
|
if (event.getClickedBlock().getState() instanceof Lever) {
|
||||||
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.lever"))
|
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.LEVER))
|
||||||
return;
|
return;
|
||||||
event.getPlayer().sendMessage(L("blocked.lever"));
|
event.getPlayer().sendMessage(L("blocked.lever"));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else {
|
} else {
|
||||||
if (plugin.config.getPermissionsEnabled() && hasPermission("limitedcreative.nolimit.button"))
|
if (plugin.config.getPermissionsEnabled() && hasPermission(Perms.NoLimit.BUTTON))
|
||||||
return;
|
return;
|
||||||
event.getPlayer().sendMessage(L("blocked.button"));
|
event.getPlayer().sendMessage(L("blocked.button"));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long lastFloatingTimeWarning = 0;
|
/*
|
||||||
|
* 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());
|
||||||
|
|
||||||
public void setRegionCreativeAllowed(boolean rcreative, PlayerMoveEvent event) {
|
PlayerMoveEvent event = changearea_event.getMoveEvent();
|
||||||
GameMode DEFAULT_GAMEMODE = plugin.com.isCreative(event.getTo().getWorld()) ? GameMode.CREATIVE : GameMode.SURVIVAL;
|
GameMode CURRENT_GAMEMODE = event.getPlayer().getGameMode();
|
||||||
GameMode TEMPORARY_GAMEMODE = DEFAULT_GAMEMODE == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL;
|
GameMode DEFAULT_GAMEMODE = plugin.com.getDefaultGameMode(event.getTo().getWorld());
|
||||||
|
GameMode TEMPORARY_GAMEMODE = DEFAULT_GAMEMODE == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL; // the opposite
|
||||||
|
|
||||||
if (rcreative && player.getGameMode() == DEFAULT_GAMEMODE && !isRegionCreative()) {
|
if (rcreative && CURRENT_GAMEMODE != TEMPORARY_GAMEMODE && !this.isRegionGameMode(TEMPORARY_GAMEMODE)) {
|
||||||
setRegionCreative(true); // have to be set, before setGameMode
|
Core.debug(getName()+": entering creative area");
|
||||||
player.setGameMode(TEMPORARY_GAMEMODE);
|
// 1. the region allows "the other (temporary) gamemode"
|
||||||
} else if (!rcreative && player.getGameMode() == TEMPORARY_GAMEMODE && !isPermanentCreative()) {
|
// 2. but the player is not in that mode
|
||||||
if (getFloatingHeight() > 3) {
|
// 3. and the player is not aware of that
|
||||||
if (System.currentTimeMillis() - lastFloatingTimeWarning > 10000) {// 10 sec. limit
|
// result: change him to that mode
|
||||||
player.sendMessage(L("blocked.survival_flying"));
|
setRegionGameMode(TEMPORARY_GAMEMODE); // have to be set, before setGameMode
|
||||||
lastFloatingTimeWarning = System.currentTimeMillis();
|
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();
|
Location newloc = event.getTo().clone();
|
||||||
newloc.setX(event.getFrom().getX());
|
newloc.setX(event.getFrom().getX());
|
||||||
|
@ -351,16 +368,39 @@ public class LCPlayer {
|
||||||
newloc.setZ(event.getFrom().getZ());
|
newloc.setZ(event.getFrom().getZ());
|
||||||
event.setTo(newloc);
|
event.setTo(newloc);
|
||||||
} else {
|
} else {
|
||||||
setRegionCreative(false);
|
setRegionGameMode(null);
|
||||||
player.setGameMode(GameMode.SURVIVAL); // also unsets isRegionCreative;
|
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()) {
|
} else if (!rcreative && this.isRegionGameMode(TEMPORARY_GAMEMODE)) {
|
||||||
setRegionCreative(false); // we have left, while in optional survival
|
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() {
|
public int getFloatingHeight() {
|
||||||
Block b = player.getLocation().getBlock();
|
Block b = getPlayer().getLocation().getBlock();
|
||||||
int steps = 0;
|
int steps = 0;
|
||||||
while (b.getType() == Material.AIR) {
|
while (b.getType() == Material.AIR) {
|
||||||
steps++;
|
steps++;
|
||||||
|
@ -370,22 +410,28 @@ public class LCPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void goToFloor() {
|
public void goToFloor() {
|
||||||
Block b = player.getLocation().getBlock();
|
Block b = getPlayer().getLocation().getBlock();
|
||||||
int steps = 0;
|
int steps = 0;
|
||||||
while (b.getType() == Material.AIR) {
|
while (b.getType() == Material.AIR) {
|
||||||
steps++;
|
steps++;
|
||||||
b = b.getRelative(BlockFace.DOWN);
|
b = b.getRelative(BlockFace.DOWN);
|
||||||
}
|
}
|
||||||
if (steps > 2) {
|
if (steps > 2) {
|
||||||
player.teleport(new Location(player.getWorld(),
|
getPlayer().teleport(new Location(getPlayer().getWorld(),
|
||||||
player.getLocation().getX(),
|
getPlayer().getLocation().getX(),
|
||||||
b.getY()+1,
|
b.getY()+1,
|
||||||
player.getLocation().getZ()));
|
getPlayer().getLocation().getZ()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPermission(String permission) {
|
public boolean hasPermission(IPermission permission) {
|
||||||
return plugin.perm.hasPermission(this.getRaw(), permission);
|
return plugin.perm.hasPermission(this.getPlayer(), permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isGameModeAllowed(GameMode gm) {
|
||||||
|
if (plugin.config.getRegionOptional() && isRegionGameMode()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,10 @@ import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemStack;
|
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 class NoBlockItemSpawn {
|
||||||
public final static long TIME_OFFSET = 250;
|
public final static long TIME_OFFSET = 250;
|
||||||
|
|
||||||
|
@ -71,11 +75,11 @@ public class NoBlockItemSpawn {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void block(Block block, LCPlayer player) {
|
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());
|
block(block.getLocation(), block.getType());
|
||||||
} else {
|
} else {
|
||||||
// doesn't include silktouch
|
// 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());
|
block(block.getLocation(), i.getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
66
src/de/jaschastarke/minecraft/limitedcreative/Perms.java
Normal file
66
src/de/jaschastarke/minecraft/limitedcreative/Perms.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
82
src/de/jaschastarke/minecraft/limitedcreative/Players.java
Normal file
82
src/de/jaschastarke/minecraft/limitedcreative/Players.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,35 +42,31 @@ import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
|
||||||
import org.bukkit.material.Button;
|
import org.bukkit.material.Button;
|
||||||
import org.bukkit.material.Lever;
|
import org.bukkit.material.Lever;
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.BlackList;
|
import de.jaschastarke.minecraft.limitedcreative.BlackList;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
|
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;
|
import static de.jaschastarke.minecraft.utils.Locale.L;
|
||||||
|
|
||||||
public class LimitListener implements Listener {
|
public class LimitListener implements Listener {
|
||||||
private LimitedCreativeCore plugin;
|
private Core plugin;
|
||||||
public LimitListener(LimitedCreativeCore plugin) {
|
public LimitListener(Core plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
|
||||||
LCPlayer.get(event.getPlayer()).onRespawn(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||||
LCPlayer.get(event.getPlayer()).onDropItem(event);
|
Players.get(event.getPlayer()).onDropItem(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||||
LCPlayer.get(event.getPlayer()).onPickupItem(event);
|
Players.get(event.getPlayer()).onPickupItem(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority=EventPriority.LOWEST)
|
@EventHandler(priority=EventPriority.LOWEST)
|
||||||
|
@ -78,8 +74,8 @@ public class LimitListener implements Listener {
|
||||||
if (MainListener.isCancelled(event) || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
if (MainListener.isCancelled(event) || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LCPlayer player = LCPlayer.get(event.getPlayer());
|
LCPlayer player = Players.get(event.getPlayer());
|
||||||
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) {
|
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.USE)) {
|
||||||
if (event.getItem() != null && BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getItem())) {
|
if (event.getItem() != null && BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getItem())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.setUseItemInHand(Event.Result.DENY);
|
event.setUseItemInHand(Event.Result.DENY);
|
||||||
|
@ -109,8 +105,8 @@ public class LimitListener implements Listener {
|
||||||
if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.CREATIVE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LCPlayer player = LCPlayer.get(event.getPlayer());
|
LCPlayer player = Players.get(event.getPlayer());
|
||||||
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) {
|
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.USE)) {
|
||||||
if (event.getPlayer().getItemInHand() != null && BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getPlayer().getItemInHand())) {
|
if (event.getPlayer().getItemInHand() != null && BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getPlayer().getItemInHand())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getPlayer().sendMessage(L("blocked.use"));
|
event.getPlayer().sendMessage(L("blocked.use"));
|
||||||
|
@ -126,22 +122,28 @@ public class LimitListener implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityDamage(EntityDamageEvent meta_event) {
|
public void onEntityDamage(EntityDamageEvent event) {
|
||||||
if (meta_event.isCancelled())
|
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;
|
return;
|
||||||
if (meta_event instanceof EntityDamageByEntityEvent) {
|
Entity source = event.getDamager();
|
||||||
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) meta_event;
|
if (source instanceof Projectile)
|
||||||
|
source = ((Projectile) source).getShooter();
|
||||||
|
|
||||||
Entity source = event.getDamager();
|
if (event.getEntity() instanceof Player) {
|
||||||
if (source instanceof Projectile)
|
Players.get((Player) event.getEntity()).onDamage(source, event);
|
||||||
source = ((Projectile) source).getShooter();
|
}
|
||||||
|
if (!event.isCancelled() && source instanceof Player) {
|
||||||
if (event.getEntity() instanceof Player) {
|
Players.get((Player) source).onDealDamage(event);
|
||||||
LCPlayer.get((Player) event.getEntity()).onDamage(source, event);
|
|
||||||
}
|
|
||||||
if (!event.isCancelled() && source instanceof Player) {
|
|
||||||
LCPlayer.get((Player) source).onDealDamage(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -149,7 +151,7 @@ public class LimitListener implements Listener {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
if (event.getTarget() instanceof Player) {
|
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) {
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
if (event.getEntity() instanceof Player) {
|
if (event.getEntity() instanceof Player) {
|
||||||
Player player = (Player) event.getEntity();
|
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
|
@EventHandler
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||||
LCPlayer player = LCPlayer.get(event.getPlayer());
|
LCPlayer player = Players.get(event.getPlayer());
|
||||||
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.break")) {
|
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.BREAK)) {
|
||||||
if (BlackList.isBlackListed(plugin.config.getBlockedBreaks(), event.getBlock())) {
|
if (BlackList.isBlackListed(plugin.config.getBlockedBreaks(), event.getBlock())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getPlayer().sendMessage(L("blocked.break"));
|
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;
|
return;
|
||||||
// Prevent dropping of doors and beds when destroying the wrong part
|
// Prevent dropping of doors and beds when destroying the wrong part
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
|
@ -205,8 +211,8 @@ public class LimitListener implements Listener {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||||
LCPlayer player = LCPlayer.get(event.getPlayer());
|
LCPlayer player = Players.get(event.getPlayer());
|
||||||
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission("limitedcreative.nolimit.use")) {
|
if (!plugin.config.getPermissionsEnabled() || !player.hasPermission(Perms.NoLimit.USE)) {
|
||||||
if (BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getBlock())) {
|
if (BlackList.isBlackListed(plugin.config.getBlockedUse(), event.getBlock())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getPlayer().sendMessage(L("blocked.place"));
|
event.getPlayer().sendMessage(L("blocked.place"));
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
*/
|
*/
|
||||||
package de.jaschastarke.minecraft.limitedcreative.listeners;
|
package de.jaschastarke.minecraft.limitedcreative.listeners;
|
||||||
|
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
@ -25,13 +24,14 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
|
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||||
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
|
import de.jaschastarke.minecraft.limitedcreative.Players;
|
||||||
|
|
||||||
public class MainListener implements Listener {
|
public class MainListener implements Listener {
|
||||||
private LimitedCreativeCore plugin;
|
private Core plugin;
|
||||||
public MainListener(LimitedCreativeCore plugin) {
|
public MainListener(Core plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,20 +47,18 @@ public class MainListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
||||||
LimitedCreativeCore.debug("onPlayerGameModeChange: "+event.getPlayer().getName());
|
if (Core.isDebug()) {
|
||||||
LimitedCreativeCore.debug("Current GameMode: "+event.getPlayer().getGameMode());
|
Core.debug("onPlayerGameModeChange: "+event.getPlayer().getName());
|
||||||
LimitedCreativeCore.debug("New GameMode: "+event.getNewGameMode());
|
Core.debug("Current GameMode: "+event.getPlayer().getGameMode());
|
||||||
LimitedCreativeCore.debug("isLoggedin: "+plugin.com.isLoggedIn(event.getPlayer()));
|
Core.debug("New GameMode: "+event.getNewGameMode());
|
||||||
LimitedCreativeCore.debug("isCancelled: "+event.isCancelled());
|
Core.debug("isLoggedin: "+plugin.com.isLoggedIn(event.getPlayer()));
|
||||||
|
Core.debug("isCancelled: "+event.isCancelled());
|
||||||
|
}
|
||||||
if (!plugin.com.isLoggedIn(event.getPlayer()))
|
if (!plugin.com.isLoggedIn(event.getPlayer()))
|
||||||
return;
|
return;
|
||||||
if (event.getNewGameMode() == GameMode.CREATIVE) {
|
|
||||||
if (!LCPlayer.get(event.getPlayer()).onSetCreative())
|
if (!Players.get(event.getPlayer()).onSetGameMode(event.getNewGameMode()))
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else if (event.getNewGameMode() == GameMode.SURVIVAL) {
|
|
||||||
if (!LCPlayer.get(event.getPlayer()).onSetSurvival())
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,27 +75,8 @@ public class MainListener implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onLogout(PlayerQuitEvent event) {
|
||||||
/*
|
// what? i can't cancel a logout event? but how to chain the user to the server than? xD
|
||||||
public static class VehicleListen extends VehicleListener {
|
Players.remove(event.getPlayer().getName());
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,14 +16,15 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
|
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.utils.Util;
|
||||||
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
|
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
|
||||||
import de.jaschastarke.minecraft.worldguard.CRegionManager;
|
import de.jaschastarke.minecraft.worldguard.CRegionManager;
|
||||||
import de.jaschastarke.minecraft.worldguard.events.PlayerChangedAreaEvent;
|
import de.jaschastarke.minecraft.worldguard.events.PlayerChangedAreaEvent;
|
||||||
|
|
||||||
public class RegionListener implements Listener {
|
public class RegionListener implements Listener {
|
||||||
private static LimitedCreativeCore plugin = WorldGuardIntegration.plugin;
|
private static Core plugin = WorldGuardIntegration.plugin;
|
||||||
private CRegionManager rm;
|
private CRegionManager rm;
|
||||||
public RegionListener(WorldGuardIntegration wgi) {
|
public RegionListener(WorldGuardIntegration wgi) {
|
||||||
rm = wgi.getRegionManager();
|
rm = wgi.getRegionManager();
|
||||||
|
@ -39,14 +40,29 @@ public class RegionListener implements Listener {
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
LCPlayer player = LCPlayer.get(event.getPlayer());
|
|
||||||
ApplicableRegions set = rm.getRegionSet(event.getBlock());
|
|
||||||
|
|
||||||
if (player.isRegionCreative() && !set.allows(Flags.CREATIVE, player)) {
|
LCPlayer player = Players.get(event.getPlayer());
|
||||||
event.getPlayer().sendMessage(L("blocked.outside_creative_break"));
|
boolean diffrent_region = rm.isDiffrentRegion(event.getPlayer(), event.getBlock().getLocation());
|
||||||
event.setCancelled(true);
|
boolean creative_world = plugin.com.isCreative(event.getBlock().getWorld());
|
||||||
} else if (player.getRaw().getGameMode() != GameMode.CREATIVE && set.allows(Flags.CREATIVE)) {
|
|
||||||
plugin.spawnblock.block(event.getBlock(), player);
|
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) {
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
LCPlayer player = LCPlayer.get(event.getPlayer());
|
|
||||||
if (player.isRegionCreative() && rm.isDiffrentRegion(event.getPlayer(), event.getBlock().getLocation())) {
|
LCPlayer player = Players.get(event.getPlayer());
|
||||||
// do not build outside of creative regions, when in the region
|
boolean diffrent_region = rm.isDiffrentRegion(event.getPlayer(), event.getBlock().getLocation());
|
||||||
ApplicableRegions set = rm.getRegionSet(event.getBlock());
|
|
||||||
if (!set.allows(Flags.CREATIVE, player)) {
|
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.getPlayer().sendMessage(L("blocked.outside_creative"));
|
||||||
event.setCancelled(true);
|
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
|
@EventHandler
|
||||||
public void onPlayerChangedArea(PlayerChangedAreaEvent event) {
|
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
|
@EventHandler
|
||||||
|
@ -76,12 +100,12 @@ public class RegionListener implements Listener {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Block source = event.getBlock().getRelative(event.getDirection());
|
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 (source.getType() != Material.AIR) {
|
||||||
if (regionSet(source).allows(Flags.CREATIVE)) {
|
if (regionSet(source).allows(Flags.CREATIVE)) {
|
||||||
for (int i = 1; i <= 12; i++) {
|
for (int i = 1; i <= 12; i++) {
|
||||||
Block dest = source.getRelative(event.getDirection(), 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)) {
|
if (!regionSet(dest).allows(Flags.CREATIVE)) {
|
||||||
plugin.logger.warning(L("blocked.piston", source.getRelative(event.getDirection(), i - 1).getType().toString(), Util.toString(source.getLocation())));
|
plugin.logger.warning(L("blocked.piston", source.getRelative(event.getDirection(), i - 1).getType().toString(), Util.toString(source.getLocation())));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
@ -100,9 +124,9 @@ public class RegionListener implements Listener {
|
||||||
return;
|
return;
|
||||||
Block source = event.getBlock().getRelative(event.getDirection(), 2);
|
Block source = event.getBlock().getRelative(event.getDirection(), 2);
|
||||||
Block dest = source.getRelative(event.getDirection().getOppositeFace());
|
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) {
|
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(source).allows(Flags.CREATIVE)) {
|
||||||
if (!regionSet(dest).allows(Flags.CREATIVE)) {
|
if (!regionSet(dest).allows(Flags.CREATIVE)) {
|
||||||
plugin.logger.warning(L("blocked.piston", source.getType().toString(), Util.toString(source.getLocation())));
|
plugin.logger.warning(L("blocked.piston", source.getType().toString(), Util.toString(source.getLocation())));
|
||||||
|
|
|
@ -22,16 +22,16 @@ import java.util.List;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.protection.flags.Flag;
|
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.CRegionManager;
|
||||||
import de.jaschastarke.minecraft.worldguard.Integration;
|
import de.jaschastarke.minecraft.worldguard.Integration;
|
||||||
import de.jaschastarke.minecraft.worldguard.Interface;
|
import de.jaschastarke.minecraft.worldguard.Interface;
|
||||||
|
|
||||||
public class WorldGuardIntegration implements Integration {
|
public class WorldGuardIntegration implements Integration {
|
||||||
public static LimitedCreativeCore plugin;
|
public static Core plugin;
|
||||||
public static WorldGuardPlugin wg;
|
public static WorldGuardPlugin wg;
|
||||||
|
|
||||||
public WorldGuardIntegration(LimitedCreativeCore plugin) {
|
public WorldGuardIntegration(Core plugin) {
|
||||||
WorldGuardIntegration.plugin = plugin;
|
WorldGuardIntegration.plugin = plugin;
|
||||||
wg = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard");
|
wg = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||||
|
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,11 +15,9 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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);
|
|
||||||
}
|
}
|
|
@ -24,7 +24,7 @@ import java.util.List;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
|
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||||
|
|
||||||
public class Locale {
|
public class Locale {
|
||||||
protected YamlConfiguration lang;
|
protected YamlConfiguration lang;
|
||||||
|
@ -46,7 +46,7 @@ public class Locale {
|
||||||
|
|
||||||
String fn = getFilename(lang);
|
String fn = getFilename(lang);
|
||||||
|
|
||||||
LimitedCreativeCore.debug("Using Locale: " + lang);
|
Core.debug("Using Locale: " + lang);
|
||||||
File localefile = new File(plugin.getDataFolder(), fn);
|
File localefile = new File(plugin.getDataFolder(), fn);
|
||||||
if (localefile.exists())
|
if (localefile.exists())
|
||||||
this.lang = YamlConfiguration.loadConfiguration(localefile);
|
this.lang = YamlConfiguration.loadConfiguration(localefile);
|
||||||
|
|
|
@ -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;
|
package de.jaschastarke.minecraft.utils;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
|
import de.jaschastarke.minecraft.limitedcreative.Core;
|
||||||
import de.jaschastarke.minecraft.worldedit.PermissionsBridge;
|
import de.jaschastarke.minecraft.worldedit.PermissionsBridge;
|
||||||
|
|
||||||
public class Permissions {
|
public class Permissions {
|
||||||
|
@ -32,6 +49,10 @@ public class Permissions {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasPermission(CommandSender player, IPermission permission) {
|
||||||
|
return hasPermission(player, permission.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasPermission(CommandSender sender, String permission) {
|
public boolean hasPermission(CommandSender sender, String permission) {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
return hasPermission((Player) sender, permission);
|
return hasPermission((Player) sender, permission);
|
||||||
|
@ -42,7 +63,7 @@ public class Permissions {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void debug(CommandSender player, String permission, boolean result) {
|
private void debug(CommandSender player, String permission, boolean result) {
|
||||||
if (plugin instanceof LimitedCreativeCore && ((LimitedCreativeCore) plugin).config.getDebug())
|
if (plugin instanceof Core && ((Core) plugin).config.getDebug())
|
||||||
LimitedCreativeCore.debug("hasPermission: " + player.getName() + " - " + permission + " - " + result);
|
Core.debug("hasPermission: " + player.getName() + " - " + permission + " - " + result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
package de.jaschastarke.minecraft.worldedit;
|
||||||
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
* This Namespace may be used as a Standalone-Plugin just providing the WorldGuard-API
|
* This Namespace may be used as a Standalone-Plugin just providing the WorldGuard-API
|
||||||
* TODO: Not done yet
|
* TODO: Not done yet
|
||||||
*/
|
*/
|
||||||
|
@Deprecated // NOT READY YET
|
||||||
public class API extends JavaPlugin {
|
public class API extends JavaPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
*/
|
*/
|
||||||
package de.jaschastarke.minecraft.worldguard;
|
package de.jaschastarke.minecraft.worldguard;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
import com.sk89q.worldguard.protection.flags.Flag;
|
import com.sk89q.worldguard.protection.flags.Flag;
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.LCPlayer;
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration;
|
import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration;
|
||||||
|
|
||||||
public class ApplicableRegions {
|
public class ApplicableRegions {
|
||||||
|
@ -42,9 +43,9 @@ public class ApplicableRegions {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean allows(StateFlag flag, LCPlayer player) {
|
public boolean allows(StateFlag flag, Player player) {
|
||||||
extendRegionFlags();
|
extendRegionFlags();
|
||||||
boolean r = regions.allows(flag, WorldGuardIntegration.wg.wrapPlayer(player.getRaw()));
|
boolean r = regions.allows(flag, WorldGuardIntegration.wg.wrapPlayer(player));
|
||||||
contractRegionFlags();
|
contractRegionFlags();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -58,6 +59,13 @@ public class ApplicableRegions {
|
||||||
pr.setFlag(flag, value);
|
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")
|
@SuppressWarnings("unchecked")
|
||||||
private <T extends Flag<V>, V> void contractRegionFlags() {
|
private <T extends Flag<V>, V> void contractRegionFlags() {
|
||||||
|
@ -67,6 +75,12 @@ public class ApplicableRegions {
|
||||||
pr.setFlag(flag, null);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
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.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.protection.flags.Flag;
|
import com.sk89q.worldguard.protection.flags.Flag;
|
||||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
|
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
|
||||||
|
@ -104,18 +106,36 @@ public class CCommand implements CommandExecutor {
|
||||||
|
|
||||||
CRegion reg = rm.world(world).region(region);
|
CRegion reg = rm.world(world).region(region);
|
||||||
|
|
||||||
switch (act) {
|
try {
|
||||||
case INFO:
|
switch (act) {
|
||||||
onInfo(sender, player, reg);
|
case INFO:
|
||||||
return true;
|
onInfo(sender, player, reg);
|
||||||
case FLAG:
|
return true;
|
||||||
onFlag(sender, player, reg, args);
|
case FLAG:
|
||||||
return true;
|
onFlag(sender, player, reg, args);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (CommandException ex) { // worldedit command exception!
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + ex.getMessage());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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()};
|
String[] args = new String[]{"info", region.getWorld().getName(), region.getProtectedRegion().getId()};
|
||||||
wg.onCommand(sender, wg.getCommand("region"), "region", args);
|
wg.onCommand(sender, wg.getCommand("region"), "region", args);
|
||||||
|
|
||||||
|
@ -160,4 +180,9 @@ public class CCommand implements CommandExecutor {
|
||||||
sender.sendMessage(L("command.worldguard.flag_set", flag.getName()));
|
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;
|
||||||
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package de.jaschastarke.minecraft.worldguard;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
@ -33,34 +34,27 @@ public class CListener implements Listener {
|
||||||
this.com = com;
|
this.com = com;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority=EventPriority.HIGHEST) // run very late, because the event may be cancelled
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
|
//if (event.isCoarse()) { // next bukkit release will shortcut that
|
||||||
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|
if (event.getFrom().getBlockX() != event.getTo().getBlockX()
|
||||||
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|
||||||
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) { // he really moved, and not just looked around
|
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()) { // he really moved, and not just looked around
|
||||||
|
|
||||||
if (com.getRegionManager().isDiffrentRegion(event.getPlayer(), event.getTo())) {
|
if (com.getRegionManager().isDiffrentRegion(event.getPlayer(), event.getTo())) {
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangedAreaEvent(event));
|
String current_hash = CPlayer.get(event.getPlayer()).getHash();
|
||||||
CPlayer.get(event.getPlayer()).setHash(com.getRegionManager().getRegionsHash(event.getTo()));
|
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) {
|
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||||
if (event.isCancelled())
|
onPlayerMove(event);
|
||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
|
@ -82,6 +82,10 @@ public class CRegionManager {
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
public ProtectedRegion getGlobalRegion() {
|
||||||
|
return getWGManager(world).getRegion("__global__");
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <V> void storeFlag(CRegion region, Flag<V> flag, Object value) {
|
public <V> void storeFlag(CRegion region, Flag<V> flag, Object value) {
|
||||||
if (wc == null) {
|
if (wc == null) {
|
||||||
|
@ -136,10 +140,17 @@ public class CRegionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRegionsHash(Location loc) {
|
public String getRegionsHash(Location loc) {
|
||||||
|
StringBuilder hash = new StringBuilder(loc.getWorld().getName());
|
||||||
List<String> idlist = getWGGlobalManager().get(loc.getWorld()).getApplicableRegionsIDs(BukkitUtil.toVector(loc));
|
List<String> idlist = getWGGlobalManager().get(loc.getWorld()).getApplicableRegionsIDs(BukkitUtil.toVector(loc));
|
||||||
String[] ids = idlist.toArray(new String[idlist.size()]);
|
if (idlist.size() > 0) {
|
||||||
Arrays.sort(ids);
|
hash.append("#");
|
||||||
return Util.join(ids, "|");
|
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) {
|
public ApplicableRegions getRegionSet(Location loc) {
|
||||||
|
|
38
src/de/jaschastarke/minecraft/worldguard/Perms.java
Normal file
38
src/de/jaschastarke/minecraft/worldguard/Perms.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,17 +23,23 @@ import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
|
||||||
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
|
|
||||||
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
|
import de.jaschastarke.minecraft.worldguard.ApplicableRegions;
|
||||||
import de.jaschastarke.minecraft.worldguard.Interface;
|
import de.jaschastarke.minecraft.worldguard.Interface;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class PlayerChangedAreaEvent extends Event {
|
public class PlayerChangedAreaEvent extends Event {
|
||||||
private PlayerMoveEvent event;
|
private PlayerMoveEvent event;
|
||||||
|
private String _previous_hash;
|
||||||
|
private String _new_hash;
|
||||||
|
|
||||||
public PlayerChangedAreaEvent(PlayerMoveEvent moveevent) {
|
public PlayerChangedAreaEvent(PlayerMoveEvent moveevent) {
|
||||||
event = 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() {
|
public Player getPlayer() {
|
||||||
return event.getPlayer();
|
return event.getPlayer();
|
||||||
|
@ -50,19 +56,32 @@ public class PlayerChangedAreaEvent extends Event {
|
||||||
return Interface.getInstance().getRegionManager().getRegionSet(event.getTo());
|
return Interface.getInstance().getRegionManager().getRegionSet(event.getTo());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
public String getPreviousRegionHash() {
|
||||||
|
if (_previous_hash == null)
|
||||||
public HandlerList getHandlers() {
|
_previous_hash = Interface.getInstance().getRegionManager().getRegionsHash(event.getFrom());
|
||||||
LimitedCreativeCore.debug("getHandlers");
|
return _previous_hash;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
|
public String getNewRegionHash() {
|
||||||
public static HandlerList getHandlerList() {
|
if (_new_hash == null)
|
||||||
LimitedCreativeCore.debug("getHandlerList");
|
_new_hash = Interface.getInstance().getRegionManager().getRegionsHash(event.getTo());
|
||||||
return handlers;
|
return _new_hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerMoveEvent getMoveEvent() {
|
public PlayerMoveEvent getMoveEvent() {
|
||||||
return event;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue