Skip to content

Commit

Permalink
Update du rtp du /feed du /tpa (#83)
Browse files Browse the repository at this point in the history
Update du rtp du /feed du /tpa

Le /rtp n'est plus disponible si on n'est pas op mais il y a le rtp wand
(Il est dans https://discord.gg/aywen-communaute-1161296442577653802)

Ajout du /tpcancel
  • Loading branch information
Margouta authored Jul 7, 2024
2 parents 4f75e49 + 2474107 commit e89d4cb
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 92 deletions.
7 changes: 7 additions & 0 deletions src/main/java/fr/communaywen/core/AywenCraftPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import fr.communaywen.core.tpa.CommandTPA;
import fr.communaywen.core.tpa.CommandTpaccept;
import fr.communaywen.core.tpa.CommandTpcancel;
import fr.communaywen.core.tpa.CommandTpdeny;

import fr.communaywen.core.economy.EconomyManager;
Expand Down Expand Up @@ -119,6 +120,12 @@ public void onEnable() {
final @Nullable PluginCommand proutCommand = super.getCommand("prout");
if (proutCommand != null)
proutCommand.setExecutor(new ProutCommand());

this.getCommand("tpa").setExecutor(new CommandTPA());
this.getCommand("tpa").setTabCompleter(new CommandTPA());
this.getCommand("tpaccept").setExecutor(new CommandTpaccept());
this.getCommand("tpdeny").setExecutor(new CommandTpdeny());
this.getCommand("tpcancel").setExecutor(new CommandTpcancel());
/* -------- */

/* LISTENERS */
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/fr/communaywen/core/commands/FeedCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import java.util.UUID;

public class FeedCommand implements CommandExecutor {
private long COOLDOWN_TIME;
private final long COOLDOWN_TIME;
private final HashMap<UUID, Long> cooldowns = new HashMap<>();

public FeedCommand(@NotNull AywenCraftPlugin plugin) {
COOLDOWN_TIME = plugin.getConfig().getLong("feed.cooldown");
}
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
public boolean onCommand(final @NotNull CommandSender sender, final @NotNull Command command, final @NotNull String label, final String[] args) {
if (sender instanceof Player player) {
UUID playerId = player.getUniqueId();
long Time = System.currentTimeMillis() / 1000;
Expand All @@ -34,8 +34,10 @@ public boolean onCommand(final CommandSender sender, final Command command, fina
}
}
player.setFoodLevel(20);
player.sendMessage("Vous avez été nouris\uE032"); //émoji baguette
cooldowns.put(playerId, COOLDOWN_TIME);
player.setSaturation(5);
player.setExhaustion(0);
player.sendMessage("Vous avez été nouris \uE032"); //émoji baguette
cooldowns.put(playerId, Time);
return true;
}
return false;
Expand Down
53 changes: 21 additions & 32 deletions src/main/java/fr/communaywen/core/commands/RTPCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.entity.Player;

import fr.communaywen.core.AywenCraftPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
Expand All @@ -23,13 +24,14 @@ public class RTPCommand implements CommandExecutor {
private final int COOLDOWN_ERROR;
private final int MIN_X;
private final int MAX_X;
private int MIN_Y;
private int MAX_Y;
private final int MIN_Z;
private final int MAX_Z;
private int MAX_TRY;

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

private final HashMap<UUID, Location> loc = new HashMap<>();

public RTPCommand(AywenCraftPlugin plugin) {
this.plugin = plugin;

Expand All @@ -38,62 +40,49 @@ public RTPCommand(AywenCraftPlugin plugin) {
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");
if (MIN_Y <= -64 || MIN_Y >= 319){
plugin.getConfig().set("rtp.miny", 64);
MIN_Y = 64;
}
if (MAX_Y <= -64 || MAX_Y >= 319){
plugin.getConfig().set("rtp.maxy", 100);
MAX_Y = 100;
}
plugin.getConfig().options().copyDefaults(true);
plugin.saveConfig();
MAX_TRY = plugin.getConfig().getInt("rtp.max_try");

}

@SuppressWarnings("deprecation")
@Override
public boolean onCommand(@NotNull final CommandSender sender,@NotNull final Command command,@NotNull final String label, final String[] args) {
if (sender instanceof Player player) {
UUID playerId = player.getUniqueId();
long Time = System.currentTimeMillis() / 1000;
long ExactTime = System.currentTimeMillis();

if (cooldowns.containsKey(playerId)) {
long lastUsed = cooldowns.get(playerId);
long timeSinceLastUse = Time - 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);
int y = 0;
Location location = new Location(world, x, y, z);
if (!world.getBiome(location).equals(Biome.RIVER) || !world.getBiome(location).toString().contains("OCEAN")) {
y = world.getHighestBlockAt(x,z).getY();
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 + " "+(System.currentTimeMillis() / 1000 -Time)+"s");
cooldowns.put(playerId, Time);
return true;
for (int i=1; i<=MAX_TRY;i++) {
int x = (int) (Math.random() * (MAX_X - MIN_X) + MIN_X);
int z = (int) (Math.random() * (MAX_Z - MIN_Z) + MIN_Z);
if (!world.getBiome(new Location(world, x, 64, z)).equals(Biome.RIVER) || !world.getBiome(new Location(world, x, 64, z)).toString().contains("OCEAN")) {
int y = world.getHighestBlockAt(new Location(world, x, 64, z)).getY();
Location location = new Location(world, x, y+1, z);
if (new Location(world, x, y, z).getBlock().getType().isSolid()){
player.teleport(location);
player.sendMessage(" §aRTP réussi x: §f" + x + " §ay: §f" + y + " §az: §f" + z );
player.sendTitle(" §aRTP réussi", "x: " + x + " y: " + y + " z: " + z );
cooldowns.put(playerId, Time);
return true;
}
}
else {
if (i==3){
player.sendTitle(" §cErreur","/rtp");
cooldowns.put(playerId, Time - COOLDOWN_TIME + COOLDOWN_ERROR);
return true;
}
}
player.sendTitle(" §cErreur","/rtp");
cooldowns.put(playerId, Time - COOLDOWN_TIME + COOLDOWN_ERROR);
return true;
}

return true;
Expand Down
51 changes: 23 additions & 28 deletions src/main/java/fr/communaywen/core/listeners/RTPWand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class RTPWand implements Listener {
private int MAX_Y;
private int MIN_Z;
private int MAX_Z;
private int MAX_TRY;
private String RTP_WAND_NAME;

private final HashMap<UUID, Long> cooldowns = new HashMap<>();
Expand All @@ -43,62 +44,56 @@ public RTPWand(AywenCraftPlugin plugin) {
MIN_Z = plugin.getConfig().getInt("rtp.minz");
MAX_Z = plugin.getConfig().getInt("rtp.maxz");
RTP_WAND_NAME = plugin.getConfig().getString("rtp.rtp_wand");
if (MIN_Y <= -64 || MIN_Y >= 319){
plugin.getConfig().set("rtp.miny", 64);
MIN_Y = 64;
}
if (MAX_Y <= -64 || MAX_Y >= 319){
plugin.getConfig().set("rtp.maxy", 100);
MAX_Y = 100;
}
MAX_TRY = plugin.getConfig().getInt("rtp.max_try");
plugin.getConfig().options().copyDefaults(true);
plugin.saveConfig();

}

@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Player player = event.getPlayer();
ItemStack item = player.getItemInHand();
CustomStack customStack = CustomStack.byItemStack(item);
if (customStack != null && customStack.getNamespacedID().equals(RTP_WAND_NAME)) {
event.setCancelled(true);
event.setCancelled(true);
UUID playerId = player.getUniqueId();
long Time = System.currentTimeMillis() / 1000;
long ExactTime = System.currentTimeMillis();

if (cooldowns.containsKey(playerId)) {
long lastUsed = cooldowns.get(playerId);
long timeSinceLastUse = Time - 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;
return ;
}
}
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);
int y = 0;
Location location = new Location(world, x, y, z);
if (!world.getBiome(location).equals(Biome.RIVER) || !world.getBiome(location).toString().contains("OCEAN")) {
y = world.getHighestBlockAt(x,z).getY();
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 + " "+(System.currentTimeMillis() / 1000 -Time)+"s");
cooldowns.put(playerId, Time);
return;
for (int i=1; i<=MAX_TRY;i++) {
int x = (int) (Math.random() * (MAX_X - MIN_X) + MIN_X);
int z = (int) (Math.random() * (MAX_Z - MIN_Z) + MIN_Z);
if (!world.getBiome(new Location(world, x, 64, z)).equals(Biome.RIVER) || !world.getBiome(new Location(world, x, 64, z)).toString().contains("OCEAN")) {
int y = world.getHighestBlockAt(new Location(world, x, 64, z)).getY();
Location location = new Location(world, x, y+1, z);
if (new Location(world, x, y, z).getBlock().getType().isSolid()){
player.teleport(location);
player.sendMessage(" §aRTP réussi x: §f" + x + " §ay: §f" + y + " §az: §f" + z );
player.sendTitle(" §aRTP réussi", "x: " + x + " y: " + y + " z: " + z );
cooldowns.put(playerId, Time);
player.setCooldown(item.getType(),COOLDOWN_TIME*20);
return;
}
}
else {
player.sendTitle(" §cErreur","/rtp");
if (i==3){
player.sendTitle(" §cErreur","");
cooldowns.put(playerId, Time - COOLDOWN_TIME + COOLDOWN_ERROR);
return;
player.setCooldown(item.getType(),COOLDOWN_ERROR*20);
}
}
player.sendTitle(" §cErreur","/rtp");
cooldowns.put(playerId, Time - COOLDOWN_TIME + COOLDOWN_ERROR);
}
}
}
Expand Down
31 changes: 27 additions & 4 deletions src/main/java/fr/communaywen/core/tpa/CommandTPA.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package fr.communaywen.core.tpa;

import fr.communaywen.core.AywenCraftPlugin;
import fr.communaywen.core.teams.Team;
import fr.communaywen.core.teams.TeamManager;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;

public class CommandTPA implements CommandExecutor {
// This method is called, when somebody uses our command
import net.md_5.bungee.api.ChatColor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

public class CommandTPA implements CommandExecutor, TabCompleter {

TPAQueue tpQueue = TPAQueue.INSTANCE;

Expand All @@ -22,15 +32,28 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
Player player = (Player) sender;
Player receiver = Bukkit.getPlayerExact(args[0]);
if (receiver == null) {
player.sendMessage("Impossible de trouver le joeur \""+args[0]+"\"");
player.sendMessage("Impossible de trouver le joueur «"+args[0]+"»");
return false;
}
tpQueue.TPA_REQUESTS.put(receiver, new TPARequest(player));
tpQueue.TPA_REQUESTS.put(receiver, player);
tpQueue.TPA_REQUESTS2.put(player, receiver);
player.sendMessage("Vous avez envoyé une demande de tpa à " + receiver.getName());
receiver.sendMessage(player.getName() + " vous a envoyé un demande de téléportation faites /tpaccept pour l'accepter");
return true;
}

return false;
}

@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
List<String> list = new ArrayList<String>();
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.getName().startsWith(strings[0])){
list.add(p.getName());
}
}
return list;
}
}
19 changes: 13 additions & 6 deletions src/main/java/fr/communaywen/core/tpa/CommandTpaccept.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package fr.communaywen.core.tpa;

import fr.communaywen.core.AywenCraftPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import net.md_5.bungee.api.ChatColor;
import org.bukkit.scheduler.BukkitRunnable;

public class CommandTpaccept implements CommandExecutor {
TPAQueue tpQueue = TPAQueue.INSTANCE;
Expand All @@ -16,15 +18,20 @@ public class CommandTpaccept implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
TPARequest tpRequest = tpQueue.TPA_REQUESTS.get(player);
if (tpRequest == null) {
Player tpaplayer = tpQueue.TPA_REQUESTS.get(player);
if (tpaplayer == null) {
player.sendMessage(ChatColor.RED + "Vous n'avez pas de demande de téléporation");
return true;
}
player.sendMessage(tpRequest.requeste.getName()+" va être téléporté à vous");
tpRequest.requeste.sendTitle("Téléportation à "+player.getName()+" dans ...",null,0,20,10);
tpRequest.requeste.teleport(player);
tpQueue.TPA_REQUESTS.remove(player);
player.sendMessage(tpaplayer.getName()+" va être téléporté à vous dans 3 secondes");
tpaplayer.sendTitle("Téléportation à "+player.getName()," dans 3 secondes...",0,20,40);
new BukkitRunnable() {
@Override
public void run() {
tpaplayer.teleport(player);
tpQueue.TPA_REQUESTS.remove(player);
}
}.runTaskLater(AywenCraftPlugin.getInstance(),60);
return true;
}
return false;
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/fr/communaywen/core/tpa/CommandTpcancel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fr.communaywen.core.tpa;

import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class CommandTpcancel implements CommandExecutor {

TPAQueue tpQueue = TPAQueue.INSTANCE;

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
Player tpaplayer = tpQueue.TPA_REQUESTS2.get(player);
if (tpaplayer == null) {
player.sendMessage(ChatColor.RED + "Vous n'avez pas de demande de téléporation");
return true;
}
player.sendMessage(ChatColor.RED + player.getName() + " a refusé votre demande de téléportation");
tpQueue.TPA_REQUESTS.remove(tpaplayer);
tpQueue.TPA_REQUESTS2.remove(player);
return true;
}

return false;
}
}
8 changes: 5 additions & 3 deletions src/main/java/fr/communaywen/core/tpa/CommandTpdeny.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ public class CommandTpdeny implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
TPARequest tpRequest = tpQueue.TPA_REQUESTS.get(player);
if (tpRequest == null) {
Player tpaplayer = tpQueue.TPA_REQUESTS.get(player);
if (tpaplayer == null) {
player.sendMessage(ChatColor.RED + "Vous n'avez pas de demande de téléporation");
return true;
}
tpRequest.requeste.sendMessage(ChatColor.RED + player.getName() + " a refusé votre demande de téléportation");
tpQueue.TPA_REQUESTS.remove(player);
tpQueue.TPA_REQUESTS2.remove(tpaplayer);
tpaplayer.sendMessage(ChatColor.RED + player.getName() + " a refusé votre demande de téléportation");
player.sendMessage("Vous avez refusé la demande de téléporation de "+tpaplayer.getName());
return true;
}

Expand Down
Loading

0 comments on commit e89d4cb

Please sign in to comment.