From 4c8d153f1c6ba2431ea48532e28852dad0c551c3 Mon Sep 17 00:00:00 2001 From: misieur <153451816+misieur@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:32:38 +0200 Subject: [PATCH 1/5] Update AywenCraftPlugin.java --- src/main/java/fr/communaywen/core/AywenCraftPlugin.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/fr/communaywen/core/AywenCraftPlugin.java b/src/main/java/fr/communaywen/core/AywenCraftPlugin.java index a1edaddf..0abe38e3 100644 --- a/src/main/java/fr/communaywen/core/AywenCraftPlugin.java +++ b/src/main/java/fr/communaywen/core/AywenCraftPlugin.java @@ -10,6 +10,7 @@ import fr.communaywen.core.utils.MOTDChanger; import fr.communaywen.core.commands.VersionCommand; import fr.communaywen.core.utils.PermissionCategory; +import fr.communaywen.core.commands.RTPCommand; import org.bukkit.command.PluginCommand; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -65,6 +66,10 @@ public void onEnable() { final @Nullable PluginCommand proutCommand = super.getCommand("prout"); if (proutCommand != null) proutCommand.setExecutor(new ProutCommand()); + + this.getCommand("rtp").setExecutor(new RTPCommand(this)); + getServer().getPluginManager().registerEvents(new AntiTrampling(),this); + saveDefaultConfig(); } @Override From 8a9215dc5875e6ac1309fa43846c7c6d5c196491 Mon Sep 17 00:00:00 2001 From: misieur <153451816+misieur@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:33:05 +0200 Subject: [PATCH 2/5] Create RTPCommand.java --- .../communaywen/core/commands/RTPCommand.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/main/java/fr/communaywen/core/commands/RTPCommand.java diff --git a/src/main/java/fr/communaywen/core/commands/RTPCommand.java b/src/main/java/fr/communaywen/core/commands/RTPCommand.java new file mode 100644 index 00000000..84fa3add --- /dev/null +++ b/src/main/java/fr/communaywen/core/commands/RTPCommand.java @@ -0,0 +1,85 @@ +package fr.communaywen.core.commands; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.Team; +import org.bukkit.util.Vector; + +import java.util.HashMap; +import java.util.UUID; + +public class RTPCommand implements CommandExecutor { + + + + + private final Configs plugin; + public RTPCommand(Congis plugin){ + this.plugin = plugin; + } + + + //Merci à ri1ongithub pour le système de cooldown que j'avais la flème de refaire + private final HashMap cooldowns = new HashMap<>(); + private static final int COOLDOWN = this.plugin.getConfig().getint("rtp.cooldown"); //temps en secondes + private static final int COOLDOWN_ERROR = this.plugin.getConfig().getint("rtp.cooldown-error"); //temps en secondes + + + + + @Override + public boolean onCommand(final CommandSender sender,final Command command,final String label,final String[] args) { + if (sender instanceof Player player) { + UUID playerId = player.getUniqueId(); + long currentTime = System.currentTimeMillis() / 1000; + + if (cooldowns.containsKey(playerId)) { + long lastUsed = cooldowns.get(playerId); + long timeSinceLastUse = currentTime - lastUsed; + + if (timeSinceLastUse < COOLDOWN_TIME) { + long timeLeft = COOLDOWN_TIME - timeSinceLastUse; + player.sendMessage("Vous devez attendre encore " + timeLeft + " secondes avant d'utiliser cette commande à nouveau."); + return true; + } + } + int minx = this.plugin.getConfig().getint("rtp.minx"); + int maxx = this.plugin.getConfig().getint("rtp.maxx"); + int miny = this.plugin.getConfig().getint("rtp.miny"); + int maxy = this.plugin.getConfig().getint("rtp.maxy"); + int minz = this.plugin.getConfig().getint("rtp.minz"); + int maxz = this.plugin.getConfig().getint("rtp.maxz"); + int x = (int) ((Math.random() * (maxx - minx)) + minx); + int z = (int) ((Math.random() * (maxz - minz)) + minz); + World world = player.getWorld(); + Location location,belowlocation; + for (int y = miny; y Date: Fri, 5 Jul 2024 14:33:28 +0200 Subject: [PATCH 3/5] Create config.yml --- src/main/resources/config.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/resources/config.yml diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 00000000..267dabe0 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,9 @@ +rtp: + cooldown: 60 + cooldown-error: 5 + minx: -3000 + maxx: 3000 + miny: -3000 + maxy: 3000 + minz: -3000 + maxz: 3000 From 0c9bf9bb3a4b6bf2d1ad2edab83d2a4ca81a2edb Mon Sep 17 00:00:00 2001 From: misieur <153451816+misieur@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:58:09 +0200 Subject: [PATCH 4/5] Update RTPCommand.java --- .../communaywen/core/commands/RTPCommand.java | 93 ++++++++++--------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/src/main/java/fr/communaywen/core/commands/RTPCommand.java b/src/main/java/fr/communaywen/core/commands/RTPCommand.java index 84fa3add..053b7eb6 100644 --- a/src/main/java/fr/communaywen/core/commands/RTPCommand.java +++ b/src/main/java/fr/communaywen/core/commands/RTPCommand.java @@ -2,43 +2,49 @@ import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.Particle; -import org.bukkit.Sound; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; -import org.bukkit.util.Vector; + +import fr.misieur.AywenCraftPlugin.AywenCraftPlugin; import java.util.HashMap; import java.util.UUID; public class RTPCommand implements CommandExecutor { - - - - private final Configs plugin; - public RTPCommand(Congis plugin){ - this.plugin = plugin; - } + private final AywenCraftPlugin plugin; + // Configuration values + private final int COOLDOWN_TIME; + private final int COOLDOWN_ERROR; + private final int MIN_X; + private final int MAX_X; + private final int MIN_Y; + private final int MAX_Y; + private final int MIN_Z; + private final int MAX_Z; - //Merci à ri1ongithub pour le système de cooldown que j'avais la flème de refaire private final HashMap cooldowns = new HashMap<>(); - private static final int COOLDOWN = this.plugin.getConfig().getint("rtp.cooldown"); //temps en secondes - private static final int COOLDOWN_ERROR = this.plugin.getConfig().getint("rtp.cooldown-error"); //temps en secondes - - - - - @Override - public boolean onCommand(final CommandSender sender,final Command command,final String label,final String[] args) { + + public RTPCommand(AywenCraftPlugin plugin) { + this.plugin = plugin; + + // Load configuration values + COOLDOWN_TIME = plugin.getConfig().getInt("rtp.cooldown"); + COOLDOWN_ERROR = plugin.getConfig().getInt("rtp.cooldown-error"); + MIN_X = plugin.getConfig().getInt("rtp.minx"); + MAX_X = plugin.getConfig().getInt("rtp.maxx"); + MIN_Y = plugin.getConfig().getInt("rtp.miny"); + MAX_Y = plugin.getConfig().getInt("rtp.maxy"); + MIN_Z = plugin.getConfig().getInt("rtp.minz"); + MAX_Z = plugin.getConfig().getInt("rtp.maxz"); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { if (sender instanceof Player player) { UUID playerId = player.getUniqueId(); long currentTime = System.currentTimeMillis() / 1000; @@ -53,33 +59,28 @@ public boolean onCommand(final CommandSender sender,final Command command,final return true; } } - int minx = this.plugin.getConfig().getint("rtp.minx"); - int maxx = this.plugin.getConfig().getint("rtp.maxx"); - int miny = this.plugin.getConfig().getint("rtp.miny"); - int maxy = this.plugin.getConfig().getint("rtp.maxy"); - int minz = this.plugin.getConfig().getint("rtp.minz"); - int maxz = this.plugin.getConfig().getint("rtp.maxz"); - int x = (int) ((Math.random() * (maxx - minx)) + minx); - int z = (int) ((Math.random() * (maxz - minz)) + minz); + World world = player.getWorld(); - Location location,belowlocation; - for (int y = miny; y Date: Fri, 5 Jul 2024 14:59:22 +0200 Subject: [PATCH 5/5] Update RTPCommand.java --- src/main/java/fr/communaywen/core/commands/RTPCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/communaywen/core/commands/RTPCommand.java b/src/main/java/fr/communaywen/core/commands/RTPCommand.java index 053b7eb6..044dce42 100644 --- a/src/main/java/fr/communaywen/core/commands/RTPCommand.java +++ b/src/main/java/fr/communaywen/core/commands/RTPCommand.java @@ -70,13 +70,13 @@ public boolean onCommand(final CommandSender sender, final Command command, fina if (location.getBlock().getType().isAir() && belowLocation.getBlock().getType().isSolid()) { player.teleport(location); - player.sendTitle("§aRTP réussi", "x: " + x + " y: " + y + " z: " + z); + player.sendTitle(" §aRTP réussi", "x: " + x + " y: " + y + " z: " + z); cooldowns.put(playerId, currentTime); return true; } } - player.sendTitle("§cErreur", null); + player.sendTitle(" §cErreur","/rtp)); cooldowns.put(playerId, currentTime - COOLDOWN_TIME + COOLDOWN_ERROR); return true; }