-
-
Notifications
You must be signed in to change notification settings - Fork 10
GH-266 New features for Trident and Pearls #303
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
Pawelusze
wants to merge
32
commits into
EternalCodeTeam:master
Choose a base branch
from
Pawelusze:feature/add-reset-timer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
3fa5bfa
I've added new options to Pearl and Trident that reset the timer when…
Pawelusze fa7e220
I made the corrections that gemini noticed
Pawelusze e48a01f
The improvements suggested by the team have been implemented
Pawelusze f4bdbb7
Implemented suggestions from the team
Pawelusze 51d4e34
Bump packetevents version to support future MC versions
Jakubk15 2e899de
Make tridents throw check work on all tridents, regardless of enchant…
Jakubk15 0be6867
Merge remote-tracking branch 'origin/feature/add-reset-timer' into fe…
Pawelusze ab4e804
Implemented suggestions from the team and fixed `FightTridentControll…
Pawelusze 5ec350a
Corrected comments and field names
Pawelusze ee6cac5
Implemented CitralFlo suggestions
Pawelusze 68fb2ef
Implemented CitralFlo suggestions again
Pawelusze 5efe39b
Merge branch 'master' into feature/add-reset-timer
CitralFlo 0841c22
Follow igoyek's review from 21.10.25
CitralFlo 76e84ab
CR
Rollczi 07ab306
Simplify naming - extract logic to service for Pearls
CitralFlo 795c7b6
make it more logical
CitralFlo 984449b
Refactor trident-related classes and services for improved clarity an…
CitralFlo 3b0bd15
Rename trident cooldown methods to improve clarity and update comment…
CitralFlo 486789d
Fixes after tests - everything should be working now!
CitralFlo 70b3c7b
Remove commented line
CitralFlo 996e95c
Add cooldown to enderpearl - hack by:https://www.spigotmc.org/threads…
CitralFlo 3b19294
Bump minecraft version in runServer task to 1.21.11
Jakubk15 c7588e5
Add combat restrictions for Riptide tridents and improve event handling
vLuckyyy 70f6a5f
Update eternalcombat-plugin/src/main/java/com/eternalcode/combat/figh…
Jakubk15 1bdeaf6
Apply suggestion from @Jakubk15
Jakubk15 20ab95a
Merge branch 'master' into feature/add-reset-timer
Jakubk15 3f8b624
Merge remote-tracking branch 'refs/remotes/upstream/master' into feat…
Jakubk15 4a8cf17
Migrate to commons delay
Jakubk15 a3b1a33
Merge branch 'master' into feature/add-reset-timer
Jakubk15 2a8b17b
Merge branch 'master' into feature/add-reset-timer
Jakubk15 9f4a715
Merge remote-tracking branch 'origin/feature/add-reset-timer' into fe…
Jakubk15 38cc29e
Resolve conflicts
Jakubk15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...nalcombat-api/src/main/java/com/eternalcode/combat/fight/trident/FightTridentService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.eternalcode.combat.fight.trident; | ||
|
|
||
| import java.time.Duration; | ||
| import java.time.Instant; | ||
| import java.util.UUID; | ||
|
|
||
| public interface FightTridentService { | ||
|
|
||
| Instant getDelay(UUID uuid); | ||
|
|
||
| Duration getRemainingDelay(UUID uuid); | ||
|
|
||
| boolean hasDelay(UUID uuid); | ||
|
|
||
| void markDelay(UUID uuid); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...bat-plugin/src/main/java/com/eternalcode/combat/fight/trident/FightTridentController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package com.eternalcode.combat.fight.trident; | ||
|
|
||
| import com.eternalcode.combat.config.implementation.PluginConfig; | ||
| import com.eternalcode.combat.fight.FightManager; | ||
|
|
||
| import com.eternalcode.combat.fight.event.CauseOfTag; | ||
| import com.eternalcode.combat.notification.NoticeService; | ||
| import com.eternalcode.combat.util.DurationUtil; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.player.PlayerInteractEvent; | ||
| import org.bukkit.inventory.ItemStack; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.UUID; | ||
|
|
||
| public class FightTridentController implements Listener { | ||
|
Jakubk15 marked this conversation as resolved.
Outdated
|
||
|
|
||
| private final FightTridentSettings settings; | ||
| private final NoticeService noticeService; | ||
| private final FightManager fightManager; | ||
| private final FightTridentService fightTridentService; | ||
| private final PluginConfig config; | ||
|
|
||
| public FightTridentController( | ||
| FightTridentSettings settings, | ||
| NoticeService noticeService, | ||
| FightManager fightManager, | ||
| FightTridentService fightTridentService, | ||
| PluginConfig config | ||
| ) { | ||
| this.settings = settings; | ||
| this.noticeService = noticeService; | ||
| this.fightManager = fightManager; | ||
| this.fightTridentService = fightTridentService; | ||
| this.config = config; | ||
| } | ||
|
|
||
|
|
||
| @EventHandler(priority = EventPriority.HIGHEST) | ||
| public void onTridentInteract(PlayerInteractEvent event) { | ||
| ItemStack item = event.getItem(); | ||
|
|
||
| if (item == null || item.getType() != Material.TRIDENT) { | ||
| return; | ||
| } | ||
|
|
||
| Player player = event.getPlayer(); | ||
| UUID playerId = player.getUniqueId(); | ||
|
|
||
| if (!this.fightManager.isInCombat(playerId)) { | ||
| return; | ||
| } | ||
|
|
||
| if (this.settings.tridentThrowDisabledDuringCombat) { | ||
| event.setCancelled(true); | ||
| this.noticeService.create() | ||
| .player(playerId) | ||
| .notice(this.settings.tridentThrowBlockedDuringCombat) | ||
| .send(); | ||
| return; | ||
| } | ||
|
|
||
| if (this.settings.tridentCooldownEnabled) { | ||
| this.handleTridentCooldown(event, player, playerId); | ||
| } | ||
|
|
||
| if (this.settings.tridentResetsTimerEnabled) { | ||
| Duration combatTime = this.config.settings.combatTimerDuration; | ||
| this.fightManager.tag(playerId, combatTime, CauseOfTag.CUSTOM); | ||
| } | ||
| } | ||
|
|
||
| private void handleTridentCooldown(PlayerInteractEvent event, Player player, UUID playerId) { | ||
| if (this.settings.tridentThrowDelay.isZero()) { | ||
| return; | ||
| } | ||
|
|
||
| if (this.fightTridentService.hasDelay(playerId)) { | ||
| event.setCancelled(true); | ||
| Duration remainingDelay = this.fightTridentService.getRemainingDelay(playerId); | ||
|
|
||
| this.noticeService.create() | ||
| .player(playerId) | ||
| .notice(this.settings.tridentThrowBlockedDelayDuringCombat) | ||
| .placeholder("{TIME}", DurationUtil.format(remainingDelay)) | ||
| .send(); | ||
| return; | ||
| } | ||
|
|
||
| this.fightTridentService.markDelay(playerId); | ||
| int cooldownTicks = (int) (this.settings.tridentThrowDelay.toMillis() / 50); | ||
| player.setCooldown(Material.TRIDENT, cooldownTicks); | ||
| } | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
...at-plugin/src/main/java/com/eternalcode/combat/fight/trident/FightTridentServiceImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package com.eternalcode.combat.fight.trident; | ||
|
|
||
| import com.github.benmanes.caffeine.cache.Cache; | ||
| import com.github.benmanes.caffeine.cache.Caffeine; | ||
|
|
||
| import java.time.Duration; | ||
| import java.time.Instant; | ||
| import java.util.UUID; | ||
|
|
||
| public class FightTridentServiceImpl implements FightTridentService { | ||
| private final FightTridentSettings tridentSettings; | ||
| private final Cache<UUID, Instant> tridentStartTimes; | ||
|
|
||
| public FightTridentServiceImpl(FightTridentSettings pearlSettings) { | ||
| this.tridentSettings = pearlSettings; | ||
|
Jakubk15 marked this conversation as resolved.
Outdated
|
||
| this.tridentStartTimes = Caffeine.newBuilder() | ||
| .expireAfterWrite(pearlSettings.tridentThrowDelay) | ||
|
CitralFlo marked this conversation as resolved.
Outdated
|
||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public void markDelay(UUID uuid) { | ||
| this.tridentStartTimes.put(uuid, Instant.now()); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean hasDelay(UUID uuid) { | ||
| return this.tridentStartTimes.getIfPresent(uuid) != null; | ||
| } | ||
|
|
||
| @Override | ||
| public Duration getRemainingDelay(UUID uuid) { | ||
| Instant startTime = this.tridentStartTimes.getIfPresent(uuid); | ||
| if (startTime == null) { | ||
| return Duration.ZERO; | ||
| } | ||
|
|
||
| Duration elapsed = Duration.between(startTime, Instant.now()); | ||
| Duration remaining = this.tridentSettings.tridentThrowDelay.minus(elapsed); | ||
|
|
||
| return remaining.isNegative() ? Duration.ZERO : remaining; | ||
| } | ||
|
|
||
| @Override | ||
| public Instant getDelay(UUID uuid) { | ||
| Instant startTime = this.tridentStartTimes.getIfPresent(uuid); | ||
| return startTime != null ? startTime.plus(this.tridentSettings.tridentThrowDelay) : Instant.MIN; | ||
| } | ||
| } | ||
|
|
||
39 changes: 39 additions & 0 deletions
39
...ombat-plugin/src/main/java/com/eternalcode/combat/fight/trident/FightTridentSettings.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.eternalcode.combat.fight.trident; | ||
|
|
||
| import com.eternalcode.multification.bukkit.notice.BukkitNotice; | ||
| import com.eternalcode.multification.notice.Notice; | ||
| import eu.okaeri.configs.OkaeriConfig; | ||
| import eu.okaeri.configs.annotation.Comment; | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
| public class FightTridentSettings extends OkaeriConfig { | ||
|
|
||
| @Comment({ | ||
| "# Set true, If you want to disable throwing trident during combat", | ||
|
CitralFlo marked this conversation as resolved.
Outdated
|
||
| "# This will work globally, but can be overridden by region settings" | ||
| }) | ||
| public boolean tridentThrowDisabledDuringCombat = true; | ||
|
CitralFlo marked this conversation as resolved.
Outdated
|
||
|
|
||
| @Comment("# Set true, If you want add cooldown to trident") | ||
|
CitralFlo marked this conversation as resolved.
Outdated
|
||
| public boolean tridentCooldownEnabled = false; | ||
|
|
||
| @Comment("# Set true, If you want to reset timer when player uses trident") | ||
|
CitralFlo marked this conversation as resolved.
Outdated
|
||
| public boolean tridentResetsTimerEnabled = true; | ||
|
CitralFlo marked this conversation as resolved.
Outdated
|
||
|
|
||
| @Comment({ | ||
| "# Block throwing trident with delay?", | ||
| "# If you set this to for example 3s, player will have to wait 3 seconds before throwing trident" | ||
|
CitralFlo marked this conversation as resolved.
Outdated
|
||
| }) | ||
| public Duration tridentThrowDelay = Duration.ofSeconds(3); | ||
|
|
||
| @Comment("# Message sent when player tries to throw trident, but are disabled") | ||
|
CitralFlo marked this conversation as resolved.
Outdated
|
||
| public Notice tridentThrowBlockedDuringCombat = BukkitNotice.builder() | ||
| .chat("<red>Throwing trident is prohibited during combat!") | ||
| .build(); | ||
|
|
||
| @Comment("# Message sent when player tries to throw trident, but has delay") | ||
|
CitralFlo marked this conversation as resolved.
Outdated
|
||
| public Notice tridentThrowBlockedDelayDuringCombat = BukkitNotice.builder() | ||
| .chat("<red>You must wait {TIME} before next throw!") | ||
| .build(); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.