Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -193,6 +193,8 @@ public enum Permission {
ESSENTIALS_PAY_TOGGLE,
ESSENTIALS_PAY_TOGGLE_OTHER,
ESSENTIALS_MESSAGE_TOGGLE_OTHER,
ESSENTIALS_TP_TOGGLE("Toggle receiving teleport requests"),
ESSENTIALS_TP_TOGGLE_OTHER("Toggle receiving teleport requests for other players"),
ESSENTIALS_GIVE,
ESSENTIALS_GIVE_ALL,
ESSENTIALS_ITEM_LORE_CLEAR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ public enum Message {
DESCRIPTION_MESSAGE("Send a private message to a player"),
DESCRIPTION_REPLY("Reply to a private message"),
DESCRIPTION_MESSAGE_TOGGLE("Toggle private message"),
DESCRIPTION_TP_TOGGLE("Toggle receiving teleport requests"),
DESCRIPTION_POWER_TOOLS_TOGGLE("Toggle power tools"),
DESCRIPTION_SOCIALSPY("Display private messages of players"),
DESCRIPTION_COMPACT_ALL("Compact items in your inventories"),
Expand Down Expand Up @@ -685,6 +686,9 @@ public enum Message {
COMMAND_PAY_TOGGLE_DISABLE("<error>All of your power tools have been disabled &7for &f%player%<error>."),
COMMAND_POWER_TOOLS_TOGGLE_ENABLE("<success>All of your power tools have been enabled &7for &f%player%<success>."),
COMMAND_POWER_TOOLS_TOGGLE_DISABLE("&7Pay <error>disable &7for &f%player%<error>."),
COMMAND_TELEPORT_REQUEST_DISABLED("<error>The player &f%player%<error> has disabled teleport requests."),
COMMAND_TP_TOGGLE_ENABLE("&7Teleport requests <success>enabled &7for &f%player%<success>."),
COMMAND_TP_TOGGLE_DISABLE("&7Teleport requests <error>disabled &7for &f%player%<error>."),

COMMAND_FURNACE_TYPE("<error>Impossible to smelt the material &f%material%<error>."),
COMMAND_FURNACE_ERROR("<error>You have no &f%item%<error> in your inventory."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ public enum Option {
PHANTOMS_DISABLE,
WORLDEDIT_INVENTORY,
WORLDEDIT_BOSSBAR_DISABLE,
TELEPORT_REQUEST_DISABLE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import fr.maxlego08.essentials.commands.commands.messages.CommandMessageToggle;
import fr.maxlego08.essentials.commands.commands.messages.CommandReply;
import fr.maxlego08.essentials.commands.commands.messages.CommandSocialSpy;
import fr.maxlego08.essentials.commands.commands.teleport.CommandTpToggle;
import fr.maxlego08.essentials.commands.commands.sanction.CommandBan;
import fr.maxlego08.essentials.commands.commands.sanction.CommandFreeze;
import fr.maxlego08.essentials.commands.commands.sanction.CommandKick;
Expand Down Expand Up @@ -232,6 +233,7 @@ public void loadCommands(CommandManager commandManager) {
register("message", CommandMessage.class, "msg", "tell", "whisper", "m", "w");
register("reply", CommandReply.class, "r");
register("messagetoggle", CommandMessageToggle.class, "msgtoggle", "mtg");
register("tptoggle", CommandTpToggle.class);
register("socialspy", CommandSocialSpy.class);

register("repair", CommandRepair.class, "fix");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package fr.maxlego08.essentials.commands.commands.teleport;

import fr.maxlego08.essentials.api.EssentialsPlugin;
import fr.maxlego08.essentials.api.commands.CommandResultType;
import fr.maxlego08.essentials.api.commands.Permission;
import fr.maxlego08.essentials.api.messages.Message;
import fr.maxlego08.essentials.api.user.Option;
import fr.maxlego08.essentials.api.user.User;
import fr.maxlego08.essentials.module.modules.MessageModule;
import fr.maxlego08.essentials.zutils.utils.commands.VCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

/**
* Command to toggle receiving teleport requests.
* Allows players to enable/disable receiving TPA and TPAHERE requests from other players.
*/
public class CommandTpToggle extends VCommand {

public CommandTpToggle(EssentialsPlugin plugin) {
super(plugin);
this.setModule(MessageModule.class);
this.setPermission(Permission.ESSENTIALS_TP_TOGGLE);
this.setDescription(Message.DESCRIPTION_TP_TOGGLE);
this.addOptionalArg("player");
}

@Override
protected CommandResultType perform(EssentialsPlugin plugin) {

Player player = this.argAsPlayer(0, this.player);

if (player == null) {
return CommandResultType.SYNTAX_ERROR;
}

// Check if toggling for self or if user has permission to toggle for others
if (player == this.player || !hasPermission(sender, Permission.ESSENTIALS_TP_TOGGLE_OTHER)) {
toggleTeleportRequest(player, this.user, sender);
} else {
User otherUser = getUser(player);
toggleTeleportRequest(player, otherUser, sender);
}

return CommandResultType.SUCCESS;
}

/**
* Toggle the teleport request option for the specified user.
*
* @param player The player whose setting is being toggled
* @param user The user object to modify
* @param sender The command sender who executed the command
*/
private void toggleTeleportRequest(Player player, User user, CommandSender sender) {

user.setOption(Option.TELEPORT_REQUEST_DISABLE, !user.getOption(Option.TELEPORT_REQUEST_DISABLE));
boolean isTeleportRequestDisable = user.getOption(Option.TELEPORT_REQUEST_DISABLE);

Message messageKey = isTeleportRequestDisable ? Message.COMMAND_TP_TOGGLE_DISABLE : Message.COMMAND_TP_TOGGLE_ENABLE;
message(sender, messageKey, "%player%", user == this.user ? Message.YOU.getMessageAsString() : player.getName());
}
}
12 changes: 12 additions & 0 deletions src/main/java/fr/maxlego08/essentials/user/ZUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ public void sendTeleportRequest(User targetUser) {
return;
}

// Check if target user has disabled teleport requests
if (targetUser.getOption(Option.TELEPORT_REQUEST_DISABLE)) {
message(this, Message.COMMAND_TELEPORT_REQUEST_DISABLED, targetUser);
return;
}

this.teleports.entrySet().removeIf(next -> !next.getValue().isValid());

if (this.teleports.containsKey(targetUser.getUniqueId())) {
Expand Down Expand Up @@ -181,6 +187,12 @@ public void sendTeleportHereRequest(User targetUser) {
return;
}

// Check if target user has disabled teleport requests
if (targetUser.getOption(Option.TELEPORT_REQUEST_DISABLE)) {
message(this, Message.COMMAND_TELEPORT_REQUEST_DISABLED, targetUser);
return;
}

this.teleports.entrySet().removeIf(next -> !next.getValue().isValid());

if (this.teleports.containsKey(targetUser.getUniqueId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ public void register(Placeholder placeholder, EssentialsPlugin plugin) {
return isPayDisabled ? economyManager.getPayTogglePlaceholderDisabled() : economyManager.getPayTogglePlaceholderEnabled();
}, "Returns the configured placeholder for the player's pay status");

// TpToggle
placeholder.register("user_is_tptoggle_disabled", (player) -> {
User user = iStorage.getUser(player.getUniqueId());
return user != null ? String.valueOf(user.getOption(Option.TELEPORT_REQUEST_DISABLE)) : "false";
}, "Returns true if the player has disabled teleport requests (tptoggle)");

// Vanish
placeholder.register("user_is_vanished", (player) -> {
User user = iStorage.getUser(player.getUniqueId());
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ blacklist-uuids:
# - PHANTOMS_DISABLE: Disables phantom spawning
# - WORLDEDIT_INVENTORY: Allows to use the player's inventory for WorldEdit
# - WORLDEDIT_BOSSBAR_DISABLE: Disables the WorldEdit bossbar
# - TELEPORT_REQUEST_DISABLE: Disables receiving teleport requests from other players
default-options:
- option: WORLDEDIT_INVENTORY
value: true
4 changes: 4 additions & 0 deletions src/main/resources/messages/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ command-back: "&7Returning to previous location."
command-back-error: "<error>You have no last location. Impossible to go back."
command-random-tp-error: "<error>No safe location found after multiple attempts, please try again."
command-random-tp-configuration-not-found: "<error>Impossible to find the random tp configuration for the world &f%world%<error>."
command-teleport-request-disabled: "<error>The player &f%player%<error> has disabled teleport requests."
command-tp-toggle-enable: "&7Teleport requests <success>enabled &7for &f%player%<success>."
command-tp-toggle-disable: "&7Teleport requests <error>disabled &7for &f%player%<error>."


# First join
Expand Down Expand Up @@ -379,6 +382,7 @@ description-chat-broadcast: "Broadcast a message"
description-message: "Send a private message to a player"
description-reply: "Reply to a private message"
description-message-toggle: "Toggle private message"
description-tp-toggle: "Toggle receiving teleport requests"
description-socialspy: "Display private messages of players"
description-furnace: "Smelt all the items in your hand"
description-skull: "Gets the head of a player"
Expand Down