mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-29 19:41:50 +01:00
Add blockbreaker, navigator callback
This commit is contained in:
parent
155022e82b
commit
f5a9f3794a
@ -29,8 +29,10 @@ public class TraitCommands {
|
||||
List<String> added = Lists.newArrayList();
|
||||
List<String> failed = Lists.newArrayList();
|
||||
for (String traitName : Splitter.on(',').split(args.getJoinedStrings(0))) {
|
||||
if (!sender.hasPermission("citizens.npc.trait." + traitName))
|
||||
if (!sender.hasPermission("citizens.npc.trait." + traitName)) {
|
||||
failed.add(String.format("%s: No permission", traitName));
|
||||
continue;
|
||||
}
|
||||
|
||||
Class<? extends Trait> clazz = CitizensAPI.getTraitFactory().getTraitClass(traitName);
|
||||
if (clazz == null) {
|
||||
@ -84,8 +86,10 @@ public class TraitCommands {
|
||||
List<String> removed = Lists.newArrayList();
|
||||
List<String> failed = Lists.newArrayList();
|
||||
for (String traitName : Splitter.on(',').split(args.getJoinedStrings(0))) {
|
||||
if (!sender.hasPermission("citizens.npc.trait." + traitName))
|
||||
if (!sender.hasPermission("citizens.npc.trait." + traitName)) {
|
||||
failed.add(String.format("%s: No permission", traitName));
|
||||
continue;
|
||||
}
|
||||
|
||||
Class<? extends Trait> clazz = CitizensAPI.getTraitFactory().getTraitClass(traitName);
|
||||
if (clazz == null) {
|
||||
@ -118,8 +122,10 @@ public class TraitCommands {
|
||||
List<String> removed = Lists.newArrayList();
|
||||
List<String> failed = Lists.newArrayList();
|
||||
for (String traitName : Splitter.on(',').split(args.getJoinedStrings(0))) {
|
||||
if (!sender.hasPermission("citizens.npc.trait." + traitName))
|
||||
if (!sender.hasPermission("citizens.npc.trait." + traitName)) {
|
||||
failed.add(String.format("%s: No permission", traitName));
|
||||
continue;
|
||||
}
|
||||
|
||||
Class<? extends Trait> clazz = CitizensAPI.getTraitFactory().getTraitClass(traitName);
|
||||
if (clazz == null) {
|
||||
|
@ -34,6 +34,9 @@ public class BlockBreaker implements Runnable {
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
if (configuration.callback() != null) {
|
||||
configuration.callback().run();
|
||||
}
|
||||
isDigging = false;
|
||||
currentDamage = -1;
|
||||
entity.world.g(entity.id, x, y, z, -1);
|
||||
@ -131,11 +134,20 @@ public class BlockBreaker implements Runnable {
|
||||
}
|
||||
|
||||
public static class Configuration {
|
||||
private Runnable callback;
|
||||
private org.bukkit.inventory.ItemStack itemStack;
|
||||
|
||||
private double radius;
|
||||
|
||||
public org.bukkit.inventory.ItemStack item() {
|
||||
private Runnable callback() {
|
||||
return callback;
|
||||
}
|
||||
|
||||
public Configuration callback(Runnable callback) {
|
||||
this.callback = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
private org.bukkit.inventory.ItemStack item() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@ -149,7 +161,7 @@ public class BlockBreaker implements Runnable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public double radiusSquared() {
|
||||
private double radiusSquared() {
|
||||
return Math.pow(radius, 2);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.citizensnpcs.npc.ai;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.ai.EntityTarget;
|
||||
import net.citizensnpcs.api.ai.Navigator;
|
||||
@ -10,6 +12,7 @@ import net.citizensnpcs.api.ai.TeleportStuckAction;
|
||||
import net.citizensnpcs.api.ai.event.CancelReason;
|
||||
import net.citizensnpcs.api.ai.event.NavigationBeginEvent;
|
||||
import net.citizensnpcs.api.ai.event.NavigationCancelEvent;
|
||||
import net.citizensnpcs.api.ai.event.NavigatorCallback;
|
||||
import net.citizensnpcs.api.ai.event.NavigationCompleteEvent;
|
||||
import net.citizensnpcs.api.ai.event.NavigationReplaceEvent;
|
||||
import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer;
|
||||
@ -115,7 +118,7 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
PathStrategy old = executing;
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (old == executing)
|
||||
stopNavigating();
|
||||
stopNavigating(null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,6 +177,15 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
private void stopNavigating(CancelReason reason) {
|
||||
if (!isNavigating())
|
||||
return;
|
||||
Iterator<NavigatorCallback> itr = localParams.callbacks().iterator();
|
||||
while (itr.hasNext()) {
|
||||
itr.next().onCompletion(reason);
|
||||
itr.remove();
|
||||
}
|
||||
if (reason == null) {
|
||||
stopNavigating(reason);
|
||||
return;
|
||||
}
|
||||
if (reason == CancelReason.STUCK && localParams.stuckAction() != null) {
|
||||
StuckAction action = localParams.stuckAction();
|
||||
boolean shouldContinue = action.run(npc, this);
|
||||
|
Loading…
Reference in New Issue
Block a user