-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-715 Introduce a Jail system, fix multipart sudo command, fix audie…
…nce converter for console. (#715) * Initial Commit - Setup ENG messages, Setup subcommands framework. Work on JailService implementation. Setup Events and api. * Fix code style issues. Fix code to work. Add PL translation, add all messages in chat. Add correct Beans * Create Event handlers for blocked commands. Setup jailedPlayers list to check if player is in jail. * Add OrmLite repository, update commands, add tp event controller * Setup OrmLite repository for saved jail location. Fix issues in prisoner repos. * Add list command, add translations for this, fix minor issues. * Remove reason from any prisoner (its hard to paste it as a command, and I find no use in posting reasons) * Add Jail Task, add small config, update Prisoner fields, fix PlayerCommandEvent type * Add supported type of List in config, update existing usages. * Add eternalcore.jail.bypass permission, implement Cancellable in JailDetainEvent.java * Revert code style changes * Resolve changes from previous commits * Convert Location to Position inside Jail Feature * Fix database issue, related to thread stopping * Update messages, add custom TIME_UNITS * Remove `Reason` from commands * Add actionbar countdown support, fix missing placeholder, add method to extract time left of prisoner * Cleanup of translation sections * Small fixup * Implement DMK's review. Increase readability of code. Clear unused imports. Extract methods and much more. Co-authored by @imDMK * Break JailService into JailService and PrisonerService, resolve changes and fix errors * Move notifications form JailServiceImpl to JailCommand, add /jail setup command with no <args> * Move Notice logic to JailCommand, add JailedPlayer class to easy access to values needed in JailList * Add comments to api features * Follow @imDMK review * Fix error * Remove Jail Location Repo, use instead Location Configuration, change field type to String in detainedBy to match console command use. create method isPrisoner to check if player is prisoner. * Update eternalcore-api/src/main/java/com/eternalcode/core/feature/jail/JailService.java Co-authored-by: DMK <81445555+imDMK@users.noreply.github.com> * Update eternalcore-api/src/main/java/com/eternalcode/core/feature/jail/JailedPlayer.java Co-authored-by: DMK <81445555+imDMK@users.noreply.github.com> * Update eternalcore-api/src/main/java/com/eternalcode/core/feature/jail/Prisoner.java Co-authored-by: DMK <81445555+imDMK@users.noreply.github.com> * Update eternalcore-api/src/main/java/com/eternalcode/core/feature/jail/PrisonerService.java Co-authored-by: DMK <81445555+imDMK@users.noreply.github.com> * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/jail/PrisonerServiceImpl.java Co-authored-by: DMK <81445555+imDMK@users.noreply.github.com> * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/jail/PrisonerServiceImpl.java Co-authored-by: DMK <81445555+imDMK@users.noreply.github.com> * Update eternalcore-api/src/main/java/com/eternalcode/core/feature/jail/event/JailDetainEvent.java Co-authored-by: DMK <81445555+imDMK@users.noreply.github.com> * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/jail/JailCommand.java Co-authored-by: DMK <81445555+imDMK@users.noreply.github.com> * Follow code style and minor fixes from @imDMK and @vLuckyyy * minor fix * Add eventCaller and call events in PrisonerServiceImpl * Move PrisonerWrapper to separate class * Follow @vLuckyyy code * Add detain and release event result and custom message for that event * Remove JailedPlayer.java class, remove unnecessary fields in events. Remove unnecessary methods in PrisonerService * Code style issue * Rename fields in Translation services. Change type of getJailLocation to Optional<Location> Follow @Rollczi review * Remove event cancellation message, change suggested by @vLuckyyy * fix code style error * Remove unused messages from Translation files * Changes suggested by Rollczi in review GH-715 * Resolve self-conflicts. * Merge two services in one. * Fix merge bugs. * Fix placeholders and COE. * Fix sudo command * Fix audience converter implementation. * Remove useless check. * Add missing override annotation and remove notnull annotations. * Add api example * Add JailService to implementation of EternalCoreApi * Update eternalcore-api-example/src/main/java/com/eternalcode/example/feature/jail/ApiJailCommand.java Co-authored-by: Martin Sulikowski <vLuckyyy.biznes@gmail.com> * Apply @vLuckyyy suggestions once again * Fix spawn is not set warn. --------- Co-authored-by: DMK <81445555+imDMK@users.noreply.github.com> Co-authored-by: Rollczi <ndejlich5@gmail.com> Co-authored-by: Martin Sulikowski <vLuckyyy.biznes@gmail.com>
- Loading branch information
1 parent
167065a
commit ce9d87e
Showing
27 changed files
with
1,353 additions
and
125 deletions.
There are no files selected for viewing
This file contains 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
40 changes: 40 additions & 0 deletions
40
...alcore-api-example/src/main/java/com/eternalcode/example/feature/jail/ApiJailCommand.java
This file contains 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,40 @@ | ||
package com.eternalcode.example.feature.jail; | ||
|
||
import com.eternalcode.core.feature.jail.JailService; | ||
import dev.rollczi.litecommands.annotations.command.Command; | ||
import dev.rollczi.litecommands.annotations.context.Context; | ||
import dev.rollczi.litecommands.annotations.execute.Execute; | ||
import org.bukkit.entity.Player; | ||
|
||
@Command(name = "api jail") | ||
public class ApiJailCommand { | ||
|
||
private final JailService jailService; | ||
|
||
public ApiJailCommand(JailService jailService) { | ||
this.jailService = jailService; | ||
} | ||
|
||
/** | ||
* This method allows jailed player to buy freedom for 1 exp. | ||
*/ | ||
@Execute(name = "buy freedom") | ||
void executeBuyFreedom(@Context Player player) { | ||
if (!this.jailService.isPlayerJailed(player.getUniqueId())) { | ||
player.sendMessage("You are not jailed!"); | ||
return; | ||
} | ||
|
||
float exp = player.getExp(); | ||
|
||
if (exp < 1F) { | ||
player.sendMessage("You need at least 1 exp to buy freedom!"); | ||
return; | ||
} | ||
|
||
exp -= 1F; | ||
player.setExp(exp); | ||
|
||
this.jailService.releasePlayer(player); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...lcore-api-example/src/main/java/com/eternalcode/example/feature/jail/ApiJailListener.java
This file contains 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.example.feature.jail; | ||
|
||
import com.eternalcode.core.feature.jail.event.JailDetainEvent; | ||
import com.eternalcode.core.feature.jail.event.JailReleaseEvent; | ||
import org.bukkit.Server; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.potion.PotionEffect; | ||
import org.bukkit.potion.PotionEffectType; | ||
|
||
public class ApiJailListener implements Listener { | ||
|
||
private final Server server; | ||
|
||
public ApiJailListener(Server server) { | ||
this.server = server; | ||
} | ||
|
||
/** | ||
* This method applies blindness effect to the player when they are jailed. | ||
**/ | ||
@EventHandler | ||
public void onJailDetainEvent(JailDetainEvent event) { | ||
Player player = event.getPlayer(); | ||
|
||
PotionEffect effect = new PotionEffect(PotionEffectType.BLINDNESS, 1000000, 2); | ||
|
||
player.addPotionEffect(effect); | ||
} | ||
|
||
/** | ||
* This method removes blindness effect from the player when they are released from jail. | ||
**/ | ||
@EventHandler | ||
public void onJailReleaseEvent(JailReleaseEvent event) { | ||
Player player = this.server.getPlayer(event.getPlayerUniqueId()); | ||
|
||
assert player != null; | ||
player.removePotionEffect(PotionEffectType.BLINDNESS); | ||
} | ||
} |
This file contains 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
65 changes: 65 additions & 0 deletions
65
eternalcore-api/src/main/java/com/eternalcode/core/feature/jail/JailService.java
This file contains 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,65 @@ | ||
package com.eternalcode.core.feature.jail; | ||
|
||
import java.time.Duration; | ||
import java.util.Collection; | ||
import java.util.UUID; | ||
import javax.annotation.Nullable; | ||
import org.bukkit.Location; | ||
|
||
import java.util.Optional; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.Blocking; | ||
|
||
public interface JailService { | ||
|
||
/** | ||
* Detains the player in jail. If the duration is null, the default duration from plugin configuration is used. | ||
* If the player is already jailed, the duration is updated. Detained player is teleported to jail. | ||
* Returns true if player has been detained. | ||
* | ||
* @param player The player to detain. | ||
* @param detainedBy The player who detained the player. | ||
* @param duration The duration of the detainment. | ||
*/ | ||
boolean detainPlayer(Player player, CommandSender detainedBy, @Nullable Duration duration); | ||
|
||
/** | ||
* Releases the player from jail. If the player is not jailed, nothing happens. | ||
* Released player is teleported to spawn. | ||
* Returns true if player has been released. | ||
* | ||
* @param player The player to release. | ||
*/ | ||
boolean releasePlayer(Player player); | ||
|
||
/** | ||
* Releases all players from jail and teleports them to spawn. | ||
* If some players are offline and there are still jailed, they will not be teleported to spawn. | ||
*/ | ||
void releaseAllPlayers(); | ||
|
||
boolean isPlayerJailed(UUID player); | ||
|
||
Collection<JailedPlayer> getJailedPlayers(); | ||
|
||
/** | ||
* Changes location of the jail. | ||
* | ||
* @param jailLocation The location of the jail. | ||
*/ | ||
@Blocking | ||
void setupJailArea(Location jailLocation); | ||
|
||
/** | ||
* Removes the jail location. | ||
*/ | ||
@Blocking | ||
void removeJailArea(); | ||
|
||
/** | ||
* Provides the jail location. | ||
*/ | ||
Optional<Location> getJailAreaLocation(); | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
eternalcore-api/src/main/java/com/eternalcode/core/feature/jail/JailedPlayer.java
This file contains 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,48 @@ | ||
package com.eternalcode.core.feature.jail; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.UUID; | ||
|
||
public class JailedPlayer { | ||
|
||
private final UUID player; | ||
private final Instant detainedAt; | ||
private final Duration prisonTime; | ||
private final String detainedBy; | ||
|
||
public JailedPlayer(UUID player, Instant detainedAt, Duration prisonTime, String lockedUpBy) { | ||
this.player = player; | ||
this.detainedAt = detainedAt; | ||
this.prisonTime = prisonTime; | ||
this.detainedBy = lockedUpBy; | ||
} | ||
|
||
public UUID getPlayerUniqueId() { | ||
return this.player; | ||
} | ||
|
||
public Instant getDetainedAt() { | ||
return this.detainedAt; | ||
} | ||
|
||
public String getDetainedBy() { | ||
return this.detainedBy; | ||
} | ||
|
||
public Duration getPrisonTime() { | ||
return this.prisonTime; | ||
} | ||
|
||
public boolean isPrisonExpired() { | ||
return this.detainedAt.plus(this.prisonTime).isBefore(Instant.now()); | ||
} | ||
|
||
public Instant getReleaseTime() { | ||
return Instant.now().plus(this.prisonTime); | ||
} | ||
|
||
public Duration getRemainingTime() { | ||
return Duration.between(Instant.now(), this.detainedAt.plus(this.prisonTime)); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
eternalcore-api/src/main/java/com/eternalcode/core/feature/jail/event/JailDetainEvent.java
This file contains 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,44 @@ | ||
package com.eternalcode.core.feature.jail.event; | ||
|
||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Cancellable; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.event.player.PlayerEvent; | ||
|
||
public class JailDetainEvent extends PlayerEvent implements Cancellable { | ||
|
||
private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
|
||
private final CommandSender detainedBy; | ||
|
||
private boolean cancelled; | ||
|
||
public JailDetainEvent(Player player, CommandSender detainedBy) { | ||
super(player); | ||
this.detainedBy = detainedBy; | ||
} | ||
|
||
public CommandSender getDetainedBy() { | ||
return this.detainedBy; | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return this.cancelled; | ||
} | ||
|
||
@Override | ||
public void setCancelled(boolean cancel) { | ||
this.cancelled = cancel; | ||
} | ||
|
||
@Override | ||
public HandlerList getHandlers() { | ||
return HANDLER_LIST; | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return HANDLER_LIST; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
eternalcore-api/src/main/java/com/eternalcode/core/feature/jail/event/JailReleaseEvent.java
This file contains 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.jail.event; | ||
|
||
import org.bukkit.event.Cancellable; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
|
||
import java.util.UUID; | ||
|
||
public class JailReleaseEvent extends Event implements Cancellable { | ||
|
||
private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
|
||
private final UUID uuid; | ||
private boolean cancelled; | ||
|
||
public JailReleaseEvent(UUID uniqueId) { | ||
this.uuid = uniqueId; | ||
} | ||
|
||
public UUID getPlayerUniqueId() { | ||
return this.uuid; | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return this.cancelled; | ||
} | ||
|
||
@Override | ||
public void setCancelled(boolean cancel) { | ||
this.cancelled = cancel; | ||
} | ||
|
||
@Override | ||
public HandlerList getHandlers() { | ||
return HANDLER_LIST; | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return HANDLER_LIST; | ||
} | ||
} |
This file contains 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 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.