/**
   * Attempt to load the MCPC remapper.
   *
   * @return TRUE if we succeeded, FALSE otherwise.
   * @throws RemapperUnavaibleException If the remapper is not present.
   */
  public RemappedClassSource initialize() {
    try {
      Server server = Bukkit.getServer();
      if (server == null) {
        throw new IllegalStateException("Bukkit not initialized.");
      }

      String version = server.getVersion();
      if (!version.contains("MCPC") && !version.contains("Cauldron")) {
        throw new RemapperUnavaibleException(Reason.MCPC_NOT_PRESENT);
      }

      // Obtain the Class remapper used by MCPC+/Cauldron
      this.classRemapper = FieldUtils.readField(getClass().getClassLoader(), "remapper", true);

      if (this.classRemapper == null) {
        throw new RemapperUnavaibleException(Reason.REMAPPER_DISABLED);
      }

      // Initialize some fields and methods used by the Jar Remapper
      Class<?> renamerClazz = classRemapper.getClass();

      this.mapType =
          MethodUtils.getAccessibleMethod(renamerClazz, "map", new Class<?>[] {String.class});

      return this;

    } catch (RemapperUnavaibleException e) {
      throw e;
    } catch (Exception e) {
      // Damn it
      throw new RuntimeException("Cannot access MCPC remapper.", e);
    }
  }
Exemplo n.º 2
0
  @Override
  public void onEnable() {
    dfolder = getDataFolder();
    dfolder.mkdirs();
    this.gen = new UUIDGenerator();
    /* Register some listeners... */
    getServer().getPluginManager().registerEvents(new OnSignChanged(), this);
    getServer().getPluginManager().registerEvents(new OnDispense(), this);
    getServer().getPluginManager().registerEvents(new OnBlockPlace(), this);
    getServer().getPluginManager().registerEvents(new OnBlockBreak(), this);
    getServer().getPluginManager().registerEvents(new OnInteract(), this);
    getServer().getPluginManager().registerEvents(new OnPlayerJoin(), this);
    getCommand("infinitedispenser").setExecutor(new CommandInfiniteDispenser());

    Server serv = Bukkit.getServer();
    StatsRequest s = new StatsRequest("start");
    s.put("Plugin Version", ver + "");
    s.put("Bukkit Version", serv.getBukkitVersion());
    s.put("Full Version", serv.getVersion());
    s.put("Server Port", serv.getPort() + "");
    s.put("Online Mode", serv.getOnlineMode() + "");
    try {
      s.put("Unique ID", gen.getUID());
    } catch (Exception e1) {
    }
    s.put("Time", System.currentTimeMillis() + "");

    s.send("http://dashie.in/s.php?stat=%stat%");
    try {
      Metrics metrics = new Metrics(this);
      metrics.start();
    } catch (IOException e) {
      System.out.println("[ID] Error starting metrics!");
    }
    this.saveDefaultConfig();
    FileConfiguration cf = this.getConfig();
    update = cf.getBoolean("update-checking");
  }
Exemplo n.º 3
0
 @Override
 public String getVersion() {
   return server.getVersion();
 }
Exemplo n.º 4
0
  public static Object handle(Object obj) {
    if (obj instanceof World.Environment) {
      World.Environment e = (World.Environment) obj;
      if (e == World.Environment.NETHER) {
        return "nether";
      } else {
        return "normal";
      }
    } else if (obj instanceof File) {
      return ((File) obj).toString();
    } else if (obj instanceof Player) {
      Player p = (Player) obj;
      JSONObject o = new JSONObject();

      o.put("name", p.getName());
      o.put("op", p.isOp());
      o.put("health", p.getHealth());
      o.put("ip", p.getAddress().toString());
      o.put("itemInHand", p.getItemInHand());
      o.put("location", p.getLocation());
      o.put("inventory", p.getInventory());
      o.put("sneaking", p.isSneaking());
      o.put("inVehicle", p.isInsideVehicle());
      o.put("sleeping", p.isSleeping());
      o.put("world", p.getServer().getWorlds().indexOf(p.getWorld()));

      return o;
    } else if (obj instanceof Server) {
      Server s = (Server) obj;

      JSONObject o = new JSONObject();

      o.put("maxPlayers", s.getMaxPlayers());
      o.put("players", Arrays.asList(s.getOnlinePlayers()));
      o.put("port", s.getPort());
      o.put("name", s.getName());
      o.put("serverName", s.getServerName());
      o.put("version", s.getVersion());
      o.put("worlds", s.getWorlds());

      return o;
    } else if (obj instanceof World) {
      World w = (World) obj;

      JSONObject o = new JSONObject();

      o.put("environment", w.getEnvironment());
      o.put("fullTime", w.getFullTime());
      o.put("time", w.getTime());
      o.put("name", w.getName());
      o.put("isThundering", w.isThundering());
      o.put("hasStorm", w.hasStorm());

      return o;
    } else if (obj instanceof Plugin) {
      Plugin p = (Plugin) obj;
      PluginDescriptionFile d = p.getDescription();

      JSONObject o = new JSONObject();

      o.put("name", d.getName());
      o.put("description", d.getDescription());
      o.put("authors", d.getAuthors());
      o.put("version", d.getVersion());
      o.put("website", d.getWebsite());
      o.put("enabled", JSONAPI.instance.getServer().getPluginManager().isPluginEnabled(p));

      return o;
    } else if (obj instanceof ItemStack) {
      ItemStack i = (ItemStack) obj;

      JSONObject o = new JSONObject();

      o.put("type", i.getTypeId());
      o.put("durability", i.getDurability());
      o.put("amount", i.getAmount());

      return o;
    } else if (obj instanceof PlayerInventory) {
      PlayerInventory p = (PlayerInventory) obj;

      JSONObject o = new JSONObject();

      JSONObject armor = new JSONObject();
      armor.put("boots", p.getBoots());
      armor.put("chestplate", p.getChestplate());
      armor.put("helmet", p.getHelmet());
      armor.put("leggings", p.getLeggings());

      o.put("armor", armor);
      o.put("hand", p.getItemInHand());
      o.put("inventory", Arrays.asList(p.getContents()));

      return o;
    } else if (obj instanceof Location) {
      Location l = (Location) obj;

      JSONObject o = new JSONObject();

      o.put("x", l.getX());
      o.put("y", l.getY());
      o.put("z", l.getZ());
      o.put("pitch", l.getPitch());
      o.put("yaw", l.getYaw());

      return o;
    } else if (obj instanceof Plugin[]) {
      List<Plugin> l = Arrays.asList((Plugin[]) obj);

      Collections.sort(l, new PluginSorter());

      return l;
    } else if (obj instanceof Object[]) {
      int l = ((Object[]) obj).length;
      JSONArray a = new JSONArray();
      for (int i = 0; i < l; i++) {
        a.add(((Object[]) obj)[i]);
      }

      return a;
    }
    Logger.getLogger("JSONAPI").warning("Uncaugh object! Value:");
    Logger.getLogger("JSONAPI").warning(obj.toString());
    Logger.getLogger("JSONAPI").warning("Type:");
    Logger.getLogger("JSONAPI").warning(obj.getClass().getName());

    return new Object();
  }
Exemplo n.º 5
0
 @Override
 public void queryGameState(Tregmine tregmine) {
   Server server = tregmine.getServer();
   version = server.getName() + " " + server.getVersion();
 }