Skip to content

Commit 4c0d370

Browse files
committed
Clean Up
1 parent ade276a commit 4c0d370

File tree

14 files changed

+159
-176
lines changed

14 files changed

+159
-176
lines changed

src/main/java/systems/kscott/randomspawnplus/RandomSpawnPlus.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public final class RandomSpawnPlus extends JavaPlugin {
3737
@Getter
3838
private LuckPerms luckPerms;
3939

40+
public static RandomSpawnPlus getInstance() {
41+
return INSTANCE;
42+
}
43+
4044
@Override
4145
public void onEnable() {
4246

@@ -84,7 +88,6 @@ public void onDisable() {
8488
SpawnCacher.getInstance().save();
8589
}
8690

87-
8891
public void registerEvents() {
8992
getServer().getPluginManager().registerEvents(new RSPDeathListener(this), this);
9093
getServer().getPluginManager().registerEvents(new RSPLoginListener(this), this);
@@ -99,10 +102,6 @@ public void registerCommands() {
99102
}
100103
}
101104

102-
public static RandomSpawnPlus getInstance() {
103-
return INSTANCE;
104-
}
105-
106105
public IEssentials getEssentials() {
107106
return (IEssentials) getServer().getPluginManager().getPlugin("Essentials");
108107
}

src/main/java/systems/kscott/randomspawnplus/commands/CommandRSP.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import co.aikar.commands.annotation.*;
55
import org.bukkit.command.CommandSender;
66
import systems.kscott.randomspawnplus.RandomSpawnPlus;
7-
import systems.kscott.randomspawnplus.spawn.SpawnCacher;
87
import systems.kscott.randomspawnplus.util.Chat;
98

109
@CommandAlias("rsp|randomspawnplus")
@@ -21,7 +20,7 @@ public CommandRSP(RandomSpawnPlus plugin) {
2120
@Default
2221
@Subcommand("help|h")
2322
public void _main(CommandSender player) {
24-
Chat.msg(player, "&8[&3RandomSpawnPlus&8] &7Running &bv"+plugin.getDescription().getVersion()+"&7, made with love &a:^)");
23+
Chat.msg(player, "&8[&3RandomSpawnPlus&8] &7Running &bv" + plugin.getDescription().getVersion() + "&7, made with love &a:^)");
2524
Chat.msg(player, "");
2625
Chat.msg(player, "&b/rsp &8- &7The help menu.");
2726
Chat.msg(player, "&b/rsp reload &8- &7Reload the plugin configuration.");

src/main/java/systems/kscott/randomspawnplus/commands/CommandWild.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package systems.kscott.randomspawnplus.commands;
22

33
import co.aikar.commands.BaseCommand;
4-
import co.aikar.commands.annotation.*;
4+
import co.aikar.commands.annotation.CommandAlias;
5+
import co.aikar.commands.annotation.CommandPermission;
6+
import co.aikar.commands.annotation.Default;
7+
import co.aikar.commands.annotation.Description;
58
import com.earth2me.essentials.User;
69
import io.papermc.lib.PaperLib;
7-
import net.luckperms.api.LuckPerms;
8-
import net.luckperms.api.node.Node;
910
import org.bukkit.Bukkit;
1011
import org.bukkit.Location;
1112
import org.bukkit.command.CommandSender;
@@ -56,7 +57,7 @@ public void wild(CommandSender sender) {
5657

5758

5859
String message = plugin.getLang().getString("wild-tp-cooldown");
59-
message = message.replace("%delay", Chat.timeLeft(cooldown/1000 - Instant.now().getEpochSecond()));
60+
message = message.replace("%delay", Chat.timeLeft(cooldown / 1000 - Instant.now().getEpochSecond()));
6061

6162
Chat.msg(player, message);
6263
return;

src/main/java/systems/kscott/randomspawnplus/events/RandomSpawnEvent.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,24 @@
88

99
public class RandomSpawnEvent extends Event {
1010

11+
@Getter
12+
private static final HandlerList HANDLERS_LIST = new HandlerList();
1113
@Getter
1214
private Location location;
13-
1415
@Getter
1516
private Player player;
16-
1717
@Getter
1818
private SpawnType spawnType;
1919

20-
@Getter
21-
private static final HandlerList HANDLERS_LIST = new HandlerList();
22-
23-
24-
@Override
25-
public HandlerList getHandlers() {
26-
return HANDLERS_LIST;
27-
}
2820

2921
public RandomSpawnEvent(Location location, Player player, SpawnType spawnType) {
3022
this.location = location;
3123
this.player = player;
3224
this.spawnType = spawnType;
3325
}
26+
27+
@Override
28+
public HandlerList getHandlers() {
29+
return HANDLERS_LIST;
30+
}
3431
}

src/main/java/systems/kscott/randomspawnplus/events/SpawnCheckEvent.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,23 @@
77

88
public class SpawnCheckEvent extends Event {
99

10-
public static HandlerList getHandlerList() {
11-
return HANDLERS_LIST;
12-
}
13-
1410
private static final HandlerList HANDLERS_LIST = new HandlerList();
15-
1611
@Getter
1712
private Location location;
18-
1913
@Getter
2014
private boolean valid;
21-
2215
@Getter
2316
private String validReason = "UNK";
2417

25-
2618
public SpawnCheckEvent(Location location) {
2719
this.location = location;
2820
this.valid = true;
2921
}
3022

23+
public static HandlerList getHandlerList() {
24+
return HANDLERS_LIST;
25+
}
26+
3127
@Override
3228
public HandlerList getHandlers() {
3329
return HANDLERS_LIST;

src/main/java/systems/kscott/randomspawnplus/listeners/RSPDeathListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public void onDeath(PlayerRespawnEvent event) {
4444
try {
4545
location = SpawnFinder.getInstance().findSpawn(true).add(0.5, 0, 0.5);
4646
} catch (FinderTimedOutException e) {
47-
plugin.getLogger().warning("The spawn finder failed to find a valid spawn, and has not given "+player.getName()+" a random spawn. If you find this happening a lot, then raise the 'spawn-finder-tries-before-timeout' key in the config.");
48-
return;
47+
plugin.getLogger().warning("The spawn finder failed to find a valid spawn, and has not given " + player.getName() + " a random spawn. If you find this happening a lot, then raise the 'spawn-finder-tries-before-timeout' key in the config.");
48+
return;
4949
}
5050

5151
RandomSpawnEvent randomSpawnEvent = new RandomSpawnEvent(location, player, SpawnType.ON_DEATH);

src/main/java/systems/kscott/randomspawnplus/listeners/RSPLoginListener.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111

1212
public class RSPLoginListener implements Listener {
1313

14+
public static ArrayList<String> firstJoinPlayers = new ArrayList<>();
1415
private FileConfiguration config;
1516

17+
1618
public RSPLoginListener(RandomSpawnPlus plugin) {
1719
this.config = plugin.getConfig();
1820
}
1921

20-
21-
public static ArrayList<String> firstJoinPlayers = new ArrayList<>();
22-
2322
@EventHandler
2423
public void preLoginHandler(AsyncPlayerPreLoginEvent event) {
2524
if (config.getBoolean("randomspawn-enabled")) {

src/main/java/systems/kscott/randomspawnplus/spawn/SpawnCacher.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,17 @@
88
import systems.kscott.randomspawnplus.RandomSpawnPlus;
99
import systems.kscott.randomspawnplus.util.Locations;
1010

11-
import java.util.*;
11+
import java.util.ArrayList;
12+
import java.util.Iterator;
13+
import java.util.List;
14+
import java.util.Random;
1215

1316
public class SpawnCacher {
1417

1518
public static SpawnCacher INSTANCE;
16-
17-
18-
public static void initialize(RandomSpawnPlus plugin) {
19-
INSTANCE = new SpawnCacher(plugin);
20-
}
21-
22-
public static SpawnCacher getInstance() {
23-
return INSTANCE;
24-
}
25-
2619
private RandomSpawnPlus plugin;
27-
2820
@Getter
2921
private boolean spawnsRequireSaving;
30-
3122
@Getter
3223
private List<String> cachedSpawns;
3324

@@ -39,6 +30,14 @@ public SpawnCacher(RandomSpawnPlus plugin) {
3930
runWatchdog();
4031
}
4132

33+
public static void initialize(RandomSpawnPlus plugin) {
34+
INSTANCE = new SpawnCacher(plugin);
35+
}
36+
37+
public static SpawnCacher getInstance() {
38+
return INSTANCE;
39+
}
40+
4241
private void cacheSpawns() {
4342
boolean debugMode = plugin.getConfigManager().getConfig().getBoolean("debug-mode");
4443

@@ -59,7 +58,7 @@ private void cacheSpawns() {
5958

6059
List<String> newLocations = new ArrayList<>();
6160

62-
Bukkit.getLogger().info("Caching "+missingLocations+" spawns.");
61+
Bukkit.getLogger().info("Caching " + missingLocations + " spawns.");
6362
for (int i = 0; i <= missingLocations; i++) {
6463
new BukkitRunnable() {
6564

@@ -84,7 +83,7 @@ public void run() {
8483
/* Wait for all spawns to be cached */
8584
if (newLocations.size() <= missingLocations) {
8685
if (debugMode)
87-
Bukkit.getLogger().info(newLocations.size() +", "+ missingLocations);
86+
Bukkit.getLogger().info(newLocations.size() + ", " + missingLocations);
8887
} else {
8988
cachedSpawns.addAll(newLocations);
9089
/* Save spawns to file */
@@ -101,7 +100,7 @@ public Location getRandomSpawn() {
101100
}
102101

103102
public void deleteSpawn(Location location) {
104-
for (Iterator<String> iterator = cachedSpawns.iterator(); iterator.hasNext();) {
103+
for (Iterator<String> iterator = cachedSpawns.iterator(); iterator.hasNext(); ) {
105104
String locationString = iterator.next();
106105
//Bukkit.getLogger().info(Locations.serializeString(location)+", "+locationString);
107106
if (Locations.serializeString(location).equals(locationString)) {

src/main/java/systems/kscott/randomspawnplus/spawn/SpawnFinder.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,9 @@
2020
public class SpawnFinder {
2121

2222
public static SpawnFinder INSTANCE;
23-
24-
public static void initialize(RandomSpawnPlus plugin) {
25-
INSTANCE = new SpawnFinder(plugin);
26-
}
27-
28-
public static SpawnFinder getInstance() {
29-
return INSTANCE;
30-
}
31-
32-
ArrayList<Material> safeBlocks;
33-
3423
public RandomSpawnPlus plugin;
35-
3624
public FileConfiguration config;
25+
ArrayList<Material> safeBlocks;
3726

3827
public SpawnFinder(RandomSpawnPlus plugin) {
3928
this.plugin = plugin;
@@ -53,13 +42,21 @@ public SpawnFinder(RandomSpawnPlus plugin) {
5342
safeBlocks.add(XMaterial.CAVE_AIR.parseMaterial());
5443
}
5544

45+
public static void initialize(RandomSpawnPlus plugin) {
46+
INSTANCE = new SpawnFinder(plugin);
47+
}
48+
49+
public static SpawnFinder getInstance() {
50+
return INSTANCE;
51+
}
52+
5653
public Location getCandidateLocation() {
5754
String worldString = config.getString("respawn-world");
5855

5956
World world = Bukkit.getWorld(worldString);
6057

6158
if (world == null) {
62-
plugin.getLogger().severe("The world '"+worldString+"' is invalid. Please change the 'respawn-world' key in the config.");
59+
plugin.getLogger().severe("The world '" + worldString + "' is invalid. Please change the 'respawn-world' key in the config.");
6360
plugin.getServer().getPluginManager().disablePlugin(plugin);
6461
}
6562

@@ -77,7 +74,7 @@ public Location getCandidateLocation() {
7774
SpawnRegion region1 = new SpawnRegion(minX, minXblocked, minZ, minZblocked);
7875
SpawnRegion region2 = new SpawnRegion(minXblocked, maxXblocked, minZblocked, maxZ - maxZblocked);
7976
SpawnRegion region3 = new SpawnRegion(maxXblocked, maxX, maxZblocked, maxX);
80-
SpawnRegion region4 = new SpawnRegion(minZblocked, maxZ-minZblocked, minZ + minXblocked, maxZ - minZblocked);
77+
SpawnRegion region4 = new SpawnRegion(minZblocked, maxZ - minZblocked, minZ + minXblocked, maxZ - minZblocked);
8178

8279
SpawnRegion[] spawnRegions = new SpawnRegion[]{region1, region2, region3, region4};
8380

@@ -143,7 +140,7 @@ public Location findSpawn(boolean useSpawnCaching) throws FinderTimedOutExceptio
143140
plugin.getLogger().info(locClone.getBlock().getType().toString());
144141
plugin.getLogger().info(locClone.add(0, 1, 0).getBlock().getType().toString());
145142
plugin.getLogger().info(locClone.add(0, 1, 0).getBlock().getType().toString());
146-
plugin.getLogger().info("Spawned at "+location.getBlockX()+", "+location.getBlockY()+", "+location.getBlockZ());
143+
plugin.getLogger().info("Spawned at " + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ());
147144
}
148145
return location.add(0, 1, 0);
149146
}
@@ -190,7 +187,7 @@ public boolean checkSpawn(Location location) {
190187

191188
if (!isValid) {
192189
if (debugMode)
193-
plugin.getLogger().info("Invalid spawn: "+spawnCheckEvent.getValidReason());
190+
plugin.getLogger().info("Invalid spawn: " + spawnCheckEvent.getValidReason());
194191
}
195192

196193
if (blockedSpawnRange) {
@@ -218,7 +215,7 @@ public boolean checkSpawn(Location location) {
218215

219216
if (!safeBlocks.contains(block1.getType())) {
220217
if (debugMode) {
221-
plugin.getLogger().info("Invalid spawn: "+block1.getType().toString()+" is not a safe block!");
218+
plugin.getLogger().info("Invalid spawn: " + block1.getType().toString() + " is not a safe block!");
222219
}
223220
isValid = false;
224221
}

src/main/java/systems/kscott/randomspawnplus/util/CooldownManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import systems.kscott.randomspawnplus.RandomSpawnPlus;
55

66
import java.time.Instant;
7-
import java.util.Date;
87
import java.util.HashMap;
98
import java.util.concurrent.TimeUnit;
109

0 commit comments

Comments
 (0)