@Override
 protected boolean execute(CommandSender sender, MatchResult[] data) throws UsageException {
   Player player = sender instanceof Player ? (Player) sender : null;
   int tpNum = 0;
   if (data.length == 0) {
     if (player == null) {
       throw new UsageException(this.coloredUsage, "Must specify which player to teleport.");
     }
   } else if (data.length == 1) {
     if (player == null) {
       String playerName = data[0].getString();
       player = this.plugin.getServer().getPlayer(playerName);
       if (player == null) {
         sender.sendMessage(
             "Couldn't find player "
                 + ChatColor.GREEN.toString()
                 + playerName
                 + ChatColor.WHITE
                 + ".");
         return true;
       }
     } else {
       Integer numData = data[0].getInteger();
       if (numData == null || numData <= 0) {
         throw new UsageException(this.coloredUsage, "Location num must be a positive integer.");
       }
       tpNum = numData - 1;
     }
   } else if (data.length == 2) {
     String playerName = data[0].getString();
     player = this.plugin.getServer().getPlayer(playerName);
     if (player == null) {
       sender.sendMessage(
           "Couldn't find player " + ChatColor.GREEN + playerName + ChatColor.WHITE + ".");
       return true;
     }
     Integer numData = data[1].getInteger();
     if (numData == null || numData <= 0) {
       throw new UsageException(this.coloredUsage, "Location num must be a positive integer.");
     }
     tpNum = numData - 1;
   }
   List<Entry<Location, Integer>> actList = this.plugin.getRedstoneActivityList();
   if (tpNum >= actList.size()) {
     sender.sendMessage(
         "Location num " + ChatColor.YELLOW + (tpNum + 1) + ChatColor.WHITE + "does not exist.");
   } else {
     player.teleport(actList.get(tpNum).getKey());
     if (player == sender) {
       sender.sendMessage("Teleporting...");
     } else {
       sender.sendMessage(
           ChatColor.GREEN.toString()
               + sender.getName()
               + ChatColor.WHITE
               + "is teleporting you...");
     }
   }
   return true;
 }
Ejemplo n.º 2
0
 // 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
 }
Ejemplo n.º 3
0
 @Override
 public void onLeftClick(Player player, HumanNPC npc) {
   if (PermissionManager.hasPermission(player, "citizens.wizard.use.interact")) {
     if (UtilityProperties.isHoldingTool("WizardInteractItem", player)) {
       String msg = ChatColor.GREEN.toString();
       switch (mode) {
         case TELEPORT:
           if (locations.size() > 0) {
             cycle();
             msg += "Location set to " + StringUtils.wrap(getCurrentLocationName());
           } else {
             msg += ChatColor.RED + npc.getName() + " has no locations.";
           }
           break;
         case SPAWN:
           cycle();
           msg += "Mob to spawn set to " + StringUtils.wrap(StringUtils.format(mob));
           break;
         case TIME:
           cycle();
           msg += "Time setting set to " + StringUtils.wrap(time);
           break;
         case WEATHER:
           return;
         default:
           msg = ChatColor.RED + "No valid mode selected.";
       }
       player.sendMessage(msg);
     }
   } else {
     player.sendMessage(MessageUtils.noPermissionsMessage);
   }
 }
Ejemplo n.º 4
0
 private String colorize(boolean has) {
   if (has) {
     return ChatColor.GREEN.toString();
   } else {
     return ChatColor.RED.toString();
   }
 }
Ejemplo n.º 5
0
 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";
   }
 }
Ejemplo n.º 6
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;
  }
Ejemplo n.º 7
0
 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";
   }
 }
Ejemplo n.º 8
0
 public void listPlugins(Player player) {
   StringBuilder list = new StringBuilder();
   for (String plugin : pluginHelpList.keySet()) {
     list.append(ChatColor.GREEN.toString());
     list.append(plugin);
     list.append(ChatColor.WHITE.toString());
     list.append(", ");
   }
   list.delete(list.length() - 2, list.length());
   player.sendMessage(ChatColor.AQUA + "Plugins with Help entries:");
   player.sendMessage(list.toString());
 }
