-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
d7e461c
commit ca18d17
Showing
4 changed files
with
176 additions
and
5 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
110 changes: 110 additions & 0 deletions
110
...a/eu/endermite/commandwhitelist/spigot/listeners/LegacyPlayerTabChatCompleteListener.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,110 @@ | ||
package eu.endermite.commandwhitelist.spigot.listeners; | ||
|
||
import com.comphenix.protocol.PacketType; | ||
import com.comphenix.protocol.ProtocolLibrary; | ||
import com.comphenix.protocol.ProtocolManager; | ||
import com.comphenix.protocol.events.ListenerPriority; | ||
import com.comphenix.protocol.events.PacketAdapter; | ||
import com.comphenix.protocol.events.PacketContainer; | ||
import com.comphenix.protocol.events.PacketEvent; | ||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class LegacyPlayerTabChatCompleteListener { | ||
|
||
public static void protocol(CommandWhitelist plugin) { | ||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); | ||
tabCompleteServerBound(protocolManager, plugin); | ||
tabCompleteClientBound(protocolManager, plugin); | ||
} | ||
|
||
public static void tabCompleteServerBound(ProtocolManager protocolManager, Plugin plugin) { | ||
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.TAB_COMPLETE) { | ||
@Override | ||
public void onPacketSending(PacketEvent event) { | ||
|
||
try { | ||
Player player = event.getPlayer(); | ||
if (player.hasPermission("commandwhitelist.bypass")) { | ||
return; | ||
} | ||
PacketContainer packet = event.getPacket(); | ||
String[] message = packet.getSpecificModifier(String[].class).read(0); | ||
|
||
List<String> commandList = new ArrayList<>(); | ||
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) { | ||
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) { | ||
commandList.addAll(s.getValue()); | ||
} | ||
} | ||
|
||
List<String> finalList = new ArrayList<>(); | ||
int components = 0; | ||
|
||
for (String cmd : message) { | ||
for (String cmdFromList : commandList) { | ||
if (cmd.equalsIgnoreCase("/" + cmdFromList) || !cmd.startsWith("/")) { | ||
finalList.add(components++, cmd); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
String[] toWrite = new String[components]; | ||
int counter = 0; | ||
for (String cmd : finalList) { | ||
toWrite[counter++] = cmd; | ||
} | ||
|
||
packet.getSpecificModifier(String[].class).write(0, toWrite); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
}); | ||
} | ||
|
||
public static void tabCompleteClientBound(ProtocolManager protocolManager, Plugin plugin) { | ||
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.TAB_COMPLETE) { | ||
@Override | ||
public void onPacketReceiving(PacketEvent event) { | ||
try { | ||
Player player = event.getPlayer(); | ||
if (player.hasPermission("commandwhitelist.bypass")) { | ||
return; | ||
} | ||
PacketContainer packet = event.getPacket(); | ||
String command = packet.getSpecificModifier(String.class).read(0); | ||
System.out.println(command); | ||
|
||
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) { | ||
if (player.hasPermission("commandwhitelist.commands." + s.getKey())) { | ||
for (String comm : s.getValue()) { | ||
comm = comm.toLowerCase(); | ||
if (command.equalsIgnoreCase("/"+comm)) | ||
return; | ||
else if (command.startsWith("/" + comm + " ")) { | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
event.setCancelled(true); | ||
|
||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
}); | ||
} | ||
|
||
} |
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