This repository has been archived by the owner on Sep 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* placeholder api in pom * placeholderapi added as softdepend, expansion class + runtime check for PlaceholderAPI in onEnable
- Loading branch information
Showing
5 changed files
with
84 additions
and
0 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
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
64 changes: 64 additions & 0 deletions
64
...anks-plugin/src/main/java/com/github/ms5984/clans/clansbanks/model/BanksPlaceholders.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,64 @@ | ||
package com.github.ms5984.clans.clansbanks.model; | ||
|
||
import com.github.ms5984.clans.clansbanks.ClansBanks; | ||
import com.github.ms5984.clans.clansbanks.api.BanksAPI; | ||
import com.github.ms5984.clans.clansbanks.api.ClanBank; | ||
import com.youtube.hempfest.clans.HempfestClans; | ||
import me.clip.placeholderapi.expansion.PlaceholderExpansion; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Optional; | ||
|
||
public final class BanksPlaceholders extends PlaceholderExpansion { | ||
|
||
private final Plugin plugin; | ||
private final BanksAPI api; | ||
|
||
public BanksPlaceholders(ClansBanks plugin) { | ||
this.plugin = plugin; | ||
this.api = plugin; | ||
} | ||
|
||
@Override | ||
public boolean persist() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean canRegister() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public @NotNull String getAuthor() { | ||
return plugin.getDescription().getAuthors().toString(); | ||
} | ||
|
||
@Override | ||
public @NotNull String getIdentifier() { | ||
return "clansbanks"; | ||
} | ||
|
||
@Override | ||
public @NotNull String getVersion() { | ||
return plugin.getDescription().getVersion(); | ||
} | ||
|
||
@Override | ||
public String onPlaceholderRequest(Player player, @NotNull String params) { | ||
final Optional<Player> optionalPlayer = Optional.ofNullable(player); | ||
return optionalPlayer.map(p -> { | ||
if ("balance".equals(params)) { | ||
final Optional<BigDecimal> optionalBalance = Optional.ofNullable(HempfestClans.getInstance().playerClan.get(player.getUniqueId())) | ||
.map(s -> HempfestClans.clanManager(player)).map(api::getBank).map(ClanBank::getBalance); | ||
if (optionalBalance.isPresent()) { | ||
return optionalBalance.get().toString(); | ||
} | ||
} | ||
return null; | ||
}).orElse(null); | ||
} | ||
} |
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