Skip to content

Commit b062cc7

Browse files
Merge branch 'main' of github.com:ParallelMC/ParallelUtils
2 parents 19aaead + 9af760b commit b062cc7

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

api/build.gradle

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,27 @@ bukkit {
313313
'parallelutils.chat.formats' {
314314
description = 'Gives access to chat formatting'
315315
}
316+
'parallelutils.book' {
317+
description = 'Gives access to chat elements on books'
318+
childrenMap = ['parallelutils.book.colors': true, 'parallelutils.book.formats': true,'parallelutils.book.hex': true,'parallelutils.book.magic': true,]
319+
setDefault('FALSE')
320+
}
321+
'parallelutils.book.colors' {
322+
description = 'Gives access to chat colors on signs'
323+
setDefault('FALSE')
324+
}
325+
'parallelutils.book.formats' {
326+
description = 'Gives access to chat formatting on signs'
327+
setDefault('FALSE')
328+
}
329+
'parallelutils.book.hex' {
330+
description = 'Gives access to chat hex colors on signs'
331+
setDefault('FALSE')
332+
}
333+
'parallelutils.book.magic' {
334+
description = 'Gives access to magic chat formatting on signs'
335+
setDefault('FALSE')
336+
}
316337
'parallelutils.bypass' {
317338
description = 'Bypasses some ParallelUtils modules'
318339
childrenMap = ['parallelutils.bypass.anticaps': true, 'parallelutils.bypass.antislur': true, 'parallelutils.bypass.clearchat': true, 'parallelutils.bypass.socialspy': true, 'parallelutils.bypass.commandspy': true, 'parallelutils.bypass.mutechat': true,]

modules/src/main/java/parallelmc/parallelutils/modules/parallelchat/ParallelChat.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ UUID varchar(36) not null,
227227

228228
this.emojiManager = new EmojiManager();
229229

230+
manager.registerEvents(new OnBookEdit(), puPlugin);
230231
manager.registerEvents(new OnChatMessage(), puPlugin);
231232
manager.registerEvents(new OnJoinLeave(puPlugin), puPlugin);
232233
manager.registerEvents(new OnSignTextSet(), puPlugin);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package parallelmc.parallelutils.modules.parallelchat.events;
2+
3+
import net.kyori.adventure.text.Component;
4+
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
5+
import org.bukkit.entity.Player;
6+
import org.bukkit.event.EventHandler;
7+
import org.bukkit.event.EventPriority;
8+
import org.bukkit.event.Listener;
9+
import org.bukkit.event.player.PlayerEditBookEvent;
10+
import org.bukkit.inventory.meta.BookMeta;
11+
12+
public class OnBookEdit implements Listener {
13+
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
14+
public void onBookEdit(PlayerEditBookEvent event) {
15+
Player player = event.getPlayer();
16+
BookMeta bookMeta = event.getNewBookMeta();
17+
// TODO: Add antiswear stuff once it's not jank
18+
if (bookMeta.hasPages()) {
19+
for (int i = 1; i <= bookMeta.getPageCount(); i++) {
20+
Component newText = bookMeta.page(i); // Book pages are 1-indexed
21+
// Intellij tells me that newText is never null so /shrug
22+
// Check sign colors permission
23+
if (!player.hasPermission("parallelutils.book.colors")) {
24+
newText = newText.replaceText(x -> x.match("&[[0-9][a-f]]").replacement(""));
25+
}
26+
27+
// Check sign hex permission
28+
if (!player.hasPermission("parallelutils.book.hex")) {
29+
newText = newText.replaceText(x -> x.match("&#(.{6})").replacement(""));
30+
}
31+
32+
// Check sign formats permission
33+
if (!player.hasPermission("parallelutils.book.formats")) {
34+
newText = newText.replaceText(x -> x.match("&[[l-o]r]").replacement(""));
35+
}
36+
37+
// Check sign magic permission
38+
if (!player.hasPermission("parallelutils.book.magic")) {
39+
newText = newText.replaceText(x -> x.match("&k").replacement(""));
40+
}
41+
//Update bookmeta
42+
bookMeta.page(i, LegacyComponentSerializer.legacyAmpersand().deserialize(LegacyComponentSerializer.legacyAmpersand().serialize(newText)));
43+
}
44+
// Set the new bookmeta onto the book
45+
event.setNewBookMeta(bookMeta);
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)