Skip to content

Commit

Permalink
Persist use new pathfinder if set manually
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Apr 20, 2022
1 parent 46a6c64 commit 96ba80e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 67 deletions.
12 changes: 6 additions & 6 deletions main/src/main/java/net/citizensnpcs/commands/NPCCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -1558,25 +1558,25 @@ public void pathfindingOptions(CommandContext args, CommandSender sender, NPC np
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,10 @@
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 })
Expand Down
45 changes: 7 additions & 38 deletions main/src/main/java/net/citizensnpcs/editor/GenericEquipperGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

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;

Expand All @@ -22,49 +21,19 @@
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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,10 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ public void save(DataKey root) {
} 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);
Expand Down
47 changes: 46 additions & 1 deletion main/src/main/java/net/citizensnpcs/trait/ShopTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
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;
Expand Down Expand Up @@ -36,7 +48,7 @@ public static class NPCShop {
@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;
Expand All @@ -46,13 +58,40 @@ public void display(Player sender) {
}

public void displayEditor(Player sender) {
InventoryMenu.create(new NPCShopEditor(this)).present(sender);
}

public String getName() {
return name;
}
}

@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;
Expand All @@ -69,6 +108,12 @@ public static class NPCShopPage {
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")
Expand Down

0 comments on commit 96ba80e

Please sign in to comment.