The hack works!
This commit is contained in:
parent
f85b56fe28
commit
f8c543017a
3 changed files with 49 additions and 20 deletions
2
pom.xml
2
pom.xml
|
@ -153,7 +153,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot</artifactId>
|
<artifactId>spigot</artifactId>
|
||||||
<version>1.12-R0.1-SNAPSHOT</version>
|
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -39,6 +39,7 @@ import sx.blah.discord.util.RequestBuffer.IVoidRequest;
|
||||||
public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
private static final String SubredditURL = "https://www.reddit.com/r/ChromaGamers";
|
private static final String SubredditURL = "https://www.reddit.com/r/ChromaGamers";
|
||||||
private static boolean stop = false;
|
private static boolean stop = false;
|
||||||
|
private static Thread mainThread;
|
||||||
public static IDiscordClient dc;
|
public static IDiscordClient dc;
|
||||||
public static DiscordPlugin plugin;
|
public static DiscordPlugin plugin;
|
||||||
public static boolean SafeMode = true;
|
public static boolean SafeMode = true;
|
||||||
|
@ -59,6 +60,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
cb.withToken(Files.readFirstLine(new File("TBMC", "Token.txt"), StandardCharsets.UTF_8));
|
cb.withToken(Files.readFirstLine(new File("TBMC", "Token.txt"), StandardCharsets.UTF_8));
|
||||||
dc = cb.login();
|
dc = cb.login();
|
||||||
dc.getDispatcher().registerListener(this);
|
dc.getDispatcher().registerListener(this);
|
||||||
|
mainThread = Thread.currentThread();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
|
@ -372,6 +374,8 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
public static <T> T perform(IRequest<T> action) {
|
public static <T> T perform(IRequest<T> action) {
|
||||||
if (SafeMode)
|
if (SafeMode)
|
||||||
return null;
|
return null;
|
||||||
|
if (Thread.currentThread() == mainThread)
|
||||||
|
throw new RuntimeException("Tried to wait for a Discord request on the main thread. This could cause lag.");
|
||||||
return RequestBuffer.request(action).get(); // Let the pros handle this
|
return RequestBuffer.request(action).get(); // Let the pros handle this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,6 +385,8 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
public static Void perform(IVoidRequest action) {
|
public static Void perform(IVoidRequest action) {
|
||||||
if (SafeMode)
|
if (SafeMode)
|
||||||
return null;
|
return null;
|
||||||
|
if (Thread.currentThread() == mainThread)
|
||||||
|
throw new RuntimeException("Tried to wait for a Discord request on the main thread. This could cause lag.");
|
||||||
return RequestBuffer.request(action).get(); // Let the pros handle this
|
return RequestBuffer.request(action).get(); // Let the pros handle this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.UUID;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
|
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.v1_12_R1.util.CraftChatMessage;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
import org.objenesis.ObjenesisStd;
|
import org.objenesis.ObjenesisStd;
|
||||||
|
|
||||||
|
@ -17,6 +18,7 @@ import buttondevteam.discordplugin.listeners.MCChatListener;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import net.minecraft.server.v1_12_R1.AdvancementDataPlayer;
|
import net.minecraft.server.v1_12_R1.AdvancementDataPlayer;
|
||||||
|
import net.minecraft.server.v1_12_R1.ChatMessageType;
|
||||||
import net.minecraft.server.v1_12_R1.DedicatedPlayerList;
|
import net.minecraft.server.v1_12_R1.DedicatedPlayerList;
|
||||||
import net.minecraft.server.v1_12_R1.DedicatedServer;
|
import net.minecraft.server.v1_12_R1.DedicatedServer;
|
||||||
import net.minecraft.server.v1_12_R1.Entity;
|
import net.minecraft.server.v1_12_R1.Entity;
|
||||||
|
@ -31,6 +33,7 @@ import net.minecraft.server.v1_12_R1.NBTTagCompound;
|
||||||
import net.minecraft.server.v1_12_R1.NetworkManager;
|
import net.minecraft.server.v1_12_R1.NetworkManager;
|
||||||
import net.minecraft.server.v1_12_R1.OpList;
|
import net.minecraft.server.v1_12_R1.OpList;
|
||||||
import net.minecraft.server.v1_12_R1.Packet;
|
import net.minecraft.server.v1_12_R1.Packet;
|
||||||
|
import net.minecraft.server.v1_12_R1.PacketPlayOutChat;
|
||||||
import net.minecraft.server.v1_12_R1.ScoreboardServer;
|
import net.minecraft.server.v1_12_R1.ScoreboardServer;
|
||||||
import net.minecraft.server.v1_12_R1.ServerStatisticManager;
|
import net.minecraft.server.v1_12_R1.ServerStatisticManager;
|
||||||
import net.minecraft.server.v1_12_R1.WhiteList;
|
import net.minecraft.server.v1_12_R1.WhiteList;
|
||||||
|
@ -44,10 +47,39 @@ public class PlayerListWatcher extends DedicatedPlayerList {
|
||||||
super(minecraftserver); // <-- Does some init stuff and calls Bukkit.setServer() so we have to use Objenesis
|
super(minecraftserver); // <-- Does some init stuff and calls Bukkit.setServer() so we have to use Objenesis
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendAll(Packet<?> packet) {
|
||||||
|
plist.sendAll(packet);
|
||||||
|
try { // Some messages get sent by directly constructing a packet
|
||||||
|
if (packet instanceof PacketPlayOutChat) {
|
||||||
|
Field msgf = PacketPlayOutChat.class.getDeclaredField("a");
|
||||||
|
msgf.setAccessible(true);
|
||||||
|
MCChatListener.sendSystemMessageToChat(((IChatBaseComponent) msgf.get(packet)).toPlainText());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
TBMCCoreAPI.SendException("Failed to broadcast message sent to all players - hacking failed.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(IChatBaseComponent ichatbasecomponent, boolean flag) {
|
public void sendMessage(IChatBaseComponent ichatbasecomponent, boolean flag) { // Needed so it calls the overriden method
|
||||||
super.sendMessage(ichatbasecomponent, flag);
|
plist.getServer().sendMessage(ichatbasecomponent);
|
||||||
MCChatListener.sendSystemMessageToChat(ichatbasecomponent.toPlainText());
|
ChatMessageType chatmessagetype = flag ? ChatMessageType.SYSTEM : ChatMessageType.CHAT;
|
||||||
|
|
||||||
|
// CraftBukkit start - we run this through our processor first so we can get web links etc
|
||||||
|
this.sendAll(new PacketPlayOutChat(CraftChatMessage.fixComponent(ichatbasecomponent), chatmessagetype));
|
||||||
|
// CraftBukkit end
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(IChatBaseComponent ichatbasecomponent) { // Needed so it calls the overriden method
|
||||||
|
this.sendMessage(ichatbasecomponent, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(IChatBaseComponent[] iChatBaseComponents) { // Needed so it calls the overriden method
|
||||||
|
for (IChatBaseComponent component : iChatBaseComponents) {
|
||||||
|
sendMessage(component, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void hookUp() {
|
public static void hookUp() {
|
||||||
|
@ -65,6 +97,9 @@ public class PlayerListWatcher extends DedicatedPlayerList {
|
||||||
modf.set(plf, plf.getModifiers() & ~Modifier.FINAL);
|
modf.set(plf, plf.getModifiers() & ~Modifier.FINAL);
|
||||||
plf.set(plw, plw.plist.players);
|
plf.set(plw, plw.plist.players);
|
||||||
server.a(plw);
|
server.a(plw);
|
||||||
|
Field pllf = CraftServer.class.getDeclaredField("playerList");
|
||||||
|
pllf.setAccessible(true);
|
||||||
|
pllf.set(Bukkit.getServer(), plw);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("Error while hacking the player list!", e);
|
TBMCCoreAPI.SendException("Error while hacking the player list!", e);
|
||||||
}
|
}
|
||||||
|
@ -74,10 +109,6 @@ public class PlayerListWatcher extends DedicatedPlayerList {
|
||||||
plist.a(entityhuman, ichatbasecomponent);
|
plist.a(entityhuman, ichatbasecomponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerStatisticManager a(EntityHuman entityhuman) {
|
|
||||||
return plist.a(entityhuman);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void a(EntityPlayer entityplayer, int i) {
|
public void a(EntityPlayer entityplayer, int i) {
|
||||||
plist.a(entityplayer, i);
|
plist.a(entityplayer, i);
|
||||||
}
|
}
|
||||||
|
@ -297,18 +328,6 @@ public class PlayerListWatcher extends DedicatedPlayerList {
|
||||||
plist.sendAll(packet, world);
|
plist.sendAll(packet, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendAll(Packet<?> packet) {
|
|
||||||
plist.sendAll(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessage(IChatBaseComponent ichatbasecomponent) {
|
|
||||||
plist.sendMessage(ichatbasecomponent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessage(IChatBaseComponent[] iChatBaseComponents) {
|
|
||||||
plist.sendMessage(iChatBaseComponents);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendPacketNearby(EntityHuman entityhuman, double d0, double d1, double d2, double d3, int i,
|
public void sendPacketNearby(EntityHuman entityhuman, double d0, double d1, double d2, double d3, int i,
|
||||||
Packet<?> packet) {
|
Packet<?> packet) {
|
||||||
plist.sendPacketNearby(entityhuman, d0, d1, d2, d3, i, packet);
|
plist.sendPacketNearby(entityhuman, d0, d1, d2, d3, i, packet);
|
||||||
|
@ -349,4 +368,8 @@ public class PlayerListWatcher extends DedicatedPlayerList {
|
||||||
public List<EntityPlayer> v() {
|
public List<EntityPlayer> v() {
|
||||||
return plist.v();
|
return plist.v();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerStatisticManager getStatisticManager(EntityPlayer entityhuman) {
|
||||||
|
return plist.getStatisticManager(entityhuman);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue