Skip to content

Commit

Permalink
Implement getters and setters in wander waypoint goal
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jul 9, 2023
1 parent 0e9dcf2 commit d0abea6
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 129 deletions.
Expand Up @@ -41,10 +41,10 @@
public class WanderWaypointProvider implements WaypointProvider {
private WanderGoal currentGoal;
@Persist
public int delay = -1;
private int delay = -1;
private NPC npc;
@Persist
public boolean pathfind = true;
private boolean pathfind = true;
private boolean paused;
@Persist
private final List<Location> regionCentres = Lists.newArrayList();
Expand All @@ -53,9 +53,9 @@ public class WanderWaypointProvider implements WaypointProvider {
private String worldguardRegion;
private Object worldguardRegionCache;
@Persist
public int xrange = DEFAULT_XRANGE;
private int xrange = DEFAULT_XRANGE;
@Persist
public int yrange = DEFAULT_YRANGE;
private int yrange = DEFAULT_YRANGE;

public void addRegionCentre(Location centre) {
regionCentres.add(centre);
Expand Down Expand Up @@ -106,15 +106,12 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {
range = 0;
}
if (message.startsWith("xrange")) {
xrange = range;
setXYRange(range, yrange);
} else {
yrange = range;
}
if (currentGoal != null) {
currentGoal.setXYRange(xrange, yrange);
setXYRange(xrange, range);
}
recalculateTree();
} catch (Exception ex) {
} catch (NumberFormatException ex) {
}
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
() -> Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_RANGE_SET, xrange, yrange));
Expand All @@ -136,17 +133,14 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {
});
} else if (message.startsWith("delay")) {
event.setCancelled(true);
delay = Util.parseTicks(message.split(" ")[1]);
if (currentGoal != null) {
currentGoal.setDelay(delay);
}
setDelay(Util.parseTicks(message.split(" ")[1]));
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
() -> Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_DELAY_SET, delay));
} else if (message.startsWith("worldguardregion")) {
event.setCancelled(true);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
Object region = null;
String regionId = message.replace("worldguardregion ", "");
String regionId = message.replace("worldguardregion", "").trim();
try {
RegionManager manager = WorldGuard.getInstance().getPlatform().getRegionContainer()
.get(BukkitAdapter.adapt(npc.getStoredLocation().getWorld()));
Expand All @@ -158,7 +152,7 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {
Messaging.sendErrorTr(sender, Messages.WANDER_WAYPOINTS_WORLDGUARD_REGION_NOT_FOUND);
return;
}
WanderWaypointProvider.this.worldguardRegion = regionId;
setWorldGuardRegion(regionId);
Messaging.sendErrorTr(sender, Messages.WANDER_WAYPOINTS_WORLDGUARD_REGION_SET, regionId);
});
} else if (message.startsWith("pathfind")) {
Expand Down Expand Up @@ -212,6 +206,10 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
};
}

public int getDelay() {
return delay;
}

public List<Location> getRegionCentres() {
return new RecalculateList();
}
Expand All @@ -233,6 +231,18 @@ public Object getWorldGuardRegion() {
}
}

public int getXRange() {
return xrange;
}

public int getYRange() {
return yrange;
}

public boolean isPathfind() {
return pathfind;
}

