示例#1
0
  // TODO: Convert this to use one of the new text classes?
  public static String listKits(final IEssentials ess, final User user) throws Exception {
    try {
      final ConfigurationSection kits = ess.getSettings().getKits();
      final StringBuilder list = new StringBuilder();
      for (String kitItem : kits.getKeys(false)) {
        if (user == null) {
          list.append(" ").append(capitalCase(kitItem));
        } else if (user.isAuthorized("essentials.kits." + kitItem.toLowerCase(Locale.ENGLISH))) {
          String cost = "";
          String name = capitalCase(kitItem);
          BigDecimal costPrice =
              new Trade("kit-" + kitItem.toLowerCase(Locale.ENGLISH), ess).getCommandCost(user);
          if (costPrice.signum() > 0) {
            cost = tl("kitCost", NumberUtil.displayCurrency(costPrice, ess));
          }

          Kit kit = new Kit(kitItem, ess);
          if (kit.getNextUse(user) != 0) {
            name = tl("kitDelay", name);
          }

          list.append(" ").append(name).append(cost);
        }
      }
      return list.toString().trim();
    } catch (Exception ex) {
      throw new Exception(tl("kitError"), ex);
    }
  }
 public void addPlayer(String name, ReservationType type) {
   ConfigurationSection section =
       this.getConfiguration().getConfigurationSection("reserved-players");
   section.set(name, type.name());
   this.save();
   this.reservedPlayers.put(name, type);
 }
 public static void loadClasses(ConfigurationSection cs) {
   if (cs == null) {
     Log.info(BattleArena.getPName() + " has no classes");
     return;
   }
   StringBuilder sb = new StringBuilder();
   Set<String> keys = cs.getKeys(false);
   boolean first = true;
   for (String className : keys) {
     ArenaClass ac = parseArenaClass(cs.getConfigurationSection(className));
     if (ac == null) continue;
     if (first) first = false;
     else sb.append(", ");
     sb.append(ac.getName());
     ArenaClassController.addClass(ac);
   }
   if (first) {
     Log.info(
         BattleArena.getPName()
             + " no predefined classes found. inside of "
             + cs.getCurrentPath());
   } else {
     Log.info(BattleArena.getPName() + " registering classes: " + sb.toString());
   }
 }
示例#4
0
  @Override
  public PermissionGroup getDefaultGroup(String worldName) {
    ConfigurationSection groups = this.permissions.getConfigurationSection("groups");

    if (groups == null) {
      throw new RuntimeException("No groups defined. Check your permissions file.");
    }

    String defaultGroupProperty = "default";
    if (worldName != null) {
      defaultGroupProperty = buildPath("worlds", worldName, defaultGroupProperty);
    }

    for (Map.Entry<String, Object> entry : groups.getValues(false).entrySet()) {
      if (entry.getValue() instanceof ConfigurationSection) {
        ConfigurationSection groupSection = (ConfigurationSection) entry.getValue();

        if (groupSection.getBoolean(defaultGroupProperty, false)) {
          return this.manager.getGroup(entry.getKey());
        }
      }
    }

    if (worldName == null) {
      throw new RuntimeException(
          "Default user group is not defined. Please select one using the \"default: true\" property");
    }

    return null;
  }
  private void saveToBackend(Lot lot) {

    UUID uuid = lot.getUuid();
    String uuidString = uuid.toString();
    ItemStack item = lot.getItem();
    boolean started = lot.isStarted();
    double price = lot.getPrice();
    String lastBidPlayerName = lot.getLastBidPlayerName();
    UUID lastBidPlayerUuid = lot.getLastBidPlayerUuid();
    double lastBidPrice = lot.getLastBidPrice();
    double minimumIncrement = lot.getMinimumIncrement();
    long preserveTimeExpire = lot.getPreserveTimeExpire();
    long auctionDurationExpire = lot.getAuctionDurationExpire();

    String sectionPath = "lots." + uuidString;
    ConfigurationSection singleLotSection =
        data.getYamlConfig().getConfigurationSection(sectionPath);
    if (null == singleLotSection) {
      singleLotSection = data.getYamlConfig().createSection(sectionPath);
    }

    singleLotSection.set("item", item);
    singleLotSection.set("started", started);
    singleLotSection.set("price", price);
    singleLotSection.set("lastBidPlayerName", lastBidPlayerName);
    singleLotSection.set(
        "lastBidPlayerUuid", null == lastBidPlayerUuid ? null : lastBidPlayerUuid.toString());
    singleLotSection.set("lastBidPrice", lastBidPrice);
    singleLotSection.set("minimumIncrement", minimumIncrement);
    singleLotSection.set("preserveTimeExpire", preserveTimeExpire);
    singleLotSection.set("auctionDurationExpire", auctionDurationExpire);
  }
