コード例 #1
0
ファイル: ColorMap.java プロジェクト: hef/IRCTransport
 // Setup the irc <-> minecraft color mappings.
 static {
   ircToMinecraftColor.put(Colors.WHITE, ChatColor.WHITE.toString()); // black
   ircToMinecraftColor.put(Colors.BLACK, ChatColor.BLACK.toString()); // white
   ircToMinecraftColor.put(Colors.DARK_BLUE, ChatColor.DARK_BLUE.toString()); // dark_blue
   ircToMinecraftColor.put(Colors.DARK_GREEN, ChatColor.DARK_GREEN.toString()); // dark_green
   ircToMinecraftColor.put(Colors.RED, ChatColor.RED.toString()); // red
   ircToMinecraftColor.put(Colors.BROWN, ChatColor.DARK_RED.toString()); // brown
   ircToMinecraftColor.put(Colors.PURPLE, ChatColor.DARK_PURPLE.toString()); // purple
   ircToMinecraftColor.put(Colors.OLIVE, ChatColor.GOLD.toString()); // olive
   ircToMinecraftColor.put(Colors.YELLOW, ChatColor.YELLOW.toString()); // yellow
   ircToMinecraftColor.put(Colors.GREEN, ChatColor.GREEN.toString()); // green
   ircToMinecraftColor.put(Colors.TEAL, ChatColor.DARK_AQUA.toString()); // teal
   ircToMinecraftColor.put(Colors.CYAN, ChatColor.AQUA.toString()); // cyan
   ircToMinecraftColor.put(Colors.BLUE, ChatColor.BLUE.toString()); // blue
   ircToMinecraftColor.put(Colors.MAGENTA, ChatColor.LIGHT_PURPLE.toString()); // magenta
   ircToMinecraftColor.put(Colors.DARK_GRAY, ChatColor.DARK_GRAY.toString()); // dark_gray
   ircToMinecraftColor.put(Colors.LIGHT_GRAY, ChatColor.GRAY.toString()); // light_gray
   minecraftToIrcColor.put(ChatColor.WHITE.toString(), Colors.WHITE); // black
   minecraftToIrcColor.put(ChatColor.BLACK.toString(), Colors.BLACK); // white
   minecraftToIrcColor.put(ChatColor.DARK_BLUE.toString(), Colors.DARK_BLUE); // dark_blue
   minecraftToIrcColor.put(ChatColor.DARK_GREEN.toString(), Colors.DARK_GREEN); // dark_green
   minecraftToIrcColor.put(ChatColor.RED.toString(), Colors.RED); // red
   minecraftToIrcColor.put(ChatColor.DARK_RED.toString(), Colors.BROWN); // brown
   minecraftToIrcColor.put(ChatColor.DARK_PURPLE.toString(), Colors.PURPLE); // purple
   minecraftToIrcColor.put(ChatColor.GOLD.toString(), Colors.OLIVE); // olive
   minecraftToIrcColor.put(ChatColor.YELLOW.toString(), Colors.YELLOW); // yellow
   minecraftToIrcColor.put(ChatColor.GREEN.toString(), Colors.GREEN); // green
   minecraftToIrcColor.put(ChatColor.DARK_AQUA.toString(), Colors.TEAL); // teal
   minecraftToIrcColor.put(ChatColor.AQUA.toString(), Colors.CYAN); // cyan
   minecraftToIrcColor.put(ChatColor.BLUE.toString(), Colors.BLUE); // blue
   minecraftToIrcColor.put(ChatColor.LIGHT_PURPLE.toString(), Colors.MAGENTA); // magenta
   minecraftToIrcColor.put(ChatColor.DARK_GRAY.toString(), Colors.DARK_GRAY); // dark_gray
   minecraftToIrcColor.put(ChatColor.GRAY.toString(), Colors.LIGHT_GRAY); // light_gray
 }
