Skip to content
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

GH-204 Add Border #204

Open
wants to merge 15 commits into
base: 2.0
Choose a base branch
from
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object Versions {
const val WORLD_GUARD_BUKKIT = "7.0.9"

const val PLACEHOLDER_API = "2.11.6"
const val PAPERLIB = "1.0.8"

}

Expand Down
21 changes: 0 additions & 21 deletions buildSrc/src/main/kotlin/eternalcombat-java.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
`java-library`
checkstyle
}

group = "com.eternalcode"
Expand All @@ -11,26 +10,6 @@ java {
targetCompatibility = JavaVersion.VERSION_17
}

checkstyle {
toolVersion = "10.17.0"

configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")

maxErrors = 0
maxWarnings = 0
}

// https://github.com/JabRef/jabref/pull/10812/files#diff-49a96e7eea8a94af862798a45174e6ac43eb4f8b4bd40759b5da63ba31ec3ef7R267
configurations.named("checkstyle") {
resolutionStrategy {
capabilitiesResolution {
withCapability("com.google.collections:google-collections") {
select("com.google.guava:guava:33.2.1-jre")
}
}
}
}

tasks.compileJava {
options.compilerArgs = listOf("-Xlint:deprecation", "-parameters")
options.encoding = "UTF-8"
Expand Down
15 changes: 8 additions & 7 deletions buildSrc/src/main/kotlin/eternalcombat-repositories.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ plugins {
repositories {
mavenCentral()

maven { url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") }
maven { url = uri("https://papermc.io/repo/repository/maven-public/") }
maven { url = uri("https://repo.eternalcode.pl/releases") }
maven { url = uri("https://storehouse.okaeri.eu/repository/maven-public/") }
maven { url = uri("https://repo.panda-lang.org/releases") }
maven { url = uri("https://maven.enginehub.org/repo/") }
maven { url = uri("https://repo.extendedclip.com/content/repositories/placeholderapi/")}
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://repo.eternalcode.pl/releases")
maven("https://storehouse.okaeri.eu/repository/maven-public/")
maven("https://repo.panda-lang.org/releases")
maven("https://maven.enginehub.org/repo/")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://repo.codemc.io/repository/maven-releases/")
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,20 @@ public interface Region {

Location getCenter();

Location getMin();

Location getMax();

default boolean contains(Location location) {
return this.contains(location.getX(), location.getY(), location.getZ());
}

default boolean contains(double x, double y, double z) {
Location min = this.getMin();
Location max = this.getMax();
return x >= min.getX() && x < max.getX()
&& y >= min.getY() && y < max.getY()
&& z >= min.getZ() && z < max.getZ();
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.eternalcode.combat.region;

import java.util.Collection;
import java.util.Optional;
import org.bukkit.Location;
import org.bukkit.World;

public interface RegionProvider {

Expand All @@ -11,4 +13,6 @@ default boolean isInRegion(Location location) {
return this.getRegion(location).isPresent();
}

Collection<Region> getRegions(World world);

}
6 changes: 3 additions & 3 deletions eternalcombat-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ dependencies {
// Multification
implementation("com.eternalcode:multification-bukkit:${Versions.MULTIFICATION}")
implementation("com.eternalcode:multification-okaeri:${Versions.MULTIFICATION}")
implementation("com.github.retrooper:packetevents-spigot:2.7.0")
implementation("io.papermc:paperlib:${Versions.PAPERLIB}")
}

bukkit {
Expand All @@ -68,15 +70,13 @@ bukkit {

tasks {
runServer {
minecraftVersion("1.21.1")
minecraftVersion("1.21.4")
}
}

tasks.shadowJar {
archiveFileName.set("EternalCombat v${project.version}.jar")

dependsOn("checkstyleMain")
dependsOn("checkstyleTest")
dependsOn("test")

exclude(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.eternalcode.combat;

import com.eternalcode.combat.border.BorderTriggerController;
import com.eternalcode.combat.border.BorderService;
import com.eternalcode.combat.border.BorderServiceImpl;
import com.eternalcode.combat.border.particle.BorderBlockController;
import com.eternalcode.combat.border.particle.BorderParticleController;
import com.eternalcode.combat.bridge.BridgeService;
import com.eternalcode.combat.fight.drop.DropKeepInventoryService;
import com.eternalcode.combat.fight.FightManager;
import com.eternalcode.combat.fight.drop.DropService;
import com.eternalcode.combat.fight.effect.FightEffectService;
import com.eternalcode.combat.fight.knockback.KnockbackService;
import com.eternalcode.combat.fight.tagout.FightTagOutService;
import com.eternalcode.combat.fight.pearl.FightPearlService;
import com.eternalcode.combat.handler.InvalidUsageHandlerImpl;
Expand Down Expand Up @@ -34,17 +40,21 @@
import com.eternalcode.combat.fight.tagout.FightTagOutServiceImpl;
import com.eternalcode.combat.fight.tagout.FightTagOutCommand;
import com.eternalcode.combat.notification.NotificationAnnouncer;
import com.eternalcode.combat.region.RegionController;
import com.eternalcode.combat.fight.knockback.KnockbackRegionController;
import com.eternalcode.combat.region.RegionProvider;
import com.eternalcode.combat.updater.UpdaterNotificationController;
import com.eternalcode.combat.updater.UpdaterService;
import com.eternalcode.commons.adventure.AdventureLegacyColorPostProcessor;
import com.eternalcode.commons.adventure.AdventureLegacyColorPreProcessor;
import com.eternalcode.commons.bukkit.scheduler.BukkitSchedulerImpl;
import com.eternalcode.commons.scheduler.Scheduler;
import com.eternalcode.multification.notice.Notice;
import com.github.retrooper.packetevents.PacketEvents;
import com.google.common.base.Stopwatch;
import dev.rollczi.litecommands.LiteCommands;
import dev.rollczi.litecommands.bukkit.LiteBukkitFactory;
import dev.rollczi.litecommands.bukkit.LiteBukkitMessages;
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
import net.kyori.adventure.platform.AudienceProvider;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.minimessage.MiniMessage;
Expand Down Expand Up @@ -79,6 +89,12 @@ public final class CombatPlugin extends JavaPlugin implements EternalCombatApi {
private AudienceProvider audienceProvider;
private LiteCommands<CommandSender> liteCommands;

@Override
public void onLoad() {
PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
PacketEvents.getAPI().load();
}

@Override
public void onEnable() {
Stopwatch started = Stopwatch.createStarted();
Expand All @@ -89,6 +105,7 @@ public void onEnable() {
ConfigService configService = new ConfigService();

EventCaller eventCaller = new EventCaller(server);
Scheduler scheduler = new BukkitSchedulerImpl(this);

this.pluginConfig = configService.create(PluginConfig.class, new File(dataFolder, "config.yml"));

Expand All @@ -111,7 +128,8 @@ public void onEnable() {
BridgeService bridgeService = new BridgeService(this.pluginConfig, server.getPluginManager(), this.getLogger(), this);
bridgeService.init(this.fightManager, server);
this.regionProvider = bridgeService.getRegionProvider();

BorderService borderService = new BorderServiceImpl(scheduler, server, regionProvider, eventCaller, () -> 6.5);
KnockbackService knockbackService = new KnockbackService(this.pluginConfig, scheduler);

NotificationAnnouncer notificationAnnouncer = new NotificationAnnouncer(this.audienceProvider, this.pluginConfig, miniMessage);

Expand Down Expand Up @@ -154,10 +172,13 @@ public void onEnable() {
new FightActionBlockerController(this.fightManager, notificationAnnouncer, this.pluginConfig),
new FightPearlController(this.pluginConfig.pearl, notificationAnnouncer, this.fightManager, this.fightPearlService),
new UpdaterNotificationController(updaterService, this.pluginConfig, this.audienceProvider, miniMessage),
new RegionController(notificationAnnouncer, this.regionProvider, this.fightManager, this.pluginConfig),
new KnockbackRegionController(notificationAnnouncer, this.regionProvider, this.fightManager, this.pluginConfig, knockbackService, server),
new FightEffectController(this.pluginConfig.effect, this.fightEffectService, this.fightManager, this.getServer()),
new FightTagOutController(this.fightTagOutService),
new FightMessageController(this.fightManager, notificationAnnouncer, this.pluginConfig, this.getServer())
new FightMessageController(this.fightManager, notificationAnnouncer, this.pluginConfig, this.getServer()),
new BorderTriggerController(borderService, fightManager, server),
new BorderParticleController(borderService, scheduler, server),
new BorderBlockController(borderService, scheduler, server)
).forEach(listener -> this.getServer().getPluginManager().registerEvents(listener, this));

EternalCombatProvider.initialize(this);
Expand All @@ -179,6 +200,8 @@ public void onDisable() {
}

this.fightManager.untagAll();

PacketEvents.getAPI().terminate();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.eternalcode.combat.border;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

class BorderActivePointsIndex {

private final Map<String, Map<UUID, Set<BorderPoint>>> registry = new ConcurrentHashMap<>();

boolean hasPoints(String world, UUID player) {
Map<UUID, Set<BorderPoint>> worldRegistry = this.registry.get(world);
if (worldRegistry == null) {
return false;
}

return worldRegistry.containsKey(player);
}

Set<BorderPoint> putPoints(String world, UUID player, Set<BorderPoint> points) {
Map<UUID, Set<BorderPoint>> worldRegistry = this.registry.computeIfAbsent(world, k -> new ConcurrentHashMap<>());
Set<BorderPoint> oldPoints = worldRegistry.put(player, points);
if (oldPoints != null) {
return calculateRemovedPoints(points, oldPoints);
}

return Set.of();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't Collections#emptySet better?

}

private static Set<BorderPoint> calculateRemovedPoints(Set<BorderPoint> points, Set<BorderPoint> oldPoints) {
Set<BorderPoint> removed = new HashSet<>();
for (BorderPoint oldPoint : oldPoints) {
if (!points.contains(oldPoint)) {
removed.add(oldPoint);
}
}
return removed;
}

Set<BorderPoint> getPoints(String world, UUID player) {
Map<UUID, Set<BorderPoint>> worldRegistry = this.registry.get(world);
if (worldRegistry == null) {
return Set.of();
}

return worldRegistry.getOrDefault(player, Set.of());
}

Set<BorderPoint> removePoints(String world, UUID player) {
Map<UUID, Set<BorderPoint>> worldRegistry = this.registry.get(world);
if (worldRegistry == null) {
return Set.of();
}

Set<BorderPoint> remove = worldRegistry.remove(player);
if (remove == null) {
return Set.of();
}

return remove;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.eternalcode.combat.border;

import org.jetbrains.annotations.Nullable;

public record BorderPoint(int x, int y, int z, @Nullable BorderPoint inclusive) {

public BorderPoint(int x, int y, int z) {
this(x, y, z, null);
}

public BorderPoint toInclusive() {
if (inclusive == null) {
return this;
}

return inclusive;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.eternalcode.combat.border;

import java.util.Set;

public interface BorderResult {

Set<BorderPoint> collect();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.eternalcode.combat.border;

import java.util.Set;
import org.bukkit.Location;
import org.bukkit.entity.Player;

public interface BorderService {

void updateBorder(Player player, Location to);

void clearBorder(Player player);

Set<BorderPoint> getActiveBorder(Player player);

}
Loading
Loading