Created
September 20, 2014 13:29
-
-
Save NeatMonster/452b909ac1c7c5408ff9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: RadiusTP | |
| version: 1.0 | |
| author: Max633 | |
| main: me.max633.radiustp.RadiusTP | |
| commands: | |
| tpall: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package me.max633.radiustp; | |
| import org.bukkit.ChatColor; | |
| import org.bukkit.command.Command; | |
| import org.bukkit.command.CommandSender; | |
| import org.bukkit.entity.Player; | |
| import org.bukkit.plugin.java.JavaPlugin; | |
| public class RadiusTP extends JavaPlugin { | |
| @Override | |
| public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { | |
| // On vérifie si la commande nous est bien adressée. | |
| if (command.getName().equalsIgnoreCase("tpall")) { | |
| // On vérifie que c'est bien un joueur qui a effectué la commande. | |
| if (sender instanceof Player) { | |
| // On sait maintenant que c'est un joueur, on peut donc le récupérer. | |
| final Player player = (Player) sender; | |
| // On peut alors vérifier si le joueur a une certaine permission. | |
| if (player.hasPermission("tpall.admin")) { | |
| // On vérifie que le joueur a spécifié un et seulement un argument. | |
| if (args.length == 1) { | |
| // On essaie alors de transformer l'argument de type String en type double. | |
| try { | |
| final double radius = Double.parseDouble(args[0]); | |
| // Les lignes suivantes seront exécutées uniquement si l'opération a réussi. | |
| // On boucle sur tous les joueurs et téléporte ceux qui vérifient nos critères. | |
| for (final Player otherPlayer : getServer().getOnlinePlayers()) | |
| // Le joueur doit être dans le même monde que nous | |
| // et la distance entre lui et nous doit être inférieure au rayon. | |
| if (otherPlayer.getWorld().equals(player.getWorld()) | |
| && otherPlayer.getLocation().distance(player.getLocation()) <= radius) | |
| otherPlayer.teleport(player.getLocation()); | |
| } catch (final NumberFormatException e) { | |
| // Si elle a échoué, on affiche un message. | |
| player.sendMessage(ChatColor.YELLOW + "Syntaxe : /tpall <rayon>"); | |
| } | |
| } else | |
| // S'il n'y a pas ou trop d'arguments, on affiche un message. | |
| player.sendMessage(ChatColor.YELLOW + "Syntaxe : /tpall <rayon>"); | |
| } else | |
| // Si le joueur n'a pas cette permission, on affiche un message. | |
| player.sendMessage(ChatColor.RED + "Vous n'avez pas la permission de faire ça."); | |
| } else | |
| // Si ce n'est pas un joueur, on affiche un message. | |
| sender.sendMessage(ChatColor.RED + "Cette commande est uniquement pour les joueurs."); | |
| return true; | |
| } | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment