CommandMixin plz

This commit is contained in:
Olof Larsson 2013-08-05 13:30:32 +02:00
parent 62b0e8f8b3
commit f0dfc539ba
4 changed files with 84 additions and 0 deletions

View File

@ -0,0 +1,12 @@
package com.massivecraft.mcore.mixin;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore.store.SenderEntity;
public interface CommandMixin
{
public boolean dispatchCommand(CommandSender sender, String commandLine);
public boolean dispatchCommand(SenderEntity<?> sender, String commandLine);
public boolean dispatchCommand(String sender, String commandLine);
}

View File

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

View File

@ -0,0 +1,28 @@
package com.massivecraft.mcore.mixin;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore.util.SenderUtil;
public class CommandMixinDefault extends CommandMixinAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static CommandMixinDefault i = new CommandMixinDefault();
public static CommandMixinDefault get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public boolean dispatchCommand(String sender, String commandLine)
{
CommandSender commandSender = SenderUtil.getSender(sender);
if (commandSender == null) return false;
return this.dispatchCommand(sender, commandLine);
}
}

View File

@ -66,6 +66,10 @@ public class Mixin
public static ActualMixin getActualMixin() { return actualMixin; } public static ActualMixin getActualMixin() { return actualMixin; }
public static void setActualMixin(ActualMixin val) { actualMixin = val; } public static void setActualMixin(ActualMixin val) { actualMixin = val; }
private static CommandMixin commandMixin = CommandMixinDefault.get();
public static CommandMixin getCommandMixin() { return commandMixin; }
public static void setCommandMixin(CommandMixin val) { commandMixin = val; }
// -------------------------------------------- // // -------------------------------------------- //
// STATIC EXPOSE: WORLD // STATIC EXPOSE: WORLD
// -------------------------------------------- // // -------------------------------------------- //
@ -702,4 +706,23 @@ public class Mixin
return getActualMixin().isActualLeave(event); return getActualMixin().isActualLeave(event);
} }
// -------------------------------------------- //
// STATIC EXPOSE: COMMAND
// -------------------------------------------- //
public boolean dispatchCommand(CommandSender sender, String commandLine)
{
return getCommandMixin().dispatchCommand(sender, commandLine);
}
public boolean dispatchCommand(SenderEntity<?> sender, String commandLine)
{
return getCommandMixin().dispatchCommand(sender, commandLine);
}
public boolean dispatchCommand(String sender, String commandLine)
{
return getCommandMixin().dispatchCommand(sender, commandLine);
}
} }