|
|
@ -19,6 +19,8 @@ import engine.objects.*; |
|
|
|
import org.joda.time.DateTime; |
|
|
|
import org.joda.time.DateTime; |
|
|
|
import org.pmw.tinylog.Logger; |
|
|
|
import org.pmw.tinylog.Logger; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.sql.Connection; |
|
|
|
|
|
|
|
import java.sql.PreparedStatement; |
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.LocalDateTime; |
|
|
@ -40,25 +42,25 @@ public class dbBuildingHandler extends dbHandlerBase { |
|
|
|
DateTime upgradeDate, int blueprintUUID, float w, float rotY) { |
|
|
|
DateTime upgradeDate, int blueprintUUID, float w, float rotY) { |
|
|
|
|
|
|
|
|
|
|
|
Building toCreate = null; |
|
|
|
Building toCreate = null; |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prepareCallable("CALL `building_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? ,? ,?, ?);"); |
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("CALL `building_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? ,? ,?, ?);")) { |
|
|
|
setInt(1, parentZoneID); |
|
|
|
|
|
|
|
setInt(2, OwnerUUID); |
|
|
|
preparedStatement.setInt(1, parentZoneID); |
|
|
|
setString(3, name); |
|
|
|
preparedStatement.setInt(2, OwnerUUID); |
|
|
|
setInt(4, meshUUID); |
|
|
|
preparedStatement.setString(3, name); |
|
|
|
setFloat(5, location.x); |
|
|
|
preparedStatement.setInt(4, meshUUID); |
|
|
|
setFloat(6, location.y); |
|
|
|
preparedStatement.setFloat(5, location.x); |
|
|
|
setFloat(7, location.z); |
|
|
|
preparedStatement.setFloat(6, location.y); |
|
|
|
setFloat(8, meshScale); |
|
|
|
preparedStatement.setFloat(7, location.z); |
|
|
|
setInt(9, currentHP); |
|
|
|
preparedStatement.setFloat(8, meshScale); |
|
|
|
setString(10, protectionState.name()); |
|
|
|
preparedStatement.setInt(9, currentHP); |
|
|
|
setInt(11, currentGold); |
|
|
|
preparedStatement.setString(10, protectionState.name()); |
|
|
|
setInt(12, rank); |
|
|
|
preparedStatement.setInt(11, currentGold); |
|
|
|
|
|
|
|
preparedStatement.setInt(12, rank); |
|
|
|
|
|
|
|
|
|
|
|
if (upgradeDate != null) |
|
|
|
if (upgradeDate != null) |
|
|
|
setTimeStamp(13, upgradeDate.getMillis()); |
|
|
|
preparedStatement.setTimestamp(13, new java.sql.Timestamp(upgradeDate.getMillis())); |
|
|
|
else |
|
|
|
else |
|
|
|
setNULL(13, java.sql.Types.DATE); |
|
|
|
setNULL(13, java.sql.Types.DATE); |
|
|
|
|
|
|
|
|
|
|
@ -66,16 +68,15 @@ public class dbBuildingHandler extends dbHandlerBase { |
|
|
|
setFloat(15, w); |
|
|
|
setFloat(15, w); |
|
|
|
setFloat(16, rotY); |
|
|
|
setFloat(16, rotY); |
|
|
|
|
|
|
|
|
|
|
|
int objectUUID = (int) getUUID(); |
|
|
|
ResultSet rs = preparedStatement.executeQuery(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int objectUUID = (int) rs.getLong("UID"); |
|
|
|
|
|
|
|
|
|
|
|
if (objectUUID > 0) |
|
|
|
if (objectUUID > 0) |
|
|
|
toCreate = GET_BUILDINGBYUUID(objectUUID); |
|
|
|
toCreate = GET_BUILDINGBYUUID(objectUUID); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
Logger.error("CREATE_BUILDING", e.getMessage()); |
|
|
|
throw new RuntimeException(e); |
|
|
|
return null; |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
closeCallable(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return toCreate; |
|
|
|
return toCreate; |
|
|
@ -93,6 +94,7 @@ public class dbBuildingHandler extends dbHandlerBase { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Building GET_BUILDINGBYUUID(int uuid) { |
|
|
|
public Building GET_BUILDINGBYUUID(int uuid) { |
|
|
|
|
|
|
|
|
|
|
|
if (uuid == 0) |
|
|
|
if (uuid == 0) |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
|
@ -101,11 +103,19 @@ public class dbBuildingHandler extends dbHandlerBase { |
|
|
|
if (building != null) |
|
|
|
if (building != null) |
|
|
|
return building; |
|
|
|
return building; |
|
|
|
|
|
|
|
|
|
|
|
prepareCallable("SELECT `obj_building`.*, `object`.`parent` FROM `object` INNER JOIN `obj_building` ON `obj_building`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;"); |
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_building`.*, `object`.`parent` FROM `object` INNER JOIN `obj_building` ON `obj_building`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
preparedStatement.setLong(1, (long) uuid); |
|
|
|
|
|
|
|
|
|
|
|
setLong(1, (long) uuid); |
|
|
|
ResultSet rs = preparedStatement.executeQuery(); |
|
|
|
return (Building) getObjectSingle(uuid); |
|
|
|
building = (Building) getObjectFromRs(rs); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
Logger.error(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return building; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Building GET_BUILDING_BY_MESH(final int meshID) { |
|
|
|
public Building GET_BUILDING_BY_MESH(final int meshID) { |
|
|
@ -154,9 +164,19 @@ public class dbBuildingHandler extends dbHandlerBase { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean removeFromBuildings(final Building b) { |
|
|
|
private boolean removeFromBuildings(final Building b) { |
|
|
|
prepareCallable("DELETE FROM `object` WHERE `UID` = ?"); |
|
|
|
|
|
|
|
setLong(1, b.getObjectUUID()); |
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
return (executeUpdate() > 0); |
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
preparedStatement.setLong(1, b.getObjectUUID()); |
|
|
|
|
|
|
|
preparedStatement.execute(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
Logger.error(e); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean CHANGE_NAME(Building b, String newName) { |
|
|
|
public boolean CHANGE_NAME(Building b, String newName) { |
|
|
|