Add ability to require a presence in the mixin for commands.

This commit is contained in:
Olof Larsson 2013-08-06 15:11:20 +02:00
parent ae2c1285d6
commit 0d5fb204a6
4 changed files with 32 additions and 11 deletions

View File

@ -8,5 +8,6 @@ public interface CommandMixin
{ {
public boolean dispatchCommand(CommandSender sender, String commandLine); public boolean dispatchCommand(CommandSender sender, String commandLine);
public boolean dispatchCommand(SenderEntity<?> sender, String commandLine); public boolean dispatchCommand(SenderEntity<?> sender, String commandLine);
public boolean dispatchCommand(String sender, String commandLine); public boolean dispatchCommand(String senderId, String commandLine);
public boolean dispatchCommand(String presentId, String senderId, String commandLine); // This one is non-abstract
} }

View File

@ -1,21 +1,27 @@
package com.massivecraft.mcore.mixin; package com.massivecraft.mcore.mixin;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.massivecraft.mcore.store.SenderEntity; import com.massivecraft.mcore.store.SenderEntity;
import com.massivecraft.mcore.util.SenderUtil;
public abstract class CommandMixinAbstract implements CommandMixin public abstract class CommandMixinAbstract implements CommandMixin
{ {
@Override
public boolean dispatchCommand(CommandSender sender, String commandLine) public boolean dispatchCommand(CommandSender sender, String commandLine)
{ {
return Bukkit.getServer().dispatchCommand(sender, commandLine); return this.dispatchCommand(SenderUtil.getSenderId(sender), SenderUtil.getSenderId(sender), commandLine);
} }
@Override @Override
public boolean dispatchCommand(SenderEntity<?> sender, String commandLine) public boolean dispatchCommand(SenderEntity<?> sender, String commandLine)
{ {
return this.dispatchCommand(sender.getId(), commandLine); return this.dispatchCommand(sender.getId(), sender.getId(), commandLine);
} }
@Override
public boolean dispatchCommand(String senderId, String commandLine)
{
return this.dispatchCommand(senderId, senderId, commandLine);
}
} }

View File

@ -1,5 +1,6 @@
package com.massivecraft.mcore.mixin; package com.massivecraft.mcore.mixin;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.massivecraft.mcore.util.SenderUtil; import com.massivecraft.mcore.util.SenderUtil;
@ -18,11 +19,19 @@ public class CommandMixinDefault extends CommandMixinAbstract
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public boolean dispatchCommand(String sender, String commandLine) public boolean dispatchCommand(String presentId, String senderId, String commandLine)
{ {
CommandSender commandSender = SenderUtil.getSender(sender); // Additional enforced presence
if (commandSender == null) return false; CommandSender present = SenderUtil.getSender(presentId);
return this.dispatchCommand(sender, commandLine); if (present == null) return false;
// We must then of course have the presence of the sender
CommandSender sender = SenderUtil.getSender(senderId);
if (sender == null) return false;
// Great! Let's do it!
Bukkit.getServer().dispatchCommand(sender, commandLine);
return true;
} }
} }

View File

@ -720,9 +720,14 @@ public class Mixin
return getCommandMixin().dispatchCommand(sender, commandLine); return getCommandMixin().dispatchCommand(sender, commandLine);
} }
public static boolean dispatchCommand(String sender, String commandLine) public static boolean dispatchCommand(String senderId, String commandLine)
{ {
return getCommandMixin().dispatchCommand(sender, commandLine); return getCommandMixin().dispatchCommand(senderId, commandLine);
}
public static boolean dispatchCommand(String presentId, String senderId, String commandLine)
{
return getCommandMixin().dispatchCommand(presentId, senderId, commandLine);
} }
} }