-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes a Level addon crash on startup.
Level addon crashed at the startup if Visit or Warps addon were not installed. It happened because Level addon main class were implementing Listener interface. To avoid it and fix the crash, I moved migration listener to a separate class. Fixes #2012
- Loading branch information
Showing
3 changed files
with
69 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/world/bentobox/level/listeners/MigrationListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// Created by BONNe | ||
// Copyright - 2022 | ||
// | ||
|
||
|
||
package world.bentobox.level.listeners; | ||
|
||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
|
||
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent; | ||
import world.bentobox.level.Level; | ||
|
||
|
||
/** | ||
* This listener checks when BentoBox is ready and then tries to migrate Levels addon database, if it is required. | ||
*/ | ||
public class MigrationListener implements Listener | ||
{ | ||
public MigrationListener(Level addon) | ||
{ | ||
this.addon = addon; | ||
} | ||
|
||
@EventHandler | ||
public void onBentoBoxReady(BentoBoxReadyEvent e) { | ||
// Perform upgrade check | ||
this.addon.getManager().migrate(); | ||
// Load TopTens | ||
this.addon.getManager().loadTopTens(); | ||
/* | ||
* DEBUG code to generate fake islands and then try to level them all. | ||
Bukkit.getScheduler().runTaskLater(getPlugin(), () -> { | ||
getPlugin().getAddonsManager().getGameModeAddons().stream() | ||
.filter(gm -> !settings.getGameModes().contains(gm.getDescription().getName())) | ||
.forEach(gm -> { | ||
for (int i = 0; i < 1000; i++) { | ||
try { | ||
NewIsland.builder().addon(gm).player(User.getInstance(UUID.randomUUID())).name("default").reason(Reason.CREATE).noPaste().build(); | ||
} catch (IOException e1) { | ||
// TODO Auto-generated catch block | ||
e1.printStackTrace(); | ||
} | ||
} | ||
}); | ||
// Queue all islands DEBUG | ||
getIslands().getIslands().stream().filter(Island::isOwned).forEach(is -> { | ||
this.getManager().calculateLevel(is.getOwner(), is).thenAccept(r -> | ||
log("Result for island calc " + r.getLevel() + " at " + is.getCenter())); | ||
}); | ||
}, 60L);*/ | ||
} | ||
|
||
|
||
private final Level addon; | ||
} |