Ejemplo n.º 9
0
  @Override
  public void updateDescription() {
    List<String> description = null;
    if (getDescription() != null) {
      description = getDescription();
      String desc = ChatColor.stripColor(getDescription().get(0));

      if (desc.matches("([0-9]+[dhms]:?)+"))
        description.set(
            0, ChatColor.GREEN.toString() + MinigameUtils.convertTime(getValue().getValue(), true));
      else
        description.add(
            0, ChatColor.GREEN.toString() + MinigameUtils.convertTime(getValue().getValue(), true));
    } else {
      description = new ArrayList<String>();
      description.add(
          ChatColor.GREEN.toString() + MinigameUtils.convertTime(getValue().getValue(), true));
    }

    setDescription(description);
  }
Ejemplo n.º 10
0
  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();
  }
Ejemplo n.º 11
0
 public boolean handleCommand(String command) {
   try {
     if (command.equals("/?") || command.startsWith("/client help")) {
       SpoutClient.getHandle()
           .ingameGUI
           .addChatMessage(ChatColor.YELLOW.toString() + "Spoutcraft Client Debug Commands:");
       SpoutClient.getHandle().ingameGUI.addChatMessage("/client gc - run the garbage collector");
       return true;
     } else if (command.startsWith("/client gc")) {
       SpoutClient.getHandle()
           .ingameGUI
           .addChatMessage(ChatColor.YELLOW.toString() + "Starting Garbage Collection...");
       long start = System.currentTimeMillis();
       long mem = Runtime.getRuntime().freeMemory();
       long time = 250;
       if (command.split(" ").length > 2) {
         try {
           time = Long.parseLong(command.split(" ")[2]);
         } catch (Exception ignore) {
         }
       }
       while ((System.currentTimeMillis() - start) < time) {
         System.gc();
       }
       SpoutClient.getHandle()
           .ingameGUI
           .addChatMessage(ChatColor.GREEN.toString() + "Garbage Collection Complete!");
       SpoutClient.getHandle()
           .ingameGUI
           .addChatMessage(
               ChatColor.GREEN.toString()
                   + (Runtime.getRuntime().freeMemory() - mem) / (1024D * 1024D)
                   + " mb of memory freed");
       return true;
     }
   } catch (Exception e) {
   }
   return false;
 }
Ejemplo n.º 12
0
public class Messaging {

  public static void configure(String messageColour, String highlightColour) {
    MESSAGE_COLOUR = messageColour;
    HIGHLIGHT_COLOUR = highlightColour;
  }

  private static String prettify(String message) {
    String trimmed = message.trim();
    String messageColor = Colorizer.parseColors(MESSAGE_COLOUR);
    if (!trimmed.isEmpty()) {
      if (trimmed.charAt(0) == ChatColor.COLOR_CHAR) {
        ChatColor test = ChatColor.getByChar(trimmed.substring(1, 2));
        if (test == null) {
          message = messageColor + message;
        }
      } else message = messageColor + message;
    }
    return message;
  }

  public static void send(CommandSender sender, String msg) {
    sendMessageTo(sender, msg);
  }

  public static void sendInfo(CommandSender sender, String msg) {
    send(sender, ChatColor.YELLOW.toString() + msg);
  }

  public static void sendError(CommandSender sender, String msg) {
    send(sender, ChatColor.RED.toString() + msg);
  }

  private static void sendMessageTo(CommandSender sender, String rawMessage) {
    if (sender instanceof Player) {
      Player player = (Player) sender;
      rawMessage = rawMessage.replace("<player>", player.getName());
      rawMessage = rawMessage.replace("<world>", player.getWorld().getName());
    }
    rawMessage = Colorizer.parseColors(rawMessage);
    for (String message : rawMessage.split("<br>|<n>|\\n")) {
      sender.sendMessage(prettify(message));
    }
  }

  private static String HIGHLIGHT_COLOUR = ChatColor.YELLOW.toString();

  private static String MESSAGE_COLOUR = ChatColor.GREEN.toString();
}
Ejemplo n.º 13
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);
  }
Ejemplo n.º 14
0
  @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;
  }
Ejemplo n.º 15
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));
  }
}
Ejemplo n.º 16
0
  @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;
  }
