Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Allowed any sub-class of Number to be used in MessageConfig
Browse files Browse the repository at this point in the history
Moved percentage sign from locales to MessageConfig
Moved arithmetic precision from MessageManager calls to MessageConfig
Removed locale indexes Messages.speedExact and Messages.jumpExact
  • Loading branch information
Zedd7 committed Apr 7, 2017
1 parent 21911b4 commit 46ec022
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 452 deletions.
10 changes: 4 additions & 6 deletions locale_EN.yml
Expand Up @@ -86,8 +86,8 @@ Messages:
horseWithdrawnFromSale: "<gold><horse><yellow> has been withdrawn from sale."
idsSwapped: "<yellow>The two horse IDs have been swapped."
invalidHealthArgument: "<yellow>The health must be between <gold><amount><yellow> and <gold><max><yellow>."
invalidJumpArgument: "<yellow>The jump strength must be between <gold><amount>%<yellow> and <gold><max>%<yellow>."
invalidSpeedArgument: "<yellow>The speed must be between <gold><amount>%<yellow> and <gold><max>%<yellow>."
invalidJumpArgument: "<yellow>The jump strength must be between <gold><amount><yellow> and <gold><max><yellow>."
invalidSpeedArgument: "<yellow>The speed must be between <gold><amount><yellow> and <gold><max><yellow>."
invalidStrengthArgument: "<yellow>The llama strength must be between <gold><amount><yellow> and <gold><max><yellow>."
languageAlreadyUsed: "<yellow>You are already using the language <gold><lang><yellow>."
languageAlreadyUsedOther: "<gold><player><yellow> is already using the language <gold><lang><yellow>."
Expand Down Expand Up @@ -148,17 +148,15 @@ Economy:
Horse informations:
health: "<yellow>Health : <gold><amount><yellow>/<gold><max>"
id: "<yellow>ID : <gold><id>"
jump: "<yellow>Jump strength : <gold><amount>%"
jumpExact: "<yellow>Jump strength : <gold><value>"
jump: "<yellow>Jump strength : <gold><amount>"
location: "<yellow>Location : <gold><value>"
locked: "[Lo]"
name: "<yellow>Name : <gold><horse>"
owner: "<yellow>Owner : <gold><player>"
price: "<yellow>Price : <gold><currency><amount>"
protected: "[Pr]"
shared: "[Sh]"
speed: "<yellow>Speed : <gold><amount>%"
speedExact: "<yellow>Speed : <gold><value>"
speed: "<yellow>Speed : <gold><amount>"
status: "<yellow>Status : <gold><value>"
strength: "<yellow>Chest size : <gold><amount>"

Expand Down
10 changes: 4 additions & 6 deletions locale_FR.yml
Expand Up @@ -86,8 +86,8 @@ Messages:
horseWithdrawnFromSale: "<gold><horse><yellow> a été retiré de la vente."
idsSwapped: "<yellow>Les deux IDs de cheval ont été échangés."
invalidHealthArgument: "<yellow>La vie doit être comprise entre <gold><amount><yellow> et <gold><max><yellow>."
invalidJumpArgument: "<yellow>La force de saut doit être comprise entre <gold><amount>%<yellow> et <gold><max>%<yellow>."
invalidSpeedArgument: "<yellow>La vitesse doit être comprise entre <gold><amount>%<yellow> et <gold><max>%<yellow>."
invalidJumpArgument: "<yellow>La force de saut doit être comprise entre <gold><amount><yellow> et <gold><max><yellow>."
invalidSpeedArgument: "<yellow>La vitesse doit être comprise entre <gold><amount><yellow> et <gold><max><yellow>."
invalidStrengthArgument: "<yellow>La force du lama doit être comprise entre <gold><amount><yellow> et <gold><max><yellow>."
languageAlreadyUsed: "<yellow>Vous utilisez déjà la langue <gold><lang><yellow>."
languageAlreadyUsedOther: "<gold><player><yellow> utilise déjà la langue <gold><lang><yellow>."
Expand Down Expand Up @@ -148,17 +148,15 @@ Economy:
Horse informations:
health: "<yellow>Santé : <gold><amount><yellow>/<gold><max>"
id: "<yellow>ID : <gold><id>"
jump: "<yellow>Hauteur de saut : <gold><amount>%"
jumpExact: "<yellow>Hauteur de saut : <gold><value>"
jump: "<yellow>Hauteur de saut : <gold><amount>"
location: "<yellow>Position : <gold><value>"
locked: "[Lo]"
name: "<yellow>Nom : <gold><horse>"
owner: "<yellow>Maître : <gold><player>"
price: "<yellow>Prix : <gold><amount><currency>"
protected: "[Pr]"
shared: "[Sh]"
speed: "<yellow>Vitesse : <gold><amount>%"
speedExact: "<yellow>Vitesse : <gold><value>"
speed: "<yellow>Vitesse : <gold><amount>"
status: "<yellow>Statut : <gold><value>"
strength: "<yellow>Taille du coffre : <gold><amount>"

