Skip to content

Commit 9203309

Browse files
authored
GH-167 start of normalizing developer api (#195)
* GH-167 start of normalizing developer api * Extract all of services to interfaces * Add jetbrains annotatiots. * Fix checkstyle violations * Follow citralflo feedback. * Add CancelTagReason * remove unsed `OTHER` in CancelTagReason.
1 parent 381007a commit 9203309

File tree

79 files changed

+619
-349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+619
-349
lines changed

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ object Versions {
66
const val JUNIT_JUPITER_PARAMS = "5.10.3"
77
const val JUNIT_JUPITER_ENGINE = "5.10.3"
88

9+
const val JETBRAINS_ANNOTATIONS = "24.1.0"
10+
911
const val ETERNALCODE_COMMONS = "1.1.3"
1012
// TODO: Multification.
1113

eternalcombat-api/build.gradle.kts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,5 @@ plugins {
88
dependencies {
99
// Spigot api
1010
compileOnlyApi("org.spigotmc:spigot-api:${Versions.SPIGOT_API}")
11-
12-
// kyori
13-
api("net.kyori:adventure-platform-bukkit:${Versions.ADVENTURE_PLATFORM_BUKKIT}")
14-
api("net.kyori:adventure-text-minimessage:${Versions.ADVENTURE_TEXT_MINIMESSAGE}")
15-
16-
// litecommands
17-
api("dev.rollczi:litecommands-bukkit:${Versions.LITE_COMMANDS}")
18-
19-
// Okaeri configs
20-
api("eu.okaeri:okaeri-configs-yaml-bukkit:${Versions.OKAERI_CONFIGS_YAML_BUKKIT}")
21-
api("eu.okaeri:okaeri-configs-serdes-commons:${Versions.OKAERI_CONFIGS_SERDES_COMMONS}")
22-
api("eu.okaeri:okaeri-configs-serdes-bukkit:${Versions.OKAERI_CONFIGS_SERDES_BUKKIT}")
23-
24-
// Panda utilities
25-
api("org.panda-lang:panda-utilities:${Versions.PANDA_UTILITIES}")
26-
27-
// GitCheck
28-
api("com.eternalcode:gitcheck:${Versions.GIT_CHECK}")
29-
30-
// commons
31-
api("commons-io:commons-io:${Versions.APACHE_COMMONS}")
32-
33-
// bstats
34-
api("org.bstats:bstats-bukkit:${Versions.B_STATS_BUKKIT}")
35-
36-
// caffeine
37-
api("com.github.ben-manes.caffeine:caffeine:${Versions.CAFFEINE}")
38-
39-
api("com.eternalcode:eternalcode-commons-bukkit:${Versions.ETERNALCODE_COMMONS}")
40-
api("com.eternalcode:eternalcode-commons-adventure:${Versions.ETERNALCODE_COMMONS}")
41-
42-
// worldguard
43-
compileOnly("com.sk89q.worldguard:worldguard-bukkit:${Versions.WORLD_GUARD_BUKKIT}")
44-
45-
// PlaceholderAPI
46-
compileOnlyApi("me.clip:placeholderapi:${Versions.PLACEHOLDER_API}")
47-
11+
api("org.jetbrains:annotations:${Versions.JETBRAINS_ANNOTATIONS}")
4812
}
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
package com.eternalcode.combat;
22

3-
import com.eternalcode.combat.config.implementation.PluginConfig;
4-
import com.eternalcode.combat.drop.DropKeepInventoryManager;
5-
import com.eternalcode.combat.drop.DropManager;
3+
import com.eternalcode.combat.fight.drop.DropKeepInventoryService;
64
import com.eternalcode.combat.fight.FightManager;
5+
import com.eternalcode.combat.fight.drop.DropService;
76
import com.eternalcode.combat.fight.effect.FightEffectService;
8-
import com.eternalcode.combat.fight.pearl.FightPearlManager;
9-
import com.eternalcode.combat.fight.tagout.FightTagOutService;
7+
import com.eternalcode.combat.fight.pearl.FightPearlService;
108
import com.eternalcode.combat.region.RegionProvider;
9+
import com.eternalcode.combat.fight.tagout.FightTagOutService;
1110

1211
public interface EternalCombatApi {
1312

1413
FightManager getFightManager();
1514

1615
RegionProvider getRegionProvider();
1716

18-
FightPearlManager getFightPearlManager();
17+
FightPearlService getFightPearlService();
1918

2019
FightTagOutService getFightTagOutService();
2120

2221
FightEffectService getFightEffectService();
2322

24-
DropManager getDropManager();
25-
26-
DropKeepInventoryManager getDropKeepInventoryManager();
23+
DropService getDropService();
2724

28-
PluginConfig getPluginConfig();
25+
DropKeepInventoryService getDropKeepInventoryService();
2926

3027
}

eternalcombat-api/src/main/java/com/eternalcode/combat/fight/FightManager.java

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,76 +4,26 @@
44
import com.eternalcode.combat.fight.event.CauseOfUnTag;
55
import com.eternalcode.combat.fight.event.FightTagEvent;
66
import com.eternalcode.combat.fight.event.FightUntagEvent;
7-
import com.eternalcode.combat.event.EventCaller;
8-
97
import java.time.Duration;
10-
import java.time.Instant;
118
import java.util.Collection;
12-
import java.util.Collections;
13-
import java.util.Map;
149
import java.util.UUID;
15-
import java.util.concurrent.ConcurrentHashMap;
1610
import org.jetbrains.annotations.ApiStatus;
1711
import org.jetbrains.annotations.Nullable;
1812

19-
public class FightManager {
20-
21-
private final Map<UUID, FightTag> fights = new ConcurrentHashMap<>();
22-
private final EventCaller eventCaller;
23-
24-
public FightManager(EventCaller eventCaller) {
25-
this.eventCaller = eventCaller;
26-
}
27-
28-
public boolean isInCombat(UUID player) {
29-
if (!this.fights.containsKey(player)) {
30-
return false;
31-
}
32-
33-
FightTag fightTag = this.fights.get(player);
13+
public interface FightManager {
3414

35-
return !fightTag.isExpired();
36-
}
15+
boolean isInCombat(UUID player);
3716

38-
public FightUntagEvent untag(UUID player, CauseOfUnTag causeOfUnTag) {
39-
FightUntagEvent event = this.eventCaller.publishEvent(new FightUntagEvent(player, causeOfUnTag));
40-
if (event.isCancelled()) {
41-
return event;
42-
}
17+
FightTag getTag(UUID target);
4318

44-
this.fights.remove(player);
45-
return event;
46-
}
47-
48-
public FightTagEvent tag(UUID target, Duration delay, CauseOfTag causeOfTag) {
49-
return this.tag(target, delay, causeOfTag, null);
50-
}
19+
Collection<FightTag> getFights();
5120

5221
@ApiStatus.Experimental
53-
public FightTagEvent tag(UUID target, Duration delay, CauseOfTag causeOfTag, @Nullable UUID tagger) {
54-
FightTagEvent event = this.eventCaller.publishEvent(new FightTagEvent(target, causeOfTag));
55-
56-
if (event.isCancelled()) {
57-
return event;
58-
}
59-
Instant now = Instant.now();
60-
Instant endOfCombatLog = now.plus(delay);
61-
62-
FightTag fightTag = new FightTag(target, endOfCombatLog, tagger);
63-
64-
this.fights.put(target, fightTag);
65-
return event;
66-
}
22+
FightTagEvent tag(UUID target, Duration delay, CauseOfTag causeOfTag, @Nullable UUID tagger);
6723

68-
public Collection<FightTag> getFights() {
69-
return Collections.unmodifiableCollection(this.fights.values());
70-
}
24+
FightTagEvent tag(UUID target, Duration delay, CauseOfTag causeOfTag);
7125

72-
public FightTag getTag(UUID target) {
73-
return this.fights.get(target);
74-
}
26+
FightUntagEvent untag(UUID player, CauseOfUnTag causeOfUnTag);
7527

76-
public void untagAll() {
77-
this.fights.clear();
78-
}
28+
void untagAll();
7929
}

eternalcombat-api/src/main/java/com/eternalcode/combat/fight/FightTag.java

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,17 @@
66
import org.jetbrains.annotations.ApiStatus;
77
import org.jetbrains.annotations.Nullable;
88

9-
public class FightTag {
9+
public interface FightTag {
1010

11-
private final UUID taggedPlayer;
12-
private final Instant endOfCombatLog;
13-
private final @Nullable UUID tagger;
14-
15-
FightTag(UUID personToAddCombat, Instant endOfCombatLog, @Nullable UUID tagger) {
16-
this.taggedPlayer = personToAddCombat;
17-
this.endOfCombatLog = endOfCombatLog;
18-
this.tagger = tagger;
19-
}
20-
21-
public UUID getTaggedPlayer() {
22-
return this.taggedPlayer;
23-
}
24-
25-
public Instant getEndOfCombatLog() {
26-
return this.endOfCombatLog;
27-
}
28-
29-
public boolean isExpired() {
30-
return Instant.now().isAfter(this.endOfCombatLog);
31-
}
32-
33-
public Duration getRemainingDuration() {
34-
Duration between = Duration.between(Instant.now(), this.endOfCombatLog);
11+
@Nullable
12+
@ApiStatus.Experimental
13+
UUID getTagger();
3514

36-
if (between.isNegative()) {
37-
return Duration.ZERO;
38-
}
15+
Duration getRemainingDuration();
3916

40-
return between;
41-
}
17+
boolean isExpired();
4218

43-
@Nullable
44-
@ApiStatus.Experimental
45-
public UUID getTagger() {
46-
return this.tagger;
47-
}
19+
Instant getEndOfCombatLog();
4820

21+
UUID getTaggedPlayer();
4922
}

eternalcombat-api/src/main/java/com/eternalcode/combat/drop/Drop.java renamed to eternalcombat-api/src/main/java/com/eternalcode/combat/fight/drop/Drop.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.eternalcode.combat.drop;
1+
package com.eternalcode.combat.fight.drop;
22

33
import org.bukkit.entity.Player;
44
import org.bukkit.inventory.ItemStack;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.eternalcode.combat.fight.drop;
2+
3+
import java.util.List;
4+
import java.util.UUID;
5+
import org.bukkit.inventory.ItemStack;
6+
7+
public interface DropKeepInventoryService {
8+
9+
List<ItemStack> nextItems(UUID uuid);
10+
11+
boolean hasItems(UUID uuid);
12+
13+
void addItems(UUID uuid, List<ItemStack> item);
14+
15+
void addItem(UUID uuid, ItemStack item);
16+
}

eternalcombat-api/src/main/java/com/eternalcode/combat/drop/DropModifier.java renamed to eternalcombat-api/src/main/java/com/eternalcode/combat/fight/drop/DropModifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.eternalcode.combat.drop;
1+
package com.eternalcode.combat.fight.drop;
22

33
public interface DropModifier {
44

eternalcombat-api/src/main/java/com/eternalcode/combat/drop/DropResult.java renamed to eternalcombat-api/src/main/java/com/eternalcode/combat/fight/drop/DropResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.eternalcode.combat.drop;
1+
package com.eternalcode.combat.fight.drop;
22

33
import org.bukkit.inventory.ItemStack;
44

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.eternalcode.combat.fight.drop;
2+
3+
public interface DropService {
4+
5+
DropResult modify(DropType dropType, Drop drop);
6+
7+
void registerModifier(DropModifier dropModifier);
8+
}

eternalcombat-api/src/main/java/com/eternalcode/combat/drop/DropType.java renamed to eternalcombat-api/src/main/java/com/eternalcode/combat/fight/drop/DropType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.eternalcode.combat.drop;
1+
package com.eternalcode.combat.fight.drop;
22

33
public enum DropType {
44

Lines changed: 12 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,25 @@
11
package com.eternalcode.combat.fight.effect;
22

3+
import java.util.List;
34
import org.bukkit.entity.Player;
45
import org.bukkit.potion.PotionEffect;
56
import org.bukkit.potion.PotionEffectType;
67

7-
import java.util.HashMap;
8-
import java.util.Map;
9-
import java.util.UUID;
10-
import java.util.List;
11-
import java.util.ArrayList;
12-
13-
public class FightEffectService {
14-
15-
private final Map<UUID, List<PotionEffect>> activeEffects = new HashMap<>();
16-
private static final int INFINITE_DURATION = -1;
17-
18-
public void storeActiveEffect(Player player, PotionEffect effect) {
19-
List<PotionEffect> effects = this.activeEffects.computeIfAbsent(player.getUniqueId(), k -> new ArrayList<>());
20-
21-
effects.add(effect);
22-
}
23-
24-
public void restoreActiveEffects(Player player) {
25-
List<PotionEffect> currentEffects = this.getCurrentEffects(player);
26-
27-
for (PotionEffect effect : currentEffects) {
28-
player.addPotionEffect(effect);
29-
}
30-
31-
this.clearStoredEffects(player);
32-
}
33-
34-
public void clearStoredEffects(Player player) {
35-
this.activeEffects.remove(player.getUniqueId());
36-
}
37-
38-
public List<PotionEffect> getCurrentEffects(Player player) {
39-
return this.activeEffects.getOrDefault(player.getUniqueId(), new ArrayList<>());
40-
}
41-
42-
public void applyCustomEffect(Player player, PotionEffectType type, Integer amplifier) {
43-
PotionEffect activeEffect = player.getPotionEffect(type);
44-
45-
if (activeEffect == null) {
46-
player.addPotionEffect(new PotionEffect(type, INFINITE_DURATION, amplifier));
47-
return;
48-
}
49-
50-
if (activeEffect.getAmplifier() > amplifier) {
51-
return;
52-
}
8+
/**
9+
* Manages custom potion effects on players during combat.
10+
* Active effects before combat are stored and restored after combat ends.
11+
*/
12+
public interface FightEffectService {
5313

54-
if (activeEffect.getDuration() == -1) {
55-
return;
56-
}
14+
void removeCustomEffect(Player player, PotionEffectType type, Integer amplifier);
5715

58-
this.storeActiveEffect(player, activeEffect);
59-
player.addPotionEffect(new PotionEffect(type, INFINITE_DURATION, amplifier));
60-
}
16+
void applyCustomEffect(Player player, PotionEffectType type, Integer amplifier);
6117

62-
public void removeCustomEffect(Player player, PotionEffectType type, Integer amplifier) {
63-
PotionEffect activeEffect = player.getPotionEffect(type);
18+
List<PotionEffect> getCurrentEffects(Player player);
6419

65-
if (activeEffect == null) {
66-
return;
67-
}
20+
void clearStoredEffects(Player player);
6821

69-
if (activeEffect.getAmplifier() != amplifier) {
70-
return;
71-
}
22+
void restoreActiveEffects(Player player);
7223

73-
player.removePotionEffect(type);
74-
}
24+
void storeActiveEffect(Player player, PotionEffect effect);
7525
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.eternalcode.combat.fight.event;
2+
3+
public enum CancelTagReason {
4+
5+
TAGOUT
6+
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
package com.eternalcode.combat.fight.event;
22

33
public enum CauseOfTag {
4+
5+
/**
6+
* The player was tagged in combat as a result of an attack by another player.
7+
*/
48
PLAYER,
9+
10+
/**
11+
* The player was tagged in combat due to an interaction with a non-player entity
12+
* (e.g., mobs or environmental damage).
13+
*/
514
NON_PLAYER,
15+
16+
/**
17+
* A command was executed to apply a combat tag to the player.
18+
*/
619
COMMAND,
20+
21+
/**
22+
* A custom cause, typically defined by external plugins or systems, applied the combat tag.
23+
*/
724
CUSTOM
825
}

0 commit comments

Comments
 (0)