-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid server-side deadlock when Starlight is installed
- Loading branch information
Showing
7 changed files
with
42 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 8 additions & 5 deletions
13
common/src/main/java/com/copycatsplus/copycats/utility/ChatUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
package com.copycatsplus.copycats.utility; | ||
|
||
import com.copycatsplus.copycats.Copycats; | ||
import com.copycatsplus.copycats.config.CCConfigs; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.network.chat.Component; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
public class ChatUtils { | ||
public static Set<String> messages = new HashSet<>(); | ||
|
||
private static final Supplier<Boolean> disableWarnings = CCConfigs.safeGetter(() -> CCConfigs.client().disableGraphicsWarnings.get(), false); | ||
|
||
/** | ||
* Send a local warning message to the player once. | ||
* | ||
* @param id Unique identifier for the message. Messages with the same id will only be sent once. | ||
* @param message The message to send. | ||
*/ | ||
public static void sendWarningOnce(String id, String message) { | ||
if (Minecraft.getInstance().player == null) return; | ||
if (CCConfigs.client().disableGraphicsWarnings.get()) return; | ||
if (disableWarnings.get()) return; | ||
if (messages.contains(id)) return; | ||
messages.add(id); | ||
Minecraft.getInstance().player.sendSystemMessage(Component.literal("Warning: " + message)); | ||
if (!Platform.Environment.CLIENT.isCurrent() || !ClientUtils.sendSystemMessage("Warning: " + message)) { | ||
Copycats.LOGGER.warn("Warning: {}", message); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
common/src/main/java/com/copycatsplus/copycats/utility/ClientUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.copycatsplus.copycats.utility; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.network.chat.Component; | ||
|
||
/** | ||
* This class should only be accessed on the client side. | ||
* It is not marked as client-only itself to avoid class loading issues. | ||
*/ | ||
public class ClientUtils { | ||
public static boolean sendSystemMessage(String message) { | ||
if (Minecraft.getInstance().player == null) { | ||
return false; | ||
} | ||
Minecraft.getInstance().player.sendSystemMessage(Component.literal(message)); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters