localization base implementation
commands: - switch gamemode - change options permissions: - for commands - bypass limits
This commit is contained in:
parent
b7b247f92e
commit
a660fab73a
15 changed files with 639 additions and 55 deletions
48
LimitedCreative/config.yml
Normal file
48
LimitedCreative/config.yml
Normal file
|
@ -0,0 +1,48 @@
|
|||
# --------------------------------
|
||||
# Limited Creative - Configuration
|
||||
# Full Default Configuration at:
|
||||
#
|
||||
# --------------------------------
|
||||
|
||||
store:
|
||||
# StoreCreative
|
||||
# Should the creative-inventory also be stored on disk, when switching to survival?
|
||||
# If disabled, the inventory gets cleared every time on switching to creative.
|
||||
# default: true
|
||||
creative: true
|
||||
|
||||
# InventoryFolder
|
||||
# The folder inside the datadir-folder (plugin/LimitedCreative) where the inventories are saved to.
|
||||
# By default the inventories are saved to plugin/LimitedCreative/inventories.
|
||||
# default: "inventories"
|
||||
folder: "inventories"
|
||||
|
||||
limit:
|
||||
# BlockPickup
|
||||
# Prevents the pickup of items while in creative mode
|
||||
# default: true
|
||||
pickup: true
|
||||
|
||||
# BlockSign
|
||||
# Prevents interacting with signs (right-click), while in creative mode, so trading becomes more difficult.
|
||||
# Attention: this will also block useful signs, like Lifts.
|
||||
# default: true
|
||||
sign: true
|
||||
|
||||
permissions:
|
||||
# PermissionsEnabled
|
||||
# When enabled, the Permissions will allow selected users to ignore limitations like PvP, Chest-Block, etc.
|
||||
# When not enabled, all users are treated equally.
|
||||
# Note: The Permission needed for commands, are not affected by this option. So you still need the defined
|
||||
# permissions or op, to use commands, even if this options is disabled!
|
||||
# default: false
|
||||
enabled: false
|
||||
|
||||
# PermissionKeepInventory
|
||||
# Disables the limitedcreative.keepinventory-Permission, so you can use the separated-inventories-feature, even
|
||||
# if you have a permission plugin that grants ALL permission to you.
|
||||
# If Enabled, only players WITHOUT the limitedcreative.keepinventory-Permission, have separated inventories;
|
||||
# Players with the permission will have the inventory, like this plugin were not installed.
|
||||
# When "PermissionsEnabled" is false, the KeepInventory-Option will act like disabled, even if you set it to true.
|
||||
# default: false
|
||||
keepinventory: false
|
23
LimitedCreative/lang/default.yml
Normal file
23
LimitedCreative/lang/default.yml
Normal file
|
@ -0,0 +1,23 @@
|
|||
command:
|
||||
player: player
|
||||
switch:
|
||||
survival: Changes the game mode of a player to survival
|
||||
creative: Changes the game mode of a player to creative
|
||||
condif:
|
||||
overview: storecreative|blockpickup|blocksign|permissions|perm_keepinventory
|
||||
gamemode:
|
||||
changed: "{0}'s game mode has been changed"
|
||||
option:
|
||||
done: Option changed.
|
||||
exception:
|
||||
command:
|
||||
lackingpermission: You do not have access to this command
|
||||
toomuchparameter: Too much arguments given
|
||||
missingparameter: Not enough arguments given
|
||||
playernotfound: Player not found
|
||||
invalidoption: Unknown option
|
||||
config:
|
||||
savefail: Failed to write modified configuration to disk
|
||||
blocked:
|
||||
chest: Access to chests is not allowed in creative mode
|
||||
sign: To interact with signs is not allowed in creative mode
|
|
@ -2,8 +2,39 @@ name: LimitedCreative
|
|||
main: de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore
|
||||
version: 0.1-beta
|
||||
softdepend: [WorldGuard]
|
||||
#commands:
|
||||
# limitedcreative:
|
||||
# description: Manually control the Creative-Features
|
||||
# aliases: lc
|
||||
# usage: /<command> load
|
||||
commands:
|
||||
limitedcreative:
|
||||
description: Main LimitedCreative-Controlling-Commands
|
||||
aliases: lc
|
||||
usage: /<command> - displays LimitedCreative-Help
|
||||
permissions:
|
||||
limitedcreative.config:
|
||||
description: Allows enabling/disabling of config options ingame
|
||||
default: op
|
||||
limitedcreative.switch_gamemode:
|
||||
description: Allows switching of own game mode to creative and back
|
||||
default: op
|
||||
limitedcreative.switch_gamemode.backonly:
|
||||
description: Allows switching of own game mode to survival, but not to creative
|
||||
default: true
|
||||
limitedcreative.switch_gamemode.other:
|
||||
description: Allows switching of other users game mode
|
||||
default: op
|
||||
limitedcreative.keepinventory:
|
||||
description: Allows bypassing the inventory separation (if PermissionKeepInventory is enabled in config)
|
||||
default: false
|
||||
limitedcreative.nolimit.drop:
|
||||
description: Allows bypassing the "do not drop anything"-limitation
|
||||
default: false
|
||||
limitedcreative.nolimit.pickup:
|
||||
description: Allows bypassing the "do not pickup anything"-limitation
|
||||
default: false
|
||||
limitedcreative.nolimit.chest:
|
||||
description: Allows bypassing the "do not open a chest"-limitation
|
||||
default: false
|
||||
limitedcreative.nolimit.sign:
|
||||
description: Allows bypassing the "do not interact with signs"-limitation
|
||||
default: false
|
||||
limitedcreative.nolimit.pvp:
|
||||
description: Allows bypassing the "no pvp"-limitation
|
||||
default: false
|
|
@ -1,45 +1,196 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2011 Essentials Team
|
||||
*
|
||||
* 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 org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
//import org.bukkit.plugin.PluginManager;
|
||||
import static de.jaschastarke.minecraft.utils.Locale.L;
|
||||
|
||||
public class Commands {
|
||||
private static LimitedCreativeCore plugin;
|
||||
//private static PluginManager pm;
|
||||
|
||||
public static class MainCommandExecutor implements CommandExecutor {
|
||||
|
||||
public enum Action {
|
||||
C, CREATIVE,
|
||||
S, SURVIVAL,
|
||||
E, ENABLE,
|
||||
D, DISABLE,
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
Player player = null;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
} else {
|
||||
sender.sendMessage("Console-Commands not supported");
|
||||
if (args.length > 0) {
|
||||
Action act = null;
|
||||
try {
|
||||
act = Action.valueOf(args[0].toUpperCase());
|
||||
} catch (IllegalArgumentException e) {}
|
||||
if (act != null) {
|
||||
try {
|
||||
switch (act) {
|
||||
case C:
|
||||
case CREATIVE:
|
||||
this.setGameMode(GameMode.CREATIVE, sender, args);
|
||||
return true;
|
||||
case S:
|
||||
case SURVIVAL:
|
||||
this.setGameMode(GameMode.SURVIVAL, sender, args);
|
||||
return true;
|
||||
case E:
|
||||
case ENABLE:
|
||||
this.setOption(sender, args, true);
|
||||
return true;
|
||||
case D:
|
||||
case DISABLE:
|
||||
this.setOption(sender, args, false);
|
||||
return true;
|
||||
}
|
||||
} catch (CommandException e) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + e.getLocalizedMessage());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length >= 1 && args[0].equalsIgnoreCase("load")) {
|
||||
if (args.length == 1 || args[1].equalsIgnoreCase("survival") || args[1] == "0") {
|
||||
new Inventory(player).load(GameMode.SURVIVAL);
|
||||
String c = label;
|
||||
String message = "";
|
||||
if (sender.hasPermission("limitedcreative.switch_gamemode") || sender.hasPermission("limitedcreative.switch_gamemode.backonly"))
|
||||
message += "/"+c+" s[urvival] ["+L("command.player")+"] - "+L("command.switch.survival")+"\n";
|
||||
if (sender.hasPermission("limitedcreative.switch_gamemode"))
|
||||
message += "/"+c+" c[reative] ["+L("command.player")+"] - "+L("command.switch.creative")+"\n";
|
||||
if (sender.hasPermission("limitedcreative.config"))
|
||||
message += "/"+c+" e[nable] "+L("command.config.overview")+"\n";
|
||||
if (sender.hasPermission("limitedcreative.config"))
|
||||
message += "/"+c+" d[isable] "+L("command.config.overview")+"\n";
|
||||
if (message.length() > 0) {
|
||||
sender.sendMessage("Usage:");
|
||||
for (String m : message.split("\n")) {
|
||||
sender.sendMessage(m);
|
||||
}
|
||||
return true;
|
||||
}/* else if (args.length == 2 && (args[1].equalsIgnoreCase("creative") || args[1] == "1")) {
|
||||
new Inventory(player).load(GameMode.CREATIVE);
|
||||
return true;
|
||||
}*/
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public enum Option {
|
||||
STORECREATIVE,
|
||||
BLOCKPICKUP,
|
||||
BLOCKSIGN,
|
||||
PERMISSIONS,
|
||||
PERM_KEEPINVENTORY,
|
||||
};
|
||||
|
||||
private void setOption(CommandSender sender, String[] args, boolean b) throws CommandException {
|
||||
if (sender instanceof Player && !sender.hasPermission("limitedcreative.config") && !sender.isOp()) {
|
||||
throw new LackingPermissionException();
|
||||
}
|
||||
if (args.length > 2)
|
||||
throw new InvalidCommandException("exception.command.tomuchparameter");
|
||||
if (args.length < 2)
|
||||
throw new InvalidCommandException("exception.command.missingparameter");
|
||||
|
||||
Option opt = null;
|
||||
try {
|
||||
opt = Option.valueOf(args[1].toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new InvalidCommandException("exception.command.invalidoption");
|
||||
}
|
||||
|
||||
switch (opt) {
|
||||
case STORECREATIVE:
|
||||
plugin.config.setStoreCreative(b);
|
||||
break;
|
||||
case BLOCKPICKUP:
|
||||
plugin.config.setBlockPickupInCreative(b);
|
||||
break;
|
||||
case BLOCKSIGN:
|
||||
plugin.config.setSignBlock(b);
|
||||
break;
|
||||
case PERMISSIONS:
|
||||
plugin.config.setPermissionsEnabled(b);
|
||||
break;
|
||||
case PERM_KEEPINVENTORY:
|
||||
plugin.config.setPermissionToKeepInventory(b);
|
||||
break;
|
||||
}
|
||||
sender.sendMessage(L("command.option.done"));
|
||||
}
|
||||
|
||||
private void setGameMode(GameMode gm, CommandSender sender, String[] args) throws CommandException {
|
||||
Player target = null;
|
||||
if (args.length > 2)
|
||||
throw new InvalidCommandException("exception.command.tomuchparameter");
|
||||
if (args.length == 2)
|
||||
target = plugin.getServer().getPlayer(args[1]);
|
||||
else if (sender instanceof Player)
|
||||
target = (Player) sender;
|
||||
|
||||
if (sender instanceof Player && !sender.isOp()) {
|
||||
if (!sender.hasPermission("limitedcreative.switch_gamemode")) {
|
||||
if (gm != GameMode.SURVIVAL || !sender.hasPermission("limitedcreative.switch_gamemode.backonly")) {
|
||||
throw new LackingPermissionException();
|
||||
}
|
||||
}
|
||||
if (sender != target && !sender.hasPermission("limitedcreative.switch_gamemode.other")) {
|
||||
throw new LackingPermissionException();
|
||||
}
|
||||
}
|
||||
if (target == null) {
|
||||
throw new InvalidCommandException("exception.command.playernotfound");
|
||||
}
|
||||
if (target.getGameMode() != gm) {
|
||||
target.setGameMode(gm);
|
||||
if (target != sender) {
|
||||
sender.sendMessage(L("commands.gamemode.changed", target.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void register(LimitedCreativeCore pplugin) {
|
||||
plugin = pplugin;
|
||||
//pm = plugin.getServer().getPluginManager();
|
||||
|
||||
plugin.getCommand("limitedcreative").setExecutor(new MainCommandExecutor());
|
||||
}
|
||||
|
||||
abstract static public class CommandException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CommandException(String s) {super(s);}
|
||||
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
return L(super.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
public static class InvalidCommandException extends CommandException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InvalidCommandException(String s) {super(s);}
|
||||
}
|
||||
public static class LackingPermissionException extends CommandException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public LackingPermissionException() {super("exception.command.lackingpermission");}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,102 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2011 Essentials Team
|
||||
*
|
||||
* 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.io.File;
|
||||
//import java.io.IOException;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class Configuration {
|
||||
public Configuration(FileConfiguration cfg) {
|
||||
import static de.jaschastarke.minecraft.utils.Util.copyFile;
|
||||
//import static de.jaschastarke.minecraft.utils.Locale.L;
|
||||
|
||||
public class Configuration {
|
||||
private FileConfiguration c;
|
||||
private File file;
|
||||
public static LimitedCreativeCore plugin;
|
||||
|
||||
public Configuration(LimitedCreativeCore pplugin) {
|
||||
plugin = pplugin;
|
||||
|
||||
file = new File(plugin.getDataFolder(), "config.yml");
|
||||
if (!file.exists())
|
||||
//plugin.saveDefaultConfig();
|
||||
copyFile(plugin.getResource("config.yml"), file);
|
||||
|
||||
c = plugin.getConfig();
|
||||
}
|
||||
public boolean getStoreCreative() {
|
||||
return true;
|
||||
}
|
||||
public boolean getDropInCreative() {
|
||||
return false;
|
||||
return c.getBoolean("store.creative", true);
|
||||
}
|
||||
public String getInventoryFolder() {
|
||||
return "inventories";
|
||||
return c.getString("store.folder", "inventories");
|
||||
}
|
||||
public boolean getBlockPickupInCreative() {
|
||||
return c.getBoolean("limit.pickup", true);
|
||||
}
|
||||
public boolean getSignBlock() {
|
||||
return true;
|
||||
return c.getBoolean("limit.sign", true);
|
||||
}
|
||||
public boolean getPermissionsEnabled() {
|
||||
return c.getBoolean("permissions.enabled", false);
|
||||
}
|
||||
public boolean getPermissionToKeepInventory() {
|
||||
return this.getPermissionsEnabled() && c.getBoolean("permissions.keepinventory", false);
|
||||
}
|
||||
|
||||
public void setStoreCreative(boolean value) {
|
||||
this.reload();
|
||||
c.set("store.creative", value);
|
||||
this.save();
|
||||
}
|
||||
public void setBlockPickupInCreative(boolean value) {
|
||||
this.reload();
|
||||
c.set("limit.pickup", value);
|
||||
this.save();
|
||||
}
|
||||
public void setSignBlock(boolean value) {
|
||||
this.reload();
|
||||
c.set("limit.sign", value);
|
||||
this.save();
|
||||
}
|
||||
public void setPermissionsEnabled(boolean value) {
|
||||
this.reload();
|
||||
c.set("permissions.enabled", value);
|
||||
this.save();
|
||||
}
|
||||
public void setPermissionToKeepInventory(boolean value) {
|
||||
this.reload();
|
||||
if (value == true)
|
||||
this.setPermissionsEnabled(true);
|
||||
c.set("permissions.keepinventory", value);
|
||||
this.save();
|
||||
}
|
||||
protected void reload() {
|
||||
plugin.reloadConfig();
|
||||
c = plugin.getConfig();
|
||||
}
|
||||
protected void save() {
|
||||
plugin.saveConfig();
|
||||
/*try {
|
||||
c.save(file);
|
||||
} catch (IOException e) {
|
||||
plugin.logger.severe(L("exception.config.savefail"));
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2011 Essentials Team
|
||||
*
|
||||
* 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.io.File;
|
||||
|
|
|
@ -1,9 +1,29 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2011 Essentials Team
|
||||
*
|
||||
* 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.logging.Logger;
|
||||
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import static de.jaschastarke.minecraft.utils.Util.versionCompare;
|
||||
import de.jaschastarke.minecraft.utils.Locale;
|
||||
|
||||
|
||||
public class LimitedCreativeCore extends JavaPlugin {
|
||||
public final Logger logger = Logger.getLogger("Minecraft");
|
||||
|
@ -15,18 +35,21 @@ public class LimitedCreativeCore extends JavaPlugin {
|
|||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
Locale.unload();
|
||||
logger.info("["+this.getDescription().getName()+"] cleanly unloaded.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
|
||||
config = new Configuration(this);
|
||||
serializeFallBack = versionCompare(getServer().getBukkitVersion().replaceAll("-.*$", ""), "1.1") < 0;
|
||||
|
||||
config = new Configuration(this.getConfig());
|
||||
new Locale(this);
|
||||
|
||||
Listener.register(this);
|
||||
//Commands.register(this);
|
||||
Commands.register(this);
|
||||
|
||||
try {
|
||||
Class.forName("com.sk89q.worldguard.bukkit.WorldGuardPlugin", false, null);
|
||||
worldguard = new WorldGuardIntegration(this);
|
||||
|
@ -36,18 +59,4 @@ public class LimitedCreativeCore extends JavaPlugin {
|
|||
PluginDescriptionFile df = this.getDescription();
|
||||
logger.info("["+df.getName() + " v" + df.getVersion() + "] done loading.");
|
||||
}
|
||||
|
||||
public static int versionCompare(String vers1, String vers2) {
|
||||
String[] v1 = vers1.split("\\.");
|
||||
String[] v2 = vers2.split("\\.");
|
||||
int i = 0;
|
||||
while (i < v1.length && i < v2.length && v1[i].equals(v2[i])) {
|
||||
i++;
|
||||
}
|
||||
if (i < v1.length && i < v2.length) {
|
||||
int diff = new Integer(v1[i]).compareTo(new Integer(v2[i]));
|
||||
return diff < 0 ? -1 : (diff == 0 ? 0 : 1);
|
||||
}
|
||||
return v1.length < v2.length ? -1 : (v1.length == v2.length ? 0 : 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2011 Essentials Team
|
||||
*
|
||||
* 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 org.bukkit.GameMode;
|
||||
|
@ -20,6 +37,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import static de.jaschastarke.minecraft.utils.Locale.L;
|
||||
|
||||
public final class Listener {
|
||||
private static LimitedCreativeCore plugin;
|
||||
|
@ -38,14 +56,18 @@ public final class Listener {
|
|||
|
||||
@Override
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE && !plugin.config.getDropInCreative()) {
|
||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
|
||||
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.drop"))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE && !plugin.config.getDropInCreative()) {
|
||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE && plugin.config.getBlockPickupInCreative()) {
|
||||
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.pickup"))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -61,11 +83,15 @@ public final class Listener {
|
|||
Block block = event.getClickedBlock();
|
||||
|
||||
if (block.getState() instanceof ContainerBlock) {
|
||||
event.getPlayer().sendMessage("Access to chests is not allowed in creative mode");
|
||||
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.chest"))
|
||||
return;
|
||||
event.getPlayer().sendMessage(L("blocked.chest"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (plugin.config.getSignBlock() && block.getState() instanceof Sign) {
|
||||
event.getPlayer().sendMessage("To interact with signs is not allowed in creative mode");
|
||||
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.sign"))
|
||||
return;
|
||||
event.getPlayer().sendMessage(L("blocked.sign"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +104,9 @@ public final class Listener {
|
|||
Entity entity = event.getRightClicked();
|
||||
|
||||
if (entity instanceof StorageMinecart) {
|
||||
event.getPlayer().sendMessage("Access to chests is not allowed in creative mode");
|
||||
if (plugin.config.getPermissionsEnabled() && event.getPlayer().hasPermission("limitedcreative.nolimit.chest"))
|
||||
return;
|
||||
event.getPlayer().sendMessage(L("blocked.chest"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -99,11 +127,19 @@ public final class Listener {
|
|||
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) meta_event;
|
||||
if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
|
||||
// its PVP
|
||||
if (((Player) event.getEntity()).getGameMode() == GameMode.CREATIVE ||
|
||||
((Player) event.getDamager()).getGameMode() == GameMode.CREATIVE) { // one of them is creative
|
||||
Player attacker = (Player) event.getDamager();
|
||||
Player attacked = (Player) event.getEntity();
|
||||
if (attacker.getGameMode() == GameMode.CREATIVE) {
|
||||
if (!plugin.config.getPermissionsEnabled() || !attacker.hasPermission("limitedcreative.nolimit.pvp")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (attacked.getGameMode() == GameMode.CREATIVE) {
|
||||
if (!plugin.config.getPermissionsEnabled() || !attacked.hasPermission("limitedcreative.nolimit.pvp")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2011 Essentials Team
|
||||
*
|
||||
* 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 org.bukkit.GameMode;
|
||||
|
@ -13,6 +30,8 @@ public class PlayerCore {
|
|||
}
|
||||
|
||||
public void onSetCreative() {
|
||||
if (plugin.config.getPermissionToKeepInventory() && player.hasPermission("limitedcreative.keepinventory"))
|
||||
return;
|
||||
Inventory inv = new Inventory(player);
|
||||
inv.save();
|
||||
if (plugin.config.getStoreCreative() && inv.isStored(GameMode.CREATIVE)) {
|
||||
|
@ -22,6 +41,8 @@ public class PlayerCore {
|
|||
}
|
||||
}
|
||||
public void onSetSurvival() {
|
||||
if (plugin.config.getPermissionToKeepInventory() && player.hasPermission("limitedcreative.keepinventory"))
|
||||
return;
|
||||
Inventory inv = new Inventory(player);
|
||||
if (plugin.config.getStoreCreative()) {
|
||||
inv.save();
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2011 Essentials Team
|
||||
*
|
||||
* 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 com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2011 Essentials Team
|
||||
*
|
||||
* 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;
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2011 Essentials Team
|
||||
*
|
||||
* 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.Map;
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2011 Essentials Team
|
||||
*
|
||||
* 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;
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Limited Creative - (Bukkit Plugin)
|
||||
* Copyright (C) 2011 Essentials Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jaschastarke.minecraft.utils;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Locale {
|
||||
protected YamlConfiguration lang;
|
||||
private static Locale inst = null;
|
||||
|
||||
public Locale(JavaPlugin plugin) {
|
||||
lang = YamlConfiguration.loadConfiguration(plugin.getResource("lang/default.yml"));
|
||||
inst = this;
|
||||
}
|
||||
public String get(String msg) {
|
||||
if (lang.contains(msg))
|
||||
return lang.getString(msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static String L(String msg, Object... objects) {
|
||||
if (inst != null)
|
||||
msg = inst.get(msg);
|
||||
if (objects.length > 0)
|
||||
return MessageFormat.format(msg, objects);
|
||||
else
|
||||
return msg;
|
||||
}
|
||||
public static void unload() {
|
||||
inst = null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package de.jaschastarke.minecraft.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
final public class Util {
|
||||
public static int versionCompare(String vers1, String vers2) {
|
||||
String[] v1 = vers1.split("\\.");
|
||||
String[] v2 = vers2.split("\\.");
|
||||
int i = 0;
|
||||
while (i < v1.length && i < v2.length && v1[i].equals(v2[i])) {
|
||||
i++;
|
||||
}
|
||||
if (i < v1.length && i < v2.length) {
|
||||
int diff = new Integer(v1[i]).compareTo(new Integer(v2[i]));
|
||||
return diff < 0 ? -1 : (diff == 0 ? 0 : 1);
|
||||
}
|
||||
return v1.length < v2.length ? -1 : (v1.length == v2.length ? 0 : 1);
|
||||
}
|
||||
|
||||
public static void copyFile(InputStream is, File to) {
|
||||
try {
|
||||
OutputStream os;
|
||||
os = new FileOutputStream(to);
|
||||
byte[] buffer = new byte[512];
|
||||
int length;
|
||||
while ((length = is.read(buffer)) > 0) {
|
||||
os.write(buffer, 0, length);
|
||||
}
|
||||
os.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static void copyFile(File from, File to) {
|
||||
try {
|
||||
copyFile(new FileInputStream(from), to);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue