Skip to content

Commit

Permalink
Replace all legacy color codes by components
Browse files Browse the repository at this point in the history
  • Loading branch information
RappyTV committed Aug 18, 2023
1 parent 91853c3 commit a936901
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 54 deletions.
12 changes: 9 additions & 3 deletions core/src/main/java/com/rappytv/toolwarn/TbwAddon.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
package com.rappytv.toolwarn;

import com.rappytv.toolwarn.commands.TbwCommand;
import com.rappytv.toolwarn.config.TbwConfiguration;
import com.rappytv.toolwarn.core.generated.DefaultReferenceStorage;
import com.rappytv.toolwarn.listener.GameTickListener;
import com.rappytv.toolwarn.util.ITbwSounds;
import net.labymod.api.addon.LabyAddon;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;
import net.labymod.api.client.component.format.Style;
import net.labymod.api.client.component.format.TextDecoration;
import net.labymod.api.models.addon.annotation.AddonMain;

@AddonMain
public class TbwAddon extends LabyAddon<TbwConfiguration> {

public static final String prefix = "§c§lTBW §8» §7";
public static Component prefix;
private static ITbwSounds sounds;

@Override
protected void enable() {
// "§c§lTBW §8» §7"
prefix = Component
.text("TBW ", Style.builder().color(NamedTextColor.RED).decorate(TextDecoration.BOLD).build())
.append(Component.text("» ", NamedTextColor.DARK_GRAY));
sounds = ((DefaultReferenceStorage) this.referenceStorageAccessor()).iTbwSounds();
registerSettingCategory();

registerCommand(new TbwCommand(this));
registerListener(new GameTickListener(this));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public class TbwConfiguration extends AddonConfig {
@SwitchSetting
@SpriteSlot(size = 32, x = 3)
private final ConfigProperty<Boolean> lastHit = new ConfigProperty<>(true);
@SwitchSetting
@SpriteSlot(size = 32, y = 1)
private final ConfigProperty<Boolean> debug = new ConfigProperty<>(false);

@SettingSection("sounds")
@SpriteSlot(size = 32, y = 1, x = 1)
Expand Down Expand Up @@ -62,9 +59,6 @@ public ConfigProperty<Boolean> format() {
public ConfigProperty<Boolean> lastHit() {
return lastHit;
}
public ConfigProperty<Boolean> debug() {
return debug;
}

public TbwSoundSubConfig sounds() {
return sounds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import com.rappytv.toolwarn.util.Util;
import com.rappytv.toolwarn.util.WarnSound;
import net.labymod.api.Laby;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;
import net.labymod.api.client.entity.player.ClientPlayer;
import net.labymod.api.client.entity.player.GameMode;
import net.labymod.api.client.world.item.ItemStack;
import net.labymod.api.event.Subscribe;
import net.labymod.api.event.client.lifecycle.GameTickEvent;
import net.labymod.api.util.I18n;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -46,13 +47,11 @@ public void toolUsed(ItemStack itemStack, ToolType toolType) {

int itemWarnInt = (toolType.getWarnPercentage(config) * itemStack.getMaximumDamage()) / 100;
int itemUsedInt = itemStack.getMaximumDamage() - itemStack.getCurrentDamageValue();
if(config.debug().get())
Util.msg(I18n.translate("toolwarn.messages.debug", toolType.displayName(), (config.format().get() ? Util.formatNumber(itemStack.getMaximumDamage()) : itemStack.getMaximumDamage()), (config.format().get() ? Util.formatNumber(itemUsedInt) : itemUsedInt), (config.format().get() ? Util.formatNumber(itemWarnInt) : itemWarnInt)), false);

if(itemUsedInt == itemWarnInt) {
if(!warns.contains(itemStack)) {
if(this.config.openChat().get()) Laby.labyAPI().minecraft().openChat("");
Util.msg(I18n.getTranslation("toolwarn.messages.warning", toolType.getWarnPercentage(config)), true);
Util.msg(Component.translatable("toolwarn.messages.warning", NamedTextColor.RED, Component.text(toolType.getWarnPercentage(config))), true);
warns.add(itemStack);

if(config.sounds().enabled().get() && config.sounds().warnSound().get() != WarnSound.NONE) {
Expand All @@ -66,7 +65,7 @@ public void toolUsed(ItemStack itemStack, ToolType toolType) {
} else if(isLastHit(itemStack)) {
if(!warns.contains(itemStack)) {
if(this.config.openChat().get()) Laby.labyAPI().minecraft().openChat("");
Util.msg(I18n.translate("toolwarn.messages.lastHit"), true);
Util.msg(Component.translatable("toolwarn.messages.lastHit", NamedTextColor.RED), true);
warns.add(itemStack);

if(config.sounds().enabled().get() && config.sounds().lastHitSound().get() != WarnSound.NONE) {
Expand Down
9 changes: 7 additions & 2 deletions core/src/main/java/com/rappytv/toolwarn/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

import com.rappytv.toolwarn.TbwAddon;
import net.labymod.api.Laby;
import net.labymod.api.client.component.Component;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Locale;

public class Util {

public static void msg(String text, boolean prefix) {
Laby.references().chatExecutor().displayClientMessage(prefix ? TbwAddon.prefix + text : text);
public static void msg(Component component, boolean prefix) {
Component message = Component.empty();
if(prefix)
message.append(TbwAddon.prefix);
message.append(component);
Laby.references().chatExecutor().displayClientMessage(message);
}

public static String formatNumber(int number) {
Expand Down
21 changes: 2 additions & 19 deletions core/src/main/resources/assets/toolwarn/i18n/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,8 @@
"shovel": "Schaufel"
},
"messages": {
"lastHit": "§cDu solltest das Tool jetzt weglegen. Das ist dein letzter Schlag!",
"warning": "§cWillst du das Tool wirklich weiter benutzen? Die Haltbarkeit liegt bei %s%%!",
"debug": "§e§m §e§l[ Event ausgelöst ]§e§m \n§7Event: §b%s in Haupthand\n§7Maximale Haltbarkeit: §b%s\n§7Aktuelle Haltbarkeit: §b%s\n§7Warnungshaltbarkeit: §b%s\n§e§m "
},
"command": {
"invalidSubcommand": "§cBitte gib einen gültigen Subcommand an! [disable, format, debug, config]",
"onOff": "§cBitte gib ein gültiges Argument an! [on, off]",
"onOnceOff": "§cBitte gib ein gültiges Argument an! arguments: [on, once, off]",
"addonEnabled": "§7Addon erfolgreich §aaktiviert§7!",
"addonDisabled": "§7Addon erfolgreich §cdeaktiviert§7!",
"formattingEnabled": "§7Nummerformatierungen erfolgreich §aaktiviert§7!",
"formattingDisabled": "§7Nummerformatierungen erfolgreich §cdeaktiviert§7!",
"debugEnabled": "§7Debug Modus erfolgreich §aaktiviert§7!",
"debugDisabled": "§7Debug Modus erfolgreich §cdeaktiviert§7!",
"debugOnce": "§7Debug Modus erfolgreich einmalig §aaktiviert§7)!",
"noEventTriggered": "§e§m §e§l[ Kein Event ausgelöst ]§e§m \n§7Event: §8-\n§7Maximale Haltbarkeit: §8-\n§7Aktuelle Haltbarkeit: §8-\n§7Warnungshaltbarkeit: §8-\n§e§m ",
"config": "§e§m §e§l[ Config ]§e§m \n§7%s: %s\n§7%s: %s\n§7%s: %s\n§7%s: %s\n§7%s: §b%s\n§7%s: §b%s\n§7%s: §b%s\n§7%s: §b%s\n§e§m ",
"yes": "Ja",
"no": "Nein"
"lastHit": "Du solltest das Tool jetzt weglegen. Das ist dein letzter Schlag!",
"warning": "Willst du das Tool wirklich weiter benutzen? Die Haltbarkeit liegt bei %s%%!"
}
}
}
21 changes: 2 additions & 19 deletions core/src/main/resources/assets/toolwarn/i18n/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,8 @@
"shovel": "Shovel"
},
"messages": {
"lastHit": "§cYou should stop using this tool now, this is your last hit!",
"warning": "§cDo you really want to continue using this tool? Its durability is at %s%%!",
"debug": "§e§m §e§l[ Event triggered ]§e§m \n§7Event: §b%s in main hand\n§7Max durability: §b%s\n§7Current durability: §b%s\n§7Warn durability: §b%s\n§e§m "
},
"command": {
"invalidSubcommand": "§cPlease provide a valid subcommand! [disable, format, debug, config]",
"onOff": "§cPlease provide a valid argument! [on, off]",
"onOnceOff": "§cPlease provide a valid argument! [on, once, off]",
"addonEnabled": "§7Addon successfully §aenabled§7!",
"addonDisabled": "§7Addon successfully §cdisabled§7!",
"formattingEnabled": "§7Number formatting successfully §aenabled§7!",
"formattingDisabled": "§7Number formatting successfully §cdisabled§7!",
"debugEnabled": "§7Debug mode successfully §aenabled§7!",
"debugDisabled": "§7Debug mode successfully §cdisabled§7!",
"debugOnce": "§7Debug mode successfully §aenabled §7once!",
"noEventTriggered": "§e§m §e§l[ No event triggered ]§e§m \n§7Event: §8-\n§7Max durability: §8-\n§7Current durability: §8-\n§7Warn durability: §8-\n§e§m ",
"config": "§e§m §e§l[ Config ]§e§m \n§7%s: %s\n§7%s: %s\n§7%s: %s\n§7%s: %s\n§7%s: §b%s\n§7%s: §b%s\n§7%s: §b%s\n§7%s: §b%s\n§e§m ",
"yes": "Yes",
"no": "No"
"lastHit": "You should stop using this tool now, this is your last hit!",
"warning": "Do you really want to continue using this tool? Its durability is at %s%%!"
}
}
}

0 comments on commit a936901

Please sign in to comment.