Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hydro vehicle tp #7

Merged
merged 14 commits into from
Aug 13, 2023
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
- name: Build with Gradle
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
with:
arguments: shadowJar build
arguments: shadowJar
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ stable:
cost: 4500.0 # Cost to create the waypoint.
travel_cost: 450 # Cost to travel to waypoint.
max: 1 # Max number of plots of this type allowed per town.
travel_with_vehicle: true # If true, player's vehicle will travel with the player.
permission: townywaypoints.landpoint.stable # Permission node required to set a plot to a type of this waypoint, if no permission is set anyone can create this waypoint, grant it in townyperms.yml
allowed_biomes: # List of biomes this plot type can be created on. If it's not provided the plot type can be created on any biome.
- FOREST
Expand All @@ -77,6 +78,7 @@ seaport:
cost: 2500.0 # Cost to create the waypoint.
travel_cost: 250 # Cost to travel to waypoint.
max: 1 # Max number of plots of this type allowed per town.
travel_with_vehicle: false # If true, player's vehicle will travel with the player.
permission: townywaypoints.seapoint.seaport # Permission node required to set a plot to a type of this waypoint, if no permission is set anyone can create this waypoint, grant it in townyperms.yml
allowed_biomes: # List of biomes this plot type can be created on. If it's not provided the plot type can be created on any biome.
- COLD_OCEAN
Expand Down
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "net.mvndicraft.townywaypoints"
version = "1.1-SNAPSHOT"
version = "1.2-SNAPSHOT"

