Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add invulnerability period #117

Open
wants to merge 43 commits into
base: v6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
58c72ee
feat: add invulnerability period
Thatsmusic99 Aug 2, 2023
720c721
fix: warning about slimjar and semi-fix for building
Thatsmusic99 Aug 8, 2023
51eff97
chore(version): bump to v6.0.0-rc.3
Thatsmusic99 Aug 9, 2023
80f62bd
Merge branch 'v6' into feat/teleport-invulnerability
Thatsmusic99 Nov 24, 2023
7c8a510
Merge branch 'v6' into feat/teleport-invulnerability
Thatsmusic99 Apr 9, 2024
4001396
Merge branch 'v6' into feat/teleport-invulnerability
Thatsmusic99 May 3, 2024
850a42e
Merge branch 'v6' into feat/teleport-invulnerability
Thatsmusic99 May 15, 2024
fe99245
chore: remove old building issues
Thatsmusic99 May 15, 2024
ffa7e2b
chore: cant believe i deleted a whole line
Thatsmusic99 May 15, 2024
1c917de
feat: Adding permission nodes to bypass teleport timer cancellations …
Thatsmusic99 May 15, 2024
5145e81
feat: add check-exact-coordinates
Thatsmusic99 May 15, 2024
1ea09cc
chore: streams have no place in tab completion
Thatsmusic99 May 21, 2024
6495d93
feat: add cooldowns to signs
Thatsmusic99 May 21, 2024
eb2bcff
feat: allow /tploc to run from the console
Thatsmusic99 May 22, 2024
f127133
chore: debug /homes issues
Thatsmusic99 May 31, 2024
d7f20d2
fix: version parsing working incorrectly for certain versions
Thatsmusic99 Jun 5, 2024
0dc5a9b
feat: this is a sign.
Thatsmusic99 Jun 11, 2024
419929f
fix: typo
Thatsmusic99 Jun 11, 2024
19373b3
chore: extra documentation on API
Thatsmusic99 Jun 11, 2024
589c4e0
chore: tidy up core class
Thatsmusic99 Jun 11, 2024
b49db85
chore(version): bump to 6.1.0
Thatsmusic99 Jun 11, 2024
71e88be
fix: oOOPS incomplete code
Thatsmusic99 Jun 11, 2024
e15fbe9
fix: correct regex pattern
Thatsmusic99 Jun 11, 2024
38fe0cb
fix: missing versions for publishing
Thatsmusic99 Jun 11, 2024
b05be1c
chore: add debugging to signs
Thatsmusic99 Jun 16, 2024
6300686
chore: debug sign manager method
Thatsmusic99 Jun 16, 2024
a4854b0
fix: your honour, I am an IntelliJ programmer using Vim
Thatsmusic99 Jun 16, 2024
bb03e67
fix: your honour, I repeat what I just said
Thatsmusic99 Jun 16, 2024
9b7709f
fix: this is gonna take too long to compile here
Thatsmusic99 Jun 16, 2024
30eccf3
chore: attempt to debug missing signs
Thatsmusic99 Jun 16, 2024
f7be025
fix: compare text content in flat display name
Thatsmusic99 Jun 18, 2024
1dad476
fix: I rest my case
Thatsmusic99 Jun 18, 2024
0171216
fix: WorldGuard not being picked up?
Thatsmusic99 Jun 19, 2024
09e04ad
fix: make the plugin hook manager not check a single claim plugin
Thatsmusic99 Jun 19, 2024
f25eefb
chore(version): bump to 6.1.1
Thatsmusic99 Jun 21, 2024
6fa7220
fix: neverBlocked message not used
Thatsmusic99 Jun 26, 2024
ca6889e
fix: #131 (floodgate players not being assigned on login)
Thatsmusic99 Jul 3, 2024
ed08a29
feat: add invulnerability period
Thatsmusic99 Aug 2, 2023
0da529d
chore: these names were disgusting so I changed them
Thatsmusic99 Jul 7, 2024
c403246
fix: invulnerability not being applied to /tpa and /tpahere
Thatsmusic99 Jul 7, 2024
a8182dc
feat: add cancel-warm-up-on-damage
Thatsmusic99 Jul 7, 2024
e9d2901
Merge branch 'v6' into feat/teleport-invulnerability
Thatsmusic99 Jul 7, 2024
081711a
fix: you want a valid statement?? i'll give YOU a valid statement
Thatsmusic99 Jul 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
import io.github.niestrat99.advancedteleport.api.events.players.ToggleTeleportationEvent;
import io.github.niestrat99.advancedteleport.config.CustomMessages;
import io.github.niestrat99.advancedteleport.config.MainConfig;
import io.github.niestrat99.advancedteleport.managers.CooldownManager;
import io.github.niestrat99.advancedteleport.managers.MovementManager;
import io.github.niestrat99.advancedteleport.managers.ParticleManager;
import io.github.niestrat99.advancedteleport.managers.PluginHookManager;
import io.github.niestrat99.advancedteleport.managers.*;
import io.github.niestrat99.advancedteleport.payments.PaymentManager;
import io.github.niestrat99.advancedteleport.sql.BlocklistManager;
import io.github.niestrat99.advancedteleport.sql.HomeSQLManager;
Expand Down Expand Up @@ -211,13 +208,15 @@ public void teleport(
PaymentManager.getInstance()
.withdraw(
command, player, event.getToLocation().getWorld());
InvulnerabilityManager.createInvulnerability(player, getInvulnerability(command, event.getToLocation().getWorld()));
if (MainConfig.get()
.APPLY_COOLDOWN_AFTER
.get()
.equalsIgnoreCase("teleport")) {
CooldownManager.addToCooldown(
command, player, event.getToLocation().getWorld());
}
InvulnerabilityManager.createInvulnerability(player, getInvulnerability(command, event.getToLocation().getWorld()));
});
}
}
Expand Down Expand Up @@ -607,7 +606,7 @@ public boolean hasHome(@NotNull final String name) {

if (home == null) return;
HomeSQLManager.get().removeHome(uuid, home.getName());

}, CoreClass.async);
}