Ejemplo n.º 17
0
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    final Player p = (Player) sender;
    if (!(GuildMechanics.inGuild(p.getName()))) {
      p.sendMessage(
          ChatColor.RED
              + "You must be in a "
              + ChatColor.BOLD
              + "GUILD"
              + ChatColor.RED
              + " to use "
              + ChatColor.BOLD
              + "/gquit.");
      return true;
    }

    if (args.length != 0) {
      p.sendMessage(
          ChatColor.RED + "" + ChatColor.BOLD + "Invalid Syntax. " + ChatColor.RED + "/gquit");
      return true;
    }

    String g_name = GuildMechanics.getGuild(p.getName());
    p.sendMessage(
        ChatColor.GRAY
            + "Are you sure you want to QUIT the guild '"
            + ChatColor.DARK_AQUA
            + g_name
            + ChatColor.GRAY
            + "' - This cannot be undone. "
            + "("
            + ChatColor.GREEN.toString()
            + ChatColor.BOLD
            + "Y"
            + ChatColor.GRAY
            + " / "
            + ChatColor.RED.toString()
            + ChatColor.BOLD
            + "N"
            + ChatColor.GRAY
            + ")");
    if (GuildMechanics.isGuildLeader(p.getName())) {
      p.sendMessage(
          ChatColor.RED.toString()
              + ChatColor.BOLD.toString()
              + "WARNING: "
              + ChatColor.GRAY
              + "You are the "
              + ChatColor.UNDERLINE
              + "GUILD LEADER"
              + ChatColor.GRAY
              + ", if you leave this guild it will be "
              + ChatColor.BOLD
              + "PERMENANTLY DELETED"
              + ChatColor.GRAY
              + ". All members will be kicked, and you will lose your 5,000g deposit.");
    }

    GuildMechanics.guild_quit_confirm.add(p.getName());
    return true;
  }
Ejemplo n.º 18
0
public class Survival extends JavaPlugin {

  public static final String MOTD =
      ChatColor.GREEN.toString()
          + ChatColor.BOLD
          + "Survival "
          + ChatColor.GOLD
          + ChatColor.BOLD
          + "Network"
          + ChatColor.AQUA
          + "\nSurvival Server "
          + ChatColor.DARK_BLUE
          + "-"
          + ChatColor.DARK_AQUA
          + " Currently in development!";
  public static Survival instance;
  public final int timeChangePrevDelay = 10;
  public Map<UUID, KitData> kitData = new HashMap<>();
  public boolean weatherChange = true;
  public boolean timeChange = true;
  public TimeChangePrevention timeChangePrevention = new TimeChangePrevention();
  public TabListHeader tabListHeader = new TabListHeader();
  List<Player> godMode = new ArrayList<>();

  public static Survival getInstance() {
    return instance;
  }

