Don't allow online players as command argument if not visible

This commit is contained in:
Magnus Ulf Jørgensen 2017-01-22 13:31:36 +01:00
parent f23b42e118
commit 1281173689
2 changed files with 21 additions and 9 deletions

View File

@ -111,14 +111,21 @@ public abstract class TypeSenderIdAbstract<T> extends TypeAbstract<T>
// All of our subclasses return null if senderId is null.
// Thus we don't need to check for that being null, but only check ret.
// If presence is online or local ...
if (this.presence == SenderPresence.LOCAL || this.presence == SenderPresence.ONLINE)
{
// ... and the target is not visible for the sender ...
if (!MixinVisibility.get().isVisible(senderId, sender))
{
// .. throw an error.
throwError(arg);
}
}
// Create & populate Ret
T ret = this.getResultForSenderId(senderId);
if (ret == null)
{
// No alternatives found
throw new MassiveException().addMessage(this.getErrorMessageForArg(arg));
}
if (ret == null) throwError(arg);
// Return Ret
return ret;
@ -178,6 +185,11 @@ public abstract class TypeSenderIdAbstract<T> extends TypeAbstract<T>
// UTIL
// -------------------------------------------- //
public void throwError(String arg) throws MassiveException
{
throw new MassiveException().addMessage(this.getErrorMessageForArg(arg));
}
public String getErrorMessageForArg(String arg)
{
return Txt.parse("<b>No %s matches \"<h>%s<b>\".", this.getName(), arg);