Fixed bug with toggle commands not properly displaying the success message.

This commit is contained in:
GJ 2013-10-29 11:45:27 -04:00
parent 97b9214d6e
commit fd9154e009
5 changed files with 23 additions and 28 deletions

View File

@ -9,6 +9,7 @@ Key:
Version 1.4.08-dev Version 1.4.08-dev
+ Added the possibility to gain experience when using Fishing "Shake" + Added the possibility to gain experience when using Fishing "Shake"
= Fixed bug with toggle commands not properly displaying the success message.
= Fixed IllegalArgumentException caused by an empty Fishing treasure category = Fixed IllegalArgumentException caused by an empty Fishing treasure category
Version 1.4.07 Version 1.4.07

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.commands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@ -17,13 +18,13 @@ public class McabilityCommand extends ToggleCommand {
} }
@Override @Override
protected void applyCommandAction() { protected void applyCommandAction(McMMOPlayer mcMMOPlayer) {
player.sendMessage(LocaleLoader.getString("Commands.Ability." + (mcMMOPlayer.getAbilityUse() ? "Off" : "On"))); mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Ability." + (mcMMOPlayer.getAbilityUse() ? "Off" : "On")));
mcMMOPlayer.toggleAbilityUse(); mcMMOPlayer.toggleAbilityUse();
} }
@Override @Override
protected void sendSuccessMessage(CommandSender sender) { protected void sendSuccessMessage(CommandSender sender, String playerName) {
sender.sendMessage(LocaleLoader.getString("Commands.Ability.Toggle")); sender.sendMessage(LocaleLoader.getString("Commands.Ability.Toggle", playerName));
} }
} }

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.commands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@ -17,13 +18,13 @@ public class McgodCommand extends ToggleCommand {
} }
@Override @Override
protected void applyCommandAction() { protected void applyCommandAction(McMMOPlayer mcMMOPlayer) {
player.sendMessage(LocaleLoader.getString("Commands.GodMode." + (mcMMOPlayer.getGodMode() ? "Disabled" : "Enabled"))); mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.GodMode." + (mcMMOPlayer.getGodMode() ? "Disabled" : "Enabled")));
mcMMOPlayer.toggleGodMode(); mcMMOPlayer.toggleGodMode();
} }
@Override @Override
protected void sendSuccessMessage(CommandSender sender) { protected void sendSuccessMessage(CommandSender sender, String playerName) {
sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Success")); sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Toggle", playerName));
} }
} }

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.commands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@ -17,17 +18,17 @@ public class McrefreshCommand extends ToggleCommand {
} }
@Override @Override
protected void applyCommandAction() { protected void applyCommandAction(McMMOPlayer mcMMOPlayer) {
mcMMOPlayer.setRecentlyHurt(0); mcMMOPlayer.setRecentlyHurt(0);
mcMMOPlayer.resetCooldowns(); mcMMOPlayer.resetCooldowns();
mcMMOPlayer.resetToolPrepMode(); mcMMOPlayer.resetToolPrepMode();
mcMMOPlayer.resetAbilityMode(); mcMMOPlayer.resetAbilityMode();
player.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh")); mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
} }
@Override @Override
protected void sendSuccessMessage(CommandSender sender) { protected void sendSuccessMessage(CommandSender sender, String playerName) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", player.getName())); sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", playerName));
} }
} }

View File

@ -7,7 +7,6 @@ import java.util.Set;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
@ -18,9 +17,6 @@ import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
public abstract class ToggleCommand implements TabExecutor { public abstract class ToggleCommand implements TabExecutor {
protected McMMOPlayer mcMMOPlayer;
protected Player player;
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
@ -34,10 +30,7 @@ public abstract class ToggleCommand implements TabExecutor {
return true; return true;
} }
player = (Player) sender; applyCommandAction(UserManager.getPlayer(sender.getName()));
mcMMOPlayer = UserManager.getPlayer(player);
applyCommandAction();
return true; return true;
case 1: case 1:
@ -47,20 +40,18 @@ public abstract class ToggleCommand implements TabExecutor {
} }
String playerName = Misc.getMatchedPlayerName(args[0]); String playerName = Misc.getMatchedPlayerName(args[0]);
mcMMOPlayer = UserManager.getPlayer(playerName); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
if (!CommandUtils.checkPlayerExistence(sender, playerName, mcMMOPlayer)) { if (!CommandUtils.checkPlayerExistence(sender, playerName, mcMMOPlayer)) {
return true; return true;
} }
player = mcMMOPlayer.getPlayer(); if (CommandUtils.isOffline(sender, mcMMOPlayer.getPlayer())) {
if (CommandUtils.isOffline(sender, player)) {
return true; return true;
} }
applyCommandAction(); applyCommandAction(mcMMOPlayer);
sendSuccessMessage(sender); sendSuccessMessage(sender, playerName);
return true; return true;
default: default:
@ -81,6 +72,6 @@ public abstract class ToggleCommand implements TabExecutor {
protected abstract boolean hasOtherPermission(CommandSender sender); protected abstract boolean hasOtherPermission(CommandSender sender);
protected abstract boolean hasSelfPermission(CommandSender sender); protected abstract boolean hasSelfPermission(CommandSender sender);
protected abstract void applyCommandAction(); protected abstract void applyCommandAction(McMMOPlayer mcMMOPlayer);
protected abstract void sendSuccessMessage(CommandSender sender); protected abstract void sendSuccessMessage(CommandSender sender, String playerName);
} }