Skip to content

Commit 1e97d29

Browse files
More archived console fixes
1 parent 3e1cbfd commit 1e97d29

File tree

11 files changed

+249
-201
lines changed

11 files changed

+249
-201
lines changed

src/main/java/me/eccentric_nz/TARDIS/commands/tardis/TARDISArchiveCommand.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ boolean zip(Player player, String[] args) {
132132
// get the schematic start location, width, length and height
133133
JsonObject obj = null;
134134
if (current.getPermission().equals("archive")) {
135-
HashMap<String, Object> wherean = new HashMap<>();
136-
wherean.put("uuid", uuid);
137-
wherean.put("name", name);
138-
ResultSetArchive rsa = new ResultSetArchive(plugin, wherean);
135+
ResultSetArchiveByName rsa = new ResultSetArchiveByName(plugin, uuid, name);
139136
if (rsa.resultSet()) {
140137
Archive archive = rsa.getArchive();
141138
obj = archive.getJSON();

src/main/java/me/eccentric_nz/TARDIS/database/resultset/ResultSetStandby.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import me.eccentric_nz.TARDIS.enumeration.ChameleonPreset;
2323
import me.eccentric_nz.TARDIS.enumeration.Consoles;
2424
import me.eccentric_nz.TARDIS.enumeration.TardisLight;
25-
import me.eccentric_nz.TARDIS.schematic.ResultSetArchive;
25+
import me.eccentric_nz.TARDIS.schematic.ResultSetArchiveByUse;
2626

2727
import java.sql.Connection;
2828
import java.sql.PreparedStatement;
@@ -73,10 +73,7 @@ public HashMap<Integer, StandbyData> onStandby() {
7373
switch (rs.getString("size")) {
7474
case "JUNK" -> sd = new StandbyData(Integer.MAX_VALUE, UUID.fromString(rs.getString("uuid")), false, false, ChameleonPreset.JUNK, TardisLight.TENTH);
7575
case "ARCHIVE" -> {
76-
HashMap<String, Object> wherea = new HashMap<>();
77-
wherea.put("uuid", rs.getString("uuid"));
78-
wherea.put("use", 1);
79-
ResultSetArchive rsa = new ResultSetArchive(plugin, wherea);
76+
ResultSetArchiveByUse rsa = new ResultSetArchiveByUse(plugin, rs.getString("uuid"), 1);
8077
TardisLight lightType = TardisLight.LAMP;
8178
if (rsa.resultSet()) {
8279
lightType = rsa.getArchive().getLight();

src/main/java/me/eccentric_nz/TARDIS/database/resultset/ResultSetTardisSize.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
import me.eccentric_nz.TARDIS.database.TARDISDatabaseConnection;
2121
import me.eccentric_nz.TARDIS.enumeration.ConsoleSize;
2222
import me.eccentric_nz.TARDIS.enumeration.Consoles;
23-
import me.eccentric_nz.TARDIS.schematic.ResultSetArchive;
23+
import me.eccentric_nz.TARDIS.schematic.ResultSetArchiveByUse;
2424

2525
import java.sql.Connection;
2626
import java.sql.PreparedStatement;
2727
import java.sql.ResultSet;
2828
import java.sql.SQLException;
29-
import java.util.HashMap;
3029

3130
/**
3231
* Many facts, figures, and formulas are contained within the Matrix, including... the locations of the TARDIS vaults.
@@ -74,10 +73,7 @@ public boolean fromUUID(String uuid) {
7473
rs.next();
7574
if (rs.getString("size").equals("ARCHIVE")) {
7675
// get archive
77-
HashMap<String, Object> where = new HashMap<>();
78-
where.put("uuid", uuid);
79-
where.put("use", 1);
80-
ResultSetArchive rsa = new ResultSetArchive(plugin, where);
76+
ResultSetArchiveByUse rsa = new ResultSetArchiveByUse(plugin, uuid, 1);
8177
if (rsa.resultSet()) {
8278
consoleSize = rsa.getArchive().getConsoleSize();
8379
}

src/main/java/me/eccentric_nz/TARDIS/desktop/TARDISFullThemeRunnable.java

Lines changed: 95 additions & 101 deletions
Large diffs are not rendered by default.

src/main/java/me/eccentric_nz/TARDIS/desktop/TARDISRepair.java

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import me.eccentric_nz.TARDIS.enumeration.TardisModule;
3030
import me.eccentric_nz.TARDIS.rooms.TARDISCondenserData;
3131
import me.eccentric_nz.TARDIS.schematic.ArchiveUpdate;
32-
import me.eccentric_nz.TARDIS.schematic.ResultSetArchive;
32+
import me.eccentric_nz.TARDIS.schematic.ResultSetArchiveByUse;
3333
import me.eccentric_nz.TARDIS.schematic.TARDISSchematicGZip;
3434
import me.eccentric_nz.TARDIS.utility.TARDISStaticLocationGetters;
3535
import org.bukkit.Material;
@@ -255,28 +255,19 @@ private JsonObject getConsole() {
255255
String perm = tardis.getSchematic().getPermission();
256256
if (perm.equals("archive")) {
257257
// try 1
258-
HashMap<String, Object> wherea = new HashMap<>();
259-
wherea.put("uuid", uuid);
260-
wherea.put("use", 1);
261-
ResultSetArchive rsa = new ResultSetArchive(plugin, wherea);
258+
ResultSetArchiveByUse rsa = new ResultSetArchiveByUse(plugin, uuid.toString(), 1);
262259
if (rsa.resultSet()) {
263260
obj = rsa.getArchive().getJSON();
264261
} else {
265262
// try 2
266-
HashMap<String, Object> wherea2 = new HashMap<>();
267-
wherea2.put("uuid", uuid);
268-
wherea2.put("use", 2);
269-
ResultSetArchive rsa2 = new ResultSetArchive(plugin, wherea2);
263+
ResultSetArchiveByUse rsa2 = new ResultSetArchiveByUse(plugin, uuid.toString(), 2);
270264
if (rsa2.resultSet()) {
271265
obj = rsa2.getArchive().getJSON();
272266
// set as active
273267
new ArchiveUpdate(plugin, uuid.toString(), rsa2.getArchive().getName()).setInUse();
274268
} else {
275269
// try 3
276-
HashMap<String, Object> wherea3 = new HashMap<>();
277-
wherea3.put("uuid", uuid);
278-
wherea3.put("use", 0);
279-
ResultSetArchive rsa3 = new ResultSetArchive(plugin, wherea3);
270+
ResultSetArchiveByUse rsa3 = new ResultSetArchiveByUse(plugin, uuid.toString(), 0);
280271
if (rsa3.resultSet()) {
281272
obj = rsa2.getArchive().getJSON();
282273
// set as active
@@ -295,26 +286,17 @@ private JsonObject getConsole() {
295286
private String getArchiveName() {
296287
String uuid = player.getUniqueId().toString();
297288
// try 1
298-
HashMap<String, Object> wherea = new HashMap<>();
299-
wherea.put("uuid", uuid);
300-
wherea.put("use", 1);
301-
ResultSetArchive rsa = new ResultSetArchive(plugin, wherea);
289+
ResultSetArchiveByUse rsa = new ResultSetArchiveByUse(plugin, uuid, 1);
302290
if (rsa.resultSet()) {
303291
return rsa.getArchive().getName();
304292
} else {
305293
// try 2
306-
HashMap<String, Object> wherea2 = new HashMap<>();
307-
wherea2.put("uuid", uuid);
308-
wherea2.put("use", 2);
309-
ResultSetArchive rsa2 = new ResultSetArchive(plugin, wherea2);
294+
ResultSetArchiveByUse rsa2 = new ResultSetArchiveByUse(plugin, uuid, 2);
310295
if (rsa2.resultSet()) {
311296
return rsa2.getArchive().getName();
312297
} else {
313298
// try 3
314-
HashMap<String, Object> wherea3 = new HashMap<>();
315-
wherea3.put("uuid", uuid);
316-
wherea3.put("use", 0);
317-
ResultSetArchive rsa3 = new ResultSetArchive(plugin, wherea3);
299+
ResultSetArchiveByUse rsa3 = new ResultSetArchiveByUse(plugin, uuid, 0);
318300
if (rsa3.resultSet()) {
319301
return rsa3.getArchive().getName();
320302
}

src/main/java/me/eccentric_nz/TARDIS/desktop/TARDISThemeProcessor.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import me.eccentric_nz.TARDIS.enumeration.ConsoleSize;
2929
import me.eccentric_nz.TARDIS.enumeration.TardisModule;
3030
import me.eccentric_nz.TARDIS.schematic.ArchiveReset;
31-
import me.eccentric_nz.TARDIS.schematic.ResultSetArchive;
31+
import me.eccentric_nz.TARDIS.schematic.ResultSetArchiveByUse;
3232
import me.eccentric_nz.TARDIS.schematic.TARDISSchematicGZip;
3333
import org.bukkit.entity.Player;
3434

@@ -70,15 +70,16 @@ public void changeDesktop() {
7070
return;
7171
}
7272
}
73-
// get Archive if necessary
73+
// get archive if necessary
7474
ConsoleSize size_next;
7575
int nextHeight;
7676
int nextWidth;
77+
if (tud.getPrevious().getPermission().equals("archive")) {
78+
// set use as 2
79+
new ArchiveReset(plugin, uuid.toString(), 1, 2).resetUse();
80+
}
7781
if (tud.getSchematic().getPermission().equals("archive")) {
78-
HashMap<String, Object> where = new HashMap<>();
79-
where.put("uuid", uuid.toString());
80-
where.put("use", 1);
81-
ResultSetArchive rs = new ResultSetArchive(plugin, where);
82+
ResultSetArchiveByUse rs = new ResultSetArchiveByUse(plugin, uuid.toString(), 1);
8283
if (rs.resultSet()) {
8384
archive_next = rs.getArchive();
8485
JsonObject dimensions = archive_next.getJSON().get("dimensions").getAsJsonObject();
@@ -90,10 +91,10 @@ public void changeDesktop() {
9091
Player cp = plugin.getServer().getPlayer(uuid);
9192
plugin.getMessenger().send(cp, TardisModule.TARDIS, "ARCHIVE_NOT_FOUND");
9293
// reset next archive back to 0
93-
94+
new ArchiveReset(plugin, uuid.toString(), 1, 0).resetUse();
9495
if (tud.getPrevious().getPermission().equals("archive")) {
9596
// reset previous back to 1
96-
97+
new ArchiveReset(plugin, uuid.toString(), 2, 1).resetUse();
9798
}
9899
return;
99100
}
@@ -113,10 +114,7 @@ public void changeDesktop() {
113114
int previousHeight;
114115
int previousWidth;
115116
if (tud.getPrevious().getPermission().equals("archive")) {
116-
HashMap<String, Object> where = new HashMap<>();
117-
where.put("uuid", uuid.toString());
118-
where.put("use", 2);
119-
ResultSetArchive rs = new ResultSetArchive(plugin, where);
117+
ResultSetArchiveByUse rs = new ResultSetArchiveByUse(plugin, uuid.toString(), 2);
120118
if (rs.resultSet()) {
121119
JsonObject dimensions = rs.getArchive().getJSON().get("dimensions").getAsJsonObject();
122120
previousHeight = dimensions.get("height").getAsInt();
@@ -128,10 +126,10 @@ public void changeDesktop() {
128126
plugin.getMessenger().send(cp, TardisModule.TARDIS, "ARCHIVE_NOT_FOUND");
129127
if (tud.getSchematic().getPermission().equals("archive")) {
130128
// reset next back to 0
131-
129+
new ArchiveReset(plugin, uuid.toString(), 1, 0).resetUse();
132130
}
133131
// reset previous archive back to 1
134-
132+
new ArchiveReset(plugin, uuid.toString(), 2, 1).resetUse();
135133
return;
136134
}
137135
} else {
@@ -176,11 +174,11 @@ public void changeDesktop() {
176174
plugin.getTrackerKeeper().getUpgrades().remove(uuid);
177175
if (tud.getSchematic().getPermission().equals("archive")) {
178176
// reset next archive back to 0
179-
new ArchiveReset(plugin, uuid.toString(), 1,0).resetUse();
177+
new ArchiveReset(plugin, uuid.toString(), 1, 0).resetUse();
180178
}
181179
if (tud.getPrevious().getPermission().equals("archive")) {
182180
// reset previous back to 1
183-
new ArchiveReset(plugin, uuid.toString(), 2,1).resetUse();
181+
new ArchiveReset(plugin, uuid.toString(), 2, 1).resetUse();
184182
}
185183
return;
186184
}

src/main/java/me/eccentric_nz/TARDIS/desktop/TARDISThemeRepairRunnable.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242
import me.eccentric_nz.TARDIS.rooms.TARDISCondenserData;
4343
import me.eccentric_nz.TARDIS.rooms.TARDISPainting;
4444
import me.eccentric_nz.TARDIS.rotors.TARDISTimeRotor;
45-
import me.eccentric_nz.TARDIS.schematic.ArchiveReset;
46-
import me.eccentric_nz.TARDIS.schematic.ResultSetArchive;
45+
import me.eccentric_nz.TARDIS.schematic.ResultSetArchiveByUse;
4746
import me.eccentric_nz.TARDIS.schematic.TARDISSchematicGZip;
4847
import me.eccentric_nz.TARDIS.schematic.getters.DataPackPainting;
4948
import me.eccentric_nz.TARDIS.schematic.setters.*;
@@ -126,12 +125,9 @@ public class TARDISThemeRepairRunnable extends TARDISThemeRunnable {
126125
public void run() {
127126
// initialise
128127
if (!running) {
129-
// get Archive if necessary
128+
// get archive if necessary
130129
if (tud.getSchematic().getPermission().equals("archive")) {
131-
HashMap<String, Object> wherean = new HashMap<>();
132-
wherean.put("uuid", uuid.toString());
133-
wherean.put("use", 1);
134-
ResultSetArchive rs = new ResultSetArchive(plugin, wherean);
130+
ResultSetArchiveByUse rs = new ResultSetArchiveByUse(plugin, uuid.toString(), 1);
135131
if (rs.resultSet()) {
136132
archive = rs.getArchive();
137133
} else {

src/main/java/me/eccentric_nz/TARDIS/floodgate/FloodgateDesktopArchiveForm.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import me.eccentric_nz.TARDIS.enumeration.Schematic;
2828
import me.eccentric_nz.TARDIS.enumeration.TardisModule;
2929
import me.eccentric_nz.TARDIS.schematic.ArchiveUpdate;
30-
import me.eccentric_nz.TARDIS.schematic.ResultSetArchive;
3130
import me.eccentric_nz.TARDIS.schematic.ResultSetArchiveButtons;
31+
import me.eccentric_nz.TARDIS.schematic.ResultSetArchiveByName;
3232
import me.eccentric_nz.TARDIS.utility.ComponentUtils;
3333
import org.bukkit.entity.Player;
3434
import org.bukkit.inventory.ItemStack;
@@ -39,7 +39,6 @@
3939
import org.geysermc.floodgate.api.FloodgateApi;
4040
import org.geysermc.floodgate.api.player.FloodgatePlayer;
4141

42-
import java.util.HashMap;
4342
import java.util.Locale;
4443
import java.util.UUID;
4544

@@ -121,10 +120,7 @@ private void handleResponse(SimpleFormResponse response) {
121120
// remember the upgrade choice
122121
Schematic schm = Consoles.schematicFor("archive");
123122
TARDISUpgradeData tud = plugin.getTrackerKeeper().getUpgrades().get(uuid);
124-
HashMap<String, Object> where = new HashMap<>();
125-
where.put("uuid", uuid.toString());
126-
where.put("name", label);
127-
ResultSetArchive rsa = new ResultSetArchive(plugin, where);
123+
ResultSetArchiveByName rsa = new ResultSetArchiveByName(plugin, uuid.toString(), label);
128124
if (rsa.resultSet()) {
129125
Archive a = rsa.getArchive();
130126
if (a.getUse() == 1) {

src/main/java/me/eccentric_nz/TARDIS/schematic/ResultSetArchive.java renamed to src/main/java/me/eccentric_nz/TARDIS/schematic/ResultSetArchiveByName.java

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,53 +26,40 @@
2626
import java.sql.PreparedStatement;
2727
import java.sql.ResultSet;
2828
import java.sql.SQLException;
29-
import java.util.HashMap;
30-
import java.util.Map;
3129
import java.util.UUID;
3230

3331
/**
3432
* @author eccentric_nz
3533
*/
36-
public class ResultSetArchive {
34+
public class ResultSetArchiveByName {
3735

3836
private final TARDISDatabaseConnection service = TARDISDatabaseConnection.getINSTANCE();
3937
private final Connection connection = service.getConnection();
4038
private final TARDIS plugin;
41-
private final HashMap<String, Object> where;
4239
private final String prefix;
40+
private final String uuid;
41+
private final String name;
4342
private Archive archive;
4443

45-
public ResultSetArchive(TARDIS plugin, HashMap<String, Object> where) {
44+
public ResultSetArchiveByName(TARDIS plugin, String uuid, String name) {
4645
this.plugin = plugin;
47-
this.where = where;
4846
prefix = this.plugin.getPrefix();
47+
this.uuid = uuid;
48+
this.name = name;
4949
}
5050

5151
public boolean resultSet() {
5252
PreparedStatement statement = null;
5353
ResultSet rs = null;
54-
String wheres = "";
55-
if (where != null) {
56-
StringBuilder sbw = new StringBuilder();
57-
where.forEach((key, value) -> sbw.append(key).append(" = ? AND "));
58-
wheres = " WHERE " + sbw.substring(0, sbw.length() - 5);
59-
}
60-
String query = "SELECT * FROM " + prefix + "archive" + wheres;
54+
String query = "SELECT " + prefix + "archive.*, " + prefix + "player_prefs.lights FROM "
55+
+ prefix + "archive, " + prefix + "player_prefs WHERE archive.uuid = ? AND name = ?"
56+
+ " AND " + prefix + "archive.uuid = " + prefix + "player_prefs.uuid";
57+
plugin.debug(query);
6158
try {
6259
service.testConnection(connection);
6360
statement = connection.prepareStatement(query);
64-
if (where != null) {
65-
int s = 1;
66-
for (Map.Entry<String, Object> entry : where.entrySet()) {
67-
if (entry.getValue() instanceof String) {
68-
statement.setString(s, entry.getValue().toString());
69-
} else {
70-
statement.setInt(s, (Integer) entry.getValue());
71-
}
72-
s++;
73-
}
74-
where.clear();
75-
}
61+
statement.setString(1, uuid);
62+
statement.setString(2, name);
7663
rs = statement.executeQuery();
7764
if (rs.isBeforeFirst()) {
7865
while (rs.next()) {

0 commit comments

Comments
 (0)