Search in sources :

Example 21 with CommandSender

use of org.bukkit.command.CommandSender in project MagicPlugin by elBukkit.

the class CommandCitizensTrait method perform.

@Override
public boolean perform(net.citizensnpcs.api.event.NPCRightClickEvent event) {
    if (command == null || command.isEmpty())
        return false;
    CommandSender sender = event.getClicker();
    Player player = event.getClicker();
    boolean result = true;
    boolean isOp = sender.isOp();
    if (op && !isOp) {
        sender.setOp(true);
    }
    Location location = player.getLocation();
    CommandSender executor = console ? Bukkit.getConsoleSender() : player;
    try {
        String converted = command.replace("@pd", player.getDisplayName()).replace("@pn", player.getName()).replace("@p", player.getName()).replace("@uuid", player.getUniqueId().toString()).replace("@world", location.getWorld().getName()).replace("@x", Double.toString(location.getX())).replace("@y", Double.toString(location.getY())).replace("@z", Double.toString(location.getZ()));
        ;
        api.getPlugin().getServer().dispatchCommand(executor, converted);
    } catch (Exception ex) {
        result = false;
        api.getLogger().log(Level.WARNING, "Error running command: " + command, ex);
    }
    if (op && !isOp) {
        sender.setOp(false);
    }
    return result;
}
Also used : Player(org.bukkit.entity.Player) CommandSender(org.bukkit.command.CommandSender) Location(org.bukkit.Location)

Example 22 with CommandSender

use of org.bukkit.command.CommandSender in project MagicPlugin by elBukkit.

the class WandUpgradePath method upgraded.

public void upgraded(com.elmakers.mine.bukkit.api.wand.Wand wand, Mage mage) {
    CommandSender sender = Bukkit.getConsoleSender();
    Location location = null;
    if (mage != null) {
        playEffects(mage, "upgrade");
        location = mage.getLocation();
    }
    Player player = mage != null ? mage.getPlayer() : null;
    boolean shouldRunCommands = (player == null || !player.hasPermission("Magic.bypass_upgrade_commands"));
    if (upgradeCommands != null && shouldRunCommands) {
        for (String command : upgradeCommands) {
            if (command.contains("@uuid") || command.contains("@pn") || command.contains("@pd")) {
                if (mage == null) {
                    Bukkit.getLogger().warning("Tried to upgrade with commands but no mage");
                    continue;
                }
                command = command.replace("@uuid", mage.getId()).replace("@pn", mage.getName()).replace("@pd", mage.getDisplayName());
                ;
            }
            if (location != null) {
                command = command.replace("@world", location.getWorld().getName()).replace("@x", Double.toString(location.getX())).replace("@y", Double.toString(location.getY())).replace("@z", Double.toString(location.getZ()));
            }
            WandUpgradePath upgrade = getPath(upgradeKey);
            command = command.replace("$path", upgrade.getName());
            command = ChatColor.translateAlternateColorCodes('&', command);
            wand.getController().getPlugin().getServer().dispatchCommand(sender, command);
        }
    }
    if (upgradeItemKey != null && !upgradeItemKey.isEmpty()) {
        com.elmakers.mine.bukkit.api.wand.Wand upgradeWand = wand.getController().createWand(upgradeItemKey);
        if (upgradeWand != null) {
            wand.add(upgradeWand, mage);
        }
    }
}
Also used : EffectPlayer(com.elmakers.mine.bukkit.effect.EffectPlayer) Player(org.bukkit.entity.Player) CommandSender(org.bukkit.command.CommandSender) Location(org.bukkit.Location)

Example 23 with CommandSender

use of org.bukkit.command.CommandSender in project MassiveCore by MassiveCraft.

the class Pager method getHeightCalc.

public Integer getHeightCalc() {
    Integer ret = this.getHeight();
    if (ret != null)
        return ret;
    CommandSender sender = this.getSenderCalc();
    if (sender == null)
        return Txt.PAGEHEIGHT_PLAYER;
    if (sender instanceof Player)
        return Txt.PAGEHEIGHT_PLAYER;
    return Txt.PAGEHEIGHT_CONSOLE;
}
Also used : Player(org.bukkit.entity.Player) CommandSender(org.bukkit.command.CommandSender)

Example 24 with CommandSender

use of org.bukkit.command.CommandSender in project MassiveCore by MassiveCraft.

the class NmsChat method sendChatPlain.

public void sendChatPlain(Object sendeeObject, String plain) {
    CommandSender sendee = IdUtil.getSender(sendeeObject);
    if (sendee == null)
        return;
    MassiveCoreMConf mconf = MassiveCoreMConf.get();
    if (mconf != null && !mconf.consoleColorsEnabled && sendee instanceof ConsoleCommandSender) {
        plain = ChatColor.stripColor(plain);
    }
    sendee.sendMessage(plain);
}
Also used : MassiveCoreMConf(com.massivecraft.massivecore.MassiveCoreMConf) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 25 with CommandSender

use of org.bukkit.command.CommandSender in project MassiveCore by MassiveCraft.

the class NmsChatAbstract method sendChatMson.

// -------------------------------------------- //
// CHAT
// -------------------------------------------- //
@Override
public void sendChatMson(Object sendeeObject, Mson mson) {
    CommandSender sendee = IdUtil.getSender(sendeeObject);
    if (sendee == null)
        return;
    if (sendee instanceof Player) {
        Player player = (Player) sendee;
        String raw = mson.toRaw();
        Object component = toComponent(raw);
        Object packet = ReflectionUtil.invokeConstructor(this.constructorPacketPlayOutChat, component);
        NmsBasics.get().sendPacket(player, packet);
    } else {
        String plain = mson.toPlain(true);
        this.sendChatPlain(sendee, plain);
    }
}
Also used : Player(org.bukkit.entity.Player) CommandSender(org.bukkit.command.CommandSender)

Aggregations

CommandSender (org.bukkit.command.CommandSender)295 Test (org.junit.Test)171 Player (org.bukkit.entity.Player)94 Matchers.containsString (org.hamcrest.Matchers.containsString)68 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)50 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)43 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)30 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)29 PermissionNode (fr.xephi.authme.permission.PermissionNode)17 BlockCommandSender (org.bukkit.command.BlockCommandSender)16 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)12 Location (org.bukkit.Location)10 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)9 ArrayList (java.util.ArrayList)9 List (java.util.List)9 FoundCommandResult (fr.xephi.authme.command.FoundCommandResult)8 IOException (java.io.IOException)7 Entity (org.bukkit.entity.Entity)7 IEssentialsCommand (com.earth2me.essentials.commands.IEssentialsCommand)6 NoChargeException (com.earth2me.essentials.commands.NoChargeException)6