Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
Code -> Total code reformation
Browse files Browse the repository at this point in the history
  • Loading branch information
EinfacheSache committed Jul 21, 2023
1 parent c2a5e04 commit 73fad99
Show file tree
Hide file tree
Showing 41 changed files with 880 additions and 844 deletions.
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# NeoProtect plugin
Official NeoProtect plugin maintained by [EinfacheSache (aka CubeAttack)](https://github.com/EinfacheSache)

Official NeoProtect plugin maintained by [EinfacheSache (aka CubeAttack)](https://github.com/EinfacheSache)

## Feature

| Feature | Available |
|:--------------------------------------------------------------------|:-------------------:|
| Proxy Protocol | :white_check_mark: |
| Debug-tool for high ping problem (BungeeCord, Velocity coming soon) | :white_check_mark: |
| Auto update backend IP | :white_check_mark: |
| Anti-portscanner (Bungeecord + Velocity) | :white_check_mark: |
| IPanic mode command (toggle AntiBot level) | :white_check_mark: |
| Some commands to interact with NeoProtect intern system | :white_check_mark: |
| In-game message if server is under attack | :white_check_mark: |
| In-game analytics | :white_check_mark: |

| Feature | Available |
|:--------------------------------------------------------------------|:------------------:|
| Proxy Protocol | :white_check_mark: |
| Debug-tool for high ping problem (BungeeCord, Velocity coming soon) | :white_check_mark: |
| Auto update backend IP | :white_check_mark: |
| Anti-portscanner (Bungeecord + Velocity) | :white_check_mark: |
| IPanic mode command (toggle AntiBot level) | :white_check_mark: |
| Some commands to interact with NeoProtect intern system | :white_check_mark: |
| In-game message if server is under attack | :white_check_mark: |
| In-game analytics | :white_check_mark: |

Prerequisites:
=================
1) You have created an account and posess a GameShield at [NeoProtect](https://neoprotect.net).

1) You have created an account and possess a GameShield at [NeoProtect](https://neoprotect.net).
2) You have a server/network that you can connect to.
3) The required software installed [Compatibility version](https://github.com/NeoProtect/NeoPlugin/blob/master/SECURITY.md)


Install Instructions:
=====================

1) First, stop your server/network and put the plugin jar into the plugins folder.
Continue by starting your server and note that if there is a folder in the plugins folder called "NeoProtect",
Continue by starting your server and note that if there is a folder in the plugins folder called "NeoProtect",
don't change anything there.

2) Now join the server while having the permission "neoprotect.admin" when joining
and you should now see a message in the chat telling you how to proceed.
2) Now join the server while having the permission "neoprotect.admin" when joining
and you should now see a message in the chat telling you how to proceed.

## Permissions

Expand All @@ -44,7 +44,8 @@ Install Instructions:
| /np setbackend | set backend for establish the connection to NeoProtect | neoprotect.admin |
| under attack message | In-game message if server is under attack | neoprotect.admin<br/>neoprotect.notify |

## Take a look at the config.yml
## Take a look at the config.yml

