Skip to content

Commit

Permalink
Là normalement c'est bon (#36)
Browse files Browse the repository at this point in the history
*Avez vous lu le [Code de
Conduite](https://github.com/Margouta/PluginOpenMC/blob/main/CODE_OF_CONDUCT.md)?*

## Decrivez vos changements
*Clairement et avec des screenshots si nécessaires*
  • Loading branch information
Margouta authored Jul 5, 2024
2 parents 9da4c1d + a523df6 commit 6766cad
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
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 @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
79 changes: 79 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,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<UUID, Long> 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<maxy;y++) {
location = new Location(world,x,y,z);
if (location.getBlock().getType().isAir()) {
belowlocation = new Location(world,x,y-1,z);
if (belowlocation.getBlock().getType().isBlock()) {
player.teleport(location);
player.sendTitle("§aRTP réussi","x: "+x+" y: "+y+" z: "+z);
cooldowns.put(playerId, currentTime);
return true;
}
}
}
player.sendTitle(" §cErreur",null);
cooldowns.put(playerId, currentTime-COOLDOWN_TIME+COOLDOWN_TIME_ERROR);
return true;

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

0 comments on commit 6766cad

Please sign in to comment.