コード例 #2
0
ファイル: spawns.java プロジェクト: SpleefLeague/Core
  @Override
  protected void run(Player p, SLPlayer slp, Command cmd, String[] args) {
    p.sendMessage(
        ChatColor.DARK_GRAY
            + "[ "
            + ChatColor.GRAY
            + "============ "
            + ChatColor.DARK_AQUA
            + "Spawns"
            + ChatColor.GRAY
            + " ============"
            + ChatColor.DARK_GRAY
            + " ]");

    ModifiableFinal<Integer> current = new ModifiableFinal<>(1);
    SpleefLeague.getInstance()
        .getSpawnManager()
        .getAll()
        .forEach(
            (SpawnManager.SpawnLocation spawnLocation) -> {
              ComponentBuilder componentBuilder =
                  new ComponentBuilder("#" + current.getValue())
                      .color(ChatColor.RED.asBungee())
                      .append(" | ")
                      .color(ChatColor.DARK_GRAY.asBungee())
                      .append("CLICK TO TELEPORT")
                      .color(ChatColor.GRAY.asBungee())
                      .event(
                          new ClickEvent(
                              ClickEvent.Action.RUN_COMMAND,
                              "/tppos "
                                  + spawnLocation.getLocation().getBlockX()
                                  + " "
                                  + spawnLocation.getLocation().getBlockY()
                                  + ' '
                                  + spawnLocation.getLocation().getBlockZ()))
                      .append(" | ")
                      .color(ChatColor.DARK_GRAY.asBungee())
                      .append(spawnLocation.getPlayersInRadius() + " players")
                      .color(ChatColor.GRAY.asBungee());
              slp.spigot().sendMessage(componentBuilder.create());
              current.setValue(current.getValue() + 1);
            });

    p.sendMessage(
        ChatColor.RED
            + "All spawns were cached "
            + TimeUtil.dateToString(
                new Date(SpleefLeague.getInstance().getSpawnManager().getLastCached()), false)
            + " ago.");
  }
コード例 #3
0
ファイル: ConsoleManager.java プロジェクト: kitskub/Glowstone
 private String colorize(String string) {
   if (string.indexOf(ChatColor.COLOR_CHAR) < 0) {
     return string; // no colors in the message
   } else if ((!jLine || !reader.getTerminal().isAnsiSupported()) && jTerminal == null) {
     return ChatColor.stripColor(string); // color not supported
   } else {
     return string
             .replace(ChatColor.RED.toString(), "\033[1;31m")
             .replace(ChatColor.YELLOW.toString(), "\033[1;33m")
             .replace(ChatColor.GREEN.toString(), "\033[1;32m")
             .replace(ChatColor.AQUA.toString(), "\033[1;36m")
             .replace(ChatColor.BLUE.toString(), "\033[1;34m")
             .replace(ChatColor.LIGHT_PURPLE.toString(), "\033[1;35m")
             .replace(ChatColor.BLACK.toString(), "\033[0;0m")
             .replace(ChatColor.DARK_GRAY.toString(), "\033[1;30m")
             .replace(ChatColor.DARK_RED.toString(), "\033[0;31m")
             .replace(ChatColor.GOLD.toString(), "\033[0;33m")
             .replace(ChatColor.DARK_GREEN.toString(), "\033[0;32m")
             .replace(ChatColor.DARK_AQUA.toString(), "\033[0;36m")
             .replace(ChatColor.DARK_BLUE.toString(), "\033[0;34m")
             .replace(ChatColor.DARK_PURPLE.toString(), "\033[0;35m")
             .replace(ChatColor.GRAY.toString(), "\033[0;37m")
             .replace(ChatColor.WHITE.toString(), "\033[1;37m")
         + "\033[0m";
   }
 }
コード例 #4
0
  /**
   * Replace color macros in a string. The macros are in the form of `[char] where char represents
   * the color. R is for red, Y is for yellow, G is for green, C is for cyan, B is for blue, and P
   * is for purple. The uppercase versions of those are the darker shades, while the lowercase
   * versions are the lighter shades. For white, it's 'w', and 0-2 are black, dark grey, and grey,
   * respectively.
   *
   * @param str
   * @return color-coded string
   */
  public static String replaceColorMacros(String str) {
    str = str.replace("&r", ChatColor.RED.toString());
    str = str.replace("&R", ChatColor.DARK_RED.toString());

    str = str.replace("&y", ChatColor.YELLOW.toString());
    str = str.replace("&Y", ChatColor.GOLD.toString());

    str = str.replace("&g", ChatColor.GREEN.toString());
    str = str.replace("&G", ChatColor.DARK_GREEN.toString());

    str = str.replace("&c", ChatColor.AQUA.toString());
    str = str.replace("&C", ChatColor.DARK_AQUA.toString());

    str = str.replace("&b", ChatColor.BLUE.toString());
    str = str.replace("&B", ChatColor.DARK_BLUE.toString());

    str = str.replace("&p", ChatColor.LIGHT_PURPLE.toString());
    str = str.replace("&P", ChatColor.DARK_PURPLE.toString());

    str = str.replace("&0", ChatColor.BLACK.toString());
    str = str.replace("&1", ChatColor.DARK_GRAY.toString());
    str = str.replace("&2", ChatColor.GRAY.toString());
    str = str.replace("&w", ChatColor.WHITE.toString());

    return str;
  }
