Skip to content

Commit

Permalink
Merge pull request #9 from RappyLabyAddons/fix/reduce_objects
Browse files Browse the repository at this point in the history
v1.3.0: Reduce objects, remove /tbw
  • Loading branch information
RappyTV committed Aug 18, 2023
2 parents 4639917 + 113ec76 commit b9710d2
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 235 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ labyMod {
displayName = "Toolbreak Warning"
author = "RappyTV"
description = "Stops you from using your currently used tool when its almost destroyed."
version = System.getenv().getOrDefault("VERSION", "1.2.1")
version = System.getenv().getOrDefault("VERSION", "1.3.0")
}

minecraft {
Expand Down
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
106 changes: 0 additions & 106 deletions core/src/main/java/com/rappytv/toolwarn/commands/TbwCommand.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ public class TbwConfiguration extends AddonConfig {
@SpriteSlot(size = 32, x = 1)
private final ConfigProperty<Boolean> openChat = new ConfigProperty<>(true);
@SwitchSetting
@SpriteSlot(size = 32, x = 2)
private final ConfigProperty<Boolean> format = new ConfigProperty<>(true);
@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 All @@ -56,15 +50,9 @@ public ConfigProperty<Boolean> enabled() {
public ConfigProperty<Boolean> openChat() {
return openChat;
}
public ConfigProperty<Boolean> format() {
return 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
29 changes: 2 additions & 27 deletions core/src/main/resources/assets/toolwarn/i18n/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,10 @@
"name": "Chat öffnen beim warnen",
"description": "Wenn das Addon dich warnt, wird sich dein Chat öffnen, damit du daran gehindert wirst, die letzten Hits mit deinem Tool zu verbrauchen."
},
"format": {
"name": "Zahlen formatieren",
"description": "Unformatierte Zahl: 1561\nFormatierte Zahl: 1.561"
},
"lastHit": {
"name": "Warnung beim letzten Schlag",
"description": "Warnt dich, wenn dein Tool bei Haltbarkeit 1 angekommen ist"
},
"debug": {
"name": "Debug Modus (Entwicklungs-Funktion)",
"description": "Sendet jeden Tick eine Nachricht in den Chat, in dem du ein Tool in der Hand hältst."
},
"sounds": {
"name": "Sound Einstellungen",
"description": "Verwaltet die Sounds, die abgespielt werden.",
Expand Down Expand Up @@ -76,25 +68,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%%!"
}
}
}
29 changes: 2 additions & 27 deletions core/src/main/resources/assets/toolwarn/i18n/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,10 @@
"name": "Open chat on warn",
"description": "When the addon warns you, your chat will open to prevent you from wasting the last durability of your tool."
},
"format": {
"name": "Format numbers",
"description": "Unformatted Number: 1561\nFormatted Number: 1.561"
},
"lastHit": {
"name": "Warn on last hit",
"description": "Warns you when your tool is at 1 durability"
},
"debug": {
"name": "Debug Mode (Development Feature)",
"description": "Sends a message in the chat every tick you're holding a tool."
},
"sounds": {
"name": "Sound Settings",
"description": "Manages the sounds that are played.",
Expand Down Expand Up @@ -76,25 +68,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%%!"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@
@Implements(ITbwSounds.class)
public class TbwSoundImpl implements ITbwSounds {

private final ResourceLocation plingSound = ResourceLocation.create("minecraft", "block.note.pling");
private final ResourceLocation levelUpSound = ResourceLocation.create("minecraft", "entity.player.levelup");
private final ResourceLocation glassBreakSound = ResourceLocation.create("minecraft", "block.glass.break");
private final ResourceLocation anvilUseSound = ResourceLocation.create("minecraft", "block.anvil.use");

@Override
public ResourceLocation getPlingSound() {
return ResourceLocation.create("minecraft", "block.note.pling");
return plingSound;
}
@Override
public ResourceLocation getLevelUpSound() {
return ResourceLocation.create("minecraft", "entity.player.levelup");
return levelUpSound;
}
@Override
public @NotNull ResourceLocation getGlassBreakSound() {
return ResourceLocation.create("minecraft", "block.glass.break");
return glassBreakSound;
}
@Override
public ResourceLocation getAnvilUseSound() {
return ResourceLocation.create("minecraft", "block.anvil.use");
return anvilUseSound;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@
@Implements(ITbwSounds.class)
public class TbwSoundImpl implements ITbwSounds {

private final ResourceLocation plingSound = ResourceLocation.create("minecraft", "block.note_block.pling");
private final ResourceLocation levelUpSound = ResourceLocation.create("minecraft", "entity.player.levelup");
private final ResourceLocation glassBreakSound = ResourceLocation.create("minecraft", "block.glass.break");
private final ResourceLocation anvilUseSound = ResourceLocation.create("minecraft", "block.anvil.use");

@Override
public ResourceLocation getPlingSound() {
return ResourceLocation.create("minecraft", "block.note_block.pling");
return plingSound;
}
@Override
public ResourceLocation getLevelUpSound() {
return ResourceLocation.create("minecraft", "entity.player.levelup");
return levelUpSound;
}
@Override
public @NotNull ResourceLocation getGlassBreakSound() {
return ResourceLocation.create("minecraft", "block.glass.break");
return glassBreakSound;
}
@Override
public ResourceLocation getAnvilUseSound() {
return ResourceLocation.create("minecraft", "block.anvil.use");
return anvilUseSound;
}
}
Loading

0 comments on commit b9710d2

Please sign in to comment.