repositories {
mavenCentral()
Expand All @@ -22,11 +22,13 @@ dependencies {
compileOnly("io.github.townyadvanced.commentedconfiguration:CommentedConfiguration:1.0.0")
compileOnly("com.github.MilkBowl:VaultAPI:1.7")
implementation("co.aikar:acf-paper:0.5.1-SNAPSHOT")
implementation("com.github.Anon8281:UniversalScheduler:0.1.6")
}

tasks.named<ShadowJar>("shadowJar") {
relocate("co.aikar.commands","net.mvndicraft.townywaypoints.acf")
relocate("co.aikar.locales","net.mvndicraft.townywaypoints.locales")
relocate("com.github.Anon8281.universalScheduler", "net.mvndicraft.townywaypoints.universalscheduler")
}

java {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/net/mvndicraft/townywaypoints/TownyWaypoints.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.mvndicraft.townywaypoints;

import co.aikar.commands.PaperCommandManager;
import com.github.Anon8281.universalScheduler.UniversalScheduler;
import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler;
import com.google.common.collect.ImmutableList;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.*;
Expand All @@ -27,6 +29,7 @@ public class TownyWaypoints extends JavaPlugin
{
private static TownyWaypoints instance;
private static Economy economy;
private static TaskScheduler scheduler;
protected static final ConcurrentHashMap<String, Waypoint> waypoints = new ConcurrentHashMap<>();
private final String biomeKey = "allowed_biomes";

Expand Down Expand Up @@ -103,6 +106,7 @@ public void onEnable()
public void onLoad()
{
instance = this;
scheduler = UniversalScheduler.getScheduler(instance);
loadWaypoints();
}

Expand Down Expand Up @@ -135,9 +139,15 @@ public static Economy getEconomy()
return economy;
}

public static TaskScheduler getScheduler()
{
return scheduler;
}

public String getVersion() {
return instance.getPluginMeta().getVersion();
}

public static ConcurrentHashMap<String, Waypoint> getWaypoints()
{
return waypoints;
Expand Down Expand Up @@ -171,6 +181,7 @@ private static Waypoint createWaypoint(ConfigurationSection config)
config.getDouble("travel_cost"),
config.getInt("max"),
config.getBoolean("sea"),
config.getBoolean("travel_with_vehicle"),
config.getString("permission"),
config.contains(instance.biomeKey) ? config.getStringList(instance.biomeKey) : new ArrayList<>()
);
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/net/mvndicraft/townywaypoints/Waypoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ public final class Waypoint {
private final double travelCost;
private final int max;
private final boolean sea;
private final boolean travelWithVehicle;
private final String permission;
private final List<String> allowedBiomes;

public Waypoint(String name, String mapKey, double cost, double travelCost, int max, boolean sea, String permission, List<String> allowedBiomes)
public Waypoint(String name, String mapKey, double cost, double travelCost, int max, boolean sea, boolean travelWithVehicle, String permission, List<String> allowedBiomes)
{
this.name = name;
this.mapKey = mapKey;
this.cost = cost;
this.travelCost = travelCost;
this.max = max;
this.sea = sea;
this.travelWithVehicle = travelWithVehicle;
this.permission = permission;
this.allowedBiomes = allowedBiomes;
}
Expand Down Expand Up @@ -50,6 +52,10 @@ public boolean isSea()
{
return sea;
}
public boolean travelWithVehicle()
{
return travelWithVehicle;
}

public String getPermission()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
package net.mvndicraft.townywaypoints.commands;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import javax.annotation.Nonnull;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.*;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.Translatable;
import com.palmergames.bukkit.towny.tasks.CooldownTimerTask;
import com.palmergames.paperlib.PaperLib;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Syntax;
import net.kyori.adventure.text.Component;
import net.mvndicraft.townywaypoints.TownyWaypoints;
import net.mvndicraft.townywaypoints.Waypoint;
import net.mvndicraft.townywaypoints.settings.Settings;
import net.mvndicraft.townywaypoints.settings.TownyWaypointsSettings;
import net.mvndicraft.townywaypoints.util.Messaging;
import net.mvndicraft.townywaypoints.util.TownBlockMetaDataController;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

@CommandAlias("townywaypoints|twaypoints|twp")
public class TownyWaypointsCommand extends BaseCommand
Expand Down Expand Up @@ -108,11 +123,13 @@ public static void onTravel(Player player, String townName, String waypointName,
Waypoint waypoint = TownyWaypoints.getWaypoints().get(waypointName);
double travelcost = waypoint.getTravelCost();

boolean admin = player.hasPermission(TownyWaypoints.ADMIN_PERMISSION);

String plotName = townBlock.getName();
if (plotName.equals(""))
plotName = Translatable.of("townywaypoints_plot_unnamed").defaultLocale();

if (!player.hasPermission(TownyWaypoints.ADMIN_PERMISSION) && TownyWaypoints.getEconomy().getBalance(player) - travelcost < 0) {
if (!admin && TownyWaypoints.getEconomy().getBalance(player) - travelcost < 0) {
Messaging.sendErrorMsg(player, Translatable.of("msg_err_waypoint_travel_insufficient_funds", plotName, travelcost));
return;
}
Expand All @@ -124,7 +141,7 @@ public static void onTravel(Player player, String townName, String waypointName,
return;
}

if (!player.hasPermission(TownyWaypoints.ADMIN_PERMISSION) && (TownyWaypointsSettings.getMaxDistance() != -1 && player.getLocation().distance(loc) > TownyWaypointsSettings.getMaxDistance())) {
if (!admin && (TownyWaypointsSettings.getMaxDistance() != -1 && player.getLocation().distance(loc) > TownyWaypointsSettings.getMaxDistance())) {
Messaging.sendErrorMsg(player, Translatable.of("msg_err_waypoint_travel_too_far", townBlock.getName(), TownyWaypointsSettings.getMaxDistance()));
return;
}
Expand All @@ -133,7 +150,7 @@ public static void onTravel(Player player, String townName, String waypointName,

TownBlock playerTownBlock = townyAPI.getTownBlock(player);

if (!player.hasPermission(TownyWaypoints.ADMIN_PERMISSION) && (playerTownBlock == null || TownyWaypointsSettings.getPeerToPeer() && !playerTownBlock.getType().getName().equals(waypointName))) {
if (!admin && (playerTownBlock == null || TownyWaypointsSettings.getPeerToPeer() && !playerTownBlock.getType().getName().equals(waypointName))) {
Messaging.sendErrorMsg(player, Translatable.of("msg_err_waypoint_p2p", waypointName, waypointName));
return;
}
Expand All @@ -143,14 +160,31 @@ public static void onTravel(Player player, String townName, String waypointName,
return;

int cooldown = CooldownTimerTask.getCooldownRemaining(player.getName(), "waypoint");
if (player.hasPermission(TownyWaypoints.ADMIN_PERMISSION) || cooldown == 0) {
if (admin || cooldown == 0) {
TownyWaypoints.getEconomy().withdrawPlayer(player, travelcost);
Messaging.sendMsg(player, Translatable.of("msg_waypoint_travel_warmup"));
townyAPI.requestTeleport(player, loc);
if (admin)
Messaging.sendMsg(player, Translatable.of("msg_waypoint_travel_warmup"));
else
Messaging.sendMsg(player, Translatable.of("msg_waypoint_travel_warmup_cost", travelcost));
teleport(player, loc, waypoint.travelWithVehicle());

if (!CooldownTimerTask.hasCooldown(player.getName(), "waypoint"))
CooldownTimerTask.addCooldownTimer(player.getName(), "waypoint", TownyWaypointsSettings.getCooldown());
} else {
Messaging.sendErrorMsg(player, Translatable.of("msg_err_waypoint_travel_cooldown", cooldown, townBlock.getName()));
}
}

private static void teleport(@Nonnull final Player player, @Nonnull Location loc, boolean travelWithVehicle) {
Entity vehicle = player.getVehicle();
boolean needToTpVehicle = travelWithVehicle && player.isInsideVehicle() && vehicle != null;

if(needToTpVehicle) {
vehicle.eject();
PaperLib.teleportAsync(vehicle, loc, TeleportCause.COMMAND);
}
PaperLib.teleportAsync(player, loc, TeleportCause.COMMAND);
if(needToTpVehicle)
TownyWaypoints.getScheduler().runTask(loc, () -> vehicle.addPassenger(player));
}
}
1 change: 1 addition & 0 deletions src/main/resources/lang/af-ZA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ msg_err_waypoint_create_insufficient_funds: 'Insufficient funds! Create cost for
msg_err_waypoint_create_insufficient_permission: 'You do not have permission to create %s waypoint!'
msg_err_waypoint_travel_too_far: '%s is too far away! Maximum travel distance is %d.'
msg_waypoint_travel_warmup: 'Waiting to teleport...'
msg_waypoint_travel_warmup_cost: 'Travel cost is %.2f. Waiting to teleport...'
msg_err_waypoint_travel_cooldown: 'You must wait %ds before traveling to %s!'
msg_err_waypoint_p2p: 'You must be standing in a %s waypoint plot to travel to another %s waypoint!'
msg_err_waypoint_set_spawn_insufficient_permission: 'You do not have permission to set the spawn of this waypoint!'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/ar-SA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ msg_err_waypoint_create_insufficient_funds: 'Insufficient funds! Create cost for
msg_err_waypoint_create_insufficient_permission: 'You do not have permission to create %s waypoint!'
msg_err_waypoint_travel_too_far: '%s is too far away! Maximum travel distance is %d.'
msg_waypoint_travel_warmup: 'Waiting to teleport...'
msg_waypoint_travel_warmup_cost: 'Travel cost is %.2f. Waiting to teleport...'
msg_err_waypoint_travel_cooldown: 'You must wait %ds before traveling to %s!'
msg_err_waypoint_p2p: 'You must be standing in a %s waypoint plot to travel to another %s waypoint!'
msg_err_waypoint_set_spawn_insufficient_permission: 'You do not have permission to set the spawn of this waypoint!'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/ca-ES.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ msg_err_waypoint_create_insufficient_funds: 'Insufficient funds! Create cost for
msg_err_waypoint_create_insufficient_permission: 'You do not have permission to create %s waypoint!'
msg_err_waypoint_travel_too_far: '%s is too far away! Maximum travel distance is %d.'
msg_waypoint_travel_warmup: 'Waiting to teleport...'
msg_waypoint_travel_warmup_cost: 'Travel cost is %.2f. Waiting to teleport...'
msg_err_waypoint_travel_cooldown: 'You must wait %ds before traveling to %s!'
msg_err_waypoint_p2p: 'You must be standing in a %s waypoint plot to travel to another %s waypoint!'
msg_err_waypoint_set_spawn_insufficient_permission: 'You do not have permission to set the spawn of this waypoint!'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/cs-CZ.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ msg_err_waypoint_create_insufficient_funds: 'Insufficient funds! Create cost for
msg_err_waypoint_create_insufficient_permission: 'You do not have permission to create %s waypoint!'
msg_err_waypoint_travel_too_far: '%s is too far away! Maximum travel distance is %d.'
msg_waypoint_travel_warmup: 'Waiting to teleport...'
msg_waypoint_travel_warmup_cost: 'Travel cost is %.2f. Waiting to teleport...'
msg_err_waypoint_travel_cooldown: 'You must wait %ds before traveling to %s!'
msg_err_waypoint_p2p: 'You must be standing in a %s waypoint plot to travel to another %s waypoint!'
msg_err_waypoint_set_spawn_insufficient_permission: 'You do not have permission to set the spawn of this waypoint!'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/da-DK.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ msg_err_waypoint_create_insufficient_funds: 'Insufficient funds! Create cost for
msg_err_waypoint_create_insufficient_permission: 'You do not have permission to create %s waypoint!'
msg_err_waypoint_travel_too_far: '%s is too far away! Maximum travel distance is %d.'
msg_waypoint_travel_warmup: 'Waiting to teleport...'
msg_waypoint_travel_warmup_cost: 'Travel cost is %.2f. Waiting to teleport...'
msg_err_waypoint_travel_cooldown: 'You must wait %ds before traveling to %s!'
msg_err_waypoint_p2p: 'You must be standing in a %s waypoint plot to travel to another %s waypoint!'
msg_err_waypoint_set_spawn_insufficient_permission: 'You do not have permission to set the spawn of this waypoint!'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/de-DE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ msg_err_waypoint_create_insufficient_funds: 'Insufficient funds! Create cost for
msg_err_waypoint_create_insufficient_permission: 'You do not have permission to create %s waypoint!'
msg_err_waypoint_travel_too_far: '%s is too far away! Maximum travel distance is %d.'
msg_waypoint_travel_warmup: 'Waiting to teleport...'
msg_waypoint_travel_warmup_cost: 'Travel cost is %.2f. Waiting to teleport...'
msg_err_waypoint_travel_cooldown: 'You must wait %ds before traveling to %s!'
msg_err_waypoint_p2p: 'You must be standing in a %s waypoint plot to travel to another %s waypoint!'
msg_err_waypoint_set_spawn_insufficient_permission: 'You do not have permission to set the spawn of this waypoint!'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/el-GR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ msg_err_waypoint_create_insufficient_funds: 'Insufficient funds! Create cost for
msg_err_waypoint_create_insufficient_permission: 'You do not have permission to create %s waypoint!'
msg_err_waypoint_travel_too_far: '%s is too far away! Maximum travel distance is %d.'
msg_waypoint_travel_warmup: 'Waiting to teleport...'
msg_waypoint_travel_warmup_cost: 'Travel cost is %.2f. Waiting to teleport...'
msg_err_waypoint_travel_cooldown: 'You must wait %ds before traveling to %s!'
msg_err_waypoint_p2p: 'You must be standing in a %s waypoint plot to travel to another %s waypoint!'
msg_err_waypoint_set_spawn_insufficient_permission: 'You do not have permission to set the spawn of this waypoint!'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ msg_err_waypoint_create_insufficient_funds: 'Insufficient funds! Create cost for
msg_err_waypoint_create_insufficient_permission: 'You do not have permission to create %s waypoint!'
msg_err_waypoint_travel_too_far: '%s is too far away! Maximum travel distance is %d.'
msg_waypoint_travel_warmup: 'Waiting to teleport...'
msg_waypoint_travel_warmup_cost: 'Travel cost is %.2f. Waiting to teleport...'
msg_err_waypoint_travel_cooldown: 'You must wait %ds before traveling to %s!'
msg_err_waypoint_p2p: 'You must be standing in a %s waypoint plot to travel to another %s waypoint!'
msg_err_waypoint_set_spawn_insufficient_permission: 'You do not have permission to set the spawn of this waypoint!'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/es-ES.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ msg_err_waypoint_create_insufficient_funds: 'Insufficient funds! Create cost for
msg_err_waypoint_create_insufficient_permission: 'You do not have permission to create %s waypoint!'
msg_err_waypoint_travel_too_far: '%s is too far away! Maximum travel distance is %d.'
msg_waypoint_travel_warmup: 'Waiting to teleport...'
msg_waypoint_travel_warmup_cost: 'Travel cost is %.2f. Waiting to teleport...'
msg_err_waypoint_travel_cooldown: 'You must wait %ds before traveling to %s!'
msg_err_waypoint_p2p: 'You must be standing in a %s waypoint plot to travel to another %s waypoint!'
msg_err_waypoint_set_spawn_insufficient_permission: 'You do not have permission to set the spawn of this waypoint!'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/fi-FI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ msg_err_waypoint_create_insufficient_funds: 'Insufficient funds! Create cost for
msg_err_waypoint_create_insufficient_permission: 'You do not have permission to create %s waypoint!'
msg_err_waypoint_travel_too_far: '%s is too far away! Maximum travel distance is %d.'
msg_waypoint_travel_warmup: 'Waiting to teleport...'
msg_waypoint_travel_warmup_cost: 'Travel cost is %.2f. Waiting to teleport...'
msg_err_waypoint_travel_cooldown: 'You must wait %ds before traveling to %s!'
msg_err_waypoint_p2p: 'You must be standing in a %s waypoint plot to travel to another %s waypoint!'
msg_err_waypoint_set_spawn_insufficient_permission: 'You do not have permission to set the spawn of this waypoint!'
Expand Down
Loading