コード例 #5
0
ファイル: ConsoleManager.java プロジェクト: Raphfrk/Glowstone
 public String colorize(String string) {
   if (!string.contains("\u00A7")) {
     return string;
   } else if ((!jLine || !reader.getTerminal().isANSISupported()) && jTerminal == null) {
     return ChatColor.stripColor(string);
   } else {
     return string
             .replace(ChatColor.RED.toString(), "\033[1;31m")
             .replace(ChatColor.YELLOW.toString(), "\033[1;33m")
             .replace(ChatColor.GREEN.toString(), "\033[1;32m")
             .replace(ChatColor.AQUA.toString(), "\033[1;36m")
             .replace(ChatColor.BLUE.toString(), "\033[1;34m")
             .replace(ChatColor.LIGHT_PURPLE.toString(), "\033[1;35m")
             .replace(ChatColor.BLACK.toString(), "\033[0;0m")
             .replace(ChatColor.DARK_GRAY.toString(), "\033[1;30m")
             .replace(ChatColor.DARK_RED.toString(), "\033[0;31m")
             .replace(ChatColor.GOLD.toString(), "\033[0;33m")
             .replace(ChatColor.DARK_GREEN.toString(), "\033[0;32m")
             .replace(ChatColor.DARK_AQUA.toString(), "\033[0;36m")
             .replace(ChatColor.DARK_BLUE.toString(), "\033[0;34m")
             .replace(ChatColor.DARK_PURPLE.toString(), "\033[0;35m")
             .replace(ChatColor.GRAY.toString(), "\033[0;37m")
             .replace(ChatColor.WHITE.toString(), "\033[1;37m")
         + "\033[0m";
   }
 }
コード例 #6
0
ファイル: Features.java プロジェクト: superlode/Features
  public static String getColor(Player player, LivingEntity target) {
    if ((target instanceof Player)) {
      for (String arg : default_colours.keySet()) {
        if (((arg.equals("op")) && (((Player) target).isOp()))
            || (arg.equals("default"))
            || (((Player) target).hasPermission(arg))) {
          String color = (String) default_colours.get(arg);
          if (color.matches("[0-9a-f]")) {
            return new StringBuilder().append("§").append(color).toString();
          }
          return ChatColor.valueOf(color.toUpperCase()).toString();
        }
      }
      return ((Player) target).isOp() ? ChatColor.GOLD.toString() : ChatColor.YELLOW.toString();
    }
    if ((target instanceof Monster)) {
      if ((player != null) && (player.equals(((Monster) target).getTarget()))) {
        return ChatColor.RED.toString();
      }
      return ChatColor.YELLOW.toString();
    }
    if ((target instanceof WaterMob)) return ChatColor.GREEN.toString();
    if ((target instanceof Flying)) return ChatColor.YELLOW.toString();
    if ((target instanceof Animals)) {
      if ((player != null) && (player.equals(((Animals) target).getTarget())))
        return ChatColor.RED.toString();
      if ((target instanceof Tameable)) {
        Tameable pet = (Tameable) target;
        if (pet.isTamed()) {
          return ChatColor.GREEN.toString();
        }
        return ChatColor.YELLOW.toString();
      }

      return ChatColor.GRAY.toString();
    }

    return ChatColor.GRAY.toString();
  }
コード例 #7
0
ファイル: CommandLogout.java プロジェクト: averlieren/DR-old
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    Player p = (Player) sender;
    double seconds_left = 3;
    if (DuelMechanics.isDamageDisabled(p.getLocation())) {
      // They're in a safe zone, no need for this.
      p.kickPlayer(
          ChatColor.GREEN.toString()
              + "You have safely logged out."
              + "\n\n"
              + ChatColor.GRAY.toString()
              + "Your player data has been synced.");
      return true;
    }

    if (HealthMechanics.in_combat.containsKey(p.getName())) {
      long dif =
          ((HealthMechanics.HealthRegenCombatDelay * 1000)
                  + HealthMechanics.in_combat.get(p.getName()))
              - System.currentTimeMillis();
      seconds_left = (dif / 1000.0D) + 0.5D;
      seconds_left = Math.round(seconds_left);
    }

    if (seconds_left < 3) {
      seconds_left = 3;
    }

    p.sendMessage(
        ChatColor.RED
            + "You will be "
            + ChatColor.BOLD
            + "LOGGED OUT"
            + ChatColor.RED
            + " of the game world shortly.");
    Hive.safe_logout.put(p.getName(), (int) seconds_left);
    Hive.safe_logout_location.put(p.getName(), p.getLocation());

    // p.kickPlayer(ChatColor.GREEN.toString() + "You have safely logged out." + "\n\n" +
    // ChatColor.GRAY.toString() + "Goodbye!");
    return true;
  }
