mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2026-02-16 02:21:06 +00:00
cooldown and canrtp placeholders
This commit is contained in:
@@ -3,6 +3,7 @@ package me.SuperRonanCraft.BetterRTP.references.depends;
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPSetupInformation;
|
||||
import me.SuperRonanCraft.BetterRTP.references.PermissionNode;
|
||||
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperDate;
|
||||
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP_Command;
|
||||
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP_Info;
|
||||
@@ -11,12 +12,17 @@ import me.SuperRonanCraft.BetterRTP.references.player.playerdata.PlayerData;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.CooldownData;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.CooldownHandler;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.RTPWorld;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldPlayer;
|
||||
import me.SuperRonanCraft.BetterRTP.references.settings.Settings;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DepPlaceholderAPI extends PlaceholderExpansion {
|
||||
|
||||
@NotNull
|
||||
@@ -43,29 +49,10 @@ public class DepPlaceholderAPI extends PlaceholderExpansion {
|
||||
if (request.equalsIgnoreCase("count")) {
|
||||
return String.valueOf(data.getRtpCount());
|
||||
} else if (request.equalsIgnoreCase("cooldown")) {
|
||||
CooldownData cooldownData = data.getCooldowns().getOrDefault(player.getWorld(), null);
|
||||
if (cooldownData != null)
|
||||
return String.valueOf(cooldownData.getTime());
|
||||
else
|
||||
return "None";
|
||||
return cooldown(data, player.getWorld());
|
||||
} else if (request.startsWith("cooldown_")) {
|
||||
CooldownData cooldownData = null;
|
||||
String world_name = request.replace("cooldown_", "");
|
||||
if (world_name.length() > 0) {
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
if (world_name.equalsIgnoreCase(world.getName())) {
|
||||
cooldownData = data.getCooldowns().getOrDefault(player.getWorld(), null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cooldownData != null)
|
||||
return String.valueOf(cooldownData.getTime());
|
||||
else
|
||||
return "None";
|
||||
} else if (request.startsWith("rtpable_")) {
|
||||
String world_name = request.replace("rtpable_", "");
|
||||
World world = null;
|
||||
String world_name = request.replace("cooldown_", "");
|
||||
if (world_name.length() > 0) {
|
||||
for (World _world : Bukkit.getWorlds()) {
|
||||
if (world_name.equalsIgnoreCase(_world.getName())) {
|
||||
@@ -74,13 +61,51 @@ public class DepPlaceholderAPI extends PlaceholderExpansion {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (world == null) return "Invalid World";
|
||||
if (!PermissionNode.getAWorld(player, world.getName()))
|
||||
return "No Permission";
|
||||
CooldownData cooldownData = HelperPlayer.getData(player).getCooldowns().getOrDefault(world, null);
|
||||
//RTPWorld rtpWorld = BetterRTP.getInstance().getRTP().getPlayerWorld(new RTPSetupInformation());
|
||||
//if (cooldownData != null && BetterRTP.getInstance().getCooldowns().timeLeft(player, cooldownData, world))
|
||||
return cooldown(data, world);
|
||||
} else if (request.startsWith("canrtp_")) {
|
||||
String world_name = request.replace("canrtp_", "");
|
||||
World world = null;
|
||||
if (world_name.length() > 0)
|
||||
for (World _world : Bukkit.getWorlds())
|
||||
if (world_name.equalsIgnoreCase(_world.getName())) {
|
||||
world = _world;
|
||||
break;
|
||||
}
|
||||
return canRTP(player, world);
|
||||
} else if (request.equalsIgnoreCase("canrtp")) {
|
||||
World world = player.getWorld();
|
||||
return canRTP(player, world);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String cooldown(PlayerData data, World world) {
|
||||
if (world == null) return "Invalid World";
|
||||
if (BetterRTP.getInstance().getRTP().overriden.containsKey(world.getName()))
|
||||
world = Bukkit.getWorld(BetterRTP.getInstance().getRTP().overriden.get(world.getName()));
|
||||
CooldownData cooldownData = data.getCooldowns().getOrDefault(world, null);
|
||||
if (cooldownData != null)
|
||||
return HelperDate.stringFrom(cooldownData.getTime());
|
||||
else
|
||||
return "None";
|
||||
}
|
||||
|
||||
private String canRTP(Player player, World world) {
|
||||
if (world == null) return "Invalid World";
|
||||
if (BetterRTP.getInstance().getRTP().overriden.containsKey(world.getName()))
|
||||
world = Bukkit.getWorld(BetterRTP.getInstance().getRTP().overriden.get(world.getName()));
|
||||
//Permission
|
||||
if (!PermissionNode.getAWorld(player, world.getName()))
|
||||
return BetterRTP.getInstance().getSettings().getPlaceholder_nopermission();
|
||||
RTPSetupInformation setupInformation = new RTPSetupInformation(world, player, player, true);
|
||||
//Cooldown
|
||||
if (!HelperRTP.isCoolingDown(player, player, setupInformation, false))
|
||||
return BetterRTP.getInstance().getSettings().getPlaceholder_cooldown();
|
||||
WorldPlayer worldPlayer = BetterRTP.getInstance().getRTP().getPlayerWorld(setupInformation);
|
||||
//Price
|
||||
if (!BetterRTP.getInstance().getEco().hasBalance(player, worldPlayer))
|
||||
return BetterRTP.getInstance().getSettings().getPlaceholder_balance();
|
||||
//True
|
||||
return BetterRTP.getInstance().getSettings().getPlaceholder_true();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package me.SuperRonanCraft.BetterRTP.references.helpers;
|
||||
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.references.settings.Settings;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class HelperDate {
|
||||
|
||||
public static Date getDate() {
|
||||
return Calendar.getInstance().getTime();
|
||||
}
|
||||
|
||||
public static String stringFrom(Long amount) {
|
||||
Date current_date = HelperDate.getDate();
|
||||
long min = Math.min(amount, current_date.getTime());
|
||||
long max = Math.max(amount, current_date.getTime());
|
||||
long diffInMillies = max - min;
|
||||
long days = 0, hours = 0, minutes = 0, seconds = 0;
|
||||
if (diffInMillies > 0) {
|
||||
days = TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS);
|
||||
diffInMillies -= (((1000 * 60) * 60) * 24) * days;
|
||||
hours = TimeUnit.HOURS.convert(diffInMillies, TimeUnit.MILLISECONDS);
|
||||
diffInMillies -= ((1000 * 60) * 60) * hours;
|
||||
minutes = TimeUnit.MINUTES.convert(diffInMillies, TimeUnit.MILLISECONDS);
|
||||
diffInMillies -= (1000 * 60) * minutes;
|
||||
seconds = TimeUnit.SECONDS.convert(diffInMillies, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
Settings settings = BetterRTP.getInstance().getSettings();
|
||||
String time_str = settings.getPlaceholder_timeFormat();
|
||||
if (time_str.contains("%d"))
|
||||
time_str = time_str.replace("%d", settings.getPlaceholder_timeDays().replace("{0}", String.valueOf(days)));
|
||||
if (time_str.contains("%h"))
|
||||
time_str = time_str.replace("%h", settings.getPlaceholder_timeDays().replace("{0}", String.valueOf(hours)));
|
||||
if (time_str.contains("%m"))
|
||||
time_str = time_str.replace("%m", settings.getPlaceholder_timeDays().replace("{0}", String.valueOf(max)));
|
||||
if (time_str.contains("%s"))
|
||||
time_str = time_str.replace("%s", settings.getPlaceholder_timeDays().replace("{0}", String.valueOf(seconds)));
|
||||
|
||||
return time_str;
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class HelperRTP {
|
||||
delay = true;
|
||||
RTPSetupInformation setup_info = new RTPSetupInformation(world, sendi, player, true,
|
||||
biomes, delay, rtpType, locations, !ignoreCooldown && cooldownApplies(sendi, player)); //ignore cooldown or else
|
||||
if (ignoreCooldown || isCoolingDown(sendi, player, setup_info)) { //Is Cooling down
|
||||
if (ignoreCooldown || isCoolingDown(sendi, player, setup_info, true)) { //Is Cooling down
|
||||
getPl().getRTP().start(setup_info);
|
||||
}
|
||||
}
|
||||
@@ -77,12 +77,13 @@ public class HelperRTP {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isCoolingDown(CommandSender sendi, Player player, RTPSetupInformation setupInfo) {
|
||||
public static boolean isCoolingDown(CommandSender sendi, Player player, RTPSetupInformation setupInfo, boolean sendText) {
|
||||
if (!cooldownApplies(sendi, player)) //Bypassing/Forced?
|
||||
return true;
|
||||
CooldownHandler cooldownHandler = getPl().getCooldowns();
|
||||
if (!cooldownHandler.isLoaded() || !cooldownHandler.loadedPlayer(player)) { //Cooldowns have yet to download
|
||||
getPl().getText().getCooldown(sendi, String.valueOf(-1L));
|
||||
if (sendText)
|
||||
getPl().getText().getCooldown(sendi, String.valueOf(-1L));
|
||||
return false;
|
||||
}
|
||||
//Cooldown Data
|
||||
@@ -91,13 +92,15 @@ public class HelperRTP {
|
||||
if (cooldownData.getTime() == 0) //Global cooldown with nothing
|
||||
return true;
|
||||
else if (cooldownHandler.locked(player)) { //Infinite cooldown (locked)
|
||||
getPl().getText().getNoPermission(sendi);
|
||||
if (sendText)
|
||||
getPl().getText().getNoPermission(sendi);
|
||||
return false;
|
||||
} else { //Normal cooldown
|
||||
long timeLeft = cooldownHandler.timeLeft(player, cooldownData, BetterRTP.getInstance().getRTP().getPlayerWorld(setupInfo));
|
||||
if (timeLeft > 0) {
|
||||
//Still cooling down
|
||||
getPl().getText().getCooldown(sendi, String.valueOf(timeLeft));
|
||||
if (sendText)
|
||||
getPl().getText().getCooldown(sendi, String.valueOf(timeLeft));
|
||||
return false;
|
||||
} else {
|
||||
//Reset timer, but allow them to tp
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds;
|
||||
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_SHAPE;
|
||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -10,7 +10,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class WorldCustom implements RTPWorld, RTPWorld_Defaulted {
|
||||
public World world;
|
||||
|
||||
@@ -22,6 +22,17 @@ public class Settings {
|
||||
@Getter private boolean useLocationsInSameWorld;
|
||||
@Getter private boolean permissionGroupEnabled;
|
||||
@Getter private boolean queueEnabled;
|
||||
//Placeholders
|
||||
@Getter private String placeholder_true;
|
||||
@Getter private String placeholder_nopermission;
|
||||
@Getter private String placeholder_cooldown;
|
||||
@Getter private String placeholder_balance;
|
||||
@Getter private String placeholder_timeFormat;
|
||||
@Getter private String placeholder_timeDays;
|
||||
@Getter private String placeholder_timeHours;
|
||||
@Getter private String placeholder_timeMinutes;
|
||||
@Getter private String placeholder_timeSeconds;
|
||||
|
||||
|
||||
public void load() { //Load Settings
|
||||
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
|
||||
@@ -39,6 +50,16 @@ public class Settings {
|
||||
useLocationIfAvailable = FileBasics.FILETYPE.LOCATIONS.getBoolean("UseLocationIfAvailable");
|
||||
locationNeedPermission = FileBasics.FILETYPE.LOCATIONS.getBoolean("RequirePermission");
|
||||
useLocationsInSameWorld = FileBasics.FILETYPE.LOCATIONS.getBoolean("UseLocationsInSameWorld");
|
||||
//Placeholders
|
||||
placeholder_true = FileBasics.FILETYPE.PLACEHOLDERS.getString("Config.CanRTP.Success");
|
||||
placeholder_nopermission = FileBasics.FILETYPE.PLACEHOLDERS.getString("Config.CanRTP.NoPermission");
|
||||
placeholder_cooldown = FileBasics.FILETYPE.PLACEHOLDERS.getString("Config.CanRTP.Cooldown");
|
||||
placeholder_balance = FileBasics.FILETYPE.PLACEHOLDERS.getString("Config.CanRTP.Price");
|
||||
placeholder_timeFormat = FileBasics.FILETYPE.PLACEHOLDERS.getString("Config.TimeFormat.Format");
|
||||
placeholder_timeDays = FileBasics.FILETYPE.PLACEHOLDERS.getString("Config.TimeFormat.Days");
|
||||
placeholder_timeHours = FileBasics.FILETYPE.PLACEHOLDERS.getString("Config.TimeFormat.Hours");
|
||||
placeholder_timeMinutes = FileBasics.FILETYPE.PLACEHOLDERS.getString("Config.TimeFormat.Minutes");
|
||||
placeholder_timeSeconds = FileBasics.FILETYPE.PLACEHOLDERS.getString("Config.TimeFormat.Seconds");
|
||||
depends.load();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
## These are a list of placeholders for your use, Editting these will do nothing!
|
||||
betterrtp_count: 'Get total amount of rtp''s done'
|
||||
betterrtp_cooldown: 'Get cooldown in current world'
|
||||
betterrtp_cooldown_<world_name>: 'Get cooldown of a specified world'
|
||||
betterrtp_cooldown_<world_name>: 'Get cooldown of a specified world'
|
||||
betterrtp_canrtp_<world_name>: 'Get the reason or yes output if player can rtp in set world'
|
||||
betterrtp_canrtp: 'Get the reason or yes output if player can rtp in current world'
|
||||
|
||||
##Config section for placeholder outputs
|
||||
Config:
|
||||
TimeFormat:
|
||||
Days: '{0} Day(s)'
|
||||
Hours: '{0} Hours'
|
||||
Minutes: '{0} Mins'
|
||||
Seconds: '{0} Secs'
|
||||
#Placeholder %d = DAYS, %h = HOURS, %m = MINUTES, %s = SECONDS
|
||||
Format: '%d, %h, %m and %s'
|
||||
CanRTP:
|
||||
Success: '&aYes'
|
||||
NoPermission: '&cNo Permission'
|
||||
Cooldown: '&fCooling Down'
|
||||
Price: '&cNo. &7Reason: &eBankrupt'
|
||||
Reference in New Issue
Block a user