-
-
Notifications
You must be signed in to change notification settings - Fork 21
GH-1134 Add permissions allowing to ignore sleep count for night skip and phantom spawn #1135
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9d40d4e
Add sleep controllers for ignore sleeping and preventing spawn of pha…
Jakubk15 f747830
Add a new line between static field and class declaration
Jakubk15 0deac50
Update eternalcore-core/src/main/java/com/eternalcode/core/feature/sl…
Jakubk15 6d4cf6f
improve event fields and add javadoc
Jakubk15 c6f9eb2
Update PhantomSpawnAttemptEvent.java
Jakubk15 f52b685
Update PhantomSpawnAttemptEvent.java
Jakubk15 2128916
Update PhantomSpawnAttemptEvent.java
Jakubk15 acdfd07
Update PhantomSpawnAttemptEvent.java
Jakubk15 37295b7
Update PhantomSpawnAttemptEvent.java
Jakubk15 8ce86d6
Update PlayerJoinSleepController.java
Jakubk15 532b130
Update PhantomSpawnAttemptEvent.java
Jakubk15 15b8815
Adjust event field names to P1otrulla's demands
Jakubk15 e6826c9
remove duplicate code to fix build
Jakubk15 1de082e
Update eternalcore-core/src/main/java/com/eternalcode/core/feature/sl…
Jakubk15 38f7704
Update eternalcore-core/src/main/java/com/eternalcode/core/feature/sl…
Jakubk15 477acf2
Update eternalcore-core/src/main/java/com/eternalcode/core/feature/sl…
Jakubk15 97554ef
inline field
Jakubk15 cb0afc5
Update PhantomSpawnController.java
Jakubk15 446aa81
Update PlayerJoinSleepController.java
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
34 changes: 34 additions & 0 deletions
34
...nalcore-core/src/main/java/com/eternalcode/core/feature/sleep/PhantomSpawnController.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,34 @@ | ||
| package com.eternalcode.core.feature.sleep; | ||
|
|
||
| import com.eternalcode.annotations.scan.permission.PermissionDocs; | ||
| import com.eternalcode.core.injector.annotations.Inject; | ||
| import com.eternalcode.core.injector.annotations.component.Controller; | ||
| import com.eternalcode.paper.phantom.PhantomEventInitializer; | ||
| import com.eternalcode.paper.phantom.PhantomSpawnAttemptEvent; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.plugin.Plugin; | ||
|
|
||
| @Controller | ||
| @PermissionDocs( | ||
| name = "Phantom Spawn Ignore", | ||
| permission = "eternalcore.sleep.noinsomnia", | ||
| description = "Allows the player holding the permission to not spawn phantoms when not sleeping for 3+ nights" | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| public class PhantomSpawnController implements Listener { | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Inject | ||
| public PhantomSpawnController(Plugin plugin) { | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| new PhantomEventInitializer(plugin).initialize(); | ||
| } | ||
|
|
||
| @EventHandler | ||
| void onPhantomSpawnAttempt(PhantomSpawnAttemptEvent event) { | ||
| if (event.getSpawningEntity() instanceof Player player) { | ||
| if (player.hasPermission("eternalcore.sleep.noinsomnia")) { | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| event.setCancelled(true); | ||
| } | ||
| } | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
...core-core/src/main/java/com/eternalcode/core/feature/sleep/PlayerJoinSleepController.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,25 @@ | ||
| package com.eternalcode.core.feature.sleep; | ||
|
|
||
| import com.eternalcode.annotations.scan.permission.PermissionDocs; | ||
| import com.eternalcode.core.injector.annotations.component.Controller; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.player.PlayerJoinEvent; | ||
|
|
||
| @Controller | ||
| @PermissionDocs( | ||
| name = "Sleep Ignore", | ||
| permission = "eternalcore.sleep.ignore", | ||
| description = "Allows the player holding the permission to be ignored while sleeping in the night" | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| public class PlayerJoinSleepController implements Listener { | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private static final String SLEEP_IGNORE_PERMISSION = "eternalcore.sleep.ignore"; | ||
|
|
||
| @EventHandler | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| void onPlayerJoin(PlayerJoinEvent event) { | ||
| if (event.getPlayer().hasPermission(SLEEP_IGNORE_PERMISSION)) { | ||
| event.getPlayer().setSleepingIgnored(true); | ||
| } | ||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
eternalcore-paper/src/main/java/com/eternalcode/paper/phantom/PhantomEventInitializer.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,17 @@ | ||
| package com.eternalcode.paper.phantom; | ||
|
|
||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.plugin.Plugin; | ||
|
|
||
| public class PhantomEventInitializer { | ||
P1otrulla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private final Plugin plugin; | ||
|
|
||
| public PhantomEventInitializer(Plugin plugin) { | ||
| this.plugin = plugin; | ||
| } | ||
|
|
||
| public void initialize() { | ||
| Bukkit.getPluginManager().registerEvents(new PhantomEventWrapper(), this.plugin); | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
eternalcore-paper/src/main/java/com/eternalcode/paper/phantom/PhantomEventWrapper.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,25 @@ | ||
| package com.eternalcode.paper.phantom; | ||
|
|
||
| import com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent; | ||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.event.Listener; | ||
|
|
||
P1otrulla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| class PhantomEventWrapper implements Listener { | ||
|
|
||
| @EventHandler(priority = EventPriority.HIGH) | ||
| void onPhantomSpawn(PhantomPreSpawnEvent event) { | ||
| PhantomSpawnAttemptEvent attemptEvent = new PhantomSpawnAttemptEvent( | ||
| event.getSpawningEntity(), | ||
| event.getSpawnLocation(), | ||
| event.getReason() | ||
| ); | ||
|
|
||
| Bukkit.getPluginManager().callEvent(attemptEvent); | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (attemptEvent.isCancelled()) { | ||
| event.setCancelled(true); | ||
| } | ||
| } | ||
| } | ||
55 changes: 55 additions & 0 deletions
55
eternalcore-paper/src/main/java/com/eternalcode/paper/phantom/PhantomSpawnAttemptEvent.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,55 @@ | ||
| package com.eternalcode.paper.phantom; | ||
|
|
||
| import org.bukkit.Location; | ||
| import org.bukkit.entity.Entity; | ||
| import org.bukkit.event.Cancellable; | ||
| import org.bukkit.event.Event; | ||
| import org.bukkit.event.HandlerList; | ||
| import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| /** | ||
| * Internal event of {@link com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent} | ||
| */ | ||
| public class PhantomSpawnAttemptEvent extends Event implements Cancellable { | ||
Rollczi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private static final HandlerList handlers = new HandlerList(); | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private final Entity spawningEntity; | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private final Location spawnLocation; | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private final SpawnReason spawnReason; | ||
| private boolean cancelled = false; | ||
|
|
||
| public PhantomSpawnAttemptEvent(Entity spawningEntity, Location spawnLocation, SpawnReason spawnReason) { | ||
| this.spawningEntity = spawningEntity; | ||
| this.spawnLocation = spawnLocation; | ||
| this.spawnReason = spawnReason; | ||
| } | ||
|
|
||
| public Entity getSpawningEntity() { | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return spawningEntity; | ||
| } | ||
|
|
||
| public Location getSpawnLocation() { | ||
| return spawnLocation; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isCancelled() { | ||
| return cancelled; | ||
| } | ||
|
|
||
| @Override | ||
| public void setCancelled(boolean cancelled) { | ||
| this.cancelled = cancelled; | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull HandlerList getHandlers() { | ||
| return handlers; | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public static HandlerList getHandlerList() { | ||
| return handlers; | ||
Jakubk15 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
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.