Skip to content

Commit 664214a

Browse files
Check for errors (#177)
1 parent 9978534 commit 664214a

4 files changed

Lines changed: 62 additions & 34 deletions

File tree

Plugin/src/main/java/dev/lrxh/neptune/Neptune.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ public final class Neptune extends JavaPlugin {
8585
@Setter
8686
private boolean allowMatches;
8787

88+
private boolean errored;
89+
public void setErrored() {
90+
errored = true;
91+
}
92+
8893
public static Neptune get() {
8994
return instance;
9095
}
@@ -215,8 +220,10 @@ private void loadCommandManager() {
215220

216221
@Override
217222
public void onDisable() {
218-
stopService(KitService.get(), KitService::save);
219-
stopService(ArenaService.get(), ArenaService::save);
223+
if (!errored) {
224+
stopService(KitService.get(), KitService::save);
225+
stopService(ArenaService.get(), ArenaService::save);
226+
}
220227
stopService(MatchService.get(), MatchService::stopAllGames);
221228
stopService(TaskScheduler.get(), TaskScheduler::stopAllTasks);
222229
stopService(ProfileService.get(), ProfileService::saveAll);

Plugin/src/main/java/dev/lrxh/neptune/game/arena/ArenaService.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import dev.lrxh.api.arena.IArena;
44
import dev.lrxh.api.arena.IArenaService;
5+
import dev.lrxh.neptune.Neptune;
56
import dev.lrxh.neptune.configs.ConfigService;
67
import dev.lrxh.neptune.providers.manager.IService;
78
import dev.lrxh.neptune.providers.manager.Value;
@@ -37,8 +38,14 @@ public void load() {
3738
FileConfiguration config = ConfigService.get().getArenasConfig().getConfiguration();
3839
if (config.contains("arenas")) {
3940
for (String arenaName : getKeys("arenas")) {
40-
Arena arena = loadArena(arenaName);
41-
arenas.add(arena);
41+
try {
42+
Arena arena = loadArena(arenaName);
43+
arenas.add(arena);
44+
} catch (Exception e) {
45+
Neptune.get().getLogger().severe("Error occurred while loading an arena with key: " + arenaName);
46+
Neptune.get().setErrored();
47+
throw e;
48+
}
4249
}
4350
}
4451
}

Plugin/src/main/java/dev/lrxh/neptune/game/kit/KitService.java

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import dev.lrxh.api.arena.IArena;
44
import dev.lrxh.api.kit.IKit;
55
import dev.lrxh.api.kit.IKitService;
6+
import dev.lrxh.neptune.Neptune;
67
import dev.lrxh.neptune.configs.ConfigService;
78
import dev.lrxh.neptune.game.arena.Arena;
89
import dev.lrxh.neptune.game.arena.ArenaService;
@@ -36,41 +37,47 @@ public void load() {
3637
FileConfiguration config = ConfigService.get().getKitsConfig().getConfiguration();
3738
if (config.contains("kits")) {
3839
for (String kitName : getKeys("kits")) {
39-
String path = "kits." + kitName + ".";
40-
String displayName = config.getString(path + "displayName", kitName);
41-
ItemStack icon = ItemUtils.deserializeItem(config.getString(path + "icon", ""));
42-
43-
List<ItemStack> items = ItemUtils.deserialize(config.getString(path + "items", ""));
44-
int slot = config.getInt(path + "slot", kits.size() + 1);
45-
int kitEditorSlot = config.getInt(path + "kitEditor-slot", slot);
46-
double health = config.getDouble(path + "health", 20);
47-
double damageMultiplier = config.getDouble(path + "damage-multiplier", 1.0);
48-
49-
HashSet<Arena> arenas = new HashSet<>();
50-
if (!config.getStringList(path + "arenas").isEmpty()) {
51-
for (String arenaName : config.getStringList(path + "arenas")) {
52-
Arena arena = ArenaService.get().getArenaByName(arenaName);
53-
if (arena == null) {
54-
ServerUtils.error("KitService: Arena " + arenaName + " not found for kit " + kitName);
55-
continue;
40+
try {
41+
String path = "kits." + kitName + ".";
42+
String displayName = config.getString(path + "displayName", kitName);
43+
ItemStack icon = ItemUtils.deserializeItem(config.getString(path + "icon", ""));
44+
45+
List<ItemStack> items = ItemUtils.deserialize(config.getString(path + "items", ""));
46+
int slot = config.getInt(path + "slot", kits.size() + 1);
47+
int kitEditorSlot = config.getInt(path + "kitEditor-slot", slot);
48+
double health = config.getDouble(path + "health", 20);
49+
double damageMultiplier = config.getDouble(path + "damage-multiplier", 1.0);
50+
51+
HashSet<Arena> arenas = new HashSet<>();
52+
if (!config.getStringList(path + "arenas").isEmpty()) {
53+
for (String arenaName : config.getStringList(path + "arenas")) {
54+
Arena arena = ArenaService.get().getArenaByName(arenaName);
55+
if (arena == null) {
56+
ServerUtils.error("KitService: Arena " + arenaName + " not found for kit " + kitName);
57+
continue;
58+
}
59+
arenas.add(arena);
5660
}
57-
arenas.add(arena);
5861
}
59-
}
6062

61-
HashMap<KitRule, Boolean> rules = new HashMap<>();
62-
for (KitRule kitRule : KitRule.values()) {
63-
rules.put(kitRule, config.getBoolean(path + kitRule.getSaveName(), false));
64-
}
63+
HashMap<KitRule, Boolean> rules = new HashMap<>();
64+
for (KitRule kitRule : KitRule.values()) {
65+
rules.put(kitRule, config.getBoolean(path + kitRule.getSaveName(), false));
66+
}
6567

66-
List<PotionEffect> potionEffects = new ArrayList<>();
67-
if (!config.getStringList(path + "potionEffects").isEmpty()) {
68-
for (String potion : config.getStringList(path + "potionEffects")) {
69-
potionEffects.add(PotionEffectUtils.deserialize(potion));
68+
List<PotionEffect> potionEffects = new ArrayList<>();
69+
if (!config.getStringList(path + "potionEffects").isEmpty()) {
70+
for (String potion : config.getStringList(path + "potionEffects")) {
71+
potionEffects.add(PotionEffectUtils.deserialize(potion));
72+
}
7073
}
71-
}
7274

73-
kits.add(new Kit(kitName, displayName, items, arenas, icon, rules, slot, health, kitEditorSlot, potionEffects, damageMultiplier));
75+
kits.add(new Kit(kitName, displayName, items, arenas, icon, rules, slot, health, kitEditorSlot, potionEffects, damageMultiplier));
76+
} catch (Exception e) {
77+
Neptune.get().getLogger().severe("Error occurred while loading a kit with key: " + kitName);
78+
Neptune.get().setErrored();
79+
throw e;
80+
}
7481
}
7582
}
7683
}

Plugin/src/main/java/dev/lrxh/neptune/profile/ProfileService.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import dev.lrxh.neptune.Neptune;
66
import dev.lrxh.neptune.feature.queue.QueueService;
77
import dev.lrxh.neptune.profile.impl.Profile;
8+
import dev.lrxh.neptune.utils.CC;
89
import org.bukkit.entity.Player;
910

1011
import java.util.UUID;
@@ -29,7 +30,13 @@ public static ProfileService get() {
2930

3031
public CompletableFuture<Void> createProfile(Player player) {
3132
return Profile.create(player.getName(), player.getUniqueId(), plugin, false)
32-
.thenAccept(profile -> profiles.put(player.getUniqueId(), profile));
33+
.thenAccept(profile -> profiles.put(player.getUniqueId(), profile))
34+
.whenComplete((result, throwable) -> {
35+
if (throwable != null) {
36+
Neptune.get().getLogger().severe("Error occurred while loading profile for player: " + player.getName());
37+
player.kick(CC.color("<aqua>[Neptune] <dark_red>An error occurred while loading your profile information! Report to the developers."));
38+
}
39+
});
3340
}
3441

3542
public CompletableFuture<Profile> createFakeProfile(UUID uuid) {

0 commit comments

Comments
 (0)