Skip to content
This repository was archived by the owner on Nov 23, 2021. It is now read-only.

Commit de3294d

Browse files
committed
Add experimental velocity proxy support
Mostly added so I can see how well the abstraction changes are working. Fairly well, clearly more work to do. The velocity module will eventually need its own tests and handlers and etc, but that can come with time. I can already see that we're going to need some sort of ugly workaround for Optionals.
1 parent d962d45 commit de3294d

File tree

10 files changed

+575
-2
lines changed

10 files changed

+575
-2
lines changed

debuggery-common/src/main/java/io/zachbr/debuggery/util/PlatformType.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
package io.zachbr.debuggery.util;
1919

2020
public enum PlatformType {
21-
BUKKIT
21+
BUKKIT,
22+
VELOCITY
2223
}

debuggery-velocity/build.gradle

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
plugins {
2+
id "net.kyori.blossom" version "1.1.0"
3+
}
4+
5+
repositories {
6+
maven {
7+
name = 'velocity'
8+
url = 'https://repo.velocitypowered.com/snapshots/'
9+
}
10+
}
11+
12+
dependencies {
13+
compile project(':debuggery-common')
14+
compile 'com.velocitypowered:velocity-api:1.0-SNAPSHOT'
15+
annotationProcessor 'com.velocitypowered:velocity-api:1.0-SNAPSHOT'
16+
17+
testCompile project (path: ":debuggery-common", configuration: 'testArtifacts')
18+
}
19+
20+
blossom {
21+
def main = 'src/main/java/io/zachbr/debuggery/DebuggeryVelocity.java'
22+
replaceToken '@version@', pluginVersion, main
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* This file is part of Debuggery.
3+
*
4+
* Debuggery is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Debuggery is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Debuggery. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package io.zachbr.debuggery;
19+
20+
import com.google.inject.Inject;
21+
import com.velocitypowered.api.plugin.Plugin;
22+
import com.velocitypowered.api.plugin.PluginContainer;
23+
import com.velocitypowered.api.proxy.ProxyServer;
24+
import io.zachbr.debuggery.commands.*;
25+
import io.zachbr.debuggery.commands.base.CommandBase;
26+
import io.zachbr.debuggery.util.PlatformType;
27+
28+
import java.util.HashMap;
29+
import java.util.Map;
30+
31+
@Plugin(id = "debuggery",
32+
name = "Debuggery",
33+
version = "1.3.0-SNAPSHOT", // todo - make gradle deal with this
34+
description = "A small plugin designed to expose API values at runtime.",
35+
authors = {"Z750"},
36+
url = "https://github.com/zachbr/Debuggery")
37+
public class DebuggeryVelocity extends DebuggeryBase {
38+
private final ProxyServer server;
39+
private final Map<String, CommandBase> commands = new HashMap<>();
40+
private PluginContainer container;
41+
42+
@Inject
43+
DebuggeryVelocity(ProxyServer server, org.slf4j.Logger logger) {
44+
super(new VelocityLogger(logger), PlatformType.VELOCITY);
45+
this.server = server;
46+
47+
registerCommand(new ProxyPlayerCommand(this));
48+
registerCommand(new ProxyServerCommand(this));
49+
registerCommand(new ServerConnectionCommand(this));
50+
}
51+
52+
@Override
53+
String getPluginVersion() {
54+
if (this.container == null) {
55+
this.container = server.getPluginManager().getPlugin("debuggery").orElseThrow();
56+
}
57+
58+
return this.container.getDescription().getVersion().orElseThrow();
59+
}
60+
61+
@Override
62+
String getPlatformName() {
63+
return server.getVersion().getName();
64+
}
65+
66+
@Override
67+
String getPlatformVersion() {
68+
return server.getVersion().getVersion();
69+
}
70+
71+
public ProxyServer getProxyServer() {
72+
return this.server;
73+
}
74+
75+
private void registerCommand(CommandBase base) {
76+
this.commands.put(base.getName(), base);
77+
this.server.getCommandManager().register(base, base.getName());
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* This file is part of Debuggery.
3+
*
4+
* Debuggery is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Debuggery is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Debuggery. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package io.zachbr.debuggery;
19+
20+
public class VelocityLogger implements Logger {
21+
private final org.slf4j.Logger platformLogger;
22+
23+
VelocityLogger(org.slf4j.Logger platformLogger) {
24+
this.platformLogger = platformLogger;
25+
}
26+
27+
@Override
28+
public void info(String str) {
29+
platformLogger.info(str);
30+
}
31+
32+
@Override
33+
public void warn(String str) {
34+
platformLogger.warn(str);
35+
}
36+
37+
@Override
38+
public void err(String str) {
39+
platformLogger.error(str);
40+
}
41+
42+
@Override
43+
public void debug(String str) {
44+
platformLogger.debug(str);
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* This file is part of Debuggery.
3+
*
4+
* Debuggery is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Debuggery is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Debuggery. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package io.zachbr.debuggery.commands;
19+
20+
import com.velocitypowered.api.command.CommandSource;
21+
import com.velocitypowered.api.proxy.Player;
22+
import io.zachbr.debuggery.DebuggeryVelocity;
23+
import io.zachbr.debuggery.commands.base.CommandReflection;
24+
import org.jetbrains.annotations.NotNull;
25+
26+
public class ProxyPlayerCommand extends CommandReflection {
27+
28+
public ProxyPlayerCommand(DebuggeryVelocity plugin) {
29+
super("vplayer", "debuggery.vplayer", true, Player.class, plugin);
30+
}
31+
32+
@Override
33+
protected void commandLogic(@NotNull CommandSource source, @NotNull String[] args) {
34+
doReflectionLookups(source, args, source);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This file is part of Debuggery.
3+
*
4+
* Debuggery is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Debuggery is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Debuggery. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package io.zachbr.debuggery.commands;
19+
20+
import com.velocitypowered.api.command.CommandSource;
21+
import com.velocitypowered.api.proxy.ProxyServer;
22+
import io.zachbr.debuggery.DebuggeryVelocity;
23+
import io.zachbr.debuggery.commands.base.CommandReflection;
24+
import org.jetbrains.annotations.NotNull;
25+
26+
public class ProxyServerCommand extends CommandReflection {
27+
private final DebuggeryVelocity debuggery;
28+
29+
public ProxyServerCommand(DebuggeryVelocity plugin) {
30+
super("vproxy", "debuggery.vproxy", false, ProxyServer.class, plugin);
31+
this.debuggery = plugin;
32+
}
33+
34+
@Override
35+
protected void commandLogic(@NotNull CommandSource source, @NotNull String[] args) {
36+
doReflectionLookups(source, args, debuggery.getProxyServer());
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* This file is part of Debuggery.
3+
*
4+
* Debuggery is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Debuggery is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Debuggery. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package io.zachbr.debuggery.commands;
19+
20+
import com.velocitypowered.api.command.CommandSource;
21+
import com.velocitypowered.api.proxy.Player;
22+
import com.velocitypowered.api.proxy.ServerConnection;
23+
import io.zachbr.debuggery.DebuggeryVelocity;
24+
import io.zachbr.debuggery.commands.base.CommandReflection;
25+
import net.kyori.text.TextComponent;
26+
import net.kyori.text.format.TextColor;
27+
import org.jetbrains.annotations.NotNull;
28+
29+
public class ServerConnectionCommand extends CommandReflection {
30+
31+
public ServerConnectionCommand(DebuggeryVelocity plugin) {
32+
super("vconnection", "debuggery.vconnection", true, ServerConnection.class, plugin);
33+
}
34+
35+
@Override
36+
protected void commandLogic(@NotNull CommandSource source, @NotNull String[] args) {
37+
Player player = (Player) source;
38+
player.getCurrentServer().ifPresentOrElse(
39+
it -> doReflectionLookups(source, args, it),
40+
() -> source.sendMessage(TextComponent.of("Not connected to a server!").color(TextColor.RED)));
41+
}
42+
}

0 commit comments

Comments
 (0)