@Override
public boolean isPaused() {
return paused;
Expand Down Expand Up @@ -298,6 +308,20 @@ public void removeRegionCentres(Collection<Location> centre) {
public void save(DataKey key) {
}

public void setDelay(int delay) {
this.delay = delay;
if (currentGoal != null) {
currentGoal.setDelay(delay);
}
}

public void setPathfind(boolean pathfind) {
this.pathfind = pathfind;
if (currentGoal != null) {
currentGoal.setPathfind(pathfind);
}
}

@Override
public void setPaused(boolean paused) {
this.paused = paused;
Expand Down
Expand Up @@ -16,6 +16,7 @@
import java.util.Random;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

import org.bukkit.Bukkit;
Expand Down Expand Up @@ -55,7 +56,6 @@
import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;

import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -541,12 +541,7 @@ public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity ent
Entity handle = NMSImpl.getHandle(entity);
if (handle == null || handle.passengers == null)
return Lists.newArrayList();
return Lists.transform(handle.passengers, new Function<Entity, org.bukkit.entity.Entity>() {
@Override
public org.bukkit.entity.Entity apply(Entity input) {
return input.getBukkitEntity();
}
});
return Lists.transform(handle.passengers, input -> input.getBukkitEntity());
}

@Override
Expand Down Expand Up @@ -609,19 +604,11 @@ public float getStepHeight(org.bukkit.entity.Entity entity) {
@Override
public MCNavigator getTargetNavigator(org.bukkit.entity.Entity entity, Iterable<Vector> dest,
final NavigatorParameters params) {
final PathEntity path = new PathEntity(
Iterables.toArray(Iterables.transform(dest, new Function<Vector, PathPoint>() {
@Override
public PathPoint apply(Vector input) {
return new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ());
}
}), PathPoint.class));
return getTargetNavigator(entity, params, new Function<NavigationAbstract, Boolean>() {
@Override
public Boolean apply(NavigationAbstract input) {
return input.a(path, params.speed());
}
});
final PathEntity path = new PathEntity(Iterables.toArray(
Iterables.transform(dest,
input -> new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ())),
PathPoint.class));
return getTargetNavigator(entity, params, input -> input.a(path, params.speed()));
}

@Override
Expand Down
Expand Up @@ -55,7 +55,7 @@
import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;

import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -561,12 +561,7 @@ public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity ent
Entity handle = NMSImpl.getHandle(entity);
if (handle == null || handle.passengers == null)
return Lists.newArrayList();
return Lists.transform(handle.passengers, new Function<Entity, org.bukkit.entity.Entity>() {
@Override
public org.bukkit.entity.Entity apply(Entity input) {
return input.getBukkitEntity();
}
});
return Lists.transform(handle.passengers, input->input.getBukkitEntity());
}

