-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
175 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,7 @@ public enum Key { | |
GetStrings, | ||
CreatePacket, | ||
ComponentSerializer, | ||
Convert, | ||
ConvertBypass, | ||
NONE, | ||
} |
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,7 +1,10 @@ | ||
package aplini.usetranslatednames.Enum; | ||
|
||
public class Status { | ||
public long Messages = 0; | ||
public long Matches = 0; | ||
// 消息总数 | ||
public long MsgCount = 0; | ||
// 成功匹配次数 | ||
public long MatchesCount = 0; | ||
// 总计耗时 | ||
public double TotalTime = 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package aplini.usetranslatednames; | ||
|
||
import aplini.usetranslatednames.Enum.Key; | ||
import com.comphenix.protocol.PacketType; | ||
import com.comphenix.protocol.events.PacketContainer; | ||
import com.comphenix.protocol.wrappers.WrappedChatComponent; | ||
import net.md_5.bungee.api.chat.TextComponent; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.AsyncPlayerChatEvent; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static aplini.usetranslatednames.UseTranslatedNames.*; | ||
|
||
public class onPlayerChat implements Listener { | ||
|
||
static onPlayerChat func = null; | ||
static Key mode; | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST) | ||
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event){ | ||
// 取消发送消息 | ||
event.setCancelled(true); | ||
|
||
CompletableFuture.runAsync(() -> { | ||
|
||
Player player = event.getPlayer(); | ||
// 获取已格式化的消息 | ||
String msg = String.format(event.getFormat(), player.getName(), event.getMessage()); | ||
|
||
if(_debug >= 1){ | ||
plugin.getLogger().info(""); | ||
plugin.getLogger().info(""); | ||
plugin.getLogger().info("[DEBUG] [PlayerChat] [Player: "+ event.getPlayer().getName() + | ||
", Lang: "+ player.getLocale() +"] [Length: "+ msg.length() +"], [MODE: "+ mode.toString() +"]"); | ||
if(_debug >= 2){ | ||
plugin.getLogger().info(" - [FORMAT]: "+ event.getFormat()); | ||
plugin.getLogger().info(" - [MSG]: "+ event.getMessage()); | ||
plugin.getLogger().info(" - [GET]: "+ msg); | ||
} | ||
} | ||
Bukkit.getConsoleSender().sendMessage(msg); | ||
switch(mode){ | ||
case Convert -> Bukkit.spigot().broadcast(new TextComponent(msg)); | ||
case ConvertBypass -> { | ||
// 静默发送消息给每个玩家 | ||
PacketContainer chatPacket = protocolManager.createPacket(PacketType.Play.Server.SYSTEM_CHAT); | ||
chatPacket.getChatComponents().write(0, WrappedChatComponent.fromText(msg)); | ||
for(Player li : Bukkit.getOnlinePlayers()){ | ||
protocolManager.sendServerPacket(li, chatPacket, false); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} |
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