From 61f1952ecb082e7ee272d992420ad47aa92913a6 Mon Sep 17 00:00:00 2001 From: misieur Date: Sat, 6 Jul 2024 18:49:23 +0200 Subject: [PATCH 1/3] Merge remote-tracking branch 'origin/main' --- src/main/java/fr/communaywen/core/commands/FeedCommand.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/fr/communaywen/core/commands/FeedCommand.java b/src/main/java/fr/communaywen/core/commands/FeedCommand.java index c114c387..66600d0c 100644 --- a/src/main/java/fr/communaywen/core/commands/FeedCommand.java +++ b/src/main/java/fr/communaywen/core/commands/FeedCommand.java @@ -39,6 +39,8 @@ public boolean onCommand(final CommandSender sender, final Command command, fina } } player.setFoodLevel(20); + player.setSaturation(5); + player.setExhaustion(0); player.sendMessage("Vous avez été nouris\uE032"); //émoji baguette cooldowns.put(playerId, COOLDOWN_TIME); return true; From e201e9e6ed8e6662ee27a044036f26fa350b7a47 Mon Sep 17 00:00:00 2001 From: misieur Date: Sun, 7 Jul 2024 08:47:52 +0200 Subject: [PATCH 2/3] Merge remote-tracking branch 'origin/main' --- .../fr/communaywen/core/AywenCraftPlugin.java | 2 +- .../core/commands/FeedCommand.java | 8 +++--- .../communaywen/core/commands/RTPCommand.java | 26 +++++-------------- .../communaywen/core/listeners/RTPWand.java | 26 +++++++------------ .../fr/communaywen/core/tpa/CommandTPA.java | 25 ++++++++++++++++-- 5 files changed, 45 insertions(+), 42 deletions(-) diff --git a/src/main/java/fr/communaywen/core/AywenCraftPlugin.java b/src/main/java/fr/communaywen/core/AywenCraftPlugin.java index b74963da..8f538519 100644 --- a/src/main/java/fr/communaywen/core/AywenCraftPlugin.java +++ b/src/main/java/fr/communaywen/core/AywenCraftPlugin.java @@ -104,12 +104,12 @@ public void onEnable() { getServer().getPluginManager().registerEvents(new AntiTrampling(),this); getServer().getPluginManager().registerEvents(new RTPWand(this), this); this.getCommand("tpa").setExecutor(new CommandTPA()); + this.getCommand("tpa").setTabCompleter(new CommandTPA()); this.getCommand("tpaccept").setExecutor(new CommandTpaccept()); this.getCommand("tpdeny").setExecutor(new CommandTpdeny()); getServer().getPluginManager().registerEvents(new SleepListener(),this); - saveDefaultConfig(); // Initialiser EconomyManager et enregistrer la commande money economyManager = new EconomyManager(getDataFolder()); diff --git a/src/main/java/fr/communaywen/core/commands/FeedCommand.java b/src/main/java/fr/communaywen/core/commands/FeedCommand.java index 66600d0c..79ff2409 100644 --- a/src/main/java/fr/communaywen/core/commands/FeedCommand.java +++ b/src/main/java/fr/communaywen/core/commands/FeedCommand.java @@ -16,14 +16,14 @@ import java.util.UUID; public class FeedCommand implements CommandExecutor { - private long COOLDOWN_TIME; + private final long COOLDOWN_TIME; private final HashMap 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; @@ -41,8 +41,8 @@ public boolean onCommand(final CommandSender sender, final Command command, fina player.setFoodLevel(20); player.setSaturation(5); player.setExhaustion(0); - player.sendMessage("Vous avez été nouris\uE032"); //émoji baguette - cooldowns.put(playerId, COOLDOWN_TIME); + player.sendMessage("Vous avez été nouris \uE032"); //émoji baguette + cooldowns.put(playerId, Time); return true; } return false; diff --git a/src/main/java/fr/communaywen/core/commands/RTPCommand.java b/src/main/java/fr/communaywen/core/commands/RTPCommand.java index 5996eeb5..6f1945b9 100644 --- a/src/main/java/fr/communaywen/core/commands/RTPCommand.java +++ b/src/main/java/fr/communaywen/core/commands/RTPCommand.java @@ -41,17 +41,12 @@ public RTPCommand(AywenCraftPlugin plugin) { 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(); @@ -76,22 +71,15 @@ public boolean onCommand(@NotNull final CommandSender sender,@NotNull final Comm 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; + int y = MIN_Y; 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; - } - else { - player.sendTitle(" §cErreur","/rtp"); - cooldowns.put(playerId, Time - COOLDOWN_TIME + COOLDOWN_ERROR); - return true; - } + y = world.getHighestBlockAt(location).getY(); + 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; } player.sendTitle(" §cErreur","/rtp"); cooldowns.put(playerId, Time - COOLDOWN_TIME + COOLDOWN_ERROR); diff --git a/src/main/java/fr/communaywen/core/listeners/RTPWand.java b/src/main/java/fr/communaywen/core/listeners/RTPWand.java index b1c92f5a..97b7c03f 100644 --- a/src/main/java/fr/communaywen/core/listeners/RTPWand.java +++ b/src/main/java/fr/communaywen/core/listeners/RTPWand.java @@ -66,7 +66,7 @@ public void onPlayerInteract(PlayerInteractEvent event) { 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; @@ -76,32 +76,26 @@ public void onPlayerInteract(PlayerInteractEvent event) { if (timeSinceLastUse < COOLDOWN_TIME) { long timeLeft = COOLDOWN_TIME - timeSinceLastUse; - player.sendMessage("Vous devez attendre encore " + timeLeft + " secondes avant d'utiliser cette commande à nouveau."); 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; + int y = MIN_Y; 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; - } - else { - player.sendTitle(" §cErreur","/rtp"); - cooldowns.put(playerId, Time - COOLDOWN_TIME + COOLDOWN_ERROR); - return; - } + y = world.getHighestBlockAt(location).getY(); + player.teleport(location); + player.sendTitle(" §aRTP réussi", "x: " + x + " y: " + y + " z: " + z + " " + (System.currentTimeMillis() / 1000 - Time) + "s"); + cooldowns.put(playerId, Time); + player.setCooldown(item.getType(),COOLDOWN_TIME); + return; } player.sendTitle(" §cErreur","/rtp"); cooldowns.put(playerId, Time - COOLDOWN_TIME + COOLDOWN_ERROR); + player.setCooldown(item.getType(),COOLDOWN_ERROR); } } } diff --git a/src/main/java/fr/communaywen/core/tpa/CommandTPA.java b/src/main/java/fr/communaywen/core/tpa/CommandTPA.java index b31dfa76..ebfd6467 100644 --- a/src/main/java/fr/communaywen/core/tpa/CommandTPA.java +++ b/src/main/java/fr/communaywen/core/tpa/CommandTPA.java @@ -1,14 +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; import net.md_5.bungee.api.ChatColor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class CommandTPA implements CommandExecutor { +import java.util.ArrayList; +import java.util.List; + +public class CommandTPA implements CommandExecutor, TabCompleter { // This method is called, when somebody uses our command TPAQueue tpQueue = TPAQueue.INSTANCE; @@ -24,7 +33,7 @@ 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)); @@ -35,4 +44,16 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } + + @Nullable + @Override + public List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { + List list = new ArrayList(); + for (Player p : Bukkit.getOnlinePlayers()) { + if (p.getName().startsWith(strings[0])){ + list.add(p.getName()); + } + } + return list; + } } From d43bbc74c93c2f474852919da9600f8edbde448b Mon Sep 17 00:00:00 2001 From: misieur Date: Sun, 7 Jul 2024 08:47:52 +0200 Subject: [PATCH 3/3] Update du rtp /feed et tpa --- .../fr/communaywen/core/AywenCraftPlugin.java | 4 +- .../core/commands/FeedCommand.java | 8 +-- .../communaywen/core/commands/RTPCommand.java | 33 ++++-------- .../communaywen/core/listeners/RTPWand.java | 51 +++++++++---------- .../fr/communaywen/core/tpa/CommandTPA.java | 28 ++++++++-- .../communaywen/core/tpa/CommandTpaccept.java | 19 ++++--- .../communaywen/core/tpa/CommandTpcancel.java | 30 +++++++++++ .../communaywen/core/tpa/CommandTpdeny.java | 8 +-- .../fr/communaywen/core/tpa/TPAQueue.java | 4 +- .../fr/communaywen/core/tpa/TPARequest.java | 11 ---- src/main/resources/config.yml | 1 + src/main/resources/plugin.yml | 7 ++- 12 files changed, 121 insertions(+), 83 deletions(-) create mode 100644 src/main/java/fr/communaywen/core/tpa/CommandTpcancel.java delete mode 100644 src/main/java/fr/communaywen/core/tpa/TPARequest.java diff --git a/src/main/java/fr/communaywen/core/AywenCraftPlugin.java b/src/main/java/fr/communaywen/core/AywenCraftPlugin.java index b74963da..d3d514c1 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.commands.ProutCommand; 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.utils.DiscordWebhook; import fr.communaywen.core.utils.LinkerAPI; @@ -104,12 +105,13 @@ public void onEnable() { getServer().getPluginManager().registerEvents(new AntiTrampling(),this); getServer().getPluginManager().registerEvents(new RTPWand(this), this); 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()); getServer().getPluginManager().registerEvents(new SleepListener(),this); - saveDefaultConfig(); // Initialiser EconomyManager et enregistrer la commande money economyManager = new EconomyManager(getDataFolder()); diff --git a/src/main/java/fr/communaywen/core/commands/FeedCommand.java b/src/main/java/fr/communaywen/core/commands/FeedCommand.java index 66600d0c..79ff2409 100644 --- a/src/main/java/fr/communaywen/core/commands/FeedCommand.java +++ b/src/main/java/fr/communaywen/core/commands/FeedCommand.java @@ -16,14 +16,14 @@ import java.util.UUID; public class FeedCommand implements CommandExecutor { - private long COOLDOWN_TIME; + private final long COOLDOWN_TIME; private final HashMap 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; @@ -41,8 +41,8 @@ public boolean onCommand(final CommandSender sender, final Command command, fina player.setFoodLevel(20); player.setSaturation(5); player.setExhaustion(0); - player.sendMessage("Vous avez été nouris\uE032"); //émoji baguette - cooldowns.put(playerId, COOLDOWN_TIME); + player.sendMessage("Vous avez été nouris \uE032"); //émoji baguette + cooldowns.put(playerId, Time); return true; } return false; diff --git a/src/main/java/fr/communaywen/core/commands/RTPCommand.java b/src/main/java/fr/communaywen/core/commands/RTPCommand.java index 5996eeb5..f770701d 100644 --- a/src/main/java/fr/communaywen/core/commands/RTPCommand.java +++ b/src/main/java/fr/communaywen/core/commands/RTPCommand.java @@ -1,16 +1,15 @@ package fr.communaywen.core.commands; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Biome; -import org.bukkit.block.Block; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import fr.communaywen.core.AywenCraftPlugin; +import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -32,6 +31,8 @@ public class RTPCommand implements CommandExecutor { private final HashMap cooldowns = new HashMap<>(); + private final HashMap loc = new HashMap<>(); + public RTPCommand(AywenCraftPlugin plugin) { this.plugin = plugin; @@ -40,28 +41,20 @@ 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(); } + @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); @@ -69,25 +62,22 @@ public boolean onCommand(@NotNull final CommandSender sender,@NotNull final Comm 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()) { + 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.sendTitle(" §aRTP réussi", "x: " + x + " y: " + y + " z: " + z + " "+(System.currentTimeMillis() / 1000 -Time)+"s"); + player.sendTitle(" §aRTP réussi", "x: " + x + " y: " + y + " z: " + z + " " + (System.currentTimeMillis() - ExactTime)/1000 + "s"); cooldowns.put(playerId, Time); return true; } - else { + else{ player.sendTitle(" §cErreur","/rtp"); cooldowns.put(playerId, Time - COOLDOWN_TIME + COOLDOWN_ERROR); return true; @@ -95,7 +85,6 @@ public boolean onCommand(@NotNull final CommandSender sender,@NotNull final Comm } player.sendTitle(" §cErreur","/rtp"); cooldowns.put(playerId, Time - COOLDOWN_TIME + COOLDOWN_ERROR); - return true; } return true; diff --git a/src/main/java/fr/communaywen/core/listeners/RTPWand.java b/src/main/java/fr/communaywen/core/listeners/RTPWand.java index b1c92f5a..df840a93 100644 --- a/src/main/java/fr/communaywen/core/listeners/RTPWand.java +++ b/src/main/java/fr/communaywen/core/listeners/RTPWand.java @@ -31,6 +31,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 cooldowns = new HashMap<>(); @@ -46,19 +47,13 @@ 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) { @@ -66,9 +61,10 @@ public void onPlayerInteract(PlayerInteractEvent event) { 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); @@ -76,32 +72,31 @@ public void onPlayerInteract(PlayerInteractEvent event) { 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); } } } diff --git a/src/main/java/fr/communaywen/core/tpa/CommandTPA.java b/src/main/java/fr/communaywen/core/tpa/CommandTPA.java index b31dfa76..88311c79 100644 --- a/src/main/java/fr/communaywen/core/tpa/CommandTPA.java +++ b/src/main/java/fr/communaywen/core/tpa/CommandTPA.java @@ -1,14 +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; import net.md_5.bungee.api.ChatColor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class CommandTPA implements CommandExecutor { +import java.util.ArrayList; +import java.util.List; + +public class CommandTPA implements CommandExecutor, TabCompleter { // This method is called, when somebody uses our command TPAQueue tpQueue = TPAQueue.INSTANCE; @@ -24,10 +33,11 @@ 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; @@ -35,4 +45,16 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } + + @Nullable + @Override + public List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { + List list = new ArrayList(); + for (Player p : Bukkit.getOnlinePlayers()) { + if (p.getName().startsWith(strings[0])){ + list.add(p.getName()); + } + } + return list; + } } diff --git a/src/main/java/fr/communaywen/core/tpa/CommandTpaccept.java b/src/main/java/fr/communaywen/core/tpa/CommandTpaccept.java index fe2e06ef..2b2aa60a 100644 --- a/src/main/java/fr/communaywen/core/tpa/CommandTpaccept.java +++ b/src/main/java/fr/communaywen/core/tpa/CommandTpaccept.java @@ -1,13 +1,13 @@ package fr.communaywen.core.tpa; import fr.communaywen.core.AywenCraftPlugin; -import org.bukkit.Bukkit; 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; @@ -18,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; diff --git a/src/main/java/fr/communaywen/core/tpa/CommandTpcancel.java b/src/main/java/fr/communaywen/core/tpa/CommandTpcancel.java new file mode 100644 index 00000000..a355dd2d --- /dev/null +++ b/src/main/java/fr/communaywen/core/tpa/CommandTpcancel.java @@ -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; + } +} diff --git a/src/main/java/fr/communaywen/core/tpa/CommandTpdeny.java b/src/main/java/fr/communaywen/core/tpa/CommandTpdeny.java index 744ce57b..93655196 100644 --- a/src/main/java/fr/communaywen/core/tpa/CommandTpdeny.java +++ b/src/main/java/fr/communaywen/core/tpa/CommandTpdeny.java @@ -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; } diff --git a/src/main/java/fr/communaywen/core/tpa/TPAQueue.java b/src/main/java/fr/communaywen/core/tpa/TPAQueue.java index 43ee2d25..442a1b3c 100644 --- a/src/main/java/fr/communaywen/core/tpa/TPAQueue.java +++ b/src/main/java/fr/communaywen/core/tpa/TPAQueue.java @@ -2,7 +2,6 @@ import java.util.HashMap; -import fr.communaywen.core.tpa.TPARequest; import org.bukkit.entity.Player; import org.bukkit.Location; @@ -10,5 +9,6 @@ public class TPAQueue { public static final TPAQueue INSTANCE = new TPAQueue(); private TPAQueue() { } - public final HashMap TPA_REQUESTS = new HashMap(); + public final HashMap TPA_REQUESTS = new HashMap(); + public final HashMap TPA_REQUESTS2 = new HashMap(); } diff --git a/src/main/java/fr/communaywen/core/tpa/TPARequest.java b/src/main/java/fr/communaywen/core/tpa/TPARequest.java deleted file mode 100644 index 57acfbf2..00000000 --- a/src/main/java/fr/communaywen/core/tpa/TPARequest.java +++ /dev/null @@ -1,11 +0,0 @@ -package fr.communaywen.core.tpa; - -import org.bukkit.entity.Player; - -public class TPARequest { - public Player requeste; - - public TPARequest (Player sender) { - requeste = sender; - } -} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7a03ec04..77eb8d9b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -10,5 +10,6 @@ rtp: minz: -3000 maxz: 3000 rtp_wand: "wand:rtpwand" + max_try: 3 feed: cooldown: 60 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b91ef1a3..1c251117 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -38,10 +38,13 @@ commands: description: tpa permission: ayw.command.tpa tpaccept: - description: tpa + description: tpaccept permission: ayw.command.tpa tpdeny: - description: tpa + description: tpdeny + permission: ayw.command.tpa + tpcancel: + description: tpcancel permission: ayw.command.tpa permissions: