org.bukkit.command.Command.broadcastCommandMessage()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中org.bukkit.command.Command.broadcastCommandMessage()方法的一些代码示例,展示了Command.broadcastCommandMessage()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Command.broadcastCommandMessage()方法的具体详情如下:
包路径:org.bukkit.command.Command
类名称:Command
方法名:broadcastCommandMessage

Command.broadcastCommandMessage介绍

暂无

代码示例

代码示例来源:origin: Bukkit/Bukkit

public static void broadcastCommandMessage(CommandSender source, String message) {
  broadcastCommandMessage(source, message, true);
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  Command.broadcastCommandMessage(sender, "Forcing save..");
  Bukkit.savePlayers();
  for (World world : Bukkit.getWorlds()) {
    world.save();
  }
  Command.broadcastCommandMessage(sender, "Save complete.");
  return true;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender)) return true;

    Bukkit.reload();
    Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete.");

    return true;
  }
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  if (args.length != 1)  {
    sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
    return false;
  }
  if (BanIpCommand.ipValidity.matcher(args[0]).matches()) {
    Bukkit.unbanIP(args[0]);
    Command.broadcastCommandMessage(sender, "Pardoned ip " + args[0]);
  } else {
    sender.sendMessage("Invalid ip");
  }
  return true;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  if (args.length != 1 || args[0].length() == 0)  {
    sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
    return false;
  }
  OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
  player.setOp(true);
  Command.broadcastCommandMessage(sender, "Opped " + args[0]);
  return true;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  for (World world : Bukkit.getWorlds()) {
    world.setAutoSave(false);
  }
  Command.broadcastCommandMessage(sender, "Disabled level saving..");
  return true;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  for (World world : Bukkit.getWorlds()) {
    world.setAutoSave(true);
  }
  Command.broadcastCommandMessage(sender, "Enabled level saving..");
  return true;
}

代码示例来源:origin: Bukkit/Bukkit

