Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ef9a17b
- Added Event priority to config.
MassiveLag Apr 29, 2025
bffd3d6
- Some modifications
MassiveLag Apr 29, 2025
b5c9943
Update eternalcombat-plugin/src/main/java/com/eternalcode/combat/figh…
MassiveLag Apr 29, 2025
581dcbd
Update eternalcombat-plugin/src/main/java/com/eternalcode/combat/figh…
MassiveLag Apr 29, 2025
0756657
Update eternalcombat-plugin/src/main/java/com/eternalcode/combat/figh…
MassiveLag Apr 29, 2025
59e908a
Update eternalcombat-plugin/src/main/java/com/eternalcode/combat/figh…
MassiveLag Apr 29, 2025
60ee88a
Update eternalcombat-plugin/src/main/java/com/eternalcode/combat/figh…
MassiveLag Apr 29, 2025
4bdc3b8
Update eternalcombat-plugin/src/main/java/com/eternalcode/combat/figh…
MassiveLag Apr 29, 2025
0d143c1
- Added whitelist reasons for punishments
MassiveLag Apr 29, 2025
01cad15
- Added whitelist reasons for punishments
MassiveLag Apr 29, 2025
aaa2349
- Fixed description in CombatSettings
MassiveLag Apr 29, 2025
4b97b93
- Made untag command also executeable via console
MassiveLag Apr 29, 2025
21f0f9f
- Better way of untagging all players.
MassiveLag Apr 29, 2025
35ae5fa
- Needs testing - head drops #214
MassiveLag Apr 29, 2025
40a6a2c
- Added bypass checks for combat
MassiveLag May 5, 2025
8c4f09a
- Changed the way how bypass is being detected. Using function FightT…
MassiveLag May 8, 2025
2382aa7
- Disabling elytra when get tagged when you are moving. Currently the…
MassiveLag May 8, 2025
8cdea75
Remove event declaration duplications by DynamicListener and EventMan…
Rollczi May 11, 2025
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 @@ -28,7 +28,7 @@
import com.eternalcode.combat.fight.controller.FightTagController;
import com.eternalcode.combat.fight.controller.FightUnTagController;
import com.eternalcode.combat.fight.effect.FightEffectController;
import com.eternalcode.combat.event.EventCaller;
import com.eternalcode.combat.event.EventManager;
import com.eternalcode.combat.fight.FightManagerImpl;
import com.eternalcode.combat.fight.FightTask;
import com.eternalcode.combat.fight.effect.FightEffectServiceImpl;
Expand Down Expand Up @@ -61,6 +61,8 @@
import org.bstats.bukkit.Metrics;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
Expand Down Expand Up @@ -105,14 +107,14 @@ public void onEnable() {

ConfigService configService = new ConfigService();

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

PacketEvents.getAPI().init();

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

this.fightManager = new FightManagerImpl(eventCaller);
this.fightManager = new FightManagerImpl(eventManager);
this.fightPearlService = new FightPearlServiceImpl(this.pluginConfig.pearl);
this.fightTagOutService = new FightTagOutServiceImpl();
this.fightEffectService = new FightEffectServiceImpl();
Expand All @@ -131,7 +133,7 @@ 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, pluginConfig.border);
BorderService borderService = new BorderServiceImpl(scheduler, server, regionProvider, eventManager, pluginConfig.border);
KnockbackService knockbackService = new KnockbackService(this.pluginConfig, scheduler);

NoticeService noticeService = new NoticeService(this.audienceProvider, this.pluginConfig, miniMessage);
Expand Down Expand Up @@ -166,11 +168,8 @@ public void onEnable() {
new PlayersHealthDropModifier(this.pluginConfig.drop, this.logoutService)
).forEach(this.dropService::registerModifier);


Stream.of(
new DropController(this.dropService, this.dropKeepInventoryService, this.pluginConfig.drop, this.fightManager),
eventManager.subscribe(
new FightTagController(this.fightManager, this.pluginConfig),
new LogoutController(this.fightManager, this.logoutService, noticeService, 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),
Expand All @@ -182,7 +181,19 @@ public void onEnable() {
new BorderTriggerController(borderService, pluginConfig.border, fightManager, server),
new ParticleController(borderService, pluginConfig.border.particle, scheduler, server),
new BorderBlockController(borderService, pluginConfig.border.block, scheduler, server)
).forEach(listener -> this.getServer().getPluginManager().registerEvents(listener, this));
);

eventManager.subscribe(
PlayerDeathEvent.class,
this.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)
);

