Skip to content

Commit

Permalink
Made it so chunks get unloaded and loaded for matches
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Feb 2, 2024
1 parent 74d398d commit 2f80e07
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/main/java/me/funky/praxi/arena/Arena.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import me.funky.praxi.arena.impl.StandaloneArena;
import me.funky.praxi.kit.Kit;
import me.funky.praxi.util.LocationUtil;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;

import java.util.ArrayList;
Expand Down Expand Up @@ -146,10 +148,22 @@ public boolean isSetup() {
}

public int getMaxBuildHeight() {
int highest = (int) (spawnA.getY() >= spawnB.getY() ? spawnA.getY() : spawnB.getY());
int highest = (int) (Math.max(spawnA.getY(), spawnB.getY()));
return highest + 5;
}

public void unloadArena(){
for(Chunk chunk : getChunks()) {
chunk.getWorld().unloadChunk(chunk);
}
}

public void loadArena(){
for(Chunk chunk : getChunks()) {
chunk.getWorld().loadChunk(chunk);
}
}

public Location getSpawnA() {
if (spawnA == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Map<Integer, Button> getButtons(Player player) {
Map<Integer, Button> buttons = new HashMap<>();
AtomicInteger i = new AtomicInteger(10);
Kit.getKits().forEach(kit -> {
if (kit.isEnabled()) {
if (kit.isEnabled() && kit.getKitLoadout().getContents() != null) {
buttons.put(i.getAndIncrement(), new KitDisplayButton(kit));
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/funky/praxi/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public Player getOpponent(Player player) {


public void start() {
arena.loadArena();
// Set state
state = MatchState.STARTING_ROUND;

Expand Down Expand Up @@ -229,6 +230,7 @@ public void start() {
}

public void end() {
arena.unloadArena();
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) {
if (!gamePlayer.isDisconnected()) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/me/funky/praxi/profile/ProfileListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import me.funky.praxi.profile.option.OptionsOpenedEvent;
import me.funky.praxi.profile.visibility.VisibilityLogic;
import me.funky.praxi.util.CC;
import org.apache.logging.log4j.core.net.Priority;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
Expand Down Expand Up @@ -117,7 +118,7 @@ public void onAsyncPlayerPreLoginEvent(AsyncPlayerPreLoginEvent event) {
Profile.getProfiles().put(event.getUniqueId(), profile);
}

@EventHandler
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoinEvent(PlayerJoinEvent event) {
event.setJoinMessage(null);
Praxi.getInstance().getEssentials().teleportToSpawn(event.getPlayer());
Expand All @@ -138,7 +139,7 @@ public void run() {
}.runTaskLater(Praxi.getInstance(), 10L);
}

@EventHandler(priority = EventPriority.HIGHEST)
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuitEvent(PlayerQuitEvent event) {
event.setQuitMessage(null);
Profile profile = Profile.getProfiles().get(event.getPlayer().getUniqueId());
Expand Down

0 comments on commit 2f80e07

Please sign in to comment.