mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-31 04:36:29 +00:00
Merge branch 'feature-cost-teleport' into 'master'
Feature: teleport cost See merge request SamB440/rpgregions-2!7
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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")),
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -58,6 +58,9 @@ allprojects {
|
||||
// GriefDefender
|
||||
maven("https://repo.glaremasters.me/repository/bloodshot")
|
||||
|
||||
// Crunch
|
||||
maven("https://redempt.dev")
|
||||
|
||||
flatDir { dir("../libraries") }
|
||||
}
|
||||
|
||||
@@ -80,6 +83,15 @@ allprojects {
|
||||
|
||||
relocate("com.convallyria.languagy", "net.islandearth.rpgregions.libs.languagy")
|
||||
relocate("io.papermc.lib", "net.islandearth.rpgregions.libs.paperlib")
|
||||
relocate("redempt.crunch", "net.islandearth.rpgregions.libs.crunch")
|
||||
relocate("co.aikar.commands", "net.islandearth.rpgregions.libs.acf")
|
||||
relocate("co.aikar.locales", "net.islandearth.rpgregions.libs.acf.locales")
|
||||
relocate("co.aikar.idb", "net.islandearth.rpgregions.libs.idb")
|
||||
relocate("com.github.stefvanschie.inventoryframework", "net.islandearth.rpgregions.libs.inventoryframework")
|
||||
relocate("org.bstats", "net.islandearth.rpgregions.libs.bstats")
|
||||
relocate("org.apache.commons.lang3", "net.islandearth.rpgregions.libs.lang3")
|
||||
relocate("me.lucko.helper", "net.islandearth.rpgregions.libs.helper")
|
||||
relocate("net.wesjd", "net.islandearth.rpgregions.libs.anvilgui")
|
||||
}
|
||||
|
||||
build {
|
||||
|
||||
@@ -60,6 +60,7 @@ import net.islandearth.rpgregions.rewards.RegionRewardRegistry;
|
||||
import net.islandearth.rpgregions.rewards.TeleportReward;
|
||||
import net.islandearth.rpgregions.tasks.DynmapTask;
|
||||
import net.islandearth.rpgregions.translation.Translations;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bstats.charts.SingleLineChart;
|
||||
@@ -69,6 +70,7 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
@@ -83,6 +85,7 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI {
|
||||
|
||||
private RPGRegionsManagers managers;
|
||||
private PaperCommandManager commandManager;
|
||||
private Economy ecoProvider;
|
||||
|
||||
public PaperCommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
@@ -116,6 +119,7 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI {
|
||||
this.translator = Translator.of(this, "lang", Language.ENGLISH, debug());
|
||||
this.registerTasks();
|
||||
this.registerMetrics();
|
||||
this.setupEconomy();
|
||||
|
||||
// Tell integration to enable
|
||||
if (managers.getIntegrationManager() instanceof RPGRegionsIntegration rpgRegionsIntegration) {
|
||||
@@ -296,6 +300,21 @@ public final class RPGRegions extends JavaPlugin implements IRPGRegionsAPI {
|
||||
return Bukkit.getPluginManager().getPlugin("HeadDatabase") != null;
|
||||
}
|
||||
|
||||
private void setupEconomy() {
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
return;
|
||||
}
|
||||
this.ecoProvider = rsp.getProvider();
|
||||
}
|
||||
|
||||
public Economy getEcoProvider() {
|
||||
return ecoProvider;
|
||||
}
|
||||
|
||||
private void registerTasks() {
|
||||
if (Bukkit.getPluginManager().getPlugin("Dynmap") != null
|
||||
&& getConfig().getBoolean("settings.external.dynmap")) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.github.stefvanschie.inventoryframework.pane.util.Mask;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import me.arcaniax.hdb.api.HeadDatabaseAPI;
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import net.islandearth.rpgregions.api.RPGRegionsAPI;
|
||||
import net.islandearth.rpgregions.command.IconCommand;
|
||||
import net.islandearth.rpgregions.managers.data.account.RPGRegionsAccount;
|
||||
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
||||
@@ -18,12 +19,14 @@ import net.islandearth.rpgregions.requirements.RegionRequirement;
|
||||
import net.islandearth.rpgregions.translation.Translations;
|
||||
import net.islandearth.rpgregions.utils.ItemStackBuilder;
|
||||
import net.islandearth.rpgregions.utils.StringUtils;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -237,6 +240,8 @@ public class DiscoveryGUI extends RPGRegionsGUI {
|
||||
.build();
|
||||
|
||||
boolean finalRequirements = requirements;
|
||||
double teleportCost = configuredRegion.getTeleportCost(player);
|
||||
Economy eco = plugin.getEcoProvider() != null ? plugin.getEcoProvider() : null;
|
||||
items.add(new GuiItem(new ItemStackBuilder(item)
|
||||
.withName(colour + configuredRegion.getCustomName())
|
||||
.withLore(lore)
|
||||
@@ -245,6 +250,7 @@ public class DiscoveryGUI extends RPGRegionsGUI {
|
||||
.withLore(" ")
|
||||
.withLore(requirementStrings)
|
||||
.withLore(teleport)
|
||||
.withLore(eco == null ? "" : Translations.TELEPORT_COST.get(player) + " " + teleportCost + eco.currencyNamePlural())
|
||||
.addFlags(ItemFlag.HIDE_ATTRIBUTES)
|
||||
.build(),
|
||||
event -> {
|
||||
@@ -255,12 +261,17 @@ public class DiscoveryGUI extends RPGRegionsGUI {
|
||||
if (!account.getCooldowns().contains(RPGRegionsAccount.AccountCooldown.TELEPORT)) {
|
||||
if (configuredRegion.getWorld() == null || !finalRequirements) {
|
||||
Translations.CANNOT_TELEPORT.send(player);
|
||||
} else if (eco != null && eco.getBalance(player) < teleportCost) {
|
||||
Translations.NO_MONEY.send(player);
|
||||
} else {
|
||||
if (configuredRegion.getLocation() != null) PaperLib.teleportAsync(player, configuredRegion.getLocation());
|
||||
else player.sendMessage(ChatColor.RED + "Unable to find teleport location.");
|
||||
if (configuredRegion.getLocation() != null) {
|
||||
PaperLib.teleportAsync(player, configuredRegion.getLocation());
|
||||
if (eco != null) eco.withdrawPlayer(player, teleportCost);
|
||||
} else player.sendMessage(ChatColor.RED + "Unable to find teleport location.");
|
||||
if (configuredRegion.getTeleportCooldown() != 0) {
|
||||
account.getCooldowns().add(RPGRegionsAccount.AccountCooldown.TELEPORT);
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> account.getCooldowns().remove(RPGRegionsAccount.AccountCooldown.TELEPORT), configuredRegion.getTeleportCooldown());
|
||||
Bukkit.getScheduler().runTaskLater(plugin,
|
||||
() -> account.getCooldowns().remove(RPGRegionsAccount.AccountCooldown.TELEPORT), configuredRegion.getTeleportCooldown());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -25,6 +25,10 @@ settings:
|
||||
name: RPGRegions # Name of the integration: WorldGuard, Residence, GriefPrevention, GriefDefender, UltraRegions, Lands, RPGRegions
|
||||
external:
|
||||
dynmap: true # Enable dynmap support
|
||||
teleport:
|
||||
# Enable a permission for costing money on teleport.
|
||||
# Example: rpgregions.teleport.10*n+100 means It costs $100 per teleport and 10 more per block away from the target location.
|
||||
permission-based-cost: true
|
||||
storage:
|
||||
mode: file # Storage mode to use: sqlite, file, mysql. If you are dealing with lots of players, please use a mysql database.
|
||||
sql: # SQL settings
|
||||
|
||||
Reference in New Issue
Block a user