-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework to minimize future need for compatibility with other addons.
Removed BTHNetServerHandler
- Loading branch information
1 parent
c2865f8
commit 5a2d1ef
Showing
19 changed files
with
231 additions
and
83 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This class should contain a list of custom NetServerHandler classes for every BTW addon | ||
// that sends custom network packages. This will ensure compatibility for future releases | ||
// without needing to keep changing every addon's source code when other addons update. | ||
// If a new BTW addon is released that also handles custom network packages this list | ||
// should be updated with it's custom network handler class name, following the same pattern bellow. | ||
|
||
class_name=JBNetServerHandler | ||
class_name=AddonNetServerHandler |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This class should contain a list of custom NetServerHandler classes for every BTW addon | ||
// that sends custom network packages. This will ensure compatibility for future releases | ||
// without needing to keep changing every addon's source code when other addons update. | ||
// If a new BTW addon is released that also handles custom network packages this list | ||
// should be updated with it's custom network handler class name, following the same pattern bellow. | ||
|
||
class_name=JBNetServerHandler | ||
class_name=AddonNetServerHandler |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
src/minecraft/net/minecraft/src/CustomBTWAddonNetServerHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.minecraft.src; | ||
|
||
import net.minecraft.server.MinecraftServer; | ||
|
||
public abstract class CustomBTWAddonNetServerHandler { | ||
public CustomBTWAddonNetServerHandler(MinecraftServer aServer, INetworkManager aNetManager, EntityPlayerMP aPlayer) {} | ||
|
||
public void handleCustomPayload(Packet250CustomPayload aPacket) {} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/minecraft/net/minecraft/src/GenericBTWAddonNetServerHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package net.minecraft.src; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
import java.lang.reflect.Constructor; | ||
import java.util.ArrayList; | ||
|
||
import net.minecraft.server.MinecraftServer; | ||
|
||
public class GenericBTWAddonNetServerHandler extends NetServerHandler { | ||
private ArrayList<CustomBTWAddonNetServerHandler> customHandlers = new ArrayList<CustomBTWAddonNetServerHandler>(); | ||
public final MinecraftServer mcServer; | ||
public EntityPlayerMP playerEntity; | ||
|
||
public GenericBTWAddonNetServerHandler(MinecraftServer aServer, INetworkManager aNetManager, EntityPlayerMP aPlayer) { | ||
super(aServer, aNetManager, aPlayer); | ||
|
||
this.mcServer = aServer; | ||
this.playerEntity = aPlayer; | ||
|
||
String prefix = getClassPackagePrefix(); | ||
ArrayList<String> classNames = getCustomNetworkListenersClassNames(); | ||
|
||
try { | ||
for (String className : classNames) { | ||
Constructor<?> c = Class.forName(prefix + className).getConstructor(MinecraftServer.class, INetworkManager.class, | ||
EntityPlayerMP.class); | ||
|
||
CustomBTWAddonNetServerHandler nsh = (CustomBTWAddonNetServerHandler) c.newInstance(aServer, aNetManager, aPlayer); | ||
|
||
customHandlers.add(nsh); | ||
} | ||
} catch (Throwable e) {} | ||
} | ||
|
||
public void handleCustomPayload(Packet250CustomPayload aPacket) { | ||
for (CustomBTWAddonNetServerHandler netHandler : customHandlers) { | ||
netHandler.handleCustomPayload(aPacket); | ||
} | ||
} | ||
|
||
private static ArrayList<String> getCustomNetworkListenersClassNames() { | ||
ArrayList<String> result = new ArrayList<String>(); | ||
BufferedReader buffer = null; | ||
|
||
try { | ||
buffer = new BufferedReader( | ||
new InputStreamReader(NetworkListenThread.class.getResourceAsStream("/SharedCompatibilityAddonConfig.txt"))); | ||
} catch (Throwable e) { | ||
// Currently known addons | ||
result.add("JBNetServerHandler"); | ||
result.add("AddonNetServerHandler"); | ||
return result; | ||
} | ||
|
||
try { | ||
String line = ""; | ||
|
||
while ((line = buffer.readLine()) != null) { | ||
String[] value = line.split("="); | ||
|
||
for (int i = 0; i < value.length; ++i) { | ||
value[i] = value[i].trim(); | ||
} | ||
|
||
if (!value[0].equals("class_name")) { | ||
continue; | ||
} | ||
|
||
result.add(value[1]); | ||
} | ||
|
||
buffer.close(); | ||
} catch (Throwable e) { | ||
System.out.println("Failed to load SharedCompatibilityAddonConfig.txt"); | ||
e.printStackTrace(); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private String getClassPackagePrefix() { | ||
try { | ||
if (Class.forName("FCBetterThanWolves") != null) { | ||
return ""; | ||
} | ||
} catch (Throwable e) { | ||
} | ||
try { | ||
if (Class.forName("net.minecraft.src.FCBetterThanWolves") != null) { | ||
return "net.minecraft.src."; | ||
} | ||
} catch (Throwable e) { | ||
} | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
src/minecraft_server/net/minecraft/src/BTHNetServerHandler.java
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
src/minecraft_server/net/minecraft/src/CustomBTWAddonNetServerHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.minecraft.src; | ||
|
||
import net.minecraft.server.MinecraftServer; | ||
|
||
public abstract class CustomBTWAddonNetServerHandler { | ||
public CustomBTWAddonNetServerHandler(MinecraftServer aServer, INetworkManager aNetManager, EntityPlayerMP aPlayer) {} | ||
|
||
public void handleCustomPayload(Packet250CustomPayload aPacket) {} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/minecraft_server/net/minecraft/src/GenericBTWAddonNetServerHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package net.minecraft.src; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
import java.lang.reflect.Constructor; | ||
import java.util.ArrayList; | ||
|
||
import net.minecraft.server.MinecraftServer; | ||
|
||
public class GenericBTWAddonNetServerHandler extends NetServerHandler { | ||
private ArrayList<CustomBTWAddonNetServerHandler> customHandlers = new ArrayList<CustomBTWAddonNetServerHandler>(); | ||
public final MinecraftServer mcServer; | ||
public EntityPlayerMP playerEntity; | ||
|
||
public GenericBTWAddonNetServerHandler(MinecraftServer aServer, INetworkManager aNetManager, EntityPlayerMP aPlayer) { | ||
super(aServer, aNetManager, aPlayer); | ||
|
||
this.mcServer = aServer; | ||
this.playerEntity = aPlayer; | ||
|
||
String prefix = getClassPackagePrefix(); | ||
ArrayList<String> classNames = getCustomNetworkListenersClassNames(); | ||
|
||
try { | ||
for (String className : classNames) { | ||
Constructor<?> c = Class.forName(prefix + className).getConstructor(MinecraftServer.class, INetworkManager.class, | ||
EntityPlayerMP.class); | ||
|
||
CustomBTWAddonNetServerHandler nsh = (CustomBTWAddonNetServerHandler) c.newInstance(aServer, aNetManager, aPlayer); | ||
|
||
customHandlers.add(nsh); | ||
} | ||
} catch (Throwable e) {} | ||
} | ||
|
||
public void handleCustomPayload(Packet250CustomPayload aPacket) { | ||
for (CustomBTWAddonNetServerHandler netHandler : customHandlers) { | ||
netHandler.handleCustomPayload(aPacket); | ||
} | ||
} | ||
|
||
private static ArrayList<String> getCustomNetworkListenersClassNames() { | ||
ArrayList<String> result = new ArrayList<String>(); | ||
BufferedReader buffer = null; | ||
|
||
try { | ||
buffer = new BufferedReader( | ||
new InputStreamReader(NetworkListenThread.class.getResourceAsStream("/SharedCompatibilityAddonConfig.txt"))); | ||
} catch (Throwable e) { | ||
// Currently known addons | ||
result.add("JBNetServerHandler"); | ||
result.add("AddonNetServerHandler"); | ||
return result; | ||
} | ||
|
||
try { | ||
String line = ""; | ||
|
||
while ((line = buffer.readLine()) != null) { | ||
String[] value = line.split("="); | ||
|
||
for (int i = 0; i < value.length; ++i) { | ||
value[i] = value[i].trim(); | ||
} | ||
|
||
if (!value[0].equals("class_name")) { | ||
continue; | ||
} | ||
|
||
result.add(value[1]); | ||
} | ||
|
||
buffer.close(); | ||
} catch (Throwable e) { | ||
System.out.println("Failed to load SharedCompatibilityAddonConfig.txt"); | ||
e.printStackTrace(); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private String getClassPackagePrefix() { | ||
try { | ||
if (Class.forName("FCBetterThanWolves") != null) { | ||
return ""; | ||
} | ||
} catch (Throwable e) { | ||
} | ||
try { | ||
if (Class.forName("net.minecraft.src.FCBetterThanWolves") != null) { | ||
return "net.minecraft.src."; | ||
} | ||
} catch (Throwable e) { | ||
} | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters