Skip to content

Commit

Permalink
move area save to world unload
Browse files Browse the repository at this point in the history
  • Loading branch information
NonSwag committed Apr 11, 2024
1 parent 73c8270 commit dfcb194
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "net.thenextlvl.protect"
version = "2.0.2-pre11"
version = "2.0.3"

java {
withSourcesJar()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ private void registerCommands() {
}
}

@Override
public void onDisable() {
areaProvider().saveAreas();
}

public class Flags {
public final Flag<@NotNull Boolean> areaEnter = flagRegistry().register(ProtectPlugin.this, Boolean.class, "enter", true);
public final Flag<@NotNull Boolean> areaLeave = flagRegistry().register(ProtectPlugin.this, Boolean.class, "leave", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@ public FileIO<Area> loadFile(World world, @Nullable Area area, IO file) {
}

@ApiStatus.Internal
public void saveAreas() {
areas.values().stream()
.flatMap(Set::stream)
.forEach(FileIO::save);
public void saveAreas(World world) {
areas.get(world).forEach(FileIO::save);
}

@ApiStatus.Internal
public void unloadAreas(World world) {
areas.remove(world);
}

@ApiStatus.Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;

@RequiredArgsConstructor
public class WorldListener implements Listener {
Expand All @@ -24,6 +25,12 @@ public void onWorldLoad(WorldLoadEvent event) {
plugin.areaProvider().loadAreas(event.getWorld());
}

@EventHandler(priority = EventPriority.NORMAL)
public void onWorldUnload(WorldUnloadEvent event) {
plugin.areaProvider().saveAreas(event.getWorld());
plugin.areaProvider().unloadAreas(event.getWorld());
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
event.setCancelled(!plugin.protectionService().canBreak(
Expand Down

0 comments on commit dfcb194

Please sign in to comment.