示例#6
0
 private static Message getNoCampMessage(ConfigurationSection config) {
   NoCampMessageDecorator message =
       new NoCampMessageDecorator(
           new DefaultMessage(config.getString("Messages.NoCampMessage", NO_CAMP_MESSAGE)));
   message.setSpawnerCampMessageEnabled(config.getBoolean("Messages.Spawner", false));
   return message;
 }
  @Override
  public void apply(final FileConfiguration base) {
    final ConfigurationSection target = this.target(base);
    if (target == null) return;

    target.set(this.key, null);
  }
示例#8
0
  @Override
  public SpellResult onCast(ConfigurationSection parameters) {
    Block target = getTargetBlock();
    if (target == null) {
      return SpellResult.NO_TARGET;
    }

    // TODO: Optimize this
    Set<Material> dropMaterials = controller.getMaterialSet(parameters.getString("drop"));

    if (!dropMaterials.contains(target.getType())) {
      return SpellResult.NO_TARGET;
    }
    if (!hasBuildPermission(target)) {
      return SpellResult.INSUFFICIENT_PERMISSION;
    }

    int maxRecursion = parameters.getInt("recursion_depth", DEFAULT_MAX_RECURSION);
    drop(target, dropMaterials, maxRecursion);

    // Make this undoable.. even though it means you can exploit it for ore with Rewind. Meh!
    registerForUndo();

    return SpellResult.CAST;
  }
示例#9
0
  @Override
  public void prepare(CastContext context, ConfigurationSection parameters) {
    track = parameters.getBoolean("track", true);
    loot = parameters.getBoolean("loot", false);
    force = parameters.getBoolean("force", false);
    setTarget = parameters.getBoolean("set_target", false);
    speed = parameters.getDouble("speed", 0);
    direction = ConfigurationUtils.getVector(parameters, "direction");
    dyOffset = parameters.getDouble("dy_offset", 0);

    if (parameters.contains("type")) {
      String mobType = parameters.getString("type");
      entityData = context.getController().getMob(mobType);
      if (entityData == null) {
        entityData =
            new com.elmakers.mine.bukkit.entity.EntityData(context.getController(), parameters);
      }
    }

    if (parameters.contains("reason")) {
      String reasonText = parameters.getString("reason").toUpperCase();
      try {
        spawnReason = CreatureSpawnEvent.SpawnReason.valueOf(reasonText);
      } catch (Exception ex) {
        spawnReason = CreatureSpawnEvent.SpawnReason.EGG;
      }
    }
  }
  public static List<String> getDates(final String name) {
    BaseSerializer serializer = getSerializer(name);
    if (serializer == null) return null;
    PriorityQueue<Long> dates =
        new PriorityQueue<Long>(Defaults.NUM_INV_SAVES, Collections.reverseOrder());
    Set<String> keys = serializer.config.getKeys(false);

    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);

    for (String key : keys) {
      ConfigurationSection cs = serializer.config.getConfigurationSection(key);
      if (cs == null) continue;
      String strdate = cs.getString("storedDate");
      Date date;
      try {
        date = format.parse(strdate);
      } catch (ParseException e) {
        e.printStackTrace();
        continue;
      }
      dates.add(date.getTime());
    }
    List<String> strdates = new ArrayList<String>();
    for (Long l : dates) {
      strdates.add(format.format(l));
    }
    return strdates;
  }
