effects load properly + Added Loading and Cancelled Titles

This commit is contained in:
SuperRonanCraft
2020-08-11 16:15:17 -04:00
parent 375ade83b3
commit 3bea7167a7
8 changed files with 158 additions and 68 deletions

View File

@@ -64,12 +64,12 @@ public class RTPCooldown {
public void remove(UUID id) { public void remove(UUID id) {
if (lockedAfter > 0) { if (lockedAfter > 0) {
locked.put(id, locked.getOrDefault(id, 1) - 1); locked.put(id, locked.getOrDefault(id, 1) - 1);
if (locked.get(id) <= 0) { //Remove completely if (locked.get(id) <= 0) { //Remove from file as well
cooldowns.remove(id);
savePlayer(id, false, 0L, 0); savePlayer(id, false, 0L, 0);
} else { //Keep the player cached } else { //Keep the player cached
savePlayer(id, false, cooldowns.get(id), locked.get(id)); savePlayer(id, false, cooldowns.get(id), locked.get(id));
} }
cooldowns.remove(id);
} else { //Remove completely } else { //Remove completely
cooldowns.remove(id); cooldowns.remove(id);
savePlayer(id, false, 0L, 0); savePlayer(id, false, 0L, 0);
@@ -102,6 +102,7 @@ public class RTPCooldown {
} else { } else {
if (!configfile.exists()) { if (!configfile.exists()) {
try { try {
configfile.getParentFile().mkdir();
configfile.createNewFile(); configfile.createNewFile();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@@ -120,7 +121,7 @@ public class RTPCooldown {
private void loadFile() { private void loadFile() {
config = null; config = null;
configfile = new File(Main.getInstance().getDataFolder(), "cooldowns.yml"); configfile = new File(Main.getInstance().getDataFolder(), "data/cooldowns.yml");
YamlConfiguration config = getFile(); YamlConfiguration config = getFile();
assert config != null; assert config != null;
for (String id : config.getKeys(false)) { for (String id : config.getKeys(false)) {

View File

@@ -79,7 +79,8 @@ class RTPDelay implements Listener {
Bukkit.getScheduler().cancelTask(run); Bukkit.getScheduler().cancelTask(run);
if (!Bukkit.getScheduler().isCurrentlyRunning(run)) { if (!Bukkit.getScheduler().isCurrentlyRunning(run)) {
HandlerList.unregisterAll(this); 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().getEco().unCharge(pWorld.getPlayer(), pWorld.getPrice());
getPl().getCmd().cooldowns.remove(pWorld.getPlayer().getUniqueId()); getPl().getCmd().cooldowns.remove(pWorld.getPlayer().getUniqueId());
getPl().getCmd().rtping.put(pWorld.getPlayer().getUniqueId(), false); getPl().getCmd().rtping.put(pWorld.getPlayer().getUniqueId(), false);

View File

@@ -28,11 +28,11 @@ public class RTPParticles {
}; };
void load() { void load() {
FileBasics.FILETYPE config = getPl().getFiles().getType(FileBasics.FILETYPE.CONFIG); FileBasics.FILETYPE config = getPl().getFiles().getType(FileBasics.FILETYPE.EFFECTS);
enabled = config.getBoolean("Settings.Particles.Enabled"); enabled = config.getBoolean("Particles.Enabled");
if (!enabled) return; if (!enabled) return;
//Enabled? Load all this junk //Enabled? Load all this junk
String type = config.getString("Settings.Particles.Type"); String type = config.getString("Particles.Type");
try { try {
effect = ParticleEffect.valueOf(type.toUpperCase()); effect = ParticleEffect.valueOf(type.toUpperCase());
} catch (IllegalArgumentException | NullPointerException e) { } catch (IllegalArgumentException | NullPointerException e) {
@@ -40,7 +40,7 @@ public class RTPParticles {
getPl().getLogger().severe("The particle '" + type + "' doesn't exist! Default particle enabled... " + getPl().getLogger().severe("The particle '" + type + "' doesn't exist! Default particle enabled... " +
"Try using '/rtp info particles' to get a list of available particles"); "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)) { if (!Arrays.asList(shapeTypes).contains(shape)) {
getPl().getLogger().severe("The particle shape '" + shape + "' doesn't exist! Default particle shape enabled..."); 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()); getPl().getLogger().severe("Try using '/rtp info shapes' to get a list of shapes, or: " + Arrays.asList(shapeTypes).toString());

View File

@@ -10,37 +10,40 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
public class RTPPotions { public class RTPPotions { //Potions AND Invincibility
private boolean potionEnabled; private boolean potionEnabled;
private final HashMap<PotionEffectType, Integer> potionEffects = new HashMap<>(); private final HashMap<PotionEffectType, Integer[]> potionEffects = new HashMap<>();
private boolean invincibleEnabled; private boolean invincibleEnabled;
private int invincibleTime; private int invincibleTime;
void load() { void load() {
potionEffects.clear(); potionEffects.clear();
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG; FileBasics.FILETYPE config = FileBasics.FILETYPE.EFFECTS;
String pre = "Settings.Effects."; //Invincible
potionEnabled = config.getBoolean(pre + "Potions.Enabled"); invincibleEnabled = config.getBoolean("Invincible.Enabled");
invincibleEnabled = config.getBoolean(pre + "Invincible.Enabled");
if (invincibleEnabled) if (invincibleEnabled)
invincibleTime = config.getInt(pre + "Invincible.Seconds"); invincibleTime = config.getInt("Invincible.Seconds");
//Potions
potionEnabled = config.getBoolean("Potions.Enabled");
if (potionEnabled) { if (potionEnabled) {
List<String> list = config.getStringList(pre + "Potions.Types"); List<String> list = config.getStringList("Potions.Types");
for (String p : list) { for (String p : list) {
String[] ary = p.split(":"); String[] ary = p.replaceAll(" ", "").split(":");
String type = ary[0]; String type = ary[0].trim();
PotionEffectType effect = PotionEffectType.getByName(type); PotionEffectType effect = PotionEffectType.getByName(type);
if (effect != null) { if (effect != null) {
try { try {
int time = ary.length >= 2 ? Integer.parseInt(ary[1]) : 3; int duration = ary.length >= 2 ? Integer.parseInt(ary[1]) : 60;
potionEffects.put(effect, time); int amplifier = ary.length >= 3 ? Integer.parseInt(ary[2]) : 1;
potionEffects.put(effect, new Integer[] {duration, amplifier});
} catch (NumberFormatException e) { } 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 } else
Main.getInstance().getLogger().info("The potion effect `" + type + "` does not exist! " + 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); p.setNoDamageTicks(invincibleTime);
if (potionEnabled) { if (potionEnabled) {
List<PotionEffect> effects = new ArrayList<>(); List<PotionEffect> effects = new ArrayList<>();
for (PotionEffectType e : potionEffects.keySet()) for (PotionEffectType e : potionEffects.keySet()) {
effects.add(new PotionEffect(e, potionEffects.get(e), 1, false, false)); 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); p.addPotionEffects(effects);
} }
} }

View File

@@ -2,6 +2,7 @@ package me.SuperRonanCraft.BetterRTP.player.rtp;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import me.SuperRonanCraft.BetterRTP.Main; import me.SuperRonanCraft.BetterRTP.Main;
import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.CommandSender; 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, void sendPlayer(final CommandSender sendi, final Player p, final Location loc, final int price,
final int attempts) throws NullPointerException { final int attempts) throws NullPointerException {
if (sendi != p) //Tell sendi that the player will/is being rtp'd loadingTeleport(p, sendi); //Send loading message to player who requested
sendSuccessMsg(sendi, p.getDisplayName(), loc, price, false, attempts);
getPl().getText().getSuccessLoading(sendi); //Send loading message
List<CompletableFuture<Chunk>> asyncChunks = getChunks(loc); //Get a list of chunks List<CompletableFuture<Chunk>> asyncChunks = getChunks(loc); //Get a list of chunks
CompletableFuture.allOf(asyncChunks.toArray(new CompletableFuture[] {})).thenRun(() -> { //Async chunk load CompletableFuture.allOf(asyncChunks.toArray(new CompletableFuture[] {})).thenRun(() -> { //Async chunk load
try { new BukkitRunnable() { //Run synchronously
PaperLib.teleportAsync(p, loc).thenRun(new BukkitRunnable() { //Async teleport @Override
@Override public void run() {
public void run() { try {
afterTeleport(p, loc, price, attempts); PaperLib.teleportAsync(p, loc).thenRun(new BukkitRunnable() { //Async teleport
getPl().getCmd().rtping.remove(p.getUniqueId()); //No longer rtp'ing @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) { }.runTask(getPl());
getPl().getCmd().rtping.remove(p.getUniqueId()); //No longer rtp'ing (errored)
e.printStackTrace();
}
}); });
} }
@@ -53,18 +59,32 @@ public class RTPTeleport {
eParticles.display(p); eParticles.display(p);
ePotions.giveEffects(p); ePotions.giveEffects(p);
eTitles.showTeleport(p, loc, attempts); 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 public void beforeTeleport(Player p, int delay) { //Only Delays should call this
eSounds.playDelay(p); eSounds.playDelay(p);
eTitles.showDelay(p, p.getLocation()); eTitles.showDelay(p, p.getLocation(), delay);
getPl().getText().getDelay(p, 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 private List<CompletableFuture<Chunk>> getChunks(Location loc) { //List all chunks in range to load
List<CompletableFuture<Chunk>> asyncChunks = new ArrayList<>(); 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 x = -range; x <= range; x++) {
for (int z = -range; z <= range; z++) { for (int z = -range; z <= range; z++) {
Location locLoad = new Location(loc.getWorld(), loc.getX() + (x * 16), loc.getY(), loc.getZ() + (z * 16)); Location locLoad = new Location(loc.getWorld(), loc.getX() + (x * 16), loc.getY(), loc.getZ() + (z * 16));

View File

@@ -1,5 +1,6 @@
package me.SuperRonanCraft.BetterRTP.player.rtp; package me.SuperRonanCraft.BetterRTP.player.rtp;
import me.SuperRonanCraft.BetterRTP.Main;
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics; import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -10,46 +11,99 @@ public class RTPTitles {
private String private String
titleTeleport, titleTeleport,
titleDelay, titleDelay,
titleCancel,
titleLoading,
subTeleport, subTeleport,
subDelay; subDelay,
subCancel,
subLoading;
private boolean //Disable default messages in chat
showMsgTeleport,
showMsgDelay,
showMsgCancel,
showMsgLoading;
void load() { void load() {
FileBasics.FILETYPE config = FileBasics.FILETYPE.EFFECTS; FileBasics.FILETYPE config = FileBasics.FILETYPE.EFFECTS;
enabled = config.getBoolean("Titles.Enabled"); enabled = config.getBoolean("Titles.Enabled");
if (enabled) { if (enabled) {
//Titles
titleTeleport = config.getString("Titles.Teleport.Title"); titleTeleport = config.getString("Titles.Teleport.Title");
titleDelay = config.getString("Titles.Teleport.Title"); titleDelay = config.getString("Titles.Delay.Title");
subTeleport = config.getString("Titles.Teleport.Title"); titleCancel = config.getString("Titles.Cancelled.Title");
subDelay = config.getString("Titles.Teleport.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) { void showTeleport(Player p, Location loc, int attempts) {
if (!enabled) return; if (!enabled) return;
String title = getPlaceholders(titleTeleport, p, loc, attempts); String title = getPlaceholders(titleTeleport, p, loc, attempts, 0);
String subTitle = getPlaceholders(subTeleport, p, loc, attempts); String sub = getPlaceholders(subTeleport, p, loc, attempts, 0);
show(p, title, subTitle); show(p, title, sub);
} }
void showDelay(Player p, Location loc) { void showDelay(Player p, Location loc, int delay) {
if (!enabled) return; if (!enabled) return;
String title = getPlaceholders(titleDelay, p, loc, 0); String title = getPlaceholders(titleDelay, p, loc, 0, delay);
String subTitle = getPlaceholders(subDelay, p, loc, 0); String sub = getPlaceholders(subDelay, p, loc, 0, delay);
show(p, title, subTitle); 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()) return str.replace("%player%", p.getName())
.replace("%x%", String.valueOf(loc.getBlockX())) .replace("%x%", String.valueOf(loc.getBlockX()))
.replace("%y%", String.valueOf(loc.getBlockY())) .replace("%y%", String.valueOf(loc.getBlockY()))
.replace("%z%", String.valueOf(loc.getBlockZ())) .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) { private void show(Player p, String title, String sub) {
// int fadeIn = getPl().text.getFadeIn(); // int fadeIn = getPl().text.getFadeIn();
// int stay = text.getStay(); // int stay = text.getStay();
// int fadeOut = text.getFadeOut(); // int fadeOut = text.getFadeOut();
title = Main.getInstance().getText().color(title);
sub = Main.getInstance().getText().color(sub);
p.sendTitle(title, sub); p.sendTitle(title, sub);
// player.sendTitle(title, subTitle, fadeIn, stay, fadeOut); // player.sendTitle(title, subTitle, fadeIn, stay, fadeOut);
} }

View File

@@ -22,7 +22,7 @@ Settings:
Cooldown: Cooldown:
Enabled: true # Enabled or disabled cooldown timer Enabled: true # Enabled or disabled cooldown timer
LockAfter: 0 # Lock the player in an infinite cooldown after # rtp's (0 to disable) 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 # ## Time between command and actually rtp'ing, time is in SECONDS. Set to "0" to disable delay timer #
Delay: Delay:
Enabled: true Enabled: true

View File

@@ -4,26 +4,33 @@ Sounds:
Delay: 'entity_tnt_primed' Delay: 'entity_tnt_primed'
Success: 'entity_generic_explode' Success: 'entity_generic_explode'
Titles: Titles:
Enabled: true Enabled: true # Enable the titles effect feature
## All support %player% %x% %y% and %z% placeholders
Teleport: Teleport:
## Both support %player% %x% %y% and %z% placeholders
Title: '&6Teleported!' Title: '&6Teleported!'
Subtitle: '&fx=%x% y=%y% z=%z% in %attempts% attempts' Subtitle: '&fx=%x% y=%y% z=%z% in %attempts% attempts'
SendMessage: true # Allow the teleport success message in chat
Delay: Delay:
## Both support %player% placeholders Title: ''
Title: ' '
Subtitle: '&fTeleporting in %time% seconds...' Subtitle: '&fTeleporting in %time% seconds...'
SendMessage: true # Allow the teleport delay message in chat
Particles: 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 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 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", or use `/rtp info shapes` for a list of shapes
Shape: 'SCAN' #Types available are "Scan, Teleport and Explode"
Invincible: #Amount of time a player should not take damage for Invincible: #Amount of time a player should not take damage for
Enabled: true Enabled: true
Seconds: 5 Seconds: 5
Potions: Potions: #Use `/rtp info potion_effects` for a list of effects
Enabled: true Enabled: true
Types: Types: #Format <potion_name>:[duration_ticks]:[amplifier] #Default duration=60, amplifier=1
- 'Blindness:60' - 'Blindness:60:1'
- 'Invisibility:60' - 'Invisibility:60:1'