Abstract our Spout commands.

This commit is contained in:
GJ 2013-02-07 11:57:54 -05:00
parent 57063246fb
commit c3f83302c5
3 changed files with 101 additions and 112 deletions

View File

@ -1,56 +1,29 @@
package com.gmail.nossr50.spout.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.spout.SpoutConfig;
import com.gmail.nossr50.spout.huds.HudType;
import com.gmail.nossr50.spout.huds.SpoutHud;
import com.gmail.nossr50.util.Users;
public class MchudCommand implements CommandExecutor {
public class MchudCommand extends SpoutCommand {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandHelper.noConsoleUsage(sender)) {
return true;
protected boolean noArguments(Command command, CommandSender sender, String[] args) {
return false;
}
if (!mcMMO.spoutEnabled || !SpoutConfig.getInstance().getXPBarEnabled()) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true;
}
PlayerProfile playerProfile = Users.getPlayer((Player) sender).getProfile();
SpoutHud spoutHud = playerProfile.getSpoutHud();
if (spoutHud == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true;
}
switch (args.length) {
case 1:
@Override
protected boolean oneArgument(Command command, CommandSender sender, String[] args) {
for (HudType hudType : HudType.values()) {
if (hudType.toString().equalsIgnoreCase(args[0])) {
playerProfile.setHudType(hudType);
spoutHud.initializeXpBar();
spoutHud.updateXpBar();
return true;
}
}
sender.sendMessage(LocaleLoader.getString("Commands.mchud.Invalid"));
return true;
default:
return false;
}
}
}

View File

@ -0,0 +1,53 @@
package com.gmail.nossr50.spout.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.spout.SpoutConfig;
import com.gmail.nossr50.spout.huds.SpoutHud;
import com.gmail.nossr50.util.Users;
public abstract class SpoutCommand implements CommandExecutor {
protected PlayerProfile playerProfile;
protected SpoutHud spoutHud;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandHelper.noConsoleUsage(sender)) {
return true;
}
if (!mcMMO.spoutEnabled || !SpoutConfig.getInstance().getXPBarEnabled()) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true;
}
playerProfile = Users.getPlayer((Player) sender).getProfile();
spoutHud = playerProfile.getSpoutHud();
if (spoutHud == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true;
}
switch (args.length) {
case 0:
return noArguments(command, sender, args);
case 1:
return oneArgument(command, sender, args);
default:
return false;
}
}
protected abstract boolean noArguments(Command command, CommandSender sender, String[] args);
protected abstract boolean oneArgument(Command command, CommandSender sender, String[] args);
}

View File

@ -1,79 +1,35 @@
package com.gmail.nossr50.spout.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.spout.SpoutConfig;
import com.gmail.nossr50.spout.huds.SpoutHud;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class XplockCommand implements CommandExecutor {
public class XplockCommand extends SpoutCommand {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandHelper.noConsoleUsage(sender)) {
return true;
}
if (!mcMMO.spoutEnabled || !SpoutConfig.getInstance().getXPBarEnabled()) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true;
}
PlayerProfile playerProfile = Users.getPlayer((Player) sender).getProfile();
SpoutHud spoutHud = playerProfile.getSpoutHud();
SkillType lastGained;
if (spoutHud == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true;
}
switch (args.length) {
case 0:
protected boolean noArguments(Command command, CommandSender sender, String[] args) {
if (spoutHud.getXpBarLocked()) {
spoutHud.toggleXpBarLocked();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
unlockXpBar(sender);
return true;
}
lastGained = spoutHud.getLastGained();
if (lastGained == null) {
return false;
lockXpBar(sender, spoutHud.getLastGained());
return true;
}
spoutHud.toggleXpBarLocked();
spoutHud.setSkillLock(lastGained);
spoutHud.updateXpBar();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(lastGained.toString())));
return true;
case 1:
@Override
protected boolean oneArgument(Command command, CommandSender sender, String[] args) {
if (args[0].equalsIgnoreCase("on")) {
lastGained = spoutHud.getLastGained();
spoutHud.setXpBarLocked(true);
spoutHud.setSkillLock(lastGained);
spoutHud.updateXpBar();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(lastGained.toString())));
lockXpBar(sender, spoutHud.getLastGained());
return true;
}
if (args[0].equalsIgnoreCase("off")) {
spoutHud.setXpBarLocked(false);
sender.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
unlockXpBar(sender);
return true;
}
@ -84,17 +40,24 @@ public class XplockCommand implements CommandExecutor {
if (!Permissions.hasPermission(sender, "mcmmo.commands.xplock." + args[0].toLowerCase())) {
sender.sendMessage(command.getPermissionMessage());
}
spoutHud.setXpBarLocked(true);
spoutHud.setSkillLock(SkillTools.getSkillType(args[0]));
spoutHud.updateXpBar();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(args[0])));
return true;
}
default:
return false;
lockXpBar(sender, SkillTools.getSkillType(args[0]));
return true;
}
private void lockXpBar(CommandSender sender, SkillType skill) {
if (skill != null) {
spoutHud.setXpBarLocked(true);
spoutHud.setSkillLock(skill);
spoutHud.updateXpBar();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(skill.toString())));
}
}
private void unlockXpBar(CommandSender sender) {
spoutHud.setXpBarLocked(false);
sender.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
}
}