Skip to content

fix(deps): update dependency net.thenextlvl.protect:api to v3 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repositories {
}

dependencies {
compileOnly("net.thenextlvl.protect:api:1.0.1")
compileOnly("net.thenextlvl.protect:api:3.0.3")
compileOnly("io.papermc.paper:paper-api:1.21.5-R0.1-SNAPSHOT")
compileOnly("com.intellectualsites.plotsquared:plotsquared-core")
compileOnly("com.sk89q.worldedit:worldedit-core:7.3.0-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.thenextlvl.redprotect.listener;

import net.thenextlvl.protect.area.Area;
import net.thenextlvl.protect.area.AreaProvider;
import net.thenextlvl.redprotect.RedProtect;
import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand All @@ -12,16 +13,20 @@
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.WeakHashMap;

public class AreaRedstoneListener implements Listener {
private static final HashMap<Area, Integer> AREA_STATES = new HashMap<>();
private static final Map<Area, Integer> AREA_STATES = new WeakHashMap<>();
private static final List<Area> BLOCKED_AREAS = new ArrayList<>();
private final AreaProvider areaProvider;

private final JavaPlugin plugin;

public AreaRedstoneListener(JavaPlugin plugin) {
this.areaProvider = Objects.requireNonNull(plugin.getServer().getServicesManager().load(AreaProvider.class));
this.plugin = plugin;
}

Expand All @@ -31,8 +36,8 @@ public void onRedstone(BlockRedstoneEvent event) {
var location = event.getBlock().getLocation();
var area = area(location);
if (area == null) return;
long time = RedProtect.config().clockDisableTime();
long updates = RedProtect.config().updatesPerState();
var time = RedProtect.config.clockDisableTime();
var updates = RedProtect.config.updatesPerState();
Bukkit.getScheduler().runTaskLater(plugin, () -> decreaseState(area), time);
if (increaseState(area) < updates) return;
event.setNewCurrent(0);
Expand All @@ -42,25 +47,25 @@ public void onRedstone(BlockRedstoneEvent event) {
Bukkit.getScheduler().runTaskLater(plugin, () -> BLOCKED_AREAS.remove(area), time);
}

public static int increaseState(Area area) {
public int increaseState(Area area) {
return setState(area, getState(area) + 1);
}

public static void decreaseState(Area area) {
public void decreaseState(Area area) {
setState(area, getState(area) - 1);
}

public static int setState(Area area, int state) {
public int setState(Area area, int state) {
if (state <= 0) AREA_STATES.remove(area);
else AREA_STATES.put(area, state);
return getState(area);
}

public static int getState(Area area) {
public int getState(Area area) {
return AREA_STATES.getOrDefault(area, 0);
}

private static @Nullable Area area(Location location) {
return location.getWorld() != null ? Area.highestArea(location) : null;
private @Nullable Area area(Location location) {
return location.getWorld() != null ? areaProvider.getArea(location) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public void onRedstone(BlockRedstoneEvent event) {
var location = event.getBlock().getLocation();
var plot = plot(location);
if (plot == null) return;
var time = RedProtect.config().clockDisableTime();
var updates = RedProtect.config().updatesPerState();
var time = RedProtect.config.clockDisableTime();
var updates = RedProtect.config.updatesPerState();
Bukkit.getScheduler().runTaskLater(plugin, () -> decreaseState(plot), time);
if (increaseState(plot) < updates) return;
event.setNewCurrent(0);
Expand Down
Loading