private void processIPBan(String ip, CommandSender sender, String reason) {
  Bukkit.getBanList(BanList.Type.IP).addBan(ip, reason, null, sender.getName());
  // Find all matching players and kick
  for (Player player : Bukkit.getOnlinePlayers()) {
    if (player.getAddress().getAddress().getHostAddress().equals(ip)) {
      player.kickPlayer("You have been IP banned.");
    }
  }
  Command.broadcastCommandMessage(sender, "Banned IP Address " + ip);
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
  if (!testPermission(sender)) return true;
  if (args.length == 0) {
    sender.sendMessage("Usage: " + usageMessage);
    return false;
  }
  String modeArg = args[0];
  int value = -1;
  try {
    value = Integer.parseInt(modeArg);
  } catch (NumberFormatException ex) {}
  GameMode mode = GameMode.getByValue(value);
  if (mode == null) {
    if (modeArg.equalsIgnoreCase("creative") || modeArg.equalsIgnoreCase("c")) {
      mode = GameMode.CREATIVE;
    } else if (modeArg.equalsIgnoreCase("adventure") || modeArg.equalsIgnoreCase("a")) {
      mode = GameMode.ADVENTURE;
    } else {
      mode = GameMode.SURVIVAL;
    }
  }
  Bukkit.getServer().setDefaultGameMode(mode);
  Command.broadcastCommandMessage(sender, "Default game mode set to " + mode.toString().toLowerCase());
  return true;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  Command.broadcastCommandMessage(sender, "Stopping the server..");
  Bukkit.shutdown();
  String reason = this.createString(args, 0);
  if (StringUtils.isNotEmpty(reason)) {
    for (Player player : Bukkit.getOnlinePlayers()) {
      player.kickPlayer(reason);
    }
  }
  return true;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  if (args.length != 1)  {
    sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
    return false;
  }
  Bukkit.getBanList(BanList.Type.NAME).pardon(args[0]);
  Command.broadcastCommandMessage(sender, "Pardoned " + args[0]);
  return true;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  if (args.length != 1 || args[0].length() == 0) {
    sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
    return false;
  }
  OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
  player.setOp(false);
  if (player instanceof Player) {
    ((Player) player).sendMessage(ChatColor.YELLOW + "You are no longer op!");
  }
  Command.broadcastCommandMessage(sender, "De-opped " + args[0]);
  return true;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  if (args.length == 0) {
    sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
    return false;
  }
  int duration = (300 + new Random().nextInt(600)) * 20;
  if (args.length >= 2) {
    duration = getInteger(sender, args[1], 1, 1000000) * 20;
  }
  World world = Bukkit.getWorlds().get(0);
  world.setWeatherDuration(duration);
  world.setThunderDuration(duration);
  if ("clear".equalsIgnoreCase(args[0])) {
    world.setStorm(false);
    world.setThundering(false);
    Command.broadcastCommandMessage(sender, "Changed weather to clear for " + (duration / 20) + " seconds.");
  } else if ("rain".equalsIgnoreCase(args[0])) {
    world.setStorm(true);
    world.setThundering(false);
    Command.broadcastCommandMessage(sender, "Changed weather to rainy for " + (duration / 20) + " seconds.");
  } else if ("thunder".equalsIgnoreCase(args[0])) {
    world.setStorm(true);
    world.setThundering(true);
    Command.broadcastCommandMessage(sender, "Changed weather to thundering " + (duration / 20) + " seconds.");
  }
  return true;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  if (args.length == 1) {
    int minutes;
    try {
      minutes = getInteger(sender, args[0], 0, Integer.MAX_VALUE, true);
    } catch (NumberFormatException ex) {
      sender.sendMessage(ex.getMessage());
      return true;
    }
    Bukkit.getServer().setIdleTimeout(minutes);
    Command.broadcastCommandMessage(sender, "Successfully set the idle timeout to " + minutes + " minutes.");
    return true;
  }
  sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
  return false;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  if (args.length == 0)  {
    sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
    return false;
  }
  String reason = args.length > 0 ? StringUtils.join(args, ' ', 1, args.length) : null;
  Bukkit.getBanList(BanList.Type.NAME).addBan(args[0], reason, null, sender.getName());
  Player player = Bukkit.getPlayer(args[0]);
  if (player != null) {
    player.kickPlayer("Banned by admin.");
  }
  Command.broadcastCommandMessage(sender, "Banned player " + args[0]);
  return true;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  if (args.length < 1 || args[0].length() == 0) {
    sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
    return false;
  }
  Player player = Bukkit.getPlayerExact(args[0]);
  if (player != null) {
    String reason = "Kicked by an operator.";
    if (args.length > 1) {
      reason = createString(args, 1);
    }
    player.kickPlayer(reason);
    Command.broadcastCommandMessage(sender, "Kicked player " + player.getName() + ". With reason:\n" + reason);
  } else {
    sender.sendMessage( args[0] + " not found.");
  }
  return true;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  if (args.length != 1 || args[0].length() == 0) {
    sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
    return false;
  }
  Difficulty difficulty = Difficulty.getByValue(getDifficultyForString(sender, args[0]));
  if (Bukkit.isHardcore()) {
    difficulty = Difficulty.HARD;
  }
  Bukkit.getWorlds().get(0).setDifficulty(difficulty);
  int levelCount = 1;
  if (Bukkit.getAllowNether()) {
    Bukkit.getWorlds().get(levelCount).setDifficulty(difficulty);
    levelCount++;
  }
  if (Bukkit.getAllowEnd()) {
    Bukkit.getWorlds().get(levelCount).setDifficulty(difficulty);
  }
  Command.broadcastCommandMessage(sender, "Set difficulty to " + difficulty.toString());
  return true;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  World world = null;
  if (args.length == 1) {
    world = Bukkit.getWorld(args[0]);
    if (world == null) {
      sender.sendMessage(ChatColor.RED + "No world exists with the name '" + args[0] + "'");
      return true;
    }
  } else if (sender instanceof Player) {
    world = ((Player) sender).getWorld();
  } else {
    world = Bukkit.getWorlds().get(0);
  }
  Command.broadcastCommandMessage(sender, "Toggling downfall " + (world.hasStorm() ? "off" : "on") + " for world '" + world.getName() + "'");
  world.setStorm(!world.hasStorm());
  return true;
}

代码示例来源:origin: Bukkit/Bukkit

int count = player.getInventory().clear(id, data);
  Command.broadcastCommandMessage(sender, "Cleared the inventory of " + player.getDisplayName() + ", removing " + count + " items");
} else if (args.length == 0) {
  sender.sendMessage(ChatColor.RED + "Please provide a player!");

代码示例来源:origin: Bukkit/Bukkit

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
  if (!testPermission(sender)) return true;
  if (args.length > 0) {
    String rule = args[0];
    World world = getGameWorld(sender);
    if (world.isGameRule(rule)) {
      if (args.length > 1) {
        String value = args[1];
        world.setGameRuleValue(rule, value);
        Command.broadcastCommandMessage(sender, "Game rule " + rule + " has been set to: " + value);
      } else {
        String value = world.getGameRuleValue(rule);
        sender.sendMessage(rule + " = " + value);
      }
    } else {
      sender.sendMessage(ChatColor.RED + "No game rule called " + rule + " is available");
    }
    return true;
  } else {
    sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
    sender.sendMessage("Rules: " + this.createString(getGameWorld(sender).getGameRules(), 0, ", "));
    return true;
  }
}

相关文章