Working commands

This commit is contained in:
Jascha Starke 2013-01-22 18:38:48 +01:00
parent 771d2a01f9
commit de57c93844
12 changed files with 301 additions and 56 deletions

View file

@ -4,11 +4,13 @@ basic.loaded.module: Module loaded.
basic.feature.store: separated inventories
basic.feature.limit: creative restrictions
basic.feature.region: creative regions
basic.feature.gamemodecommands: GameMode Commands
basic.conflict: Due to conflict with the plugin {0}, the feature {1} is disabled
basic.warning.worldguard_not_found: WorldGuard isn't found, the feature {0} is disabled
# double single-quote '' because of MessageFormater to insert {0}
command.player: player
command.general: LimitedCreative: GameMode-Switch, Creative-Regions, Config and more
command.switch.survival: Changes the game mode of a player to survival
command.switch.creative: Changes the game mode of a player to creative
command.switch.adventure: Changes the game mode of a player to adventure

18
pom.xml
View file

@ -102,7 +102,7 @@
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<!-- <resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/</directory>
@ -111,19 +111,19 @@
<include>config.yml</include>
<include>META-INF/descriptions.jos</include>
</includes>
</resource>
</resource>-->
<resource>
<targetPath>lang/</targetPath>
<directory>${basedir}/lang/</directory>
</resource>
<resource>
<!-- <resource>
<targetPath>META-INF/</targetPath>
<filtering>true</filtering>
<directory>${project.build.directory}/generated-sources/annotations/META-INF/</directory>
<includes>
<include>descriptions.jos</include>
</includes>
</resource>
</resource> -->
</resources>
<plugins>
@ -157,14 +157,22 @@
<param>WorldGuard</param>
<param>WorldEdit</param>
<param>MultiInv</param>
<param>xAuth</param>
<param>AuthMe</param>
<param>MultiInv</param>
<param>Multiverse-Inventories</param>
</softdepend>
<custom>
<dev-url>http://dev.bukkit.org/server-mods/limited-creative/</dev-url>
</custom>
<registeredPermissions>
<param>de.jaschastarke.minecraft.limitedcreative.Permissions</param>
<param>de.jaschastarke.minecraft.limitedcreative.Permissions:CONTAINER</param>
<param>de.jaschastarke.minecraft.limitedcreative.inventories.InventoryPermissions</param>
<param>de.jaschastarke.minecraft.limitedcreative.SwitchGameModePermissions:ALL</param>
</registeredPermissions>
<registeredCommands>
<param>de.jaschastarke.minecraft.limitedcreative.MainCommand</param>
</registeredCommands>
</configuration>
</execution>
</executions>

View file

