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.store: separated inventories
basic.feature.limit: creative restrictions basic.feature.limit: creative restrictions
basic.feature.region: creative regions 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.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 basic.warning.worldguard_not_found: WorldGuard isn't found, the feature {0} is disabled
# double single-quote '' because of MessageFormater to insert {0} # double single-quote '' because of MessageFormater to insert {0}
command.player: player 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.survival: Changes the game mode of a player to survival
command.switch.creative: Changes the game mode of a player to creative command.switch.creative: Changes the game mode of a player to creative
command.switch.adventure: Changes the game mode of a player to adventure 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> <finalName>${project.artifactId}</finalName>
<resources> <resources>
<resource> <!-- <resource>
<targetPath>.</targetPath> <targetPath>.</targetPath>
<filtering>true</filtering> <filtering>true</filtering>
<directory>${basedir}/</directory> <directory>${basedir}/</directory>
@ -111,19 +111,19 @@
<include>config.yml</include> <include>config.yml</include>
<include>META-INF/descriptions.jos</include> <include>META-INF/descriptions.jos</include>
</includes> </includes>
</resource> </resource>-->
<resource> <resource>
<targetPath>lang/</targetPath> <targetPath>lang/</targetPath>
<directory>${basedir}/lang/</directory> <directory>${basedir}/lang/</directory>
</resource> </resource>
<resource> <!-- <resource>
<targetPath>META-INF/</targetPath> <targetPath>META-INF/</targetPath>
<filtering>true</filtering> <filtering>true</filtering>
<directory>${project.build.directory}/generated-sources/annotations/META-INF/</directory> <directory>${project.build.directory}/generated-sources/annotations/META-INF/</directory>
<includes> <includes>
<include>descriptions.jos</include> <include>descriptions.jos</include>
</includes> </includes>
</resource> </resource> -->
</resources> </resources>
<plugins> <plugins>
@ -157,14 +157,22 @@
<param>WorldGuard</param> <param>WorldGuard</param>
<param>WorldEdit</param> <param>WorldEdit</param>
<param>MultiInv</param> <param>MultiInv</param>
<param>xAuth</param>
<param>AuthMe</param>
<param>MultiInv</param>
<param>Multiverse-Inventories</param>
</softdepend> </softdepend>
<custom> <custom>
<dev-url>http://dev.bukkit.org/server-mods/limited-creative/</dev-url> <dev-url>http://dev.bukkit.org/server-mods/limited-creative/</dev-url>
</custom> </custom>
<registeredPermissions> <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.inventories.InventoryPermissions</param>
<param>de.jaschastarke.minecraft.limitedcreative.SwitchGameModePermissions:ALL</param>
</registeredPermissions> </registeredPermissions>
<registeredCommands>
<param>de.jaschastarke.minecraft.limitedcreative.MainCommand</param>
</registeredCommands>
</configuration> </configuration>
</execution> </execution>
</executions> </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; import de.jaschastarke.bukkit.lib.PluginLang;
public class LimitedCreative extends Core { public class LimitedCreative extends Core {
private i18n lang;
protected Config config = null; protected Config config = null;
protected MainCommand command = null;
@Override @Override
public void OnInitialize() { public void OnInitialize() {
@ -14,16 +14,20 @@ public class LimitedCreative extends Core {
config = new Config(this); config = new Config(this);
this.debug = config.getDebug(); 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); Hooks.inizializeHooks(this);
addModule(new FeatureSwitchGameMode(this));
addModule(new ModInventories(this)); addModule(new ModInventories(this));
addModule(new ModCreativeLimits(this)); addModule(new ModCreativeLimits(this));
addModule(new ModRegions(this)); addModule(new ModRegions(this));
addModule(new ModCmdBlocker(this)); addModule(new ModCmdBlocker(this));
config.save(); config.saveDefault();
} }
public Config getPluginConfig() { public Config getPluginConfig() {
@ -32,9 +36,13 @@ public class LimitedCreative extends Core {
@Deprecated @Deprecated
public String L(String msg, Object... objects) { public String L(String msg, Object... objects) {
return lang.trans(msg, objects); return getLang().trans(msg, objects);
} }
public i18n getLocale() { 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.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import de.jaschastarke.bukkit.lib.CoreModule; 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.ArmoryConfig;
import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory; import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory;
import de.jaschastarke.minecraft.limitedcreative.inventories.InventoryConfig; import de.jaschastarke.minecraft.limitedcreative.inventories.InventoryConfig;
@ -73,7 +71,7 @@ public class ModInventories extends CoreModule<LimitedCreative> {
} }
public void onSetGameMode(Player player, GameMode gm) { public void onSetGameMode(Player player, GameMode gm) {
if (PermissionManager.hasPermission(player, InventoryPermissions.KEEP_INVENTORY)) if (plugin.getPermManager().hasPermission(player, InventoryPermissions.KEEP_INVENTORY))
return; return;
player.closeInventory(); player.closeInventory();
@ -107,17 +105,17 @@ public class ModInventories extends CoreModule<LimitedCreative> {
} }
public void setCreativeArmor(Player player) { public void setCreativeArmor(Player player) {
Map<String, MaterialData> armor = armor_config.getCreativeArmor(); Map<String, ItemStack> armor = armor_config.getCreativeArmor();
if (armor != null) { if (armor != null) {
ItemStack[] is = new ItemStack[4]; ItemStack[] is = new ItemStack[4];
if (armor.containsKey("feet")) if (armor.containsKey("feet"))
is[0] = armor.get("feet").toItemStack(1); is[0] = armor.get("feet");
if (armor.containsKey("legs")) if (armor.containsKey("legs"))
is[1] = armor.get("legs").toItemStack(1); is[1] = armor.get("legs");
if (armor.containsKey("chest")) if (armor.containsKey("chest"))
is[2] = armor.get("chest").toItemStack(1); is[2] = armor.get("chest");
if (armor.containsKey("head")) if (armor.containsKey("head"))
is[3] = armor.get("head").toItemStack(1); is[3] = armor.get("head");
player.getInventory().setArmorContents(is); player.getInventory().setArmorContents(is);
} }
} }

View file

@ -19,26 +19,26 @@ package de.jaschastarke.minecraft.limitedcreative;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
import de.jaschastarke.Singleton;
import de.jaschastarke.maven.ArchiveDocComments; import de.jaschastarke.maven.ArchiveDocComments;
import de.jaschastarke.minecraft.lib.permissions.BasicPermission; import de.jaschastarke.minecraft.lib.permissions.BasicPermission;
import de.jaschastarke.minecraft.lib.permissions.IPermission; import de.jaschastarke.minecraft.lib.permissions.IPermission;
import de.jaschastarke.minecraft.lib.permissions.SimplePermissionContainer; import de.jaschastarke.minecraft.lib.permissions.SimplePermissionContainerNode;
@ArchiveDocComments @ArchiveDocComments
public class Permissions extends SimplePermissionContainer implements Singleton { public class Permissions extends SimplePermissionContainerNode {
private static Permissions instance = new Permissions(); protected Permissions(String name) {
public static Permissions getInstance() { super(name);
return instance;
} }
public final static Permissions CONTAINER = new Permissions("limitedcreative");
/** /**
* Allows changing plugin configuration ingame via commands * Allows changing plugin configuration ingame via commands
*/ */
public static final IPermission CONFIG = new BasicPermission(instance, "config", PermissionDefault.OP); public static final IPermission CONFIG = new BasicPermission(CONTAINER, "config", PermissionDefault.OP);
/**
@Override * Gives player access to the general /limitedcreative command. This permission doesn't affect the usability, but
public String getFullString() { * allows to hide the command from /help for users.
return "limitedcreative"; */
} 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() { Hooks.DefaultWorldGameMode.register(new WorldTypeHooker.Check() {
@Override @Override
public GameMode test(World world) { public GameMode get(World world) {
MultiverseWorld mvWorld = getMV().getMVWorldManager().getMVWorld(world); MultiverseWorld mvWorld = getMV().getMVWorldManager().getMVWorld(world);
if (mvWorld == null) if (mvWorld == null)
return null; return null;

View file

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

View file

@ -5,12 +5,13 @@ import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
import de.jaschastarke.bukkit.lib.ModuleLogger; import de.jaschastarke.bukkit.lib.ModuleLogger;
import de.jaschastarke.bukkit.lib.configuration.Configuration; import de.jaschastarke.bukkit.lib.configuration.Configuration;
import de.jaschastarke.bukkit.lib.items.MaterialDataNotRecognizedException; 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.bukkit.lib.items.Utils;
import de.jaschastarke.configuration.IConfigurationSubGroup; import de.jaschastarke.configuration.IConfigurationSubGroup;
import de.jaschastarke.configuration.annotations.IsConfigurationNode; import de.jaschastarke.configuration.annotations.IsConfigurationNode;
@ -59,22 +60,26 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou
public boolean getEnabled() { public boolean getEnabled() {
return config.getBoolean("enabled", true); return config.getBoolean("enabled", true);
} }
public Map<String, MaterialData> getCreativeArmor() { public Map<String, ItemStack> getCreativeArmor() {
if (getEnabled()) { 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()) { for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
if (!entry.getKey().equals("enabled")) { if (!entry.getKey().equals("enabled")) {
if (entry instanceof ItemStack) {
armor.put(entry.getKey(), (ItemStack) entry);
} else {
MaterialData md = null; MaterialData md = null;
try { try {
md = Utils.parseMaterial((String) entry.getValue()); md = Utils.parseMaterial((String) entry.getValue());
} catch (MaterilNotRecognizedException e) { } catch (MaterialNotRecognizedException e) {
getLog().warn(L("exception.config.material_not_found", entry.getValue())); getLog().warn(L("exception.config.material_not_found", entry.getValue()));
} catch (MaterialDataNotRecognizedException e) { } catch (MaterialDataNotRecognizedException e) {
getLog().warn(L("exception.config.materiak_data_not_found", entry.getValue())); getLog().warn(L("exception.config.materiak_data_not_found", entry.getValue()));
} }
if (md != null) if (md != null)
armor.put(entry.getKey(), md); armor.put(entry.getKey(), md.toItemStack());
}
} }
} }
return armor.size() > 0 ? armor : null; return armor.size() > 0 ? armor : null;
@ -90,20 +95,20 @@ public class ArmoryConfig extends Configuration implements IConfigurationSubGrou
* *see Blacklist for details on Item-Types * *see Blacklist for details on Item-Types
*/ */
@IsConfigurationNode(order = 500) @IsConfigurationNode(order = 500)
public String getHead() { public Object getHead() {
return config.getString("head", "CHAINMAIL_HELMET"); return config.get("head", "CHAINMAIL_HELMET");
} }
@IsConfigurationNode(order = 501) @IsConfigurationNode(order = 501)
public String getChest() { public Object getChest() {
return config.getString("chest", "CHAINMAIL_CHESTPLATE"); return config.get("chest", "CHAINMAIL_CHESTPLATE");
} }
@IsConfigurationNode(order = 502) @IsConfigurationNode(order = 502)
public String getLegs() { public Object getLegs() {
return config.getString("legs", "CHAINMAIL_LEGGINGS"); return config.get("legs", "CHAINMAIL_LEGGINGS");
} }
@IsConfigurationNode(order = 503) @IsConfigurationNode(order = 503)
public String getFeet() { public Object getFeet() {
return config.getString("feet", "CHAINMAIL_BOOTS"); return config.get("feet", "CHAINMAIL_BOOTS");
} }
@Deprecated @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.lib.permissions.SimplePermissionContainer;
import de.jaschastarke.minecraft.limitedcreative.Permissions; import de.jaschastarke.minecraft.limitedcreative.Permissions;
/**
*
* @internal Doesn't represent a node, is only a list of additional permissions with an other parent.
*
*/
@ArchiveDocComments @ArchiveDocComments
public class InventoryPermissions extends SimplePermissionContainer { public class InventoryPermissions extends SimplePermissionContainer {
/** /**
* Allows bypassing the inventory separation * 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);
} }