Skip to content

Commit

Permalink
1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
BenceX100 committed Dec 17, 2024
1 parent f746c90 commit 3ed5863
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.artillexstudios</groupId>
<artifactId>AxAFKZone</artifactId>
<version>1.4.1</version>
<version>1.4.2</version>
<packaging>jar</packaging>

<name>AxAFKZone</name>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/artillexstudios/axafkzone/AxAFKZone.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.artillexstudios.axafkzone.commands.Commands;
import com.artillexstudios.axafkzone.libraries.Libraries;
import com.artillexstudios.axafkzone.listeners.WandListeners;
import com.artillexstudios.axafkzone.listeners.WorldListeners;
import com.artillexstudios.axafkzone.schedulers.TickZones;
import com.artillexstudios.axafkzone.utils.FileUtils;
import com.artillexstudios.axafkzone.utils.NumberUtils;
Expand Down Expand Up @@ -70,6 +71,7 @@ public void enable() {
FileUtils.loadAll();

getServer().getPluginManager().registerEvents(new WandListeners(), this);
getServer().getPluginManager().registerEvents(new WorldListeners(), this);

if (CONFIG.getBoolean("update-notifier.enabled", true)) new UpdateNotifier(this, 6598);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.artillexstudios.axafkzone.listeners;

import com.artillexstudios.axafkzone.zones.Zone;
import com.artillexstudios.axafkzone.zones.Zones;
import com.artillexstudios.axapi.scheduler.Scheduler;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.jetbrains.annotations.NotNull;

public class WorldListeners implements Listener {

@EventHandler
public void onLoad(@NotNull WorldLoadEvent event) {
Scheduler.get().run(scheduledTask -> {
for (Zone zone : Zones.getZones().values()) {
if (zone.getRegion().getWorld() != null) continue;
zone.reload();
}
});
}

@EventHandler
public void onUnload(@NotNull WorldUnloadEvent event) {
for (Zone zone : Zones.getZones().values()) {
World world = zone.getRegion().getWorld();
if (world != null && world.equals(event.getWorld())) {
zone.getRegion().setWorld(null);
}
}
}
}
13 changes: 10 additions & 3 deletions src/main/java/com/artillexstudios/axafkzone/selection/Region.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
import java.util.Set;

public class Region {
private final Location corner1;
private final Location corner2;
private final Location center;
private final World world;
private World world;
private final Zone zone;

public Region(Location corner1, Location corner2, @NotNull Zone zone) {
Expand All @@ -25,7 +27,8 @@ public Region(Location corner1, Location corner2, @NotNull Zone zone) {
this.center = new Location(corner1.getWorld(), (corner1.getBlockX() + corner2.getBlockX()) / 2D, (corner1.getBlockY() + corner2.getBlockY()) / 2D, (corner1.getBlockZ() + corner2.getBlockZ()) / 2D);
}

public HashSet<Player> getPlayersInZone() {
public Set<Player> getPlayersInZone() {
if (world == null) return Set.of();
final HashSet<Player> players = new HashSet<>();

String permission = zone.getSettings().getString("permission");
Expand Down Expand Up @@ -78,8 +81,12 @@ public Location getCenter() {
return center;
}

@NotNull
@Nullable
public World getWorld() {
return world;
}

public void setWorld(World world) {
this.world = world;
}
}
7 changes: 6 additions & 1 deletion src/main/java/com/artillexstudios/axafkzone/zones/Zone.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public Zone(String name, Config settings) {
this.name = name;
this.settings = settings;
this.msg = new MessageUtils(settings.getBackingDocument(), "prefix", CONFIG.getBackingDocument());
this.region = new Region(Serializers.LOCATION.deserialize(settings.getString("zone.location1")), Serializers.LOCATION.deserialize(settings.getString("zone.location2")), this);
reload();
}

Expand Down Expand Up @@ -159,6 +158,12 @@ public List<Reward> giveRewards(Player player) {
public boolean reload() {
if (!settings.reload()) return false;

this.region = new Region(
Serializers.LOCATION.deserialize(settings.getString("zone.location1")),
Serializers.LOCATION.deserialize(settings.getString("zone.location2")),
this
);

this.rewardSeconds = settings.getInt("reward-time-seconds", 180);
this.rollAmount = settings.getInt("roll-amount", 1);

Expand Down

0 comments on commit 3ed5863

Please sign in to comment.