예제 #1
0
  @Override
  @SuppressWarnings("deprecation")
  public void onDropItem(LWCDropItemEvent event) {
    Player bPlayer = event.getPlayer();
    Item item = event.getEvent().getItemDrop();
    ItemStack itemStack = item.getItemStack();

    LWCPlayer player = lwc.wrapPlayer(bPlayer);
    int protectionId = getPlayerDropTransferTarget(player);

    if (protectionId == -1) {
      return;
    }

    if (!isPlayerDropTransferring(player)) {
      return;
    }

    Protection protection = lwc.getPhysicalDatabase().loadProtection(protectionId);

    if (protection == null) {
      lwc.sendLocale(player, "lwc.nolongerexists");
      player.disableMode(player.getMode("dropTransfer"));
      return;
    }

    // load the world and the inventory
    World world = player.getServer().getWorld(protection.getWorld());

    if (world == null) {
      lwc.sendLocale(player, "lwc.invalidworld");
      player.disableMode(player.getMode("dropTransfer"));
      return;
    }

    // Don't allow them to transfer items across worlds
    if (bPlayer.getWorld() != world
        && !lwc.getConfiguration().getBoolean("modes.droptransfer.crossWorld", false)) {
      lwc.sendLocale(player, "lwc.dropxfer.acrossworlds");
      player.disableMode(player.getMode("dropTransfer"));
      return;
    }

    Block block = world.getBlockAt(protection.getX(), protection.getY(), protection.getZ());
    Map<Integer, ItemStack> remaining = lwc.depositItems(block, itemStack);

    if (remaining.size() > 0) {
      lwc.sendLocale(player, "lwc.dropxfer.chestfull");

      for (ItemStack temp : remaining.values()) {
        bPlayer.getInventory().addItem(temp);
      }
    }

    bPlayer.updateInventory(); // if they're in the chest and dropping items, this is required
    item.remove();
  }
예제 #2
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();
  }
예제 #3
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;
    }
  }