  public void onEnable() {
    instance = this;
    Bukkit.getConsoleSender()
        .sendMessage(
            Messages.INFO.prefix
                + "Creating tables for survival server if they don't already exist...");
    try {
      if (Main.getInstance().debugMsgs)
        Bukkit.getConsoleSender()
            .sendMessage(Messages.DEBUG.prefix + "Creating table 'SurvivalKit'...");
      Main.getInstance()
          .getSql()
          .updateSQL(
              "CREATE TABLE IF NOT EXISTS`survival`.`survivalkit` ( "
                  + "  `ID` BIGINT(20) NOT NULL AUTO_INCREMENT, "
                  + "  `UUID` TINYTEXT NOT NULL, "
                  + "  `SNOWBALL` BIGINT(20) ZEROFILL, "
                  + "  `FIREWORK` BIGINT(20) ZEROFILL, "
                  + "  `SIGN` BIGINT(20) ZEROFILL, "
                  + "  `FOOD` BIGINT(20) ZEROFILL, "
                  + "  `STONE` BIGINT(20) ZEROFILL, "
                  + "  `TORCH` BIGINT(20) ZEROFILL, "
                  + "  `GOLD` BIGINT(20) ZEROFILL, "
                  + "  `FUEL` BIGINT(20) ZEROFILL, "
                  + "  `LOG` BIGINT(20) ZEROFILL, "
                  + "  `GOLDARMOUR` BIGINT(20) ZEROFILL, "
                  + "  `WATER` BIGINT(20) ZEROFILL, "
                  + "  `LAVA` BIGINT(20) ZEROFILL, "
                  + "  `IRON` BIGINT(20) ZEROFILL, "
                  + "  `FARMER` BIGINT(20) ZEROFILL, "
                  + "  `IRONARMOUR` BIGINT(20) ZEROFILL, "
                  + "  `BUCKET` BIGINT(20) ZEROFILL, "
                  + "  `BUFFET` BIGINT(20) ZEROFILL, "
                  + "  `BOW` BIGINT(20) ZEROFILL, "
                  + "  `DIAMOND` BIGINT(20) ZEROFILL, "
                  + "  `PISTON` BIGINT(20) ZEROFILL, "
                  + "  `LANDSCAPE` BIGINT(20) ZEROFILL, "
                  + "  `DIAMONDARMOUR` BIGINT(20) ZEROFILL, "
                  + "  `REDSTONE` BIGINT(20) ZEROFILL, "
                  + "  `WOOL` BIGINT(20) ZEROFILL, "
                  + "  `ACHIEVEMENT` BIGINT(20) ZEROFILL, "
                  + "  `ACHIEVEMENT2` BIGINT(20) ZEROFILL, "
                  + "  PRIMARY KEY (`ID`)); ");
      if (Main.getInstance().debugMsgs)
        Bukkit.getConsoleSender().sendMessage(Messages.DEBUG.prefix + "Completed!");
    } catch (SQLException e) {
      Bukkit.getConsoleSender()
          .sendMessage(Messages.ERROR.prefix + "Couldn't create table 'SurvivalKit'! Details:");
      e.printStackTrace();
      Bukkit.getPluginManager().disablePlugin(instance);
      return;
    }
    Bukkit.getConsoleSender().sendMessage(Messages.INFO.prefix + "Done!");
    timeChangePrevention.runTaskTimer(instance, timeChangePrevDelay, timeChangePrevDelay);
    tabListHeader.runTaskTimer(instance, 20, 20);
    Bukkit.getPluginManager().registerEvents(new PlayerJoin(), instance);
    Bukkit.getPluginManager().registerEvents(new PlayerQuit(), instance);
    Bukkit.getPluginManager().registerEvents(new KitInvClick(), instance);
    Bukkit.getPluginManager().registerEvents(new PlayerDamage(), instance);
    Bukkit.getPluginManager().registerEvents(new MobHandle(), instance);
    Bukkit.getPluginManager().registerEvents(new WeatherChange(), instance);
    Bukkit.getPluginManager().registerEvents(new ServerListPing(), instance);
    Bukkit.getPluginManager().registerEvents(new PlayerDeath(), instance);
    setCmds();
    // DISABLE CHEST IN COSMETIC
    if (Bukkit.getPluginManager().getPlugin("SurvivalCosmetic") != null
        && Bukkit.getPluginManager().getPlugin("SurvivalCosmetic").isEnabled()) {
      SurvivalCosmetic.getInstance().setDisableChest(true);
    }
  }

  void setCmds() {
    getCommand("kit").setExecutor(new Kit());
    getCommand("fly").setExecutor(new Fly());
    getCommand("god").setExecutor(new God());
    getCommand("killall").setExecutor(new KillAll());
    getCommand("mob").setExecutor(new Mob());
    getCommand("time").setExecutor(new Time());
    getCommand("weather").setExecutor(new Weather());
    getCommand("gamemode").setExecutor(new Gamemode());
    getCommand("gm").setExecutor(new Gamemode());
    getCommand("heal").setExecutor(new Heal());
    getCommand("tp").setExecutor(new Teleport());
    getCommand("teleport").setExecutor(new Teleport());
    getCommand("world").setExecutor(new WorldCMD());
    getCommand("craft").setExecutor(new Craft());
    getCommand("workbench").setExecutor(new Craft());
    getCommand("wb").setExecutor(new Craft());
    getCommand("echest").setExecutor(new EnderChest());
    getCommand("enderchest").setExecutor(new EnderChest());
    getCommand("ec").setExecutor(new EnderChest());
    getCommand("repair").setExecutor(new Repair());
    getCommand("clear").setExecutor(new ClearInventory());
    getCommand("ci").setExecutor(new ClearInventory());
    getCommand("clearinventory").setExecutor(new ClearInventory());
  }

  public Map<UUID, KitData> getKitData() {
    return kitData;
  }

  public List<Player> getGodMode() {
    return godMode;
  }

  public void toggleGodMode(Player player) {
    if (godMode.contains(player)) {
      godMode.remove(player);
    } else {
      godMode.add(player);
    }
  }

  public boolean isWeatherChange() {
    return weatherChange;
  }

  public void setWeatherChange(boolean weatherChange) {
    this.weatherChange = weatherChange;
  }

  public boolean isTimeChange() {
    return timeChange;
  }

  public void setTimeChange(boolean timeChange) {
    this.timeChange = timeChange;
  }

  public int getTimeChangePrevDelay() {
    return timeChangePrevDelay;
  }
}
Ejemplo n.º 19
0
  /**
   * 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;
  }