Skip to content

Commit

Permalink
feat: improve failed world warning
Browse files Browse the repository at this point in the history
Failed worlds will now show a warning message at the end after adding arenas.
  • Loading branch information
HappyAreaBean committed Jan 27, 2023
1 parent 1dd61c0 commit d755b21
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/java/cc/happyareabean/swmhook/SWMHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void onDisable() {

public void addToArena() {
worldsList.getWorlds().forEach(w -> arenaProviderManager.getProvider().addArena(w));
arenaProviderManager.checkFailedWorld();
}

public void loadAllSWMHWorld() {
Expand Down Expand Up @@ -194,6 +195,10 @@ public static void prefixedLog(String message) {
Bukkit.getConsoleSender().sendMessage(Color.translate(Constants.PREFIX + message));
}

public static void prefixedLog() {
Bukkit.getConsoleSender().sendMessage(Color.translate(Constants.PREFIX));
}

public static void log(String message) {
Bukkit.getConsoleSender().sendMessage(Color.translate("&c[SWMHook] " + message));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public String getProviderName() {
return null;
}

public String getProviderFileName() {
return null;
}

public void log(String message) {
SWMHook.log(String.format("[%s] %s", getProviderName(), message));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class ArenaProviderManager {

@Getter
private ArenaProvider provider;
@Getter
private List<SWMHWorld> loadFailed = new ArrayList<>();

public ArenaProviderManager() {
PluginManager pm = Bukkit.getPluginManager();
Expand All @@ -32,4 +39,27 @@ public static void errorWhenAdding(ArenaProvider provider, SWMHWorld world, Stri
SWMHook.log(String.format("Error when adding arena from template world %s to provider %s: %s",
world.getTemplateName(), provider.getProviderName(), message));
}

public void addFailedWorld(SWMHWorld world) {
loadFailed.add(world);
}

public void checkFailedWorld() {
if (loadFailed.size() == 0)
return;

Arrays.asList(
"",
String.format("&cThe following %s SWMHWorld failed to add as an arena in arena provider %s:", loadFailed.size(), getProviderName()),
loadFailed.stream().map(w -> " &c- " + w.getTemplateName()).collect(Collectors.joining("\n")),
"",
"&cPlease make sure that SWMHWorld is configured properly:",
String.format(" &c- The SWMHWorld template world is an arena in your provider %s.", getProviderName()),
String.format(" &c- Make sure your template world names are the same in the %s's %s.", getProviderName(), provider.getProviderFileName()),
" &c- The arena setup is complete.",
""
).forEach(SWMHook::prefixedLog);

loadFailed.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public void addArena(SWMHWorld world) {
List<Arena> arenas = Arena.getArenas().stream().filter(a -> !a.isEnabled()).collect(Collectors.toList());

if (arenas.stream().noneMatch(a -> a.getName().equalsIgnoreCase(world.getTemplateName()))) {
log(world.getTemplateName(), "No available template in Eden's arenas.yml, please make sure you use template world created a arena first!");
log(world.getTemplateName(), "Please ALSO remember the arena MUST be disabled in Eden!");
SWMHook.getInstance().getArenaProviderManager().addFailedWorld(world);
return;
}

Expand Down Expand Up @@ -79,6 +78,11 @@ public String getProviderName() {
return "Eden";
}

@Override
public String getProviderFileName() {
return "arenas.yml";
}

private ArenaDetail newArenaDetail(Arena arena, String worldName) {
Location a = arena.getA().clone();
Location b = arena.getB().clone();
Expand Down

0 comments on commit d755b21

Please sign in to comment.