EternalCombatProvider.initialize(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.eternalcode.combat.border.event.BorderHideAsyncEvent;
import com.eternalcode.combat.border.event.BorderShowAsyncEvent;
import com.eternalcode.combat.event.EventCaller;
import com.eternalcode.combat.event.EventManager;
import com.eternalcode.combat.region.RegionProvider;
import com.eternalcode.commons.scheduler.Scheduler;
import dev.rollczi.litecommands.shared.Lazy;
Expand All @@ -19,16 +19,16 @@
public class BorderServiceImpl implements BorderService {

private final Scheduler scheduler;
private final EventCaller eventCaller;
private final EventManager eventManager;

private final BorderSettings settings;

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

public BorderServiceImpl(Scheduler scheduler, Server server, RegionProvider provider, EventCaller eventCaller, BorderSettings settings) {
public BorderServiceImpl(Scheduler scheduler, Server server, RegionProvider provider, EventManager eventManager, BorderSettings settings) {
this.scheduler = scheduler;
this.eventCaller = eventCaller;
this.eventManager = eventManager;
this.settings = settings;
this.borderIndexes = BorderTriggerIndex.started(server, scheduler, provider, settings);
}
Expand All @@ -52,14 +52,14 @@ public void updateBorder(Player player, Location location) {
Set<BorderPoint> points = borderResult.collect();

if (!points.isEmpty()) {
BorderShowAsyncEvent event = eventCaller.publishEvent(new BorderShowAsyncEvent(player, points));
BorderShowAsyncEvent event = eventManager.publishEvent(new BorderShowAsyncEvent(player, points));
points = event.getPoints();
}

Set<BorderPoint> removed = this.activeBorderIndex.putPoints(world, player.getUniqueId(), points);

if (!removed.isEmpty()) {
eventCaller.publishEvent(new BorderHideAsyncEvent(player, removed));
eventManager.publishEvent(new BorderHideAsyncEvent(player, removed));
}
});
}
Expand All @@ -72,7 +72,7 @@ public void clearBorder(Player player) {
scheduler.runAsync(() -> {
Set<BorderPoint> removed = this.activeBorderIndex.removePoints(world.getName(), uniqueId);
if (!removed.isEmpty()) {
eventCaller.publishEvent(new BorderHideAsyncEvent(player, removed));
eventManager.publishEvent(new BorderHideAsyncEvent(player, removed));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import eu.okaeri.configs.annotation.Comment;
import java.util.List;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;

Expand Down Expand Up @@ -72,4 +73,23 @@ public class CombatSettings extends OkaeriConfig {
EntityType.ENDER_PEARL,
EntityType.EGG
);

@Comment({
"# The event priority at which quit punishments should be handled.",
"# This determines when the plugin processes combat log punishment during PlayerQuitEvent.",
"# Options: LOWEST, LOW, NORMAL, HIGH, HIGHEST, MONITOR",
"# Tip: Set to LOWEST or LOW if you want quit punishments to happen before most other plugins.",
"# Default: NORMAL"
})
public EventPriority quitPunishmentEventPriority = EventPriority.NORMAL;

@Comment({
"# List of kick reasons where players will NOT be punished for combat logging.",
"# If this list is empty, players are ALWAYS punished when kicked during combat.",
"# If one of the listed phrases is found in the kick reason (case-insensitive),",
"# the player will NOT be punished.",
"# Example: 'Timed out', 'Kicked for inactivity', etc.",
"# To always punish players on kick, set: whitelistedKickReasons: []"
})
public List<String> whitelistedKickReasons = List.of("Kicked for inactivity", "Timed out", "Server is restarting");
Comment thread
MassiveLag marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ public static class AdminMessages extends OkaeriConfig {
public Notice adminUntagPlayer = Notice.chat(
"<gradient:#00ff88:#00b300>✌ <gray>Removed</gray> <white>{PLAYER}</white> <gray>from combat</gray></gradient>");

@Comment({
"# Message displayed to an admin when they remove a player from combat.",
"# The {PLAYER} placeholder is replaced with the player's name."
})
public Notice adminUntagAll = Notice.chat(
"<gradient:#00ff88:#00b300>✌ <gray>Removed</gray> <white>{COUNT}</white> <gray> players from combat</gray></gradient>");

@Comment({
"# Message displayed when an admin attempts to untag a player who is not in combat.",
"# This message informs the admin that the player is not currently in combat."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.eternalcode.combat.event;

import org.bukkit.event.Listener;

public interface DynamicListener<E> extends Listener {

void onEvent(E event);

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.eternalcode.combat.event;

import org.bukkit.event.Event;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;

public class EventManager {

private final Plugin plugin;

public EventManager(Plugin plugin) {
this.plugin = plugin;
}

public <T extends Event> T publishEvent(T event) {
this.plugin.getServer().getPluginManager().callEvent(event);

return event;
}

public void subscribe(Listener... listeners) {
for (Listener listener : listeners) {
plugin.getServer().getPluginManager().registerEvents(listener, plugin);
}
}

public <E extends Event, L extends DynamicListener<E>> void subscribe(Class<E> type, EventPriority priority, L listener) {
plugin.getServer().getPluginManager().registerEvents(listener, plugin);
plugin.getServer().getPluginManager().registerEvent(type, listener, priority, (l, event) -> {
if (type.isInstance(event)) {
listener.onEvent(type.cast(event));
}
}, plugin);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.eternalcode.combat.fight;

import com.eternalcode.combat.event.EventCaller;
import com.eternalcode.combat.event.EventManager;

import com.eternalcode.combat.fight.event.CauseOfTag;
import com.eternalcode.combat.fight.event.CauseOfUnTag;
Expand All @@ -19,10 +19,10 @@
public class FightManagerImpl implements FightManager {

private final Map<UUID, FightTag> fights = new ConcurrentHashMap<>();
private final EventCaller eventCaller;
private final EventManager eventManager;

public FightManagerImpl(EventCaller eventCaller) {
this.eventCaller = eventCaller;
public FightManagerImpl(EventManager eventManager) {
this.eventManager = eventManager;
}

@Override
Expand All @@ -38,7 +38,7 @@ public boolean isInCombat(UUID player) {

@Override
public FightUntagEvent untag(UUID player, CauseOfUnTag causeOfUnTag) {
FightUntagEvent event = this.eventCaller.publishEvent(new FightUntagEvent(player, causeOfUnTag));
FightUntagEvent event = this.eventManager.publishEvent(new FightUntagEvent(player, causeOfUnTag));
if (event.isCancelled()) {
return event;
}
Expand All @@ -55,7 +55,7 @@ public FightTagEvent tag(UUID target, Duration delay, CauseOfTag causeOfTag) {
@ApiStatus.Experimental
@Override
public FightTagEvent tag(UUID target, Duration delay, CauseOfTag causeOfTag, @Nullable UUID tagger) {
FightTagEvent event = this.eventCaller.publishEvent(new FightTagEvent(target, causeOfTag));
FightTagEvent event = this.eventManager.publishEvent(new FightTagEvent(target, causeOfTag));

if (event.isCancelled()) {
return event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
import dev.rollczi.litecommands.annotations.priority.Priority;
import dev.rollczi.litecommands.annotations.priority.PriorityValue;
import java.time.Duration;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -124,7 +127,7 @@ void tagMultiple(@Context CommandSender sender, @Arg Player firstTarget, @Arg Pl

@Execute(name = "untag")
@Permission("eternalcombat.untag")
void untag(@Context Player sender, @Arg Player target) {
void untag(@Context CommandSender sender, @Arg Player target) {
UUID targetUniqueId = target.getUniqueId();

if (!this.fightManager.isInCombat(targetUniqueId)) {
Expand All @@ -149,6 +152,23 @@ void untag(@Context Player sender, @Arg Player target) {
.send();
}

@Execute(name = "untagall")
@Permission("eternalcombat.untagall")
void untagAll(@Context CommandSender sender) {
int combatPlayersSize = this.fightManager.getFights().size();

this.fightManager.getFights().stream()
.map(FightTag::getTaggedPlayer)
.collect(Collectors.toSet())
.forEach(uuid -> this.fightManager.untag(uuid, CauseOfUnTag.COMMAND));

this.noticeService.create()
.notice(this.config.messagesSettings.admin.adminUntagAll)
.placeholder("{COUNT}", String.valueOf(combatPlayersSize))
.viewer(sender)
.send();
}

private void tagoutReasonHandler(CommandSender sender, CancelTagReason cancelReason, MessagesSettings messagesSettings) {
if (cancelReason == CancelTagReason.TAGOUT) {
this.noticeService.create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.bukkit.event.entity.EntityToggleGlideEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;

import java.util.List;
Expand Down Expand Up @@ -109,6 +110,26 @@ void onToggleGlide(EntityToggleGlideEvent event) {
}
}

@EventHandler
void onMoveWhileGliding(PlayerMoveEvent event) {
if (!this.config.combat.disableElytraUsage) {
return;
}

Player player = event.getPlayer();
UUID uniqueId = player.getUniqueId();

if (!this.fightManager.isInCombat(uniqueId)) {
return;
}

if (player.isGliding()) {
player.setGliding(false);
}
}



@EventHandler
void onFly(PlayerToggleFlightEvent event) {
if (!this.config.combat.disableFlying) {
Expand Down
Loading
Loading