Skip to content

Commit

Permalink
fix: remove faction from discord presence
Browse files Browse the repository at this point in the history
  • Loading branch information
AsoDesu committed Apr 20, 2024
1 parent 9e9b2c9 commit 03a3905
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,6 @@ public static void updateTimeLeft(Long endTimestamp) {
updateActivity();
}

public static int lastLevel = -1;
public static void setLevel(int level) {
if (activity == null) return;
if (!IslandOptions.getDiscord().showFactionLevel) return;

lastLevel = level;
String faction = "";
if (MccIslandState.getFaction() != null)
faction = " (" + MccIslandState.getFaction().getTitle() + ")";

try { activity.assets().setSmallText("Level " + level + faction); }
catch (Exception e) { e.printStackTrace(); }
}

public static void updatePlace(Game game) {
if (activity == null) return;
if (!IslandOptions.getDiscord().showGame) return;
Expand Down Expand Up @@ -238,9 +224,6 @@ public static void updateFromConfig(DiscordOptions options) {
activity.timestamps().setEnd(Instant.ofEpochSecond(0));
} else updatePlace(MccIslandState.getGame());

if (!options.showFactionLevel) activity.assets().setSmallText("");
else setLevel(lastLevel);

if (!options.showGameInfo) activity.setState("");
else updatePlace(MccIslandState.getGame());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import net.asodev.islandutils.modules.plobby.PlobbyJoinCodeCopy;
import net.asodev.islandutils.modules.scavenging.Scavenging;
import net.asodev.islandutils.modules.splits.LevelTimer;
import net.asodev.islandutils.state.faction.Faction;
import net.asodev.islandutils.state.faction.FactionComponents;
import net.minecraft.client.gui.font.providers.BitmapProvider;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
Expand All @@ -17,7 +15,6 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static net.asodev.islandutils.modules.cosmetics.CosmeticState.MCC_ICONS;
import static net.asodev.islandutils.state.faction.FactionComponents.MCC_ICONS_19;

@Mixin(BitmapProvider.Definition.class)
public class FontLoaderMixin {
Expand All @@ -32,7 +29,6 @@ private void init(ResourceLocation file, int i, int j, int[][] chars, CallbackIn

String character = builder.toString();
Component comp = Component.literal(character).setStyle(Style.EMPTY.withFont(MCC_ICONS));
Component factionComp = Component.literal(character).setStyle(Style.EMPTY.withFont(MCC_ICONS_19));
switch (file.getPath()) {
case "_fonts/body/blueprint_assembly.png" -> CraftingUI.setAssemblerCharacter(character);
case "_fonts/body/fusion_forge.png" -> CraftingUI.setForgeCharacter(character);
Expand All @@ -46,17 +42,6 @@ private void init(ResourceLocation file, int i, int j, int[][] chars, CallbackIn
case "_fonts/medals.png" -> LevelTimer.medalCharacter = character;
case "_fonts/split_up.png" -> LevelTimer.splitUpComponent = comp;
case "_fonts/split_down.png" -> LevelTimer.splitDownComponent = comp;

case "_fonts/team/aqua_big.png" -> FactionComponents.setComponent(Faction.AQUA, factionComp);
case "_fonts/team/blue_big.png" -> FactionComponents.setComponent(Faction.BLUE, factionComp);
case "_fonts/team/cyan_big.png" -> FactionComponents.setComponent(Faction.CYAN, factionComp);
case "_fonts/team/green_big.png" -> FactionComponents.setComponent(Faction.GREEN, factionComp);
case "_fonts/team/lime_big.png" -> FactionComponents.setComponent(Faction.LIME, factionComp);
case "_fonts/team/orange_big.png" -> FactionComponents.setComponent(Faction.ORANGE, factionComp);
case "_fonts/team/pink_big.png" -> FactionComponents.setComponent(Faction.PINK, factionComp);
case "_fonts/team/purple_big.png" -> FactionComponents.setComponent(Faction.PURPLE, factionComp);
case "_fonts/team/red_big.png" -> FactionComponents.setComponent(Faction.RED, factionComp);
case "_fonts/team/yellow_big.png" -> FactionComponents.setComponent(Faction.YELLOW, factionComp);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.asodev.islandutils.state.Game;
import net.asodev.islandutils.modules.cosmetics.CosmeticSlot;
import net.asodev.islandutils.modules.cosmetics.CosmeticState;
import net.asodev.islandutils.state.faction.FactionComponents;
import net.asodev.islandutils.modules.splits.LevelTimer;
import net.asodev.islandutils.util.ChatUtils;
import net.asodev.islandutils.util.MusicUtil;
Expand Down Expand Up @@ -61,25 +60,6 @@ protected PacketListenerMixin(Minecraft minecraft, Connection connection, Common
super(minecraft, connection, commonListenerCookie);
}

@Inject(method = "handleSetExperience", at = @At("TAIL")) // Get our faction level
public void handleSetExperience(ClientboundSetExperiencePacket clientboundSetExperiencePacket, CallbackInfo ci) {
if (!MccIslandState.isOnline()) return; // We must be online!
DiscordPresenceUpdator.setLevel(clientboundSetExperiencePacket.getExperienceLevel()); // Set our faction level on discord to our XP
}

String lastCheckedActionBar = "";
@Inject(method = "setActionBarText", at = @At("TAIL")) // Get our faction!
public void handleSetExperience(ClientboundSetActionBarTextPacket clientboundSetActionBarTextPacket, CallbackInfo ci) {
if (!MccIslandState.isOnline()) return; // Me must be on the island!
String text = clientboundSetActionBarTextPacket.getText().getString(); // Get the string version of our actionbar
if (Objects.equals(lastCheckedActionBar, text)) return; // If the action bar is the same as the last, ignore it
lastCheckedActionBar = text;

FactionComponents.comps.forEach((faction, component) -> { // Loop over the faction icon characters
if (text.contains(component.getString())) MccIslandState.setFaction(faction); // If we contain it, that's our faction!!
});
}

// Patterns for the Map & Modifier options on scoreboard
final Map<String, Pattern> scoreboardPatterns = Map.of(
"MAP", Pattern.compile("MAP: (?<map>\\w+(?:,? \\w+)*)"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class DiscordOptions implements OptionsCategory {
public boolean showGameInfo = true;
public boolean showTimeRemaining = true;
public boolean showTimeElapsed = true;
public boolean showFactionLevel = true;

@Override
public ConfigCategory getCategory() {
Expand Down Expand Up @@ -51,12 +50,6 @@ public ConfigCategory getCategory() {
.controller(TickBoxControllerBuilder::create)
.binding(defaults.showTimeElapsed, () -> showTimeElapsed, value -> this.showTimeElapsed = value)
.build();
Option<Boolean> showFactionOption = Option.<Boolean>createBuilder()
.name(Component.translatable("text.autoconfig.islandutils.option.showFactionLevel"))
.description(OptionDescription.of(Component.translatable("text.autoconfig.islandutils.option.showFactionLevel.@Tooltip")))
.controller(TickBoxControllerBuilder::create)
.binding(defaults.showFactionLevel, () -> showFactionLevel, value -> this.showFactionLevel = value)
.build();

return ConfigCategory.createBuilder()
.name(Component.literal("Discord Presence"))
Expand All @@ -68,7 +61,6 @@ public ConfigCategory getCategory() {
.option(showGameInfoOption)
.option(showTimeRemainOption)
.option(showTimeElapsedOption)
.option(showFactionOption)
.build())
.build();
}
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/net/asodev/islandutils/state/MccIslandState.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package net.asodev.islandutils.state;

import net.asodev.islandutils.IslandUtilsEvents;
import net.asodev.islandutils.discord.DiscordPresenceUpdator;
import net.asodev.islandutils.state.faction.Faction;
import net.asodev.islandutils.util.ChatUtils;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
Expand All @@ -15,7 +13,6 @@ public class MccIslandState {
private static Game game = Game.HUB;
private static String modifier = "INACTIVE";
private static String map = "UNKNOWN";
private static Faction faction;

public static String getModifier() {
return modifier;
Expand Down Expand Up @@ -80,15 +77,6 @@ public static String getMap() {
return map;
}

public static Faction getFaction() {
return faction;
}
public static void setFaction(Faction faction) {
//ChatUtils.debug("Detected Faction: " + faction);
DiscordPresenceUpdator.setLevel(DiscordPresenceUpdator.lastLevel);
MccIslandState.faction = faction;
}

public static boolean isOnline() {
ServerData currentServer = Minecraft.getInstance().getCurrentServer();
if (currentServer == null) return false;
Expand Down
22 changes: 0 additions & 22 deletions src/main/java/net/asodev/islandutils/state/faction/Faction.java

This file was deleted.

This file was deleted.

0 comments on commit 03a3905

Please sign in to comment.