Skip to content

Commit 34ae66b

Browse files
committed
Sorta some functionality, skeleton structure. Nothing here really worth keeping yet
0 parents  commit 34ae66b

File tree

8 files changed

+396
-0
lines changed

8 files changed

+396
-0
lines changed

.gitignore

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# User-specific stuff
2+
.idea/
3+
4+
*.iml
5+
*.ipr
6+
*.iws
7+
8+
# IntelliJ
9+
out/
10+
11+
# Compiled class file
12+
*.class
13+
14+
# Log file
15+
*.log
16+
17+
# BlueJ files
18+
*.ctxt
19+
20+
# Package Files #
21+
*.jar
22+
*.war
23+
*.nar
24+
*.ear
25+
*.zip
26+
*.tar.gz
27+
*.rar
28+
29+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
30+
hs_err_pid*
31+
32+
*~
33+
34+
# temporary files which can be created if a process still has a handle open of a deleted file
35+
.fuse_hidden*
36+
37+
# KDE directory preferences
38+
.directory
39+
40+
# Linux trash folder which might appear on any partition or disk
41+
.Trash-*
42+
43+
# .nfs files are created when an open file is removed but is still being accessed
44+
.nfs*
45+
46+
# General
47+
.DS_Store
48+
.AppleDouble
49+
.LSOverride
50+
51+
# Icon must end with two \r
52+
Icon
53+
54+
# Thumbnails
55+
._*
56+
57+
# Files that might appear in the root of a volume
58+
.DocumentRevisions-V100
59+
.fseventsd
60+
.Spotlight-V100
61+
.TemporaryItems
62+
.Trashes
63+
.VolumeIcon.icns
64+
.com.apple.timemachine.donotpresent
65+
66+
# Directories potentially created on remote AFP share
67+
.AppleDB
68+
.AppleDesktop
69+
Network Trash Folder
70+
Temporary Items
71+
.apdisk
72+
73+
# Windows thumbnail cache files
74+
Thumbs.db
75+
Thumbs.db:encryptable
76+
ehthumbs.db
77+
ehthumbs_vista.db
78+
79+
# Dump file
80+
*.stackdump
81+
82+
# Folder config file
83+
[Dd]esktop.ini
84+
85+
# Recycle Bin used on file shares
86+
$RECYCLE.BIN/
87+
88+
# Windows Installer files
89+
*.cab
90+
*.msi
91+
*.msix
92+
*.msm
93+
*.msp
94+
95+
# Windows shortcuts
96+
*.lnk
97+
98+
target/
99+
100+
pom.xml.tag
101+
pom.xml.releaseBackup
102+
pom.xml.versionsBackup
103+
pom.xml.next
104+
105+
release.properties
106+
dependency-reduced-pom.xml
107+
buildNumber.properties
108+
.mvn/timing.properties
109+
.mvn/wrapper/maven-wrapper.jar
110+
.flattened-pom.xml
111+
112+
# Common working directory
113+
run/

