Skip to content

Commit 0b26c78

Browse files
author
Jan Kluka
committed
1.3
Implemented rebirths api
1 parent 6fff551 commit 0b26c78

File tree

9 files changed

+213
-17
lines changed

9 files changed

+213
-17
lines changed

src/main/java/dev/drawethree/xprison/api/XPrisonAPI.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import dev.drawethree.xprison.api.pickaxeskins.XPrisonPickaxeSkinsAPI;
1515
import dev.drawethree.xprison.api.prestiges.XPrisonPrestigesAPI;
1616
import dev.drawethree.xprison.api.ranks.XPrisonRanksAPI;
17+
import dev.drawethree.xprison.api.rebirth.XPrisonRebirthAPI;
1718
import org.jetbrains.annotations.NotNull;
1819

1920
/**
@@ -133,6 +134,14 @@ public interface XPrisonAPI {
133134
@NotNull
134135
XPrisonPickaxeSkinsAPI getPickaxeSkinsApi();
135136

137+
/**
138+
* Gets the Rebirth API
139+
*
140+
* @return the Rebirth API instance
141+
*/
142+
@NotNull
143+
XPrisonRebirthAPI getRebirthApi();
144+
136145
/**
137146
* Gets the singleton instance of the XPrisonAPI.
138147
*

src/main/java/dev/drawethree/xprison/api/currency/enums/LostCause.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public enum LostCause {
2525
*/
2626
RANKUP,
2727

28+
/**
29+
* Player lost currency by rebirth.
30+
*/
31+
REBIRTH,
32+
2833
/**
2934
* Player lost currency by an admin running a command affecting currency.
3035
*/

