コード例 #1
0
ファイル: Updater.java プロジェクト: pyrodogg/LWC
  /** Load all the classes in the current jar file so it can be overwritten */
  private void loadAllClasses() {
    LWC lwc = LWC.getInstance();

    try {
      // Load the jar
      JarFile jar = new JarFile(lwc.getPlugin().getFile());

      // Walk through all of the entries
      Enumeration<JarEntry> enumeration = jar.entries();

      while (enumeration.hasMoreElements()) {
        JarEntry entry = enumeration.nextElement();
        String name = entry.getName();

        // is it a class file?
        if (name.endsWith(".class")) {
          // convert to package
          String path = name.replaceAll("/", ".");
          path = path.substring(0, path.length() - ".class".length());

          // Load it
          this.getClass().getClassLoader().loadClass(path);
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
ファイル: Database.java プロジェクト: TeamMCD/LWC
  public Database() {
    currentType = DefaultType;

    prefix = LWC.getInstance().getConfiguration().getString("database.prefix", "");
    if (prefix == null) {
      prefix = "";
    }
  }
コード例 #3
0
ファイル: Database.java プロジェクト: TeamMCD/LWC
  /** @return the path where the database file should be saved */
  public String getDatabasePath() {
    Configuration lwcConfiguration = LWC.getInstance().getConfiguration();

    if (currentType == Type.MySQL) {
      return "//"
          + lwcConfiguration.getString("database.host")
          + "/"
          + lwcConfiguration.getString("database.database");
    }

    return lwcConfiguration.getString("database.path");
  }
コード例 #4
0
ファイル: LimitsV2.java プロジェクト: Kainzo/LWC
  /**
   * Checks if a player has reached their protection limit
   *
   * @param player
   * @param material the material type the player has interacted with
   * @return
   */
  public boolean hasReachedLimit(Player player, Material material) {
    LWC lwc = LWC.getInstance();
    Limit limit = getEffectiveLimit(player, material);

    // if they don't have a limit it's not possible to reach it ^^
    //  ... but if it's null, what the hell did the server owner do?
    if (limit == null) {
      return false;
    }

    // Get the effective limit placed upon them
    int neverPassThisNumber = limit.getLimit();

    // get the amount of protections the player has
    int protections = limit.getProtectionCount(player, material);

    return protections >= neverPassThisNumber;
  }
コード例 #5
0
ファイル: LimitsV2.java プロジェクト: Kainzo/LWC
  /**
   * Gets the list of limits that may apply to the player. For group limits, it uses the highest one
   * found.
   *
   * @param player
   * @return
   */
  public List<Limit> getPlayerLimits(Player player) {
    LWC lwc = LWC.getInstance();
    List<Limit> limits = new LinkedList<Limit>();

    // get all of their own limits
    String playerName = player.getName().toLowerCase();
    if (playerLimits.containsKey(playerName)) {
      limits.addAll(playerLimits.get(playerName));
    }

    // Look over the group limits
    for (String group : lwc.getPermissions().getGroups(player)) {
      if (groupLimits.containsKey(group)) {
        for (Limit limit : groupLimits.get(group)) {
          // try to match one already inside what we found
          Limit matched = findLimit(limits, limit);

          if (matched != null) {
            // Is our limit better?
            if (limit.getLimit() > matched.getLimit()) {
              limits.remove(matched);
              limits.add(limit);
            }
          } else {
            limits.add(limit);
          }
        }
      }
    }

    // Look at the default limits
    for (Limit limit : defaultLimits) {
      // try to match one already inside what we found
      Limit matched = findLimit(limits, limit);

      if (matched == null) {
        limits.add(limit);
      }
    }

    return limits;
  }
コード例 #6
0
ファイル: LimitsV2.java プロジェクト: Kainzo/LWC
  /**
   * Sends the list of limits to the player
   *
   * @param sender the commandsender to send the limits to
   * @param target the player limits are being shown for, can be null
   * @param limits
   */
  public void sendLimits(CommandSender sender, Player target, List<Limit> limits) {
    LWC lwc = LWC.getInstance();

    for (Limit limit : limits) {
      if (limit == null) {
        continue;
      }

      String stringLimit =
          limit.getLimit() == UNLIMITED ? "Unlimited" : Integer.toString(limit.getLimit());
      String colour = Colors.Yellow;

      if (target != null) {
        boolean reachedLimit =
            hasReachedLimit(
                target,
                ((limit instanceof BlockLimit) ? ((BlockLimit) limit).getMaterial() : null));
        colour = reachedLimit ? Colors.Red : Colors.Green;
      }

      if (limit instanceof DefaultLimit) {
        String currentProtected =
            target != null ? (Integer.toString(limit.getProtectionCount(target, null)) + "/") : "";
        sender.sendMessage("Default: " + colour + currentProtected + stringLimit);
      } else if (limit instanceof BlockLimit) {
        BlockLimit blockLimit = (BlockLimit) limit;
        String currentProtected =
            target != null
                ? (Integer.toString(limit.getProtectionCount(target, blockLimit.getMaterial()))
                    + "/")
                : "";
        sender.sendMessage(
            lwc.materialToString(blockLimit.getMaterial())
                + ": "
                + colour
                + currentProtected
                + stringLimit);
      } else {
        sender.sendMessage(limit.getClass().getSimpleName() + ": " + Colors.Yellow + stringLimit);
      }
    }
  }
コード例 #7
0
ファイル: Updater.java プロジェクト: pyrodogg/LWC
  public void init() {
    LWC lwc = LWC.getInstance();
    updateBranch = UpdateBranch.match(lwc.getConfiguration().getString("updater.branch", "STABLE"));
    updateMethod = UpdateMethod.match(lwc.getConfiguration().getString("updater.method", "MANUAL"));

    if (updateMethod == UpdateMethod.AUTOMATIC) {
      this.loadVersions(
          true,
          new Runnable() {

            public void run() {
              tryAutoUpdate(false);
              logger.info("LWC: Latest version: " + latestVersion);
            }
          });
    }

    // verify we have local files (e.g sqlite.jar, etc)
    this.verifyFiles();
    this.downloadFiles();
  }
コード例 #8
0
  @Override
  public void onBlockInteract(LWCBlockInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
      return;
    }

    if (!event.hasAction("create")) {
      return;
    }

    LWC lwc = event.getLWC();
    Block block = event.getBlock();
    LWCPlayer player = lwc.wrapPlayer(event.getPlayer());

    if (!lwc.isProtectable(block)) {
      return;
    }

    PhysDB physDb = lwc.getPhysicalDatabase();

    Action action = player.getAction("create");
    String actionData = action.getData();
    String[] split = actionData.split(" ");
    String protectionType = split[0].toLowerCase();
    String protectionData = StringUtil.join(split, 1);

    // check permissions again (DID THE LITTLE SHIT MOVE WORLDS??!?!?!?!?!?)
    if (!lwc.hasPermission(
        event.getPlayer(), "lwc.create." + protectionType, "lwc.create", "lwc.protect")) {
      lwc.sendLocale(player, "protection.accessdenied");
      lwc.removeModes(player);
      event.setResult(Result.CANCEL);
      return;
    }

    // misc data we'll use later
    String playerName = player.getName();
    String worldName = block.getWorld().getName();
    int blockX = block.getX();
    int blockY = block.getY();
    int blockZ = block.getZ();

    lwc.removeModes(player);
    LWCProtectionRegisterEvent evt =
        new LWCProtectionRegisterEvent(player.getBukkitPlayer(), block);
    lwc.getModuleLoader().dispatchEvent(evt);

    // another plugin cancelled the registration
    if (evt.isCancelled()) {
      return;
    }

    // The created protection
    Protection protection = null;

    if (protectionType.equals("public")) {
      protection =
          physDb.registerProtection(
              block.getTypeId(),
              Protection.Type.PUBLIC,
              worldName,
              player.getUniqueId().toString(),
              "",
              blockX,
              blockY,
              blockZ);
      lwc.sendLocale(player, "protection.interact.create.finalize");
    } else if (protectionType.equals("password")) {
      String password = lwc.encrypt(protectionData);

      protection =
          physDb.registerProtection(
              block.getTypeId(),
              Protection.Type.PASSWORD,
              worldName,
              player.getUniqueId().toString(),
              password,
              blockX,
              blockY,
              blockZ);
      player.addAccessibleProtection(protection);

      lwc.sendLocale(player, "protection.interact.create.finalize");
      lwc.sendLocale(player, "protection.interact.create.password");
    } else if (protectionType.equals("private") || protectionType.equals("donation")) {
      String[] rights = protectionData.split(" ");

      protection =
          physDb.registerProtection(
              block.getTypeId(),
              Protection.Type.matchType(protectionType),
              worldName,
              player.getUniqueId().toString(),
              "",
              blockX,
              blockY,
              blockZ);

      lwc.sendLocale(player, "protection.interact.create.finalize");
      lwc.processRightsModifications(player, protection, rights);
    }

    // tell the modules that a protection was registered
    if (protection != null) {
      // Fix the blocks that match it
      protection.removeCache();
      LWC.getInstance().getProtectionCache().addProtection(protection);

      lwc.getModuleLoader().dispatchEvent(new LWCProtectionRegistrationPostEvent(protection));
    }

    event.setResult(Result.CANCEL);
  }
コード例 #9
0
ファイル: Statistics.java プロジェクト: kevupton/LWC
  /**
   * Send a performance report to a Console Sender
   *
   * @param sender
   */
  public static void sendReport(CommandSender sender) {
    LWC lwc = LWC.getInstance();

    sender.sendMessage(" ");
    sender.sendMessage(Colors.Red + "LWC Report");
    sender.sendMessage("  Version: " + Colors.Green + LWCInfo.FULL_VERSION);
    sender.sendMessage(
        "  Running time: " + Colors.Green + TimeUtil.timeToString(getTimeRunningSeconds()));
    sender.sendMessage(
        "  Players: "
            + Colors.Green
            + Bukkit.getServer().getOnlinePlayers().length
            + "/"
            + Bukkit.getServer().getMaxPlayers());
    sender.sendMessage(
        "  Item entities: "
            + Colors.Green
            + getEntityCount(Item.class)
            + "/"
            + getEntityCount(null));
    sender.sendMessage(" ");
    sender.sendMessage(Colors.Red + " ==== Modules ====");

    for (Map.Entry<Plugin, List<MetaData>> entry :
        lwc.getModuleLoader().getRegisteredModules().entrySet()) {
      Plugin plugin = entry.getKey();
      List<MetaData> modules = entry.getValue();

      // Why?
      if (plugin == null) {
        continue;
      }

      sender.sendMessage(
          "  "
              + Colors.Green
              + plugin.getDescription().getName()
              + " v"
              + plugin.getDescription().getVersion()
              + Colors.Yellow
              + " -> "
              + Colors.Green
              + modules.size()
              + Colors.Yellow
              + " registered modules");
    }
    sender.sendMessage(" ");

    sender.sendMessage(Colors.Red + " ==== Database ====");
    sender.sendMessage("  Engine: " + Colors.Green + Database.DefaultType);
    sender.sendMessage(
        "  Protections: "
            + Colors.Green
            + formatNumber(lwc.getPhysicalDatabase().getProtectionCount()));
    sender.sendMessage(
        "  Queries: "
            + Colors.Green
            + formatNumber(queries)
            + " | "
            + String.format("%.2f", getAverage(queries))
            + " / second");
    sender.sendMessage(" ");

    sender.sendMessage(Colors.Red + " ==== Cache ==== ");
    ProtectionCache cache = lwc.getProtectionCache();
    sender.sendMessage("  Refs: " + cache.size() + "/" + cache.capacity());
    sender.sendMessage(
        "  Reads: "
            + formatNumber(cache.getReads())
            + " | "
            + String.format("%.2f", getAverage(cache.getReads()))
            + " / second");
    sender.sendMessage(
        "  Writes: "
            + formatNumber(cache.getWrites())
            + " | "
            + String.format("%.2f", getAverage(cache.getWrites()))
            + " / second");
  }
コード例 #10
0
ファイル: Database.java プロジェクト: TeamMCD/LWC
 /**
  * Log a string to stdout
  *
  * @param str The string to log
  */
 public void log(String str) {
   LWC.getInstance().log(str);
 }
コード例 #11
0
ファイル: Database.java プロジェクト: TeamMCD/LWC
  /**
   * Connect to MySQL
   *
   * @return if the connection was succesful
   */
  public boolean connect() throws Exception {
    if (connection != null) {
      return true;
    }

    if (currentType == null || currentType == Type.NONE) {
      log("Invalid database engine");
      return false;
    }

    // load the database jar
    ClassLoader classLoader;

    if (currentType == Type.SQLite) {
      classLoader =
          new URLClassLoader(
              new URL[] {
                new URL(
                    "jar:file:"
                        + new File(Updater.DEST_LIBRARY_FOLDER + currentType.getDriver()).getPath()
                        + "!/")
              });
    } else {
      classLoader = Bukkit.getServer().getClass().getClassLoader();
    }

    // What class should we try to load?
    String className = "";
    if (currentType == Type.MySQL) {
      className = "com.mysql.jdbc.Driver";
    } else {
      className = "org.sqlite.JDBC";
    }

    // Load the driver class
    Driver driver = (Driver) classLoader.loadClass(className).newInstance();

    // Create the properties to pass to the driver
    Properties properties = new Properties();

    // if we're using mysql, append the database info
    if (currentType == Type.MySQL) {
      LWC lwc = LWC.getInstance();
      properties.put("autoReconnect", "true");
      properties.put("user", lwc.getConfiguration().getString("database.username"));
      properties.put("password", lwc.getConfiguration().getString("database.password"));
    }

    // Connect to the database
    try {
      connection =
          driver.connect(
              "jdbc:" + currentType.toString().toLowerCase() + ":" + getDatabasePath(), properties);
      connected = true;
      return true;
    } catch (SQLException e) {
      log("Failed to connect to " + currentType);
      e.printStackTrace();
      return false;
    }
  }
コード例 #12
0
ファイル: LimitsV2.java プロジェクト: Kainzo/LWC
 @Override
 public int getProtectionCount(Player player, Material material) {
   return LWC.getInstance().getPhysicalDatabase().getProtectionCount(player.getName());
 }