Implement new API

This commit is contained in:
fullwall 2016-08-08 17:26:27 +08:00
parent e607244a5f
commit c0a3f0b1de
6 changed files with 38 additions and 29 deletions

View File

@ -6,7 +6,6 @@
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>

View File

@ -37,6 +37,7 @@ import net.citizensnpcs.api.astar.pathfinder.PathPoint.PathCallback;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
public class CitizensNavigator implements Navigator, Runnable {
private final NavigatorParameters defaultParams = new NavigatorParameters().baseSpeed(UNINITIALISED_SPEED)
@ -152,6 +153,9 @@ public class CitizensNavigator implements Navigator, Runnable {
updatePathfindingRange();
boolean finished = executing.update();
if (localParams.lookAtFunction() != null) {
Util.faceLocation(npc.getEntity(), localParams.lookAtFunction().apply(this), true);
}
if (!finished) {
return;
}

View File

@ -56,16 +56,15 @@ class ProfileFetchThread implements Runnable {
queue.add(request);
requested.put(name, request);
return;
}
else if (request.getResult() == ProfileFetchResult.TOO_MANY_REQUESTS) {
} else if (request.getResult() == ProfileFetchResult.TOO_MANY_REQUESTS) {
queue.add(request);
}
}
if (handler != null) {
if (request.getResult() == ProfileFetchResult.PENDING ||
request.getResult() == ProfileFetchResult.TOO_MANY_REQUESTS) {
if (request.getResult() == ProfileFetchResult.PENDING
|| request.getResult() == ProfileFetchResult.TOO_MANY_REQUESTS) {
addHandler(request, handler);
} else {
sendResult(handler, request);

View File

@ -8,6 +8,7 @@ import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitTask;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.mojang.authlib.Agent;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.GameProfileRepository;
@ -41,8 +42,7 @@ public class ProfileFetcher {
int i = 0;
for (ProfileRequest request : requests) {
playerNames[i] = request.getPlayerName();
i++;
playerNames[i++] = request.getPlayerName();
}
repo.findProfilesByNames(playerNames, Agent.MINECRAFT, new ProfileLookupCallback() {
@ -50,7 +50,8 @@ public class ProfileFetcher {
public void onProfileLookupFailed(GameProfile profile, Exception e) {
if (Messaging.isDebugging()) {
Messaging.debug(
"Profile lookup for player '" + profile.getName() + "' failed: " + getExceptionMsg(e));
"Profile lookup for player '" + profile.getName() + "' failed2: " + getExceptionMsg(e));
Messaging.debug(Throwables.getStackTraceAsString(e));
}
ProfileRequest request = findRequest(profile.getName(), requests);
@ -76,12 +77,13 @@ public class ProfileFetcher {
if (request == null)
return;
try {
try {
request.setResult(NMS.fillProfileProperties(profile, true), ProfileFetchResult.SUCCESS);
} catch (Exception e) {
if (Messaging.isDebugging()) {
Messaging.debug(
"Profile lookup for player '" + profile.getName() + "' failed: " + getExceptionMsg(e));
"Profile lookup for player '" + profile.getName() + "' failed2: " + getExceptionMsg(e));
Messaging.debug(Throwables.getStackTraceAsString(e));
}
if (isTooManyRequests(e)) {
@ -124,9 +126,7 @@ public class ProfileFetcher {
}
private static String getExceptionMsg(Exception e) {
String message = e.getMessage();
String cause = e.getCause() != null ? e.getCause().getMessage() : null;
return cause != null ? cause : message;
return Throwables.getRootCause(e).getMessage();
}
private static void initThread() {

View File

@ -23,17 +23,6 @@ public class Util {
private Util() {
}
public static float clampYaw(float yaw) {
while (yaw < -180.0F) {
yaw += 360.0F;
}
while (yaw >= 180.0F) {
yaw -= 360.0F;
}
return yaw;
}
public static void assumePose(Entity entity, float yaw, float pitch) {
NMS.look(entity, yaw, pitch);
}
@ -51,14 +40,29 @@ public class Util {
return event;
}
public static float clampYaw(float yaw) {
while (yaw < -180.0F) {
yaw += 360.0F;
}
while (yaw >= 180.0F) {
yaw -= 360.0F;
}
return yaw;
}
public static void faceEntity(Entity entity, Entity at) {
if (entity.getWorld() != at.getWorld())
if (at == null || entity == null || entity.getWorld() != at.getWorld())
return;
faceLocation(entity, at.getLocation(AT_LOCATION));
}
public static void faceLocation(Entity entity, Location to) {
if (entity.getWorld() != to.getWorld())
faceLocation(entity, to, false);
}
public static void faceLocation(Entity entity, Location to, boolean headOnly) {
if (to == null || entity.getWorld() != to.getWorld())
return;
Location fromLocation = entity.getLocation(FROM_LOCATION);
double xDiff, yDiff, zDiff;
@ -74,7 +78,11 @@ public class Util {
if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2;
NMS.look(entity, (float) yaw - 90, (float) pitch);
if (headOnly) {
NMS.setHeadYaw(entity, (float) yaw - 90);
} else {
NMS.look(entity, (float) yaw - 90, (float) pitch);
}
}
public static Location getEyeLocation(Entity entity) {

View File

@ -471,8 +471,7 @@ public class NMSImpl implements NMSBridge {
public TargetNavigator getTargetNavigator(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity target,
NavigatorParameters parameters) {
NavigationAbstract navigation = getNavigation(entity);
return navigation == null ? null
: new NavigationFieldWrapper(navigation, target, parameters);
return navigation == null ? null : new NavigationFieldWrapper(navigation, target, parameters);
}
@Override