示例#1
0
  /**
   * Applies a list of transformation on a block, if the block is not protected.
   *
   * @param toTransform the Bukkit block object to transform
   * @param transformations the list if transformations to apply
   */
  public static void transform(Block toTransform, List<List<String>> transformations) {
    if (isBlockProtected(toTransform)) {
      return;
    }

    for (List<String> toCheck : transformations) {
      ArrayList<String[]> stateIndex = new ArrayList<String[]>();

      for (int i = 0; i != 2; ++i) {
        String got = toCheck.get(i);

        if (got.contains(":")) { // Check for data _ appended.
          stateIndex.add(got.split(":"));
        } else {
          stateIndex.add(new String[] {got, "0"});
        }
      }

      String[] curState = stateIndex.get(0), toState = stateIndex.get(1);

      if (Integer.valueOf(curState[0]) == toTransform.getTypeId()
          && Integer.valueOf(curState[1]) == toTransform.getData()) {
        toTransform.setTypeIdAndData(Integer.valueOf(toState[0]), Byte.parseByte(toState[1]), true);
        return;
      }
    }
  }
示例#2
0
  public void PrintHlpList(CommandSender p, int page, int lpp) {
    String title =
        "&6&l" + this.project_name + " v" + des.getVersion() + " &r&6| " + getMSG("hlp_help", '6');
    List<String> hlp = new ArrayList<String>();
    hlp.add(getMSG("hlp_thishelp", "/" + plgcmd + " help"));
    hlp.add(
        getMSG(
            "hlp_execcmd",
            "/"
                + plgcmd
                + " <"
                + getMSG("hlp_cmdparam_command", '2')
                + "> ["
                + getMSG("hlp_cmdparam_parameter", '2')
                + "]"));
    if (p instanceof Player)
      hlp.add(
          getMSG(
              "hlp_typecmdpage",
              "/" + plgcmd + " help <" + getMSG("hlp_cmdparam_page", '2') + ">"));

    String[] ks = (cmdlist.replace(" ", "")).split(",");
    if (ks.length > 0) {
      for (String cmd : ks) hlp.add(cmds.get(cmd).desc);
    }
    printPage(p, hlp, page, title, "", false, lpp);
  }
