mirror of
https://github.com/itHotL/PlayerStats.git
synced 2024-11-10 10:10:47 +01:00
Merged different StatResult classes into one typed record
This commit is contained in:
parent
e4fca5a0c8
commit
b46a25d23f
@ -18,7 +18,7 @@ import java.util.Arrays;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class InternalStatRequest extends StatRequest<Object> {
|
||||
public final class InternalStatRequest extends StatRequest<Object> {
|
||||
|
||||
private final OfflinePlayerHandler offlinePlayerHandler;
|
||||
private final EnumHandler enumHandler;
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.artemis.the.gr8.playerstats.statistic.request;
|
||||
|
||||
import com.artemis.the.gr8.playerstats.Main;
|
||||
import com.artemis.the.gr8.playerstats.statistic.result.PlayerStatResult;
|
||||
import com.artemis.the.gr8.playerstats.api.RequestGenerator;
|
||||
import com.artemis.the.gr8.playerstats.msg.components.ComponentUtils;
|
||||
import com.artemis.the.gr8.playerstats.statistic.result.StatResult;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -39,11 +39,7 @@ public final class PlayerStatRequest extends StatRequest<Integer> implements Req
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerStatResult execute() {
|
||||
return getStatResult();
|
||||
}
|
||||
|
||||
private PlayerStatResult getStatResult() {
|
||||
public @NotNull StatResult<Integer> execute() {
|
||||
int stat = Main
|
||||
.getStatCalculator()
|
||||
.getPlayerStat(settings);
|
||||
@ -56,6 +52,6 @@ public final class PlayerStatRequest extends StatRequest<Integer> implements Req
|
||||
.getTranslatableComponentSerializer()
|
||||
.serialize(prettyComponent);
|
||||
|
||||
return new PlayerStatResult(stat, prettyComponent, prettyString);
|
||||
return new StatResult<>(stat, prettyComponent, prettyString);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package com.artemis.the.gr8.playerstats.statistic.request;
|
||||
|
||||
import com.artemis.the.gr8.playerstats.Main;
|
||||
import com.artemis.the.gr8.playerstats.statistic.result.ServerStatResult;
|
||||
import com.artemis.the.gr8.playerstats.api.RequestGenerator;
|
||||
import com.artemis.the.gr8.playerstats.msg.components.ComponentUtils;
|
||||
import com.artemis.the.gr8.playerstats.statistic.result.StatResult;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -39,11 +39,7 @@ public final class ServerStatRequest extends StatRequest<Long> implements Reques
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerStatResult execute() {
|
||||
return getStatResult();
|
||||
}
|
||||
|
||||
private ServerStatResult getStatResult() {
|
||||
public @NotNull StatResult<Long> execute() {
|
||||
long stat = Main
|
||||
.getStatCalculator()
|
||||
.getServerStat(settings);
|
||||
@ -56,6 +52,6 @@ public final class ServerStatRequest extends StatRequest<Long> implements Reques
|
||||
.getTranslatableComponentSerializer()
|
||||
.serialize(prettyComponent);
|
||||
|
||||
return new ServerStatResult(stat, prettyComponent, prettyString);
|
||||
return new StatResult<>(stat, prettyComponent, prettyString);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.artemis.the.gr8.playerstats.statistic.request;
|
||||
|
||||
import com.artemis.the.gr8.playerstats.Main;
|
||||
import com.artemis.the.gr8.playerstats.statistic.result.TopStatResult;
|
||||
import com.artemis.the.gr8.playerstats.statistic.result.StatResult;
|
||||
import com.artemis.the.gr8.playerstats.api.RequestGenerator;
|
||||
import com.artemis.the.gr8.playerstats.msg.components.ComponentUtils;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
@ -41,11 +41,7 @@ public final class TopStatRequest extends StatRequest<LinkedHashMap<String, Inte
|
||||
}
|
||||
|
||||
@Override
|
||||
public TopStatResult execute() {
|
||||
return getStatResult();
|
||||
}
|
||||
|
||||
private TopStatResult getStatResult() {
|
||||
public @NotNull StatResult<LinkedHashMap<String, Integer>> execute() {
|
||||
LinkedHashMap<String, Integer> stat = Main
|
||||
.getStatCalculator()
|
||||
.getTopStats(settings);
|
||||
@ -58,6 +54,6 @@ public final class TopStatRequest extends StatRequest<LinkedHashMap<String, Inte
|
||||
.getTranslatableComponentSerializer()
|
||||
.serialize(prettyComponent);
|
||||
|
||||
return new TopStatResult(stat, prettyComponent, prettyString);
|
||||
return new StatResult<>(stat, prettyComponent, prettyString);
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ import net.kyori.adventure.text.TextComponent;
|
||||
* This Record is used to store stat-results internally,
|
||||
* so Players can share them by clicking a share-button.
|
||||
*/
|
||||
public record InternalStatResult(String executorName, TextComponent formattedValue, int ID) implements StatResult<Integer> {
|
||||
public record InternalStatResult(String executorName, TextComponent formattedValue, int ID) {
|
||||
|
||||
/**
|
||||
* Gets the ID number for this StatResult. Unlike for the
|
||||
@ -19,17 +19,14 @@ public record InternalStatResult(String executorName, TextComponent formattedVal
|
||||
*
|
||||
@return Integer that represents this StatResult's ID number
|
||||
*/
|
||||
@Override
|
||||
public Integer getNumericalValue() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextComponent getFormattedTextComponent() {
|
||||
return formattedValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormattedString() {
|
||||
return ComponentUtils.getTranslatableComponentSerializer()
|
||||
.serialize(formattedValue);
|
||||
|
@ -1,21 +0,0 @@
|
||||
package com.artemis.the.gr8.playerstats.statistic.result;
|
||||
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
|
||||
public record PlayerStatResult(int value, TextComponent formattedComponent, String formattedString) implements StatResult<Integer> {
|
||||
|
||||
@Override
|
||||
public Integer getNumericalValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextComponent getFormattedTextComponent() {
|
||||
return formattedComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormattedString() {
|
||||
return formattedString;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.artemis.the.gr8.playerstats.statistic.result;
|
||||
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
|
||||
public record ServerStatResult(long value, TextComponent formattedComponent, String formattedString) implements StatResult<Long> {
|
||||
|
||||
@Override
|
||||
public Long getNumericalValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextComponent getFormattedTextComponent() {
|
||||
return formattedComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormattedString() {
|
||||
return formattedString;
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ import net.kyori.adventure.text.TextComponent;
|
||||
* <br> [2.] [player-name] [.....] [formatted-number]
|
||||
* <br> [3.] etc...
|
||||
* </ul>
|
||||
|
||||
* <p>
|
||||
* By default, the resulting message is a {@link TextComponent}, which can be
|
||||
* sent directly to a Minecraft client or console with the Adventure library.
|
||||
* To send a Component, you need to get a {@link BukkitAudiences} object,
|
||||
@ -35,44 +35,46 @@ import net.kyori.adventure.text.TextComponent;
|
||||
* on how to get and use the BukkitAudiences object can be found on
|
||||
* <a href="https://docs.adventure.kyori.net/platform/bukkit.html">Adventure's website</a>.
|
||||
*
|
||||
* <p>You can also use the provided {@link #getFormattedString()} method to get the
|
||||
* <p>You can also use the provided {@link #formattedString ()} method to get the
|
||||
* same information in String-format. Don't use Adventure's <code>#content()</code>
|
||||
* or <code>#toString()</code> methods on the Components - those won't get the actual
|
||||
* message. And finally, if you want the results to be formatted differently,
|
||||
* you can get an instance of the {@link ApiFormatter}.
|
||||
*/
|
||||
public interface StatResult<T> {
|
||||
public record StatResult<T>(T value, TextComponent formattedComponent, String formattedString) {
|
||||
|
||||
/**
|
||||
* Gets the raw number for the completed stat-lookup this {@link StatResult}
|
||||
* stores.
|
||||
* Gets the raw number for the completed stat-lookup this {@link StatResult} stores.
|
||||
*
|
||||
* @return {@code Integer} for playerStat, {@code Long} for serverStat,
|
||||
* and {@code LinkedHashMap<String, Integer>} for topStat
|
||||
* @return {@code Integer} for playerStat, {@code Long} for serverStat, and {@code LinkedHashMap<String, Integer>}
|
||||
* for topStat
|
||||
*/
|
||||
T getNumericalValue();
|
||||
T getNumericalValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the formatted message for the completed stat-lookup this
|
||||
* StatResult stores.
|
||||
|
||||
* @return a {@code TextComponent} message containing the formatted number.
|
||||
* This message follows the same style/color/language settings that are
|
||||
* specified in the PlayerStats config. See class description for more
|
||||
* Gets the formatted message for the completed stat-lookup this StatResult stores.
|
||||
*
|
||||
* @return a {@code TextComponent} message containing the formatted number. This message follows the same
|
||||
* style/color/language settings that are specified in the PlayerStats config. See class description for more
|
||||
* information.
|
||||
* @see StatResult
|
||||
*/
|
||||
TextComponent getFormattedTextComponent();
|
||||
TextComponent getFormattedTextComponent() {
|
||||
return formattedComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the formatted message for the completed stat-lookup this
|
||||
* StatResult stores.
|
||||
|
||||
* @return a String message containing the formatted number. This message
|
||||
* follows the same style and color settings that are specified in the
|
||||
* PlayerStats config, but it is not translatable (it is always plain English).
|
||||
* See class description for more information.
|
||||
* Gets the formatted message for the completed stat-lookup this StatResult stores.
|
||||
*
|
||||
* @return a String message containing the formatted number. This message follows the same style and color settings
|
||||
* that are specified in the PlayerStats config, but it is not translatable (it is always plain English). See class
|
||||
* description for more information.
|
||||
* @see StatResult
|
||||
*/
|
||||
String getFormattedString();
|
||||
@Override
|
||||
public String formattedString() {
|
||||
return formattedString;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.artemis.the.gr8.playerstats.statistic.result;
|
||||
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public record TopStatResult(LinkedHashMap<String, Integer> value, TextComponent formattedComponent, String formattedString) implements StatResult<LinkedHashMap<String,Integer>> {
|
||||
|
||||
@Override
|
||||
public LinkedHashMap<String, Integer> getNumericalValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextComponent getFormattedTextComponent() {
|
||||
return formattedComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormattedString() {
|
||||
return formattedString;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user