Skip to content

Commit

Permalink
Remove unnecessary method PaperImplementations#getThreadPoolExecutor
Browse files Browse the repository at this point in the history
Clean up unnecessary temporary variables
  • Loading branch information
willkroboth committed Oct 21, 2023
1 parent c096c30 commit c13e3fd
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

import dev.jorel.commandapi.nms.NMS;
import io.papermc.paper.event.server.ServerResourcesReloadedEvent;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Field;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ThreadPoolExecutor;
Expand All @@ -37,7 +35,7 @@ public PaperImplementations(boolean isPaperPresent, boolean isFoliaPresent, NMS<
this.isPaperPresent = isPaperPresent;
this.isFoliaPresent = isFoliaPresent;
this.nmsInstance = nmsInstance;

Class<? extends CommandSender> tempFeedbackForwardingCommandSender = null;
try {
tempFeedbackForwardingCommandSender = (Class<? extends CommandSender>) Class.forName("io.papermc.paper.commands.FeedbackForwardingSender");
Expand All @@ -46,22 +44,16 @@ public PaperImplementations(boolean isPaperPresent, boolean isFoliaPresent, NMS<
}
this.feedbackForwardingCommandSender = tempFeedbackForwardingCommandSender;

this.paperCommandSendingPool = getThreadPoolExecutor(nmsInstance);
}

@Nullable
private static ThreadPoolExecutor getThreadPoolExecutor(NMS<?> nmsInstance) {
Class<?> nmsCommandsClass = nmsInstance.getNMSCommandsClass();
ThreadPoolExecutor tempPaperCommandSendingPool = null;
try {
// public static field
Field commandSendingPoolField = nmsCommandsClass.getField("COMMAND_SENDING_POOL");
return (ThreadPoolExecutor) commandSendingPoolField.get(null);
tempPaperCommandSendingPool = (ThreadPoolExecutor) nmsInstance.getNMSCommandsClass().getField("COMMAND_SENDING_POOL").get(null);
} catch (NoSuchFieldException | IllegalAccessException e) {
// Not a big deal, if the thread pool doesn't exist, then the server also isn't using it
// We don't need to worry about ConcurrentModificationExceptions if Commands packets are
// being built synchronously
return null;
}
this.paperCommandSendingPool = tempPaperCommandSendingPool;
}

/**
Expand Down

0 comments on commit c13e3fd

Please sign in to comment.