diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 0fae0302..dc9b8359 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -457,9 +457,9 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc * Teleports the player to a specific waypoint. This applies * the stellium waypoint cost and plays the teleport animation. * - * @param waypoint Target waypoint + * @param target Target waypoint */ - public void warp(Waypoint waypoint, CostType costType) { + public void warp(Waypoint source, Waypoint target, CostType costType) { /* * This cooldown is only used internally to make sure the player is not @@ -467,8 +467,10 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc * player waypoints data */ setLastActivity(PlayerActivity.USE_WAYPOINT); + Validate.isTrue(source!=null||costType!=CostType.NORMAL_USE,"You must precise a source to use normal waypoint" ); + final double cost = costType == CostType.DYNAMIC_USE ? target.getDynamicCost() : source.getCost(target); + - final double cost = waypoint.getCost(costType); giveStellium(-cost, PlayerResourceUpdateEvent.UpdateReason.USE_WAYPOINT); new BukkitRunnable() { @@ -491,7 +493,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc MMOCore.plugin.configManager.getSimpleMessage("warping-comencing", "left", "" + ((120 - t) / 20)).send(getPlayer()); if (t++ >= 100) { - getPlayer().teleport(waypoint.getLocation()); + getPlayer().teleport(target.getLocation()); getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1, false, false)); MMOCore.plugin.soundManager.getSound(SoundEvent.WARP_TELEPORT).playTo(getPlayer()); cancel(); @@ -869,7 +871,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc * checks if they could potentially upgrade to one of these * * @return If the player can change its current class to - * a subclass + * a subclass */ public boolean canChooseSubclass() { for (Subclass subclass : getProfess().getSubclasses()) diff --git a/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java b/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java index c8f59612..f913b127 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java +++ b/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java @@ -22,7 +22,9 @@ import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class WaypointViewer extends EditableInventory { public WaypointViewer() { @@ -65,8 +67,8 @@ public class WaypointViewer extends EditableInventory { } public class WaypointItem extends SimplePlaceholderItem { - private final SimplePlaceholderItem noWaypoint, locked; - private final WaypointItemHandler availWaypoint, notLinked, notDynamic, noStellium; + private final SimplePlaceholderItem noWaypoint, locked,notLinked,notDynamic; + private final WaypointItemHandler availWaypoint,noStellium; public WaypointItem(ConfigurationSection config) { super(Material.BARRIER, config); @@ -80,8 +82,8 @@ public class WaypointViewer extends EditableInventory { noWaypoint = new SimplePlaceholderItem(config.getConfigurationSection("no-waypoint")); locked = new SimplePlaceholderItem(config.getConfigurationSection("locked")); - notLinked = new WaypointItemHandler(config.getConfigurationSection("not-a-destination")); - notDynamic = new WaypointItemHandler(config.getConfigurationSection("not-dynamic")); + notLinked = new SimplePlaceholderItem(config.getConfigurationSection("not-a-destination")); + notDynamic = new SimplePlaceholderItem(config.getConfigurationSection("not-dynamic")); noStellium = new WaypointItemHandler(config.getConfigurationSection("not-enough-stellium")); availWaypoint = new WaypointItemHandler(config.getConfigurationSection("display")); } @@ -104,20 +106,23 @@ public class WaypointViewer extends EditableInventory { return locked.display(inv, n); // Waypoints are not linked - if (inv.current != null && inv.current.getPath(waypoint)==null) + if (inv.current != null && !inv.paths.containsKey(waypoint)) return notLinked.display(inv, n); // Not dynamic waypoint if (inv.current == null && !waypoint.hasOption(WaypointOption.DYNAMIC)) return notDynamic.display(inv, n); - //Dynamic waypoint - if(waypoint.hasOption(WaypointOption.DYNAMIC)&&inv.current==null) - // Stellium cost - if (waypoint.getCost(inv.current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE) > inv.getPlayerData().getStellium()) + //Dynamic waypoint + if (waypoint.hasOption(WaypointOption.DYNAMIC) && inv.current == null && waypoint.getDynamicCost() > inv.getPlayerData().getStellium()) return noStellium.display(inv, n); + //Normal cost + if (inv.current != null && inv.paths.get(waypoint).getCost() > inv.getPlayerData().getStellium()) + return noStellium.display(inv, n); + + return availWaypoint.display(inv, n); } } @@ -133,9 +138,9 @@ public class WaypointViewer extends EditableInventory { // If a player can teleport to another waypoint given his location Waypoint waypoint = inv.waypoints.get(inv.page * inv.getEditable().getByFunction("waypoint").getSlots().size() + n); - ItemMeta meta=disp.getItemMeta(); - PersistentDataContainer container=meta.getPersistentDataContainer(); - container.set(new NamespacedKey(MMOCore.plugin,"waypointId"),PersistentDataType.STRING,waypoint.getId()); + ItemMeta meta = disp.getItemMeta(); + PersistentDataContainer container = meta.getPersistentDataContainer(); + container.set(new NamespacedKey(MMOCore.plugin, "waypointId"), PersistentDataType.STRING, waypoint.getId()); disp.setItemMeta(meta); return disp; } @@ -146,9 +151,10 @@ public class WaypointViewer extends EditableInventory { Waypoint waypoint = inv.waypoints.get(inv.page * inv.getByFunction("waypoint").getSlots().size() + n); holders.register("name", waypoint.getName()); - holders.register("current_cost", decimal.format(waypoint.getCost(inv.waypointCostType))); - holders.register("normal_cost", decimal.format(waypoint.getCost(CostType.NORMAL_USE))); - holders.register("dynamic_cost", decimal.format(waypoint.getCost(CostType.DYNAMIC_USE))); + holders.register("current_cost", decimal.format(inv.waypointCostType.equals(CostType.DYNAMIC_USE) ? waypoint.getDynamicCost() : inv.paths.get(waypoint).getCost())); + holders.register("normal_cost", decimal.format(inv.paths.get(waypoint).getCost())); + holders.register("dynamic_cost", decimal.format(waypoint.getDynamicCost())); + holders.register("intermediary_waypoints", inv.paths.get(waypoint).displayIntermediaryWayPoints()); return holders; } @@ -157,7 +163,7 @@ public class WaypointViewer extends EditableInventory { public class WaypointViewerInventory extends GeneratedInventory { private final List waypoints = new ArrayList<>(MMOCore.plugin.waypointManager.getAll()); private final Waypoint current; - private final ArrayList paths; + private final Map paths = new HashMap<>(); private final CostType waypointCostType; private int page; @@ -166,7 +172,11 @@ public class WaypointViewer extends EditableInventory { super(playerData, editable); this.current = current; - paths=current!=null? current.getAllPath() : null; + if (current != null) { + for (Waypoint.PathInfo pathInfo : current.getAllPath()) + paths.put(pathInfo.getFinalWaypoint(), pathInfo); + } + this.waypointCostType = current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE; } @@ -190,8 +200,8 @@ public class WaypointViewer extends EditableInventory { } if (item.getFunction().equals("waypoint")) { - PersistentDataContainer container =event.getCurrentItem().getItemMeta().getPersistentDataContainer(); - String tag =container.get(new NamespacedKey(MMOCore.plugin,"wayPointId"), PersistentDataType.STRING); + PersistentDataContainer container = event.getCurrentItem().getItemMeta().getPersistentDataContainer(); + String tag = container.get(new NamespacedKey(MMOCore.plugin, "wayPointId"), PersistentDataType.STRING); if (tag.equals("")) return; @@ -210,7 +220,7 @@ public class WaypointViewer extends EditableInventory { } // Waypoint does not have target as destination - if (current != null && !current.hasDestination(waypoint)) { + if (current != null && current.getPath(waypoint)==null) { MMOCore.plugin.configManager.getSimpleMessage("cannot-teleport-to").send(player); return; } @@ -223,7 +233,8 @@ public class WaypointViewer extends EditableInventory { // Stellium cost CostType costType = current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE; - double left = waypoint.getCost(costType) - playerData.getStellium(); + double withdraw = current == null ? waypoint.getDynamicCost() : paths.get(waypoint).getCost(); + double left = withdraw - playerData.getStellium(); if (left > 0) { MMOCore.plugin.configManager.getSimpleMessage("not-enough-stellium", "more", decimal.format(left)).send(player); return; @@ -233,7 +244,11 @@ public class WaypointViewer extends EditableInventory { return; player.closeInventory(); - playerData.warp(waypoint, costType); + if (current == null) + playerData.warp(null, waypoint, costType); + else + playerData.warp(current, waypoint, costType); + } } } diff --git a/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java b/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java index c33058e5..da7696f5 100644 --- a/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java +++ b/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java @@ -33,8 +33,21 @@ public class Waypoint implements Unlockable { /** * Stellium cost for each action (0 being the default cost) */ + private final double dynamicCost,setSpawnCost; private final Map costs = new HashMap<>(); + public double getDynamicCost() { + return dynamicCost; + } + + public double getSetSpawnCost() { + return setSpawnCost; + } + + public double getCost(Waypoint waypoint) { + return getPath(waypoint).cost; + } + public Waypoint(ConfigurationSection config) { id = Objects.requireNonNull(config, "Could not load config section").getName(); name = Objects.requireNonNull(config.getString("name"), "Could not load waypoint name"); @@ -42,8 +55,9 @@ public class Waypoint implements Unlockable { loc = readLocation(Objects.requireNonNull(config.getString("location"), "Could not read location")); radiusSquared = Math.pow(config.getDouble("radius"), 2); - for (CostType costType : CostType.values()) - costs.put(costType, config.getDouble("cost." + costType.getPath())); + dynamicCost=config.getDouble("cost.dynamic-use"); + setSpawnCost=config.getDouble("cost.set-spawnpoint"); + for (WaypointOption option : WaypointOption.values()) options.put(option, config.getBoolean("option." + option.getPath(), option.getDefaultValue())); @@ -85,7 +99,7 @@ public class Waypoint implements Unlockable { * * @return Integer.POSITIVE_INFINITY if the way point is not linked */ - public int getSimpleCostDestination(Waypoint waypoint) { + private int getSimpleCostDestination(Waypoint waypoint) { if (!destinations.keySet().contains(waypoint.getId())) return Integer.MAX_VALUE; return destinations.get(waypoint.getId()); @@ -153,11 +167,6 @@ public class Waypoint implements Unlockable { } - - public double getCost(CostType type) { - return costs.getOrDefault(type, 0d); - } - public boolean hasOption(WaypointOption option) { return options.get(option); } @@ -206,13 +215,13 @@ public class Waypoint implements Unlockable { public class PathInfo { private final ArrayList waypoints; - private final int cost; + private final double cost; public ArrayList getWaypoints() { return waypoints; } - public int getCost() { + public double getCost() { return cost; } @@ -237,17 +246,27 @@ public class Waypoint implements Unlockable { - public PathInfo(ArrayList waypoints, int cost) { + public PathInfo(ArrayList waypoints, double cost) { this.waypoints = waypoints; this.cost = cost; } + public String displayIntermediaryWayPoints() { + if(waypoints.size()<=2) + return ""; + String result=""; + for(int i=1;i newWaypoints = new ArrayList<>(); newWaypoints.addAll(waypoints); newWaypoints.add(waypoint); - int cost=this.cost+getFinalWaypoint().getSimpleCostDestination(waypoint); + double cost=this.cost+getFinalWaypoint().getSimpleCostDestination(waypoint); return new PathInfo(newWaypoints,cost); } diff --git a/src/main/resources/default/gui/waypoints.yml b/src/main/resources/default/gui/waypoints.yml index 10bf393d..aa696e33 100644 --- a/src/main/resources/default/gui/waypoints.yml +++ b/src/main/resources/default/gui/waypoints.yml @@ -34,7 +34,7 @@ items: lore: - '&7You cannot teleport as the two waypoints are not linked.' - - '&7Teleporting costs &b&l{normal_cost}&7/&b&l{dynamic_cost} &7Stellium.' + # When you cannot teleport to a non dynamic waypoint not-dynamic: @@ -43,9 +43,9 @@ items: lore: - '&7You cannot teleport as you are not standing on a waypoint.' - - '&7Teleporting costs &b&l{normal_cost}&7/&b&l{dynamic_cost} &7Stellium.' - # When you cannot teleport to a non dynamic waypoint + + # When you don't have enough stellium not-enough-stellium: name: '&a{name}' item: ENDER_PEARL