```
# Don't change anything here if you don't know what you're doing
APIKey: '' # The API-KEY is set automatically during setup
Expand Down
20 changes: 11 additions & 9 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,43 @@
The following versions are compatible with the NeoProtect plugin,
for the remaining versions there is no support and no guarantee that they will work properly.

## Java
## Java

| Version | Supported |
| ------- | ------------------ |
|---------|--------------------|
| 17 | :white_check_mark: |
| 11 | :white_check_mark: |
| 8 | :white_check_mark: |
| < 8 | :x: |


## Spigot

| Version | Supported |
| ------- | ------------------ |
|---------|--------------------|
| 1.20.1 | :white_check_mark: |
| > 1.8.8 | :white_check_mark: |
| < 1.8.8 | :x: |


## BungeeCord

| Version | Supported |
| ------- | ------------------ |
|---------|--------------------|
| 1.20.1 | :white_check_mark: |
| > 1.8.8 | :white_check_mark: |
| < 1.8.8 | :x: |


## Velocity

| Version | Supported |
| ------- | ------------------ |
|---------|--------------------|
| 1.20.1 | :white_check_mark: |
| > 1.8.8 | :white_check_mark: |
| < 1.8.8 | :x: |

## Mohist

| Version | Supported |
| ------- | ------------------ |
|---------|--------------------|
| 1.20.1 | :white_check_mark: |
| > 1.8.8 | :white_check_mark: |
| < 1.8.8 | :x: |
Expand Down
28 changes: 14 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>de.cubeattack.neoprotect.libraries.org.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>com.squareup</pattern>
<shadedPattern>de.cubeattack.neoprotect.libraries.com.squareup</shadedPattern>
</relocation>
<relocation>
<pattern>okio</pattern>
<shadedPattern>de.cubeattack.neoprotect.libraries.okio</shadedPattern>
</relocation>
</relocations>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>de.cubeattack.neoprotect.libraries.org.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>com.squareup</pattern>
<shadedPattern>de.cubeattack.neoprotect.libraries.com.squareup</shadedPattern>
</relocation>
<relocation>
<pattern>okio</pattern>
<shadedPattern>de.cubeattack.neoprotect.libraries.okio</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,25 @@ public void sendMessage(Object receiver, String text) {
public void sendMessage(Object receiver, String text, String clickAction, String clickMsg, String hoverAction, String hoverMsg) {
TextComponent msg = new TextComponent(core.getPrefix() + text);

if(clickAction != null) msg.setClickEvent(new ClickEvent(ClickEvent.Action.valueOf(clickAction), clickMsg));
if(hoverAction != null) msg.setHoverEvent(new HoverEvent(HoverEvent.Action.valueOf(hoverAction), Collections.singletonList(new Text(hoverMsg))));
if(receiver instanceof CommandSender) ((CommandSender) receiver).sendMessage(msg);
if (clickAction != null) msg.setClickEvent(new ClickEvent(ClickEvent.Action.valueOf(clickAction), clickMsg));
if (hoverAction != null)
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.valueOf(hoverAction), Collections.singletonList(new Text(hoverMsg))));
if (receiver instanceof CommandSender) ((CommandSender) receiver).sendMessage(msg);
}

@Override
public void sendAdminMessage(Permission permission, String text, String clickAction, String clickMsg, String hoverAction, String hoverMsg) {
getProxy().getPlayers().forEach(receiver -> {
if(receiver.hasPermission("neoprotect.admin") || receiver.hasPermission(permission.value))
if (receiver.hasPermission("neoprotect.admin") || receiver.hasPermission(permission.value))
sendMessage(receiver, text, clickAction, clickMsg, hoverAction, hoverMsg);
});
}

@Override
public void sendKeepAliveMessage(Object receiver, long id) {
if(receiver instanceof ProxiedPlayer){
((ProxiedPlayer)receiver).unsafe().sendPacket(new KeepAlive(id));
getCore().getPingMap().put(new KeepAliveResponseKey(((ProxiedPlayer)receiver).getSocketAddress(), id), System.currentTimeMillis());
if (receiver instanceof ProxiedPlayer) {
((ProxiedPlayer) receiver).unsafe().sendPacket(new KeepAlive(id));
getCore().getPingMap().put(new KeepAliveResponseKey(((ProxiedPlayer) receiver).getSocketAddress(), id), System.currentTimeMillis());
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/de/cubeattack/neoprotect/bungee/Startup.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

public class Startup {

public Startup(NeoProtectBungee instance){
public Startup(NeoProtectBungee instance) {
register(instance);
new ProxyProtocol(instance);
}

private void register(NeoProtectBungee instance){
private void register(NeoProtectBungee instance) {
PluginManager pm = ProxyServer.getInstance().getPluginManager();
pm.registerCommand(instance, new NeoProtectCommand(instance,"neoprotect", "neoprotect.admin", "np"));
pm.registerCommand(instance, new NeoProtectCommand(instance, "neoprotect", "neoprotect.admin", "np"));

pm.registerListener(instance, new ChatListener(instance));
pm.registerListener(instance, new LoginListener(instance));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class NeoProtectCommand extends Command {

private final NeoProtectPlugin instance;
private final Localization localization;

public NeoProtectCommand(NeoProtectPlugin instance, String name, String permission, String... aliases) {
super(name, permission, aliases);
this.instance = instance;
Expand All @@ -20,7 +21,7 @@ public NeoProtectCommand(NeoProtectPlugin instance, String name, String permissi
@Override
public void execute(CommandSender sender, String[] args) {

if(!(sender instanceof ProxiedPlayer)) {
if (!(sender instanceof ProxiedPlayer)) {
instance.sendMessage(sender, localization.get("console.command"));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public void onTabComplete(TabCompleteEvent event) {
String[] cursorSplit = cursor.split(" ");
ArrayList<String> commands = new ArrayList<>();
ArrayList<String> tabListOne = new ArrayList<>();
ArrayList<String> tabListTwo= new ArrayList<>();
ArrayList<String> tabListTwo = new ArrayList<>();

commands.add("/np");
commands.add("/neoprotect");
tabListOne.add("setup");

if(instance.getCore().isSetup()){
if (instance.getCore().isSetup()) {
tabListOne.add("ipanic");
tabListOne.add("toggle");
tabListOne.add("debugtool");
Expand Down Expand Up @@ -79,7 +79,7 @@ public static ArrayList<String> completer(boolean sort, String cursor, List<Stri
}

for (String cmd : cmds) {

if (!cursor.startsWith(cmd + " ")) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
public class ChatListener implements Listener {

private final NeoProtectBungee instance;

public ChatListener(NeoProtectBungee instance) {
this.instance = instance;
}

@EventHandler
public void onChat(ChatEvent event){
public void onChat(ChatEvent event) {
CommandSender sender = (CommandSender) event.getSender();

if(!sender.hasPermission("neoprotect.admin") || !instance.getCore().getPlayerInSetup().contains(sender) || event.isCommand()) return;
if (!sender.hasPermission("neoprotect.admin") || !instance.getCore().getPlayerInSetup().contains(sender) || event.isCommand())
return;

event.setCancelled(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
public class DisconnectListener implements Listener {

private final NeoProtectBungee instance;

public DisconnectListener(NeoProtectBungee instance) {
this.instance = instance;
}

@EventHandler
public void onDisconnect(PlayerDisconnectEvent event){
public void onDisconnect(PlayerDisconnectEvent event) {
instance.getCore().getPlayerInSetup().remove(event.getPlayer());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public void onLogin(PostLoginEvent event) {
public void run() {
ProxiedPlayer player = event.getPlayer();

if (!player.hasPermission("neoprotect.admin") && Arrays.stream(instance.getCore().getMaintainerUUID()).noneMatch(uuid -> uuid.equals(player.getUniqueId()))) return;
if (!player.hasPermission("neoprotect.admin") && Arrays.stream(instance.getCore().getMaintainerUUID()).noneMatch(uuid -> uuid.equals(player.getUniqueId())))
return;

VersionUtils.Result result = instance.getCore().getVersionResult();
if (result.getVersionStatus().equals(VersionUtils.VersionStatus.OUTDATED)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ protected void initChannel(Channel channel) {

initChannelMethod.invoke(bungeeChannelInitializer, channel);

if(channel.localAddress().toString().startsWith("local:")){
if (channel.localAddress().toString().startsWith("local:")) {
instance.getCore().debug("Detected bedrock player (return)");
return;
}

if (instance.getCore().isSetup() && instance.getCore().getRestAPI().getNeoServerIPs() == null || !instance.getCore().getRestAPI().getNeoServerIPs().toList().
contains(((InetSocketAddress)channel.remoteAddress()).getAddress().getHostAddress())) {
contains(((InetSocketAddress) channel.remoteAddress()).getAddress().getHostAddress())) {
channel.close();
instance.getCore().debug("Close connection IP (" + channel.remoteAddress() + ") doesn't match to Neo-IPs (close / return)");
return;
Expand All @@ -85,13 +85,13 @@ protected void initChannel(Channel channel) {
Field serverChild = PipelineUtils.class.getField("SERVER_CHILD");
serverChild.setAccessible(true);

if(JavaUtils.javaVersionCheck() == 8){
if (JavaUtils.javaVersionCheck() == 8) {
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(serverChild, serverChild.getModifiers() & ~Modifier.FINAL);

serverChild.set(PipelineUtils.class, channelInitializer);
}else {
} else {
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);

Expand All @@ -106,7 +106,7 @@ protected void initChannel(Channel channel) {
}
}

public void addProxyProtocolHandler(Channel channel, AtomicReference<InetSocketAddress> inetAddress){
public void addProxyProtocolHandler(Channel channel, AtomicReference<InetSocketAddress> inetAddress) {
channel.pipeline().names().forEach((n) -> {
if (n.equals("HAProxyMessageDecoder#0"))
channel.pipeline().remove("HAProxyMessageDecoder#0");
Expand All @@ -127,7 +127,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
});
}

public void addKeepAlivePacketHandler(Channel channel, AtomicReference<InetSocketAddress> inetAddress, NeoProtectPlugin instance){
public void addKeepAlivePacketHandler(Channel channel, AtomicReference<InetSocketAddress> inetAddress, NeoProtectPlugin instance) {
channel.pipeline().addAfter(PipelineUtils.PACKET_DECODER, "neo-keep-alive-handler", new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
Expand All @@ -141,7 +141,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
}

KeepAlive keepAlive = (KeepAlive) ((PacketWrapper) msg).packet;
ConcurrentHashMap<KeepAliveResponseKey, Long> pingMap = instance.getCore().getPingMap();
ConcurrentHashMap<KeepAliveResponseKey, Long> pingMap = instance.getCore().getPingMap();

instance.getCore().debug("Received KeepAlivePackets (" + keepAlive.getRandomId() + ")");

Expand Down Expand Up @@ -177,7 +177,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

ConcurrentHashMap<String, ArrayList<DebugPingResponse>> map = instance.getCore().getDebugPingResponses();

if(!map.containsKey(player.getName())) {
if (!map.containsKey(player.getName())) {
instance.getCore().getDebugPingResponses().put(player.getName(), new ArrayList<>());
}

Expand Down
Loading

0 comments on commit 73fad99

Please sign in to comment.