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
32 changes: 32 additions & 0 deletions API/src/main/java/fr/maxlego08/essentials/api/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fr.maxlego08.essentials.api.chat.ChatCooldown;
import fr.maxlego08.essentials.api.commands.CommandCooldown;
import fr.maxlego08.essentials.api.commands.CommandRestriction;
import fr.maxlego08.essentials.api.config.models.NearDirectionReplacements;
import fr.maxlego08.essentials.api.configuration.ReplacePlaceholder;
import fr.maxlego08.essentials.api.server.RedisConfiguration;
import fr.maxlego08.essentials.api.server.ServerType;
Expand Down Expand Up @@ -151,6 +152,15 @@ public interface Configuration extends ConfigurationFile {
*/
List<NearDistance> getNearPermissions();

/**
* Returns the set of directional replacements (arrows or labels) used to display
* the relative position of nearby players.
*
* @return a {@link NearDirectionReplacements} instance containing direction symbols
* @since 1.0.3.2
*/
NearDirectionReplacements getNearDirectionReplacements();

/**
* Retrieves the near distance allowed for a specific permissible entity.
*
Expand All @@ -159,6 +169,28 @@ public interface Configuration extends ConfigurationFile {
*/
double getNearDistance(Permissible permissible);

/**
* Returns the world time value used by the /day command.
*
* @return the configured day time value
*/
long getDayTime();

/**
* Returns the world time value used by the /night command.
*
* @return the configured night time value
*/
long getNightTime();

/**
* Indicates whether world time changes should be animated
* (e.g. /day, /night commands).
*
* @return {@code true} if smooth world time changes are enabled
*/
boolean isTimeSmoothChangeEnabled();

/**
* Checks if command logging is enabled.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public enum Permission {
ESSENTIALS_VANISH_OTHER,
ESSENTIALS_VANISH_SEE,
ESSENTIALS_HEAL,
ESSENTIALS_HEAL_ALL("Allows to heal another player"),
ESSENTIALS_HEAL_OTHER("Allows to heal all players on the server"),
ESSENTIALS_LIGHTING,
ESSENTIALS_LIGHTING_ALL("Allows to strike another player with lightning"),
ESSENTIALS_LIGHTING_OTHER("Allows to strike all players on the server with lightning"),
ESSENTIALS_SPEED,
ESSENTIALS_WALK_SPEED,
ESSENTIALS_FLY_SPEED,
Expand All @@ -44,10 +49,11 @@ public enum Permission {
ESSENTIALS_TP_WORLD_OTHER("Allows to teleport another player into a world"),
ESSENTIALS_TRASH,
ESSENTIALS_FEED,
ESSENTIALS_FEED_OTHER("Allows to feed another player"),
ESSENTIALS_FEED_ALL("Allows to feed all players on the server"),
ESSENTIALS_INVSEE,
ESSENTIALS_INVSEE_OFFLINE("Allows to listen to the inventory of an offline player"),
ESSENTIALS_FEED_OTHER("Allows to feed another player"),
ESSENTIALS_HEAL_OTHER("Allows to heal another player"),
ESSENTIALS_EXT_OTHER("Allows to feed another player"),
ESSENTIALS_CRAFT,
ESSENTIALS_ENCHANTING,
ESSENTIALS_INVSEE_INTERACT("Allows to interact with a player’s inventory"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package fr.maxlego08.essentials.api.config.models;

public record NearDirectionReplacements(
String forwardReplacement,
String forwardRightReplacement,
String rightReplacement,
String backRightReplacement,
String backReplacement,
String backLeftReplacement,
String leftReplacement,
String forwardLeftReplacement
) {
public static final NearDirectionReplacements DEFAULT = new NearDirectionReplacements(
"↑",
"↗",
"→",
"↘",
"↓",
"↙",
"←",
"↖"
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public enum Message {
COMMAND_ESSENTIALS("zEssentials, version %version%"),
COMMAND_GAMEMODE("&fSet game mode&e %gamemode% &ffor &b%player%&f."),
COMMAND_GAMEMODE_INVALID("<error>You need to specify a valid player."),
COMMAND_TIME_ERROR("<error>You need to specify a world."),
COMMAND_TIME_ALREADY_CHANGING("<error>Time is already changing in &f%world%<error>."),
COMMAND_DAY("&fYou have just brought &edaylight&f into the world <success>%world%&f."),
COMMAND_NIGHT("&fYou have just brought &enightfall&f into the world <success>%world%&f."),
COMMAND_SUN("&fYou have just brought the &esun&f into the world <success>%world%&f."),
Expand Down Expand Up @@ -85,9 +87,19 @@ public enum Message {
COMMAND_NIGHT_VISION_DISABLE("&7Night vision <error>disable &7for &f%player%<success>."),
COMMAND_PHANTOMS_ENABLE("&7Phantom spawning <success>enable &7for &f%player%<success>."),
COMMAND_PHANTOMS_DISABLE("&7Phantom spawning <error>disable &7for &f%player%<error>."),
COMMAND_EXT_SENDER("&7You just extinguished the player &f%player%&7."),
COMMAND_EXT_RECEIVER("<success>You are no longer burning."),
COMMAND_EXT_ERROR("<error>You cannot extinguish someone who is dead!"),
COMMAND_HEAL_ALL("&7You just healed all players on the server."),
COMMAND_HEAL_SENDER("&7You just healed the player &f%player%&7."),
COMMAND_HEAL_RECEIVER("<success>You have been healed."),
COMMAND_HEAL_ERROR("<error>You cannot heal someone who is dead !"),
COMMAND_LIGHTING_ALL("&7You just struck all players with lightning."),
COMMAND_LIGHTING("&7You just summoned lightning at the targeted location."),
COMMAND_LIGHTING_SENDER("&7You just summoned lightning at the location of &f%player%&7."),
COMMAND_LIGHTING_RECEIVER("&cYou have been struck by lightning."),
COMMAND_LIGHTING_ERROR("<error>You cannot strike a dead player with lightning!"),
COMMAND_FEED_ALL("&7You just feed all players on the server."),
COMMAND_FEED_SENDER("&7You just feed the player &f%player%&7."),
COMMAND_FEED_RECEIVER("<success>You have been feed."),
COMMAND_FEED_ERROR("<error>You cannot feed someone who is dead !"),
Expand Down Expand Up @@ -183,6 +195,7 @@ public enum Message {
DESCRIPTION_FLY_REMOVE("Removed the fly time"),
DESCRIPTION_FLY_SET("Set the fly time"),
DESCRIPTION_HEAL("Heal a player"),
DESCRIPTION_LIGHTING("Strike a player with lightning"),
DESCRIPTION_AFK("Toggle your AFK status"),
DESCRIPTION_SUN("Set the sun in your world"),
DESCRIPTION_ENDERCHEST("Open your enderchest"),
Expand Down Expand Up @@ -680,11 +693,10 @@ public enum Message {
COMMAND_REPAIR_SUCCESS("<success>You just fixed the item in your hand."),
COMMAND_REPAIR_ALL_ERROR("<error>You have no items to repair."),
COMMAND_REPAIR_ALL_SUCCESS("<success>You have just repaired all the items in your inventory"),
COMMAND_EXT("&fBy the will of Maxlego08, you no longer burn."),

COMMAND_NEAR_EMPTY("<error>No player near to you."),
COMMAND_NEAR_PLAYER("&fPlayers near to you&7:%players%"),
COMMAND_NEAR_INFO(" &7%player% &8(&e%distance%m&8)"),
COMMAND_NEAR_INFO("<newline>&6%direction% &7%player% &8(&e%distance%m&8)"),
COMMAND_PLAY_TIME(
"&7You played&8: <primary>%playtime%",
"&7Current session&8: <primary>%playtime_session%"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import fr.maxlego08.essentials.api.user.User;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -37,6 +38,18 @@ public interface EssentialsServer {
*/
List<String> getPlayersNames();

/**
* Gets the list of names of all online players
* that are visible to the given command sender.
*
* <p>Player visibility may depend on permissions,
* vanish state, or other server-side rules.</p>
*
* @param sender the command sender for whom player visibility is evaluated
* @return a list of visible online player names
*/
List<String> getVisiblePlayerNames(@NotNull CommandSender sender);

/**
* Sends a message to a player with the given UUID.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.jetbrains.annotations.NotNull;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
Expand Down Expand Up @@ -115,6 +116,11 @@ public List<String> getPlayersNames() {
return new ArrayList<>(this.playerCache.getPlayers());
}

@Override
public List<String> getVisiblePlayerNames(@NotNull CommandSender sender) {
return getPlayersNames(); // ToDO: think about the way to implement visible players filtering
}

@Override
public List<String> getOfflinePlayersNames() {
return this.plugin.getConfiguration().isEnableOfflinePlayersName() ? Arrays.stream(Bukkit.getOfflinePlayers()).map(OfflinePlayer::getName).toList() : getPlayersNames();
Expand Down
59 changes: 48 additions & 11 deletions src/main/java/fr/maxlego08/essentials/MainConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fr.maxlego08.essentials.api.chat.ChatCooldown;
import fr.maxlego08.essentials.api.commands.CommandCooldown;
import fr.maxlego08.essentials.api.commands.CommandRestriction;
import fr.maxlego08.essentials.api.config.models.NearDirectionReplacements;
import fr.maxlego08.essentials.api.configuration.NonLoadable;
import fr.maxlego08.essentials.api.configuration.ReplacePlaceholder;
import fr.maxlego08.essentials.api.configuration.ReplacePlaceholderElement;
Expand All @@ -23,16 +24,12 @@
import fr.maxlego08.sarah.database.DatabaseType;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.permissions.Permissible;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
import java.util.stream.LongStream;

public class MainConfiguration extends YamlLoader implements Configuration {
Expand All @@ -44,7 +41,13 @@ public class MainConfiguration extends YamlLoader implements Configuration {
private final StorageType storageType = StorageType.JSON;
private final List<MessageColor> messageColors = new ArrayList<>();
private final List<ChatCooldown> cooldowns = new ArrayList<>();
private double nearDistance;
@NonLoadable
private NearDirectionReplacements nearDirectionReplacements = NearDirectionReplacements.DEFAULT;
private final List<NearDistance> nearPermissions = new ArrayList<>();
private long dayTime = 1000;
private long nightTime = 13000;
private boolean timeSmoothChange = false;
private final List<String> disableFlyWorld = new ArrayList<>();
private final List<String> disableBackWorld = new ArrayList<>();
@NonLoadable
Expand All @@ -61,7 +64,6 @@ public class MainConfiguration extends YamlLoader implements Configuration {
private DatabaseConfiguration databaseConfiguration;
private ServerType serverType;
private RedisConfiguration redisConfiguration;
private double nearDistance;
private SimpleDateFormat simpleDateFormat;
private List<ReplacePlaceholder> replacePlaceholders = new ArrayList<>();
private List<String> randomWords;
Expand Down Expand Up @@ -155,6 +157,21 @@ public void load() {
configuration.getBoolean("database-configuration.debug"),
DatabaseType.MYSQL
);

final ConfigurationSection nearDirSection = configuration.getConfigurationSection("near-direction-replacements");
if (nearDirSection != null) {
this.nearDirectionReplacements = new NearDirectionReplacements(
configuration.getString("forward", "↑"),
configuration.getString("forward-right", "↗"),
configuration.getString("right", "→"),
configuration.getString("back-right", "↘"),
configuration.getString("back", "↓"),
configuration.getString("back-left", "↙"),
configuration.getString("left", "←"),
configuration.getString("forward-left", "↖")
);
}

this.cooldownCommands = this.cooldowns.stream().flatMapToLong(cooldown -> LongStream.of(cooldown.cooldown(), cooldown.messages())).toArray();
this.simpleDateFormat = this.globalDateFormat == null ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") : new SimpleDateFormat(this.globalDateFormat);
this.flyTaskAnnounce = configuration.getLongList("fly-task-announce");
Expand Down Expand Up @@ -261,20 +278,40 @@ public List<TransformMaterial> getSmeltableMaterials() {
}

@Override
public List<NearDistance> getNearPermissions() {
return nearPermissions;
public double getDefaultNearDistance() {
return nearDistance;
}

@Override
public double getDefaultNearDistance() {
return nearDistance;
public NearDirectionReplacements getNearDirectionReplacements() {
return this.nearDirectionReplacements;
}

@Override
public double getNearDistance(Permissible permissible) {
return this.nearPermissions.stream().filter(nearDistance -> permissible.hasPermission(nearDistance.permission())).map(NearDistance::distance).findFirst().orElse(this.nearDistance);
}

@Override
public List<NearDistance> getNearPermissions() {
return nearPermissions;
}

@Override
public long getDayTime() {
return this.dayTime;
}

@Override
public long getNightTime() {
return this.nightTime;
}

@Override
public boolean isTimeSmoothChangeEnabled() {
return this.timeSmoothChange;
}

@Override
public boolean isEnableCommandLog() {
return this.enableCommandLog;
Expand Down
23 changes: 2 additions & 21 deletions src/main/java/fr/maxlego08/essentials/commands/CommandLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,8 @@
import fr.maxlego08.essentials.commands.commands.teleport.CommandTeleportToHere;
import fr.maxlego08.essentials.commands.commands.teleport.CommandTeleportWorld;
import fr.maxlego08.essentials.commands.commands.teleport.CommandTop;
import fr.maxlego08.essentials.commands.commands.utils.CommandAfk;
import fr.maxlego08.essentials.commands.commands.utils.CommandCompact;
import fr.maxlego08.essentials.commands.commands.utils.CommandCompactAll;
import fr.maxlego08.essentials.commands.commands.utils.CommandCraft;
import fr.maxlego08.essentials.commands.commands.utils.CommandExt;
import fr.maxlego08.essentials.commands.commands.utils.CommandFeed;
import fr.maxlego08.essentials.commands.commands.utils.CommandFurnace;
import fr.maxlego08.essentials.commands.commands.utils.CommandHat;
import fr.maxlego08.essentials.commands.commands.utils.CommandHeal;
import fr.maxlego08.essentials.commands.commands.utils.CommandMore;
import fr.maxlego08.essentials.commands.commands.utils.CommandNear;
import fr.maxlego08.essentials.commands.commands.utils.CommandNightVision;
import fr.maxlego08.essentials.commands.commands.utils.CommandPhantoms;
import fr.maxlego08.essentials.commands.commands.utils.CommandPlayTime;
import fr.maxlego08.essentials.commands.commands.utils.CommandRepair;
import fr.maxlego08.essentials.commands.commands.utils.CommandRepairAll;
import fr.maxlego08.essentials.commands.commands.utils.CommandRules;
import fr.maxlego08.essentials.commands.commands.utils.*;
import fr.maxlego08.essentials.commands.commands.utils.lag.CommandLag;
import fr.maxlego08.essentials.commands.commands.utils.CommandSudo;
import fr.maxlego08.essentials.commands.commands.utils.CommandSuicide;
import fr.maxlego08.essentials.commands.commands.utils.CommandTrash;
import fr.maxlego08.essentials.commands.commands.utils.CommandVersion;
import fr.maxlego08.essentials.commands.commands.utils.admins.CommandEnchant;
import fr.maxlego08.essentials.commands.commands.utils.admins.CommandFlySpeed;
import fr.maxlego08.essentials.commands.commands.utils.admins.CommandGod;
Expand Down Expand Up @@ -173,6 +153,7 @@ public void loadCommands(CommandManager commandManager) {
register("god", CommandGod.class);
register("vanish", CommandVanish.class, "v");
register("heal", CommandHeal.class);
register("lightning", CommandLightning.class, "strike");
register("more", CommandMore.class);
register("worldtp", CommandTeleportWorld.class, "wtp");
register("trash", CommandTrash.class, "poubelle");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public class CommandTeleportRandomOther extends VCommand {

public CommandTeleportRandomOther(EssentialsPlugin plugin) {
super(plugin);
this.setModule(TeleportationModule.class);
this.setPermission(Permission.ESSENTIALS_TP_RANDOM_OTHER);
this.setDescription(Message.DESCRIPTION_TP_RANDOM_OTHER);
this.addSubCommand("other");
this.addRequireArg("player", getOnlinePlayers());
this.addRequireArg("world", (a, b) -> Bukkit.getWorlds().stream().map(WorldInfo::getName).toList());
super.setModule(TeleportationModule.class);
super.setPermission(Permission.ESSENTIALS_TP_RANDOM_OTHER);
super.setDescription(Message.DESCRIPTION_TP_RANDOM_OTHER);
super.addSubCommand("other");
super.addRequirePlayerNameArg();
super.addRequireArg("world", (a, b) -> Bukkit.getWorlds().stream().map(WorldInfo::getName).toList());
}

@Override
Expand Down
Loading