org.bukkit.command.ConsoleCommandSender Java Examples

The following examples show how to use org.bukkit.command.ConsoleCommandSender. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HeavySpleef.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
private void checkConfigVersions(Configuration config, Path dataFolder) {
	if (config.getInt("config-version") < DefaultConfig.CURRENT_CONFIG_VERSION) {
		Path configSource = dataFolder.resolve(ConfigType.DEFAULT_CONFIG.getDestinationFileName());
		Path configTarget = dataFolder.resolve("config_old.yml");
		
		try {
			Files.move(configSource, configTarget, StandardCopyOption.REPLACE_EXISTING);
			URL configResource = getClass().getResource(ConfigType.DEFAULT_CONFIG.getClasspathResourceName());
			
			copyResource(configResource, configSource.toFile());
			
			ConsoleCommandSender sender = Bukkit.getConsoleSender();
			sender.sendMessage(ChatColor.RED + "Due to a HeavySpleef update your old configuration has been renamed");
			sender.sendMessage(ChatColor.RED + "to config_old.yml and a new one has been generated. Make sure to");
			sender.sendMessage(ChatColor.RED + "apply your old changes to the new config");
		} catch (IOException e) {
			getLogger().log(Level.SEVERE, "Could not create updated configuration due to an IOException", e);
		}
	}
}
 
Example #2
Source File: SubCommand_Recovery.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCommand(
        @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
    if (!(sender instanceof ConsoleCommandSender)) {
        return;
    }
    File file = new File(plugin.getDataFolder(), "recovery.txt");
    if (!file.exists()) {
        MsgUtil.sendMessage(sender, "recovery.txt not exist, do not execute this command unless you know what are you doing.");
        return;
    }
    new BukkitRunnable() {
        @Override
        public void run() {
            try {
                Util.backupDatabase();
                plugin.getShopLoader().recoverFromFile(Util.readToString(file));
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }.runTaskAsynchronously(plugin);

}
 
Example #3
Source File: HelpCommand.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof ConsoleCommandSender) {
        HandleHelpPage(sender, 1);
        return true;
    }

    if (args.length == 0) {
        HandleHelpPage(sender, 1);
        return true;
    }

    if (args.length == 1) {
        try {
            int page = Integer.parseInt(args[0]);
            HandleHelpPage(sender, page);
            return true;
        } catch (NumberFormatException ignored) {
        }
    }

    RedProtect.get().lang.sendCommandHelp(sender, "help", true);
    return true;
}
 
Example #4
Source File: DeleteCommand.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof ConsoleCommandSender) {
        HandleHelpPage(sender, 1);
        return true;
    }

    Player player = (Player) sender;

    if (args.length == 0) {
        handleDelete(player);
        return true;
    }
    if (args.length == 1) {
        handleDeleteName(player, args[0], "");
        return true;
    }
    if (args.length == 2) {
        handleDeleteName(player, args[0], args[1]);
        return true;
    }

    RedProtect.get().lang.sendCommandHelp(sender, "delete", true);
    return true;
}
 
Example #5
Source File: GenericCommandHelpTopic.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public boolean canSee(CommandSender sender) {
    if (!command.isRegistered()) {
        // Unregistered commands should not show up in the help
        return false;
    }

    if (sender instanceof ConsoleCommandSender) {
        return true;
    }

    if (amendedPermission != null) {
        return sender.hasPermission(amendedPermission);
    } else {
        return command.testPermissionSilent(sender);
    }
}
 
Example #6
Source File: BorderCommand.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof ConsoleCommandSender) {
        HandleHelpPage(sender, 1);
        return true;
    }

    Player player = (Player) sender;

    if (args.length == 0) {
        Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
        if (r != null) {
            RedProtect.get().getUtil().addBorder(player, r);
        } else {
            RedProtect.get().lang.sendMessage(player, "cmdmanager.region.todo.that");
        }
        return true;
    }

    RedProtect.get().lang.sendCommandHelp(sender, "border", true);
    return true;
}
 
