Persist use new pathfinder if set manually

This commit is contained in:
fullwall 2022-04-20 11:55:15 +08:00
parent 46a6c64cf5
commit 96ba80edd8
6 changed files with 68 additions and 67 deletions

View File

@ -1558,25 +1558,25 @@ public class NPCCommands {
double distance = Double.parseDouble(args.getFlag("distance-margin"));
if (distance < 0)
throw new CommandUsageException();
npc.getNavigator().getDefaultParameters().distanceMargin(Math.pow(distance, 2));
npc.getNavigator().getDefaultParameters().distanceMargin(distance);
output += Messaging.tr(Messages.PATHFINDING_OPTIONS_DISTANCE_MARGIN_SET, npc.getName(), distance);
}
if (args.hasValueFlag("path-distance-margin")) {
double distance = Double.parseDouble(args.getFlag("path-distance-margin"));
if (args.hasAnyValueFlag("path-distance-margin", "pdm")) {
double distance = Double.parseDouble(args.getFlag("path-distance-margin", args.getFlag("pdm")));
if (distance < 0)
throw new CommandUsageException();
npc.getNavigator().getDefaultParameters().pathDistanceMargin(Math.pow(distance, 2));
npc.getNavigator().getDefaultParameters().pathDistanceMargin(distance);
output += Messaging.tr(Messages.PATHFINDING_OPTIONS_PATH_DISTANCE_MARGIN_SET, npc.getName(), distance);
}
if (args.hasValueFlag("attack-range")) {
double range = Double.parseDouble(args.getFlag("attack-range"));
if (range < 0)
throw new CommandUsageException();
npc.getNavigator().getDefaultParameters().attackRange(Math.pow(range, 2));
npc.getNavigator().getDefaultParameters().attackRange(range);
output += Messaging.tr(Messages.PATHFINDING_OPTIONS_ATTACK_RANGE_SET, npc.getName(), range);
}
if (args.hasValueFlag("use-new-finder")) {
if (args.hasAnyValueFlag("use-new-finder", "unf")) {
String raw = args.getFlag("use-new-finder", args.getFlag("unf"));
boolean use = Boolean.parseBoolean(raw);
npc.getNavigator().getDefaultParameters().useNewPathfinder(use);

View File

@ -22,19 +22,10 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.SpigotUtil;
@Menu(title = "NPC Equipment", type = InventoryType.HOPPER, dimensions = { 0, 5 })
@MenuSlot(
slot = { 0, 0 },
material = Material.ENDER_PEARL,
amount = 1,
lore = "Place a block to hold here ->",
filter = InventoryAction.UNKNOWN)
@MenuSlot(slot = { 0, 0 }, material = Material.ENDER_PEARL, amount = 1, lore = "Place a block to hold here ->")
@MenuPattern(
offset = { 0, 2 },
slots = { @MenuSlot(
filter = InventoryAction.UNKNOWN,
pat = 'x',
compatMaterial = { "BARRIER", "FIRE" },
title = "<4>Unused") },
slots = { @MenuSlot(pat = 'x', compatMaterial = { "BARRIER", "FIRE" }, title = "<4>Unused") },
value = "xxx")
public class EndermanEquipperGUI extends InventoryMenuPage {
@MenuSlot(slot = { 0, 1 })

View File

@ -4,7 +4,6 @@ import java.util.function.Function;
import org.bukkit.Material;
import org.bukkit.event.Event.Result;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
@ -22,49 +21,19 @@ import net.citizensnpcs.api.trait.trait.Equipment;
import net.citizensnpcs.api.trait.trait.Equipment.EquipmentSlot;
@Menu(title = "NPC Equipment", type = InventoryType.CHEST, dimensions = { 2, 5 })
@MenuSlot(
slot = { 0, 2 },
material = Material.DIAMOND_HELMET,
amount = 1,
lore = "Place a helmet below",
filter = InventoryAction.UNKNOWN)
@MenuSlot(
slot = { 0, 4 },
material = Material.DIAMOND_LEGGINGS,
lore = "Place leggings below",
amount = 1,
filter = InventoryAction.UNKNOWN)
@MenuSlot(slot = { 0, 2 }, material = Material.DIAMOND_HELMET, amount = 1, lore = "Place a helmet below")
@MenuSlot(slot = { 0, 4 }, material = Material.DIAMOND_LEGGINGS, lore = "Place leggings below", amount = 1)
@MenuSlot(
slot = { 0, 1 },
compatMaterial = { "SHIELD", "BARRIER", "FIRE" },
lore = "Place offhand item below",
amount = 1,
filter = InventoryAction.UNKNOWN)
@MenuSlot(
slot = { 0, 0 },
material = Material.DIAMOND_SWORD,
lore = "Place in hand item below",
amount = 1,
filter = InventoryAction.UNKNOWN)
@MenuSlot(
slot = { 0, 3 },
material = Material.DIAMOND_CHESTPLATE,
lore = "Place chestplate below",
amount = 1,
filter = InventoryAction.UNKNOWN)
@MenuSlot(
slot = { 0, 5 },
material = Material.DIAMOND_BOOTS,
lore = "Place boots below",
amount = 1,
filter = InventoryAction.UNKNOWN)
amount = 1)
@MenuSlot(slot = { 0, 0 }, material = Material.DIAMOND_SWORD, lore = "Place in hand item below", amount = 1)
@MenuSlot(slot = { 0, 3 }, material = Material.DIAMOND_CHESTPLATE, lore = "Place chestplate below", amount = 1)
@MenuSlot(slot = { 0, 5 }, material = Material.DIAMOND_BOOTS, lore = "Place boots below", amount = 1)
@MenuPattern(
offset = { 0, 6 },
slots = { @MenuSlot(
filter = InventoryAction.UNKNOWN,
pat = 'x',
compatMaterial = { "BARRIER", "FIRE" },
title = "<4>Unused") },
slots = { @MenuSlot(pat = 'x', compatMaterial = { "BARRIER", "FIRE" }, title = "<4>Unused") },
value = "xxx\nxxx")
public class GenericEquipperGUI extends InventoryMenuPage {
@MenuSlot(slot = { 1, 5 })

View File

@ -19,19 +19,10 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.trait.Saddle;
@Menu(title = "NPC Equipment", type = InventoryType.HOPPER, dimensions = { 0, 5 })
@MenuSlot(
slot = { 0, 0 },
material = Material.SADDLE,
amount = 1,
lore = "Place a saddle here ->",
filter = InventoryAction.UNKNOWN)
@MenuSlot(slot = { 0, 0 }, material = Material.SADDLE, amount = 1, lore = "Place a saddle here ->")
@MenuPattern(
offset = { 0, 2 },
slots = { @MenuSlot(
filter = InventoryAction.UNKNOWN,
pat = 'x',
compatMaterial = { "BARRIER", "FIRE" },
title = "<4>Unused") },
slots = { @MenuSlot(pat = 'x', compatMaterial = { "BARRIER", "FIRE" }, title = "<4>Unused") },
value = "xxx")
public class SteerableEquipperGUI extends InventoryMenuPage {
@InjectContext

View File

@ -231,6 +231,11 @@ public class CitizensNavigator implements Navigator, Runnable {
} else {
root.removeKey("updatepathrate");
}
if (defaultParams.useNewPathfinder() != Setting.USE_NEW_PATHFINDER.asBoolean()) {
root.setBoolean("usenewpathfinder", defaultParams.useNewPathfinder());
} else {
root.removeKey("usenewpathfinder");
}
root.setDouble("speedmodifier", defaultParams.speedModifier());
root.setBoolean("avoidwater", defaultParams.avoidWater());
root.setBoolean("usedefaultstuckaction", defaultParams.stuckAction() == TeleportStuckAction.INSTANCE);

View File

@ -3,12 +3,24 @@ package net.citizensnpcs.trait;
import java.util.List;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.citizensnpcs.api.gui.CitizensInventoryClickEvent;
import net.citizensnpcs.api.gui.ClickHandler;
import net.citizensnpcs.api.gui.InputMenu;
import net.citizensnpcs.api.gui.InventoryMenu;
import net.citizensnpcs.api.gui.InventoryMenuPage;
import net.citizensnpcs.api.gui.InventoryMenuSlot;
import net.citizensnpcs.api.gui.Menu;
import net.citizensnpcs.api.gui.MenuContext;
import net.citizensnpcs.api.gui.MenuSlot;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
@ -36,7 +48,7 @@ public class ShopTrait extends Trait {
@Persist(reify = true)
private final List<NPCShopPage> pages = Lists.newArrayList();
@Persist
private String title;
private final ShopType type = ShopType.VIEW;
private NPCShop(String name) {
this.name = name;
@ -46,6 +58,7 @@ public class ShopTrait extends Trait {
}
public void displayEditor(Player sender) {
InventoryMenu.create(new NPCShopEditor(this)).present(sender);
}
public String getName() {
@ -53,6 +66,32 @@ public class ShopTrait extends Trait {
}
}
@Menu(title = "NPC Equipment", type = InventoryType.HOPPER, dimensions = { 0, 5 })
@MenuSlot(slot = { 0, 0 }, material = Material.BOOK, amount = 1, lore = "Edit shop type")
@MenuSlot(slot = { 0, 2 }, material = Material.OAK_SIGN, amount = 1, lore = "Edit shop permission")
public static class NPCShopEditor extends InventoryMenuPage {
private MenuContext ctx;
private final NPCShop shop;
public NPCShopEditor(NPCShop shop) {
this.shop = shop;
}
@Override
public void initialise(MenuContext ctx) {
this.ctx = ctx;
}
@ClickHandler(slot = { 0, 2 }, filter = { InventoryAction.PICKUP_ALL, InventoryAction.PICKUP_ONE })
public void onPermissionChange(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
ctx.getMenu().transition(new InputMenu());
}
@ClickHandler(slot = { 0, 0 }, filter = { InventoryAction.PICKUP_ALL, InventoryAction.PICKUP_ONE })
public void onShopTypeChange(InventoryMenuSlot slot, CitizensInventoryClickEvent event) {
}
}
public static class NPCShopItem {
@Persist
private int cost;
@ -69,6 +108,12 @@ public class ShopTrait extends Trait {
private String title;
}
public enum ShopType {
BUY,
SELL,
VIEW;
}
@Persist(value = "npcShops", reify = true, namespace = "shopstrait")
private static Map<String, NPCShop> NPC_SHOPS = Maps.newHashMap();
@Persist(value = "namedShops", reify = true, namespace = "shopstrait")