@ -0,0 +1,113 @@
package de.jaschastarke.minecraft.limitedcreative;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import de.jaschastarke.IHasName;
import de.jaschastarke.bukkit.lib.CoreModule;
import de.jaschastarke.bukkit.lib.commands.AbstractCommandList;
import de.jaschastarke.bukkit.lib.commands.CommandContext;
import de.jaschastarke.bukkit.lib.commands.CommandException;
import de.jaschastarke.bukkit.lib.commands.ICommand;
import de.jaschastarke.bukkit.lib.commands.MethodCommand;
import de.jaschastarke.bukkit.lib.commands.IMethodCommandContainer;
import de.jaschastarke.bukkit.lib.commands.MissingPermissionCommandException;
import de.jaschastarke.bukkit.lib.commands.NeedsPlayerCommandException;
import de.jaschastarke.bukkit.lib.commands.annotations.Alias;
import de.jaschastarke.bukkit.lib.commands.annotations.Description;
import de.jaschastarke.bukkit.lib.commands.annotations.IsCommand;
import de.jaschastarke.bukkit.lib.commands.annotations.NeedsPermission;
import de.jaschastarke.bukkit.lib.commands.annotations.Usage;
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
import de.jaschastarke.minecraft.lib.permissions.IPermission;
public class FeatureSwitchGameMode extends CoreModule<LimitedCreative> {
public FeatureSwitchGameMode(LimitedCreative plugin) {
super(plugin);
}
protected Commands commands = null;
@Override
public String getName() {
return "SwitchGameMode";
}
@Override
public void OnEnable() {
if (commands == null)
commands = new Commands();
plugin.getMainCommand().getHandler().registerCommands(commands.getCommandList());
}
@Override
public void OnDisable() {
if (commands != null)
plugin.getMainCommand().getHandler().removeCommands(commands.getCommandList());
}
public class Commands extends AbstractCommandList implements IMethodCommandContainer, IHasName {
private List<ICommand> commands = MethodCommand.getMethodCommandsFor(this);
public List<ICommand> getCommandList() {
return commands;
}
@Override
public String getName() {
return plugin.getName() + " - " + plugin.getLang().trans("basic.feature.gamemodecommands");
}
@Override
public IPermission getPermission(String subPerm) {
return SwitchGameModePermissions.ALL.getPermission(subPerm);
}
protected boolean changeGameMode(CommandContext context, String player, GameMode tgm, IAbstractPermission permission) throws MissingPermissionCommandException, CommandException {
Player target = null;
if (player != null && !player.isEmpty())
target = Bukkit.getPlayer(player);
else if (context.isPlayer())
target = context.getPlayer();
if (target == null)
throw new NeedsPlayerCommandException();
if (!target.equals(context.getSender()) && !context.checkPermission(SwitchGameModePermissions.OTHER))
throw new MissingPermissionCommandException(SwitchGameModePermissions.OTHER);
GameMode wgm = Hooks.DefaultWorldGameMode.get(target.getWorld());
if (context.checkPermission(permission) || (wgm == tgm && context.checkPermission(SwitchGameModePermissions.BACKONLY)))
throw new MissingPermissionCommandException(permission);
target.setGameMode(tgm);
return true;
}
@IsCommand("survival")
@Alias("s")
@Description(value = "command.switch.survival", translate = true)
@NeedsPermission(value={"survival", "backonly"}, optional = true)
@Usage("[player]")
public boolean survival(CommandContext context, String player) throws MissingPermissionCommandException, CommandException {
return changeGameMode(context, player, GameMode.SURVIVAL, SwitchGameModePermissions.SURVIVAL);
}
@IsCommand("creative")
@Alias("c")
@Description(value = "command.switch.creative", translate = true)
@NeedsPermission(value={"creative", "backonly"}, optional = true)
@Usage("[player]")
public boolean creative(CommandContext context, String player) throws MissingPermissionCommandException, CommandException {
return changeGameMode(context, player, GameMode.CREATIVE, SwitchGameModePermissions.CREATIVE);
}
@IsCommand("adventure")
@Alias("a")
@Description(value = "command.switch.adventure", translate = true)
@NeedsPermission(value={"adventure", "backonly"}, optional = true)
@Usage("[player]")
public boolean adventure(CommandContext context, String player) throws MissingPermissionCommandException, CommandException {
return changeGameMode(context, player, GameMode.ADVENTURE, SwitchGameModePermissions.ADVENTURE);
}
}
}

View file