Example #7
Source File: PurgeTaskTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldStopTaskAndInformConsoleUser() {
    // given
    Set<String> names = newHashSet("name1", "name2");
    PurgeTask task = new PurgeTask(purgeService, permissionsManager, null, names, new OfflinePlayer[0]);

    BukkitTask bukkitTask = mock(BukkitTask.class);
    given(bukkitTask.getTaskId()).willReturn(10049);
    ReflectionTestUtils.setField(BukkitRunnable.class, task, "task", bukkitTask);

    Server server = mock(Server.class);
    BukkitScheduler scheduler = mock(BukkitScheduler.class);
    given(server.getScheduler()).willReturn(scheduler);
    ReflectionTestUtils.setField(Bukkit.class, null, "server", server);
    ConsoleCommandSender consoleSender = mock(ConsoleCommandSender.class);
    given(server.getConsoleSender()).willReturn(consoleSender);

    task.run(); // Run for the first time -> results in empty names list

    // when
    task.run();

    // then
    verify(scheduler).cancelTask(task.getTaskId());
    verify(consoleSender).sendMessage(argThat(containsString("Database has been purged successfully")));
}
 
Example #8
Source File: Util.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
public void logToFile(String message) {
	ConsoleCommandSender console = SkyWarsReloaded.get().getServer().getConsoleSender();
	console.sendMessage(message);

    try {
        File dataFolder = SkyWarsReloaded.get().getDataFolder();
        if (dataFolder.exists() || dataFolder.mkdir()) {
            File saveTo = new File(dataFolder, "DebugLog.txt");
            if (saveTo.exists() || saveTo.createNewFile()) {
                FileWriter fw = new FileWriter(saveTo, true);
                PrintWriter pw = new PrintWriter(fw);
                pw.println(ChatColor.stripColor(message));
                pw.flush();
                pw.close();
            }
        }
    } catch(IOException e){
        e.printStackTrace();
    }
}
 
Example #9
Source File: PurgeLimitCommand.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof ConsoleCommandSender || !RedProtect.get().config.configRoot().purge.enabled) {
        HandleHelpPage(sender, 1);
        return true;
    }

    Player player = (Player) sender;

    int limit = RedProtect.get().ph.getPurgeLimit(player);
    long amount = RedProtect.get().rm.getCanPurgePlayer(player.getUniqueId().toString(), player.getWorld().getName());
    RedProtect.get().lang.sendMessage(player, "playerlistener.region.purge-limit", new Replacer[]{
            new Replacer("{limit}", String.valueOf(limit)),
            new Replacer("{total}", String.valueOf(amount))
    });
    return true;
}
 
Example #10
Source File: MultipleCommandAliasHelpTopic.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public boolean canSee(CommandSender sender) {
    if (amendedPermission == null) {
        if (sender instanceof ConsoleCommandSender) {
            return true;
        }

        for (Command command : alias.getCommands()) {
            if (!command.testPermissionSilent(sender)) {
                return false;
            }
        }

        return true;
    } else {
        return sender.hasPermission(amendedPermission);
    }
}
 
Example #11
Source File: WelcomeCommand.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof ConsoleCommandSender) {
        HandleHelpPage(sender, 1);
        return true;
    }

    Player player = (Player) sender;

    if (args.length >= 1) {
        StringBuilder wMessage = new StringBuilder();
        if (args[0].equals("off")) {
            handleWelcome(player, wMessage.toString());
            return true;
        } else {
            for (String arg : args) {
                wMessage.append(arg).append(" ");
            }
            handleWelcome(player, wMessage.toString());
            return true;
        }
    }

    RedProtect.get().lang.sendCommandHelp(sender, "welcome", true);
    return true;
}
 
Example #12
Source File: CustomCommandExecutor.java    From 1.13-Command-API with Apache License 2.0 6 votes vote down vote up
private int executeResultingExecutor(CommandSender sender, Object[] args) throws WrapperCommandSyntaxException {
	if(sender instanceof Player && rEx.stream().anyMatch(o -> o.getType() == ExecutorType.PLAYER)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.PLAYER).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof Entity && rEx.stream().anyMatch(o -> o.getType() == ExecutorType.ENTITY)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.ENTITY).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof ConsoleCommandSender && rEx.stream().anyMatch(o -> o.getType() == ExecutorType.CONSOLE)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.CONSOLE).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof BlockCommandSender && rEx.stream().anyMatch(o -> o.getType() == ExecutorType.BLOCK)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.BLOCK).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof ProxiedCommandSender && ex.stream().anyMatch(o -> o.getType() == ExecutorType.PROXY)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.PROXY).findFirst().get().executeWith(sender, args);
	} else if(rEx.stream().anyMatch(o -> o.getType() == ExecutorType.ALL)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.ALL).findFirst().get().executeWith(sender, args);
	} else {
		throw new WrapperCommandSyntaxException(
			new SimpleCommandExceptionType(
				new LiteralMessage("This command has no implementations for " + sender.getClass().getSimpleName().toLowerCase())
			).create()
		); 
	}
}
 
