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

le RTP + la config #41

Closed
wants to merge 5 commits into from
Closed
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
5 changes: 5 additions & 0 deletions src/main/java/fr/communaywen/core/AywenCraftPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
86 changes: 86 additions & 0 deletions src/main/java/fr/communaywen/core/commands/RTPCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package fr.communaywen.core.commands;

import org.bukkit.Bukkit;
import org.bukkit.Location;
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 fr.misieur.AywenCraftPlugin.AywenCraftPlugin;

import java.util.HashMap;
import java.util.UUID;

public class RTPCommand implements CommandExecutor {

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;

private final HashMap<UUID, Long> cooldowns = new HashMap<>();

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;

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;
}
}

World world = player.getWorld();
int x = (int) (Math.random() * (MAX_X - MIN_X) + MIN_X);
int z = (int) (Math.random() * (MAX_Z - MIN_Z) + MIN_Z);

for (int y = MIN_Y; y <= MAX_Y; y++) {
Location location = new Location(world, x, y, z);
Location belowLocation = new Location(world, x, y - 1, z);

if (location.getBlock().getType().isAir() && belowLocation.getBlock().getType().isSolid()) {
player.teleport(location);
player.sendTitle(" §aRTP réussi", "x: " + x + " y: " + y + " z: " + z);
cooldowns.put(playerId, currentTime);
return true;
}
}

player.sendTitle(" §cErreur","/rtp));
cooldowns.put(playerId, currentTime - COOLDOWN_TIME + COOLDOWN_ERROR);
return true;
}

return true;
}
}
9 changes: 9 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rtp:
cooldown: 60
cooldown-error: 5
minx: -3000
maxx: 3000
miny: -3000
maxy: 3000
minz: -3000
maxz: 3000
Loading