@ -5,8 +5,8 @@ import de.jaschastarke.bukkit.lib.Core;
import de.jaschastarke.bukkit.lib.PluginLang;
public class LimitedCreative extends Core {
private i18n lang;
protected Config config = null;
protected MainCommand command = null;
@Override
public void OnInitialize() {
@ -14,16 +14,20 @@ public class LimitedCreative extends Core {
config = new Config(this);
this.debug = config.getDebug();
lang = new PluginLang("lang/messages", this);
setLang(new PluginLang("lang/messages", this));
command = new MainCommand(this);
commands.registerCommand(command);
Hooks.inizializeHooks(this);
addModule(new FeatureSwitchGameMode(this));
addModule(new ModInventories(this));
addModule(new ModCreativeLimits(this));
addModule(new ModRegions(this));
addModule(new ModCmdBlocker(this));
config.save();
config.saveDefault();
}
public Config getPluginConfig() {
@ -32,9 +36,13 @@ public class LimitedCreative extends Core {
@Deprecated
public String L(String msg, Object... objects) {
return lang.trans(msg, objects);
return getLang().trans(msg, objects);
}
public i18n getLocale() {
return lang;
return getLang();
}
public MainCommand getMainCommand() {
return command;
}
}

View file

@ -0,0 +1,54 @@
package de.jaschastarke.minecraft.limitedcreative;
import de.jaschastarke.LocaleString;
import de.jaschastarke.bukkit.lib.commands.BukkitCommand;
import de.jaschastarke.bukkit.lib.commands.IHelpDescribed;
import de.jaschastarke.maven.ArchiveDocComments;
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
/**
* LimitedCreative: GameMode-Switch, Creative-Regions, Config and more
* @usage /<command> - displays LimitedCreative-Help
* @permission limitedcreative.command
*/
@ArchiveDocComments
public class MainCommand extends BukkitCommand implements IHelpDescribed {
private LimitedCreative plugin;
public MainCommand() {
}
public MainCommand(LimitedCreative plugin) {
this.plugin = plugin;
}
@Override
public String getName() {
return "limitedcreative";
}
@Override
public String[] getAliases() {
return new String[]{"lc"};
}
/**
* @internal has no effect, as not tested by any command handler
* @see IHelpDescribed
*/
@Override
public IAbstractPermission[] getRequiredPermissions() {
return new IAbstractPermission[]{Permissions.COMMAND};
}
@Override
public String getUsage() {
return "<subcommand>";
}
@Override
public CharSequence getDescription() {
return new LocaleString("command.general");
}
@Override
public String getPackageName() {
return plugin.getName();
}
}

View file

@ -7,10 +7,8 @@ import java.util.WeakHashMap;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import de.jaschastarke.bukkit.lib.CoreModule;
import de.jaschastarke.bukkit.lib.permissions.PermissionManager;
import de.jaschastarke.minecraft.limitedcreative.inventories.ArmoryConfig;
import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory;
import de.jaschastarke.minecraft.limitedcreative.inventories.InventoryConfig;
@ -73,7 +71,7 @@ public class ModInventories extends CoreModule<LimitedCreative> {
}
public void onSetGameMode(Player player, GameMode gm) {
if (PermissionManager.hasPermission(player, InventoryPermissions.KEEP_INVENTORY))
if (plugin.getPermManager().hasPermission(player, InventoryPermissions.KEEP_INVENTORY))
return;
player.closeInventory();
@ -107,17 +105,17 @@ public class ModInventories extends CoreModule<LimitedCreative> {
}
public void setCreativeArmor(Player player) {
Map<String, MaterialData> armor = armor_config.getCreativeArmor();
Map<String, ItemStack> armor = armor_config.getCreativeArmor();
if (armor != null) {
ItemStack[] is = new ItemStack[4];
if (armor.containsKey("feet"))
is[0] = armor.get("feet").toItemStack(1);
is[0] = armor.get("feet");
if (armor.containsKey("legs"))
is[1] = armor.get("legs").toItemStack(1);
is[1] = armor.get("legs");
if (armor.containsKey("chest"))
is[2] = armor.get("chest").toItemStack(1);
is[2] = armor.get("chest");
if (armor.containsKey("head"))
is[3] = armor.get("head").toItemStack(1);
is[3] = armor.get("head");
player.getInventory().setArmorContents(is);
}
}

View file

@ -19,26 +19,26 @@ package de.jaschastarke.minecraft.limitedcreative;
import org.bukkit.permissions.PermissionDefault;
import de.jaschastarke.Singleton;
import de.jaschastarke.maven.ArchiveDocComments;
import de.jaschastarke.minecraft.lib.permissions.BasicPermission;
import de.jaschastarke.minecraft.lib.permissions.IPermission;
import de.jaschastarke.minecraft.lib.permissions.SimplePermissionContainer;
import de.jaschastarke.minecraft.lib.permissions.SimplePermissionContainerNode;
@ArchiveDocComments
public class Permissions extends SimplePermissionContainer implements Singleton {
private static Permissions instance = new Permissions();
public static Permissions getInstance() {
return instance;
public class Permissions extends SimplePermissionContainerNode {
protected Permissions(String name) {
super(name);
}
public final static Permissions CONTAINER = new Permissions("limitedcreative");
/**
* Allows changing plugin configuration ingame via commands
*/
public static final IPermission CONFIG = new BasicPermission(instance, "config", PermissionDefault.OP);
@Override
public String getFullString() {
return "limitedcreative";
}
public static final IPermission CONFIG = new BasicPermission(CONTAINER, "config", PermissionDefault.OP);
/**
* Gives player access to the general /limitedcreative command. This permission doesn't affect the usability, but
* allows to hide the command from /help for users.
*/
public static final IPermission COMMAND = new BasicPermission(CONTAINER, "command", PermissionDefault.OP);
}

View file

@ -0,0 +1,52 @@
package de.jaschastarke.minecraft.limitedcreative;
import org.bukkit.permissions.PermissionDefault;
import de.jaschastarke.maven.ArchiveDocComments;
import de.jaschastarke.minecraft.lib.permissions.BasicPermission;
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
import de.jaschastarke.minecraft.lib.permissions.IsChildPermission;
import de.jaschastarke.minecraft.lib.permissions.ParentPermissionContainerNode;
@ArchiveDocComments
public class SwitchGameModePermissions extends ParentPermissionContainerNode {
/**
* Allows switching of own game mode to creative/adventure and back
*/
public final static SwitchGameModePermissions ALL = new SwitchGameModePermissions(Permissions.CONTAINER, "switch_gamemode");
protected SwitchGameModePermissions(IAbstractPermission parent, String name) {
super(parent, name);
}
@Override
public PermissionDefault getDefault() {
return PermissionDefault.OP;
}
/**
* Allows switching of own game mode to default of the not world he is in, but not to an other
*/
public final static BasicPermission BACKONLY = new BasicPermission(ALL, "backonly", PermissionDefault.FALSE);
/**
* Allows switching of own game mode to survival, but not to creative/adventure
*/
@IsChildPermission
public final static BasicPermission SURVIVAL = new BasicPermission(ALL, "survival", PermissionDefault.FALSE);
/**
* Allows switching of own game mode to creative, but not to survival/adventure
*/
@IsChildPermission
public final static BasicPermission CREATIVE = new BasicPermission(ALL, "creative", PermissionDefault.FALSE);
/**
* Allows switching of own game mode to adventure, but not to creative/survival
*/
@IsChildPermission
public final static BasicPermission ADVENTURE = new BasicPermission(ALL, "adventure", PermissionDefault.FALSE);
/**
* Allows switching of other users game mode
*/
public final static BasicPermission OTHER = new BasicPermission(ALL, "other", PermissionDefault.OP);
}

View file

@ -21,7 +21,7 @@ public class MultiVerseHooks {
});
Hooks.DefaultWorldGameMode.register(new WorldTypeHooker.Check() {
@Override
public GameMode test(World world) {
public GameMode get(World world) {
MultiverseWorld mvWorld = getMV().getMVWorldManager().getMVWorld(world);
if (mvWorld == null)
return null;

View file

@ -8,12 +8,12 @@ import de.jaschastarke.hooking.AbstractHooker;
public class WorldTypeHooker extends AbstractHooker<WorldTypeHooker.Check> {
public interface Check {
GameMode test(World world);
GameMode get(World world);
}
public GameMode test(World world) {
public GameMode get(World world) {
for (Check c : hooks) {
return c.test(world);
return c.get(world);
}
return Bukkit.getServer().getDefaultGameMode();
}

View file

@ -5,12 +5,13 @@ import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import de.jaschastarke.bukkit.lib.ModuleLogger;
import de.jaschastarke.bukkit.lib.configuration.Configuration;
import de.jaschastarke.bukkit.lib.items.MaterialDataNotRecognizedException;
import de.jaschastarke.bukkit.lib.items.MaterilNotRecognizedException;
import de.jaschastarke.bukkit.lib.items.MaterialNotRecognizedException;
import de.jaschastarke.bukkit.lib.items.Utils;
import de.jaschastarke.configuration.IConfigurationSubGroup;
import de.jaschastarke.configuration.annotations.IsConfigurationNode;
@ -59,22 +60,26 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou
public boolean getEnabled() {
return config.getBoolean("enabled", true);
}
public Map<String, MaterialData> getCreativeArmor() {
public Map<String, ItemStack> getCreativeArmor() {
if (getEnabled()) {
Map<String, MaterialData> armor = new HashMap<String, MaterialData>();
Map<String, ItemStack> armor = new HashMap<String, ItemStack>();
for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
if (!entry.getKey().equals("enabled")) {
MaterialData md = null;
try {
md = Utils.parseMaterial((String) entry.getValue());
} catch (MaterilNotRecognizedException e) {
getLog().warn(L("exception.config.material_not_found", entry.getValue()));
} catch (MaterialDataNotRecognizedException e) {
getLog().warn(L("exception.config.materiak_data_not_found", entry.getValue()));
if (entry instanceof ItemStack) {
armor.put(entry.getKey(), (ItemStack) entry);
} else {
MaterialData md = null;
try {
md = Utils.parseMaterial((String) entry.getValue());
} catch (MaterialNotRecognizedException e) {
getLog().warn(L("exception.config.material_not_found", entry.getValue()));
} catch (MaterialDataNotRecognizedException e) {
getLog().warn(L("exception.config.materiak_data_not_found", entry.getValue()));
}
if (md != null)
armor.put(entry.getKey(), md.toItemStack());
}
if (md != null)
armor.put(entry.getKey(), md);
}
}
return armor.size() > 0 ? armor : null;
@ -90,20 +95,20 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou
* *see Blacklist for details on Item-Types
*/
@IsConfigurationNode(order = 500)
public String getHead() {
return config.getString("head", "CHAINMAIL_HELMET");
public Object getHead() {
return config.get("head", "CHAINMAIL_HELMET");
}
@IsConfigurationNode(order = 501)
public String getChest() {
return config.getString("chest", "CHAINMAIL_CHESTPLATE");
public Object getChest() {
return config.get("chest", "CHAINMAIL_CHESTPLATE");
}
@IsConfigurationNode(order = 502)
public String getLegs() {
return config.getString("legs", "CHAINMAIL_LEGGINGS");
public Object getLegs() {
return config.get("legs", "CHAINMAIL_LEGGINGS");
}
@IsConfigurationNode(order = 503)
public String getFeet() {
return config.getString("feet", "CHAINMAIL_BOOTS");
public Object getFeet() {
return config.get("feet", "CHAINMAIL_BOOTS");
}
@Deprecated

View file

@ -25,11 +25,16 @@ import de.jaschastarke.minecraft.lib.permissions.IPermission;
import de.jaschastarke.minecraft.lib.permissions.SimplePermissionContainer;
import de.jaschastarke.minecraft.limitedcreative.Permissions;
/**
*
* @internal Doesn't represent a node, is only a list of additional permissions with an other parent.
*
*/
@ArchiveDocComments
public class InventoryPermissions extends SimplePermissionContainer {
/**
* Allows bypassing the inventory separation
*/
public static final IPermission KEEP_INVENTORY = new BasicPermission(Permissions.getInstance(), "keepinventory", PermissionDefault.FALSE);
public static final IPermission KEEP_INVENTORY = new BasicPermission(Permissions.CONTAINER, "keepinventory", PermissionDefault.FALSE);
}