-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4760629
commit 0a00ea4
Showing
7 changed files
with
146 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
# BetterPreview | ||
|
||
Previews chat previes client-side to improve privacy, stability, and performance. | ||
Processes chat previews client-side to improve privacy, stability, and performance. | ||
|
||
Must be installed on both client and server to work. Currently supports Fabric clients and Spigot servers. | ||
|
||
**Minecraft Version:** 1.19 | ||
|
||
## Supported Chat Plugins | ||
|
||
- [EssentialsChat](https://essentialsx.net/) | ||
|
||
More to come |
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
40 changes: 40 additions & 0 deletions
40
bp-spigot/src/main/java/com/tisawesomeness/betterpreview/spigot/Util.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,40 @@ | ||
package com.tisawesomeness.betterpreview.spigot; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
|
||
public class Util { | ||
|
||
// Permission checker that supports wildcards without needing Vault | ||
// Adapted from EssentialsChat | ||
// https://github.com/EssentialsX/Essentials/blob/2.x/Essentials/src/main/java/com/earth2me/essentials/perm/impl/SuperpermsHandler.java | ||
|
||
/** | ||
* Checks if the player has the given permission, checking wildcards. | ||
* Use {@link Player#isPermissionSet(String)} to check if a permission is set. | ||
* @param player the player to check | ||
* @param permission the permission to check | ||
* @return whether the player has the permission | ||
*/ | ||
public static boolean hasPermission(Player player, String permission) { | ||
String perm = permission; | ||
String permToCheck = permission; | ||
int idx; | ||
while (true) { | ||
if (player.isPermissionSet(permToCheck) || isDeniedToOps(permToCheck)) { | ||
return player.hasPermission(permToCheck); | ||
} | ||
idx = perm.lastIndexOf('.'); | ||
if (idx < 1) { | ||
return player.hasPermission("*"); | ||
} | ||
perm = perm.substring(0, idx); | ||
permToCheck = perm + ".*"; | ||
} | ||
} | ||
private static boolean isDeniedToOps(String node) { | ||
var perm = Bukkit.getServer().getPluginManager().getPermission(node); | ||
return perm != null && !perm.getDefault().getValue(true); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
.../src/main/java/com/tisawesomeness/betterpreview/spigot/adapter/EssentialsChatAdapter.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,55 @@ | ||
package com.tisawesomeness.betterpreview.spigot.adapter; | ||
|
||
import com.tisawesomeness.betterpreview.format.ChatFormatter; | ||
import com.tisawesomeness.betterpreview.format.ClassicFormatter; | ||
import com.tisawesomeness.betterpreview.spigot.Util; | ||
|
||
import net.kyori.adventure.text.format.NamedTextColor; | ||
import net.kyori.adventure.text.format.TextDecoration; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.EnumSet; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class EssentialsChatAdapter implements FormatAdapter { | ||
|
||
private static final String BASE_PERMISSION = "essentials.chat"; | ||
private static final Set<TextDecoration> FORMAT_DECORATIONS = EnumSet.of( | ||
TextDecoration.BOLD, | ||
TextDecoration.ITALIC, | ||
TextDecoration.STRIKETHROUGH, | ||
TextDecoration.UNDERLINED | ||
); | ||
|
||
@Override | ||
public ChatFormatter buildChatFormatter(Player player) { | ||
var colors = new HashSet<NamedTextColor>(); | ||
if (Util.hasPermission(player, BASE_PERMISSION + ".color")) { | ||
colors.addAll(ClassicFormatter.ALL_NAMED_COLORS); | ||
} | ||
for (var color : ClassicFormatter.ALL_NAMED_COLORS) { | ||
String perm = BASE_PERMISSION + "." + color.toString(); | ||
if (player.isPermissionSet(perm)) { | ||
if (Util.hasPermission(player, perm)) { | ||
colors.add(color); | ||
} else { | ||
colors.remove(color); | ||
} | ||
} | ||
} | ||
|
||
var decorations = EnumSet.noneOf(TextDecoration.class); | ||
boolean resetAllowed = false; | ||
if (Util.hasPermission(player, BASE_PERMISSION + ".format")) { | ||
decorations.addAll(FORMAT_DECORATIONS); | ||
resetAllowed = true; | ||
} | ||
if (Util.hasPermission(player, BASE_PERMISSION + ".magic")) { | ||
decorations.add(TextDecoration.OBFUSCATED); | ||
} | ||
|
||
return new ClassicFormatter('&', colors, decorations, resetAllowed); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
bp-spigot/src/main/java/com/tisawesomeness/betterpreview/spigot/adapter/FormatAdapter.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,19 @@ | ||
package com.tisawesomeness.betterpreview.spigot.adapter; | ||
|
||
import com.tisawesomeness.betterpreview.format.ChatFormatter; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
/** | ||
* Adapts a plugin's chat system to a BetterPreview chat formatter. | ||
*/ | ||
public interface FormatAdapter { | ||
|
||
/** | ||
* Builds a chat formatter for the player based on the player's permissions and the chat plugin config. | ||
* @param player the player who will be sent the formatter | ||
* @return the formatter | ||
*/ | ||
ChatFormatter buildChatFormatter(Player player); | ||
|
||
} |
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