コード例 #8
0
  public void updateDescription() {
    List<String> description = null;
    int pos = options.indexOf(value.getValue());
    int before = pos - 1;
    int after = pos + 1;
    if (before == -1) before = options.size() - 1;
    if (after == options.size()) after = 0;

    if (getDescription() != null) {
      description = getDescription();
      if (getDescription().size() >= 3) {
        String desc = ChatColor.stripColor(getDescription().get(1));

        if (options.contains(desc)) {
          description.set(0, ChatColor.GRAY.toString() + options.get(before));
          description.set(1, ChatColor.GREEN.toString() + value.getValue());
          description.set(2, ChatColor.GRAY.toString() + options.get(after));
        } else {
          description.add(0, ChatColor.GRAY.toString() + options.get(before));
          description.add(1, ChatColor.GREEN.toString() + value.getValue());
          description.add(2, ChatColor.GRAY.toString() + options.get(after));
        }
      } else {
        description.add(0, ChatColor.GRAY.toString() + options.get(before));
        description.add(1, ChatColor.GREEN.toString() + value.getValue());
        description.add(2, ChatColor.GRAY.toString() + options.get(after));
      }
    } else {
      description = new ArrayList<String>();
      description.add(ChatColor.GRAY.toString() + options.get(before));
      description.add(ChatColor.GREEN.toString() + value.getValue());
      description.add(ChatColor.GRAY.toString() + options.get(after));
    }

    setDescription(description);
  }
コード例 #9
0
public class ProtectionSignFeature extends Feature {

  // ############### //
  // ## Constants ## //
  // ############### //

  /** First line of a Protection sign - Exactly 16 chars */
  /* package */ static final String PROTECTION =
      "[" + ChatColor.GREEN + "Private" + ChatColor.BLACK + ']';
  /** Prefix of the Protection sign Owner name */
  /* package */ static final String PRIMARY_PREFIX = ChatColor.GREEN.toString();
  /** Prefix of a Protection sign additional name */
  /* package */ static final String SECONDARY_PREFIX = ChatColor.GRAY.toString();

  /** First line of an Error sign */
  /* package */ static final String ERROR =
      "[" + ChatColor.DARK_RED + "Error" + ChatColor.RESET + ']';

  /** Amount of time to keep cached results */
  private static final int CACHE_TIME = (int) TimeUtil.getInMilliseconds("1minute");

  // ################### //
  // ## Constant sets ## //
  // ################### //

  /** Set of String that players could write as first lines to say that it's a Protection sign */
  private static Set<String> protectionStrings;

  /** Static lazy getter for {@link #protectionStrings} */
  public static Set<String> getProtectionStrings() {
    if (protectionStrings == null) {
      protectionStrings = new HashSet<>(5);
      protectionStrings.add("protection");
      protectionStrings.add("[protection]");
      protectionStrings.add("private");
      protectionStrings.add("[private]");
      protectionStrings.add("p");
    }
    return protectionStrings;
  }

  /** Set of block types that can be protected by a Protection sign */
  private static Set<Material> protectedMaterials;

  /** Static lazy getter for {@link #protectedMaterials} */
  public static Set<Material> getProtectedMaterials() {
    if (protectedMaterials == null) {
      protectedMaterials =
          EnumSet.of(
              Material.BEACON,
              Material.BREWING_STAND,
              Material.BURNING_FURNACE,
              Material.CHEST,
              Material.COMMAND,
              Material.DISPENSER,
              Material.DROPPER,
              Material.FURNACE,
              Material.HOPPER,
              Material.JUKEBOX,
              Material.TRAPPED_CHEST);
    }
    return protectedMaterials;
  }

  // ############################## //
  // ## Non-static class content ## //
  // ############################## //

  private final Map<NLocation, ProtectionState> isProtectedCache;

  private class ProtectionState {

    public final String protectedBy;
    public final long timeout;

    private ProtectionState(final String protectedBy, final long timeout) {
      this.protectedBy = protectedBy;
      this.timeout = timeout;
    }
  }

  private BukkitTask cacheFreeTask;

  public ProtectionSignFeature(final NGeneral instance) {
    super(
        instance,
        FeatureType.PROTECTION_SIGNS,
        instance.getPluginConfig().hasProtectionSignFeature());
    this.isProtectedCache = new HashMap<>();
  }

  @Override
  public void initialize() {
    final ProtectionSignListener listener = new ProtectionSignListener(this);

    Bukkit.getPluginManager().registerEvents(listener, this.getPlugin());

    this.cacheFreeTask =
        new BukkitRunnable() {

          @Override
          public void run() {
            final long now = System.currentTimeMillis();
            final Iterator<Map.Entry<NLocation, ProtectionState>> it =
                fr.ribesg.bukkit.ngeneral.feature.protectionsign.ProtectionSignFeature.this
                    .isProtectedCache
                    .entrySet()
                    .iterator();
            while (it.hasNext()) {
              if (it.next().getValue().timeout <= now) {
                it.remove();
              }
            }
          }
        }.runTaskTimer(this.plugin, 10 * 20L, 10 * 20L);
  }

  @Override
  public void terminate() {
    if (this.cacheFreeTask != null) {
      this.cacheFreeTask.cancel();
    }
  }