Expand Down Expand Up @@ -809,6 +808,17 @@ public int getCooldown(@NotNull final String command, @NotNull final World desti
MainConfig.get().COOLDOWNS.valueOf(command).get());
}

@Range(from = 0, to = Integer.MAX_VALUE)
@Contract(pure = true)
public int getInvulnerability(@NotNull final String command, @NotNull final World destinationWorld) {
return determineValue("at.member.invulnerability",
command,
MainConfig.get().COMMAND_INVULNERABILITY_DURATIONS.valueOf(command).get(),
MainConfig.get().CUSTOM_INVULNERABILITY_DURATIONS.get(),
destinationWorld,
Math::max);
}

@Range(from = 0, to = Integer.MAX_VALUE)
@Contract(pure = true)
public @Deprecated int getCooldown(@NotNull final String command) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ private void getHomes(CommandSender sender, OfflinePlayer target, ImmutableColle
+ home.getName()));
})
.toList());

CoreClass.debug("Message text built.");

if (!body.content().isEmpty() || !body.children().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ If you prefer to use the Legacy Code format (i.e. &a, &b, etc.) then you can sti
addDefault(
"Teleport.eventMovement",
"<prefix> <gray>Teleport has been cancelled due to movement.");
addDefault(
"Teleport.eventDamage",
"<prefix> <gray>Teleport has been cancelled due to damage being taken.");
addDefault("Teleport.eventMovement_title.length", 60);
addDefault("Teleport.eventMovement_title.fade-in", 0);
addDefault("Teleport.eventMovement_title.fade-out", 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public final class MainConfig extends ATConfig {
public ConfigOption<Integer> WARM_UP_TIMER_DURATION;
public ConfigOption<Boolean> CANCEL_WARM_UP_ON_ROTATION;
public ConfigOption<Boolean> CANCEL_WARM_UP_ON_MOVEMENT;
public ConfigOption<Boolean> CANCEL_WARM_UP_ON_DAMAGE;
public ConfigOption<Boolean> CHECK_EXACT_COORDINATES;
public PerCommandOption<Integer> WARM_UPS;
public ConfigOption<ConfigSection> CUSTOM_WARM_UPS;
Expand All @@ -43,6 +44,10 @@ public final class MainConfig extends ATConfig {
public ConfigOption<Object> COST_AMOUNT;
public PerCommandOption<Object> COSTS;
public ConfigOption<ConfigSection> CUSTOM_COSTS;
public ConfigOption<Integer> INVULNERABILITY_DURATION;
public ConfigOption<List<String>> INVULNERABILITY_DAMAGE_BLACKLIST;
public PerCommandOption<Integer> COMMAND_INVULNERABILITY_DURATIONS;
public ConfigOption<ConfigSection> CUSTOM_INVULNERABILITY_DURATIONS;
public ConfigOption<Boolean> USE_PARTICLES;
public PerCommandOption<String> TELEPORT_PARTICLES;
public PerCommandOption<String> WAITING_PARTICLES;
Expand Down Expand Up @@ -204,6 +209,12 @@ public void addDefaults() {
"cancel-warm-up-on-movement",
true,
"Whether or not teleportation should be cancelled upon movement only.");
addDefault(
"cancel-warm-up-on-damage",
true,
"Whether or not teleportation should be cancelled when the player receives damage.\n" +
"Best option to accompany the invulnerability system if your server has it enabled, so that " +
"players can't cheese it. :thumbsup:");
addDefault("check-exact-coordinates",
false,
"Whether the plugin should check for change in exact X, Y and Z vs. block X, Y, Z.\n" +
Expand Down Expand Up @@ -290,7 +301,7 @@ The key (vip-warm-up) and group name (VIP) do not have to be different, this is
vip-cooldown: 3
Giving a group, such as VIP, the permission at.member.cooldown.vip-cooldown will have a cooldown of 3.
The key (vip-cooldown) and group name (VIP) do not have to be different, this is just an example.
You can also add at.member.cooldown.3, but this is more efficient if you find permissions lag.To make it per-command, use at.member.cooldown.<command>.vip-cooldown. To make it per-world, use at.member.cooldown.<world>.vip-cooldown.
You can also add at.member.cooldown.3, but this is more efficient if you find permissions lag. To make it per-command, use at.member.cooldown.<command>.vip-cooldown. To make it per-world, use at.member.cooldown.<world>.vip-cooldown.
To combine the two, you can use at.member.cooldown.<command>.<world>.vip-cooldown.\
""");

Expand Down Expand Up @@ -333,6 +344,32 @@ The key (vip-cooldown) and group name (VIP) do not have to be different, this is
To make it per-command, add the permission at.member.cost.tpa.vip-cost (for tpa) instead.\
""");

addDefault("invulnerability-duration", 0, "Invulnerability", "How long the invulnerability period lasts in seconds.");
addDefault("damage-blacklist", new ArrayList<>(), "All damage causes that are not cancelled by invulnerability.\n" +
"The full list is accessible here: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/EntityDamageEvent.DamageCause.html");

addComment("per-command-invulnerability", "Command-specific invulnerability durations.");
addDefault("per-command-invulnerability.tpa", "default", "Invulnerability duration for /tpa.");
addDefault("per-command-invulnerability.tpahere", "default", "Invulnerability duration for /tpahere.");
addDefault("per-command-invulnerability.tpr", "default", "Invulnerability duration for /tpr, or /rtp.");
addDefault("per-command-invulnerability.warp", "default", "Invulnerability duration for /warp");
addDefault("per-command-invulnerability.spawn", "default", "Invulnerability duration for /spawn");
addDefault("per-command-invulnerability.home", "default", "Invulnerability duration for /home");
addDefault("per-command-invulnerability.back", "default", "Invulnerability duration for /back");

makeSectionLenient("custom-invulnerability-periods");
addComment(
"custom-invulnerability-periods",
"""
Use this section to create custom invulnerability periods per-group.
Use the following format:
custom-invulnerability-periods:
vip: 5
Giving a group, such as VIP, the permission at.member.invulnerability.vip will have an invulnerable period of 5 seconds.
To make it per-command, add the permission at.member.invulnerability.tpa.vip (for tpa) instead.\
You can also add at.member.invulnerability.5, but this is more efficient if you find permissions lag.
""");

addDefault(
"use-particles",
true,
Expand Down Expand Up @@ -1010,6 +1047,7 @@ public void postSave() {
WARM_UP_TIMER_DURATION = new ConfigOption<>("warm-up-timer-duration");
CANCEL_WARM_UP_ON_ROTATION = new ConfigOption<>("cancel-warm-up-on-rotation");
CANCEL_WARM_UP_ON_MOVEMENT = new ConfigOption<>("cancel-warm-up-on-movement");
CANCEL_WARM_UP_ON_DAMAGE = new ConfigOption<>("cancel-warm-up-on-damage");
CHECK_EXACT_COORDINATES = new ConfigOption<>("check-exact-coordinates");
WARM_UPS = new PerCommandOption<>("per-command-warm-ups", "warm-up-timer-duration");
CUSTOM_WARM_UPS = new ConfigOption<>("custom-warm-ups");
Expand Down Expand Up @@ -1041,6 +1079,11 @@ public void postSave() {
COSTS = new PerCommandOption<>("per-command-cost", "cost-amount");
CUSTOM_COSTS = new ConfigOption<>("custom-costs");

INVULNERABILITY_DURATION = new ConfigOption<>("invulnerability-duration");
INVULNERABILITY_DAMAGE_BLACKLIST = new ConfigOption<>("damage-blacklist");
COMMAND_INVULNERABILITY_DURATIONS = new PerCommandOption<>("per-command-invulnerability", "invulnerability-duration");
CUSTOM_INVULNERABILITY_DURATIONS = new ConfigOption<>("custom-invulnerability-periods");

USE_PARTICLES = new ConfigOption<>("use-particles");
WAITING_PARTICLES =
new PerCommandOption<>("waiting-particles", "default-waiting-particles");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.github.niestrat99.advancedteleport.managers;

import io.github.niestrat99.advancedteleport.CoreClass;
import io.github.niestrat99.advancedteleport.config.MainConfig;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.jetbrains.annotations.NotNull;

public class InvulnerabilityManager {

public static void createInvulnerability(Player player, int duration) {
DamageListener damage = new DamageListener(player);

Bukkit.getScheduler().runTaskLater(CoreClass.getInstance(), task -> {
damage.destroy();
}, duration * 20L);
}

private static class DamageListener implements Listener {

private final @NotNull Player player;

public DamageListener(@NotNull Player player) {
this.player = player;
Bukkit.getPluginManager().registerEvents(this, CoreClass.getInstance());
}

@EventHandler
public void onDamage(EntityDamageEvent event) {

// If it's not this player, stop there
if (event.getEntity() != this.player) return;

// Check cause of damage in the damage list
if (MainConfig.get().INVULNERABILITY_DAMAGE_BLACKLIST.get().contains(event.getCause().name())) return;

event.setCancelled(true);
}

protected void destroy() {
HandlerList.unregisterAll(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.potion.PotionEffect;
Expand Down Expand Up @@ -41,6 +42,24 @@ public void onMovement(PlayerMoveEvent event) {
}
}

@EventHandler
public void onDamage(EntityDamageEvent event) {

// Make sure it's a player and someone on a timer
if (!(event.getEntity() instanceof Player player)) return;
if (!movement.containsKey(player.getUniqueId())) return;

// Verify that the option is enabled and the player is not bypassing the option
if (MainConfig.get().CANCEL_WARM_UP_ON_DAMAGE.get() && !player.hasPermission("at.admin.bypass.damage")) return;

// Cancel the timer
final var timer = movement.get(player.getUniqueId());
timer.cancel();
CustomMessages.sendMessage(player, "Teleport.eventDamage");
ParticleManager.removeParticles(player, timer.command);
movement.remove(player.getUniqueId());
}

private static boolean willCancelTimer(PlayerMoveEvent event) {
boolean cancelOnRotate = MainConfig.get().CANCEL_WARM_UP_ON_ROTATION.get() && !event.getPlayer().hasPermission("at.admin.bypass.rotation");
boolean cancelOnMove = MainConfig.get().CANCEL_WARM_UP_ON_MOVEMENT.get() && !event.getPlayer().hasPermission("at.admin.bypass.movement");
Expand Down Expand Up @@ -140,6 +159,10 @@ public void run() {
CustomMessages.sendMessage(teleportingPlayer, message, placeholders);
PaymentManager.getInstance()
.withdraw(command, payingPlayer, location.getWorld());
InvulnerabilityManager.createInvulnerability(
teleportingPlayer,
ATPlayer.getPlayer(teleportingPlayer)
.getInvulnerability(command, location.getWorld()));
// If the cooldown is to be applied after only after a teleport takes place,
// apply it now
if (MainConfig.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github.niestrat99.advancedteleport.config.CustomMessages;
import io.github.niestrat99.advancedteleport.config.MainConfig;
import io.github.niestrat99.advancedteleport.managers.CooldownManager;
import io.github.niestrat99.advancedteleport.managers.InvulnerabilityManager;
import io.github.niestrat99.advancedteleport.managers.MovementManager;
import io.github.niestrat99.advancedteleport.payments.PaymentManager;

Expand Down Expand Up @@ -71,6 +72,7 @@ private static void teleport(Player toPlayer, Player fromPlayer, String type) {
fromPlayer, toLocation, PlayerTeleportEvent.TeleportCause.COMMAND);
CustomMessages.sendMessage(fromPlayer, "Teleport.eventTeleport");
PaymentManager.getInstance().withdraw(type, payingPlayer, toLocation.getWorld());
InvulnerabilityManager.createInvulnerability(fromPlayer, atPlayer.getInvulnerability(type, event.getToLocation().getWorld()));

// If the cooldown is to be applied after only after a teleport takes place, apply it now
if (MainConfig.get().APPLY_COOLDOWN_AFTER.get().equalsIgnoreCase("teleport")) {
Expand Down
Loading