diff --git a/gradle.properties b/gradle.properties index f3ae6329..69687162 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs = -Xmx1G org.gradle.parallel = true # Mod Properties -version = 1.3.3+1.19 +version = 1.3.4+1.19 maven_group = folk.sisby archives_base_name = switchy diff --git a/src/main/java/folk/sisby/switchy/SwitchyCommands.java b/src/main/java/folk/sisby/switchy/SwitchyCommands.java index 91c13aa8..239afeeb 100644 --- a/src/main/java/folk/sisby/switchy/SwitchyCommands.java +++ b/src/main/java/folk/sisby/switchy/SwitchyCommands.java @@ -187,7 +187,7 @@ private static int setPreset(ServerPlayerEntity player, SwitchyPresets presets, } String oldPresetName = Objects.toString(presets.getCurrentPreset(), ""); - presets.setCurrentPreset(presetName, true); + presets.setCurrentPreset(player, presetName, true); Switchy.LOGGER.info("[Switchy] Player switch: '" + oldPresetName + "' -> '" + presetName + "' [" + player.getUuid() + "]"); tellSuccess(player, "commands.switchy.set.success", literal(oldPresetName), literal(presetName)); return 1; diff --git a/src/main/java/folk/sisby/switchy/SwitchyPresets.java b/src/main/java/folk/sisby/switchy/SwitchyPresets.java index 4b1e39f4..309f5322 100644 --- a/src/main/java/folk/sisby/switchy/SwitchyPresets.java +++ b/src/main/java/folk/sisby/switchy/SwitchyPresets.java @@ -16,7 +16,6 @@ public class SwitchyPresets { private final Map presetMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); private final Map moduleToggles; - private final PlayerEntity player; private SwitchyPreset currentPreset; public static final String KEY_PRESET_CURRENT = "current"; @@ -24,7 +23,7 @@ public class SwitchyPresets { public static final String KEY_PRESET_MODULE_DISABLED = "disabled"; public static final String KEY_PRESET_LIST = "list"; - public NbtElement toNbt() { + public NbtCompound toNbt() { NbtCompound outNbt = new NbtCompound(); NbtList enabledList = new NbtList(); @@ -62,14 +61,14 @@ public static SwitchyPresets fromNbt(PlayerEntity player, NbtCompound nbt) { } } - if (nbt.contains(KEY_PRESET_CURRENT) && !outPresets.setCurrentPreset(nbt.getString(KEY_PRESET_CURRENT), false)) { + if (nbt.contains(KEY_PRESET_CURRENT) && !outPresets.setCurrentPreset(player, nbt.getString(KEY_PRESET_CURRENT), false)) { Switchy.LOGGER.warn("Switchy: Unable to set current preset from data. Data may have been lost."); } if (outPresets.presetMap.isEmpty() || outPresets.getCurrentPreset() == null) { // Recover current data as "Default" preset outPresets.addPreset(new SwitchyPreset("default", outPresets.moduleToggles)); - outPresets.setCurrentPreset("default", false); + outPresets.setCurrentPreset(player, "default", false); } return outPresets; @@ -87,15 +86,14 @@ private void toggleModulesFromNbt(NbtList list, Boolean enabled) { } private SwitchyPresets(PlayerEntity player) { - this.player = player; this.moduleToggles = Switchy.COMPAT_REGISTRY.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().get().isDefault())); } - public boolean setCurrentPreset(String presetName, Boolean performSwitch) { + public boolean setCurrentPreset(PlayerEntity player, String presetName, Boolean performSwitch) { if (this.presetMap.containsKey(presetName)) { SwitchyPreset newPreset = this.presetMap.get(presetName); - if (performSwitch) this.switchPreset(currentPreset, newPreset); + if (performSwitch) this.switchPreset(player, currentPreset, newPreset); this.currentPreset = newPreset; return true; } else { @@ -103,12 +101,12 @@ public boolean setCurrentPreset(String presetName, Boolean performSwitch) { } } - private void switchPreset(SwitchyPreset oldPreset, SwitchyPreset newPreset) { + private void switchPreset(PlayerEntity player, SwitchyPreset oldPreset, SwitchyPreset newPreset) { oldPreset.updateFromPlayer(player); newPreset.applyToPlayer(player); } - public void saveCurrentPreset() { + public void saveCurrentPreset(PlayerEntity player) { if (this.currentPreset != null) this.currentPreset.updateFromPlayer(player); } diff --git a/src/main/java/folk/sisby/switchy/mixin/MixinPlayerEntity.java b/src/main/java/folk/sisby/switchy/mixin/MixinPlayerEntity.java index e8929341..a36d2d7d 100644 --- a/src/main/java/folk/sisby/switchy/mixin/MixinPlayerEntity.java +++ b/src/main/java/folk/sisby/switchy/mixin/MixinPlayerEntity.java @@ -25,7 +25,7 @@ protected MixinPlayerEntity(EntityType entityType, World @Inject(at = @At("TAIL"), method = "writeCustomDataToNbt(Lnet/minecraft/nbt/NbtCompound;)V") public void writeCustomDataToNbt(NbtCompound tag, CallbackInfo ci) { if (switchy$switchyPresets != null) { - switchy$switchyPresets.saveCurrentPreset(); + switchy$switchyPresets.saveCurrentPreset((PlayerEntity) (Object) this); tag.put("switchy:presets", switchy$switchyPresets.toNbt()); } } diff --git a/src/main/java/folk/sisby/switchy/modules/DrogtorCompat.java b/src/main/java/folk/sisby/switchy/modules/DrogtorCompat.java index 7212a9d1..6ad67862 100644 --- a/src/main/java/folk/sisby/switchy/modules/DrogtorCompat.java +++ b/src/main/java/folk/sisby/switchy/modules/DrogtorCompat.java @@ -1,6 +1,7 @@ package folk.sisby.switchy.modules; import com.unascribed.drogtor.DrogtorPlayer; +import folk.sisby.switchy.Switchy; import folk.sisby.switchy.api.PresetModule; import folk.sisby.switchy.api.PresetModuleRegistry; import net.minecraft.entity.player.PlayerEntity; @@ -33,6 +34,7 @@ public void updateFromPlayer(PlayerEntity player) { @Override public void applyToPlayer(PlayerEntity player) { DrogtorPlayer drogtorPlayer = (DrogtorPlayer) player; + Switchy.LOGGER.info("[Switchy] Player Nickname Change: '" + player.getDisplayName() + "' -> '" + this.nickname + "'"); drogtorPlayer.drogtor$setNickname(this.nickname); drogtorPlayer.drogtor$setNameColor(this.namecolor); drogtorPlayer.drogtor$setBio(this.bio);