From b20dc64617fc56517738f252dbe70510451b34ce Mon Sep 17 00:00:00 2001 From: Adam CAVILLON Date: Thu, 4 Jul 2024 23:18:00 +0200 Subject: [PATCH] [Code] Ajout de la commande /prout --- .../fr/communaywen/core/AywenCraftPlugin.java | 9 ++++ .../core/commands/ProutCommand.java | 52 +++++++++++++++++++ src/main/resources/plugin.yml | 6 +++ 3 files changed, 67 insertions(+) create mode 100644 src/main/java/fr/communaywen/core/commands/ProutCommand.java diff --git a/src/main/java/fr/communaywen/core/AywenCraftPlugin.java b/src/main/java/fr/communaywen/core/AywenCraftPlugin.java index 5b43e6d2..d720c101 100644 --- a/src/main/java/fr/communaywen/core/AywenCraftPlugin.java +++ b/src/main/java/fr/communaywen/core/AywenCraftPlugin.java @@ -1,11 +1,16 @@ package fr.communaywen.core; +import fr.communaywen.core.commands.ProutCommand; import fr.communaywen.core.utils.MOTDChanger; import fr.communaywen.core.commands.VersionCommand; import fr.communaywen.core.utils.PermissionCategory; import org.bukkit.Bukkit; +import org.bukkit.command.PluginCommand; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; public final class AywenCraftPlugin extends JavaPlugin { @@ -21,6 +26,10 @@ public void onEnable() { this.getCommand("version").setExecutor(new VersionCommand(this)); + + final @Nullable PluginCommand proutCommand = super.getCommand("prout"); + if (proutCommand != null) + proutCommand.setExecutor(new ProutCommand()); } @Override diff --git a/src/main/java/fr/communaywen/core/commands/ProutCommand.java b/src/main/java/fr/communaywen/core/commands/ProutCommand.java new file mode 100644 index 00000000..49a33fe0 --- /dev/null +++ b/src/main/java/fr/communaywen/core/commands/ProutCommand.java @@ -0,0 +1,52 @@ +package fr.communaywen.core.commands; + +import fr.communaywen.core.utils.PermissionCategory; +import org.bukkit.Location; +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.util.Vector; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * THE Prout command. + * + * Usage: /prout + * Permission: PREFIX.command.prout + */ +public final class ProutCommand implements CommandExecutor { + + @Override + public boolean onCommand(final @NotNull CommandSender sender, + final @NotNull Command command, + final @NotNull String args, + final @NotNull String[] strings) { + if (sender instanceof Player player) { + player.sendMessage("§2Beuuurk, ça pue !"); + + // Make the player jump + final Vector currentVelocity = player.getVelocity(); + currentVelocity.setY(0.55d); + + player.setVelocity(currentVelocity); + + // Spawn some cloud particles + final Location location = player.getLocation(); + final @Nullable World world = location.getWorld(); + + if (world != null) { + world.spawnParticle(org.bukkit.Particle.CLOUD, location, 3, 0.02d, -0.04d, 0.02d, 0.09d); + + // Funny sound! + world.playSound(location, org.bukkit.Sound.ENTITY_VILLAGER_NO, 0.8f, 2.3f); + world.playSound(location, Sound.ENTITY_GOAT_EAT, 0.7f, 0.2f); + } + } + + return true; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index bfdddf74..ce3d0120 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -8,8 +8,14 @@ commands: description: Affiche la version du plugin. permission: ayw.version permission-message: "Vous n'avez pas la permission d'utiliser cette commande." + prout: + description: Prout ! + permission: ayw.command.prout permissions: ayw.admin.version: description: Permission pour utiliser la commande /version default: op + ayw.command.prout: + description: 'Prout !' + default: true