示例#3
0
 private List<Block> toBlockList(Collection<BlockVector> locs) {
   List<Block> blocks = new ArrayList<>(locs.size());
   for (BlockVector location : locs)
     blocks.add(
         world.getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
   return blocks;
 }
示例#4
0
 @Override
 public List<Player> matchPlayer(String string) {
   List<Player> matches = new ArrayList<Player>();
   for (Player player : players) {
     if (player
         .getName()
         .substring(0, Math.min(player.getName().length(), string.length()))
         .equalsIgnoreCase(string)) {
       matches.add(player);
     }
   }
   return matches;
 }
示例#5
0
  private Collection<GlowLivingEntity> getNearbyEntities() {
    // TODO: fetch only necessary entities
    List<LivingEntity> entities = world.getLivingEntities();
    List<GlowLivingEntity> nearbyEntities = new ArrayList<>();

    for (LivingEntity entity : entities) {
      if (distanceTo(entity) / (double) power < 1.) {
        nearbyEntities.add((GlowLivingEntity) entity);
      }
    }

    return nearbyEntities;
  }
示例#6
0
 @Override
 public Map<String, String[]> getCommandAliases() {
   Map<String, String[]> aliases = new HashMap<>();
   ConfigurationSection section =
       config.getConfigFile(ServerConfig.Key.COMMANDS_FILE).getConfigurationSection("aliases");
   if (section == null) {
     return aliases;
   }
   for (String key : section.getKeys(false)) {
     List<String> list = section.getStringList(key);
     aliases.put(key, list.toArray(new String[list.size()]));
   }
   return aliases;
 }
  public void zoneCrystalCreation(Player player, Location blockLocation) {

    World world = player.getWorld();

    Location centerBlock = new CenterBlock().variable(player, blockLocation, 0.475);

    centerBlock.getBlock().setType(Material.AIR);
    world.spawn(centerBlock, EnderCrystal.class);

    int cBX = centerBlock.getBlockX();
    int cBY = centerBlock.getBlockY();
    int cBZ = centerBlock.getBlockZ();

    List<String> zoneList = RocketInit.getPlugin().getConfig().getStringList("zones");
    String activeZone =
        player.getUniqueId().toString() + "|" + world.getName() + "|" + cBX + "|" + cBY + "|" + cBZ;
    zoneList.add(activeZone);

    RocketInit.getPlugin().getConfig().set("zones", zoneList);
    RocketInit.getPlugin().saveConfig();

    reloadFlyZones(false);

    Location particleLocation = new Location(world, cBX + 0.5, cBY + 1.2, cBZ + 0.5);

    world.playSound(centerBlock, Sound.ENTITY_WITHER_AMBIENT, 1.25f, 0.55f);

    PacketPlayOutWorldParticles packet =
        new PacketPlayOutWorldParticles(
            EnumParticle.PORTAL,
            false,
            particleLocation.getBlockX(),
            particleLocation.getBlockY(),
            particleLocation.getBlockZ(),
            0.0f,
            0.0f,
            0.0f,
            2,
            2500,
            null);

    for (Player serverPlayer : player.getWorld().getPlayers())
      ((CraftPlayer) serverPlayer).getHandle().playerConnection.sendPacket(packet);

    commonString.messageSend(RocketInit.getPlugin(), player, true, RocketLanguage.RB_FZ_SUCCESS);
  }
示例#8
0
 @SuppressWarnings("incomplete-switch")
 @Override
 public synchronized void run() {
   final List<WorldEditorException> errorList = new ArrayList<WorldEditorException>();
   int counter = 0;
   while (!edits.isEmpty() && counter < 100) {
     try {
       switch (edits.poll().perform()) {
         case SUCCESS:
           successes++;
           break;
         case BLACKLISTED:
           blacklistCollisions++;
           break;
       }
     } catch (final WorldEditorException ex) {
       errorList.add(ex);
     } catch (final Exception ex) {
       getLogger().log(Level.WARNING, "[LogBlock WorldEditor] Exeption: ", ex);
     }
     counter++;
   }
   if (edits.isEmpty()) {
     logblock.getServer().getScheduler().cancelTask(taskID);
     if (errorList.size() > 0)
       try {
         final File file =
             new File(
                 "plugins/LogBlock/error/WorldEditor-"
                     + new SimpleDateFormat("yy-MM-dd-HH-mm-ss").format(System.currentTimeMillis())
                     + ".log");
         file.getParentFile().mkdirs();
         final PrintWriter writer = new PrintWriter(file);
         for (final LookupCacheElement err : errorList) writer.println(err.getMessage());
         writer.close();
       } catch (final Exception ex) {
       }
     errors = errorList.toArray(new WorldEditorException[errorList.size()]);
     notify();
   }
 }
  public void reloadFlyZones(boolean showMessage) {

    RocketInit.rocketZoneLocations.clear();
    List<String> zoneList = RocketInit.getPlugin().getConfig().getStringList("zones");

    if (zoneList.size() > 0) {

      for (String zone : zoneList) {

        String[] zoneSection = zone.split("\\|");

        final Location zoneLocationStart =
            new Location(
                Bukkit.getWorld(zoneSection[1]),
                Integer.parseInt(zoneSection[2]) - 25,
                Integer.parseInt(zoneSection[3]) - 5,
                Integer.parseInt(zoneSection[4]) - 25);

        final Location zoneLocationEnd =
            new Location(
                Bukkit.getWorld(zoneSection[1]),
                Integer.parseInt(zoneSection[2]) + 25,
                Integer.parseInt(zoneSection[3]) + 50,
                Integer.parseInt(zoneSection[4]) + 25);

        RocketInit.rocketZoneLocations.put(
            UUID.fromString(zoneSection[0]),
            new ConcurrentHashMap<Location, Location>() {
              {
                put(zoneLocationStart, zoneLocationEnd);
              }
            });
      }

      if (showMessage) RocketInit.registerMap.put("zone", zoneList.size());
    }
  }
示例#10
0
 public void printConfig(
     CommandSender p, int page, int lpp, boolean section, boolean usetranslation) {
   List<String> cfgprn = new ArrayList<String>();
   if (!plg.getConfig().getKeys(true).isEmpty())
     for (String k : plg.getConfig().getKeys(true)) {
       Object objvalue = plg.getConfig().get(k);
       String value = objvalue.toString();
       String str = k;
       if ((objvalue instanceof Boolean) && (usetranslation)) value = EnDis((Boolean) objvalue);
       if (objvalue instanceof MemorySection) {
         if (!section) continue;
       } else str = k + " : " + value;
       if (usetranslation) str = getMSG("cfgmsg_" + k.replaceAll("\\.", "_"), value);
       cfgprn.add(str);
     }
   String title =
       "&6&l"
           + this.project_current_version
           + " v"
           + des.getVersion()
           + " &r&6| "
           + getMSG("msg_config", '6');
   printPage(p, cfgprn, page, title, "", false);
 }
示例#11
0
    public void printPage(CommandSender p, int pnum, int linesperpage) {
      if (ln.size() > 0) {

        int maxp = ln.size() / linesperpage;
        if ((ln.size() % linesperpage) > 0) maxp++;
        if (pnum > maxp) pnum = maxp;
        int maxl = linesperpage;
        if (pnum == maxp) {
          maxl = ln.size() % linesperpage;
          if (maxp == 1) maxl = ln.size();
        }
        if (maxl == 0) maxl = linesperpage;
        if (msg.containsKey(title_msgid)) printMsg(p, "&6&l" + getMSGnc(title_msgid));
        else printMsg(p, title_msgid);

        String numpx = "";
        for (int i = 0; i < maxl; i++) {
          if (shownum) numpx = "&3" + Integer.toString(1 + i + (pnum - 1) * linesperpage) + ". ";
          printMsg(p, numpx + "&a" + ln.get(i + (pnum - 1) * linesperpage));
        }
        if (maxp > 1) printMSG(p, this.footer_msgid, 'e', '6', pnum, maxp);
      } else printMSG(p, "lst_listisempty", 'c');
    }
示例#12
0
 public static void load() {
   final FileConfiguration config = UDSPlugin.getPlugin().getConfig();
   BLOCK_CREEPERS = config.getBoolean("block.creeper");
   BLOCK_ENDERMEN = config.getBoolean("block.endermen");
   BLOCK_SILVERFISH = config.getBoolean("block.silverfish");
   BLOCK_TNT = config.getBoolean("block.tnt");
   BLOCK_WITHER = config.getBoolean("block.wither");
   MAP_DATA = (byte) config.getInt("map-data");
   BASE_COST = config.getInt("cost.base");
   BUILD_COST = config.getInt("cost.build");
   CITY_COST = config.getInt("cost.city");
   CLAN_COST = config.getInt("cost.clan");
   EXPAND_COST = config.getInt("cost.expand");
   HOME_COST = config.getInt("cost.home");
   MAP_COST = config.getInt("cost.map");
   SHOP_COST = config.getInt("cost.shop");
   VIP_COST = config.getInt("cost.vip");
   UNDO_COUNT = config.getInt("range.undo");
   DRAIN_RANGE = config.getInt("range.drain");
   MOVE_RANGE = config.getInt("range.move");
   EDIT_RANGE = config.getInt("range.edit");
   COMPASS_RANGE = config.getInt("range.compass");
   BUTCHER_RANGE = config.getInt("range.butcher");
   VIP_SPAWNS = config.getInt("vip.spawns");
   WORLD_BORDER = config.getInt("range.world");
   WORLD_BORDER_SQRD = WORLD_BORDER * WORLD_BORDER;
   SPAWNER_EXP = config.getInt("exp.spawner");
   REQUEST_TTL = config.getLong("request-timeout") * TimeUtils.SECOND;
   MINECART_TTL = config.getLong("minecart.life") * TimeUtils.SECOND;
   PVP_TIME = config.getLong("pvp-time") * TimeUtils.SECOND;
   SLOW_TIME = config.getLong("auto-save") * TimeUtils.MINUTE;
   DRAGON_RESPAWN = config.getLong("respawn-dragon") * TimeUtils.MINUTE;
   VIP_TIME = config.getLong("vip.time") * TimeUtils.DAY;
   CURRENCIES = config.getString("currency.plural");
   WELCOME_MSG = config.getString("welcome.message");
   WELCOME_ADMIN = config.getString("welcome.admin");
   SERVER_OWNER = config.getString("server-owner");
   CURRENCY = config.getString("currency.singular");
   MAIN_WORLD = config.getString("world-name");
   WELCOME_GIFT = Material.getMaterial(config.getString("welcome.gift"));
   if (WELCOME_GIFT == null) WELCOME_GIFT = Material.EMERALD;
   SERVER_RULES = config.getStringList("server-rules");
   PISTON_POWER = config.getDouble("piston-power");
   SHARES = config.getStringList("inventory-shares");
   GMAIL_ADDRESS = config.getString("gmail.email");
   SKULL = config.getDouble("head-drop-chance");
   GMAIL_PASSWORD = config.getString("gmail.password");
   VIP_WHITELIST.clear();
   for (int typeId : config.getIntegerList("item-whitelist")) {
     VIP_WHITELIST.add(Material.getMaterial(typeId));
   }
   KITS.clear();
   for (String kit : config.getStringList("kits")) {
     final String[] kitSplit = kit.split(",");
     final List<ItemStack> items =
         new ArrayList<ItemStack>(ArrayUtils.subarray(kitSplit, 3, kitSplit.length - 1).length);
     for (Object item : ArrayUtils.subarray(kitSplit, 3, kitSplit.length - 1)) {
       items.add(new ItemStack(Material.getMaterial(Integer.parseInt((String) item))));
     }
     KITS.add(
         new Kit(
             kitSplit[0],
             Integer.parseInt(kitSplit[1]),
             items,
             PlayerRank.getByName(kitSplit[2])));
   }
   MOB_REWARDS.clear();
   for (EntityType entityType : EntityType.values()) {
     String entityName = "mob-rewards." + entityType.getName();
     if (entityName != null) {
       entityName = entityName.toLowerCase();
       MOB_REWARDS.put(entityType, config.getInt(entityName));
     }
   }
   GLOBAL_FLAGS.clear();
   for (RegionFlag flag : RegionFlag.values()) {
     final String flagname = "global-flags." + flag.toString().toLowerCase();
     GLOBAL_FLAGS.put(flag, config.getBoolean(flagname));
   }
 }
示例#13
0
 @Override
 public Player[] getOnlinePlayers() {
   return players.toArray(new Player[0]);
 }
示例#14
0
 public void addPlayer(Player base1) {
   players.add(base1);
 }
示例#15
0
 public World createWorld(String string, Environment e, long l) {
   World w = new FakeWorld(string, e);
   worlds.add(w);
   return w;
 }
示例#16
0
 public void addLine(String str) {
   ln.add(str);
 }
  private static Map<String, List<Material>> initSynonyms() {

    Map<String, List<Material>> result = new HashMap<String, List<Material>>();
    // Blocks
    result.put("ANY_FURNACE", Arrays.asList(Material.FURNACE, Material.BURNING_FURNACE));
    result.put("ANY_SIGN", Arrays.asList(Material.SIGN, Material.SIGN_POST, Material.WALL_SIGN));
    result.put(
        "ANY_REDSTONE_ORE", Arrays.asList(Material.REDSTONE_ORE, Material.GLOWING_REDSTONE_ORE));
    result.put(
        "ANY_REDSTONE_TORCH",
        Arrays.asList(Material.REDSTONE_TORCH_OFF, Material.REDSTONE_TORCH_ON));
    result.put("ANY_DIODE_BLOCK", Arrays.asList(Material.DIODE_BLOCK_OFF, Material.DIODE_BLOCK_ON));
    // Tools
    result.put(
        "ANY_SPADE",
        Arrays.asList(
            Material.WOOD_SPADE,
            Material.STONE_SPADE,
            Material.GOLD_SPADE,
            Material.IRON_SPADE,
            Material.DIAMOND_SPADE));
    result.put(
        "ANY_AXE",
        Arrays.asList(
            Material.WOOD_AXE,
            Material.STONE_AXE,
            Material.GOLD_AXE,
            Material.IRON_AXE,
            Material.DIAMOND_AXE));
    result.put(
        "ANY_HOE",
        Arrays.asList(
            Material.WOOD_HOE,
            Material.STONE_HOE,
            Material.GOLD_HOE,
            Material.IRON_HOE,
            Material.DIAMOND_HOE));
    result.put(
        "ANY_PICKAXE",
        Arrays.asList(
            Material.WOOD_PICKAXE,
            Material.STONE_PICKAXE,
            Material.GOLD_PICKAXE,
            Material.IRON_PICKAXE,
            Material.DIAMOND_PICKAXE));
    result.put(
        "ANY_SWORD",
        Arrays.asList(
            Material.WOOD_SWORD,
            Material.STONE_SWORD,
            Material.GOLD_SWORD,
            Material.IRON_SWORD,
            Material.DIAMOND_SWORD));
    result.put(
        "ANY_BUCKET",
        Arrays.asList(
            Material.BUCKET, Material.LAVA_BUCKET, Material.WATER_BUCKET, Material.MILK_BUCKET));
    // Armour
    result.put(
        "ANY_HELMET",
        Arrays.asList(
            Material.LEATHER_HELMET,
            Material.CHAINMAIL_HELMET,
            Material.GOLD_HELMET,
            Material.IRON_HELMET,
            Material.DIAMOND_HELMET));
    result.put(
        "ANY_CHESTPLATE",
        Arrays.asList(
            Material.LEATHER_CHESTPLATE,
            Material.CHAINMAIL_CHESTPLATE,
            Material.GOLD_CHESTPLATE,
            Material.IRON_CHESTPLATE,
            Material.DIAMOND_CHESTPLATE));
    result.put(
        "ANY_LEGGINGS",
        Arrays.asList(
            Material.LEATHER_LEGGINGS,
            Material.CHAINMAIL_LEGGINGS,
            Material.GOLD_LEGGINGS,
            Material.IRON_LEGGINGS,
            Material.DIAMOND_LEGGINGS));
    result.put(
        "ANY_BOOTS",
        Arrays.asList(
            Material.LEATHER_BOOTS,
            Material.CHAINMAIL_BOOTS,
            Material.GOLD_BOOTS,
            Material.IRON_BOOTS,
            Material.DIAMOND_BOOTS));
    // Minecarts
    result.put(
        "ANY_MINECART",
        Arrays.asList(Material.MINECART, Material.POWERED_MINECART, Material.STORAGE_MINECART));
    result.put(
        "ANY_RAIL", Arrays.asList(Material.RAILS, Material.POWERED_RAIL, Material.DETECTOR_RAIL));
    // Wildcards
    List<Material> merger;

    merger = new ArrayList<Material>();
    merger.addAll(result.get("ANY_SPADE"));
    merger.addAll(result.get("ANY_AXE"));
    merger.addAll(result.get("ANY_HOE"));
    merger.addAll(result.get("ANY_PICKAXE"));
    merger.addAll(result.get("ANY_SWORD"));
    merger.addAll(result.get("ANY_BUCKET"));
    merger.addAll(
        Arrays.asList(
            Material.FLINT_AND_STEEL, Material.FISHING_ROD, Material.SADDLE, Material.BOW));
    result.put("ANY_TOOL", merger);

    merger = new ArrayList<Material>();
    merger.addAll(result.get("ANY_SWORD"));
    merger.addAll(Arrays.asList(Material.BOW, Material.ARROW));
    result.put("ANY_WEAPON", merger);

    merger = new ArrayList<Material>();
    merger.addAll(result.get("ANY_HELMET"));
    merger.addAll(result.get("ANY_CHESTPLATE"));
    merger.addAll(result.get("ANY_LEGGINGS"));
    merger.addAll(result.get("ANY_BOOTS"));
    result.put("ANY_ARMOR", merger);

    merger = new ArrayList<Material>();
    merger.addAll(Arrays.asList(Material.values()));
    result.put("ANY_OBJECT", merger);

    merger = new ArrayList<Material>();
    merger.addAll(Arrays.asList(Material.values()));
    for (int i = 0; i < merger.size(); i++) {
      if (!merger.get(i).isBlock()) merger.set(i, null);
    }
    while (merger.indexOf(null) >= 0) merger.remove(null);
    result.put("ANY_BLOCK", merger);

    merger = new ArrayList<Material>();
    merger.addAll(Arrays.asList(Material.values()));
    for (int i = 0; i < merger.size(); i++) {
      if (merger.get(i).isBlock()) merger.set(i, null);
    }
    while (merger.indexOf(null) >= 0) merger.remove(null);
    result.put("ANY_ITEM", merger);

    return Collections.unmodifiableMap(result);
  }
示例#18
0
 public boolean isEmpty() {
   return ln.isEmpty();
 }