9
0
mirror of https://gitlab.com/SamB440/rpgregions-2.git synced 2026-01-06 15:41:35 +00:00

Feature: teleport cost

This commit is contained in:
ahdg
2023-02-25 14:14:24 +00:00
committed by SamB440
parent a8661fb8fc
commit f4b60744ea
8 changed files with 80 additions and 3 deletions

View File

@@ -3,6 +3,8 @@ plugins {
}
dependencies {
implementation("com.github.Redempt:Crunch:1.1.2") // used to evaluating mathematical expressions
testImplementation("junit:junit:4.13.2")
testImplementation("com.github.seeseemelk:MockBukkit-v1.17:1.13.0")
testImplementation("org.reflections:reflections:0.10.2")

View File

@@ -21,8 +21,11 @@ import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import redempt.crunch.CompiledExpression;
import redempt.crunch.Crunch;
import java.io.File;
import java.io.FileWriter;
@@ -72,6 +75,8 @@ public class ConfiguredRegion {
private Regenerate regenerate;
@EditableField(material = Material.NETHER_STAR, name = "Set teleport cooldown", description = "Set the cooldown for teleportation")
private int teleportCooldown;
@EditableField(material = Material.NETHER_STAR, name = "Set teleport cost", description = "Set the cost for teleportation")
private double teleportCost;
@NeedsGUI private boolean showActionbar;
@EditableField(material = Material.RED_DYE, name = "Hex display colour", description = "Set the colour of the region. It is a hex colour (e.g 0x42f4f1 for red) and is used in dynmap.")
private final String colour;
@@ -103,6 +108,7 @@ public class ConfiguredRegion {
this.discoveredLore = new ArrayList<>();
this.alwaysShowTitles = false;
this.teleportCooldown = 0;
this.teleportCost = 0.00;
this.showActionbar = true;
this.colour = String.valueOf(13369344);
this.lineColour = String.valueOf(13369344);
@@ -337,10 +343,29 @@ public class ConfiguredRegion {
return teleportCooldown;
}
public double getTeleportCost(Player player) {
double cost = teleportCost;
if (RPGRegionsAPI.getAPI().getConfig().getBoolean("settings.teleport.permission-based-cost") && cost == 0.00) {
for (PermissionAttachmentInfo perm : player.getEffectivePermissions()) {
if (perm.getPermission().startsWith("rpgregions.teleport" + ".")) {
String priceExpression = perm.getPermission()
.substring(perm.getPermission().lastIndexOf(".") + 1);
priceExpression = priceExpression.replace("n",
Math.round(player.getLocation().distance(this.location)) + "");
CompiledExpression exp = Crunch.compileExpression(priceExpression);
cost = exp.evaluate();
}
}
}
return cost;
}
public void setTeleportCooldown(int teleportCooldown) {
this.teleportCooldown = teleportCooldown;
}
public void setTeleportCost(int teleportCost) { this.teleportCost = teleportCost; }
public boolean showActionbar() {
return showActionbar;
}

View File

@@ -30,6 +30,8 @@ public enum Translations {
ALREADY_DISCOVERED_SUBTITLE(TranslationKey.of("already_discovered_subtitle")),
TELEPORT(TranslationKey.of("teleport")),
TELEPORT_COOLDOWN(TranslationKey.of("teleport_cooldown")),
TELEPORT_COST(TranslationKey.of("teleport_cost")),
NO_MONEY(TranslationKey.of("teleport_no_money")),
CANNOT_TELEPORT(TranslationKey.of("cannot_teleport")),
UNKNOWN_REGION(TranslationKey.of("unknown_region")),
EXIT(TranslationKey.of("exit")),

View File

@@ -12,6 +12,8 @@ already_discovered_subtitle:
- "&fAlready discovered!"
teleport: "&aClick to teleport"
teleport_cooldown: "&cTeleport is on cooldown."
teleport_cost: "Teleport will cost"
teleport_no_money: "&cYou have not enough money to teleport."
cannot_teleport: "&cWe can't teleport you because that world doesn't exist!"
unknown_region: "Unknown Realm"
exit: "&cExit"