Skip to content

Commit 5a1e635

Browse files
committed
Use change listeners rather than setters where applicable in Configs
1 parent 68987dd commit 5a1e635

File tree

7 files changed

+22
-34
lines changed

7 files changed

+22
-34
lines changed

src/main/java/net/earthcomputer/clientcommands/Configs.java

+9-21
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ public class Configs {
2424
@Config(readOnly = true, temporary = true)
2525
public static PlayerRandCracker.CrackState playerCrackState = PlayerRandCracker.CrackState.UNCRACKED;
2626

27-
@Config(setter = @Config.Setter("setEnchantingPrediction"), temporary = true)
28-
private static boolean enchantingPrediction = false;
29-
public static boolean getEnchantingPrediction() {
30-
return enchantingPrediction;
31-
}
32-
public static void setEnchantingPrediction(boolean enchantingPrediction) {
33-
Configs.enchantingPrediction = enchantingPrediction;
27+
@Config(onChange = "onChangeEnchantingPrediction", temporary = true)
28+
public static boolean enchantingPrediction = false;
29+
private static void onChangeEnchantingPrediction(boolean oldEnchantingPrediction, boolean enchantingPrediction) {
3430
if (enchantingPrediction) {
3531
ServerBrandManager.rngWarning();
3632
} else {
@@ -53,13 +49,9 @@ public boolean isEnabled() {
5349
}
5450
}
5551

56-
@Config(setter = @Config.Setter("setFishingManipulation"), temporary = true, condition = "conditionLessThan1_20")
57-
private static FishingManipulation fishingManipulation = FishingManipulation.OFF;
58-
public static FishingManipulation getFishingManipulation() {
59-
return fishingManipulation;
60-
}
61-
public static void setFishingManipulation(FishingManipulation fishingManipulation) {
62-
Configs.fishingManipulation = fishingManipulation;
52+
@Config(onChange = "onChangeFishingManipulation", temporary = true, condition = "conditionLessThan1_20")
53+
public static FishingManipulation fishingManipulation = FishingManipulation.OFF;
54+
private static void onChangeFishingManipulation(FishingManipulation oldFishingManipulation, FishingManipulation fishingManipulation) {
6355
if (fishingManipulation.isEnabled()) {
6456
ServerBrandManager.rngWarning();
6557
} else {
@@ -122,13 +114,9 @@ public static void setMaxEnchantLevels(int maxEnchantLevels) {
122114
Configs.minEnchantLevels = Math.min(Configs.minEnchantLevels, Configs.maxEnchantLevels);
123115
}
124116

125-
@Config(setter = @Config.Setter("setChorusManipulation"), temporary = true)
126-
private static boolean chorusManipulation = false;
127-
public static boolean getChorusManipulation() {
128-
return chorusManipulation;
129-
}
130-
public static void setChorusManipulation(boolean chorusManipulation) {
131-
Configs.chorusManipulation = chorusManipulation;
117+
@Config(onChange = "onChangeChorusManipulation", temporary = true)
118+
public static boolean chorusManipulation = false;
119+
public static void onChangeChorusManipulation(boolean oldChorusManipulation, boolean chorusManipulation) {
132120
if (chorusManipulation) {
133121
ServerBrandManager.rngWarning();
134122
ChorusManipulation.onChorusManipEnabled();

src/main/java/net/earthcomputer/clientcommands/command/CEnchantCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private static boolean enchantmentPredicate(Item item, Holder<Enchantment> ench)
5454
}
5555

5656
private static int cenchant(FabricClientCommandSource source, ItemAndEnchantmentsPredicate itemAndEnchantmentsPredicate) throws CommandSyntaxException {
57-
if (!Configs.getEnchantingPrediction()) {
57+
if (!Configs.enchantingPrediction) {
5858
Component component = Component.translatable("commands.cenchant.needEnchantingPrediction")
5959
.withStyle(ChatFormatting.RED)
6060
.append(" ")

src/main/java/net/earthcomputer/clientcommands/command/FishCommand.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
5656
}
5757

5858
private static int listGoals(FabricClientCommandSource source) throws CommandSyntaxException {
59-
if (!Configs.getFishingManipulation().isEnabled()) {
59+
if (!Configs.fishingManipulation.isEnabled()) {
6060
throw NEED_FISHING_MANIPULATION_EXCEPTION.create();
6161
}
6262

@@ -73,7 +73,7 @@ private static int listGoals(FabricClientCommandSource source) throws CommandSyn
7373
}
7474

7575
private static int addGoal(FabricClientCommandSource source, WithStringArgument.Result<ClientItemPredicateArgument.ClientItemPredicate> goal) throws CommandSyntaxException {
76-
if (!Configs.getFishingManipulation().isEnabled()) {
76+
if (!Configs.fishingManipulation.isEnabled()) {
7777
throw NEED_FISHING_MANIPULATION_EXCEPTION.create();
7878
}
7979

@@ -85,7 +85,7 @@ private static int addGoal(FabricClientCommandSource source, WithStringArgument.
8585
}
8686

8787
private static int addEnchantedGoal(FabricClientCommandSource source, WithStringArgument.Result<ItemAndEnchantmentsPredicate> stringAndItemAndEnchantments) throws CommandSyntaxException {
88-
if (!Configs.getFishingManipulation().isEnabled()) {
88+
if (!Configs.fishingManipulation.isEnabled()) {
8989
throw NEED_FISHING_MANIPULATION_EXCEPTION.create();
9090
}
9191

@@ -102,7 +102,7 @@ private static int addEnchantedGoal(FabricClientCommandSource source, WithString
102102
}
103103

104104
private static int removeGoal(FabricClientCommandSource source, int index) throws CommandSyntaxException {
105-
if (!Configs.getFishingManipulation().isEnabled()) {
105+
if (!Configs.fishingManipulation.isEnabled()) {
106106
throw NEED_FISHING_MANIPULATION_EXCEPTION.create();
107107
}
108108

src/main/java/net/earthcomputer/clientcommands/features/ChorusManipulation.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void onChorusManipEnabled() {
3333
TaskManager.addNonConflictingTask("chorusManipRenderer", new SimpleTask() {
3434
@Override
3535
public boolean condition() {
36-
return Configs.getChorusManipulation() && Minecraft.getInstance().player != null;
36+
return Configs.chorusManipulation && Minecraft.getInstance().player != null;
3737
}
3838

3939
@Override
@@ -48,7 +48,7 @@ protected void onTick() {
4848
}
4949

5050
public static int setGoal(Vec3 v1, Vec3 v2, boolean relative) {
51-
if (!Configs.getChorusManipulation()) {
51+
if (!Configs.chorusManipulation) {
5252
Component component = Component.translatable("chorusManip.needChorusManipulation")
5353
.withStyle(ChatFormatting.RED)
5454
.append(" ")

src/main/java/net/earthcomputer/clientcommands/features/EnchantmentCracker.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ public String toString() {
557557
// MISCELLANEOUS HELPER METHODS & ENCHANTING SIMULATION
558558

559559
public static boolean isEnchantingPredictionEnabled() {
560-
return Configs.getEnchantingPrediction();
560+
return Configs.enchantingPrediction;
561561
}
562562

563563
private static int getEnchantPower(Level level, BlockPos tablePos) {

src/main/java/net/earthcomputer/clientcommands/features/FishingCracker.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public static boolean throwFishingBobber() {
250250
}
251251

252252
public static boolean canManipulateFishing() {
253-
return Configs.getFishingManipulation().isEnabled() && !goals.isEmpty();
253+
return Configs.fishingManipulation.isEnabled() && !goals.isEmpty();
254254
}
255255

256256
private static void handleFishingRodThrow(ItemStack stack) {
@@ -267,7 +267,7 @@ public static void reset() {
267267
synchronized (STATE_LOCK) {
268268
state = State.NOT_MANIPULATING;
269269

270-
if (canManipulateFishing() && Configs.getFishingManipulation() == Configs.FishingManipulation.AFK) {
270+
if (canManipulateFishing() && Configs.fishingManipulation == Configs.FishingManipulation.AFK) {
271271
state = State.WAITING_FOR_RETRHOW;
272272
TaskManager.addNonConflictingTask("cfishRethrow", new LongTask() {
273273
private int counter;
@@ -340,7 +340,7 @@ public static void registerEvents() {
340340
}
341341
});
342342
MoreClientEvents.TIME_SYNC_ON_NETWORK_THREAD.register(packet -> {
343-
if (Configs.getFishingManipulation().isEnabled()) {
343+
if (Configs.fishingManipulation.isEnabled()) {
344344
onTimeSync();
345345
}
346346
});
@@ -590,7 +590,7 @@ private static void onTimeSync() {
590590
int delay = (totalTicksToWait - estimatedTicksElapsed) * serverMspt - magicMillisecondsCorrection - PingCommand.getLocalPing() - timeToStartOfTick + serverMspt / 2;
591591
long targetTime = (delay) * 1000000L + System.nanoTime();
592592
DELAY_EXECUTOR.schedule(() -> {
593-
if (!Configs.getFishingManipulation().isEnabled() || state != State.ASYNC_WAITING_FOR_FISH) {
593+
if (!Configs.fishingManipulation.isEnabled() || state != State.ASYNC_WAITING_FOR_FISH) {
594594
return;
595595
}
596596
LocalPlayer oldPlayer = Minecraft.getInstance().player;

src/main/java/net/earthcomputer/clientcommands/features/PlayerRandCracker.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public static void onConsume(ItemStack stack, Vec3 pos, int particleCount, int i
162162
}
163163
}
164164

165-
if (Configs.getChorusManipulation() && stack.getItem() == Items.CHORUS_FRUIT) {
165+
if (Configs.chorusManipulation && stack.getItem() == Items.CHORUS_FRUIT) {
166166
ChorusManipulation.onEat(pos, particleCount, itemUseTimeLeft);
167167
if (particleCount == 16) {
168168
//Consumption randoms

0 commit comments

Comments
 (0)