From 8ca8006558ae16fa68c52cbf8c82be10df588a46 Mon Sep 17 00:00:00 2001 From: misieur <153451816+misieur@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:07:10 +0200 Subject: [PATCH 1/3] 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 8d9f97cd..5cfb98d8 100644 --- a/src/main/java/fr/communaywen/core/AywenCraftPlugin.java +++ b/src/main/java/fr/communaywen/core/AywenCraftPlugin.java @@ -8,6 +8,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; @@ -60,6 +61,10 @@ public void onEnable() { teamCommand.setExecutor(new TeamCommand()); teamCommand.setTabCompleter(new TeamCommand()); + getServer().getPluginManager().registerEvents(new AntiTrampling(),this); + this.getCommand("rtp").setExecutor(new RTPCommand()); + saveDefaultConfig(); + final @Nullable PluginCommand proutCommand = super.getCommand("prout"); if (proutCommand != null) proutCommand.setExecutor(new ProutCommand()); From 7586b2f6549b9f8f21c465d6a66a0d00e94a1b59 Mon Sep 17 00:00:00 2001 From: misieur <153451816+misieur@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:21:06 +0200 Subject: [PATCH 2/3] Create RTPCommand.java --- .../communaywen/core/commands/RTPCommand.java | 79 +++++++++++++++++++ 1 file changed, 79 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..9820cf7f --- /dev/null +++ b/src/main/java/fr/communaywen/core/commands/RTPCommand.java @@ -0,0 +1,79 @@ +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 { + + + //Merci à ri1ongithub pour le système de cooldown que j'avais la flème de refaire + //Je n'ai pas fait de test mais normalement il y a pas de bug (j'ai quand même testé si l'aléatoir marchait) + + + private final HashMap cooldowns = new HashMap<>(); + private static final int COOLDOWN_TIME = AywenCraftPlugin.getInstance().getConfig().getInt("rtp.cooldown"); //temps en secondes + private static final int COOLDOWN_TIME_ERROR = AywenCraftPlugin.getInstance().getConfig().getInt("rtp.cooldownerror"); //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 = AywenCraftPlugin.getInstance().getConfig().getInt("rtp.minx") ; + int maxx = AywenCraftPlugin.getInstance().getConfig().getInt("rtp.maxx") ; + int minz = AywenCraftPlugin.getInstance().getConfig().getInt("rtp.minz") ; + int maxz = AywenCraftPlugin.getInstance().getConfig().getInt("rtp.maxz") ; + int miny = AywenCraftPlugin.getInstance().getConfig().getInt("rtp.miny") ; + int maxy = AywenCraftPlugin.getInstance().getConfig().getInt("rtp.maxy") ; + 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 13:22:19 +0200 Subject: [PATCH 3/3] Create config.yml --- src/main/resources/config.yml | 10 ++++++++++ 1 file changed, 10 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..8101c4b8 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,10 @@ +rtp: + cooldown: 60 + cooldownerror: 5 + minx: -3000 + maxx: 3000 + miny: 64 + maxy: 100 + minz: -3000 + maxz: 3000 +