-
-
Notifications
You must be signed in to change notification settings - Fork 25
GH-1420 Add system where mobs ignore players #1420
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
CitralFlo
wants to merge
3
commits into
master
Choose a base branch
from
notarget
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 all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
23 changes: 23 additions & 0 deletions
23
eternalcore-api/src/main/java/com/eternalcode/core/feature/notarget/MobTargetService.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,23 @@ | ||
| package com.eternalcode.core.feature.notarget; | ||
|
|
||
| import java.util.UUID; | ||
| import org.bukkit.entity.Player; | ||
|
|
||
| public interface MobTargetService { | ||
|
|
||
| /* | ||
| * Removes mob tracking for player. | ||
| */ | ||
| void removeTracking(Player player); | ||
|
|
||
| /* | ||
| * Checks if a player is ignored for mob targeting. | ||
| * @return true if the player is ignored, false otherwise. | ||
| */ | ||
| boolean doMobsIgnore(UUID uniqueId); | ||
|
CitralFlo marked this conversation as resolved.
|
||
|
|
||
| /* | ||
| * Removes a player from the mob targeting ignore list. | ||
| */ | ||
| void startTracking(UUID uniqueId); | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
eternalcore-core/src/main/java/com/eternalcode/core/feature/notarget/MobTargetListener.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,27 @@ | ||
| package com.eternalcode.core.feature.notarget; | ||
|
|
||
| import com.eternalcode.core.injector.annotations.Inject; | ||
| import com.eternalcode.core.injector.annotations.component.Controller; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.entity.EntityTargetLivingEntityEvent; | ||
|
|
||
| @Controller | ||
| public class MobTargetListener implements Listener { | ||
|
|
||
| private final MobTargetService mobTargetService; | ||
|
|
||
| @Inject | ||
| public MobTargetListener(MobTargetService mobTargetService) { | ||
| this.mobTargetService = mobTargetService; | ||
| } | ||
|
|
||
| @EventHandler | ||
| public void onMobTarget(EntityTargetLivingEntityEvent event) { | ||
| if (event.getTarget() instanceof Player player && this.mobTargetService.doMobsIgnore(player.getUniqueId())) { | ||
| event.setCancelled(true); | ||
| } | ||
|
|
||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
...alcore-core/src/main/java/com/eternalcode/core/feature/notarget/MobTargetServiceImpl.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,42 @@ | ||
| package com.eternalcode.core.feature.notarget; | ||
|
|
||
| import com.eternalcode.core.injector.annotations.component.Service; | ||
| import java.util.HashSet; | ||
| import java.util.UUID; | ||
| import org.bukkit.entity.Entity; | ||
| import org.bukkit.entity.Mob; | ||
| import org.bukkit.entity.Player; | ||
|
|
||
| @Service | ||
| public class MobTargetServiceImpl implements MobTargetService { | ||
|
|
||
| private final HashSet<UUID> mobTargetMap = new HashSet<>(); | ||
|
|
||
| @Override | ||
| public void removeTracking(Player player) { | ||
| this.mobTargetMap.add(player.getUniqueId()); | ||
|
|
||
| this.enableNoTarget(player); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean doMobsIgnore(UUID uniqueId) { | ||
| return this.mobTargetMap.contains(uniqueId); | ||
| } | ||
|
|
||
| @Override | ||
| public void startTracking(UUID uniqueId) { | ||
| this.mobTargetMap.remove(uniqueId); | ||
| } | ||
|
|
||
| private void enableNoTarget(Player player) { | ||
| for (Entity entity : player.getNearbyEntities(30, 30, 30)) { | ||
| if (entity instanceof Mob mob) { | ||
|
|
||
| if (mob.getTarget() != null && mob.getTarget().equals(player)) { | ||
| mob.setTarget(null); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
79 changes: 79 additions & 0 deletions
79
eternalcore-core/src/main/java/com/eternalcode/core/feature/notarget/NoTargetCommand.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,79 @@ | ||
| package com.eternalcode.core.feature.notarget; | ||
|
|
||
| import com.eternalcode.core.injector.annotations.Inject; | ||
| import com.eternalcode.core.notice.NoticeService; | ||
| import dev.rollczi.litecommands.annotations.argument.Arg; | ||
| import dev.rollczi.litecommands.annotations.command.Command; | ||
| import dev.rollczi.litecommands.annotations.context.Sender; | ||
| import dev.rollczi.litecommands.annotations.execute.Execute; | ||
| import dev.rollczi.litecommands.annotations.permission.Permission; | ||
| import java.util.UUID; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.bukkit.entity.Player; | ||
|
|
||
| @Command(name = "notarget") | ||
| @Permission("eternalcore.notarget") | ||
| public class NoTargetCommand { | ||
|
|
||
| private final MobTargetService mobTargetService; | ||
| private final NoticeService noticeService; | ||
|
|
||
| @Inject | ||
| public NoTargetCommand(MobTargetService mobTargetService, NoticeService noticeService) { | ||
| this.mobTargetService = mobTargetService; | ||
| this.noticeService = noticeService; | ||
| } | ||
|
|
||
| @Execute | ||
| void execute(@Sender Player player) { | ||
| UUID uniqueId = player.getUniqueId(); | ||
|
|
||
| if (this.mobTargetService.doMobsIgnore(uniqueId)) { | ||
| this.turnOff(uniqueId); | ||
| return; | ||
| } | ||
|
CitralFlo marked this conversation as resolved.
|
||
|
|
||
| this.turnOn(player); | ||
| } | ||
|
|
||
| @Execute | ||
| void execute(@Sender CommandSender sender, @Arg Player target) { | ||
| UUID uniqueId = target.getUniqueId(); | ||
|
|
||
| if (this.mobTargetService.doMobsIgnore(uniqueId)) { | ||
| this.noticeService.create() | ||
| .notice(translation -> translation.noTarget().turnedOn()) | ||
| .placeholder("{PLAYER}", target.getName()) | ||
| .sender(sender) | ||
| .send(); | ||
|
|
||
| this.turnOn(target); | ||
| return; | ||
| } | ||
|
CitralFlo marked this conversation as resolved.
|
||
| this.noticeService.create() | ||
| .notice(translation -> translation.noTarget().turnedOff()) | ||
| .placeholder("{PLAYER}", target.getName()) | ||
| .sender(sender) | ||
| .send(); | ||
|
|
||
| this.turnOff(uniqueId); | ||
| } | ||
|
|
||
| private void turnOn(Player player) { | ||
| this.mobTargetService.removeTracking(player); | ||
|
|
||
| this.noticeService.create() | ||
| .notice(translation -> translation.noTarget().enabled()) | ||
| .player(player.getUniqueId()) | ||
| .send(); | ||
| } | ||
|
|
||
| private void turnOff(UUID uniqueId) { | ||
| this.mobTargetService.startTracking(uniqueId); | ||
|
|
||
| this.noticeService.create() | ||
| .notice(translation -> translation.noTarget().disabled()) | ||
| .player(uniqueId) | ||
| .send(); | ||
| } | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
...core/src/main/java/com/eternalcode/core/feature/notarget/messages/ENNoTargetMessages.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,19 @@ | ||||||
| package com.eternalcode.core.feature.notarget.messages; | ||||||
|
|
||||||
| import com.eternalcode.multification.notice.Notice; | ||||||
| import eu.okaeri.configs.OkaeriConfig; | ||||||
| import eu.okaeri.configs.annotation.Comment; | ||||||
| import lombok.Getter; | ||||||
| import lombok.experimental.Accessors; | ||||||
|
|
||||||
| @Getter | ||||||
| @Accessors(fluent = true) | ||||||
| public class ENNoTargetMessages extends OkaeriConfig implements NoTargetMessages { | ||||||
| Notice disabled = Notice.chat("<color:#9d6eef>► <white>Monsters will target You!"); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Notice enabled = Notice.chat("<color:#9d6eef>► <white>Monsters will no longer target You!"); | ||||||
|
|
||||||
| @Comment({" ", "# Placeholder: {PLAYER} - Targeted player name"}) | ||||||
| Notice turnedOff = Notice.chat("<color:#9d6eef>► <white>Monsters will target <green>{PLAYER}<white> - protection has been turned off!"); | ||||||
| Notice turnedOn = Notice.chat("<color:#9d6eef>► <white>Monsters will ignore <green>{PLAYER}<white> - protection has been turned on!"); | ||||||
|
|
||||||
| } | ||||||
12 changes: 12 additions & 0 deletions
12
...e-core/src/main/java/com/eternalcode/core/feature/notarget/messages/NoTargetMessages.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,12 @@ | ||
| package com.eternalcode.core.feature.notarget.messages; | ||
|
|
||
| import com.eternalcode.multification.notice.Notice; | ||
|
|
||
| public interface NoTargetMessages { | ||
| Notice enabled(); | ||
| Notice disabled(); | ||
|
|
||
| Notice turnedOn(); | ||
| Notice turnedOff(); | ||
|
|
||
| } |
18 changes: 18 additions & 0 deletions
18
...core/src/main/java/com/eternalcode/core/feature/notarget/messages/PLNoTargetMessages.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,18 @@ | ||||||
| package com.eternalcode.core.feature.notarget.messages; | ||||||
|
|
||||||
| import com.eternalcode.multification.notice.Notice; | ||||||
| import eu.okaeri.configs.OkaeriConfig; | ||||||
| import eu.okaeri.configs.annotation.Comment; | ||||||
| import lombok.Getter; | ||||||
| import lombok.experimental.Accessors; | ||||||
|
|
||||||
| @Getter | ||||||
| @Accessors(fluent = true) | ||||||
| public class PLNoTargetMessages extends OkaeriConfig implements NoTargetMessages { | ||||||
| Notice disabled = Notice.chat("<color:#9d6eef>► <white>Potwory nie będą Cię więcej ignorować!"); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Notice enabled = Notice.chat("<color:#9d6eef>► <white>Potwory będą Cię ignorować!"); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| @Comment({ " ", "# Placeholder: {PLAYER} - Wybrany komendą gracz"}) | ||||||
| Notice turnedOff = Notice.chat("<color:#9d6eef>► <white>Potwory nie będą ignorować gracza: <green>{PLAYER}<white> - ochrona została wyłączona!"); | ||||||
| Notice turnedOn = Notice.chat("<color:#9d6eef>► <white>Potwory będą ignorować gracza: <green>{PLAYER}<white> - ochrona została włączona!"); | ||||||
| } | ||||||
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
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.