src/main/java/dev/drawethree/xprison/api/currency/event/PlayerCurrencyReceiveEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public final class PlayerCurrencyReceiveEvent extends XPrisonPlayerEvent impleme
5252
* @param player the {@link OfflinePlayer} receiving the currency
5353
* @param amount the amount of currency to be received
5454
*/
55-
public PlayerCurrencyReceiveEvent(XPrisonCurrency currency, ReceiveCause cause, OfflinePlayer player, long amount) {
55+
public PlayerCurrencyReceiveEvent(XPrisonCurrency currency, ReceiveCause cause, OfflinePlayer player, double amount) {
5656
super(player);
5757
this.currency = currency;
5858
this.cause = cause;

src/main/java/dev/drawethree/xprison/api/multipliers/XPrisonMultipliersAPI.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,4 @@ public interface XPrisonMultipliersAPI {
2525
*/
2626
PlayerMultiplier getPlayerMultiplier(Player p, XPrisonCurrency currency);
2727

28-
29-
/**
30-
* Calculates the total amount to deposit after applying the player's multiplier.
31-
*
32-
* @param p the player
33-
* @param deposit the original amount to deposit
34-
* @param currency the currency affected
35-
* @return the new amount to deposit after applying multiplier
36-
*/
37-
default double getTotalToDeposit(Player p, double deposit, XPrisonCurrency currency) {
38-
PlayerMultiplier multiplier = this.getPlayerMultiplier(p, currency);
39-
if (multiplier == null) {
40-
return deposit;
41-
}
42-
return deposit * (1.0 + multiplier.getMultiplier());
43-
}
4428
}

src/main/java/dev/drawethree/xprison/api/prestiges/XPrisonPrestigesAPI.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,11 @@ public interface XPrisonPrestigesAPI {
4848
*/
4949
boolean isMaxPrestige(Player player);
5050

51+
/**
52+
* Resets a player's prestige to 0.
53+
*
54+
* @param player the player whose prestige will be reset
55+
*/
56+
void resetPlayerPrestige(Player player);
57+
5158
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package dev.drawethree.xprison.api.rebirth;
2+
3+
import dev.drawethree.xprison.api.rebirth.model.Rebirth;
4+
import org.bukkit.entity.Player;
5+
6+
import java.util.Optional;
7+
8+
/**
9+
* API interface for interacting with the XPrison Rebirth system.
10+
*/
11+
public interface XPrisonRebirthAPI {
12+
13+
/**
14+
* Gets a rebirth by its unique ID.
15+
*
16+
* @param id the ID of the rebirth
17+
* @return the Rebirth corresponding to the given ID
18+
*/
19+
Rebirth getRebirthById(int id);
20+
21+
/**
22+
* Gets the current rebirth of a player.
23+
*
24+
* @param player the player whose rebirth is requested
25+
* @return the player's current Rebirth
26+
*/
27+
Rebirth getPlayerRebirth(Player player);
28+
29+
/**
30+
* Gets the next rebirth a player can achieve.
31+
*
32+
* @param player the player whose next rebirth is requested
33+
* @return an Optional containing the next Rebirth, or empty if the player has the max rebirth
34+
*/
35+
Optional<Rebirth> getNextPlayerRebirth(Player player);
36+
37+
/**
38+
* Sets a player's rebirth to the specified Rebirth.
39+
*
40+
* @param player the player whose rebirth is to be set
41+
* @param rebirth the Rebirth to assign to the player
42+
*/
43+
void setPlayerRebirth(Player player, Rebirth rebirth);
44+
45+
/**
46+
* Resets a player's rebirth to the default rebirth (usually 0 or 1 depending on config).
47+
*
48+
* @param player the player whose rebirth will be reset
49+
*/
50+
void resetPlayerRebirth(Player player);
51+
52+
/**
53+
* Checks if a player currently holds the maximum possible rebirth.
54+
*
55+
* @param player the player to check
56+
* @return true if the player has the max rebirth, false otherwise
57+
*/
58+
boolean isMaxRebirth(Player player);
59+
60+
/**
61+
* Attempts to rebirth a player, checking all requirements.
62+
*
63+
* @param player the player attempting to rebirth
64+
* @return true if the rebirth was successful, false otherwise
65+
*/
66+
boolean tryRebirth(Player player);
67+
68+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package dev.drawethree.xprison.api.rebirth.events;
2+
3+
import dev.drawethree.xprison.api.rebirth.model.Rebirth;
4+
import dev.drawethree.xprison.api.shared.events.player.XPrisonPlayerEvent;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import org.bukkit.entity.Player;
8+
import org.bukkit.event.Cancellable;
9+
import org.bukkit.event.HandlerList;
10+
11+
/**
12+
* Event fired when a player rebirths.
13+
* <p>
14+
* Contains information about the old rebirth and the new rebirth.
15+
* This event is cancellable, allowing prevention of the rebirth.
16+
*/
17+
@Getter
18+
public final class PlayerRebirthEvent extends XPrisonPlayerEvent implements Cancellable {
19+
20+
private static final HandlerList handlers = new HandlerList();
21+
22+
private final Rebirth oldRebirth;
23+
24+
@Setter
25+
private Rebirth newRebirth;
26+
27+
@Setter
28+
private boolean cancelled;
29+
30+
/**
31+
* Constructs a new PlayerRebirthEvent.
32+
*
33+
* @param player Player who rebirth
34+
* @param oldR The player's old rebirth
35+
* @param newR The new rebirth the player is moving to
36+
*/
37+
public PlayerRebirthEvent(Player player, Rebirth oldR, Rebirth newR) {
38+
super(player);
39+
this.oldRebirth = oldR;
40+
this.newRebirth = newR;
41+
}
42+
43+
/**
44+
* Gets the HandlerList for this event.
45+
*
46+
* @return HandlerList instance
47+
*/
48+
public static HandlerList getHandlerList() {
49+
return handlers;
50+
}
51+
52+
@Override
53+
public HandlerList getHandlers() {
54+
return handlers;
55+
}
56+
57+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package dev.drawethree.xprison.api.rebirth.model;
2+
3+
import java.util.List;
4+
5+
public interface Rebirth {
6+
7+
/**
8+
* @return The numeric ID of the rebirth (1, 2, 3, ...)
9+
*/
10+
int getId();
11+
12+
/**
13+
* @return The chat prefix for this rebirth.
14+
*/
15+
String getPrefix();
16+
17+
/**
18+
* @return All requirements needed to achieve this rebirth.
19+
*/
20+
List<RebirthRequirement> getRequirements();
21+
22+
/**
23+
* @return Commands to execute when the player reaches this rebirth.
24+
*/
25+
List<String> getRewardCommands();
26+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package dev.drawethree.xprison.api.rebirth.model;
2+
3+
import org.bukkit.entity.Player;
4+
5+
public interface RebirthRequirement {
6+
7+
/**
8+
* @return a short type identifier, e.g. "rank", "prestige", "currency"
9+
*/
10+
String getType();
11+
12+
/**
13+
* @return Whether this requirement is enabled.
14+
*/
15+
boolean isEnabled();
16+
17+
/**
18+
* Checks if a player meets this requirement.
19+
*
20+
* @param player the player to check
21+
* @return true if met
22+
*/
23+
boolean isMet(Player player);
24+
25+
/**
26+
* Applies the "payment" or consequence for this requirement after a rebirth happens.
27+
* For example:
28+
* - RANK → reset player rank to default
29+
* - PRESTIGE → reset player prestige to default
30+
* - CURRENCY → subtract balance
31+
*
32+
* @param player the player to apply the action to
33+
*/
34+
void apply(Player player);
35+
36+
/**
37+
* Returns the failure message to show the player when this requirement is not met.
38+
*/
39+
String getFailMessage();
40+
}

0 commit comments

Comments
 (0)