Example #13
Source File: Injector.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
private static Field getPermField(CommandSender sender)
{
    Field perm = null;
    try
    {
        if (sender instanceof Player)
        {
            perm = Class.forName(getVersionedClassName("entity.CraftHumanEntity")).getDeclaredField("perm");
        }
        else if (sender instanceof ConsoleCommandSender)
        {
            perm = Class.forName(getVersionedClassName("command.ServerCommandSender")).getDeclaredField("perm");
        }
    }
    catch (Exception e)
    {
        BungeePerms.getInstance().getDebug().log(e);
    }
    return perm;
}
 
Example #14
Source File: EntityAPICore.java    From EntityAPI with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void initializeGameComponents() {
    try {

        Class<? extends IEntityRegistry> entityRegistry = Class.forName(EntityAPI.INTERNAL_NMS_PATH + ".game.EntityRegistry").asSubclass(IEntityRegistry.class);
        GameRegistry.registerPermanently(IEntityRegistry.class, new Reflection().reflect(entityRegistry).getSafeConstructor().getAccessor().invoke());

        Class<? extends IEntitySpawnHandler> spawnHandler = Class.forName(EntityAPI.INTERNAL_NMS_PATH + ".game.EntitySpawnHandler").asSubclass(IEntitySpawnHandler.class);
        GameRegistry.register(IEntitySpawnHandler.class, new Reflection().reflect(spawnHandler).getSafeConstructor().getAccessor().invoke());

    } catch (Exception e) {
        ConsoleCommandSender console = this.getServer().getConsoleSender();
        console.sendMessage(ChatColor.RED + "-------------------------------");
        console.sendMessage(ChatColor.RED + "Failed to initialize the game components!");
        console.sendMessage(ChatColor.RED + "-------------------------------");
    }
}
 
Example #15
Source File: BroadcastScheduler.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Inject BroadcastScheduler(Loggers loggers,
                           @Named("configuration") Path configPath,
                           Scheduler scheduler,
                           ConsoleCommandSender console,
                           OnlinePlayers onlinePlayers,
                           LocalizedMessageMap.Factory messageMapFactory,
                           DocumentWatcher.Factory<List<BroadcastSchedule>> documentWatcherFactory,
                           Server localServer,
                           BroadcastFormatter formatter,
                           ComponentRenderContext renderer,
                           BroadcastSettings settings) {

    this.logger = loggers.get(getClass());
    this.configPath = configPath;
    this.configFile = configPath.resolve(CONFIG_FILE);
    this.scheduler = scheduler;
    this.console = console;
    this.onlinePlayers = onlinePlayers;
    this.messageMapFactory = messageMapFactory;
    this.documentWatcherFactory = documentWatcherFactory;
    this.localServer = localServer;
    this.formatter = formatter;
    this.renderer = renderer;
    this.settings = settings;
}
 
Example #16
Source File: MultipleCommandAliasHelpTopic.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public boolean canSee(CommandSender sender) {
    if (amendedPermission == null) {
        if (sender instanceof ConsoleCommandSender) {
            return true;
        }

        for (Command command : alias.getCommands()) {
            if (!command.testPermissionSilent(sender)) {
                return false;
            }
        }

        return true;
    } else {
        return sender.hasPermission(amendedPermission);
    }
}
 
Example #17
Source File: BungeeGuardBackendPlugin.java    From BungeeGuard with MIT License 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!(sender instanceof ConsoleCommandSender)) {
        sender.sendMessage(ChatColor.RED + "Sorry, this command can only be ran from the console.");
        return true;
    }

    if (args.length == 0 || !args[0].equalsIgnoreCase("reload")) {
        sender.sendMessage(ChatColor.RED + "Running BungeeGuard v" + getDescription().getVersion());
        sender.sendMessage(ChatColor.GRAY + "Use '/bungeeguard reload' to reload the configuration.");
        return true;
    }

    this.tokenStore.reload();
    sender.sendMessage(ChatColor.RED + "BungeeGuard configuration reloaded.");
    return true;
}
 
