Skip to content

Commit

Permalink
Close the channel better
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Dec 1, 2013
1 parent 0a87a0a commit 82e627c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import java.io.IOException;

import net.citizensnpcs.util.NMS;
import net.minecraft.server.v1_7_R1.NetworkManager;
import net.minecraft.util.io.netty.channel.ChannelHandlerContext;

public class EmptyNetworkManager extends NetworkManager {
public EmptyNetworkManager(boolean flag) throws IOException {
super(flag);
NMS.stopNetworkThreads(this);
}

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
super.channelActive(ctx);
ctx.channel().close();
}
}
14 changes: 0 additions & 14 deletions src/main/java/net/citizensnpcs/util/NMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@
import net.minecraft.server.v1_7_R1.MathHelper;
import net.minecraft.server.v1_7_R1.MobEffectList;
import net.minecraft.server.v1_7_R1.Navigation;
import net.minecraft.server.v1_7_R1.NetworkManager;
import net.minecraft.server.v1_7_R1.Packet;
import net.minecraft.server.v1_7_R1.PathfinderGoalSelector;
import net.minecraft.server.v1_7_R1.World;
import net.minecraft.util.io.netty.channel.Channel;

import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -410,17 +408,6 @@ public static void stopNavigation(Navigation navigation) {
navigation.h();
}

public static void stopNetworkThreads(NetworkManager manager) {
if (THREAD_STOPPER == null)
return;
try {
Channel channel = (Channel) THREAD_STOPPER.get(manager);
channel.close();
} catch (Exception e) {
Messaging.logTr(Messages.ERROR_STOPPING_NETWORK_THREADS, e.getMessage());
}
}

public static void trySwim(org.bukkit.entity.Entity entity) {
trySwim(entity, 0.04F);
}
Expand Down Expand Up @@ -500,7 +487,6 @@ public static void updatePathfindingRange(NPC npc, float pathfindingRange) {
private static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0);
private static Field PATHFINDING_RANGE = getField(Navigation.class, "e");
private static final Random RANDOM = Util.getFastRandom();
private static Field THREAD_STOPPER = getField(NetworkManager.class, "k");
// true field above false and three synchronised lists

static {
Expand Down

0 comments on commit 82e627c

Please sign in to comment.