  /**
   * Clear the cache for the provided location information.
   *
   * @param x the X coordinate
   * @param y the Y coordinate
   * @param z the Z coordinate
   * @param worldName the world this location relates to
   */
  public void clearCache(final int x, final int y, final int z, final String worldName) {
    for (int i = x - 2; i < x + 2; i++) {
      for (int j = y - 2; j < y + 2; j++) {
        for (int k = z - 2; k < z + 2; k++) {
          this.isProtectedCache.remove(new NLocation(worldName, x, y, z));
        }
      }
    }
  }

  /**
   * Detect if a Block can be broken by a Player or by something else (Explosion...)
   *
   * @param b the Block to be broken
   * @param player the Player that want to break the Block, if there is one, null otherwise
   * @return true if the block can be broken [by the Player], false otherwise
   */
  public boolean canBreak(final Block b, final Player player) {
    final Material blockType = b.getType();
    final String userId = player != null ? PlayerIdsUtil.getId(player.getName()) : null;
    if (blockType == Material.SIGN_POST || blockType == Material.WALL_SIGN) {
      final Sign sign = (Sign) b.getState();
      return !sign.getLine(0).equals(PROTECTION)
          || player != null && ColorUtil.stripColorCodes(sign.getLine(3)).equals(userId)
          || player != null && Perms.hasProtectionSignBreak(player);
    } else {
      final List<Sign> signLines;
      if (blockType == Material.CHEST || blockType == Material.TRAPPED_CHEST) {
        signLines = SignUtil.getSignsForChest(b);
      } else if (getProtectedMaterials().contains(blockType)) {
        signLines = SignUtil.getSignsForBlock(b);
      } else {
        return true;
      }
      for (final Sign sign : signLines) {
        if (sign.getLine(0).equals(PROTECTION)) {
          return false;
        }
      }
      return true;
    }
  }

  /**
   * Detects if a Player can use a protectable Block or not
   *
   * @param player the Player involved
   * @param b the Block to be used
   * @return true if the Player can use the Block, false otherwise
   */
  public boolean canUse(final Player player, final Block b) {
    if (Perms.hasProtectionSignBypass(player)) {
      return true;
    }
    final Material blockType = b.getType();
    final String userId = PlayerIdsUtil.getId(player.getName());
    final List<Sign> signLines;
    if (blockType == Material.CHEST || blockType == Material.TRAPPED_CHEST) {
      signLines = SignUtil.getSignsForChest(b);
    } else if (getProtectedMaterials().contains(blockType)) {
      signLines = SignUtil.getSignsForBlock(b);
    } else {
      return true;
    }
    boolean protectedBySign = false;
    boolean explicitlyAllowed = false;
    for (final Sign sign : signLines) {
      if (sign.getLine(0).equals(PROTECTION)) {
        protectedBySign = true;
        if (ColorUtil.stripColorCodes(sign.getLine(1)).equals(userId)
            || ColorUtil.stripColorCodes(sign.getLine(2)).equals(userId)
            || ColorUtil.stripColorCodes(sign.getLine(3)).equals(userId)) {
          explicitlyAllowed = true;
          break;
        }
      }
    }
    return !protectedBySign || explicitlyAllowed;
  }

  /**
   * Detect if a Protection Sign has something to protect. Note: This does not check if a
   * protectable block is already protected.
   *
   * @param l Location of the protection sign
   * @return True if there is a protectable block, otherwise false
   */
  public boolean protectsSomething(final Location l) {
    final World w = l.getWorld();
    final int x = l.getBlockX();
    final int y = l.getBlockY();
    final int z = l.getBlockZ();

    return getProtectedMaterials().contains(w.getBlockAt(x - 1, y, z).getType())
        || getProtectedMaterials().contains(w.getBlockAt(x + 1, y, z).getType())
        || getProtectedMaterials().contains(w.getBlockAt(x, y - 1, z).getType())
        || getProtectedMaterials().contains(w.getBlockAt(x, y + 1, z).getType())
        || getProtectedMaterials().contains(w.getBlockAt(x, y, z - 1).getType())
        || getProtectedMaterials().contains(w.getBlockAt(x, y, z + 1).getType());
  }

