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

General Feature Additions #577

Merged
merged 4 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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 @@ -136,7 +136,7 @@ protected static PermissionDefault getPermissionDefault(boolean isOperatorComman
public enum Type {
HOME_COMMAND(PrivateHomeCommand::new),
SET_HOME_COMMAND(SetHomeCommand::new),
HOME_LIST_COMMAND(PrivateHomeListCommand::new),
HOME_LIST_COMMAND(HomeListCommand::new),
DEL_HOME_COMMAND(DelHomeCommand::new),
EDIT_HOME_COMMAND(EditHomeCommand::new),
PUBLIC_HOME_COMMAND(PublicHomeCommand::new),
Expand Down
18 changes: 18 additions & 0 deletions bukkit/src/main/java/net/william278/huskhomes/user/BukkitUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.teleport.TeleportationException;
import net.william278.huskhomes.util.BukkitAdapter;
import net.william278.huskhomes.util.BukkitTask;
import net.william278.huskhomes.util.Task;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
WiIIiam278 marked this conversation as resolved.
Show resolved Hide resolved
import org.jetbrains.annotations.NotNull;
import space.arim.morepaperlib.scheduling.GracefulScheduling;

Expand Down Expand Up @@ -160,6 +164,20 @@ public boolean isVanished() {
.orElse(false);
}

/**
* Handles player invulnerability after teleporting
*/
@Override
public void handleInvulnerability() {
if (plugin.getSettings().getGeneral().getTeleportInvulnerabilityTime() <= 0) {
return;
}
long invulnerabilityTimeInTicks = 20L * plugin.getSettings().getGeneral().getTeleportInvulnerabilityTime();
player.setInvulnerable(true);
// Remove the invulnerability
plugin.runSyncDelayed(() -> player.setInvulnerable(false), invulnerabilityTimeInTicks);
}

/**
* Send a Bukkit plugin message to the player.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package net.william278.huskhomes.command;

import de.themoep.minedown.adventure.MineDown;
import de.themoep.minedown.adventure.MineDownParser;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.position.Home;
Expand All @@ -34,9 +36,9 @@
import java.util.Optional;
import java.util.stream.Collectors;

public class PrivateHomeListCommand extends ListCommand {
public class HomeListCommand extends ListCommand {

protected PrivateHomeListCommand(@NotNull HuskHomes plugin) {
protected HomeListCommand(@NotNull HuskHomes plugin) {
super("homelist", List.of("homes"), "[player] [page]", plugin);
addAdditionalPermissions(Map.of("other", true));
}
Expand Down Expand Up @@ -110,6 +112,8 @@ private Optional<PaginatedList> generateList(@NotNull CommandUser executor, @Not
plugin.getLocales()
.getRawLocale("home_list_item",
Locales.escapeText(home.getName()), home.getSafeIdentifier(),
home.isPublic() ? plugin.getLocales().getRawLocale("home_is_public").orElse("&#00fb9a&Public"):
Copy link
Owner

@WiIIiam278 WiIIiam278 Feb 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just supply Public or Private if no locale is found here without formatting :)

plugin.getLocales().getRawLocale("home_is_private").orElse("&#239e6f&Private"),
Locales.escapeText(home.getMeta().getDescription()))
.orElse(home.getName())).sorted().collect(Collectors.toList()),
plugin.getLocales()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void execute(@NotNull CommandUser executor, @NotNull String[] args) {
super.execute(executor, homes.get(0), args);
return;
}
plugin.getCommand(PrivateHomeListCommand.class)
plugin.getCommand(HomeListCommand.class)
.ifPresent(command -> command.showHomeList(executor, user.getUsername(), 1));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public static class GeneralSettings {
@Comment("Where the teleport warmup timer should display (CHAT, ACTION_BAR, TITLE, SUBTITLE or NONE)")
private Locales.DisplaySlot teleportWarmupDisplay = Locales.DisplaySlot.ACTION_BAR;

@Comment("How long the player should be invulnerable for after teleporting (in seconds)")
private int teleportInvulnerabilityTime = 0;

@Comment("How long before received teleport requests expire (in seconds)")
private int teleportRequestExpiryTime = 60;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private void handleInboundTeleport(@NotNull OnlineUser teleporter) {
}
plugin.getDatabase().clearCurrentTeleport(teleporter);
teleport.displayTeleportingComplete(teleporter);
teleporter.handleInvulnerability();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ private void executeLocal(@NotNull OnlineUser teleporter) throws TeleportationEx
if (updateLastPosition) {
plugin.getDatabase().setLastPosition(teleporter, teleporter.getPosition());
}

teleporter.teleportLocally(localTarget.get().getPosition(), async);
this.displayTeleportingComplete(teleporter);
teleporter.handleInvulnerability();
});
return;
}
Expand Down Expand Up @@ -127,6 +127,7 @@ private void executeLocal(@NotNull OnlineUser teleporter) throws TeleportationEx
|| target.getServer().equals(plugin.getServerName())) {
teleporter.teleportLocally(target, async);
this.displayTeleportingComplete(teleporter);
teleporter.handleInvulnerability();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ public Audience getAudience() {
*/
public abstract boolean isVanished();

/**
* Handles player invulnerability after teleporting
*
WiIIiam278 marked this conversation as resolved.
Show resolved Hide resolved
*/
public abstract void handleInvulnerability();

/**
* Get the maximum number of homes this user may set.
*
Expand Down
4 changes: 3 additions & 1 deletion common/src/main/resources/locales/en-gb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ locales:
public_home_list_page_title: '[☀ Public Homes:](#00fb9a) [(%1%-%2% of](#00fb9a) [%3%](#00fb9a bold)[)](#00fb9a)\n'
warp_list_page_title: '[Warps:](#00fb9a) [(%1%-%2% of](#00fb9a) [%3%](#00fb9a bold)[)](#00fb9a)\n'
command_list_title: '[HuskHomes](#00fb9a bold) [| Command List](#00fb9a)\n'
home_list_item: '[[%1%]](show_text=&#00fb9a&%1%\n&7ℹ %3% run_command=/huskhomes:edithome %2%)'
home_list_item: '[[%1%]](show_text=&#00fb9a&%1%\n&7Status: %3%\n&7ℹ %4% run_command=/huskhomes:edithome %2%)'
public_home_list_item: '[[%1%]](show_text=&#00fb9a&%1%\n&7☻ %3%\n&7ℹ %4% run_command=/huskhomes:phome %2%)'
home_is_public: "&#00fb9a&Public"
home_is_private: "&#239e6f&Private"
WiIIiam278 marked this conversation as resolved.
Show resolved Hide resolved
warp_list_item: '[[%1%]](show_text=&#00fb9a&%1%\n&7ℹ %3% run_command=/huskhomes:warp %2%)'
command_list_item: '[/%1%](#00fb9a show_text=&7Click to suggest command suggest_command=/%1%) [%2%](gray show_text=&#00fb9a&/%1%\n&7%3%)'
list_item_divider: ' [•](gray) '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private CommandUser resolveExecutor(@NotNull ServerCommandSource source) {
public enum Type {
HOME_COMMAND(PrivateHomeCommand::new),
SET_HOME_COMMAND(SetHomeCommand::new),
HOME_LIST_COMMAND(PrivateHomeListCommand::new),
HOME_LIST_COMMAND(HomeListCommand::new),
DEL_HOME_COMMAND(DelHomeCommand::new),
EDIT_HOME_COMMAND(EditHomeCommand::new),
PUBLIC_HOME_COMMAND(PublicHomeCommand::new),
Expand Down
18 changes: 18 additions & 0 deletions fabric/src/main/java/net/william278/huskhomes/user/FabricUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.TeleportTarget;
import net.william278.huskhomes.FabricHuskHomes;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.position.Location;
import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.position.World;
import net.william278.huskhomes.teleport.TeleportationException;
import net.william278.huskhomes.util.FabricTask;
import net.william278.huskhomes.util.Task;
import org.jetbrains.annotations.NotNull;

import java.util.*;
Expand Down Expand Up @@ -164,6 +167,21 @@ public boolean isVanished() {
return false;
}

/**
* Handles player invulnerability after teleporting
*/
@Override
public void handleInvulnerability() {
if (plugin.getSettings().getGeneral().getTeleportInvulnerabilityTime() <= 0) {
return;
}
long invulnerabilityTimeInTicks = 20L * plugin.getSettings().getGeneral().getTeleportInvulnerabilityTime();
player.setInvulnerable(true);
// Remove the invulnerability
plugin.runSyncDelayed(() -> player.setInvulnerable(false), invulnerabilityTimeInTicks);
}


@NotNull
private static Identifier parseIdentifier(@NotNull String channel) {
if (channel.equals("BungeeCord")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public Component usage(@NotNull CommandCause cause) {
public enum Type {
HOME_COMMAND(PrivateHomeCommand::new),
SET_HOME_COMMAND(SetHomeCommand::new),
HOME_LIST_COMMAND(PrivateHomeListCommand::new),
HOME_LIST_COMMAND(HomeListCommand::new),
DEL_HOME_COMMAND(DelHomeCommand::new),
EDIT_HOME_COMMAND(EditHomeCommand::new),
PUBLIC_HOME_COMMAND(PublicHomeCommand::new),
Expand Down
14 changes: 14 additions & 0 deletions sponge/src/main/java/net/william278/huskhomes/user/SpongeUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,18 @@ public boolean isVanished() {
return false;
}

/**
* Handles player invulnerability after teleporting
*/
@Override
public void handleInvulnerability() {
if (plugin.getSettings().getGeneral().getTeleportInvulnerabilityTime() <= 0) {
return;
}
long invulnerabilityTimeInTicks = 20L * plugin.getSettings().getGeneral().getTeleportInvulnerabilityTime();
player.invulnerable().set(true);
// Remove the invulnerability
plugin.runSyncDelayed(() -> player.invulnerable().set(true), invulnerabilityTimeInTicks);
WiIIiam278 marked this conversation as resolved.
Show resolved Hide resolved
}

}