Example #18
Source File: SelectWECommand.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof ConsoleCommandSender || !RedProtect.get().ph.hasCommandPerm(sender, "select-we")) {
        HandleHelpPage(sender, 1);
        return true;
    }

    Player player = (Player) sender;

    if (args.length == 0) {
        if (RedProtect.get().hooks.worldEdit) {
            Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
            if (r == null) {
                RedProtect.get().lang.sendMessage(player, "cmdmanager.region.doesexists");
                return true;
            }
            WEHook.setSelectionFromRP(player, r.getMinLocation(), r.getMaxLocation());
        }
        return true;
    }

    RedProtect.get().lang.sendCommandHelp(sender, "select-we", true);
    return true;
}
 
Example #19
Source File: UCChannel.java    From UltimateChat with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Send a message from a channel as console.
 *
 * @param sender  {@code ConsoleCommandSender} - Console sender.
 * @param message {@code FancyMessage} - Message to send.
 * @param direct  {@code boolean} - Send message direct to players on channel.
 */
public void sendMessage(ConsoleCommandSender sender, UltimateFancy message, boolean direct) {
    if (direct) {
        for (Player p : Bukkit.getOnlinePlayers()) {
            UCChannel chp = UChat.get().getPlayerChannel(p);
            if (UCPerms.channelReadPerm(p, this) && !this.isIgnoring(p.getName()) && (!this.neeFocus() || chp.equals(this))) {
                UChat.get().getUCLogger().timings(timingType.START, "UCChannel#sendMessage()|Direct Message");
                message.send(p);
            }
        }
        message.send(sender);
    } else {
        UChat.get().getUCLogger().timings(timingType.START, "UCChannel#sendMessage()|Fire MessageChannelEvent");
        Bukkit.getScheduler().runTask(UChat.get(), () -> UCMessages.sendFancyMessage(new String[0], message.toOldFormat(), this, sender, null));
    }
}
 
Example #20
Source File: Command.java    From HubBasics with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String name, @NotNull String[] args) {
    if (this.permissions.size() > 0) {
        for (String perm : this.permissions) {
            if (!sender.hasPermission(perm)) {
                HubBasics.getMessenger().send(sender, Messages.get(sender, "NO_PERMISSION"));
                return true;
            }
        }
    }
    try {
        if (sender instanceof Player) {
            this.execute((Player) sender, args);
        } else if (sender instanceof ConsoleCommandSender) { // Is commandblock a Console?
            this.execute((ConsoleCommandSender) sender, args);
        }
        this.execute(sender, args); // Always execute the "universal" one
    } catch (Exception ex) {
        logger.error("Error while executing command (" + getName() + ")", ex);
    }
    return true;
}
 
Example #21
Source File: PermissibleMonitoringInjector.java    From LuckPerms with MIT License 6 votes vote down vote up
private void injectConsole() throws Exception {
    ConsoleCommandSender consoleSender = this.plugin.getBootstrap().getServer().getConsoleSender();

    // get the ServerCommandSender class
    Class<?> serverCommandSenderClass = CraftBukkitImplementation.obcClass("command.ServerCommandSender");

    // get the perm field
    Field permField = serverCommandSenderClass.getDeclaredField("perm");
    permField.setAccessible(true);

    // get the PermissibleBase instance
    PermissibleBase permBase = (PermissibleBase) permField.get(consoleSender);

    // create a new instance which delegates to the previous PermissibleBase
    PermissibleBase newPermBase = transform(permBase, "internal/console");
    if (newPermBase == null) {
        return;
    }

    // inject the new instance
    permField.set(consoleSender, newPermBase);
}
 
