Guest User

Untitled

a guest
Jun 9th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package com.rs.worldserver;
  6.  
  7. import java.sql.*;
  8. import java.io.*;
  9.  
  10. import com.rs.worldserver.util.*;
  11.  
  12. import com.rs.worldserver.model.npc.NPC;
  13. import com.rs.worldserver.model.npc.NPC;
  14. import com.rs.worldserver.model.npc.NPCAction;
  15. import com.rs.worldserver.model.npc.NPCDefinition;
  16. import com.rs.worldserver.model.npc.NPCDrop;
  17.  
  18. public class SQL {
  19.     public static Connection connection = null;
  20.     public static Connection myConnection = Server.connection;
  21.  
  22.     public SQL() {AutoSpawn();}
  23.    
  24.     public static void AutoSpawn() {
  25.         try {
  26.             String driverName = "com.mysql.jdbc.Driver";
  27.             Class.forName(driverName).newInstance();
  28.    
  29.             // Create a connection to the database
  30.             String serverName = "127.0.0.1";//your SQL server
  31.             String dbase = "";
  32.             String url = "jdbc:mysql://" + serverName +  ":3306/dynamicdb";
  33.             String username = "root";
  34.             String password = "";
  35.             connection = DriverManager.getConnection(url, username, password);
  36.        
  37.             Statement stmt = connection.createStatement();
  38.             ResultSet rs = stmt.executeQuery("SELECT * FROM autospawn");
  39.             while (rs.next()) {
  40.                 int id = rs.getInt("NpcID");
  41.                 int slot = rs.getInt("Slot");
  42.                 NPCDefinition def = Server.npcManager.npcDefinitions.get(id);
  43.                 if (def == null)
  44.                     continue;
  45.                 //count = rs.getRow();
  46.                 NPC npc = new NPC(slot, def, rs.getInt("StartX"), rs.getInt("StartY"), rs.getInt("StartHeight"));
  47.                 //NPC npc = new NPC(slot, def, Integer
  48.                     //.valueOf(valuesArray[1]), Integer
  49.                     //.valueOf(valuesArray[2]), Integer
  50.                     //.valueOf(valuesArray[3]));
  51.                 //npc.setX1(rs.getInt("RangeX1"));
  52.                 //npc.setY1(rs.getInt("RangeY1"));
  53.                 //npc.setX2(rs.getInt("RangeX2"));
  54.                 //npc.setY2(rs.getInt("RangeY2"));
  55.                 //int walkType = rs.getInt("WalkType");
  56.                 //if (walkType == 1 || walkType == 2) {
  57.                     //npc.setWalking(true);
  58.                 //}
  59.                                         Server.npcManager.npcMap.put(npc.getNpcId(), npc);
  60.             }
  61.             stmt.close();
  62.         } catch (Exception e){
  63.             Misc.println("Error "+e);
  64.         }  
  65.     }
  66. }
Add Comment
Please, Sign In to add comment