-
Notifications
You must be signed in to change notification settings - Fork 3
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
77ddbfe
commit 6a7786c
Showing
7 changed files
with
87 additions
and
21 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 |
---|---|---|
|
@@ -22,4 +22,4 @@ | |
* SOFTWARE. | ||
*/ | ||
|
||
rootProject.name = "multilang" | ||
rootProject.name = "MultiLang" |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/me/lorenzo0111/multilang/protocol/adapter/BaseAdapter.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,35 @@ | ||
package me.lorenzo0111.multilang.protocol.adapter; | ||
|
||
import com.comphenix.protocol.PacketType; | ||
import com.comphenix.protocol.events.ListenerPriority; | ||
import com.comphenix.protocol.events.PacketAdapter; | ||
import com.comphenix.protocol.wrappers.WrappedChatComponent; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import me.lorenzo0111.multilang.MultiLangPlugin; | ||
import me.lorenzo0111.multilang.utils.RegexChecker; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public abstract class BaseAdapter extends PacketAdapter { | ||
|
||
public BaseAdapter(MultiLangPlugin plugin, ListenerPriority listenerPriority, PacketType type) { | ||
super(plugin, listenerPriority, type); | ||
} | ||
|
||
public void handle(Player player, @NotNull WrappedChatComponent component, @NotNull Runnable save) { | ||
JsonObject json = new JsonParser().parse(component.getJson()).getAsJsonObject(); | ||
|
||
this.update(json, RegexChecker.replace(player, json)); | ||
|
||
component.setJson(json.toString()); | ||
|
||
save.run(); | ||
} | ||
|
||
protected void update(@NotNull JsonObject object, String value) { | ||
object.remove("text"); | ||
object.addProperty("text",value); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/me/lorenzo0111/multilang/protocol/adapter/BossBarAdapter.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,38 @@ | ||
package me.lorenzo0111.multilang.protocol.adapter; | ||
|
||
import com.comphenix.protocol.PacketType; | ||
import com.comphenix.protocol.events.ListenerPriority; | ||
import com.comphenix.protocol.events.PacketContainer; | ||
import com.comphenix.protocol.events.PacketEvent; | ||
import com.comphenix.protocol.utility.MinecraftVersion; | ||
import com.comphenix.protocol.wrappers.WrappedChatComponent; | ||
import me.lorenzo0111.multilang.MultiLangPlugin; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class BossBarAdapter extends BaseAdapter { | ||
|
||
public BossBarAdapter(MultiLangPlugin plugin, ListenerPriority listenerPriority) { | ||
super(plugin, listenerPriority, PacketType.Play.Server.BOSS); | ||
} | ||
|
||
@Override | ||
public void onPacketSending(@NotNull PacketEvent event) { | ||
PacketContainer packet = event.getPacket(); | ||
|
||
WrappedChatComponent component; | ||
|
||
if (MinecraftVersion.CAVES_CLIFFS_1.atOrAbove()) { | ||
component = packet.getStructures().read(1).getChatComponents().read(0); | ||
} else { | ||
component = packet.getChatComponents().read(0); | ||
} | ||
|
||
this.handle(event.getPlayer(),component, () -> { | ||
if (MinecraftVersion.CAVES_CLIFFS_1.atOrAbove()) { | ||
packet.getStructures().read(1).getChatComponents().write(0, component); | ||
} else { | ||
packet.getChatComponents().write(0, component); | ||
} | ||
}); | ||
} | ||
} |
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