Expand Down
10 changes: 4 additions & 6 deletions locale_NL.yml
Expand Up @@ -88,8 +88,8 @@ Messages:
horseWithdrawnFromSale: "<gold><horse><yellow> has been withdrawn from sale."
idsSwapped: "<yellow>The two horse IDs have been swapped."
invalidHealthArgument: "<yellow>Het aantal levens moet tussen <gold><amount><yellow> en <gold><max><yellow> zijn."
invalidJumpArgument: "<yellow>De spring kracht moet tussen <gold><amount>%<yellow> en <gold><max>%<yellow> zijn."
invalidSpeedArgument: "<yellow>De snelheid moet tussen <gold><amount>%<yellow> en <gold><max>%<yellow> zijn."
invalidJumpArgument: "<yellow>De spring kracht moet tussen <gold><amount><yellow> en <gold><max><yellow> zijn."
invalidSpeedArgument: "<yellow>De snelheid moet tussen <gold><amount><yellow> en <gold><max><yellow> zijn."
invalidStrengthArgument: "<yellow>De lama kracht moet tussen <gold><amount><yellow> en <gold><max><yellow> zijn."
languageAlreadyUsed: "<yellow>Je gebruikt de <gold><lang><yellow>taal al."
languageAlreadyUsedOther: "<gold><player><yellow> gebruikt de <gold><lang><yellow>taal al."
Expand Down Expand Up @@ -150,17 +150,15 @@ Economy:
Horse informations:
health: "<yellow>Levens : <gold><amount><yellow>/<gold><max>"
id: "<yellow>ID : <gold><id>"
jump: "<yellow>Spring kracht : <gold><amount>%"
jumpExact: "<yellow>Spring kracht : <gold><value>"
jump: "<yellow>Spring kracht : <gold><amount>"
location: "<yellow>Locatie : <gold><value>"
locked: "[Gelocked]"
name: "<yellow>Naam : <gold><horse>"
owner: "<yellow>Eigenaar : <gold><player>"
price: "<yellow>Prijs : <gold><amount><currency>"
protected: "[Beschermd]"
shared: "[Gedeeld]"
speed: "<yellow>Snelheid : <gold><amount>%"
speedExact: "<yellow>Snelheid : <gold><value>"
speed: "<yellow>Snelheid : <gold><amount>"
status: "<yellow>Status : <gold><value>"
strength: "<yellow>Opslagruimte : <gold><amount>"