pom.xml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>simplexity</groupId>
8+
<artifactId>chatproxying</artifactId>
9+
<version>0.0.0</version>
10+
<packaging>jar</packaging>
11+
12+
<name>chatproxying</name>
13+
14+
<properties>
15+
<java.version>21</java.version>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
</properties>
18+
19+
<build>
20+
<defaultGoal>clean package</defaultGoal>
21+
<plugins>
22+
<plugin>
23+
<groupId>org.apache.maven.plugins</groupId>
24+
<artifactId>maven-compiler-plugin</artifactId>
25+
<version>3.13.0</version>
26+
<configuration>
27+
<source>${java.version}</source>
28+
<target>${java.version}</target>
29+
</configuration>
30+
</plugin>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-shade-plugin</artifactId>
34+
<version>3.5.3</version>
35+
<executions>
36+
<execution>
37+
<phase>package</phase>
38+
<goals>
39+
<goal>shade</goal>
40+
</goals>
41+
</execution>
42+
</executions>
43+
</plugin>
44+
</plugins>
45+
<resources>
46+
<resource>
47+
<directory>src/main/resources</directory>
48+
<filtering>true</filtering>
49+
</resource>
50+
</resources>
51+
</build>
52+
53+
<repositories>
54+
<repository>
55+
<id>papermc-repo</id>
56+
<url>https://repo.papermc.io/repository/maven-public/</url>
57+
</repository>
58+
<repository>
59+
<id>sonatype</id>
60+
<url>https://oss.sonatype.org/content/groups/public/</url>
61+
</repository>
62+
</repositories>
63+
64+
<dependencies>
65+
<dependency>
66+
<groupId>io.papermc.paper</groupId>
67+
<artifactId>paper-api</artifactId>
68+
<version>1.21.4-R0.1-SNAPSHOT</version>
69+
<scope>provided</scope>
70+
</dependency>
71+
</dependencies>
72+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package simplexity.chatProxying;
2+
3+
import io.papermc.paper.event.player.AsyncChatEvent;
4+
import net.kyori.adventure.text.Component;
5+
import net.kyori.adventure.text.minimessage.MiniMessage;
6+
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
7+
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
8+
import org.bukkit.event.EventHandler;
9+
import org.bukkit.event.Listener;
10+
11+
import java.util.ArrayList;
12+
import java.util.HashMap;
13+
import java.util.List;
14+
15+
public class ChatListener implements Listener {
16+
17+
MiniMessage miniMessage = MiniMessage.miniMessage();
18+
19+
@EventHandler
20+
public void onChat(AsyncChatEvent chatEvent) {
21+
String messageString = PlainTextComponentSerializer.plainText().serialize(chatEvent.message());
22+
Profile profile = ProxyCommand.uuidProfileMap.get(chatEvent.getPlayer().getUniqueId());
23+
List<Individual> individualList = ProxyCommand.profileIndividualMap.get(profile);
24+
HashMap<String, Individual> proxyMap = new HashMap<>();
25+
for (Individual individual : individualList) {
26+
for (String proxy : individual.getProxyFormats()) {
27+
proxyMap.put(proxy, individual);
28+
}
29+
}
30+
boolean proxyFound = false;
31+
String proxyUsed = "";
32+
Individual individualUsed = null;
33+
for (String proxy : proxyMap.keySet()) {
34+
if (!messageString.startsWith(proxy)) continue;
35+
proxyFound = true;
36+
proxyUsed = proxy;
37+
individualUsed = proxyMap.get(proxy);
38+
}
39+
if (!proxyFound) return;
40+
Component newMessage = miniMessage.deserialize(messageString,
41+
Placeholder.unparsed(proxyUsed, ""));
42+
chatEvent.message(newMessage);
43+
String finalProxyUsed = proxyUsed;
44+
Individual finalIndividualUsed = individualUsed;
45+
String messageFormat = "<username> | <proxy> : <message>";
46+
chatEvent.renderer((source, sourceDisplayName, chatMessage, viewer) ->
47+
miniMessage.deserialize(messageFormat,
48+
Placeholder.component("username", source.displayName()),
49+
Placeholder.component("proxy", miniMessage.deserialize(finalIndividualUsed.getDisplayName())),
50+
Placeholder.component("message", newMessage)));
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package simplexity.chatProxying;
2+
3+
import org.bukkit.plugin.java.JavaPlugin;
4+
5+
public final class ChatProxying extends JavaPlugin {
6+
7+
@Override
8+
public void onEnable() {
9+
this.getServer().getPluginManager().registerEvents(new ChatListener(), this);
10+
this.getCommand("proxy").setExecutor(new ProxyCommand());
11+
// Plugin startup logic
12+
13+
}
14+
15+
@Override
16+
public void onDisable() {
17+
// Plugin shutdown logic
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package simplexity.chatProxying;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
public class Individual {
7+
private String displayName;
8+
private final int individualId;
9+
private List<String> proxyFormats;
10+
11+
public Individual(String displayName, int individualId, List<String> proxyFormats) {
12+
this.displayName = displayName;
13+
this.individualId = individualId;
14+
this.proxyFormats = proxyFormats;
15+
}
16+
17+
public String getDisplayName() {
18+
return displayName;
19+
}
20+
21+
public void setDisplayName(String displayName) {
22+
this.displayName = displayName;
23+
}
24+
25+
public int getIndividualId() {
26+
return individualId;
27+
}
28+
29+
public List<String> getProxyFormats() {
30+
return proxyFormats;
31+
}
32+
33+
public void setProxyFormats(List<String> proxyFormats) {
34+
this.proxyFormats = proxyFormats;
35+
}
36+
37+
public String toString() {
38+
return "[displayName=" + displayName
39+
+ ", individualId=" + individualId
40+
+ ", proxyFormats= [" + Arrays.toString(proxyFormats.toArray());
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package simplexity.chatProxying;
2+
3+
import net.kyori.adventure.text.Component;
4+
5+
import java.util.UUID;
6+
7+
public class Profile {
8+
private final int profileID;
9+
private String profileName;
10+
private Component profileDisplayName;
11+
12+
public Profile(String profileName, int profileID, Component profileDisplayName){
13+
this.profileID = profileID;
14+
this.profileName = profileName;
15+
this.profileDisplayName = profileDisplayName;
16+
}
17+
18+
public int getProfileID() {
19+
return profileID;
20+
}
21+
22+
public String getProfileName() {
23+
return profileName;
24+
}
25+
26+
public void setProfileName(String profileName) {
27+
this.profileName = profileName;
28+
}
29+
30+
public String toString(){
31+
return "profileId=" + profileID
32+
+ ", profileName=" + profileName
33+
+ ", profileDisplayName=" + profileDisplayName; //todo add clean version of display name and not just the component dump
34+
35+
}
36+
37+
public Component getProfileDisplayName() {
38+
return profileDisplayName;
39+
}
40+
41+
public void setProfileDisplayName(Component profileDisplayName) {
42+
this.profileDisplayName = profileDisplayName;
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package simplexity.chatProxying;
2+
3+
import net.kyori.adventure.text.minimessage.MiniMessage;
4+
import org.bukkit.command.Command;
5+
import org.bukkit.command.CommandExecutor;
6+
import org.bukkit.command.CommandSender;
7+
import org.bukkit.entity.Player;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
import java.util.ArrayList;
11+
import java.util.Arrays;
12+
import java.util.HashMap;
13+
import java.util.List;
14+
import java.util.UUID;
15+
16+
public class ProxyCommand implements CommandExecutor {
17+
public static final HashMap<UUID, Profile> uuidProfileMap = new HashMap<>();
18+
public static final HashMap<Profile, List<Individual>> profileIndividualMap = new HashMap<>();
19+
20+
@Override
21+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String @NotNull [] args) {
22+
if (args[0].equalsIgnoreCase("profile")) {
23+
Player player = (Player) sender;
24+
UUID uuid = player.getUniqueId();
25+
String name = args[1];
26+
Profile profile = new Profile(name, 1, MiniMessage.miniMessage().deserialize(name));
27+
uuidProfileMap.put(uuid, profile);
28+
return true;
29+
}
30+
if (args[0].equalsIgnoreCase("alter")) {
31+
Player player = (Player) sender;
32+
UUID uuid = player.getUniqueId();
33+
String name = args[1];
34+
List<String> proxies = new ArrayList<>();
35+
Arrays.stream(args).iterator().forEachRemaining(proxies::add);
36+
Profile profile = uuidProfileMap.get(uuid);
37+
Individual individual = new Individual(name, 1, proxies);
38+
List<Individual> individualList = profileIndividualMap.get(profile);
39+
if (individualList == null) individualList = new ArrayList<>();
40+
individualList.add(individual);
41+
profileIndividualMap.put(profile, individualList);
42+
}
43+
44+
return false;
45+
}
46+
}

0 commit comments

Comments
 (0)