Skip to content

Commit

Permalink
peer to peer option
Browse files Browse the repository at this point in the history
use variable for admin permission node
  • Loading branch information
ewof committed Jul 24, 2023
1 parent 3e7c2f4 commit 879a6d9
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 19 deletions.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,32 @@ Default config:
version: '1.0'
# The language file you wish to use.
language: en_US.yml

waypoints:


############################################################
# +------------------------------------------------------+ #
# | Restrictions | #
# +------------------------------------------------------+ #
############################################################

restrictions:

# The maximum number of blocks a player can travel between waypoints.
# Disabled with value of -1
max_distance: '5000'

# The amount of minutes a player must wait between waypoint travels.
cooldown: '1800'

# If true players can only teleport from one waypoint type to another.
peer_to_peer: 'true'
```
`waypoints.restrictions.max_distance` is the maximum number of blocks a player can travel via waypoints. A player cannot travel to a waypoint that is `max_distance` blocks away from their current location.
`waypoints.cooldown` is the amount of time in seconds a player must way between waypoint travels.
`waypoints.restrictions.max_distance` is the maximum number of blocks a player can travel via waypoints. A player cannot travel to a waypoint that is `max_distance` blocks away from their current location. <br/>
`waypoints.restrictions.cooldown` is the amount of time in seconds a player must way between waypoint travels. <br/>
`waypoints.restrictions.peer_to_peer` when set to true means that players must be standing in a waypoint of the same type to teleport to another waypoint, meaning I must be standing in a stable plot to teleport to a stable waypoint.

---

Expand Down Expand Up @@ -79,7 +83,7 @@ Seaports
- Can only be created in `BEACH` biomes

A player designates a plot as a waypoint by doing `/plot set <waypoint type name>`. <br/>
They can change things about the waypoint with `/twp set <toggle> <value>`. <br/>
They can change things about the waypoint with `/twp set <open> [value]`. <br/>
Waypoints travel can be open to everyone or limited to allies, nation members, town members, or noone (closed) with `/twp set open <status>`. <br/>
The block a player gets teleported to on traveling to a waypoint can be changed with `/twp set spawn` a waypoints default spawn is where the player was standing when they designated the plot as a waypoint.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class TownyWaypoints extends JavaPlugin
protected static final ConcurrentHashMap<String, Waypoint> waypoints = new ConcurrentHashMap<>();
private final String biomeKey = "allowed_biomes";

public static final String ADMIN_PERMISSION = "townywaypoints.admin";

@Override
public void onEnable()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import com.palmergames.bukkit.towny.TownyAPI;
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.object.*;
import com.palmergames.bukkit.towny.tasks.CooldownTimerTask;
import net.kyori.adventure.text.Component;
import net.mvndicraft.townywaypoints.TownyWaypoints;
Expand All @@ -28,7 +25,7 @@ public static void onTownyWaypoints(Player player)
player.sendMessage(Component.text(TownyWaypoints.getInstance().toString()));
}

@Subcommand("reload") @CommandPermission("townywaypoints.admin")
@Subcommand("reload") @CommandPermission(TownyWaypoints.ADMIN_PERMISSION)
@Description("Reloads the plugin config and locales.")
public static void onReload(Player player)
{
Expand Down Expand Up @@ -118,18 +115,26 @@ public static void onTravel(Player player, String townName, String waypointName,
return;
}

if (!player.hasPermission("townywaypoints.admin") && (TownyWaypointsSettings.getMaxDistance() != -1 && player.getLocation().distance(loc) > TownyWaypointsSettings.getMaxDistance())) {
if (!player.hasPermission(TownyWaypoints.ADMIN_PERMISSION) && (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;
}

TownyAPI townyAPI = TownyAPI.getInstance();

TownBlock playerTownBlock = townyAPI.getTownBlock(player);

if (playerTownBlock == null || (!player.hasPermission(TownyWaypoints.ADMIN_PERMISSION) && TownyWaypointsSettings.getPeerToPeer() && !playerTownBlock.getType().getName().equals(waypointName))) {
Messaging.sendErrorMsg(player, Translatable.of("msg_err_waypoint_p2p", waypointName, waypointName));
return;
}

Resident res = townyAPI.getResident(player);
if (res == null)
return;

int cooldown = CooldownTimerTask.getCooldownRemaining(player.getName(), "waypoint");
if (player.hasPermission("townywaypoints.admin") || cooldown == 0) {
if (player.hasPermission(TownyWaypoints.ADMIN_PERMISSION) || cooldown == 0) {
TownyWaypoints.getEconomy().withdrawPlayer(player, cost);
Messaging.sendMsg(player, Translatable.of("msg_waypoint_travel_warmup"));
townyAPI.requestTeleport(player, loc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private int getPlotTypeCount(Town town, String name)
}

@EventHandler
public void onPlotChangeTypeEvent(PlotPreChangeTypeEvent event) throws NotRegisteredException {
public void onPlotPreChangeTypeEvent(PlotPreChangeTypeEvent event) throws NotRegisteredException {
TownBlock townBlock = event.getTownBlock();
String plotTypeName = event.getNewType().getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public enum ConfigNodes {
"waypoints.restrictions.cooldown",
"1800",
"",
"# The amount of minutes a player must wait between waypoint travels.");
"# The amount of minutes a player must wait between waypoint travels."),
WAYPOINTS_RESTRICTIONS_PEER_TO_PEER(
"waypoints.restrictions.peer_to_peer",
"true",
"",
"# If true players can only teleport from one waypoint type to another.");

private final String Root;
private final String Default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ public static int getCooldown()
{
return Settings.getInt(ConfigNodes.WAYPOINTS_RESTRICTIONS_COOLDOWN);
}

public static boolean getPeerToPeer()
{
return Settings.getBoolean(ConfigNodes.WAYPOINTS_RESTRICTIONS_PEER_TO_PEER);
}
}
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 @@ -36,3 +36,4 @@ msg_err_waypoint_create_insufficient_permission: 'You do not have permission to
msg_err_waypoint_travel_too_far: '%s is too far away! Maximum travel distance is %d.'
msg_waypoint_travel_warmup: '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!'
2 changes: 1 addition & 1 deletion src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ dependencies:
required: true
permissions:
townywaypoints.admin:
description: "Allows use of the reload command and disables cooldown/distance check on travel."
description: "Allows use of the reload command and disables cooldown/distance/p2p check on travel."
default: op

0 comments on commit 879a6d9

Please sign in to comment.