Skip to content

Commit c4e52ac

Browse files
committed
use world UID
1 parent 7ba6539 commit c4e52ac

File tree

1 file changed

+7
-6
lines changed
  • src/main/java/pro/cloudnode/smp/bankaccounts

1 file changed

+7
-6
lines changed

src/main/java/pro/cloudnode/smp/bankaccounts/POS.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.Date;
3030
import java.util.Objects;
3131
import java.util.Optional;
32+
import java.util.UUID;
3233
import java.util.logging.Level;
3334
import java.util.stream.IntStream;
3435
import java.util.zip.CRC32;
@@ -96,7 +97,7 @@ public POS(final @NotNull ResultSet rs) throws @NotNull SQLException, @NotNull I
9697
this.x = rs.getInt("x");
9798
this.y = rs.getInt("y");
9899
this.z = rs.getInt("z");
99-
final @NotNull Optional<@NotNull World> world = Optional.ofNullable(BankAccounts.getInstance().getServer().getWorld(rs.getString("world")));
100+
final @NotNull Optional<@NotNull World> world = Optional.ofNullable(BankAccounts.getInstance().getServer().getWorld(UUID.fromString(rs.getString("world"))));
100101
if (world.isEmpty()) throw new IllegalStateException("World not found: " + rs.getString("world"));
101102
this.world = world.get();
102103
this.price = rs.getBigDecimal("price");
@@ -123,7 +124,7 @@ public POS(final @NotNull ResultSet rs) throws @NotNull SQLException, @NotNull I
123124
* Create POS id
124125
*/
125126
public @NotNull String id() {
126-
return world.getName() + ":" + x + ":" + y + ":" + z;
127+
return world.getUID() + ":" + x + ":" + y + ":" + z;
127128
}
128129

129130
/**
@@ -135,7 +136,7 @@ public void save() {
135136
stmt.setInt(1, x);
136137
stmt.setInt(2, y);
137138
stmt.setInt(3, z);
138-
stmt.setString(4, world.getName());
139+
stmt.setString(4, world.getUID().toString());
139140
stmt.setBigDecimal(5, price);
140141
if (description == null) stmt.setNull(6, Types.VARCHAR);
141142
else stmt.setString(6, description);
@@ -157,7 +158,7 @@ public void delete() {
157158
stmt.setInt(1, x);
158159
stmt.setInt(2, y);
159160
stmt.setInt(3, z);
160-
stmt.setString(4, world.getName());
161+
stmt.setString(4, world.getUID().toString());
161162
stmt.executeUpdate();
162163
} catch (final @NotNull SQLException e) {
163164
BankAccounts.getInstance().getLogger().log(Level.SEVERE, "Could not delete POS in " + world.getName() + " at X: " + x + " Y: " + y + " Z: " + z, e);
@@ -178,7 +179,7 @@ public void delete() {
178179
stmt.setInt(1, x);
179180
stmt.setInt(2, y);
180181
stmt.setInt(3, z);
181-
stmt.setString(4, world.getName());
182+
stmt.setString(4, world.getUID().toString());
182183
final @NotNull ResultSet rs = stmt.executeQuery();
183184
return rs.next() ? Optional.of(new POS(rs)) : Optional.empty();
184185
} catch (final @NotNull SQLException e) {
@@ -236,7 +237,7 @@ public void delete() {
236237
public static @NotNull Optional<@NotNull POS> get(final @NotNull String id) {
237238
final @NotNull String @NotNull [] split = id.split(":");
238239
if (split.length != 4) return Optional.empty();
239-
final @NotNull Optional<@NotNull World> world = Optional.ofNullable(Bukkit.getWorld(split[0]));
240+
final @NotNull Optional<@NotNull World> world = Optional.ofNullable(BankAccounts.getInstance().getServer().getWorld(UUID.fromString(split[0])));
240241
if (world.isEmpty()) return Optional.empty();
241242
try {
242243
final int x = Integer.parseInt(split[1]);

0 commit comments

Comments
 (0)