-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added placeholders to show the total sum of all players on a board
- Loading branch information
1 parent
03d1c50
commit c4b8fae
Showing
6 changed files
with
209 additions
and
2 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
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
32 changes: 32 additions & 0 deletions
32
src/main/java/us/ajg0702/leaderboards/placeholders/placeholders/Total.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,32 @@ | ||
package us.ajg0702.leaderboards.placeholders.placeholders; | ||
|
||
import org.bukkit.OfflinePlayer; | ||
import us.ajg0702.leaderboards.LeaderboardPlugin; | ||
import us.ajg0702.leaderboards.boards.TimedType; | ||
import us.ajg0702.leaderboards.placeholders.Placeholder; | ||
|
||
import java.util.Locale; | ||
import java.util.regex.Matcher; | ||
|
||
public class Total extends Placeholder { | ||
public Total(LeaderboardPlugin plugin) { | ||
super(plugin); | ||
} | ||
|
||
@Override | ||
public String getRegex() { | ||
return "total_(.*)_(.*)"; | ||
} | ||
|
||
@Override | ||
public String parse(Matcher matcher, OfflinePlayer p) { | ||
String board = matcher.group(1); | ||
String typeRaw = matcher.group(2).toUpperCase(Locale.ROOT); | ||
TimedType type = TimedType.of(typeRaw); | ||
if(type == null) { | ||
return "Invalid TimedType '" + typeRaw + "'"; | ||
} | ||
double total = plugin.getTopManager().getTotal(board, type); | ||
return plugin.getPlaceholderFormatter().toFormat(total, board); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/us/ajg0702/leaderboards/placeholders/placeholders/TotalFormatted.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,34 @@ | ||
package us.ajg0702.leaderboards.placeholders.placeholders; | ||
|
||
import org.bukkit.OfflinePlayer; | ||
import us.ajg0702.leaderboards.LeaderboardPlugin; | ||
import us.ajg0702.leaderboards.boards.TimedType; | ||
import us.ajg0702.leaderboards.placeholders.Placeholder; | ||
|
||
import java.util.Locale; | ||
import java.util.regex.Matcher; | ||
|
||
import static us.ajg0702.leaderboards.boards.StatEntry.formatDouble; | ||
|
||
public class TotalFormatted extends Placeholder { | ||
public TotalFormatted(LeaderboardPlugin plugin) { | ||
super(plugin); | ||
} | ||
|
||
@Override | ||
public String getRegex() { | ||
return "total_(.*)_(.*)_formatted"; | ||
} | ||
|
||
@Override | ||
public String parse(Matcher matcher, OfflinePlayer p) { | ||
String board = matcher.group(1); | ||
String typeRaw = matcher.group(2).toUpperCase(Locale.ROOT); | ||
TimedType type = TimedType.of(typeRaw); | ||
if(type == null) { | ||
return "Invalid TimedType '" + typeRaw + "'"; | ||
} | ||
double total = plugin.getTopManager().getTotal(board, type); | ||
return formatDouble(total); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/us/ajg0702/leaderboards/placeholders/placeholders/TotalRaw.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,34 @@ | ||
package us.ajg0702.leaderboards.placeholders.placeholders; | ||
|
||
import org.bukkit.OfflinePlayer; | ||
import us.ajg0702.leaderboards.LeaderboardPlugin; | ||
import us.ajg0702.leaderboards.boards.TimedType; | ||
import us.ajg0702.leaderboards.placeholders.Placeholder; | ||
|
||
import java.text.DecimalFormat; | ||
import java.util.Locale; | ||
import java.util.regex.Matcher; | ||
|
||
public class TotalRaw extends Placeholder { | ||
public TotalRaw(LeaderboardPlugin plugin) { | ||
super(plugin); | ||
} | ||
|
||
@Override | ||
public String getRegex() { | ||
return "total_(.*)_(.*)_raw"; | ||
} | ||
|
||
@Override | ||
public String parse(Matcher matcher, OfflinePlayer p) { | ||
String board = matcher.group(1); | ||
String typeRaw = matcher.group(2).toUpperCase(Locale.ROOT); | ||
TimedType type = TimedType.of(typeRaw); | ||
if(type == null) { | ||
return "Invalid TimedType '" + typeRaw + "'"; | ||
} | ||
double total = plugin.getTopManager().getTotal(board, type); | ||
DecimalFormat df = new DecimalFormat("#.##"); | ||
return df.format(total); | ||
} | ||
} |