Example #22
Source File: RemoveMemberCommand.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length == 3 && (sender instanceof ConsoleCommandSender || RedProtect.get().ph.hasPerm(sender, "redprotect.command.admin.removemember"))) {
        World w = RedProtect.get().getServer().getWorld(args[2]);
        if (w == null) {
            RedProtect.get().lang.sendMessage(sender, RedProtect.get().lang.get("cmdmanager.region.invalidworld"));
            return true;
        }
        Region r = RedProtect.get().rm.getRegion(args[1], w.getName());
        if (r == null) {
            RedProtect.get().lang.sendMessage(sender, RedProtect.get().lang.get("cmdmanager.region.doesntexist") + ": " + args[1]);
            return true;
        }
        handleRemoveMember(sender, args[0], r);
        return true;
    } else if (sender instanceof Player) {
        Player player = (Player) sender;

        if (args.length == 1) {
            handleRemoveMember(player, args[0], null);
            return true;
        }
    }

    RedProtect.get().lang.sendCommandHelp(sender, "removemember", true);
    return true;
}
 
Example #23
Source File: ValueCommand.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof ConsoleCommandSender) {
        HandleHelpPage(sender, 1);
        return true;
    }

    Player player = (Player) sender;

    if (args.length == 0) {
        Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
        if (r != null) {
            if (RedProtect.get().ph.hasRegionPermLeader(player, "value", r)) {
                if (r.getArea() <= RedProtect.get().config.ecoRoot().max_area_toget_value) {
                    r.setValue(EconomyManager.getRegionValue(r));
                    RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.value.is").replace("{value}", EconomyManager.getFormatted(r.getValue()) + " " + RedProtect.get().config.ecoRoot().economy_name));

                    RedProtect.get().logger.debug(LogLevel.DEFAULT, "Region Value: " + r.getValue());
                    return true;
                } else {
                    RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.value.areabig").replace("{maxarea}", String.valueOf(RedProtect.get().config.ecoRoot().max_area_toget_value)));
                    return true;
                }
            } else {
                RedProtect.get().lang.sendMessage(player, "playerlistener.region.cantuse");
                return true;
            }
        } else {
            RedProtect.get().lang.sendMessage(player, "cmdmanager.region.todo.that");
            return true;
        }
    }

    RedProtect.get().lang.sendCommandHelp(sender, "value", true);
    return true;
}
 
Example #24
Source File: CustomHelpTopic.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public boolean canSee(CommandSender sender) {
    if (sender instanceof ConsoleCommandSender) {
        return true;
    }

    if (!permissionNode.equals("")) {
        return sender.hasPermission(permissionNode);
    } else {
        return true;
    }
}
 
Example #25
Source File: CommandHandler.java    From MCAuthenticator with GNU General Public License v3.0 5 votes vote down vote up
private boolean printHelp(CommandSender commandSender, String label) {
    int i = 1;

    StringBuilder sb = new StringBuilder("&7Possible commands are: ");
    for (AuthCommand c : commands.values()) {
        if(commandSender.hasPermission(c.getPermission()) ||
                (commandSender instanceof ConsoleCommandSender))
            sb.append(String.format("\n &8%d. &7/%s %s &8- &7%s", i++, label, c.getName(), c.getDesc()));
    }

    instance.getC().sendDirect(commandSender, sb.toString());
    return true;
}
 
Example #26
Source File: CommandHandler.java    From MCAuthenticator with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender commandSender, Command cmd, String commandLabel, String[] args) {

    if(!commandSender.hasPermission("mcauthenticator.use")) {
        instance.getC().sendDirect(commandSender, "&cYou do not have permission to use the authenticator!");
        return true;
    }

    if (args.length == 0) return printHelp(commandSender, commandLabel);

    AuthCommand c = commands.get(args[0].toLowerCase());
    String[] newArgs = Arrays.copyOfRange(args, 1, args.length);

    if (c == null) {
        instance.getC().sendDirect(commandSender, "&cUnknown subcommand!");
        return printHelp(commandSender, commandLabel);
    }

    if (c.getPermission() != null && !commandSender.hasPermission(c.getPermission()) && !(commandSender instanceof ConsoleCommandSender)) {
        instance.getC().sendDirect(commandSender, "&cYou do not have permission to perform this action!");
        return true;
    }

    try {
        c.execute(cmd, commandSender, newArgs);
    } catch (RuntimeException e) {
        instance.handleException(e);
    }

    return true;
}
 
