Skip to content

Commit

Permalink
Merge branch '1.18' into 1.19
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
  • Loading branch information
sisby-folk committed Sep 14, 2022
2 parents 66ee9e0 + 353ebe5 commit e442299
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/folk/sisby/switchy/SwitchyCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private static int setPreset(ServerPlayerEntity player, SwitchyPresets presets,
}

String oldPresetName = Objects.toString(presets.getCurrentPreset(), "<None>");
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;
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/folk/sisby/switchy/SwitchyPresets.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ public class SwitchyPresets {

private final Map<String, SwitchyPreset> presetMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private final Map<Identifier, Boolean> moduleToggles;
private final PlayerEntity player;
private SwitchyPreset currentPreset;

public static final String KEY_PRESET_CURRENT = "current";
public static final String KEY_PRESET_MODULE_ENABLED = "enabled";
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();
Expand Down Expand Up @@ -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;
Expand All @@ -87,28 +86,27 @@ 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 {
return false;
}
}

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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected MixinPlayerEntity(EntityType<? extends LivingEntity> 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());
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/folk/sisby/switchy/modules/DrogtorCompat.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e442299

Please sign in to comment.