public ConfigData(FileConfiguration config) {
    for (Ability ability : Ability.values()) {
      ConfigurationSection conf = config.getConfigurationSection(ability.name());

      if (conf != null) {
        int item = conf.getInt("Item");
        List<String> types = (List<String>) conf.getList("ArmorTypes");
        if ((item != 0) && (types != null) && !types.isEmpty()) {
          abilities.add(new AbilityInfo(ability, ArmorUtils.materialName(item), item, types));

          switch (ability) {
            case MOON:
              jumpNum = conf.getInt("JumpBoost");
              break;
            case SCUBA:
              scubaHasteNum = conf.getInt("Haste");
              scubaTime = conf.getInt("ScubaTime");
              break;
            case SPEED:
              speedNum = conf.getInt("SpeedBoost");
              speedHasteNum = conf.getInt("Haste");
              break;
            case LAVA:
              lavaTime = conf.getInt("LavaTime");
              break;
            case RAGE:
              rageLightningDamage = conf.getInt("LightningDamage");
              rageFireTime = conf.getInt("FireTime");
              break;
            case CREEPER:
              creeperAbilityExplosion = conf.getInt("ExplosionSize");
              creeperBlockDamage = conf.getBoolean("BlockDamage");
              break;
            case MINER:
              minerHasteNum = conf.getInt("Haste");
              break;
            case ASSASSIN:
              assassinDamage = conf.getInt("SneakDamage");
              break;
            case VAMPIRE:
              vampirePercent = conf.getDouble("VampirePercent", 25);
              break;
          }
        }
      }
    }
  }
Exemple #2
0
 public void load(ConfigurationSection config) {
   // Set some defaults.
   config.addDefault("Permission", "");
   config.addDefault("Interval", 60);
   config.addDefault("Prefix", "[&eServer&r] ");
   config.addDefault("LogToConsole", true);
   config.addDefault("Randomize", true);
   config.addDefault("Announcements", new ArrayList<String>(0));
   // Load
   permission = config.getString("Permission");
   if (permission.length() == 0) permission = null;
   interval = config.getInt("Interval");
   Object prefix = config.get("Prefix");
   logToConsole = config.getBoolean("LogToConsole");
   randomize = config.getBoolean("Randomize");
   announcements.clear();
   randomQueue = null;
   for (Object entry : config.getList("Announcements")) {
     announcements.add(Announcement.withPrefixAndEntry(prefix, entry));
   }
 }