  /**
   * Detects if a Block is protected by a Sign or not. Returns the Sign owner if protected, null
   * otherwise.
   *
   * @param b the block to check
   * @return the Sign owner name if protected, null otherwise
   */
  public String isProtected(final Block b) {
    final NLocation loc = new NLocation(b.getLocation());
    final ProtectionState state = this.isProtectedCache.get(loc);
    if (state != null && state.timeout > System.currentTimeMillis()) {
      return state.protectedBy;
    } else {
      final Material blockType = b.getType();
      String result = null;
      List<Sign> signLines = null;
      if (blockType == Material.CHEST || blockType == Material.TRAPPED_CHEST) {
        signLines = SignUtil.getSignsForChest(b);
      } else if (getProtectedMaterials().contains(blockType)) {
        signLines = SignUtil.getSignsForBlock(b);
      }
      if (signLines != null) {
        for (final Sign sign : signLines) {
          if (PROTECTION.equals(sign.getLine(0))) {
            result = ColorUtil.stripColorCodes(sign.getLine(3));
            break;
          }
        }
      }
      this.isProtectedCache.put(
          loc, new ProtectionState(result, System.currentTimeMillis() + CACHE_TIME));
      return result;
    }
  }

  /**
   * This method checks if a Player with the provided playerName can place a Special Sign at the
   * given Location.
   *
   * <p>This will check every Block that would be affected by this Sign and see if at least one of
   * them is protected, or not.
   *
   * @param loc the Location of the future Sign
   * @param playerName the name of the Player that is placing the Sign
   * @return true if none of the considered Blocks is protected, false otherwise
   */
  public boolean canPlaceSign(final String playerName, final Location loc) {
    final World w = loc.getWorld();
    final int x = loc.getBlockX();
    final int y = loc.getBlockY();
    final int z = loc.getBlockZ();

    final String userId = PlayerIdsUtil.getId(playerName);
    String protecterId;

    protecterId = this.isProtected(w.getBlockAt(x - 1, y, z));
    if (protecterId != null && !protecterId.equals(userId)) {
      return false;
    }

    protecterId = this.isProtected(w.getBlockAt(x + 1, y, z));
    if (protecterId != null && !protecterId.equals(userId)) {
      return false;
    }

    protecterId = this.isProtected(w.getBlockAt(x, y - 1, z));
    if (protecterId != null && !protecterId.equals(userId)) {
      return false;
    }

    protecterId = this.isProtected(w.getBlockAt(x, y + 1, z));
    if (protecterId != null && !protecterId.equals(userId)) {
      return false;
    }

    protecterId = this.isProtected(w.getBlockAt(x, y, z - 1));
    if (protecterId != null && !protecterId.equals(userId)) {
      return false;
    }

    protecterId = this.isProtected(w.getBlockAt(x, y, z + 1));
    return !(protecterId != null && !protecterId.equals(userId));
  }
}
コード例 #10
0
ファイル: CommandISay.java プロジェクト: toxicbyte/Syndria
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    Player p = null;

    if (sender instanceof Player) {
      p = (Player) sender;
    }

    if (p != null) {
      if (!(p.isOp())) {
        return true;
      }
    }

    if (args.length == 0) {
      if (p != null) {
        if (!(p.isOp())) {
          return true;
        }
        p.sendMessage(
            ChatColor.RED
                + "Invalid Syntax. Please use /isay <msg> to send a local world messsage.");
        return true;
      }
    }

    String msg = "";
    for (String s : args) {
      msg += s + " ";
    }
    msg = msg.substring(0, msg.lastIndexOf(" "));

    msg = msg.replaceAll("&0", ChatColor.BLACK.toString());
    msg = msg.replaceAll("&1", ChatColor.DARK_BLUE.toString());
    msg = msg.replaceAll("&2", ChatColor.DARK_GREEN.toString());
    msg = msg.replaceAll("&3", ChatColor.DARK_AQUA.toString());
    msg = msg.replaceAll("&4", ChatColor.DARK_RED.toString());
    msg = msg.replaceAll("&5", ChatColor.DARK_PURPLE.toString());
    msg = msg.replaceAll("&6", ChatColor.GOLD.toString());
    msg = msg.replaceAll("&7", ChatColor.GRAY.toString());
    msg = msg.replaceAll("&8", ChatColor.DARK_GRAY.toString());
    msg = msg.replaceAll("&9", ChatColor.BLUE.toString());
    msg = msg.replaceAll("&a", ChatColor.GREEN.toString());
    msg = msg.replaceAll("&b", ChatColor.AQUA.toString());
    msg = msg.replaceAll("&c", ChatColor.RED.toString());
    msg = msg.replaceAll("&d", ChatColor.LIGHT_PURPLE.toString());
    msg = msg.replaceAll("&e", ChatColor.YELLOW.toString());
    msg = msg.replaceAll("&f", ChatColor.WHITE.toString());

    msg = msg.replaceAll("&u", ChatColor.UNDERLINE.toString());
    msg = msg.replaceAll("&s", ChatColor.BOLD.toString());
    msg = msg.replaceAll("&i", ChatColor.ITALIC.toString());
    msg = msg.replaceAll("&m", ChatColor.MAGIC.toString());

    if (sender instanceof BlockCommandSender) {
      BlockCommandSender cb = (BlockCommandSender) sender;
      for (Player pl : cb.getBlock().getWorld().getPlayers()) {
        pl.sendMessage(msg);
      }
    } else if (sender instanceof Player) {
      for (Player pl : p.getWorld().getPlayers()) {
        pl.sendMessage(msg);
      }
    }
    return true;
  }
