Skip to content

Commit

Permalink
feat: Adding permission nodes to bypass teleport timer cancellations (#…
Browse files Browse the repository at this point in the history
…115)

* feat: Added permission nodes for bypassing movement and rotation on teleport timers

Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com>

* fix: return true by default if player is not stored in database for tp toggle (#116)

Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com>

* chore: add debugging for command registration

Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com>

* chore: add debugging for payment parsing

* fix: missing brackets

* fix: item payments being parsed incorrectly

* fix: check if permission is set

* fix: warning about slimjar and semi-fix for building

Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com>

* chore(version): bump to v6.0.0-rc.3

Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com>

* chore: remove old build stuff here too

Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com>

* chore: clarify movement timer code better

Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com>

---------

Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com>
Co-authored-by: Niestrat99 <35385996+niestrat99@users.noreply.github.com>
  • Loading branch information
Thatsmusic99 and Niestrat99 committed Jul 7, 2024
1 parent ffa7e2b commit 1c917de
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
2 changes: 2 additions & 0 deletions AdvancedTeleport-Bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,8 @@ bukkit {
"at.admin.bypass.distance-limit" to true,
"at.admin.sethome.bypass" to true,
"at.admin.bypass.teleport-on-join" to true,
"at.admin.bypass.movement" to true,
"at.admin.bypass.rotation" to true,
"at.admin.toggletp" to true,
"at.admin.bypass" to true,
"at.admin.tploc" to true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,11 @@ public class MovementManager implements Listener {

@EventHandler
public void onMovement(PlayerMoveEvent event) {
boolean cancelOnRotate = MainConfig.get().CANCEL_WARM_UP_ON_ROTATION.get();
boolean cancelOnMove = MainConfig.get().CANCEL_WARM_UP_ON_MOVEMENT.get();
if (!cancelOnRotate) {
Location locTo = event.getTo();
Location locFrom = event.getFrom();
if (locTo.getBlockX() == locFrom.getBlockX() // If the player rotated instead of moved
&& locTo.getBlockY() == locFrom.getBlockY()
&& locTo.getBlockZ() == locFrom.getBlockZ()) {
return;
}
}

boolean cancelled = willCancelTimer(event);

UUID uuid = event.getPlayer().getUniqueId();
if ((cancelOnRotate || cancelOnMove) && movement.containsKey(uuid)) {
if (cancelled && movement.containsKey(uuid)) {
ImprovedRunnable timer = movement.get(uuid);
timer.cancel();
CustomMessages.sendMessage(event.getPlayer(), "Teleport.eventMovement");
Expand All @@ -49,6 +41,37 @@ public void onMovement(PlayerMoveEvent event) {
}
}

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");

boolean cancelled = false;

// If we have to perform position checks, compare blocks
if (cancelOnMove) {
Location locTo = event.getTo();
Location locFrom = event.getFrom();
if (locTo.getBlockX() != locFrom.getBlockX() // If the player moved
|| locTo.getBlockY() != locFrom.getBlockY()
|| locTo.getBlockZ() != locFrom.getBlockZ()) {
cancelled = true;
}
}

// If we have to perform rotation checks, compare
if (cancelOnRotate && !cancelled) {
Location locTo = event.getTo();
Location locFrom = event.getFrom();

if (locTo.getPitch() != locFrom.getPitch()
|| locTo.getYaw() != locFrom.getYaw()) {
cancelled = true;
}
}

return cancelled;
}

public static HashMap<UUID, ImprovedRunnable> getMovement() {
return movement;
}
Expand Down Expand Up @@ -126,8 +149,8 @@ public void run() {
};
movement.put(uuid, movementtimer);
movementtimer.runTaskLater(CoreClass.getInstance(), warmUp * 20L);
if (MainConfig.get().CANCEL_WARM_UP_ON_MOVEMENT.get()
|| MainConfig.get().CANCEL_WARM_UP_ON_ROTATION.get()) {
if ((MainConfig.get().CANCEL_WARM_UP_ON_MOVEMENT.get() && !teleportingPlayer.hasPermission("at.admin.bypass.movement"))
|| (MainConfig.get().CANCEL_WARM_UP_ON_ROTATION.get() && !teleportingPlayer.hasPermission("at.admin.bypass.rotation"))) {
CustomMessages.sendMessage(
teleportingPlayer,
"Teleport.eventBeforeTP",
Expand Down

0 comments on commit 1c917de

Please sign in to comment.