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; for (HudType hudType : HudType.values()) {
} if (hudType.toString().equalsIgnoreCase(args[0])) {
playerProfile.setHudType(hudType);
PlayerProfile playerProfile = Users.getPlayer((Player) sender).getProfile(); spoutHud.initializeXpBar();
SpoutHud spoutHud = playerProfile.getSpoutHud(); spoutHud.updateXpBar();
return true;
if (spoutHud == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true;
}
switch (args.length) {
case 1:
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;
} }
sender.sendMessage(LocaleLoader.getString("Commands.mchud.Invalid"));
return true;
} }
} }

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,100 +1,63 @@
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)) { if (spoutHud.getXpBarLocked()) {
unlockXpBar(sender);
return true; return true;
} }
if (!mcMMO.spoutEnabled || !SpoutConfig.getInstance().getXPBarEnabled()) { lockXpBar(sender, spoutHud.getLastGained());
sender.sendMessage(LocaleLoader.getString("Commands.Disabled")); return true;
}
@Override
protected boolean oneArgument(Command command, CommandSender sender, String[] args) {
if (args[0].equalsIgnoreCase("on")) {
lockXpBar(sender, spoutHud.getLastGained());
return true; return true;
} }
PlayerProfile playerProfile = Users.getPlayer((Player) sender).getProfile(); if (args[0].equalsIgnoreCase("off")) {
SpoutHud spoutHud = playerProfile.getSpoutHud(); unlockXpBar(sender);
SkillType lastGained;
if (spoutHud == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true; return true;
} }
switch (args.length) { if (!SkillTools.isSkill(args[0])) {
case 0: sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
if (spoutHud.getXpBarLocked()) {
spoutHud.toggleXpBarLocked();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
return true;
}
lastGained = spoutHud.getLastGained();
if (lastGained == null) {
return false;
}
spoutHud.toggleXpBarLocked();
spoutHud.setSkillLock(lastGained);
spoutHud.updateXpBar();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(lastGained.toString())));
return true; return true;
}
case 1: if (!Permissions.hasPermission(sender, "mcmmo.commands.xplock." + args[0].toLowerCase())) {
if (args[0].equalsIgnoreCase("on")) { sender.sendMessage(command.getPermissionMessage());
lastGained = spoutHud.getLastGained(); return true;
}
spoutHud.setXpBarLocked(true); lockXpBar(sender, SkillTools.getSkillType(args[0]));
spoutHud.setSkillLock(lastGained); return true;
spoutHud.updateXpBar(); }
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(lastGained.toString())));
return true;
}
if (args[0].equalsIgnoreCase("off")) {
spoutHud.setXpBarLocked(false);
sender.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
return true;
}
if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
if (!Permissions.hasPermission(sender, "mcmmo.commands.xplock." + args[0].toLowerCase())) {
sender.sendMessage(command.getPermissionMessage());
}
private void lockXpBar(CommandSender sender, SkillType skill) {
if (skill != null) {
spoutHud.setXpBarLocked(true); spoutHud.setXpBarLocked(true);
spoutHud.setSkillLock(SkillTools.getSkillType(args[0])); spoutHud.setSkillLock(skill);
spoutHud.updateXpBar(); spoutHud.updateXpBar();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(skill.toString())));
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(args[0])));
return true;
default:
return false;
} }
} }
private void unlockXpBar(CommandSender sender) {
spoutHud.setXpBarLocked(false);
sender.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
}
} }