-
-
Notifications
You must be signed in to change notification settings - Fork 20
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 all 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 = "Player with this permission will not spawn phantoms" | ||
) | ||
class PhantomSpawnController implements Listener { | ||
|
||
@Inject | ||
PhantomSpawnController(Plugin plugin) { | ||
new PhantomEventInitializer(plugin).initialize(); | ||
} | ||
|
||
@EventHandler | ||
void onPhantomSpawnAttempt(PhantomSpawnAttemptEvent event) { | ||
if (event.getEntity() instanceof Player player) { | ||
if (player.hasPermission("eternalcore.sleep.noinsomnia")) { | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
event.setCancelled(true); | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...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,27 @@ | ||
package com.eternalcode.core.feature.sleep; | ||
|
||
import com.eternalcode.annotations.scan.permission.PermissionDocs; | ||
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.player.PlayerJoinEvent; | ||
|
||
@Controller | ||
@PermissionDocs( | ||
name = "Sleep Ignore", | ||
permission = "eternalcore.sleep.ignore", | ||
description = "Player with this permission will ignore sleep count needed to skip the night" | ||
) | ||
class PlayerJoinSleepController implements Listener { | ||
|
||
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) { | ||
Player player = event.getPlayer(); | ||
if (player.hasPermission(SLEEP_IGNORE_PERMISSION)) { | ||
player.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); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
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,59 @@ | ||
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 HANDLER_LIST = new HandlerList(); | ||
|
||
private final Entity entity; | ||
private final Location location; | ||
private final SpawnReason spawnReason; | ||
private boolean cancelled = false; | ||
|
||
public PhantomSpawnAttemptEvent(Entity entity, Location location, SpawnReason spawnReason) { | ||
this.entity = entity; | ||
this.location = location; | ||
this.spawnReason = spawnReason; | ||
} | ||
|
||
public Entity getEntity() { | ||
return this.entity; | ||
} | ||
|
||
public Location getLocation() { | ||
return this.location; | ||
} | ||
|
||
public SpawnReason getSpawnReason() { | ||
return this.spawnReason; | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return cancelled; | ||
} | ||
|
||
@Override | ||
public void setCancelled(boolean cancelled) { | ||
this.cancelled = cancelled; | ||
} | ||
|
||
@Override | ||
public @NotNull HandlerList getHandlers() { | ||
return HANDLER_LIST; | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return HANDLER_LIST; | ||
} | ||
} |
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.