Skip to content

GH-226 Add Lands support. #226

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ repositories {
maven("https://maven.enginehub.org/repo/")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://repo.codemc.io/repository/maven-releases/")
maven("https://jitpack.io/")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.eternalcode.combat.region;

import org.bukkit.World;

public record Point(World world, double x, double z) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public interface Region {

Location getCenter();
Point getCenter();

Location getMin();

Expand Down
21 changes: 9 additions & 12 deletions eternalcombat-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ dependencies {

// PlaceholderAPI
compileOnly("me.clip:placeholderapi:${Versions.PLACEHOLDER_API}")

// Lands
compileOnly("com.github.angeschossen:LandsAPI:7.15.4")

// Multification
implementation("com.eternalcode:multification-bukkit:${Versions.MULTIFICATION}")
implementation("com.eternalcode:multification-okaeri:${Versions.MULTIFICATION}")
implementation("com.github.retrooper:packetevents-spigot:${Versions.PACKETS_EVENTS}")
compileOnly("com.github.retrooper:packetevents-spigot:${Versions.PACKETS_EVENTS}")
implementation("io.papermc:paperlib:${Versions.PAPERLIB}")
}

Expand All @@ -61,21 +64,18 @@ bukkit {
name = "EternalCombat"
load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD
softDepend = listOf(
"WorldGuard",
"PlaceholderAPI",
"ProtocolLib",
"ProtocolSupport",
"ViaVersion",
"ViaBackwards",
"ViaRewind",
"Geyser-Spigot"
"Lands"
)
depend = listOf(
"packetevents",
)
version = "${project.version}"
}

tasks {
runServer {
minecraftVersion("1.21.4")
downloadPlugins.url("https://github.com/retrooper/packetevents/releases/download/v2.8.0/packetevents-spigot-2.8.0.jar")
}
}

Expand Down Expand Up @@ -108,7 +108,4 @@ tasks.shadowJar {
).forEach { pack ->
relocate(pack, "$prefix.$pack")
}

relocate("com.github.retrooper.packetevents", "$prefix.packetevents.api")
relocate("io.github.retrooper.packetevents", "$prefix.packetevents.impl")
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@
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 All @@ -79,24 +77,14 @@ public final class CombatPlugin extends JavaPlugin implements EternalCombatApi {
private FightTagOutService fightTagOutService;
private FightEffectService fightEffectService;

private LogoutService logoutService;

private DropService dropService;
private DropKeepInventoryService dropKeepInventoryService;

private RegionProvider regionProvider;

private PluginConfig pluginConfig;

private AudienceProvider audienceProvider;
private LiteCommands<CommandSender> liteCommands;

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

@Override
public void onEnable() {
Expand All @@ -110,15 +98,15 @@ public void onEnable() {
EventManager eventManager = new EventManager(this);
Scheduler scheduler = new BukkitSchedulerImpl(this);

PacketEvents.getAPI().init();

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

this.fightManager = new FightManagerImpl(eventManager);
this.fightPearlService = new FightPearlServiceImpl(this.pluginConfig.pearl);
this.fightPearlService = new FightPearlServiceImpl(pluginConfig.pearl);
this.fightTagOutService = new FightTagOutServiceImpl();
this.fightEffectService = new FightEffectServiceImpl();
this.logoutService = new LogoutService();

LogoutService logoutService = new LogoutService();

this.dropService = new DropServiceImpl();
this.dropKeepInventoryService = new DropKeepInventoryServiceImpl();

Expand All @@ -130,24 +118,31 @@ public void onEnable() {
.preProcessor(new AdventureLegacyColorPreProcessor())
.build();

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, eventManager, pluginConfig.border);
KnockbackService knockbackService = new KnockbackService(this.pluginConfig, scheduler);
NoticeService noticeService = new NoticeService(this.audienceProvider, pluginConfig, miniMessage);

BridgeService bridgeService = new BridgeService(
pluginConfig,
server.getPluginManager(),
this.getLogger(),
this,
this.fightManager
);
bridgeService.init(server);

NoticeService noticeService = new NoticeService(this.audienceProvider, this.pluginConfig, miniMessage);
this.regionProvider = bridgeService.getRegionProvider();
BorderService borderService = new BorderServiceImpl(scheduler, server, regionProvider, eventManager, () -> pluginConfig.border);
KnockbackService knockbackService = new KnockbackService(pluginConfig, scheduler, regionProvider);

this.liteCommands = LiteBukkitFactory.builder(FALLBACK_PREFIX, this, server)
.message(LiteBukkitMessages.PLAYER_NOT_FOUND, this.pluginConfig.messagesSettings.playerNotFound)
.message(LiteBukkitMessages.PLAYER_ONLY, this.pluginConfig.messagesSettings.admin.onlyForPlayers)
.message(LiteBukkitMessages.PLAYER_NOT_FOUND, pluginConfig.messagesSettings.playerNotFound)
.message(LiteBukkitMessages.PLAYER_ONLY, pluginConfig.messagesSettings.admin.onlyForPlayers)

.invalidUsage(new InvalidUsageHandlerImpl(this.pluginConfig, noticeService))
.missingPermission(new MissingPermissionHandlerImpl(this.pluginConfig, noticeService))
.invalidUsage(new InvalidUsageHandlerImpl(pluginConfig, noticeService))
.missingPermission(new MissingPermissionHandlerImpl(pluginConfig, noticeService))

.commands(
new FightTagCommand(this.fightManager, noticeService, this.pluginConfig),
new FightTagOutCommand(this.fightTagOutService, noticeService, this.pluginConfig),
new FightTagCommand(this.fightManager, noticeService, pluginConfig),
new FightTagOutCommand(this.fightTagOutService, noticeService, pluginConfig),
new EternalCombatReloadCommand(configService, noticeService)
)

Expand All @@ -158,41 +153,41 @@ public void onEnable() {

.build();

FightTask fightTask = new FightTask(server, this.pluginConfig, this.fightManager, noticeService);
FightTask fightTask = new FightTask(server, pluginConfig, this.fightManager, noticeService);
this.getServer().getScheduler().runTaskTimer(this, fightTask, 20L, 20L);

new Metrics(this, BSTATS_METRICS_ID);

Stream.of(
new PercentDropModifier(this.pluginConfig.drop),
new PlayersHealthDropModifier(this.pluginConfig.drop, this.logoutService)
new PercentDropModifier(pluginConfig.drop),
new PlayersHealthDropModifier(pluginConfig.drop, logoutService)
).forEach(this.dropService::registerModifier);

eventManager.subscribe(
new FightTagController(this.fightManager, this.pluginConfig),
new FightUnTagController(this.fightManager, this.pluginConfig, this.logoutService),
new FightActionBlockerController(this.fightManager, noticeService, this.pluginConfig, server),
new FightPearlController(this.pluginConfig.pearl, noticeService, this.fightManager, this.fightPearlService),
new UpdaterNotificationController(updaterService, this.pluginConfig, this.audienceProvider, miniMessage),
new FightTagController(this.fightManager, pluginConfig),
new FightUnTagController(this.fightManager, pluginConfig, logoutService),
new FightActionBlockerController(this.fightManager, noticeService, pluginConfig, server),
new FightPearlController(pluginConfig.pearl, noticeService, this.fightManager, this.fightPearlService),
new UpdaterNotificationController(updaterService, pluginConfig, this.audienceProvider, miniMessage),
new KnockbackRegionController(noticeService, this.regionProvider, this.fightManager, knockbackService, server),
new FightEffectController(this.pluginConfig.effect, this.fightEffectService, this.fightManager, this.getServer()),
new FightEffectController(pluginConfig.effect, this.fightEffectService, this.fightManager, this.getServer()),
new FightTagOutController(this.fightTagOutService),
new FightMessageController(this.fightManager, noticeService, this.pluginConfig, this.getServer()),
new BorderTriggerController(borderService, pluginConfig.border, fightManager, server),
new ParticleController(borderService, pluginConfig.border.particle, scheduler, server),
new BorderBlockController(borderService, pluginConfig.border.block, scheduler, server)
new FightMessageController(this.fightManager, noticeService, pluginConfig, this.getServer()),
new BorderTriggerController(borderService, () -> pluginConfig.border, fightManager, server),
new ParticleController(borderService, () -> pluginConfig.border.particle, scheduler, server),
new BorderBlockController(borderService, () -> pluginConfig.border.block, scheduler, server)
);

eventManager.subscribe(
PlayerDeathEvent.class,
this.pluginConfig.drop.dropEventPriority,
pluginConfig.drop.dropEventPriority,
new DropController(dropService, dropKeepInventoryService, pluginConfig.drop, fightManager)
);

eventManager.subscribe(
PlayerQuitEvent.class,
this.pluginConfig.combat.quitPunishmentEventPriority,
new LogoutController(this.fightManager, this.logoutService, noticeService, this.pluginConfig)
pluginConfig.combat.quitPunishmentEventPriority,
new LogoutController(this.fightManager, logoutService, noticeService, pluginConfig)
);

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

this.fightManager.untagAll();

PacketEvents.getAPI().terminate();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.function.Supplier;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
Expand All @@ -21,12 +22,12 @@ public class BorderServiceImpl implements BorderService {
private final Scheduler scheduler;
private final EventManager eventManager;

private final BorderSettings settings;
private final Supplier<BorderSettings> settings;

private final BorderTriggerIndex borderIndexes;
private final BorderActivePointsIndex activeBorderIndex = new BorderActivePointsIndex();

public BorderServiceImpl(Scheduler scheduler, Server server, RegionProvider provider, EventManager eventManager, BorderSettings settings) {
public BorderServiceImpl(Scheduler scheduler, Server server, RegionProvider provider, EventManager eventManager, Supplier<BorderSettings> settings) {
this.scheduler = scheduler;
this.eventManager = eventManager;
this.settings = settings;
Expand Down Expand Up @@ -106,12 +107,13 @@ private List<BorderPoint> resolveBorderPoints(BorderTrigger trigger, Location pl
int y = (int) Math.round(playerLocation.getY());
int z = (int) Math.round(playerLocation.getZ());

int realMinX = Math.max(borderMin.x(), x - settings.distanceRounded());
int realMaxX = Math.min(borderMax.x(), x + settings.distanceRounded());
int realMinY = Math.max(borderMin.y(), y - settings.distanceRounded());
int realMaxY = Math.min(borderMax.y(), y + settings.distanceRounded());
int realMinZ = Math.max(borderMin.z(), z - settings.distanceRounded());
int realMaxZ = Math.min(borderMax.z(), z + settings.distanceRounded());
int distanceRounded = settings.get().distanceRounded();
int realMinX = Math.max(borderMin.x(), x - distanceRounded);
int realMaxX = Math.min(borderMax.x(), x + distanceRounded);
int realMinY = Math.max(borderMin.y(), y - distanceRounded);
int realMaxY = Math.min(borderMax.y(), y + distanceRounded);
int realMinZ = Math.max(borderMin.z(), z - distanceRounded);
int realMaxZ = Math.min(borderMax.z(), z + distanceRounded);

List<BorderPoint> points = new ArrayList<>();

Expand Down Expand Up @@ -176,7 +178,7 @@ private void addPoint(List<BorderPoint> points, int x, int y, int z, Location pl
}

private boolean isVisible(int x, int y, int z, Location player) {
return Math.sqrt(Math.pow(x - player.getX(), 2) + Math.pow(y - player.getY(), 2) + Math.pow(z - player.getZ(), 2)) <= this.settings.distance;
return Math.sqrt(Math.pow(x - player.getX(), 2) + Math.pow(y - player.getY(), 2) + Math.pow(z - player.getZ(), 2)) <= this.settings.get().distance;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.Comment;
import java.time.Duration;
import org.jetbrains.annotations.ApiStatus;

public class BorderSettings extends OkaeriConfig {

Expand All @@ -25,6 +26,7 @@ public class BorderSettings extends OkaeriConfig {
})
public ParticleSettings particle = new ParticleSettings();

@ApiStatus.Internal
public Duration indexRefreshDelay() {
return Duration.ofSeconds(1);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.eternalcode.combat.border;

import com.eternalcode.combat.fight.FightManager;
import com.eternalcode.combat.fight.event.FightTagEvent;
import com.eternalcode.combat.fight.event.FightUntagEvent;
import java.util.function.Supplier;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.entity.Player;
Expand All @@ -14,11 +16,11 @@
public class BorderTriggerController implements Listener {

private final BorderService borderService;
private final BorderSettings border;
private final Supplier<BorderSettings> border;
private final FightManager fightManager;
private final Server server;

public BorderTriggerController(BorderService borderService, BorderSettings border, FightManager fightManager, Server server) {
public BorderTriggerController(BorderService borderService, Supplier<BorderSettings> border, FightManager fightManager, Server server) {
this.borderService = borderService;
this.border = border;
this.fightManager = fightManager;
Expand All @@ -27,7 +29,7 @@ public BorderTriggerController(BorderService borderService, BorderSettings borde

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
void onMove(PlayerMoveEvent event) {
if (!border.isEnabled()) {
if (!border.get().isEnabled()) {
return;
}

Expand All @@ -47,7 +49,7 @@ void onMove(PlayerMoveEvent event) {

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
void onTeleport(PlayerTeleportEvent event) {
if (!border.isEnabled()) {
if (!border.get().isEnabled()) {
return;
}

Expand All @@ -59,9 +61,23 @@ void onTeleport(PlayerTeleportEvent event) {
borderService.updateBorder(player, event.getTo());
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
void onFightStart(FightTagEvent event) {
if (!border.get().isEnabled()) {
return;
}

Player player = server.getPlayer(event.getPlayer());
if (player == null) {
return;
}

borderService.updateBorder(player, player.getLocation());
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
void onFightEnd(FightUntagEvent event) {
if (!border.isEnabled()) {
if (!border.get().isEnabled()) {
return;
}

Expand Down
Loading
Loading