mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2026-02-16 02:21:06 +00:00
effects load properly + Added Loading and Cancelled Titles
This commit is contained in:
@@ -64,12 +64,12 @@ public class RTPCooldown {
|
||||
public void remove(UUID id) {
|
||||
if (lockedAfter > 0) {
|
||||
locked.put(id, locked.getOrDefault(id, 1) - 1);
|
||||
if (locked.get(id) <= 0) { //Remove completely
|
||||
cooldowns.remove(id);
|
||||
if (locked.get(id) <= 0) { //Remove from file as well
|
||||
savePlayer(id, false, 0L, 0);
|
||||
} else { //Keep the player cached
|
||||
savePlayer(id, false, cooldowns.get(id), locked.get(id));
|
||||
}
|
||||
cooldowns.remove(id);
|
||||
} else { //Remove completely
|
||||
cooldowns.remove(id);
|
||||
savePlayer(id, false, 0L, 0);
|
||||
@@ -102,6 +102,7 @@ public class RTPCooldown {
|
||||
} else {
|
||||
if (!configfile.exists()) {
|
||||
try {
|
||||
configfile.getParentFile().mkdir();
|
||||
configfile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -120,7 +121,7 @@ public class RTPCooldown {
|
||||
|
||||
private void loadFile() {
|
||||
config = null;
|
||||
configfile = new File(Main.getInstance().getDataFolder(), "cooldowns.yml");
|
||||
configfile = new File(Main.getInstance().getDataFolder(), "data/cooldowns.yml");
|
||||
YamlConfiguration config = getFile();
|
||||
assert config != null;
|
||||
for (String id : config.getKeys(false)) {
|
||||
|
||||
@@ -79,7 +79,8 @@ class RTPDelay implements Listener {
|
||||
Bukkit.getScheduler().cancelTask(run);
|
||||
if (!Bukkit.getScheduler().isCurrentlyRunning(run)) {
|
||||
HandlerList.unregisterAll(this);
|
||||
getPl().getText().getMoved(pWorld.getPlayer());
|
||||
//getPl().getText().getMoved(pWorld.getPlayer());
|
||||
getPl().getRTP().getTeleport().cancelledTeleport(pWorld.getPlayer());
|
||||
getPl().getEco().unCharge(pWorld.getPlayer(), pWorld.getPrice());
|
||||
getPl().getCmd().cooldowns.remove(pWorld.getPlayer().getUniqueId());
|
||||
getPl().getCmd().rtping.put(pWorld.getPlayer().getUniqueId(), false);
|
||||
|
||||
@@ -28,11 +28,11 @@ public class RTPParticles {
|
||||
};
|
||||
|
||||
void load() {
|
||||
FileBasics.FILETYPE config = getPl().getFiles().getType(FileBasics.FILETYPE.CONFIG);
|
||||
enabled = config.getBoolean("Settings.Particles.Enabled");
|
||||
FileBasics.FILETYPE config = getPl().getFiles().getType(FileBasics.FILETYPE.EFFECTS);
|
||||
enabled = config.getBoolean("Particles.Enabled");
|
||||
if (!enabled) return;
|
||||
//Enabled? Load all this junk
|
||||
String type = config.getString("Settings.Particles.Type");
|
||||
String type = config.getString("Particles.Type");
|
||||
try {
|
||||
effect = ParticleEffect.valueOf(type.toUpperCase());
|
||||
} catch (IllegalArgumentException | NullPointerException e) {
|
||||
@@ -40,7 +40,7 @@ public class RTPParticles {
|
||||
getPl().getLogger().severe("The particle '" + type + "' doesn't exist! Default particle enabled... " +
|
||||
"Try using '/rtp info particles' to get a list of available particles");
|
||||
}
|
||||
shape = config.getString("Settings.Particles.Shape").toUpperCase();
|
||||
shape = config.getString("Particles.Shape").toUpperCase();
|
||||
if (!Arrays.asList(shapeTypes).contains(shape)) {
|
||||
getPl().getLogger().severe("The particle shape '" + shape + "' doesn't exist! Default particle shape enabled...");
|
||||
getPl().getLogger().severe("Try using '/rtp info shapes' to get a list of shapes, or: " + Arrays.asList(shapeTypes).toString());
|
||||
|
||||
@@ -10,37 +10,40 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class RTPPotions {
|
||||
public class RTPPotions { //Potions AND Invincibility
|
||||
|
||||
private boolean potionEnabled;
|
||||
private final HashMap<PotionEffectType, Integer> potionEffects = new HashMap<>();
|
||||
private final HashMap<PotionEffectType, Integer[]> potionEffects = new HashMap<>();
|
||||
private boolean invincibleEnabled;
|
||||
private int invincibleTime;
|
||||
|
||||
void load() {
|
||||
potionEffects.clear();
|
||||
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
|
||||
String pre = "Settings.Effects.";
|
||||
potionEnabled = config.getBoolean(pre + "Potions.Enabled");
|
||||
invincibleEnabled = config.getBoolean(pre + "Invincible.Enabled");
|
||||
FileBasics.FILETYPE config = FileBasics.FILETYPE.EFFECTS;
|
||||
//Invincible
|
||||
invincibleEnabled = config.getBoolean("Invincible.Enabled");
|
||||
if (invincibleEnabled)
|
||||
invincibleTime = config.getInt(pre + "Invincible.Seconds");
|
||||
invincibleTime = config.getInt("Invincible.Seconds");
|
||||
|
||||
//Potions
|
||||
potionEnabled = config.getBoolean("Potions.Enabled");
|
||||
if (potionEnabled) {
|
||||
List<String> list = config.getStringList(pre + "Potions.Types");
|
||||
List<String> list = config.getStringList("Potions.Types");
|
||||
for (String p : list) {
|
||||
String[] ary = p.split(":");
|
||||
String type = ary[0];
|
||||
String[] ary = p.replaceAll(" ", "").split(":");
|
||||
String type = ary[0].trim();
|
||||
PotionEffectType effect = PotionEffectType.getByName(type);
|
||||
if (effect != null) {
|
||||
try {
|
||||
int time = ary.length >= 2 ? Integer.parseInt(ary[1]) : 3;
|
||||
potionEffects.put(effect, time);
|
||||
int duration = ary.length >= 2 ? Integer.parseInt(ary[1]) : 60;
|
||||
int amplifier = ary.length >= 3 ? Integer.parseInt(ary[2]) : 1;
|
||||
potionEffects.put(effect, new Integer[] {duration, amplifier});
|
||||
} catch (NumberFormatException e) {
|
||||
Main.getInstance().getLogger().info("The potion duration `" + ary[1] + "` is not an integer! Effect removed!");
|
||||
Main.getInstance().getLogger().info("The potion duration or amplifier `" + ary[1] + "` is not an integer. Effect was removed!");
|
||||
}
|
||||
} else
|
||||
Main.getInstance().getLogger().info("The potion effect `" + type + "` does not exist! " +
|
||||
"Please fix or remove this potion effect! Try '/rtp info potion_effects'");
|
||||
"Please fix or remove this potion effect! Try '/rtp info potion_effects' to get a list of valid effects!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,8 +53,12 @@ public class RTPPotions {
|
||||
p.setNoDamageTicks(invincibleTime);
|
||||
if (potionEnabled) {
|
||||
List<PotionEffect> effects = new ArrayList<>();
|
||||
for (PotionEffectType e : potionEffects.keySet())
|
||||
effects.add(new PotionEffect(e, potionEffects.get(e), 1, false, false));
|
||||
for (PotionEffectType e : potionEffects.keySet()) {
|
||||
Integer[] mods = potionEffects.get(e);
|
||||
int duration = mods[0];
|
||||
int amplifier = mods[1];
|
||||
effects.add(new PotionEffect(e, duration, amplifier, false, false));
|
||||
}
|
||||
p.addPotionEffects(effects);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package me.SuperRonanCraft.BetterRTP.player.rtp;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import me.SuperRonanCraft.BetterRTP.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -28,23 +29,28 @@ public class RTPTeleport {
|
||||
|
||||
void sendPlayer(final CommandSender sendi, final Player p, final Location loc, final int price,
|
||||
final int attempts) throws NullPointerException {
|
||||
if (sendi != p) //Tell sendi that the player will/is being rtp'd
|
||||
sendSuccessMsg(sendi, p.getDisplayName(), loc, price, false, attempts);
|
||||
getPl().getText().getSuccessLoading(sendi); //Send loading message
|
||||
loadingTeleport(p, sendi); //Send loading message to player who requested
|
||||
List<CompletableFuture<Chunk>> asyncChunks = getChunks(loc); //Get a list of chunks
|
||||
CompletableFuture.allOf(asyncChunks.toArray(new CompletableFuture[] {})).thenRun(() -> { //Async chunk load
|
||||
try {
|
||||
PaperLib.teleportAsync(p, loc).thenRun(new BukkitRunnable() { //Async teleport
|
||||
@Override
|
||||
public void run() {
|
||||
afterTeleport(p, loc, price, attempts);
|
||||
getPl().getCmd().rtping.remove(p.getUniqueId()); //No longer rtp'ing
|
||||
new BukkitRunnable() { //Run synchronously
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
PaperLib.teleportAsync(p, loc).thenRun(new BukkitRunnable() { //Async teleport
|
||||
@Override
|
||||
public void run() {
|
||||
afterTeleport(p, loc, price, attempts);
|
||||
if (sendi != p) //Tell player who requested that the player rtp'd
|
||||
sendSuccessMsg(sendi, p.getDisplayName(), loc, price, false, attempts);
|
||||
getPl().getCmd().rtping.remove(p.getUniqueId()); //No longer rtp'ing
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
getPl().getCmd().rtping.remove(p.getUniqueId()); //No longer rtp'ing (errored)
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
getPl().getCmd().rtping.remove(p.getUniqueId()); //No longer rtp'ing (errored)
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.runTask(getPl());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -53,18 +59,32 @@ public class RTPTeleport {
|
||||
eParticles.display(p);
|
||||
ePotions.giveEffects(p);
|
||||
eTitles.showTeleport(p, loc, attempts);
|
||||
sendSuccessMsg(p, p.getDisplayName(), loc, price, true, attempts);
|
||||
if (eTitles.sendMsgTeleport())
|
||||
sendSuccessMsg(p, p.getDisplayName(), loc, price, true, attempts);
|
||||
}
|
||||
|
||||
public void beforeTeleport(Player p, int delay) { //Only Delays should call this
|
||||
eSounds.playDelay(p);
|
||||
eTitles.showDelay(p, p.getLocation());
|
||||
getPl().getText().getDelay(p, delay);
|
||||
eTitles.showDelay(p, p.getLocation(), delay);
|
||||
if (eTitles.sendMsgDelay())
|
||||
getPl().getText().getDelay(p, delay);
|
||||
}
|
||||
|
||||
public void cancelledTeleport(Player p) { //Only Delays should call this
|
||||
eTitles.showCancelled(p, p.getLocation());
|
||||
if (eTitles.sendMsgCancelled())
|
||||
getPl().getText().getMoved(p);
|
||||
}
|
||||
|
||||
private void loadingTeleport(Player p, CommandSender sendi) {
|
||||
eTitles.showLoading(p, p.getLocation());
|
||||
if (eTitles.sendMsgLoading() || sendi != p) //Show msg if enabled or if not same player
|
||||
getPl().getText().getSuccessLoading(sendi);
|
||||
}
|
||||
|
||||
private List<CompletableFuture<Chunk>> getChunks(Location loc) { //List all chunks in range to load
|
||||
List<CompletableFuture<Chunk>> asyncChunks = new ArrayList<>();
|
||||
int range = 5;
|
||||
int range = Math.round(Math.min(Bukkit.getServer().getViewDistance() / 2, 5));
|
||||
for (int x = -range; x <= range; x++) {
|
||||
for (int z = -range; z <= range; z++) {
|
||||
Location locLoad = new Location(loc.getWorld(), loc.getX() + (x * 16), loc.getY(), loc.getZ() + (z * 16));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.SuperRonanCraft.BetterRTP.player.rtp;
|
||||
|
||||
import me.SuperRonanCraft.BetterRTP.Main;
|
||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -10,46 +11,99 @@ public class RTPTitles {
|
||||
private String
|
||||
titleTeleport,
|
||||
titleDelay,
|
||||
titleCancel,
|
||||
titleLoading,
|
||||
subTeleport,
|
||||
subDelay;
|
||||
subDelay,
|
||||
subCancel,
|
||||
subLoading;
|
||||
private boolean //Disable default messages in chat
|
||||
showMsgTeleport,
|
||||
showMsgDelay,
|
||||
showMsgCancel,
|
||||
showMsgLoading;
|
||||
|
||||
void load() {
|
||||
FileBasics.FILETYPE config = FileBasics.FILETYPE.EFFECTS;
|
||||
enabled = config.getBoolean("Titles.Enabled");
|
||||
if (enabled) {
|
||||
//Titles
|
||||
titleTeleport = config.getString("Titles.Teleport.Title");
|
||||
titleDelay = config.getString("Titles.Teleport.Title");
|
||||
subTeleport = config.getString("Titles.Teleport.Title");
|
||||
subDelay = config.getString("Titles.Teleport.Title");
|
||||
titleDelay = config.getString("Titles.Delay.Title");
|
||||
titleCancel = config.getString("Titles.Cancelled.Title");
|
||||
titleLoading = config.getString("Titles.Loading.Title");
|
||||
//Sub titles
|
||||
subTeleport = config.getString("Titles.Teleport.Subtitle");
|
||||
subDelay = config.getString("Titles.Delay.Subtitle");
|
||||
subCancel = config.getString("Titles.Cancelled.Subtitle");
|
||||
subLoading = config.getString("Titles.Loading.Subtitle");
|
||||
//Messages
|
||||
showMsgTeleport = config.getBoolean("Titles.Teleport.SendMessage");
|
||||
showMsgDelay = config.getBoolean("Titles.Delay.SendMessage");
|
||||
showMsgCancel = config.getBoolean("Titles.Cancelled.SendMessage");
|
||||
showMsgLoading = config.getBoolean("Titles.Loading.SendMessage");
|
||||
}
|
||||
}
|
||||
|
||||
void showTeleport(Player p, Location loc, int attempts) {
|
||||
if (!enabled) return;
|
||||
String title = getPlaceholders(titleTeleport, p, loc, attempts);
|
||||
String subTitle = getPlaceholders(subTeleport, p, loc, attempts);
|
||||
show(p, title, subTitle);
|
||||
String title = getPlaceholders(titleTeleport, p, loc, attempts, 0);
|
||||
String sub = getPlaceholders(subTeleport, p, loc, attempts, 0);
|
||||
show(p, title, sub);
|
||||
}
|
||||
|
||||
void showDelay(Player p, Location loc) {
|
||||
void showDelay(Player p, Location loc, int delay) {
|
||||
if (!enabled) return;
|
||||
String title = getPlaceholders(titleDelay, p, loc, 0);
|
||||
String subTitle = getPlaceholders(subDelay, p, loc, 0);
|
||||
show(p, title, subTitle);
|
||||
String title = getPlaceholders(titleDelay, p, loc, 0, delay);
|
||||
String sub = getPlaceholders(subDelay, p, loc, 0, delay);
|
||||
show(p, title, sub);
|
||||
}
|
||||
|
||||
private String getPlaceholders(String str, Player p, Location loc, int attempts) {
|
||||
void showCancelled(Player p, Location loc) {
|
||||
if (!enabled) return;
|
||||
String title = getPlaceholders(titleCancel, p, loc, 0, 0);
|
||||
String sub = getPlaceholders(subCancel, p, loc, 0, 0);
|
||||
show(p, title, sub);
|
||||
}
|
||||
|
||||
void showLoading(Player p, Location loc) {
|
||||
if (!enabled) return;
|
||||
String title = getPlaceholders(titleLoading, p, loc, 0, 0);
|
||||
String sub = getPlaceholders(subLoading, p, loc, 0, 0);
|
||||
show(p, title, sub);
|
||||
}
|
||||
|
||||
boolean sendMsgTeleport() {
|
||||
return !enabled || showMsgTeleport;
|
||||
}
|
||||
|
||||
boolean sendMsgDelay() {
|
||||
return !enabled || showMsgDelay;
|
||||
}
|
||||
|
||||
boolean sendMsgCancelled() {
|
||||
return !enabled || showMsgCancel;
|
||||
}
|
||||
|
||||
boolean sendMsgLoading() {
|
||||
return !enabled || showMsgLoading;
|
||||
}
|
||||
|
||||
private String getPlaceholders(String str, Player p, Location loc, int attempts, int delay) {
|
||||
return str.replace("%player%", p.getName())
|
||||
.replace("%x%", String.valueOf(loc.getBlockX()))
|
||||
.replace("%y%", String.valueOf(loc.getBlockY()))
|
||||
.replace("%z%", String.valueOf(loc.getBlockZ()))
|
||||
.replace("%attempts%", String.valueOf(attempts));
|
||||
.replace("%attempts%", String.valueOf(attempts))
|
||||
.replace("%time%", String.valueOf(delay));
|
||||
}
|
||||
|
||||
private void show(Player p, String title, String sub) {
|
||||
// int fadeIn = getPl().text.getFadeIn();
|
||||
// int stay = text.getStay();
|
||||
// int fadeOut = text.getFadeOut();
|
||||
title = Main.getInstance().getText().color(title);
|
||||
sub = Main.getInstance().getText().color(sub);
|
||||
p.sendTitle(title, sub);
|
||||
// player.sendTitle(title, subTitle, fadeIn, stay, fadeOut);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ Settings:
|
||||
Cooldown:
|
||||
Enabled: true # Enabled or disabled cooldown timer
|
||||
LockAfter: 0 # Lock the player in an infinite cooldown after # rtp's (0 to disable)
|
||||
Time: 10 # in SECONDS
|
||||
Time: 600 # in SECONDS
|
||||
## Time between command and actually rtp'ing, time is in SECONDS. Set to "0" to disable delay timer #
|
||||
Delay:
|
||||
Enabled: true
|
||||
|
||||
@@ -4,26 +4,33 @@ Sounds:
|
||||
Delay: 'entity_tnt_primed'
|
||||
Success: 'entity_generic_explode'
|
||||
Titles:
|
||||
Enabled: true
|
||||
Enabled: true # Enable the titles effect feature
|
||||
## All support %player% %x% %y% and %z% placeholders
|
||||
Teleport:
|
||||
## Both support %player% %x% %y% and %z% placeholders
|
||||
Title: '&6Teleported!'
|
||||
Subtitle: '&fx=%x% y=%y% z=%z% in %attempts% attempts'
|
||||
SendMessage: true # Allow the teleport success message in chat
|
||||
Delay:
|
||||
## Both support %player% placeholders
|
||||
Title: ' '
|
||||
Title: ''
|
||||
Subtitle: '&fTeleporting in %time% seconds...'
|
||||
|
||||
Particles:
|
||||
SendMessage: true # Allow the teleport delay message in chat
|
||||
Cancelled:
|
||||
Title: '&eYou moved...'
|
||||
Subtitle: '&cRtp was cancelled!'
|
||||
SendMessage: true # Allow the cancelled message in chat too
|
||||
Loading:
|
||||
Title: ''
|
||||
Subtitle: '&7loading chunks... please wait'
|
||||
SendMessage: true # Allow the loading message in chat
|
||||
Particles: #Use `rtp info particles` for a list of particles
|
||||
Enabled: true
|
||||
Type: 'REVERSE_PORTAL' #list of particle types at https://github.com/ByteZ1337/ParticleLib/blob/master/src/main/java/xyz/xenondevs/particle/ParticleEffect.java
|
||||
Amount: 180
|
||||
Shape: 'SCAN' #Types available are "Scan, Teleport and Explode"
|
||||
Shape: 'SCAN' #Types available are "Scan, Teleport and Explode", or use `/rtp info shapes` for a list of shapes
|
||||
Invincible: #Amount of time a player should not take damage for
|
||||
Enabled: true
|
||||
Seconds: 5
|
||||
Potions:
|
||||
Potions: #Use `/rtp info potion_effects` for a list of effects
|
||||
Enabled: true
|
||||
Types:
|
||||
- 'Blindness:60'
|
||||
- 'Invisibility:60'
|
||||
Types: #Format <potion_name>:[duration_ticks]:[amplifier] #Default duration=60, amplifier=1
|
||||
- 'Blindness:60:1'
|
||||
- 'Invisibility:60:1'
|
||||
Reference in New Issue
Block a user