Exemple #3
0
 public static void load(LogBlock logblock) throws DataFormatException, IOException {
   final ConfigurationSection config = logblock.getConfig();
   final Map<String, Object> def = new HashMap<String, Object>();
   def.put("version", logblock.getDescription().getVersion());
   final List<String> worldNames = new ArrayList<String>();
   for (final World world : getWorlds()) worldNames.add(world.getName());
   if (worldNames.isEmpty()) {
     worldNames.add("world");
     worldNames.add("world_nether");
     worldNames.add("world_the_end");
   }
   def.put("loggedWorlds", worldNames);
   def.put("mysql.host", "localhost");
   def.put("mysql.port", 3306);
   def.put("mysql.database", "minecraft");
   def.put("mysql.user", "username");
   def.put("mysql.password", "pass");
   def.put("consumer.delayBetweenRuns", 2);
   def.put("consumer.forceToProcessAtLeast", 200);
   def.put("consumer.timePerRun", 1000);
   def.put("consumer.fireCustomEvents", false);
   def.put("consumer.useBukkitScheduler", true);
   def.put("consumer.queueWarningSize", 1000);
   def.put("clearlog.dumpDeletedLog", false);
   def.put("clearlog.enableAutoClearLog", false);
   def.put(
       "clearlog.auto",
       Arrays.asList(
           "world \"world\" before 365 days all",
           "world \"world\" player lavaflow waterflow leavesdecay before 7 days all",
           "world world_nether before 365 days all",
           "world world_nether player lavaflow before 7 days all"));
   def.put("clearlog.autoClearLogDelay", "6h");
   def.put("logging.logCreeperExplosionsAsPlayerWhoTriggeredThese", false);
   def.put("logging.logKillsLevel", "PLAYERS");
   def.put("logging.logPlayerInfo", false);
   def.put("logging.hiddenPlayers", new ArrayList<String>());
   def.put("logging.hiddenBlocks", Arrays.asList(0));
   def.put("logging.ignoredChat", Arrays.asList("/register", "/login"));
   def.put("rollback.dontRollback", Arrays.asList(10, 11, 46, 51));
   def.put("rollback.replaceAnyway", Arrays.asList(8, 9, 10, 11, 51));
   def.put("rollback.maxTime", "2 days");
   def.put("rollback.maxArea", 50);
   def.put("lookup.defaultDist", 20);
   def.put("lookup.defaultTime", "30 minutes");
   def.put("lookup.linesPerPage", 15);
   def.put("lookup.linesLimit", 1500);
   try {
     formatter = new SimpleDateFormat(config.getString("lookup.dateFormat", "MM-dd HH:mm:ss"));
   } catch (IllegalArgumentException e) {
     throw new DataFormatException(
         "Invalid specification for  date format, please see http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html : "
             + e.getMessage());
   }
   def.put("lookup.dateFormat", "MM-dd HH:mm:ss");
   def.put("questioner.askRollbacks", true);
   def.put("questioner.askRedos", true);
   def.put("questioner.askClearLogs", true);
   def.put("questioner.askClearLogAfterRollback", true);
   def.put("questioner.askRollbackAfterBan", false);
   def.put("questioner.banPermission", "mcbans.ban.local");
   def.put("tools.tool.aliases", Arrays.asList("t"));
   def.put("tools.tool.leftClickBehavior", "NONE");
   def.put("tools.tool.rightClickBehavior", "TOOL");
   def.put("tools.tool.defaultEnabled", true);
   def.put("tools.tool.item", 270);
   def.put("tools.tool.canDrop", true);
   def.put("tools.tool.params", "area 0 all sum none limit 15 desc silent");
   def.put("tools.tool.mode", "LOOKUP");
   def.put("tools.tool.permissionDefault", "OP");
   def.put("tools.toolblock.aliases", Arrays.asList("tb"));
   def.put("tools.toolblock.leftClickBehavior", "TOOL");
   def.put("tools.toolblock.rightClickBehavior", "BLOCK");
   def.put("tools.toolblock.defaultEnabled", true);
   def.put("tools.toolblock.item", 7);
   def.put("tools.toolblock.canDrop", false);
   def.put("tools.toolblock.params", "area 0 all sum none limit 15 desc silent");
   def.put("tools.toolblock.mode", "LOOKUP");
   def.put("tools.toolblock.permissionDefault", "OP");
   def.put("safety.id.check", true);
   for (final Entry<String, Object> e : def.entrySet())
     if (!config.contains(e.getKey())) config.set(e.getKey(), e.getValue());
   logblock.saveConfig();
   url =
       "jdbc:mysql://"
           + config.getString("mysql.host")
           + ":"
           + config.getInt("mysql.port")
           + "/"
           + getStringIncludingInts(config, "mysql.database");
   user = getStringIncludingInts(config, "mysql.user");
   password = getStringIncludingInts(config, "mysql.password");
   delayBetweenRuns = config.getInt("consumer.delayBetweenRuns", 2);
   forceToProcessAtLeast = config.getInt("consumer.forceToProcessAtLeast", 0);
   timePerRun = config.getInt("consumer.timePerRun", 1000);
   fireCustomEvents = config.getBoolean("consumer.fireCustomEvents", false);
   useBukkitScheduler = config.getBoolean("consumer.useBukkitScheduler", true);
   queueWarningSize = config.getInt("consumer.queueWarningSize", 1000);
   enableAutoClearLog = config.getBoolean("clearlog.enableAutoClearLog");
   autoClearLog = config.getStringList("clearlog.auto");
   dumpDeletedLog = config.getBoolean("clearlog.dumpDeletedLog", false);
   autoClearLogDelay = parseTimeSpec(config.getString("clearlog.autoClearLogDelay").split(" "));
   logCreeperExplosionsAsPlayerWhoTriggeredThese =
       config.getBoolean("logging.logCreeperExplosionsAsPlayerWhoTriggeredThese", false);
   logPlayerInfo = config.getBoolean("logging.logPlayerInfo", true);
   try {
     logKillsLevel =
         LogKillsLevel.valueOf(config.getString("logging.logKillsLevel").toUpperCase());
   } catch (final IllegalArgumentException ex) {
     throw new DataFormatException(
         "lookup.toolblockID doesn't appear to be a valid log level. Allowed are 'PLAYERS', 'MONSTERS' and 'ANIMALS'");
   }
   hiddenPlayers = new HashSet<String>();
   for (final String playerName : config.getStringList("logging.hiddenPlayers"))
     hiddenPlayers.add(playerName.toLowerCase().trim());
   hiddenBlocks = new HashSet<Integer>();
   for (final Object blocktype : config.getList("logging.hiddenBlocks")) {
     final Material mat = Material.matchMaterial(String.valueOf(blocktype));
     if (mat != null) hiddenBlocks.add(mat.getId());
     else throw new DataFormatException("Not a valid material: '" + blocktype + "'");
   }
   ignoredChat = new HashSet<String>();
   for (String chatCommand : config.getStringList("logging.ignoredChat")) {
     ignoredChat.add(chatCommand);
   }
   dontRollback = new HashSet<Integer>(config.getIntegerList("rollback.dontRollback"));
   replaceAnyway = new HashSet<Integer>(config.getIntegerList("rollback.replaceAnyway"));
   rollbackMaxTime = parseTimeSpec(config.getString("rollback.maxTime").split(" "));
   rollbackMaxArea = config.getInt("rollback.maxArea", 50);
   defaultDist = config.getInt("lookup.defaultDist", 20);
   defaultTime = parseTimeSpec(config.getString("lookup.defaultTime").split(" "));
   linesPerPage = config.getInt("lookup.linesPerPage", 15);
   linesLimit = config.getInt("lookup.linesLimit", 1500);
   askRollbacks = config.getBoolean("questioner.askRollbacks", true);
   askRedos = config.getBoolean("questioner.askRedos", true);
   askClearLogs = config.getBoolean("questioner.askClearLogs", true);
   askClearLogAfterRollback = config.getBoolean("questioner.askClearLogAfterRollback", true);
   askRollbackAfterBan = config.getBoolean("questioner.askRollbackAfterBan", false);
   safetyIdCheck = config.getBoolean("safety.id.check", true);
   banPermission = config.getString("questioner.banPermission");
   final List<Tool> tools = new ArrayList<Tool>();
   final ConfigurationSection toolsSec = config.getConfigurationSection("tools");
   for (final String toolName : toolsSec.getKeys(false))
     try {
       final ConfigurationSection tSec = toolsSec.getConfigurationSection(toolName);
       final List<String> aliases = tSec.getStringList("aliases");
       final ToolBehavior leftClickBehavior =
           ToolBehavior.valueOf(tSec.getString("leftClickBehavior").toUpperCase());
       final ToolBehavior rightClickBehavior =
           ToolBehavior.valueOf(tSec.getString("rightClickBehavior").toUpperCase());
       final boolean defaultEnabled = tSec.getBoolean("defaultEnabled", false);
       final int item = tSec.getInt("item", 0);
       final boolean canDrop = tSec.getBoolean("canDrop", false);
       final QueryParams params = new QueryParams(logblock);
       params.prepareToolQuery = true;
       params.parseArgs(getConsoleSender(), Arrays.asList(tSec.getString("params").split(" ")));
       final ToolMode mode = ToolMode.valueOf(tSec.getString("mode").toUpperCase());
       final PermissionDefault pdef =
           PermissionDefault.valueOf(tSec.getString("permissionDefault").toUpperCase());
       tools.add(
           new Tool(
               toolName,
               aliases,
               leftClickBehavior,
               rightClickBehavior,
               defaultEnabled,
               item,
               canDrop,
               params,
               mode,
               pdef));
     } catch (final Exception ex) {
       getLogger().log(Level.WARNING, "Error at parsing tool '" + toolName + "': ", ex);
     }
   toolsByName = new HashMap<String, Tool>();
   toolsByType = new HashMap<Integer, Tool>();
   for (final Tool tool : tools) {
     toolsByType.put(tool.item, tool);
     toolsByName.put(tool.name.toLowerCase(), tool);
     for (final String alias : tool.aliases) toolsByName.put(alias, tool);
   }
   final List<String> loggedWorlds = config.getStringList("loggedWorlds");
   worldConfigs = new HashMap<String, WorldConfig>();
   if (loggedWorlds.isEmpty()) throw new DataFormatException("No worlds configured");
   for (final String world : loggedWorlds)
     worldConfigs.put(
         world,
         new WorldConfig(new File(logblock.getDataFolder(), friendlyWorldname(world) + ".yml")));
   superWorldConfig = new LoggingEnabledMapping();
   for (final WorldConfig wcfg : worldConfigs.values())
     for (final Logging l : Logging.values())
       if (wcfg.isLogging(l)) superWorldConfig.setLogging(l, true);
 }