@Override
Expand Down Expand Up @@ -630,12 +625,7 @@ public float getStepHeight(org.bukkit.entity.Entity entity) {
public MCNavigator getTargetNavigator(org.bukkit.entity.Entity entity, Iterable<Vector> dest,
final NavigatorParameters params) {
final PathEntity path = new PathEntity(
Iterables.toArray(Iterables.transform(dest, new Function<Vector, PathPoint>() {
@Override
public PathPoint apply(Vector input) {
return new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ());
}
}), PathPoint.class));
Iterables.toArray(Iterables.transform(dest, input -> new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ())), PathPoint.class));
return getTargetNavigator(entity, params, new Function<NavigationAbstract, Boolean>() {
@Override
public Boolean apply(NavigationAbstract input) {
Expand Down
Expand Up @@ -55,7 +55,7 @@
import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;

import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -630,12 +630,7 @@ public float getStepHeight(org.bukkit.entity.Entity entity) {
public MCNavigator getTargetNavigator(org.bukkit.entity.Entity entity, Iterable<Vector> dest,
final NavigatorParameters params) {
final PathEntity path = new PathEntity(
Iterables.toArray(Iterables.transform(dest, new Function<Vector, PathPoint>() {
@Override
public PathPoint apply(Vector input) {
return new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ());
}
}), PathPoint.class));
Iterables.toArray(Iterables.transform(dest, input -> new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ())), PathPoint.class));
return getTargetNavigator(entity, params, new Function<NavigationAbstract, Boolean>() {
@Override
public Boolean apply(NavigationAbstract input) {
Expand Down
Expand Up @@ -56,7 +56,7 @@
import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;

import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -589,12 +589,7 @@ public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity ent
Entity handle = NMSImpl.getHandle(entity);
if (handle == null || handle.passengers == null)
return Lists.newArrayList();
return Lists.transform(handle.passengers, new Function<Entity, org.bukkit.entity.Entity>() {
@Override
public org.bukkit.entity.Entity apply(Entity input) {
return input.getBukkitEntity();
}
});
return Lists.transform(handle.passengers, input->input.getBukkitEntity());
}

@Override
Expand Down Expand Up @@ -658,12 +653,7 @@ public float getStepHeight(org.bukkit.entity.Entity entity) {
public MCNavigator getTargetNavigator(org.bukkit.entity.Entity entity, Iterable<Vector> dest,
final NavigatorParameters params) {
final PathEntity path = new PathEntity(
Iterables.toArray(Iterables.transform(dest, new Function<Vector, PathPoint>() {
@Override
public PathPoint apply(Vector input) {
return new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ());
}
}), PathPoint.class));
Iterables.toArray(Iterables.transform(dest, input -> new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ())), PathPoint.class));
return getTargetNavigator(entity, params, new Function<NavigationAbstract, Boolean>() {
@Override
public Boolean apply(NavigationAbstract input) {
Expand Down
Expand Up @@ -54,7 +54,7 @@
import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;

import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -626,12 +626,7 @@ public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity ent
Entity handle = NMSImpl.getHandle(entity);
if (handle == null || handle.passengers == null)
return Lists.newArrayList();
return Lists.transform(handle.passengers, new Function<Entity, org.bukkit.entity.Entity>() {
@Override
public org.bukkit.entity.Entity apply(Entity input) {
return input.getBukkitEntity();
}
});
return Lists.transform(handle.passengers, input->input.getBukkitEntity());
}

@Override
Expand Down Expand Up @@ -693,12 +688,7 @@ public float getStepHeight(org.bukkit.entity.Entity entity) {
public MCNavigator getTargetNavigator(org.bukkit.entity.Entity entity, Iterable<Vector> dest,
final NavigatorParameters params) {
List<PathPoint> list = Lists.<PathPoint> newArrayList(
Iterables.<Vector, PathPoint> transform(dest, new Function<Vector, PathPoint>() {
@Override
public PathPoint apply(Vector input) {
return new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ());
}
}));
Iterables.<Vector, PathPoint> transform(dest, input -> new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ())));
PathPoint last = list.size() > 0 ? list.get(list.size() - 1) : null;
final PathEntity path = new PathEntity(list, last != null ? new BlockPosition(last.a, last.b, last.c) : null,
true);
Expand Down
Expand Up @@ -54,7 +54,7 @@
import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;

import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -641,12 +641,7 @@ public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity ent
Entity handle = NMSImpl.getHandle(entity);
if (handle == null || handle.passengers == null)
return Lists.newArrayList();
return Lists.transform(handle.passengers, new Function<Entity, org.bukkit.entity.Entity>() {
@Override
public org.bukkit.entity.Entity apply(Entity input) {
return input.getBukkitEntity();
}
});
return Lists.transform(handle.passengers, input->input.getBukkitEntity());
}

@Override
Expand Down Expand Up @@ -708,12 +703,7 @@ public float getStepHeight(org.bukkit.entity.Entity entity) {
public MCNavigator getTargetNavigator(org.bukkit.entity.Entity entity, Iterable<Vector> dest,
final NavigatorParameters params) {
List<PathPoint> list = Lists.<PathPoint> newArrayList(
Iterables.<Vector, PathPoint> transform(dest, new Function<Vector, PathPoint>() {
@Override
public PathPoint apply(Vector input) {
return new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ());
}
}));
Iterables.<Vector, PathPoint> transform(dest, input -> new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ())));
PathPoint last = list.size() > 0 ? list.get(list.size() - 1) : null;
final PathEntity path = new PathEntity(list, last != null ? new BlockPosition(last.a, last.b, last.c) : null,
true);
Expand Down
Expand Up @@ -55,7 +55,7 @@
import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;

import com.google.common.base.Function;
import java.util.function.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -657,12 +657,7 @@ public List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity ent
Entity handle = NMSImpl.getHandle(entity);
if (handle == null || handle.passengers == null)
return Lists.newArrayList();
return Lists.transform(handle.passengers, new Function<Entity, org.bukkit.entity.Entity>() {
@Override
public org.bukkit.entity.Entity apply(Entity input) {
return input.getBukkitEntity();
}
});
return Lists.transform(handle.passengers, input->input.getBukkitEntity());
}

@Override
Expand Down Expand Up @@ -732,12 +727,7 @@ public float getStepHeight(org.bukkit.entity.Entity entity) {
public MCNavigator getTargetNavigator(org.bukkit.entity.Entity entity, Iterable<Vector> dest,
final NavigatorParameters params) {
List<PathPoint> list = Lists.<PathPoint> newArrayList(
Iterables.<Vector, PathPoint> transform(dest, new Function<Vector, PathPoint>() {
@Override
public PathPoint apply(Vector input) {
return new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ());
}
}));
Iterables.<Vector, PathPoint> transform(dest, input -> new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ())));
PathPoint last = list.size() > 0 ? list.get(list.size() - 1) : null;
final PathEntity path = new PathEntity(list, last != null ? new BlockPosition(last.a, last.b, last.c) : null,
true);
Expand Down

0 comments on commit d0abea6

Please sign in to comment.