コード例 #11
0
ファイル: Party.java プロジェクト: averlieren/DR-old
  public void removePlayer(Player p) {
    for (String tn : getPartyMembers()) {
      if (Bukkit.getPlayer(tn) == null) {
        continue;
      }
      Player t = Bukkit.getPlayer(tn);
      String name = getPlayerName(p);
      if (name.length() > 16) name = name.substring(0, 16);
      ScoreboardMechanics.getBoard(t).resetScores(Bukkit.getOfflinePlayer(name));
    }

    Objective o = ScoreboardMechanics.getBoard(p).getObjective(DisplaySlot.SIDEBAR);
    if (o != null) o.unregister();

    players.remove(p.getName());

    PartyMechanics.party_map.remove(p.getName());
    PartyMechanics.party_only.remove(p.getName());

    KarmaMechanics.sendAlignColor(p, p);
    if (ScoreboardMechanics.getBoard(p) != null
        && ScoreboardMechanics.getBoard(p).getObjective(DisplaySlot.SIDEBAR) != null) {
      ScoreboardMechanics.getBoard(p).getObjective(DisplaySlot.SIDEBAR).unregister();
    }

    InstanceMechanics.teleport_on_load.remove(p.getName());

    if (InstanceMechanics.saved_location_instance.containsKey(p.getName())) {
      // Inside an instance.
      p.teleport(InstanceMechanics.saved_location_instance.get(p.getName()));
      InstanceMechanics.saved_location_instance.remove(p.getName());
    }
    InstanceMechanics.removeFromInstanceParty(p.getName());

    if (p.getName().equalsIgnoreCase(leader.getName()) && getPartyMembers().size() > 0) {
      String new_leader = "";
      int size_mod = 1;
      if (getPartyMembers().size() <= 1) {
        size_mod = 0;
      }
      int party_index = new Random().nextInt(getPartyMembers().size() - size_mod);
      List<String> remaining_members = new ArrayList<String>();
      for (String s : getPartyMembers()) {
        if (s.equalsIgnoreCase(p.getName())) {
          continue;
        }
        remaining_members.add(s);
      }
      leader = Bukkit.getPlayer(remaining_members.get(party_index));
      for (String x : getPartyMembers()) {
        if (Bukkit.getPlayer(x) == null) continue;
        ScoreboardMechanics.getBoard(Bukkit.getPlayer(x)).resetScores(leader);
      }
      // TODO MOVES THIS

      for (String s : remaining_members) {
        if (Bukkit.getPlayer(s) != null) {
          Player pty_mem = Bukkit.getPlayer(s);
          if (!(pty_mem.getScoreboard().getPlayers().contains(Bukkit.getOfflinePlayer(s)))) {
            pty_mem.setScoreboard(Bukkit.getPlayer(s).getScoreboard());
          }
          /*
           * if(!new_ui.hasPlayerAdded(pty_mem)){
           * new_ui.showToPlayer(pty_mem); }
           */
          pty_mem.sendMessage(
              ChatColor.LIGHT_PURPLE.toString()
                  + "<"
                  + ChatColor.BOLD
                  + "P"
                  + ChatColor.LIGHT_PURPLE
                  + ">"
                  + ChatColor.GRAY
                  + " "
                  + p.getName()
                  + ChatColor.GRAY.toString()
                  + " has "
                  + ChatColor.LIGHT_PURPLE
                  + ChatColor.UNDERLINE
                  + "left"
                  + ChatColor.GRAY.toString()
                  + " your party.");
          pty_mem.sendMessage(
              ChatColor.LIGHT_PURPLE.toString()
                  + "<"
                  + ChatColor.BOLD
                  + "P"
                  + ChatColor.LIGHT_PURPLE
                  + "> "
                  + ChatColor.GRAY
                  + ChatColor.LIGHT_PURPLE.toString()
                  + new_leader
                  + ChatColor.GRAY.toString()
                  + " has been promoted to "
                  + ChatColor.UNDERLINE
                  + "Party Leader");
        }
      }
    } else {
      for (String s : getPartyMembers()) {
        if (Bukkit.getPlayer(s) != null && s != p.getName()) {
          Player pty_mem = Bukkit.getPlayer(s);
          pty_mem.sendMessage(
              ChatColor.LIGHT_PURPLE.toString()
                  + "<"
                  + ChatColor.BOLD
                  + "P"
                  + ChatColor.LIGHT_PURPLE
                  + ">"
                  + ChatColor.GRAY
                  + " "
                  + p.getName()
                  + ChatColor.GRAY.toString()
                  + " has "
                  + ChatColor.RED
                  + ChatColor.UNDERLINE
                  + "left"
                  + ChatColor.GRAY.toString()
                  + " your party.");
        }
      }
    }

    if (!Hive.pending_upload.contains(p.getName())) {
      HealthMechanics.setOverheadHP(p, HealthMechanics.getPlayerHP(p.getName()));
    }
  }