示例#11
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 protected List getList(Field field, ConfigurationSection cs, String path, int depth)
     throws Exception {
   depth++;
   int listSize = cs.getKeys(false).size();
   String key = path;
   if (key.lastIndexOf(".") >= 0) {
     key = key.substring(key.lastIndexOf("."));
   }
   List list = new ArrayList();
   if (listSize > 0) {
     int loaded = 0;
     int i = 0;
     while (loaded < listSize) {
       if (cs.isSet(key + i)) {
         Object in = cs.get(key + i);
         in = loadObject(field, cs, key + i, depth);
         list.add(in);
         loaded++;
       }
       i++;
       // ugly overflow guard... should only be needed if config was manually edited very badly
       if (i > (listSize * 3)) loaded = listSize;
     }
   }
   return list;
 }
 private static ConfigurationSection getSection(String name) {
   ConfigurationSection section = yaml.getConfigurationSection(name);
   if (section == null)
     for (String key : yaml.getKeys(false))
       if (key.equalsIgnoreCase(name)) section = yaml.getConfigurationSection(key);
   return section;
 }
示例#13
0
 /**
  * Loads a list of ItemStack objects from a ConfigurationSection.
  *
  * @param section Where to read the saved list.
  * @return A correctly build List of Itemstack Objects.
  */
 public static List<ItemStack> loadItemStack(ConfigurationSection section) {
   List<ItemStack> stacks = new LinkedList<>();
   for (String key : section.getKeys(false)) {
     stacks.add((ItemStack) section.get(key));
   }
   return stacks;
 }
示例#14
0
 // ItemStack
 public static HashMap<Integer, ItemStack> loadInventory(final ConfigurationSection config) {
   final Set<String> entries = config.getKeys(false);
   final HashMap<Integer, ItemStack> res = new HashMap<Integer, ItemStack>(entries.size());
   for (final String key : entries)
     res.put(Integer.parseInt(key), loadItemStack(config.getConfigurationSection(key)));
   return res;
 }
示例#15
0
  public static Boolean hasAbility(Player player, Integer ability) {

    if (!KIT.containsKey(player)) {
      if (plugin.DEFAULT_KIT) {

        ConfigurationSection def = BGFiles.kitconf.getConfigurationSection("default");

        List<Integer> s = def.getIntegerList("ABILITY");
        for (Integer i : s) {
          if (i == ability) {
            return true;
          }
          continue;
        }
        return false;
      } else {
        return false;
      }
    }

    String kitname = getKit(player);
    ConfigurationSection kit = BGFiles.kitconf.getConfigurationSection(kitname);

    List<Integer> s = kit.getIntegerList("ABILITY");
    for (Integer i : s) {
      if (i == ability) {
        return true;
      }
      continue;
    }
    return false;
  }
示例#16
0
  @Override
  public Set<String> getDefaultGroupNames(String worldName) {
    ConfigurationSection groups = this.permissions.getConfigurationSection("groups");

    if (groups == null) {
      return Collections.emptySet();
    }

    Set<String> names = new HashSet<String>();

    String defaultGroupProperty = "default";
    if (worldName != null) {
      defaultGroupProperty = buildPath("worlds", worldName, defaultGroupProperty);
    }

    for (Map.Entry<String, Object> entry : groups.getValues(false).entrySet()) {
      if (entry.getValue() instanceof ConfigurationSection) {
        ConfigurationSection groupSection = (ConfigurationSection) entry.getValue();

        if (groupSection.getBoolean(defaultGroupProperty, false)) {
          names.add(entry.getKey());
        }
      }
    }

    return Collections.unmodifiableSet(names);
  }
示例#17
0
  @Override
  public void serialize(ConfigurationSection section) {
    super.serialize(section, TYPE);

    section.set("amount", amount);
    section.set("boss", name);
  }
