From 159ed046cb62c93bb279560f71fbbd1f75cd4ef6 Mon Sep 17 00:00:00 2001 From: Focusvity Date: Sat, 19 Mar 2022 20:38:09 +1100 Subject: [PATCH] Removed deprecated methods from custom world and fixed a missing Jedis check --- .../plex/punishment/PunishmentManager.java | 45 ++++++++++--------- .../dev/plex/world/CustomChunkGenerator.java | 1 + .../dev/plex/world/FlatChunkGenerator.java | 6 +-- .../dev/plex/world/NoiseChunkGenerator.java | 8 ++-- .../dev/plex/world/OctaveChunkGenerator.java | 8 ++-- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/main/java/dev/plex/punishment/PunishmentManager.java b/src/main/java/dev/plex/punishment/PunishmentManager.java index bb1e00d..e292710 100644 --- a/src/main/java/dev/plex/punishment/PunishmentManager.java +++ b/src/main/java/dev/plex/punishment/PunishmentManager.java @@ -175,28 +175,31 @@ public class PunishmentManager extends PlexBase public List getActiveBans() { List punishments = Lists.newArrayList(); - Jedis jedis = Plex.get().getRedisConnection().getJedis(); - jedis.keys("*").forEach(key -> - { - try - { - UUID uuid = UUID.fromString(key); - String jsonPunishmentString = jedis.get(uuid.toString()); - JSONObject object = new JSONObject(jsonPunishmentString); - object.getJSONObject(uuid.toString()).getJSONArray("punishments").forEach(json -> - { - Punishment punishment = Punishment.fromJson(json.toString()); - if (punishment.isActive() && punishment.getType() == PunishmentType.BAN) - { - punishments.add(punishment); - } - }); - } - catch (IllegalArgumentException ignored) - { - } - }); + if (Plex.get().getRedisConnection().isEnabled()) + { + Jedis jedis = Plex.get().getRedisConnection().getJedis(); + jedis.keys("*").forEach(key -> + { + try + { + UUID uuid = UUID.fromString(key); + String jsonPunishmentString = jedis.get(uuid.toString()); + JSONObject object = new JSONObject(jsonPunishmentString); + object.getJSONObject(uuid.toString()).getJSONArray("punishments").forEach(json -> + { + Punishment punishment = Punishment.fromJson(json.toString()); + if (punishment.isActive() && punishment.getType() == PunishmentType.BAN) + { + punishments.add(punishment); + } + }); + } + catch (IllegalArgumentException ignored) + { + } + }); + } return punishments; } diff --git a/src/main/java/dev/plex/world/CustomChunkGenerator.java b/src/main/java/dev/plex/world/CustomChunkGenerator.java index 9708382..f59d170 100644 --- a/src/main/java/dev/plex/world/CustomChunkGenerator.java +++ b/src/main/java/dev/plex/world/CustomChunkGenerator.java @@ -17,6 +17,7 @@ public abstract class CustomChunkGenerator extends ChunkGenerator this.populators = Arrays.asList(populators); } + @Override public List getDefaultPopulators(World world) { return populators; diff --git a/src/main/java/dev/plex/world/FlatChunkGenerator.java b/src/main/java/dev/plex/world/FlatChunkGenerator.java index 68ad9f2..f19e234 100644 --- a/src/main/java/dev/plex/world/FlatChunkGenerator.java +++ b/src/main/java/dev/plex/world/FlatChunkGenerator.java @@ -3,6 +3,8 @@ package dev.plex.world; import java.util.Random; import org.bukkit.World; import org.bukkit.generator.BlockPopulator; +import org.bukkit.generator.WorldInfo; +import org.jetbrains.annotations.NotNull; public abstract class FlatChunkGenerator extends CustomChunkGenerator { @@ -12,9 +14,8 @@ public abstract class FlatChunkGenerator extends CustomChunkGenerator } @Override - public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) + public void generateSurface(WorldInfo worldInfo, Random random, int x, int z, ChunkData chunk) { - ChunkData chunk = this.createChunkData(world); for (int xx = 0; xx < 16; xx++) { for (int zz = 0; zz < 16; zz++) @@ -22,7 +23,6 @@ public abstract class FlatChunkGenerator extends CustomChunkGenerator createLoopChunkData(xx, height, zz, chunk); } } - return chunk; } public abstract void createLoopChunkData(int x, int y, int z, ChunkData chunk); diff --git a/src/main/java/dev/plex/world/NoiseChunkGenerator.java b/src/main/java/dev/plex/world/NoiseChunkGenerator.java index 8b38451..ddfb6eb 100644 --- a/src/main/java/dev/plex/world/NoiseChunkGenerator.java +++ b/src/main/java/dev/plex/world/NoiseChunkGenerator.java @@ -3,7 +3,9 @@ package dev.plex.world; import java.util.Random; import org.bukkit.World; import org.bukkit.generator.BlockPopulator; +import org.bukkit.generator.WorldInfo; import org.bukkit.util.noise.PerlinNoiseGenerator; +import org.jetbrains.annotations.NotNull; public abstract class NoiseChunkGenerator extends CustomChunkGenerator { @@ -16,10 +18,9 @@ public abstract class NoiseChunkGenerator extends CustomChunkGenerator } @Override - public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) + public void generateNoise(WorldInfo worldInfo, Random random, int x, int z, ChunkData chunk) { - ChunkData chunk = this.createChunkData(world); - PerlinNoiseGenerator generator = new PerlinNoiseGenerator(new Random(world.getSeed())); + PerlinNoiseGenerator generator = new PerlinNoiseGenerator(new Random(worldInfo.getSeed())); for (int xx = 0; xx < 16; xx++) { for (int zz = 0; zz < 16; zz++) @@ -28,7 +29,6 @@ public abstract class NoiseChunkGenerator extends CustomChunkGenerator createLoopChunkData(xx, height, zz, chunk); } } - return chunk; } public abstract void createLoopChunkData(int x, int y, int z, ChunkData chunk); diff --git a/src/main/java/dev/plex/world/OctaveChunkGenerator.java b/src/main/java/dev/plex/world/OctaveChunkGenerator.java index 1eed47c..5b2e044 100644 --- a/src/main/java/dev/plex/world/OctaveChunkGenerator.java +++ b/src/main/java/dev/plex/world/OctaveChunkGenerator.java @@ -3,7 +3,9 @@ package dev.plex.world; import java.util.Random; import org.bukkit.World; import org.bukkit.generator.BlockPopulator; +import org.bukkit.generator.WorldInfo; import org.bukkit.util.noise.PerlinOctaveGenerator; +import org.jetbrains.annotations.NotNull; public abstract class OctaveChunkGenerator extends CustomChunkGenerator { @@ -16,10 +18,9 @@ public abstract class OctaveChunkGenerator extends CustomChunkGenerator } @Override - public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) + public void generateNoise(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z, @NotNull ChunkData chunk) { - ChunkData chunk = this.createChunkData(world); - PerlinOctaveGenerator generator = new PerlinOctaveGenerator(new Random(world.getSeed()), options.getOctaves()); + PerlinOctaveGenerator generator = new PerlinOctaveGenerator(new Random(worldInfo.getSeed()), options.getOctaves()); for (int xx = 0; xx < 16; xx++) { for (int zz = 0; zz < 16; zz++) @@ -28,7 +29,6 @@ public abstract class OctaveChunkGenerator extends CustomChunkGenerator createLoopChunkData(xx, height, zz, chunk); } } - return chunk; } public abstract void createLoopChunkData(int x, int y, int z, ChunkData chunk);