コード例 #12
0
ファイル: Messaging.java プロジェクト: filbert66/iConomy
  /**
   * Converts color codes into the simoleon code. Sort of a HTML format color code tag and `[code]
   *
   * <p>Color codes allowed: black, navy, green, teal, red, purple, gold, silver, gray, blue, lime,
   * aqua, rose, pink, yellow, white. Example:
   *
   * <blockquote
   *
   * <pre>
   *
   * Messaging.colorize(&quot;Hello &lt;green&gt;world!&quot;); // returns: Hello $world! </pre>
   *
   * </blockquote>
   *
   * @param string Original string to be parsed against group of color names.
   * @return <code>String</code> - The parsed string after conversion.
   */
  public static String colorize(String string) {
    if (iConomy.TerminalSupport)
      if (!(sender instanceof Player))
        string =
            string
                    .replace("`r", "\033[1;31m")
                    .replace("`R", "\033[0;31m")
                    .replace("`y", "\033[1;33m")
                    .replace("`Y", "\033[0;33m")
                    .replace("`g", "\033[1;32m")
                    .replace("`G", "\033[0;32m")
                    .replace("`a", "\033[1;36m")
                    .replace("`A", "\033[0;36m")
                    .replace("`b", "\033[1;34m")
                    .replace("`B", "\033[0;34m")
                    .replace("`p", "\033[1;35m")
                    .replace("`P", "\033[0;35m")
                    .replace("`k", "\033[0;0m")
                    .replace("`s", "\033[0;37m")
                    .replace("`S", "\033[1;30m")
                    .replace("`w", "\033[1;37m")
                    .replace("<r>", "\033[0m")
                    .replace("`e", "\033[0m")
                    .replace("<silver>", "\033[0;37m")
                    .replace("<gray>", "\033[1;30m")
                    .replace("<rose>", "\033[1;31m")
                    .replace("<lime>", "\033[1;32m")
                    .replace("<aqua>", "\033[1;36m")
                    .replace("<pink>", "\033[1;35m")
                    .replace("<yellow>", "\033[1;33m")
                    .replace("<blue>", "\033[1;34m")
                    .replace("<black>", "\033[0;0m")
                    .replace("<red>", "\033[0;31m")
                    .replace("<green>", "\033[0;32m")
                    .replace("<teal>", "\033[0;36m")
                    .replace("<navy>", "\033[0;34m")
                    .replace("<purple>", "\033[0;35m")
                    .replace("<gold>", "\033[0;33m")
                    .replace("<white>", "\033[1;37m")
                + "\033[0m";

    string =
        string
            .replace("`e", "")
            .replace("`r", ChatColor.RED.toString())
            .replace("`R", ChatColor.DARK_RED.toString())
            .replace("`y", ChatColor.YELLOW.toString())
            .replace("`Y", ChatColor.GOLD.toString())
            .replace("`g", ChatColor.GREEN.toString())
            .replace("`G", ChatColor.DARK_GREEN.toString())
            .replace("`a", ChatColor.AQUA.toString())
            .replace("`A", ChatColor.DARK_AQUA.toString())
            .replace("`b", ChatColor.BLUE.toString())
            .replace("`B", ChatColor.DARK_BLUE.toString())
            .replace("`p", ChatColor.LIGHT_PURPLE.toString())
            .replace("`P", ChatColor.DARK_PURPLE.toString())
            .replace("`k", ChatColor.BLACK.toString())
            .replace("`s", ChatColor.GRAY.toString())
            .replace("`S", ChatColor.DARK_GRAY.toString())
            .replace("`w", ChatColor.WHITE.toString());

    string =
        string
            .replace("<r>", "")
            .replace("<black>", "\u00A70")
            .replace("<navy>", "\u00A71")
            .replace("<green>", "\u00A72")
            .replace("<teal>", "\u00A73")
            .replace("<red>", "\u00A74")
            .replace("<purple>", "\u00A75")
            .replace("<gold>", "\u00A76")
            .replace("<silver>", "\u00A77")
            .replace("<gray>", "\u00A78")
            .replace("<blue>", "\u00A79")
            .replace("<lime>", "\u00A7a")
            .replace("<aqua>", "\u00A7b")
            .replace("<rose>", "\u00A7c")
            .replace("<pink>", "\u00A7d")
            .replace("<yellow>", "\u00A7e")
            .replace("<white>", "\u00A7f");

    return string;
  }