Expand Down
46 changes: 31 additions & 15 deletions src/com/gmail/xibalbazedd/zhorse/commands/AbstractCommand.java
Expand Up @@ -632,15 +632,23 @@ protected boolean isStatSpeedValid(double speed) {

double minSpeed = HorseStatisticEnum.MIN_SPEED.getValue(useVanillaStats);
double maxSpeed = HorseStatisticEnum.MAX_SPEED.getValue(useVanillaStats);
if (!useExactStats && (speed >= (minSpeed / maxSpeed) * 100 && speed <= 100)) {
return true;
}
else if (speed >= minSpeed && speed <= maxSpeed) {
return true;
if (useExactStats) {
if (speed >= minSpeed && speed <= maxSpeed) {
return true;
}
else {
zh.getMM().sendMessage(s, new MessageConfig(LocaleEnum.INVALID_SPEED_ARGUMENT) {{ setAmount(minSpeed); setMax(maxSpeed); setArithmeticPrecision(3); }});
return false;
}
}
else {
zh.getMM().sendMessage(s, new MessageConfig(LocaleEnum.INVALID_SPEED_ARGUMENT) {{ setAmount((int) Math.ceil((minSpeed / maxSpeed) * 100)); setMax(100); }});
return false;
if (speed >= (minSpeed / maxSpeed) * 100 && speed <= 100) {
return true;
}
else {
zh.getMM().sendMessage(s, new MessageConfig(LocaleEnum.INVALID_SPEED_ARGUMENT) {{ setAmount(minSpeed / maxSpeed); setMax(1); setUsePercentage(true); }});
return false;
}
}
}

Expand All @@ -649,15 +657,23 @@ protected boolean isStatJumpStrengthValid(double jumpStrength) {

double minJumpStrength = HorseStatisticEnum.MIN_JUMP_STRENGTH.getValue(useVanillaStats);
double maxJumpStrength = HorseStatisticEnum.MAX_JUMP_STRENGTH.getValue(useVanillaStats);
if (!useExactStats && (jumpStrength >= (minJumpStrength / maxJumpStrength) * 100 && jumpStrength <= 100)) {
return true;
}
else if (jumpStrength >= minJumpStrength && jumpStrength <= maxJumpStrength) {
return true;
if (useExactStats) {
if (jumpStrength >= minJumpStrength && jumpStrength <= maxJumpStrength) {
return true;
}
else {
zh.getMM().sendMessage(s, new MessageConfig(LocaleEnum.INVALID_JUMP_ARGUMENT) {{ setAmount(minJumpStrength); setMax(maxJumpStrength); setArithmeticPrecision(3); }});
return false;
}
}
else {
zh.getMM().sendMessage(s, new MessageConfig(LocaleEnum.INVALID_JUMP_ARGUMENT) {{ setAmount((int) Math.ceil((minJumpStrength / maxJumpStrength) * 100)); setMax(100); }});
return false;
if (jumpStrength >= (minJumpStrength / maxJumpStrength) * 100 && jumpStrength <= 100) {
return true;
}
else {
zh.getMM().sendMessage(s, new MessageConfig(LocaleEnum.INVALID_JUMP_ARGUMENT) {{ setAmount(minJumpStrength / maxJumpStrength); setMax(1); setUsePercentage(true); }});
return false;
}
}
}

Expand Down Expand Up @@ -828,7 +844,7 @@ protected void sendAbstractHorseVariantList() {
sendHorseOptionList(HorseVariantEnum.getAllCodeArray(), LocaleEnum.LIST_HORSE_VARIANT);
}

protected <T> void sendHorseOptionList (T[] horseOptionArray, LocaleEnum index) {
protected <T> void sendHorseOptionList(T[] horseOptionArray, LocaleEnum index) {
String horseOptionArrayMessage = "";
for (int i = 0; i < horseOptionArray.length; i++) {
final String horseOption = horseOptionArray[i].toString().toLowerCase();
Expand Down
19 changes: 8 additions & 11 deletions src/com/gmail/xibalbazedd/zhorse/commands/CommandInfo.java
@@ -1,6 +1,5 @@
package com.gmail.xibalbazedd.zhorse.commands;

import java.util.Locale;
import java.util.UUID;

import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -104,28 +103,26 @@ public static void displayHealth(ZHorse zh, CommandSender s, HorseStatsRecord st
}

public static void displaySpeed(ZHorse zh, CommandSender s, HorseStatsRecord statsRecord, boolean useExactStats, boolean useVanillaStats) {
double speed = statsRecord.getSpeed();
Double speed = statsRecord.getSpeed();
if (!useExactStats) {
double maxSpeed = HorseStatisticEnum.MAX_SPEED.getValue(useVanillaStats);
int speedRatio = (int) ((speed / maxSpeed) * 100);
zh.getMM().sendMessage(s, new MessageConfig(LocaleEnum.SPEED) {{ setAmount(speedRatio); setSpaceCount(1); }}, true);
double speedRatio = speed / maxSpeed;
zh.getMM().sendMessage(s, new MessageConfig(LocaleEnum.SPEED) {{ setAmount(speedRatio); setSpaceCount(1); setUsePercentage(true); }}, true);
}
else {
String speedInfo = String.format(Locale.US, "%.3f", speed);
zh.getMM().sendMessage(s, new MessageConfig(LocaleEnum.SPEED_EXACT) {{ setSpaceCount(1); setValue(speedInfo); }}, true);
zh.getMM().sendMessage(s, new MessageConfig(LocaleEnum.SPEED) {{ setAmount(speed); setSpaceCount(1); setArithmeticPrecision(3); }}, true);
}
}

public static void displayJumpStrength(ZHorse zh, CommandSender s, HorseStatsRecord statsRecord, boolean useExactStats, boolean useVanillaStats) {
double jumpStrength = statsRecord.getJumpStrength();
Double jumpStrength = statsRecord.getJumpStrength();
if (!useExactStats) {
double maxJumpStrength = HorseStatisticEnum.MAX_JUMP_STRENGTH.getValue(useVanillaStats);
int jumpRatio = (int) ((jumpStrength / maxJumpStrength) * 100);
zh.getMM().sendMessage(s, new MessageConfig(LocaleEnum.JUMP) {{ setAmount(jumpRatio); setSpaceCount(1); }}, true);
double jumpRatio = jumpStrength / maxJumpStrength;
zh.getMM().sendMessage(s, new MessageConfig(LocaleEnum.JUMP) {{ setAmount(jumpRatio); setSpaceCount(1); setUsePercentage(true); }}, true);
}
else {
String jumpInfo = String.format(Locale.US, "%.3f", jumpStrength);
zh.getMM().sendMessage(s, new MessageConfig(LocaleEnum.JUMP_EXACT) {{ setSpaceCount(1); setValue(jumpInfo); }}, true);
zh.getMM().sendMessage(s, new MessageConfig(LocaleEnum.JUMP) {{ setAmount(jumpStrength); setSpaceCount(1); setArithmeticPrecision(3); }}, true);
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/com/gmail/xibalbazedd/zhorse/commands/CommandSpawn.java
Expand Up @@ -221,25 +221,25 @@ private boolean parseStats(String argument) {
if (speedStat != null) {
valid &= isStatSpeedValid(speedStat);
if (valid) {
if (!useExactStats) {
double maxSpeed = HorseStatisticEnum.MAX_SPEED.getValue(useVanillaStats);
speed = (speedStat * maxSpeed) / 100;
if (useExactStats) {
speed = speedStat;
}
else {
speed = speedStat;
double maxSpeed = HorseStatisticEnum.MAX_SPEED.getValue(useVanillaStats);
speed = (speedStat * maxSpeed) / 100;
}
}
}
Double jumpStat = stats[2];
if (jumpStat != null) {
valid &= isStatJumpStrengthValid(jumpStat);
if (valid) {
if (!useExactStats) {
double maxJumpStrength = HorseStatisticEnum.MAX_JUMP_STRENGTH.getValue(useVanillaStats);
jumpStrength = (jumpStat * maxJumpStrength) / 100;
if (useExactStats) {
jumpStrength = jumpStat;
}
else {
jumpStrength = jumpStat;
double maxJumpStrength = HorseStatisticEnum.MAX_JUMP_STRENGTH.getValue(useVanillaStats);
jumpStrength = (jumpStat * maxJumpStrength) / 100;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/com/gmail/xibalbazedd/zhorse/enums/LocaleEnum.java
Expand Up @@ -146,7 +146,6 @@ public enum LocaleEnum {
HEALTH("Horse informations.health"),
ID("Horse informations.id"),
JUMP("Horse informations.jump"),
JUMP_EXACT("Horse informations.jumpExact"),
LOCATION("Horse informations.location"),
LOCKED("Horse informations.locked"),
NAME("Horse informations.name"),
Expand All @@ -155,7 +154,6 @@ public enum LocaleEnum {
PROTECTED("Horse informations.protected"),
SHARED("Horse informations.shared"),
SPEED("Horse informations.speed"),
SPEED_EXACT("Horse informations.speedExact"),
STATUS("Horse informations.status"),
STRENGTH("Horse informations.strength"),

Expand Down

0 comments on commit 46ec022

Please sign in to comment.