Exemple #4
0
  public RPGItem(ConfigurationSection s) {

    name = s.getString("name");
    id = s.getInt("id");
    setDisplay(s.getString("display"), false);
    setType(
        s.getString("type", Plugin.plugin.getConfig().getString("defaults.sword", "Sword")), false);
    setHand(
        s.getString("hand", Plugin.plugin.getConfig().getString("defaults.hand", "One handed")),
        false);
    setLore(s.getString("lore"), false);
    description = (List<String>) s.getList("description", new ArrayList<String>());
    for (int i = 0; i < description.size(); i++) {
      description.set(i, ChatColor.translateAlternateColorCodes('&', description.get(i)));
    }
    quality = Quality.valueOf(s.getString("quality"));
    damageMin = s.getInt("damageMin");
    damageMax = s.getInt("damageMax");
    armour = s.getInt("armour", 0);
    item = new ItemStack(Material.valueOf(s.getString("item")));
    ItemMeta meta = item.getItemMeta();
    if (meta instanceof LeatherArmorMeta) {
      ((LeatherArmorMeta) meta).setColor(Color.fromRGB(s.getInt("item_colour", 0)));
    } else {
      item.setDurability((short) s.getInt("item_data", 0));
    }
    for (String locale : Locale.getLocales()) {
      localeMeta.put(locale, meta.clone());
    }
    ignoreWorldGuard = s.getBoolean("ignoreWorldGuard", false);

    // Powers
    ConfigurationSection powerList = s.getConfigurationSection("powers");
    if (powerList != null) {
      for (String sectionKey : powerList.getKeys(false)) {
        ConfigurationSection section = powerList.getConfigurationSection(sectionKey);
        try {
          if (!Power.powers.containsKey(section.getString("powerName"))) {
            // Invalid power
            continue;
          }
          Power pow = Power.powers.get(section.getString("powerName")).newInstance();
          pow.init(section);
          pow.item = this;
          addPower(pow, false);
        } catch (InstantiationException e) {
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        }
      }
    }
    encodedID = getMCEncodedID(id);

    // Recipes
    hasRecipe = s.getBoolean("hasRecipe", false);
    if (hasRecipe) {
      recipe = (List<ItemStack>) s.getList("recipe");
    }

    ConfigurationSection drops = s.getConfigurationSection("dropChances");
    if (drops != null) {
      for (String key : drops.getKeys(false)) {
        double chance = drops.getDouble(key, 0.0);
        chance = Math.min(chance, 100.0);
        if (chance > 0) {
          dropChances.put(key, chance);
          if (!Events.drops.containsKey(key)) {
            Events.drops.put(key, new HashSet<Integer>());
          }
          Set<Integer> set = Events.drops.get(key);
          set.add(getID());
        } else {
          dropChances.remove(key);
          if (Events.drops.containsKey(key)) {
            Set<Integer> set = Events.drops.get(key);
            set.remove(getID());
          }
        }
        dropChances.put(key, chance);
      }
    }
    if (item.getType().getMaxDurability() != 0) {
      hasBar = true;
    }
    maxDurability = s.getInt("maxDurability", item.getType().getMaxDurability());
    forceBar = s.getBoolean("forceBar", false);

    if (maxDurability == 0) {
      maxDurability = -1;
    }

    rebuild();
  }
  @EventHandler
  public void onPlayerInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();

    if (event.getAction().equals(Action.PHYSICAL)) {
      Block block = event.getClickedBlock();

      if (block.getTypeId() == 70) {
        String worldName = player.getWorld().getName();

        if (admins.containsKey(player)) {
          int mode = admins.get(event.getPlayer());
          admins.remove(player);

          @SuppressWarnings("unchecked")
          List<Vector> locations = (List<Vector>) liftsSave.getList(worldName);
          if (locations == null) {
            locations = new ArrayList<Vector>();
            liftsSave.set(worldName, locations);
          }

          switch (mode) {
            case 0:
              {
                if (locations.add(event.getClickedBlock().getLocation().toVector())) {
                  player.sendMessage("Pressure plate added!");
                } else {
                  player.sendMessage("Could not add pressure plate! Console?!");
                }
              }
              break;

            case 1:
              {
                admins.remove(player);
                if (locations.remove(event.getClickedBlock().getLocation().toVector())) {
                  player.sendMessage("Pressure plate removed!");
                } else {
                  player.sendMessage(
                      "Could not find pressure plate within database for this location!");
                }
              }
              break;
          }

        } else if (liftsSave.getList(worldName) != null
            && liftsSave.getList(worldName).contains(block.getLocation().toVector())) {

          if (lastUses.containsKey(player)) {
            Long lastUse = lastUses.get(player);
            if (new Date().getTime() - lastUse.longValue() < cooldown * 1000) {
              player.sendMessage("Cooldown aktiv. Versuch es in wenigen Sekunden noch einmal.");
              return;
            }
          }

          final Location oldLocation = player.getLocation();
          this.getServer()
              .getScheduler()
              .runTaskLater(
                  this,
                  new Runnable() {
                    public void run() {

                      if (player.isOnline()) {

                        if (player.getLocation().distance(oldLocation) < 1) {
                          lastUses.put(player, new Date().getTime());
                          spawnFirework(player.getLocation());
                          player.setVelocity(velocity);
                        }
                      }
                    }
                  },
                  timer * 20L);
        }
      }
    }
  }