Skip to content

Commit

Permalink
- Fix for SQL db code related to new Districts.
Browse files Browse the repository at this point in the history
  • Loading branch information
LlmDl committed Jul 12, 2024
1 parent ccc6438 commit f25a886
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private static String fetchTableSchema(TownyDBTableType tableType) {
case TOWNBLOCK -> fetchCreateTownBlocksStatement();
case JAIL -> fetchCreateUUIDStatement(tableType);
case PLOTGROUP -> fetchCreatePlotGroupStatement(tableType);
case DISTRICT -> fetchCreateUUIDStatement(tableType);
case COOLDOWN -> fetchCreateCooldownsStatement(tableType);
case WORLD -> fetchCreateWorldStatemnt(tableType);
case HIBERNATED_RESIDENT -> fetchCreateUUIDStatement(tableType);
Expand Down Expand Up @@ -343,6 +344,7 @@ private static List<String> getTownBlockColumns() {
columns.add("`changed` bool NOT NULL DEFAULT '0'");
columns.add("`metadata` text DEFAULT NULL");
columns.add("`groupID` VARCHAR(36) DEFAULT NULL");
columns.add("`districtID` VARCHAR(36) DEFAULT NULL");
columns.add("`claimedAt` BIGINT NOT NULL");
columns.add("`trustedResidents` mediumtext DEFAULT NULL");
columns.add("`customPermissionData` mediumtext DEFAULT NULL");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public boolean cleanup() {
public enum TownyDBTableType {
JAIL("JAILS", "SELECT uuid FROM ", "uuid"),
PLOTGROUP("PLOTGROUPS", "SELECT groupID FROM ", "groupID"),
DISTRICT("DISTRICTS", "SELECT districtID FROM ", "districtID"),
DISTRICT("DISTRICTS", "SELECT uuid FROM ", "uuid"),
RESIDENT("RESIDENTS", "SELECT name FROM ", "name"),
HIBERNATED_RESIDENT("HIBERNATEDRESIDENTS", "", "uuid"),
TOWN("TOWNS", "SELECT name FROM ", "name"),
Expand Down Expand Up @@ -636,13 +636,13 @@ public boolean loadDistrictList() {

try (Connection connection = getConnection();
Statement s = connection.createStatement();
ResultSet rs = s.executeQuery("SELECT districtID FROM " + tb_prefix + "DISTRICTS")) {
ResultSet rs = s.executeQuery("SELECT uuid FROM " + tb_prefix + "DISTRICTS")) {

while (rs.next()) {
try {
universe.newDistrictInternal(UUID.fromString(rs.getString("districtID")));
universe.newDistrictInternal(UUID.fromString(rs.getString("uuid")));
} catch (IllegalArgumentException e) {
plugin.getLogger().log(Level.WARNING, "ID for district is not a valid uuid, skipped loading district {}", rs.getString("districtID"));
plugin.getLogger().log(Level.WARNING, "ID for district is not a valid uuid, skipped loading district {}", rs.getString("uuid"));
}
}

Expand Down Expand Up @@ -1924,7 +1924,7 @@ public boolean loadTownBlocks() {
}

try {
line = rs.getString("groupID");
line = rs.getString("districtID");
if (line != null && !line.isEmpty()) {
try {
UUID districtID = UUID.fromString(line.trim());
Expand Down Expand Up @@ -2112,7 +2112,7 @@ private boolean loadDistrict(ResultSet rs) {
String uuidString = null;

try {
PlotGroup district = universe.getGroup(UUID.fromString(rs.getString("districtID")));
PlotGroup district = universe.getGroup(UUID.fromString(rs.getString("uuid")));
if (district == null) {
TownyMessaging.sendErrorMsg("SQL: A district was not registered properly on load!");
return true;
Expand Down Expand Up @@ -2436,12 +2436,12 @@ public boolean saveDistrict(District district) {
TownyMessaging.sendDebugMsg("Saving district " + district.getName());
try {
HashMap<String, Object> pltgrp_hm = new HashMap<>();
pltgrp_hm.put("districtID", district.getUUID().toString());
pltgrp_hm.put("uuid", district.getUUID().toString());
pltgrp_hm.put("districtName", district.getName());
pltgrp_hm.put("town", district.getTown().getUUID().toString());
pltgrp_hm.put("metadata", serializeMetadata(district));

updateDB("DISTRICTS", pltgrp_hm, Collections.singletonList("districtID"));
updateDB("DISTRICTS", pltgrp_hm, Collections.singletonList("uuid"));

} catch (Exception e) {
plugin.getLogger().log(Level.WARNING, "SQL: Save Districts unknown error", e);
Expand Down Expand Up @@ -2762,7 +2762,7 @@ public void deletePlotGroup(PlotGroup group) {
@Override
public void deleteDistrict(District district) {
HashMap<String, Object> district_hm = new HashMap<>();
district_hm.put("districtID", district.getUUID());
district_hm.put("uuid", district.getUUID());
DeleteDB("DISTRICTS", district_hm);
}

Expand Down
3 changes: 2 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9899,4 +9899,5 @@ v0.92.0.11:
- The TownyServerAccount is now a proper EconomyHandler, reducing jank in the code that is used in the Closed Economy feature.
- If a plugin you use has broken, the author needs only change their imports section, switching to the re-located Transaction, TransactionType classes.
- Plugins under the umbrella of the TownyAdvanced organization which are known to have broken include EventWar, FlagWar.
- Do not update your Towny if you use either of these plugins until you see they have had a compatibility update.
- Do not update your Towny if you use either of these plugins until you see they have had a compatibility update.
- Fix for SQL db code related to new Districts.

0 comments on commit f25a886

Please sign in to comment.