-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PlaceholderAPI support with the
%azlink_money%
placeholder
- Loading branch information
1 parent
41a5336
commit 231fb68
Showing
8 changed files
with
134 additions
and
1 deletion.
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
75 changes: 75 additions & 0 deletions
75
bukkit/src/main/java/com/azuriom/azlink/bukkit/integrations/MoneyPlaceholderExpansion.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,75 @@ | ||
package com.azuriom.azlink.bukkit.integrations; | ||
|
||
import com.azuriom.azlink.bukkit.AzLinkBukkitPlugin; | ||
import me.clip.placeholderapi.expansion.PlaceholderExpansion; | ||
import org.bukkit.OfflinePlayer; | ||
|
||
import java.text.DecimalFormat; | ||
import java.text.DecimalFormatSymbols; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
public class MoneyPlaceholderExpansion extends PlaceholderExpansion { | ||
|
||
private static final DecimalFormat FORMATTER = createDecimalFormat(); | ||
|
||
private final AzLinkBukkitPlugin plugin; | ||
|
||
public MoneyPlaceholderExpansion(AzLinkBukkitPlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return this.plugin.getName(); | ||
} | ||
|
||
@Override | ||
public String getAuthor() { | ||
return String.join(", ", this.plugin.getDescription().getAuthors()); | ||
} | ||
|
||
@Override | ||
public String getIdentifier() { | ||
return "azlink"; | ||
} | ||
|
||
@Override | ||
public String getVersion() { | ||
return this.plugin.getPluginVersion(); | ||
} | ||
|
||
@Override | ||
public List<String> getPlaceholders() { | ||
return Collections.singletonList("%azlink_money%"); | ||
} | ||
|
||
@Override | ||
public boolean persist() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String onRequest(OfflinePlayer player, String params) { | ||
if (params.equalsIgnoreCase("money")) { | ||
return this.plugin.getPlugin() | ||
.getUser(player.getName()) | ||
.map(user -> FORMATTER.format(user.getMoney())) | ||
.orElse("?"); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static void enable(AzLinkBukkitPlugin plugin) { | ||
if (new MoneyPlaceholderExpansion(plugin).register()) { | ||
plugin.getLogger().info("PlaceholderAPI expansion enabled"); | ||
} | ||
} | ||
|
||
private static DecimalFormat createDecimalFormat() { | ||
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(Locale.ROOT); | ||
return new DecimalFormat("0.##", symbols); | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
common/src/main/java/com/azuriom/azlink/common/data/UserInfo.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,20 @@ | ||
package com.azuriom.azlink.common.data; | ||
|
||
public class UserInfo { | ||
|
||
private final String name; | ||
private final double money; | ||
|
||
public UserInfo(String name, double money) { | ||
this.name = name; | ||
this.money = money; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public double getMoney() { | ||
return money; | ||
} | ||
} |
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