示例#18
0
  /**
   * Parses data for a kit action
   *
   * @param cfg section to parse
   * @return KitAction
   */
  private KitAction parseAction(ConfigurationSection cfg) {
    Map<String, Object> vals = cfg.getValues(true);
    KitAction action;

    if (vals.containsKey("type")) {
      String actionType = (String) vals.get("type");
      // System.out.println("Type: " + actionType);

      // Determine what type of action it is
      if (actionType.equalsIgnoreCase("ITEMS") || actionType.equalsIgnoreCase("ITEM")) {
        if (vals.containsKey("item")) {
          action = new ItemsAction(parseItem(cfg.getConfigurationSection("item")));
          return action;
        }
        return null;

      } else if (actionType.equalsIgnoreCase("EFFECT") || actionType.equalsIgnoreCase("POTION")) {
        if (vals.containsKey("effect")) {

          action = new EffectAction(parsePotion(cfg.getConfigurationSection("effect")));
          return action;
        }
        return null;

      } else if (actionType.equalsIgnoreCase("COMMAND")
          || actionType.equalsIgnoreCase("COMMANDS")) {
        String cType = cfg.getString("command.type", "console");
        String cmd = cfg.getString("command.command", "list");

        action = new CommandAction(cType, cmd);
        return action;
      }
    }
    return null;
  }
  @Override
  public boolean conflicts(final FileConfiguration base) {
    final ConfigurationSection target = this.target(base);
    if (target == null) return false;

    return target.isSet(this.key);
  }
示例#20
0
  /**
   * parse through dat to create a new item with enchantments, quantity, and damage value
   *
   * @param cfg to parse through
   * @return the new ItemStack
   */
  private ItemStack parseItem(ConfigurationSection cfg) {
    Map<String, Object> vals = cfg.getValues(true);
    ItemStack newItem;
    // check material
    newItem =
        new ItemStack(Material.getMaterial((cfg.getString("material", "stone")).toUpperCase()));

    // check damage value

    newItem.setDurability((short) (cfg.getInt("damage", 0)));

    // check quantity

    newItem.setAmount(cfg.getInt("amount", 1));

    // enchantment parsing
    for (String s : cfg.getStringList("enchantments")) {
      String[] parts = s.split(":");
      String enchant = parts[0];
      int level = 1;

      if (parts.length > 1) {
        level = Integer.parseInt(parts[1]);
      }
      newItem.addUnsafeEnchantment(Enchantment.getByName(enchant.toUpperCase()), level);
    }

    // System.out.println("Item: "+ newItem.toString());
    return newItem;

    // ItemStack is = new ItemStack(Material.);
  }
示例#21
0
  public static LoseZone deserialize(ConfigurationSection section) {
    int id = section.getInt("id");
    Location first = Parser.convertStringtoLocation(section.getString("first"));
    Location second = Parser.convertStringtoLocation(section.getString("second"));

    return new LoseZone(first, second, id);
  }
示例#22
0
  public static void saveInventory(String name, PInv pinv) {
    BaseSerializer serializer = getSerializer(name);
    Date now = new Date();
    String date = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(now);
    System.out.println("10. " + date);
    int curSection = serializer.config.getInt("curSection", 0);
    serializer.config.set("curSection", (curSection + 1) % 3);
    ConfigurationSection pcs = serializer.config.createSection(curSection + "");
    pcs.set("storedDate", date);
    List<String> stritems = new ArrayList<String>();
    for (ItemStack is : pinv.armor) {
      if (is == null || is.getType() == Material.AIR) continue;
      stritems.add(InventoryUtil.getItemString(is));
    }
    pcs.set("armor", stritems);

    stritems = new ArrayList<String>();
    for (ItemStack is : pinv.contents) {
      if (is == null || is.getType() == Material.AIR) continue;
      stritems.add(InventoryUtil.getItemString(is));
    }
    pcs.set("contents", stritems);

    serializer.save();
  }
示例#23
0
	private ChunkGenerator getGenerator(int dimID) {
		ConfigurationSection section = bukkitConfig.getConfigurationSection("worlds");
		ChunkGenerator result = null;

		if (section != null) {
			section = section.getConfigurationSection(Integer.toString(dimID));

			if (section != null) {
				String name = section.getString("generator");

				if ((name != null) && (!name.equals(""))) {
					String[] split = name.split(":", 2);
					String id = (split.length > 1) ? split[1] : null;
					Plugin plugin = pluginManager.getPlugin(split[0]);

					if (plugin == null) {
						getLogger().severe("Could not set generator for default world '" + Integer.toString(dimID) + "': Plugin '" + split[0] + "' does not exist");
					} else if (!plugin.isEnabled()) {
						getLogger().severe("Could not set generator for default world '" + Integer.toString(dimID) + "': Plugin '" + split[0] + "' is not enabled yet (is it load:STARTUP?)");
					} else {
						result = plugin.getDefaultWorldGenerator(Integer.toString(dimID), id);
					}
				}
			}
		}

		return result;
	}
