Skip to content

Commit

Permalink
Add %LEVELS% to xp display option, translate color codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Trophonix committed Jul 9, 2020
1 parent 58483e3 commit 6753987
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

<groupId>com.trophonix</groupId>
<artifactId>TradePlus</artifactId>
<version>3.73</version>
<version>3.74</version>

<properties>
<res>${project.basedir}/res/</res>
<revision>3.73.2</revision>
<revision>3.74</revision>
</properties>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ public ConfigMessage(ConfigurationSection yml, String key, String defaultText) {
}

public void send(CommandSender player, String... replacements) {
String hover = this.onHover;
if (hover != null) for (int i = 0; i < replacements.length - 1; i += 2) {
hover = hover.replace(replacements[i], replacements[i + 1]);
}
for (String line : message) {
for (int i = 0; i < replacements.length - 1; i += 2) {
line = line.replace(replacements[i], replacements[i + 1]);
}
if (onHover == null && onClick == null) {
player.sendMessage(line);
} else {
MsgUtils.send((Player) player, onHover, onClick, line);
MsgUtils.send((Player) player, hover, onClick, line);
}
}
}
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/com/trophonix/tradeplus/config/TradePlusConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ public void reload() {
guiCancelModelData = config.getInt("gui.cancel.customModelData", 0);
guiSeparatorModelData = config.getInt("gui.separator.customModelData", 0);

extrasTypePrefix = config.getString("extras.type.prefix", "&6&l!!&6> ");
extrasTypeEmpty = config.getString("extras.type.empty", "&eHow much %EXTRA% to offer?");
extrasTypeValid = config.getString("extras.type.valid", "&aClick output slot to submit offer.");
extrasTypeInvalid = config.getString("extras.type.invalid", "&cInvalid amount entered!");
extrasTypeMaximum = config.getString("extras.type.maximum", "&cYou have %BALANCE% %EXTRA%");
extrasTypePrefix = ChatColor.translateAlternateColorCodes('&', config.getString("extras.type.prefix", "&6&l!!&6> "));
extrasTypeEmpty = ChatColor.translateAlternateColorCodes('&', config.getString("extras.type.empty", "&eHow much %EXTRA% to offer?"));
extrasTypeValid = ChatColor.translateAlternateColorCodes('&', config.getString("extras.type.valid", "&aClick output slot to submit offer."));
extrasTypeInvalid = ChatColor.translateAlternateColorCodes('&', config.getString("extras.type.invalid", "&cInvalid amount entered!"));
extrasTypeMaximum = ChatColor.translateAlternateColorCodes('&', config.getString("extras.type.maximum", "&cYou have %BALANCE% %EXTRA%"));

factionsAllowTradeInEnemyTerritory = config.getBoolean("hooks.factions.allow-trades-in-enemy-territory", false);
worldguardTradingFlag = config.getBoolean("hooks.worldguard.trading-flag", true);
Expand Down Expand Up @@ -365,7 +365,7 @@ public void loadConfig() {
config.set("extras.experience.name", "experience points");
config.set(
"extras.experience.material", Sounds.version < 113 ? "exp_bottle" : "experience_bottle");
config.set("extras.experience.display", "&aYour current XP offer is &2%AMOUNT%");
config.set("extras.experience.display", "&aYour current XP offer is &2%AMOUNT% &c(%LEVELS% levels)");
config.set(
"extras.experience.theirdisplay",
"&aTheir current XP offer is &2%AMOUNT% &a(+%LEVELS% levels)");
Expand Down Expand Up @@ -1103,6 +1103,13 @@ public void update() {
if (!lang.isString("errors.same-ip")) lang.set("errors.same-ip", "&4&l(!) &4Players aren't allowed to trade on same IP!");
}

if (configVersion < 3.74) {
String xpDisplay = config.getString("extras.experience.display", "&aYour current XP offer is &2%AMOUNT%");
if (!xpDisplay.contains("%LEVELS%")) {
config.set("extras.experience.display", xpDisplay + " &c(%LEVELS% levels)");
}
}

config.set("configversion", Double.parseDouble(plugin.getDescription().getVersion()));
}
}
14 changes: 10 additions & 4 deletions src/main/java/com/trophonix/tradeplus/extras/ExperienceExtra.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ public ItemStack _getIcon(Player player) {
"%INCREMENT%",
decimalFormat.format(increment),
"%PLAYERINCREMENT%",
decimalFormat.format(player.equals(player1) ? increment1 : increment2));
decimalFormat.format(player.equals(player1) ? increment1 : increment2),
"%LEVELS%",
Integer.toString(
player.equals(player1)
? getLevelChangeFromXp(player1, -value1)
: getLevelChangeFromXp(player2, -value2)
));
}

@Override
Expand All @@ -60,11 +66,11 @@ public ItemStack _getTheirIcon(Player player) {
"%LEVELS%",
Integer.toString(
player.equals(player1)
? getLevelsFromXp(player2, value1)
: getLevelsFromXp(player1, value2)));
? getLevelChangeFromXp(player2, value1)
: getLevelChangeFromXp(player1, value2)));
}

private int getLevelsFromXp(Player receiver, double amount) {
private int getLevelChangeFromXp(Player receiver, double amount) {
int currentXp = XP.getExp(receiver);
double currentLevel = XP.getLevelFromExp(currentXp);
return (int) (XP.getLevelFromExp(currentXp + (int) amount) - currentLevel);
Expand Down

0 comments on commit 6753987

Please sign in to comment.