Skip to content

Commit 7181ce9

Browse files
committed
show message in placeholder when chest is available
1 parent b01d4a9 commit 7181ce9

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

spigot/src/main/java/com/guflimc/treasurechests/spigot/TreasureChests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void onEnable() {
4444

4545
// placeholders
4646
SpigotPlaceholderManager placeholderManager = new SpigotPlaceholderManager(this);
47-
placeholderManager.register(new TreasureChestPlaceholders(manager));
47+
placeholderManager.register(new TreasureChestPlaceholders(manager, translator));
4848

4949
// init guis
5050
SpigotBrickGUI.register(this);

spigot/src/main/java/com/guflimc/treasurechests/spigot/placeholders/TreasureChestCountdownPlaceholders.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.guflimc.treasurechests.spigot.placeholders;
22

33
import com.guflimc.brick.i18n.api.time.DurationFormatter;
4+
import com.guflimc.brick.i18n.spigot.api.SpigotTranslator;
45
import com.guflimc.brick.placeholders.api.module.PlaceholderModule;
56
import com.guflimc.brick.placeholders.api.module.PlaceholderTreeModule;
67
import com.guflimc.brick.placeholders.api.resolver.PlaceholderResolveContext;
@@ -15,10 +16,12 @@
1516
public class TreasureChestCountdownPlaceholders extends PlaceholderTreeModule<Player> implements PlaceholderModule<Player> {
1617

1718
private final TreasureChestManager manager;
19+
private final SpigotTranslator translator;
1820

19-
public TreasureChestCountdownPlaceholders(TreasureChestManager manager) {
21+
public TreasureChestCountdownPlaceholders(TreasureChestManager manager, SpigotTranslator translator) {
2022
super("treasurechests");
2123
this.manager = manager;
24+
this.translator = translator;
2225

2326
register("digital", (idp, ctx) -> format(idp, ctx, DurationFormatter.DIGITAL));
2427
register("cozy", (idp, ctx) -> format(idp, ctx, DurationFormatter.COZY));
@@ -31,8 +34,8 @@ public TreasureChestCountdownPlaceholders(TreasureChestManager manager) {
3134
.map(chest -> manager.respawnIn(chest, placeholderResolveContext.entity()))
3235
.orElse(null);
3336

34-
if ( duration == null ) {
35-
return null;
37+
if ( duration == null || duration.isZero() ) {
38+
return translator.translate(placeholderResolveContext.entity(), "chest.available");
3639
}
3740

3841
return Component.text(formatter.format(duration));
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package com.guflimc.treasurechests.spigot.placeholders;
22

3+
import com.guflimc.brick.i18n.spigot.api.SpigotTranslator;
34
import com.guflimc.brick.placeholders.api.module.PlaceholderModule;
45
import com.guflimc.brick.placeholders.api.module.PlaceholderTreeModule;
56
import com.guflimc.treasurechests.spigot.TreasureChestManager;
67
import org.bukkit.entity.Player;
78

89
public class TreasureChestPlaceholders extends PlaceholderTreeModule<Player> implements PlaceholderModule<Player> {
910

10-
public TreasureChestPlaceholders(TreasureChestManager manager) {
11+
public TreasureChestPlaceholders(TreasureChestManager manager, SpigotTranslator translator) {
1112
super("treasurechests");
12-
register("countdown", new TreasureChestCountdownPlaceholders(manager));
13+
register("countdown", new TreasureChestCountdownPlaceholders(manager, translator));
1314
}
1415

1516
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"chest.looted": "<red>This chest has already been looted.",
3-
"chest.looted.duration": "<red>This chest has already been looted. It will refill in <gold>{0}<red>."
3+
"chest.looted.duration": "<red>This chest has already been looted. It will refill in <gold>{0}<red>.",
4+
"chest.available": "<green>This chest is available."
45
}

0 commit comments

Comments
 (0)