示例#24
0
  @Override
  public boolean onCommand(
      CommandSender sender, Command command, String alias, LinkedList<String> args) {
    ConfigurationSection cfg = plugin.getConfig().getConfigurationSection("cook-mappings");
    String key = ((Player) sender).getItemInHand().getType().name();
    String newMaterialName = cfg.getString(key);
    if (newMaterialName == null) {
      ((Player) sender).sendMessage(plugin.getMsg("errors.cant-cook-item"));
      return true;
    }
    Material newMat = null;
    Short dur = null;
    if (newMaterialName.contains(":")) {
      String[] materials = newMaterialName.split(":");
      newMat = Material.getMaterial(materials[0]);
      dur = Short.parseShort(materials[1]);
    } else {
      newMat = Material.getMaterial(newMaterialName);
    }

    if (newMat == null) {
      sender.sendMessage(plugin.getMsg("errors.cant-cook-item"));
      return true;
    }
    ((Player) sender).getItemInHand().setType(newMat);
    if (dur != null) {
      ((Player) sender).getItemInHand().setDurability(dur);
    }
    ((Player) sender).sendMessage(plugin.getMsg("cooked"));
    return true;
  }
  public boolean isVaultAvailable(Player p) {

    String vaultPath = new StringBuilder(43).append("vaults.").append(p.getUniqueId()).toString();
    ConfigurationSection singlePlayerVaultSection = data.getConfigurationSection(vaultPath);

    return singlePlayerVaultSection.getInt("itemCount", 0) < auctionConfig.getVaultCapacity(p);
  }
 private static Location loadLocation(ConfigurationSection section) {
   String world = section.getString("world");
   double x = section.getDouble("x");
   double y = section.getDouble("y");
   double z = section.getDouble("z");
   return new Location(Bukkit.getWorld(world), x, y, z);
 }
 public void removePlayer(String name) {
   ConfigurationSection section =
       this.getConfiguration().getConfigurationSection("reserved-players");
   section.set(name, null);
   this.save();
   this.reservedPlayers.remove(name);
 }
示例#28
0
 public void save(ConfigurationSection section) {
   section.set("location.world", loc.getWorld().getName());
   section.set("location.x", loc.getX());
   section.set("location.y", loc.getY());
   section.set("location.z", loc.getZ());
   section.set("arena", arena.getID());
 }
示例#29
0
  @Override
  public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    if (!target.hasTarget()) {
      return SpellResult.NO_TARGET;
    }
    if (target.hasEntity()) {
      Entity entity = target.getEntity();
      undoDamage = parameters.getBoolean("undo_damage", false);
      undoVelocity = parameters.getBoolean("undo_velocity", false);
      undoMovement = parameters.getBoolean("undo_movement", false);
      if (undoDamage || undoVelocity || undoMovement) {
        if (undoDamage) {
          registerModified(entity);
        }
        if (undoVelocity) {
          registerVelocity(entity);
        }
        if (undoMovement) {
          registerMoved(entity);
        }

        registerForUndo();
      }
    }

    return SpellResult.CAST;
  }
  private void initModuleClass(Rilncraft rilncraft, YamlConfiguration definition) {

    ConfigurationSection module;
    String className;

    module = definition.getConfigurationSection("module");
    if (module == null) {
      return;
    }

    className = module.getString("main");

    try {

      Class<Module> _tempClass = (Class<Module>) Class.forName(className);
      Constructor<Module> ctor =
          _tempClass.getDeclaredConstructor(Rilncraft.class, Configuration.class);
      Module newInstance = ctor.newInstance(rilncraft, definition);
      modulesLoaded.add(newInstance);

    } catch (ClassNotFoundException
        | InstantiationException
        | IllegalAccessException
        | IllegalArgumentException
        | InvocationTargetException
        | NoSuchMethodException
        | SecurityException ex) {
      Logger.getLogger(ModuleLoader.class.getName()).log(Level.SEVERE, null, ex);
    }
  }