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; package com.gmail.nossr50.spout.commands;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; 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.locale.LocaleLoader;
import com.gmail.nossr50.spout.SpoutConfig;
import com.gmail.nossr50.spout.huds.HudType; 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 @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { protected boolean noArguments(Command command, CommandSender sender, String[] args) {
if (CommandHelper.noConsoleUsage(sender)) { return false;
return true;
} }
if (!mcMMO.spoutEnabled || !SpoutConfig.getInstance().getXPBarEnabled()) { @Override
sender.sendMessage(LocaleLoader.getString("Commands.Disabled")); protected boolean oneArgument(Command command, CommandSender sender, String[] args) {
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:
for (HudType hudType : HudType.values()) { for (HudType hudType : HudType.values()) {
if (hudType.toString().equalsIgnoreCase(args[0])) { if (hudType.toString().equalsIgnoreCase(args[0])) {
playerProfile.setHudType(hudType); playerProfile.setHudType(hudType);
spoutHud.initializeXpBar(); spoutHud.initializeXpBar();
spoutHud.updateXpBar(); spoutHud.updateXpBar();
return true; return true;
} }
} }
sender.sendMessage(LocaleLoader.getString("Commands.mchud.Invalid")); sender.sendMessage(LocaleLoader.getString("Commands.mchud.Invalid"));
return true; 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; package com.gmail.nossr50.spout.commands;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; 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.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType; 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.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class XplockCommand implements CommandExecutor { public class XplockCommand extends SpoutCommand {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { protected boolean noArguments(Command command, CommandSender sender, 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:
if (spoutHud.getXpBarLocked()) { if (spoutHud.getXpBarLocked()) {
spoutHud.toggleXpBarLocked(); unlockXpBar(sender);
sender.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
return true; return true;
} }
lastGained = spoutHud.getLastGained(); lockXpBar(sender, spoutHud.getLastGained());
return true;
if (lastGained == null) {
return false;
} }
spoutHud.toggleXpBarLocked(); @Override
spoutHud.setSkillLock(lastGained); protected boolean oneArgument(Command command, CommandSender sender, String[] args) {
spoutHud.updateXpBar();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(lastGained.toString())));
return true;
case 1:
if (args[0].equalsIgnoreCase("on")) { if (args[0].equalsIgnoreCase("on")) {
lastGained = spoutHud.getLastGained(); lockXpBar(sender, spoutHud.getLastGained());
spoutHud.setXpBarLocked(true);
spoutHud.setSkillLock(lastGained);
spoutHud.updateXpBar();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(lastGained.toString())));
return true; return true;
} }
if (args[0].equalsIgnoreCase("off")) { if (args[0].equalsIgnoreCase("off")) {
spoutHud.setXpBarLocked(false); unlockXpBar(sender);
sender.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
return true; return true;
} }
@ -84,17 +40,24 @@ public class XplockCommand implements CommandExecutor {
if (!Permissions.hasPermission(sender, "mcmmo.commands.xplock." + args[0].toLowerCase())) { if (!Permissions.hasPermission(sender, "mcmmo.commands.xplock." + args[0].toLowerCase())) {
sender.sendMessage(command.getPermissionMessage()); 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; 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"));
} }
} }