refactor: use try-with-resources for PlayerNPC db operations
This commit is contained in:
@@ -21,32 +21,17 @@
|
|||||||
*/
|
*/
|
||||||
package server.life;
|
package server.life;
|
||||||
|
|
||||||
import config.YamlConfig;
|
|
||||||
import server.life.positioner.MaplePlayerNPCPositioner;
|
|
||||||
import server.life.positioner.MaplePlayerNPCPodium;
|
|
||||||
import java.awt.Point;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import client.MapleCharacter;
|
import client.MapleCharacter;
|
||||||
import client.MapleClient;
|
import client.MapleClient;
|
||||||
import client.inventory.Item;
|
import client.inventory.Item;
|
||||||
import client.inventory.MapleInventoryType;
|
import client.inventory.MapleInventoryType;
|
||||||
|
import config.YamlConfig;
|
||||||
import constants.game.GameConstants;
|
import constants.game.GameConstants;
|
||||||
import net.server.Server;
|
import net.server.Server;
|
||||||
import net.server.channel.Channel;
|
import net.server.channel.Channel;
|
||||||
import net.server.world.World;
|
import net.server.world.World;
|
||||||
|
import server.life.positioner.MaplePlayerNPCPodium;
|
||||||
|
import server.life.positioner.MaplePlayerNPCPositioner;
|
||||||
import server.maps.AbstractMapleMapObject;
|
import server.maps.AbstractMapleMapObject;
|
||||||
import server.maps.MapleMap;
|
import server.maps.MapleMap;
|
||||||
import server.maps.MapleMapObject;
|
import server.maps.MapleMapObject;
|
||||||
@@ -55,6 +40,12 @@ import tools.DatabaseConnection;
|
|||||||
import tools.MaplePacketCreator;
|
import tools.MaplePacketCreator;
|
||||||
import tools.Pair;
|
import tools.Pair;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author XoticStory
|
* @author XoticStory
|
||||||
@@ -65,18 +56,18 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
|||||||
private static final AtomicInteger runningOverallRank = new AtomicInteger();
|
private static final AtomicInteger runningOverallRank = new AtomicInteger();
|
||||||
private static final List<AtomicInteger> runningWorldRank = new ArrayList<>();
|
private static final List<AtomicInteger> runningWorldRank = new ArrayList<>();
|
||||||
private static final Map<Pair<Integer, Integer>, AtomicInteger> runningWorldJobRank = new HashMap<>();
|
private static final Map<Pair<Integer, Integer>, AtomicInteger> runningWorldJobRank = new HashMap<>();
|
||||||
|
|
||||||
private Map<Short, Integer> equips = new HashMap<>();
|
private Map<Short, Integer> equips = new HashMap<>();
|
||||||
private int scriptId, face, hair, gender, job;
|
private int scriptId, face, hair, gender, job;
|
||||||
private byte skin;
|
private byte skin;
|
||||||
private String name = "";
|
private String name = "";
|
||||||
private int dir, FH, RX0, RX1, CY;
|
private int dir, FH, RX0, RX1, CY;
|
||||||
private int worldRank, overallRank, worldJobRank, overallJobRank;
|
private int worldRank, overallRank, worldJobRank, overallJobRank;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
getRunningMetadata();
|
getRunningMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MaplePlayerNPC(String name, int scriptId, int face, int hair, int gender, byte skin, Map<Short, Integer> equips, int dir, int FH, int RX0, int RX1, int CX, int CY, int oid) {
|
public MaplePlayerNPC(String name, int scriptId, int face, int hair, int gender, byte skin, Map<Short, Integer> equips, int dir, int FH, int RX0, int RX1, int CX, int CY, int oid) {
|
||||||
this.equips = equips;
|
this.equips = equips;
|
||||||
this.scriptId = scriptId;
|
this.scriptId = scriptId;
|
||||||
@@ -91,11 +82,11 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
|||||||
this.RX1 = RX1;
|
this.RX1 = RX1;
|
||||||
this.CY = CY;
|
this.CY = CY;
|
||||||
this.job = 7777; // supposed to be developer
|
this.job = 7777; // supposed to be developer
|
||||||
|
|
||||||
setPosition(new Point(CX, CY));
|
setPosition(new Point(CX, CY));
|
||||||
setObjectId(oid);
|
setObjectId(oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MaplePlayerNPC(ResultSet rs) {
|
public MaplePlayerNPC(ResultSet rs) {
|
||||||
try {
|
try {
|
||||||
CY = rs.getInt("cy");
|
CY = rs.getInt("cy");
|
||||||
@@ -109,26 +100,26 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
|||||||
RX0 = rs.getInt("rx0");
|
RX0 = rs.getInt("rx0");
|
||||||
RX1 = rs.getInt("rx1");
|
RX1 = rs.getInt("rx1");
|
||||||
scriptId = rs.getInt("scriptid");
|
scriptId = rs.getInt("scriptid");
|
||||||
|
|
||||||
worldRank = rs.getInt("worldrank");
|
worldRank = rs.getInt("worldrank");
|
||||||
overallRank = rs.getInt("overallrank");
|
overallRank = rs.getInt("overallrank");
|
||||||
worldJobRank = rs.getInt("worldjobrank");
|
worldJobRank = rs.getInt("worldjobrank");
|
||||||
overallJobRank = GameConstants.getOverallJobRankByScriptId(scriptId);
|
overallJobRank = GameConstants.getOverallJobRankByScriptId(scriptId);
|
||||||
job = rs.getInt("job");
|
job = rs.getInt("job");
|
||||||
|
|
||||||
setPosition(new Point(rs.getInt("x"), CY));
|
setPosition(new Point(rs.getInt("x"), CY));
|
||||||
setObjectId(rs.getInt("id"));
|
setObjectId(rs.getInt("id"));
|
||||||
|
|
||||||
Connection con = DatabaseConnection.getConnection();
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
PreparedStatement ps = con.prepareStatement("SELECT equippos, equipid FROM playernpcs_equip WHERE npcid = ?");
|
PreparedStatement ps = con.prepareStatement("SELECT equippos, equipid FROM playernpcs_equip WHERE npcid = ?")) {
|
||||||
ps.setInt(1, rs.getInt("id"));
|
ps.setInt(1, rs.getInt("id"));
|
||||||
ResultSet rs2 = ps.executeQuery();
|
|
||||||
while (rs2.next()) {
|
try (ResultSet rs2 = ps.executeQuery()) {
|
||||||
equips.put(rs2.getShort("equippos"), rs2.getInt("equipid"));
|
while (rs2.next()) {
|
||||||
|
equips.put(rs2.getShort("equippos"), rs2.getInt("equipid"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rs2.close();
|
|
||||||
ps.close();
|
|
||||||
con.close();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -145,11 +136,11 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
|||||||
public int getJob() {
|
public int getJob() {
|
||||||
return job;
|
return job;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDirection() {
|
public int getDirection() {
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFH() {
|
public int getFH() {
|
||||||
return FH;
|
return FH;
|
||||||
}
|
}
|
||||||
@@ -181,7 +172,7 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
|||||||
public int getHair() {
|
public int getHair() {
|
||||||
return hair;
|
return hair;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getGender() {
|
public int getGender() {
|
||||||
return gender;
|
return gender;
|
||||||
}
|
}
|
||||||
@@ -189,19 +180,19 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
|||||||
public int getWorldRank() {
|
public int getWorldRank() {
|
||||||
return worldRank;
|
return worldRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOverallRank() {
|
public int getOverallRank() {
|
||||||
return overallRank;
|
return overallRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWorldJobRank() {
|
public int getWorldJobRank() {
|
||||||
return worldJobRank;
|
return worldJobRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOverallJobRank() {
|
public int getOverallJobRank() {
|
||||||
return overallJobRank;
|
return overallJobRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapleMapObjectType getType() {
|
public MapleMapObjectType getType() {
|
||||||
return MapleMapObjectType.PLAYER_NPC;
|
return MapleMapObjectType.PLAYER_NPC;
|
||||||
@@ -212,118 +203,101 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
|||||||
client.announce(MaplePacketCreator.spawnPlayerNPC(this));
|
client.announce(MaplePacketCreator.spawnPlayerNPC(this));
|
||||||
client.announce(MaplePacketCreator.getPlayerNPC(this));
|
client.announce(MaplePacketCreator.getPlayerNPC(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendDestroyData(MapleClient client) {
|
public void sendDestroyData(MapleClient client) {
|
||||||
client.announce(MaplePacketCreator.removeNPCController(this.getObjectId()));
|
client.announce(MaplePacketCreator.removeNPCController(this.getObjectId()));
|
||||||
client.announce(MaplePacketCreator.removePlayerNPC(this.getObjectId()));
|
client.announce(MaplePacketCreator.removePlayerNPC(this.getObjectId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void getRunningMetadata() {
|
private static void getRunningMetadata() {
|
||||||
try {
|
try (Connection con = DatabaseConnection.getConnection()) {
|
||||||
Connection con = DatabaseConnection.getConnection();
|
|
||||||
|
|
||||||
getRunningOverallRanks(con);
|
getRunningOverallRanks(con);
|
||||||
getRunningWorldRanks(con);
|
getRunningWorldRanks(con);
|
||||||
getRunningWorldJobRanks(con);
|
getRunningWorldJobRanks(con);
|
||||||
|
|
||||||
con.close();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void getRunningOverallRanks(Connection con) throws SQLException {
|
|
||||||
PreparedStatement ps = con.prepareStatement("SELECT max(overallrank) FROM playernpcs");
|
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
|
|
||||||
if(rs.next()) {
|
private static void getRunningOverallRanks(Connection con) throws SQLException {
|
||||||
runningOverallRank.set(rs.getInt(1) + 1);
|
try (PreparedStatement ps = con.prepareStatement("SELECT max(overallrank) FROM playernpcs");
|
||||||
} else {
|
ResultSet rs = ps.executeQuery()) {
|
||||||
runningOverallRank.set(1);
|
|
||||||
|
if (rs.next()) {
|
||||||
|
runningOverallRank.set(rs.getInt(1) + 1);
|
||||||
|
} else {
|
||||||
|
runningOverallRank.set(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void getRunningWorldRanks(Connection con) throws SQLException {
|
private static void getRunningWorldRanks(Connection con) throws SQLException {
|
||||||
int numWorlds = Server.getInstance().getWorldsSize();
|
int numWorlds = Server.getInstance().getWorldsSize();
|
||||||
for(int i = 0; i < numWorlds; i++) {
|
for (int i = 0; i < numWorlds; i++) {
|
||||||
runningWorldRank.add(new AtomicInteger(1));
|
runningWorldRank.add(new AtomicInteger(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
PreparedStatement ps = con.prepareStatement("SELECT world, max(worldrank) FROM playernpcs GROUP BY world ORDER BY world");
|
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
|
|
||||||
while(rs.next()) {
|
try (PreparedStatement ps = con.prepareStatement("SELECT world, max(worldrank) FROM playernpcs GROUP BY world ORDER BY world");
|
||||||
int wid = rs.getInt(1);
|
ResultSet rs = ps.executeQuery()) {
|
||||||
if(wid < numWorlds) {
|
|
||||||
runningWorldRank.get(wid).set(rs.getInt(2) + 1);
|
while (rs.next()) {
|
||||||
|
int wid = rs.getInt(1);
|
||||||
|
if (wid < numWorlds) {
|
||||||
|
runningWorldRank.get(wid).set(rs.getInt(2) + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void getRunningWorldJobRanks(Connection con) throws SQLException {
|
|
||||||
PreparedStatement ps = con.prepareStatement("SELECT world, job, max(worldjobrank) FROM playernpcs GROUP BY world, job ORDER BY world, job");
|
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
|
|
||||||
while(rs.next()) {
|
private static void getRunningWorldJobRanks(Connection con) throws SQLException {
|
||||||
runningWorldJobRank.put(new Pair<>(rs.getInt(1), rs.getInt(2)), new AtomicInteger(rs.getInt(3) + 1));
|
try (PreparedStatement ps = con.prepareStatement("SELECT world, job, max(worldjobrank) FROM playernpcs GROUP BY world, job ORDER BY world, job");
|
||||||
|
ResultSet rs = ps.executeQuery()) {
|
||||||
|
while (rs.next()) {
|
||||||
|
runningWorldJobRank.put(new Pair<>(rs.getInt(1), rs.getInt(2)), new AtomicInteger(rs.getInt(3) + 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getAndIncrementRunningWorldJobRanks(int world, int job) {
|
private static int getAndIncrementRunningWorldJobRanks(int world, int job) {
|
||||||
AtomicInteger wjr = runningWorldJobRank.get(new Pair<>(world, job));
|
AtomicInteger wjr = runningWorldJobRank.get(new Pair<>(world, job));
|
||||||
if(wjr == null) {
|
if(wjr == null) {
|
||||||
wjr = new AtomicInteger(1);
|
wjr = new AtomicInteger(1);
|
||||||
runningWorldJobRank.put(new Pair<>(world, job), wjr);
|
runningWorldJobRank.put(new Pair<>(world, job), wjr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return wjr.getAndIncrement();
|
return wjr.getAndIncrement();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canSpawnPlayerNpc(String name, int mapid) {
|
public static boolean canSpawnPlayerNpc(String name, int mapid) {
|
||||||
boolean ret = true;
|
boolean ret = true;
|
||||||
|
|
||||||
try {
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
Connection con = DatabaseConnection.getConnection();
|
PreparedStatement ps = con.prepareStatement("SELECT name FROM playernpcs WHERE name LIKE ? AND map = ?")) {
|
||||||
PreparedStatement ps = con.prepareStatement("SELECT name FROM playernpcs WHERE name LIKE ? AND map = ?");
|
|
||||||
ps.setString(1, name);
|
ps.setString(1, name);
|
||||||
ps.setInt(2, mapid);
|
ps.setInt(2, mapid);
|
||||||
|
|
||||||
ResultSet rs = ps.executeQuery();
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
if(rs.next()) {
|
if (rs.next()) {
|
||||||
ret = false;
|
ret = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
con.close();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePlayerNPCPosition(MapleMap map, Point newPos) {
|
public void updatePlayerNPCPosition(MapleMap map, Point newPos) {
|
||||||
setPosition(newPos);
|
setPosition(newPos);
|
||||||
RX0 = newPos.x + 50;
|
RX0 = newPos.x + 50;
|
||||||
RX1 = newPos.x - 50;
|
RX1 = newPos.x - 50;
|
||||||
CY = newPos.y;
|
CY = newPos.y;
|
||||||
FH = map.getFootholds().findBelow(newPos).getId();
|
FH = map.getFootholds().findBelow(newPos).getId();
|
||||||
|
|
||||||
try {
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
Connection con = DatabaseConnection.getConnection();
|
PreparedStatement ps = con.prepareStatement("UPDATE playernpcs SET x = ?, cy = ?, fh = ?, rx0 = ?, rx1 = ? WHERE id = ?")) {
|
||||||
|
|
||||||
PreparedStatement ps = con.prepareStatement("UPDATE playernpcs SET x = ?, cy = ?, fh = ?, rx0 = ?, rx1 = ? WHERE id = ?");
|
|
||||||
ps.setInt(1, newPos.x);
|
ps.setInt(1, newPos.x);
|
||||||
ps.setInt(2, CY);
|
ps.setInt(2, CY);
|
||||||
ps.setInt(3, FH);
|
ps.setInt(3, FH);
|
||||||
@@ -331,225 +305,222 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
|||||||
ps.setInt(5, RX1);
|
ps.setInt(5, RX1);
|
||||||
ps.setInt(6, getObjectId());
|
ps.setInt(6, getObjectId());
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
|
|
||||||
ps.close();
|
|
||||||
con.close();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void fetchAvailableScriptIdsFromDb(byte branch, List<Integer> list) {
|
private static void fetchAvailableScriptIdsFromDb(byte branch, List<Integer> list) {
|
||||||
try {
|
try {
|
||||||
int branchLen = (branch < 26) ? 100 : 400;
|
int branchLen = (branch < 26) ? 100 : 400;
|
||||||
int branchSid = 9900000 + (branch * 100);
|
int branchSid = 9900000 + (branch * 100);
|
||||||
int nextBranchSid = branchSid + branchLen;
|
int nextBranchSid = branchSid + branchLen;
|
||||||
Set<Integer> usedScriptIds = new HashSet<>();
|
|
||||||
|
|
||||||
Connection con = DatabaseConnection.getConnection();
|
|
||||||
PreparedStatement ps = con.prepareStatement("SELECT scriptid FROM playernpcs WHERE scriptid >= ? AND scriptid < ? ORDER BY scriptid");
|
|
||||||
ps.setInt(1, branchSid);
|
|
||||||
ps.setInt(2, nextBranchSid);
|
|
||||||
|
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
while(rs.next()) {
|
|
||||||
usedScriptIds.add(rs.getInt(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Integer> availables = new ArrayList<>(20);
|
|
||||||
int j = 0;
|
|
||||||
for(int i = branchSid; i < nextBranchSid; i++) {
|
|
||||||
if(!usedScriptIds.contains(i)) {
|
|
||||||
if (MaplePlayerNPCFactory.isExistentScriptid(i)) { // thanks Ark, Zein, geno, Ariel, JrCl0wn for noticing client crashes due to use of missing scriptids
|
|
||||||
availables.add(i);
|
|
||||||
j++;
|
|
||||||
|
|
||||||
if(j == 20) {
|
List<Integer> availables = new ArrayList<>(20);
|
||||||
break;
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
|
PreparedStatement ps = con.prepareStatement("SELECT scriptid FROM playernpcs WHERE scriptid >= ? AND scriptid < ? ORDER BY scriptid")) {
|
||||||
|
ps.setInt(1, branchSid);
|
||||||
|
ps.setInt(2, nextBranchSid);
|
||||||
|
|
||||||
|
Set<Integer> usedScriptIds = new HashSet<>();
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
while (rs.next()) {
|
||||||
|
usedScriptIds.add(rs.getInt(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int j = 0;
|
||||||
|
for (int i = branchSid; i < nextBranchSid; i++) {
|
||||||
|
if (!usedScriptIds.contains(i)) {
|
||||||
|
if (MaplePlayerNPCFactory.isExistentScriptid(i)) { // thanks Ark, Zein, geno, Ariel, JrCl0wn for noticing client crashes due to use of missing scriptids
|
||||||
|
availables.add(i);
|
||||||
|
j++;
|
||||||
|
|
||||||
|
if (j == 20) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break; // after this point no more scriptids expected...
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
break; // after this point no more scriptids expected...
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rs.close();
|
for (int i = availables.size() - 1; i >= 0; i--) {
|
||||||
ps.close();
|
|
||||||
con.close();
|
|
||||||
|
|
||||||
for(int i = availables.size() - 1; i >= 0; i--) {
|
|
||||||
list.add(availables.get(i));
|
list.add(availables.get(i));
|
||||||
}
|
}
|
||||||
} catch(SQLException sqle) {
|
} catch (SQLException sqle) {
|
||||||
sqle.printStackTrace();
|
sqle.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getNextScriptId(byte branch) {
|
private static int getNextScriptId(byte branch) {
|
||||||
List<Integer> availablesBranch = availablePlayerNpcScriptIds.get(branch);
|
List<Integer> availablesBranch = availablePlayerNpcScriptIds.get(branch);
|
||||||
|
|
||||||
if(availablesBranch == null) {
|
if(availablesBranch == null) {
|
||||||
availablesBranch = new ArrayList<>(20);
|
availablesBranch = new ArrayList<>(20);
|
||||||
availablePlayerNpcScriptIds.put(branch, availablesBranch);
|
availablePlayerNpcScriptIds.put(branch, availablesBranch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(availablesBranch.isEmpty()) {
|
if(availablesBranch.isEmpty()) {
|
||||||
fetchAvailableScriptIdsFromDb(branch, availablesBranch);
|
fetchAvailableScriptIdsFromDb(branch, availablesBranch);
|
||||||
|
|
||||||
if(availablesBranch.isEmpty()) {
|
if(availablesBranch.isEmpty()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return availablesBranch.remove(availablesBranch.size() - 1);
|
return availablesBranch.remove(availablesBranch.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MaplePlayerNPC createPlayerNPCInternal(MapleMap map, Point pos, MapleCharacter chr) {
|
private static MaplePlayerNPC createPlayerNPCInternal(MapleMap map, Point pos, MapleCharacter chr) {
|
||||||
int mapId = map.getId();
|
int mapId = map.getId();
|
||||||
|
|
||||||
if(!canSpawnPlayerNpc(chr.getName(), mapId)) {
|
if (!canSpawnPlayerNpc(chr.getName(), mapId)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte branch = GameConstants.getHallOfFameBranch(chr.getJob(), mapId);
|
byte branch = GameConstants.getHallOfFameBranch(chr.getJob(), mapId);
|
||||||
|
|
||||||
int scriptId = getNextScriptId(branch);
|
int scriptId = getNextScriptId(branch);
|
||||||
if (scriptId == -1) {
|
if (scriptId == -1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pos == null) {
|
if (pos == null) {
|
||||||
if(GameConstants.isPodiumHallOfFameMap(map.getId())) {
|
if (GameConstants.isPodiumHallOfFameMap(map.getId())) {
|
||||||
pos = MaplePlayerNPCPodium.getNextPlayerNpcPosition(map);
|
pos = MaplePlayerNPCPodium.getNextPlayerNpcPosition(map);
|
||||||
} else {
|
} else {
|
||||||
pos = MaplePlayerNPCPositioner.getNextPlayerNpcPosition(map);
|
pos = MaplePlayerNPCPositioner.getNextPlayerNpcPosition(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pos == null) {
|
if (pos == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(YamlConfig.config.server.USE_DEBUG) System.out.println("GOT SID " + scriptId + " POS " + pos);
|
if (YamlConfig.config.server.USE_DEBUG) {
|
||||||
|
System.out.println("GOT SID " + scriptId + " POS " + pos);
|
||||||
|
}
|
||||||
|
|
||||||
int worldId = chr.getWorld();
|
int worldId = chr.getWorld();
|
||||||
int jobId = (chr.getJob().getId() / 100) * 100;
|
int jobId = (chr.getJob().getId() / 100) * 100;
|
||||||
|
|
||||||
MaplePlayerNPC ret;
|
MaplePlayerNPC ret;
|
||||||
int npcId;
|
try (Connection con = DatabaseConnection.getConnection()) {
|
||||||
try {
|
boolean createNew = false;
|
||||||
Connection con = DatabaseConnection.getConnection();
|
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM playernpcs WHERE scriptid = ?")) {
|
||||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM playernpcs WHERE scriptid = ?");
|
ps.setInt(1, scriptId);
|
||||||
ps.setInt(1, scriptId);
|
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
if (!rs.next()) { // creates new playernpc if scriptid doesn't exist
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
|
|
||||||
ps = con.prepareStatement("INSERT INTO playernpcs (name, hair, face, skin, gender, x, cy, world, map, scriptid, dir, fh, rx0, rx1, worldrank, overallrank, worldjobrank, job) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
ps.setString(1, chr.getName());
|
if (!rs.next()) {
|
||||||
ps.setInt(2, chr.getHair());
|
createNew = true;
|
||||||
ps.setInt(3, chr.getFace());
|
|
||||||
ps.setInt(4, chr.getSkinColor().getId());
|
|
||||||
ps.setInt(5, chr.getGender());
|
|
||||||
ps.setInt(6, pos.x);
|
|
||||||
ps.setInt(7, pos.y);
|
|
||||||
ps.setInt(8, worldId);
|
|
||||||
ps.setInt(9, mapId);
|
|
||||||
ps.setInt(10, scriptId);
|
|
||||||
ps.setInt(11, 1); // default direction
|
|
||||||
ps.setInt(12, map.getFootholds().findBelow(pos).getId());
|
|
||||||
ps.setInt(13, pos.x + 50);
|
|
||||||
ps.setInt(14, pos.x - 50);
|
|
||||||
ps.setInt(15, runningWorldRank.get(worldId).getAndIncrement());
|
|
||||||
ps.setInt(16, runningOverallRank.getAndIncrement());
|
|
||||||
ps.setInt(17, getAndIncrementRunningWorldJobRanks(worldId, jobId));
|
|
||||||
ps.setInt(18, jobId);
|
|
||||||
|
|
||||||
ps.executeUpdate();
|
|
||||||
|
|
||||||
rs = ps.getGeneratedKeys();
|
|
||||||
rs.next();
|
|
||||||
npcId = rs.getInt(1);
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
|
|
||||||
ps = con.prepareStatement("INSERT INTO playernpcs_equip (npcid, equipid, equippos) VALUES (?, ?, ?)");
|
|
||||||
ps.setInt(1, npcId);
|
|
||||||
for (Item equip : chr.getInventory(MapleInventoryType.EQUIPPED)) {
|
|
||||||
int position = Math.abs(equip.getPosition());
|
|
||||||
if ((position < 12 && position > 0) || (position > 100 && position < 112)) {
|
|
||||||
ps.setInt(2, equip.getItemId());
|
|
||||||
ps.setInt(3, equip.getPosition());
|
|
||||||
ps.addBatch();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ps.executeBatch();
|
}
|
||||||
ps.close();
|
|
||||||
|
|
||||||
ps = con.prepareStatement("SELECT * FROM playernpcs WHERE id = ?");
|
if (createNew) { // creates new playernpc if scriptid doesn't exist
|
||||||
ps.setInt(1, npcId);
|
final int npcId;
|
||||||
rs = ps.executeQuery();
|
try (PreparedStatement ps = con.prepareStatement("INSERT INTO playernpcs (name, hair, face, skin, gender, x, cy, world, map, scriptid, dir, fh, rx0, rx1, worldrank, overallrank, worldjobrank, job) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
|
||||||
|
ps.setString(1, chr.getName());
|
||||||
|
ps.setInt(2, chr.getHair());
|
||||||
|
ps.setInt(3, chr.getFace());
|
||||||
|
ps.setInt(4, chr.getSkinColor().getId());
|
||||||
|
ps.setInt(5, chr.getGender());
|
||||||
|
ps.setInt(6, pos.x);
|
||||||
|
ps.setInt(7, pos.y);
|
||||||
|
ps.setInt(8, worldId);
|
||||||
|
ps.setInt(9, mapId);
|
||||||
|
ps.setInt(10, scriptId);
|
||||||
|
ps.setInt(11, 1); // default direction
|
||||||
|
ps.setInt(12, map.getFootholds().findBelow(pos).getId());
|
||||||
|
ps.setInt(13, pos.x + 50);
|
||||||
|
ps.setInt(14, pos.x - 50);
|
||||||
|
ps.setInt(15, runningWorldRank.get(worldId).getAndIncrement());
|
||||||
|
ps.setInt(16, runningOverallRank.getAndIncrement());
|
||||||
|
ps.setInt(17, getAndIncrementRunningWorldJobRanks(worldId, jobId));
|
||||||
|
ps.setInt(18, jobId);
|
||||||
|
ps.executeUpdate();
|
||||||
|
|
||||||
rs.next();
|
try (ResultSet rs = ps.getGeneratedKeys()) {
|
||||||
ret = new MaplePlayerNPC(rs);
|
rs.next();
|
||||||
|
npcId = rs.getInt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try (PreparedStatement ps = con.prepareStatement("INSERT INTO playernpcs_equip (npcid, equipid, equippos) VALUES (?, ?, ?)")) {
|
||||||
|
ps.setInt(1, npcId);
|
||||||
|
|
||||||
|
for (Item equip : chr.getInventory(MapleInventoryType.EQUIPPED)) {
|
||||||
|
int position = Math.abs(equip.getPosition());
|
||||||
|
if ((position < 12 && position > 0) || (position > 100 && position < 112)) {
|
||||||
|
ps.setInt(2, equip.getItemId());
|
||||||
|
ps.setInt(3, equip.getPosition());
|
||||||
|
ps.addBatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ps.executeBatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM playernpcs WHERE id = ?")) {
|
||||||
|
ps.setInt(1, npcId);
|
||||||
|
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
rs.next();
|
||||||
|
ret = new MaplePlayerNPC(rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ret = null;
|
ret = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
con.close();
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Integer> removePlayerNPCInternal(MapleMap map, MapleCharacter chr) {
|
private static List<Integer> removePlayerNPCInternal(MapleMap map, MapleCharacter chr) {
|
||||||
Set<Integer> updateMapids = new HashSet<>();
|
Set<Integer> updateMapids = new HashSet<>();
|
||||||
|
|
||||||
List<Integer> mapids = new LinkedList<>();
|
List<Integer> mapids = new LinkedList<>();
|
||||||
mapids.add(chr.getWorld());
|
mapids.add(chr.getWorld());
|
||||||
|
|
||||||
try {
|
|
||||||
Connection con = DatabaseConnection.getConnection();
|
|
||||||
PreparedStatement ps = con.prepareStatement("SELECT id, map FROM playernpcs WHERE name LIKE ?" + (map != null ? " AND map = ?" : ""));
|
|
||||||
ps.setString(1, chr.getName());
|
|
||||||
if(map != null) ps.setInt(2, map.getId());
|
|
||||||
|
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
while(rs.next()) {
|
|
||||||
updateMapids.add(rs.getInt("map"));
|
|
||||||
int npcId = rs.getInt("id");
|
|
||||||
|
|
||||||
PreparedStatement ps2 = con.prepareStatement("DELETE FROM playernpcs WHERE id = ?");
|
|
||||||
ps2.setInt(1, npcId);
|
|
||||||
ps2.executeUpdate();
|
|
||||||
ps2.close();
|
|
||||||
|
|
||||||
ps2 = con.prepareStatement("DELETE FROM playernpcs_equip WHERE npcid = ?");
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
ps2.setInt(1, npcId);
|
PreparedStatement ps = con.prepareStatement("SELECT id, map FROM playernpcs WHERE name LIKE ?" + (map != null ? " AND map = ?" : ""))) {
|
||||||
ps2.executeUpdate();
|
ps.setString(1, chr.getName());
|
||||||
ps2.close();
|
if (map != null) {
|
||||||
|
ps.setInt(2, map.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
while (rs.next()) {
|
||||||
|
updateMapids.add(rs.getInt("map"));
|
||||||
|
int npcId = rs.getInt("id");
|
||||||
|
|
||||||
|
try (PreparedStatement ps2 = con.prepareStatement("DELETE FROM playernpcs WHERE id = ?")) {
|
||||||
|
ps2.setInt(1, npcId);
|
||||||
|
ps2.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
try (PreparedStatement ps2 = con.prepareStatement("DELETE FROM playernpcs_equip WHERE npcid = ?")) {
|
||||||
|
ps2.setInt(1, npcId);
|
||||||
|
ps2.executeUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
con.close();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Integer i : updateMapids) {
|
for (Integer i : updateMapids) {
|
||||||
mapids.add(i);
|
mapids.add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapids;
|
return mapids;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static synchronized Pair<MaplePlayerNPC, List<Integer>> processPlayerNPCInternal(MapleMap map, Point pos, MapleCharacter chr, boolean create) {
|
private static synchronized Pair<MaplePlayerNPC, List<Integer>> processPlayerNPCInternal(MapleMap map, Point pos, MapleCharacter chr, boolean create) {
|
||||||
if(create) {
|
if(create) {
|
||||||
return new Pair<>(createPlayerNPCInternal(map, pos, chr), null);
|
return new Pair<>(createPlayerNPCInternal(map, pos, chr), null);
|
||||||
@@ -557,52 +528,52 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
|||||||
return new Pair<>(null, removePlayerNPCInternal(map, chr));
|
return new Pair<>(null, removePlayerNPCInternal(map, chr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean spawnPlayerNPC(int mapid, MapleCharacter chr) {
|
public static boolean spawnPlayerNPC(int mapid, MapleCharacter chr) {
|
||||||
return spawnPlayerNPC(mapid, null, chr);
|
return spawnPlayerNPC(mapid, null, chr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean spawnPlayerNPC(int mapid, Point pos, MapleCharacter chr) {
|
public static boolean spawnPlayerNPC(int mapid, Point pos, MapleCharacter chr) {
|
||||||
if(chr == null) return false;
|
if(chr == null) return false;
|
||||||
|
|
||||||
MaplePlayerNPC pn = processPlayerNPCInternal(chr.getClient().getChannelServer().getMapFactory().getMap(mapid), pos, chr, true).getLeft();
|
MaplePlayerNPC pn = processPlayerNPCInternal(chr.getClient().getChannelServer().getMapFactory().getMap(mapid), pos, chr, true).getLeft();
|
||||||
if(pn != null) {
|
if(pn != null) {
|
||||||
for (Channel channel : Server.getInstance().getChannelsFromWorld(chr.getWorld())) {
|
for (Channel channel : Server.getInstance().getChannelsFromWorld(chr.getWorld())) {
|
||||||
MapleMap m = channel.getMapFactory().getMap(mapid);
|
MapleMap m = channel.getMapFactory().getMap(mapid);
|
||||||
|
|
||||||
m.addPlayerNPCMapObject(pn);
|
m.addPlayerNPCMapObject(pn);
|
||||||
m.broadcastMessage(MaplePacketCreator.spawnPlayerNPC(pn));
|
m.broadcastMessage(MaplePacketCreator.spawnPlayerNPC(pn));
|
||||||
m.broadcastMessage(MaplePacketCreator.getPlayerNPC(pn));
|
m.broadcastMessage(MaplePacketCreator.getPlayerNPC(pn));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MaplePlayerNPC getPlayerNPCFromWorldMap(String name, int world, int map) {
|
private static MaplePlayerNPC getPlayerNPCFromWorldMap(String name, int world, int map) {
|
||||||
World wserv = Server.getInstance().getWorld(world);
|
World wserv = Server.getInstance().getWorld(world);
|
||||||
for(MapleMapObject pnpcObj : wserv.getChannel(1).getMapFactory().getMap(map).getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.PLAYER_NPC))) {
|
for(MapleMapObject pnpcObj : wserv.getChannel(1).getMapFactory().getMap(map).getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.PLAYER_NPC))) {
|
||||||
MaplePlayerNPC pn = (MaplePlayerNPC) pnpcObj;
|
MaplePlayerNPC pn = (MaplePlayerNPC) pnpcObj;
|
||||||
|
|
||||||
if(name.contentEquals(pn.getName()) && pn.getScriptId() < 9977777) {
|
if(name.contentEquals(pn.getName()) && pn.getScriptId() < 9977777) {
|
||||||
return pn;
|
return pn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removePlayerNPC(MapleCharacter chr) {
|
public static void removePlayerNPC(MapleCharacter chr) {
|
||||||
if(chr == null) return;
|
if(chr == null) return;
|
||||||
|
|
||||||
List<Integer> updateMapids = processPlayerNPCInternal(null, null, chr, false).getRight();
|
List<Integer> updateMapids = processPlayerNPCInternal(null, null, chr, false).getRight();
|
||||||
int worldid = updateMapids.remove(0);
|
int worldid = updateMapids.remove(0);
|
||||||
|
|
||||||
for (Integer mapid : updateMapids) {
|
for (Integer mapid : updateMapids) {
|
||||||
MaplePlayerNPC pn = getPlayerNPCFromWorldMap(chr.getName(), worldid, mapid);
|
MaplePlayerNPC pn = getPlayerNPCFromWorldMap(chr.getName(), worldid, mapid);
|
||||||
|
|
||||||
if(pn != null) {
|
if(pn != null) {
|
||||||
for (Channel channel : Server.getInstance().getChannelsFromWorld(worldid)) {
|
for (Channel channel : Server.getInstance().getChannelsFromWorld(worldid)) {
|
||||||
MapleMap m = channel.getMapFactory().getMap(mapid);
|
MapleMap m = channel.getMapFactory().getMap(mapid);
|
||||||
@@ -614,37 +585,36 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void multicastSpawnPlayerNPC(int mapid, int world) {
|
public static void multicastSpawnPlayerNPC(int mapid, int world) {
|
||||||
World wserv = Server.getInstance().getWorld(world);
|
World wserv = Server.getInstance().getWorld(world);
|
||||||
if (wserv == null) return;
|
if (wserv == null) return;
|
||||||
|
|
||||||
MapleClient c = new MapleClient(null, null, null); // mock client
|
MapleClient c = new MapleClient(null, null, null); // mock client
|
||||||
c.setWorld(world);
|
c.setWorld(world);
|
||||||
c.setChannel(1);
|
c.setChannel(1);
|
||||||
|
|
||||||
for(MapleCharacter mc : wserv.loadAndGetAllCharactersView()) {
|
for(MapleCharacter mc : wserv.loadAndGetAllCharactersView()) {
|
||||||
mc.setClient(c);
|
mc.setClient(c);
|
||||||
spawnPlayerNPC(mapid, mc);
|
spawnPlayerNPC(mapid, mc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeAllPlayerNPC() {
|
public static void removeAllPlayerNPC() {
|
||||||
try {
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
Connection con = DatabaseConnection.getConnection();
|
PreparedStatement ps = con.prepareStatement("SELECT DISTINCT world, map FROM playernpcs");
|
||||||
|
ResultSet rs = ps.executeQuery()) {
|
||||||
PreparedStatement ps = con.prepareStatement("SELECT DISTINCT world, map FROM playernpcs");
|
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
|
|
||||||
int wsize = Server.getInstance().getWorldsSize();
|
int wsize = Server.getInstance().getWorldsSize();
|
||||||
while(rs.next()) {
|
while (rs.next()) {
|
||||||
int world = rs.getInt("world"), map = rs.getInt("map");
|
int world = rs.getInt("world"), map = rs.getInt("map");
|
||||||
if(world >= wsize) continue;
|
if (world >= wsize) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (Channel channel : Server.getInstance().getChannelsFromWorld(world)) {
|
for (Channel channel : Server.getInstance().getChannelsFromWorld(world)) {
|
||||||
MapleMap m = channel.getMapFactory().getMap(map);
|
MapleMap m = channel.getMapFactory().getMap(map);
|
||||||
|
|
||||||
for(MapleMapObject pnpcObj : m.getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.PLAYER_NPC))) {
|
for (MapleMapObject pnpcObj : m.getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.PLAYER_NPC))) {
|
||||||
MaplePlayerNPC pn = (MaplePlayerNPC) pnpcObj;
|
MaplePlayerNPC pn = (MaplePlayerNPC) pnpcObj;
|
||||||
m.removeMapObject(pnpcObj);
|
m.removeMapObject(pnpcObj);
|
||||||
m.broadcastMessage(MaplePacketCreator.removeNPCController(pn.getObjectId()));
|
m.broadcastMessage(MaplePacketCreator.removeNPCController(pn.getObjectId()));
|
||||||
@@ -652,27 +622,22 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
|
|
||||||
ps = con.prepareStatement("DELETE FROM playernpcs");
|
|
||||||
ps.executeUpdate();
|
|
||||||
ps.close();
|
|
||||||
|
|
||||||
ps = con.prepareStatement("DELETE FROM playernpcs_equip");
|
try (PreparedStatement ps2 = con.prepareStatement("DELETE FROM playernpcs")) {
|
||||||
ps.executeUpdate();
|
ps2.executeUpdate();
|
||||||
ps.close();
|
}
|
||||||
|
|
||||||
ps = con.prepareStatement("DELETE FROM playernpcs_field");
|
try (PreparedStatement ps2 = con.prepareStatement("DELETE FROM playernpcs_equip")) {
|
||||||
ps.executeUpdate();
|
ps2.executeUpdate();
|
||||||
ps.close();
|
}
|
||||||
|
|
||||||
for(World w : Server.getInstance().getWorlds()) {
|
try (PreparedStatement ps2 = con.prepareStatement("DELETE FROM playernpcs_field")) {
|
||||||
|
ps2.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (World w : Server.getInstance().getWorlds()) {
|
||||||
w.resetPlayerNpcMapData();
|
w.resetPlayerNpcMapData();
|
||||||
}
|
}
|
||||||
|
|
||||||
con.close();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user