Skip to content

Commit

Permalink
Update to Spigot v1_11_R1
Browse files Browse the repository at this point in the history
- Add Maven, please download a spigot.jar into a directory called lib/
- Fixed issue with ProtocolLib (moved inject code to onLoad and added dependency in plugin.yml)
- Fixed issue with getting the actual ip (InetSocketAddress.createUnresolved to new InetSocketAddress). I was getting NPEs there
- Added something to .gitignore :)
  • Loading branch information
boomer41 committed May 29, 2017
1 parent 63cd0af commit 3f08dab
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Created by .ignore support plugin (hsz.mobi)
.idea/
SpigotProxy.iml
*.iml
lib/
target/
27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>nl.thijsalders</groupId>
<artifactId>spigotproxy</artifactId>
<version>1</version>
<packaging>jar</packaging>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.11.2-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/spigot.jar</systemPath>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.spigotmc.SpigotConfig;

public class SpigotProxy extends JavaPlugin{
public class SpigotProxy extends JavaPlugin {

private String channelFieldName;

public void onEnable(){
if(SpigotConfig.lateBind){
public void onLoad(){
if (SpigotConfig.lateBind){
getLogger().log(Level.SEVERE, "Please disable late-bind in the spigot config in order to make this plugin work");
return;
}
Expand All @@ -30,7 +30,7 @@ public void onEnable(){
if(channelFieldName == null){
getLogger().log(Level.SEVERE, "Unknown server version " + version + ", please see if there are any updates avaible");
return;
}else{
} else {
getLogger().info("Detected server version " + version);
}
try {
Expand All @@ -44,7 +44,7 @@ public void onEnable(){
}

@SuppressWarnings("unchecked")
private void inject() throws Exception{
private void inject() throws Exception {
Method serverGetHandle = Bukkit.getServer().getClass().getDeclaredMethod("getServer");
Object minecraftServer = serverGetHandle.invoke(Bukkit.getServer());

Expand All @@ -62,6 +62,7 @@ private void inject() throws Exception{
for(ChannelFuture channelFuture : channelFutureList) {
ChannelPipeline channelPipeline = channelFuture.channel().pipeline();
ChannelHandler serverBootstrapAcceptor = channelPipeline.first();
System.out.println(serverBootstrapAcceptor.getClass().getName());
ChannelInitializer<SocketChannel> oldChildHandler = ReflectionUtils.getPrivateField(serverBootstrapAcceptor.getClass(), serverBootstrapAcceptor, ChannelInitializer.class, "childHandler");
ReflectionUtils.setFinalField(serverBootstrapAcceptor.getClass(), serverBootstrapAcceptor, "childHandler", new NettyChannelInitializer(oldChildHandler));
}
Expand All @@ -70,6 +71,7 @@ private void inject() throws Exception{
public String getChannelFieldName(String version){
String name = null;
switch (version){
case "v1_11_R1":
case "v1_10_R1":
case "v1_9_R2":
case "v1_9_R1":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.net.InetSocketAddress;
import java.net.SocketAddress;

import net.minecraft.server.v1_10_R1.NetworkManager;
import net.minecraft.server.v1_11_R1.NetworkManager;
import nl.thijsalders.spigotproxy.haproxy.HAProxyMessage;
import nl.thijsalders.spigotproxy.haproxy.HAProxyMessageDecoder;

Expand Down Expand Up @@ -39,8 +39,8 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
String realaddress = message.sourceAddress();
int realport = message.sourcePort();

SocketAddress socketaddr = InetSocketAddress.createUnresolved(realaddress, realport);
SocketAddress socketaddr = new InetSocketAddress(realaddress, realport);

NetworkManager networkmanager = (NetworkManager) channel.pipeline().get("packet_handler");
networkmanager.l = socketaddr;
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/plugin.yml → src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ name: SpigotProxy
main: nl.thijsalders.spigotproxy.SpigotProxy
version: 1
author: thijs_a
commands:
test:
description: test
loadbefore: ["ProtocolLib"]

0 comments on commit 3f08dab

Please sign in to comment.