Example #27
Source File: Pos1Command.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof ConsoleCommandSender) {
        HandleHelpPage(sender, 1);
        return true;
    }

    Player player = (Player) sender;

    String claimmode = RedProtect.get().config.getWorldClaimType(player.getWorld().getName());
    if (!claimmode.equalsIgnoreCase("WAND") && !claimmode.equalsIgnoreCase("BOTH") && !RedProtect.get().ph.hasCommandPerm(player, "redefine")) {
        return true;
    }

    if (args.length == 0) {
        Location pl = player.getLocation();
        RedProtect.get().firstLocationSelections.put(player, pl);
        player.sendMessage(RedProtect.get().lang.get("playerlistener.wand1") + RedProtect.get().lang.get("general.color") + " (" + ChatColor.GOLD + pl.getBlockX() + RedProtect.get().lang.get("general.color") + ", " + ChatColor.GOLD + pl.getBlockY() + RedProtect.get().lang.get("general.color") + ", " + ChatColor.GOLD + pl.getBlockZ() + RedProtect.get().lang.get("general.color") + ").");

        //show preview border
        if (RedProtect.get().firstLocationSelections.containsKey(player) && RedProtect.get().secondLocationSelections.containsKey(player)) {
            Location loc1 = RedProtect.get().firstLocationSelections.get(player);
            Location loc2 = RedProtect.get().secondLocationSelections.get(player);
            if (RedProtect.get().hooks.worldEdit && RedProtect.get().config.configRoot().hooks.useWECUI) {
                WEHook.setSelectionRP(player, loc1, loc2);
            }

            if (loc1.getWorld().equals(loc2.getWorld()) && loc1.distanceSquared(loc2) > RedProtect.get().config.configRoot().region_settings.max_scan) {
                double dist = loc1.distanceSquared(loc2);
                RedProtect.get().lang.sendMessage(player, String.format(RedProtect.get().lang.get("regionbuilder.selection.maxdefine"), RedProtect.get().config.configRoot().region_settings.max_scan, (int) dist));
            } else {
                RedProtect.get().getUtil().addBorder(player, new Region("", loc1, loc2, player.getWorld().getName()));
            }
        }
        return true;
    }

    RedProtect.get().lang.sendCommandHelp(sender, "pos1", true);
    return true;
}
 
Example #28
Source File: HelpCommand.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void sendConsoleHelp(ConsoleCommandSender console) {
    console.sendMessage(i18nonly("help_title_console").replace("%version%", "Zero " + Main.getVersion()));
    console.sendMessage(i18nonly("help_bw_list"));
    console.sendMessage(i18nonly("help_bw_stats_other"));
    console.sendMessage(i18nonly("help_bw_alljoin"));
    console.sendMessage(i18nonly("help_bw_reload"));
}
 
Example #29
Source File: BukkitCommandExecutor.java    From LuckPerms with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onConsoleCommand(ServerCommandEvent e) {
    if (!(e.getSender() instanceof ConsoleCommandSender)) {
        return;
    }

    String buffer = e.getCommand();
    if (buffer.isEmpty() || buffer.charAt(0) != '/') {
        return;
    }

    buffer = buffer.substring(1);

    String commandLabel;
    int firstSpace = buffer.indexOf(' ');
    if (firstSpace == -1) {
        commandLabel = buffer;
    } else {
        commandLabel = buffer.substring(0, firstSpace);
    }

    Command command = CommandMapUtil.getCommandMap(this.plugin.getBootstrap().getServer()).getCommand(commandLabel);
    if (command != this.command) {
        return;
    }

    e.setCommand(buffer);
}
 
Example #30
Source File: AddAdminCommand.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length == 3 && (sender instanceof ConsoleCommandSender || RedProtect.get().ph.hasPerm(sender, "redprotect.command.admin.addadmin"))) {
        World w = RedProtect.get().getServer().getWorld(args[2]);
        if (w == null) {
            RedProtect.get().lang.sendMessage(sender, RedProtect.get().lang.get("cmdmanager.region.invalidworld"));
            return true;
        }
        Region r = RedProtect.get().rm.getRegion(args[1], w.getName());
        if (r == null) {
            RedProtect.get().lang.sendMessage(sender, RedProtect.get().lang.get("cmdmanager.region.doesntexist") + ": " + args[1]);
            return true;
        }
        handleAddAdmin(sender, args[0], r);
        return true;
    } else if (sender instanceof Player) {
        Player player = (Player) sender;

        if (args.length == 1) {
            handleAddAdmin(player, args[0], null);
            return true;
        }
    }

    RedProtect.get().lang.sendCommandHelp(sender, "addadmin", true);
    return true;
}