Add Velocity ALP Classes
This commit is contained in:
parent
eb237aaa89
commit
d5a82e6005
@ -0,0 +1,32 @@
|
|||||||
|
// This class was created by JaTiTV.
|
||||||
|
|
||||||
|
package net.t2code.t2codelib.VELOCITY.api.commands;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.command.CommandManager;
|
||||||
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import net.t2code.t2codelib.VELOCITY.system.T2CodeVMain;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
public class T2CVcmd {
|
||||||
|
|
||||||
|
private static final ProxyServer server = T2CodeVMain.getServer();
|
||||||
|
private static final Logger logger = T2CodeVMain.getLogger();
|
||||||
|
|
||||||
|
public static void Console(String cmd) {
|
||||||
|
// Get the console command source
|
||||||
|
ConsoleCommandSource console = server.getConsoleCommandSource();
|
||||||
|
|
||||||
|
// Dispatch the command
|
||||||
|
server.getCommandManager().executeAsync(console, cmd).join();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Player(CommandSource player, String cmd) {
|
||||||
|
CommandManager commandManager = server.getCommandManager();
|
||||||
|
|
||||||
|
// Dispatch the command
|
||||||
|
commandManager.executeImmediatelyAsync(player, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
// This class was created by JaTiTV.
|
||||||
|
|
||||||
|
package net.t2code.t2codelib.VELOCITY.api.pluginMessaging;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import net.t2code.t2codelib.Util;
|
||||||
|
import net.t2code.t2codelib.VELOCITY.api.commands.T2CVcmd;
|
||||||
|
import net.t2code.t2codelib.VELOCITY.system.T2CodeVMain;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
public class T2CplmsgBcmd {
|
||||||
|
|
||||||
|
private static final ProxyServer server = T2CodeVMain.getServer();
|
||||||
|
private static final Logger logger = T2CodeVMain.getLogger();
|
||||||
|
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
|
server.getChannelRegistrar().register(T2CodeVMain.bcmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onPluginMessageFromPlayer(PluginMessageEvent event) {
|
||||||
|
if (event.getIdentifier() != T2CodeVMain.bcmd) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ByteArrayDataInput stream = ByteStreams.newDataInput(event.getData());
|
||||||
|
String channel = stream.readUTF();
|
||||||
|
String input = stream.readUTF();
|
||||||
|
String serverID;
|
||||||
|
try {
|
||||||
|
serverID = stream.readUTF();
|
||||||
|
} catch (Exception i) {
|
||||||
|
serverID = "not Found";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (channel.equals("T2Code-Console")) {
|
||||||
|
logger.info("{} [{}] T2C BCMD Command Console: {}", Util.getVPrefix(), serverID, input);
|
||||||
|
T2CVcmd.Console(input);
|
||||||
|
} else {
|
||||||
|
Player player = server.getPlayer(channel).orElse(null);
|
||||||
|
if (player != null) {
|
||||||
|
logger.info("{} [{}] T2C BCMD Command {}: {}", Util.getVPrefix(), serverID, player, input);
|
||||||
|
T2CVcmd.Player(player, input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
// This class was created by JaTiTV.
|
||||||
|
|
||||||
|
package net.t2code.t2codelib.VELOCITY.api.pluginMessaging.autoResponse;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import net.t2code.t2codelib.VELOCITY.api.commands.T2CVcmd;
|
||||||
|
import net.t2code.t2codelib.VELOCITY.api.messages.T2CVsend;
|
||||||
|
import net.t2code.t2codelib.VELOCITY.system.T2CodeVMain;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class T2CapiAutoResponse {
|
||||||
|
private static final ProxyServer server = T2CodeVMain.getServer();
|
||||||
|
private static final Logger logger = T2CodeVMain.getLogger();
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onPluginmessage(PluginMessageEvent event) {
|
||||||
|
if (event.getIdentifier() != T2CodeVMain.aresp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(event.getData()));
|
||||||
|
|
||||||
|
try {
|
||||||
|
String channel = stream.readUTF();
|
||||||
|
String input = stream.readUTF();
|
||||||
|
|
||||||
|
switch (channel) {
|
||||||
|
case "ConC":
|
||||||
|
logger.info("Command Console: {}", input);
|
||||||
|
T2CVcmd.Console(input);
|
||||||
|
break;
|
||||||
|
case "ALLPMSG":
|
||||||
|
for (Player player : server.getAllPlayers()) {
|
||||||
|
T2CVsend.player(player, input);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Player player = server.getPlayer(channel).orElse(null);
|
||||||
|
if (player != null) {
|
||||||
|
logger.info("Command Console: {}", input);
|
||||||
|
T2CVcmd.Player(player, input);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
// This class was created by JaTiTV.
|
||||||
|
|
||||||
|
package net.t2code.t2codelib.VELOCITY.api.pluginMessaging.commandgui;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||||
|
import com.velocitypowered.api.event.connection.PostLoginEvent;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
import net.t2code.t2codelib.VELOCITY.system.T2CodeVMain;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class T2CVapiCGUI {
|
||||||
|
|
||||||
|
private static final ProxyServer server = T2CodeVMain.getServer();
|
||||||
|
private static final Logger logger = T2CodeVMain.getLogger();
|
||||||
|
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onJoin(PostLoginEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
sendToSpigotPlayer(player.getUsername(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onDisconnect(DisconnectEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
sendToSpigotPlayer(player.getUsername(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToSpigotPlayer(String name, Boolean join) {
|
||||||
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream output = new DataOutputStream(stream);
|
||||||
|
try {
|
||||||
|
if (join) {
|
||||||
|
output.writeUTF("join");
|
||||||
|
} else {
|
||||||
|
output.writeUTF("left");
|
||||||
|
}
|
||||||
|
output.writeUTF(name);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.warn(e.getMessage());
|
||||||
|
}
|
||||||
|
byte[] data = stream.toByteArray();
|
||||||
|
for (RegisteredServer server : server.getAllServers()) {
|
||||||
|
server.sendPluginMessage(T2CodeVMain.cguiopl, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendToSpigotDeleteAll() {
|
||||||
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream output = new DataOutputStream(stream);
|
||||||
|
try {
|
||||||
|
output.writeUTF("clear");
|
||||||
|
output.writeUTF("");
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.warn(e.getMessage());
|
||||||
|
}
|
||||||
|
byte[] data = stream.toByteArray();
|
||||||
|
for (RegisteredServer server : server.getAllServers()) {
|
||||||
|
server.sendPluginMessage(T2CodeVMain.cguiopl, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
// This class was created by JaTiTV.
|
||||||
|
|
||||||
|
package net.t2code.t2codelib.VELOCITY.api.pluginMessaging.opSecurity;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
import net.t2code.t2codelib.VELOCITY.system.T2CodeVMain;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class T2CapiOpSecurity {
|
||||||
|
private static final ProxyServer server = T2CodeVMain.getServer();
|
||||||
|
private static final Logger logger = T2CodeVMain.getLogger();
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onPluginmessage(PluginMessageEvent event) {
|
||||||
|
if (event.getIdentifier() != T2CodeVMain.opsec) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(event.getData()));
|
||||||
|
try {
|
||||||
|
String channel = stream.readUTF();
|
||||||
|
String mode = stream.readUTF();
|
||||||
|
String information = stream.readUTF();
|
||||||
|
if (channel.equals("T2Cconsole")) {
|
||||||
|
sendToSpigotPlayer(channel,mode,information);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sendToSpigotPlayer(String channel,String mode,String information) {
|
||||||
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream output = new DataOutputStream(stream);
|
||||||
|
try {
|
||||||
|
output.writeUTF(channel);
|
||||||
|
output.writeUTF(mode);
|
||||||
|
output.writeUTF(information);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
}
|
||||||
|
for (RegisteredServer server : server.getAllServers()) {
|
||||||
|
server.sendPluginMessage(T2CodeVMain.opsec, stream.toByteArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
|||||||
import com.velocitypowered.api.plugin.PluginContainer;
|
import com.velocitypowered.api.plugin.PluginContainer;
|
||||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import net.t2code.t2codelib.Util;
|
import net.t2code.t2codelib.Util;
|
||||||
@ -21,7 +22,8 @@ import java.nio.file.Path;
|
|||||||
|
|
||||||
public class T2CodeVMain {
|
public class T2CodeVMain {
|
||||||
|
|
||||||
private final ProxyServer server;
|
@Getter
|
||||||
|
private static ProxyServer server;
|
||||||
@Getter
|
@Getter
|
||||||
private static Logger logger;
|
private static Logger logger;
|
||||||
@Getter
|
@Getter
|
||||||
@ -34,10 +36,17 @@ public class T2CodeVMain {
|
|||||||
private final Metrics.Factory metricsFactory;
|
private final Metrics.Factory metricsFactory;
|
||||||
|
|
||||||
|
|
||||||
|
public static final MinecraftChannelIdentifier bcmd = MinecraftChannelIdentifier.from("t2c:bcmd");
|
||||||
|
public static final MinecraftChannelIdentifier bonlp = MinecraftChannelIdentifier.from("t2c:bonlp");
|
||||||
|
public static final MinecraftChannelIdentifier cguiopl = MinecraftChannelIdentifier.from("t2c:cguiopl");
|
||||||
|
public static final MinecraftChannelIdentifier aresp = MinecraftChannelIdentifier.from("t2c:aresp");
|
||||||
|
public static final MinecraftChannelIdentifier opsec = MinecraftChannelIdentifier.from("t2c:opsec");
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public T2CodeVMain(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory, Metrics.Factory metricsFactory) {
|
public T2CodeVMain(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory, Metrics.Factory metricsFactory) {
|
||||||
starttime = System.currentTimeMillis();
|
starttime = System.currentTimeMillis();
|
||||||
this.server = server;
|
T2CodeVMain.server = server;
|
||||||
T2CodeVMain.logger = logger;
|
T2CodeVMain.logger = logger;
|
||||||
T2CodeVMain.dataDirectory = dataDirectory;
|
T2CodeVMain.dataDirectory = dataDirectory;
|
||||||
this.metricsFactory = metricsFactory;
|
this.metricsFactory = metricsFactory;
|
||||||
@ -69,12 +78,32 @@ public class T2CodeVMain {
|
|||||||
// new T2CVcmd(server, logger);
|
// new T2CVcmd(server, logger);
|
||||||
// server.getEventManager().register(this, new T2CVpluginMessagingCmd(server, logger));
|
// server.getEventManager().register(this, new T2CVpluginMessagingCmd(server, logger));
|
||||||
|
|
||||||
|
//API
|
||||||
|
server.getChannelRegistrar().register(T2CodeVMain.bcmd);
|
||||||
|
|
||||||
|
server.getChannelRegistrar().register(T2CodeVMain.bonlp);
|
||||||
|
T2CVPlayers.sendToSpigotDeleteAll();
|
||||||
|
|
||||||
|
// if (T2CVlibConfig.getApiCommandGUIEnable()) {
|
||||||
|
server.getChannelRegistrar().register(T2CodeVMain.cguiopl);
|
||||||
|
T2CVapiCGUI.sendToSpigotDeleteAll();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (T2CVlibConfig.getApiAutoResponse()) {
|
||||||
|
server.getChannelRegistrar().register(T2CodeVMain.aresp);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (T2CVlibConfig.getApiOpSecurity()) {
|
||||||
|
server.getChannelRegistrar().register(T2CodeVMain.opsec);
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
Metrics.bStats(this, Util.getBstatsID(), metricsFactory);
|
||||||
|
T2CVupdateAPI.onUpdateCheckTimer(logger, plugin, server, Util.getVPrefix(), Util.getDiscord(), Util.getSpigotID(), Util.getGit());
|
||||||
logger.info("║");
|
logger.info("║");
|
||||||
logger.info("║ Plugin loaded successfully - {}ms", System.currentTimeMillis() - starttime);
|
logger.info("║ Plugin loaded successfully - {}ms", System.currentTimeMillis() - starttime);
|
||||||
logger.info("╚════════════════════════════════════");
|
logger.info("╚════════════════════════════════════");
|
||||||
Metrics.bStats(this, Util.getBstatsID(), metricsFactory);
|
|
||||||
|
|
||||||
T2CVupdateAPI.onUpdateCheckTimer(logger, plugin, server, Util.getVPrefix(), Util.getDiscord(), Util.getSpigotID(), Util.getGit());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user