Пример #1
0
 /* Uses resource to create default file, if file does not yet exist */
 public boolean createDefaultFileFromResource(String resourcename, File deffile) {
   if (deffile.canRead()) return true;
   Log.info(deffile.getPath() + " not found - creating default");
   InputStream in = getClass().getResourceAsStream(resourcename);
   if (in == null) {
     Log.severe("Unable to find default resource - " + resourcename);
     return false;
   } else {
     FileOutputStream fos = null;
     try {
       fos = new FileOutputStream(deffile);
       byte[] buf = new byte[512];
       int len;
       while ((len = in.read(buf)) > 0) {
         fos.write(buf, 0, len);
       }
     } catch (IOException iox) {
       Log.severe("ERROR creatomg default for " + deffile.getPath());
       return false;
     } finally {
       if (fos != null)
         try {
           fos.close();
         } catch (IOException iox) {
         }
       if (in != null)
         try {
           in.close();
         } catch (IOException iox) {
         }
     }
     return true;
   }
 }
Пример #2
0
  public static Integer getHighScoreRank(String player) {
    Connection conn = getConnection();
    PreparedStatement ps = null;
    ResultSet set = null;
    boolean exist = false;
    Integer counter = 0;

    try {
      ps = conn.prepareStatement("SELECT * FROM monsterhunt_highscores ORDER BY highscore DESC");
      set = ps.executeQuery();
      while (set.next()) {
        counter++;
        String name = set.getString("name");
        if (name.equals(player)) {
          exist = true;
          break;
        }
      }
      set.close();
      ps.close();
      conn.close();
    } catch (SQLException e) {
      Log.severe("Error while retreiving high scores! - " + e.getMessage());
      e.printStackTrace();
    }
    if (exist) {
      return counter;
    } else {
      return null;
    }
  }
Пример #3
0
  public static LinkedHashMap<String, Integer> getTopScores(int number) {
    Connection conn = getConnection();
    PreparedStatement ps = null;
    ResultSet set = null;
    LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>();

    try {
      ps =
          conn.prepareStatement(
              "SELECT * FROM monsterhunt_highscores ORDER BY highscore DESC LIMIT ?");
      ps.setInt(1, number);
      set = ps.executeQuery();

      while (set.next()) {
        String name = set.getString("name");
        Integer score = set.getInt("highscore");
        map.put(name, score);
      }
      set.close();
      ps.close();
      conn.close();
    } catch (SQLException e) {
      Log.severe("Error while retreiving high scores! - " + e.getMessage());
      e.printStackTrace();
    }
    return map;
  }
Пример #4
0
 public void startWebserver() {
   try {
     webServer.startServer();
   } catch (IOException e) {
     Log.severe(
         "Failed to start WebServer on "
             + webServer.getAddress()
             + ":"
             + webServer.getPort()
             + "!");
   }
 }
Пример #5
0
  private void running() {
    try {
      while (Thread.currentThread() == thread) {
        T t = pop();
        if (t != null) {
          handler.handle(t);
        }
        sleep(dequeueTime);
      }

    } catch (Exception ex) {
      Log.severe("Exception on rendering-thread", ex);
    }
  }
Пример #6
0
 public static void UpdateHighScore(String playername, int score) {
   try {
     Connection conn = InputOutput.getConnection();
     PreparedStatement ps =
         conn.prepareStatement("REPLACE INTO monsterhunt_highscores VALUES (?,?)");
     ps.setString(1, playername);
     ps.setInt(2, score);
     ps.executeUpdate();
     conn.commit();
     ps.close();
     conn.close();
   } catch (SQLException e) {
     Log.severe("Error while inserting new high score into DB! - " + e.getMessage());
     e.printStackTrace();
   }
 }
Пример #7
0
 protected void loadDebuggers() {
   List<ConfigurationNode> debuggersConfiguration = configuration.getNodes("debuggers");
   Debug.clearDebuggers();
   for (ConfigurationNode debuggerConfiguration : debuggersConfiguration) {
     try {
       Class<?> debuggerClass = Class.forName((String) debuggerConfiguration.getString("class"));
       Constructor<?> constructor =
           debuggerClass.getConstructor(JavaPlugin.class, ConfigurationNode.class);
       Debugger debugger = (Debugger) constructor.newInstance(this, debuggerConfiguration);
       Debug.addDebugger(debugger);
     } catch (Exception e) {
       Log.severe("Error loading debugger: " + e);
       e.printStackTrace();
       continue;
     }
   }
 }
Пример #8
0
 /**
  * Register event listener - this will be cleaned up properly on a /dynmap reload, unlike
  * registering with Bukkit directly
  */
 public void registerEvent(Event.Type type, Listener listener) {
   List<Listener> ll = event_handlers.get(type);
   PluginManager pm = getServer().getPluginManager();
   if (ll == null) {
     switch (type) {
       /* See if it is a type we're brokering */
       case PLAYER_LOGIN:
       case PLAYER_CHAT:
       case PLAYER_JOIN:
       case PLAYER_QUIT:
       case PLAYER_MOVE:
         pm.registerEvent(type, ourPlayerEventHandler, Event.Priority.Monitor, this);
         break;
       case BLOCK_PLACE:
       case BLOCK_BREAK:
       case LEAVES_DECAY:
       case BLOCK_BURN:
       case BLOCK_FORM:
       case BLOCK_FADE:
       case BLOCK_SPREAD:
       case BLOCK_PISTON_EXTEND:
       case BLOCK_PISTON_RETRACT:
         pm.registerEvent(type, ourBlockEventHandler, Event.Priority.Monitor, this);
         break;
       case WORLD_LOAD:
       case CHUNK_LOAD:
       case CHUNK_POPULATED:
       case SPAWN_CHANGE:
         pm.registerEvent(type, ourWorldEventHandler, Event.Priority.Monitor, this);
         break;
       case CUSTOM_EVENT:
         pm.registerEvent(type, ourCustomEventHandler, Event.Priority.Monitor, this);
         break;
       case ENTITY_EXPLODE:
         pm.registerEvent(type, ourEntityEventHandler, Event.Priority.Monitor, this);
         break;
       default:
         Log.severe("registerEvent() in DynmapPlugin does not handle " + type);
         return;
     }
     ll = new ArrayList<Listener>();
     event_handlers.put(type, ll); /* Add list for this event */
   }
   ll.add(listener);
 }
Пример #9
0
 public static void PrepareDB() {
   Connection conn = null;
   Statement st = null;
   try {
     conn = InputOutput.getConnection();
     st = conn.createStatement();
     if (Settings.globals.getBoolean("Database.UseMySQL", false)) {
       st.executeUpdate(
           "CREATE TABLE IF NOT EXISTS `monsterhunt_highscores` ( `name` varchar(250) NOT NULL DEFAULT '', `highscore` integer DEFAULT NULL, PRIMARY KEY (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
     } else {
       st.executeUpdate(
           "CREATE TABLE IF NOT EXISTS \"monsterhunt_highscores\" (\"name\" VARCHAR PRIMARY KEY  NOT NULL , \"highscore\" INTEGER)");
     }
     conn.commit();
   } catch (SQLException e) {
     Log.severe("Error while creating tables! - " + e.getMessage());
   }
 }
Пример #10
0
 /* Trigger on main thread */
 public boolean triggerSync(DynmapCore core, final T t) {
   Future<T> future =
       core.getServer()
           .callSyncMethod(
               new Callable<T>() {
                 @Override
                 public T call() throws Exception {
                   trigger(t);
                   return t;
                 }
               });
   boolean success = false;
   try {
     if (future != null) {
       future.get();
       success = true;
     }
   } catch (ExecutionException ix) {
     Log.severe("Exception in triggerSync", ix.getCause());
   } catch (InterruptedException ix) {
   }
   return success;
 }
Пример #11
0
  public static Integer getHighScore(String player) {
    Connection conn = getConnection();
    PreparedStatement ps = null;
    ResultSet set = null;
    Integer score = null;

    try {
      ps = conn.prepareStatement("SELECT * FROM monsterhunt_highscores WHERE name = ? LIMIT 1");

      ps.setString(1, player);
      set = ps.executeQuery();

      if (set.next()) {
        score = set.getInt("highscore");
      }
      set.close();
      ps.close();
      conn.close();
    } catch (SQLException e) {
      Log.severe("Error while retreiving high scores! - " + e.getMessage());
      e.printStackTrace();
    }
    return score;
  }
Пример #12
0
  public static void LoadSettings() {
    if (!new File("plugins" + File.separator + "MonsterHunt").exists()) {
      try {
        (new File("plugins" + File.separator + "MonsterHunt")).mkdir();
      } catch (Exception e) {
        Log.severe("Unable to create plugins/MontsterHunt/ directory");
      }
    }
    Settings.globals = new YamlConfiguration();

    LoadDefaults();

    for (String n : Settings.globals.getString("EnabledWorlds").split(",")) {
      MonsterHuntWorld mw = new MonsterHuntWorld(n);
      YamlConfiguration config = new YamlConfiguration();
      Settings settings =
          new Settings(
              config,
              new File("plugins" + File.separator + "MonsterHunt" + File.separator, n + ".yml"));
      mw.settings = settings;
      HuntWorldManager.worlds.put(n, mw);
    }

    String[] temp = Settings.globals.getString("HuntZone.FirstCorner", "0,0,0").split(",");
    HuntZone.corner1 =
        new Location(
            null,
            Double.parseDouble(temp[0]),
            Double.parseDouble(temp[1]),
            Double.parseDouble(temp[2]));
    temp = Settings.globals.getString("HuntZone.SecondCorner", "0,0,0").split(",");
    HuntZone.corner2 =
        new Location(
            null,
            Double.parseDouble(temp[0]),
            Double.parseDouble(temp[1]),
            Double.parseDouble(temp[2]));
    temp = Settings.globals.getString("HuntZone.TeleportLocation", "0,0,0").split(",");
    World world =
        MonsterHunt.instance
            .getServer()
            .getWorld(
                Settings.globals.getString(
                    "HuntZone.World",
                    MonsterHunt.instance.getServer().getWorlds().get(0).getName()));
    HuntZone.teleport =
        new Location(
            world,
            Double.parseDouble(temp[0]),
            Double.parseDouble(temp[1]),
            Double.parseDouble(temp[2]));

    // Create zone world
    MonsterHuntWorld mw = new MonsterHuntWorld(world.getName());
    YamlConfiguration config = new YamlConfiguration();
    Settings settings =
        new Settings(
            config,
            new File("plugins" + File.separator + "MonsterHunt" + File.separator + "zone.yml"));
    mw.settings = settings;

    HuntWorldManager.HuntZoneWorld = mw;
  }