mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-02-25 15:11:23 +01:00
Changes in PlayerData for warp fonction and in WayPointViewer / gui/waypoints.yml
This commit is contained in:
parent
41720d9048
commit
c8096765b4
@ -457,9 +457,9 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
|||||||
* Teleports the player to a specific waypoint. This applies
|
* Teleports the player to a specific waypoint. This applies
|
||||||
* the stellium waypoint cost and plays the teleport animation.
|
* 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
|
* 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
|
* player waypoints data
|
||||||
*/
|
*/
|
||||||
setLastActivity(PlayerActivity.USE_WAYPOINT);
|
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);
|
giveStellium(-cost, PlayerResourceUpdateEvent.UpdateReason.USE_WAYPOINT);
|
||||||
|
|
||||||
new BukkitRunnable() {
|
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());
|
MMOCore.plugin.configManager.getSimpleMessage("warping-comencing", "left", "" + ((120 - t) / 20)).send(getPlayer());
|
||||||
if (t++ >= 100) {
|
if (t++ >= 100) {
|
||||||
getPlayer().teleport(waypoint.getLocation());
|
getPlayer().teleport(target.getLocation());
|
||||||
getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1, false, false));
|
getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1, false, false));
|
||||||
MMOCore.plugin.soundManager.getSound(SoundEvent.WARP_TELEPORT).playTo(getPlayer());
|
MMOCore.plugin.soundManager.getSound(SoundEvent.WARP_TELEPORT).playTo(getPlayer());
|
||||||
cancel();
|
cancel();
|
||||||
|
@ -22,7 +22,9 @@ import org.bukkit.persistence.PersistentDataContainer;
|
|||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class WaypointViewer extends EditableInventory {
|
public class WaypointViewer extends EditableInventory {
|
||||||
public WaypointViewer() {
|
public WaypointViewer() {
|
||||||
@ -65,8 +67,8 @@ public class WaypointViewer extends EditableInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class WaypointItem extends SimplePlaceholderItem<WaypointViewerInventory> {
|
public class WaypointItem extends SimplePlaceholderItem<WaypointViewerInventory> {
|
||||||
private final SimplePlaceholderItem noWaypoint, locked;
|
private final SimplePlaceholderItem noWaypoint, locked,notLinked,notDynamic;
|
||||||
private final WaypointItemHandler availWaypoint, notLinked, notDynamic, noStellium;
|
private final WaypointItemHandler availWaypoint,noStellium;
|
||||||
|
|
||||||
public WaypointItem(ConfigurationSection config) {
|
public WaypointItem(ConfigurationSection config) {
|
||||||
super(Material.BARRIER, config);
|
super(Material.BARRIER, config);
|
||||||
@ -80,8 +82,8 @@ public class WaypointViewer extends EditableInventory {
|
|||||||
|
|
||||||
noWaypoint = new SimplePlaceholderItem(config.getConfigurationSection("no-waypoint"));
|
noWaypoint = new SimplePlaceholderItem(config.getConfigurationSection("no-waypoint"));
|
||||||
locked = new SimplePlaceholderItem(config.getConfigurationSection("locked"));
|
locked = new SimplePlaceholderItem(config.getConfigurationSection("locked"));
|
||||||
notLinked = new WaypointItemHandler(config.getConfigurationSection("not-a-destination"));
|
notLinked = new SimplePlaceholderItem(config.getConfigurationSection("not-a-destination"));
|
||||||
notDynamic = new WaypointItemHandler(config.getConfigurationSection("not-dynamic"));
|
notDynamic = new SimplePlaceholderItem(config.getConfigurationSection("not-dynamic"));
|
||||||
noStellium = new WaypointItemHandler(config.getConfigurationSection("not-enough-stellium"));
|
noStellium = new WaypointItemHandler(config.getConfigurationSection("not-enough-stellium"));
|
||||||
availWaypoint = new WaypointItemHandler(config.getConfigurationSection("display"));
|
availWaypoint = new WaypointItemHandler(config.getConfigurationSection("display"));
|
||||||
}
|
}
|
||||||
@ -104,20 +106,23 @@ public class WaypointViewer extends EditableInventory {
|
|||||||
return locked.display(inv, n);
|
return locked.display(inv, n);
|
||||||
|
|
||||||
// Waypoints are not linked
|
// 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);
|
return notLinked.display(inv, n);
|
||||||
|
|
||||||
// Not dynamic waypoint
|
// Not dynamic waypoint
|
||||||
if (inv.current == null && !waypoint.hasOption(WaypointOption.DYNAMIC))
|
if (inv.current == null && !waypoint.hasOption(WaypointOption.DYNAMIC))
|
||||||
return notDynamic.display(inv, n);
|
return notDynamic.display(inv, n);
|
||||||
|
|
||||||
//Dynamic waypoint
|
|
||||||
if(waypoint.hasOption(WaypointOption.DYNAMIC)&&inv.current==null)
|
|
||||||
|
|
||||||
// Stellium cost
|
//Dynamic waypoint
|
||||||
if (waypoint.getCost(inv.current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE) > inv.getPlayerData().getStellium())
|
if (waypoint.hasOption(WaypointOption.DYNAMIC) && inv.current == null && waypoint.getDynamicCost() > inv.getPlayerData().getStellium())
|
||||||
return noStellium.display(inv, n);
|
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);
|
return availWaypoint.display(inv, n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,9 +151,10 @@ public class WaypointViewer extends EditableInventory {
|
|||||||
|
|
||||||
Waypoint waypoint = inv.waypoints.get(inv.page * inv.getByFunction("waypoint").getSlots().size() + n);
|
Waypoint waypoint = inv.waypoints.get(inv.page * inv.getByFunction("waypoint").getSlots().size() + n);
|
||||||
holders.register("name", waypoint.getName());
|
holders.register("name", waypoint.getName());
|
||||||
holders.register("current_cost", decimal.format(waypoint.getCost(inv.waypointCostType)));
|
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(waypoint.getCost(CostType.NORMAL_USE)));
|
holders.register("normal_cost", decimal.format(inv.paths.get(waypoint).getCost()));
|
||||||
holders.register("dynamic_cost", decimal.format(waypoint.getCost(CostType.DYNAMIC_USE)));
|
holders.register("dynamic_cost", decimal.format(waypoint.getDynamicCost()));
|
||||||
|
holders.register("intermediary_waypoints", inv.paths.get(waypoint).displayIntermediaryWayPoints());
|
||||||
|
|
||||||
return holders;
|
return holders;
|
||||||
}
|
}
|
||||||
@ -157,7 +163,7 @@ public class WaypointViewer extends EditableInventory {
|
|||||||
public class WaypointViewerInventory extends GeneratedInventory {
|
public class WaypointViewerInventory extends GeneratedInventory {
|
||||||
private final List<Waypoint> waypoints = new ArrayList<>(MMOCore.plugin.waypointManager.getAll());
|
private final List<Waypoint> waypoints = new ArrayList<>(MMOCore.plugin.waypointManager.getAll());
|
||||||
private final Waypoint current;
|
private final Waypoint current;
|
||||||
private final ArrayList<Waypoint.PathInfo> paths;
|
private final Map<Waypoint, Waypoint.PathInfo> paths = new HashMap<>();
|
||||||
private final CostType waypointCostType;
|
private final CostType waypointCostType;
|
||||||
|
|
||||||
private int page;
|
private int page;
|
||||||
@ -166,7 +172,11 @@ public class WaypointViewer extends EditableInventory {
|
|||||||
super(playerData, editable);
|
super(playerData, editable);
|
||||||
|
|
||||||
this.current = current;
|
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;
|
this.waypointCostType = current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +220,7 @@ public class WaypointViewer extends EditableInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Waypoint does not have target as destination
|
// 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);
|
MMOCore.plugin.configManager.getSimpleMessage("cannot-teleport-to").send(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -223,7 +233,8 @@ public class WaypointViewer extends EditableInventory {
|
|||||||
|
|
||||||
// Stellium cost
|
// Stellium cost
|
||||||
CostType costType = current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE;
|
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) {
|
if (left > 0) {
|
||||||
MMOCore.plugin.configManager.getSimpleMessage("not-enough-stellium", "more", decimal.format(left)).send(player);
|
MMOCore.plugin.configManager.getSimpleMessage("not-enough-stellium", "more", decimal.format(left)).send(player);
|
||||||
return;
|
return;
|
||||||
@ -233,7 +244,11 @@ public class WaypointViewer extends EditableInventory {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
playerData.warp(waypoint, costType);
|
if (current == null)
|
||||||
|
playerData.warp(null, waypoint, costType);
|
||||||
|
else
|
||||||
|
playerData.warp(current, waypoint, costType);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,21 @@ public class Waypoint implements Unlockable {
|
|||||||
/**
|
/**
|
||||||
* Stellium cost for each action (0 being the default cost)
|
* Stellium cost for each action (0 being the default cost)
|
||||||
*/
|
*/
|
||||||
|
private final double dynamicCost,setSpawnCost;
|
||||||
private final Map<CostType, Double> costs = new HashMap<>();
|
private final Map<CostType, Double> 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) {
|
public Waypoint(ConfigurationSection config) {
|
||||||
id = Objects.requireNonNull(config, "Could not load config section").getName();
|
id = Objects.requireNonNull(config, "Could not load config section").getName();
|
||||||
name = Objects.requireNonNull(config.getString("name"), "Could not load waypoint name");
|
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"));
|
loc = readLocation(Objects.requireNonNull(config.getString("location"), "Could not read location"));
|
||||||
radiusSquared = Math.pow(config.getDouble("radius"), 2);
|
radiusSquared = Math.pow(config.getDouble("radius"), 2);
|
||||||
|
|
||||||
for (CostType costType : CostType.values())
|
dynamicCost=config.getDouble("cost.dynamic-use");
|
||||||
costs.put(costType, config.getDouble("cost." + costType.getPath()));
|
setSpawnCost=config.getDouble("cost.set-spawnpoint");
|
||||||
|
|
||||||
|
|
||||||
for (WaypointOption option : WaypointOption.values())
|
for (WaypointOption option : WaypointOption.values())
|
||||||
options.put(option, config.getBoolean("option." + option.getPath(), option.getDefaultValue()));
|
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
|
* @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()))
|
if (!destinations.keySet().contains(waypoint.getId()))
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
return destinations.get(waypoint.getId());
|
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) {
|
public boolean hasOption(WaypointOption option) {
|
||||||
return options.get(option);
|
return options.get(option);
|
||||||
}
|
}
|
||||||
@ -206,13 +215,13 @@ public class Waypoint implements Unlockable {
|
|||||||
|
|
||||||
public class PathInfo {
|
public class PathInfo {
|
||||||
private final ArrayList<Waypoint> waypoints;
|
private final ArrayList<Waypoint> waypoints;
|
||||||
private final int cost;
|
private final double cost;
|
||||||
|
|
||||||
public ArrayList<Waypoint> getWaypoints() {
|
public ArrayList<Waypoint> getWaypoints() {
|
||||||
return waypoints;
|
return waypoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCost() {
|
public double getCost() {
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,17 +246,27 @@ public class Waypoint implements Unlockable {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public PathInfo(ArrayList<Waypoint> waypoints, int cost) {
|
public PathInfo(ArrayList<Waypoint> waypoints, double cost) {
|
||||||
this.waypoints = waypoints;
|
this.waypoints = waypoints;
|
||||||
this.cost = cost;
|
this.cost = cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String displayIntermediaryWayPoints() {
|
||||||
|
if(waypoints.size()<=2)
|
||||||
|
return "";
|
||||||
|
String result="";
|
||||||
|
for(int i=1;i<waypoints.size()-1;i++) {
|
||||||
|
result+=waypoints.get(i).name+(i!=waypoints.size()-2?",":"");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public PathInfo addWayPoint(Waypoint waypoint) {
|
public PathInfo addWayPoint(Waypoint waypoint) {
|
||||||
Validate.isTrue(!waypoints.contains(waypoint), "You can't create cyclic path");
|
Validate.isTrue(!waypoints.contains(waypoint), "You can't create cyclic path");
|
||||||
ArrayList<Waypoint> newWaypoints = new ArrayList<>();
|
ArrayList<Waypoint> newWaypoints = new ArrayList<>();
|
||||||
newWaypoints.addAll(waypoints);
|
newWaypoints.addAll(waypoints);
|
||||||
newWaypoints.add(waypoint);
|
newWaypoints.add(waypoint);
|
||||||
int cost=this.cost+getFinalWaypoint().getSimpleCostDestination(waypoint);
|
double cost=this.cost+getFinalWaypoint().getSimpleCostDestination(waypoint);
|
||||||
return new PathInfo(newWaypoints,cost);
|
return new PathInfo(newWaypoints,cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ items:
|
|||||||
|
|
||||||
lore:
|
lore:
|
||||||
- '&7You cannot teleport as the two waypoints are not linked.'
|
- '&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
|
# When you cannot teleport to a non dynamic waypoint
|
||||||
not-dynamic:
|
not-dynamic:
|
||||||
@ -43,9 +43,9 @@ items:
|
|||||||
|
|
||||||
lore:
|
lore:
|
||||||
- '&7You cannot teleport as you are not standing on a waypoint.'
|
- '&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:
|
not-enough-stellium:
|
||||||
name: '&a{name}'
|
name: '&a{name}'
|
||||||
item: ENDER_PEARL
|
item: ENDER_PEARL
|
||||||
|
Loading…
Reference in New Issue
Block a user