Revisions for ⁨My First Plugin⁩

View the changes made to this paste.

public ⁨3⁩ ⁨files⁩ 2021-07-30 21:38:38 UTC

plugin.yml

@@ -0,0 +1,10 @@

+name: FirstPlugin
+author: N8TheDev
+description: First Plugin
+version:  1.0
+api-version: 1.17.1
+main: me.nathan.myfirstplugin.MyFirstPlugin
+commands:
+  heal:
+    description: Heals you
+    usage: /<command>
\ No newline at end of file

PluginCommands.java

@@ -0,0 +1,39 @@

+package me.nathan.myfirstplugin.commands;
+
+import me.nathan.myfirstplugin.MyFirstPlugin;
+import org.bukkit.ChatColor;
+import org.bukkit.attribute.Attribute;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import java.util.Objects;
+
+public class PluginCommands implements CommandExecutor {
+    private final MyFirstPlugin main;
+
+    public PluginCommands(MyFirstPlugin main){
+        this.main = main;
+    }
+
+    @Override
+    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
+        if (sender instanceof Player){
+            Player player = (Player) sender;
+            if (player.isOp() || player.hasPermission("canHeal")){
+                double maxHealth = Objects.requireNonNull(player.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getDefaultValue();
+                player.setHealth(maxHealth);
+                player.sendMessage("§e§l(!) §eYou have been healed!");
+                return true;
+            } else {
+                player.sendMessage(ChatColor.RED + "You do not have the required permissions to use this command!");
+                return true;
+            }
+
+        } else {
+            main.getLogger().info(ChatColor.RED + "You have to be a player to use that command!");
+            return true;
+        }
+    }
+}

MyFirstPlugin.java

@@ -0,0 +1,22 @@

+package me.nathan.myfirstplugin;
+
+import me.nathan.myfirstplugin.commands.PluginCommands;
+import me.nathan.myfirstplugin.events.PluginEvents;
+import org.bukkit.ChatColor;
+import org.bukkit.plugin.java.JavaPlugin;
+
+public final class MyFirstPlugin extends JavaPlugin {
+
+    @Override
+    public void onEnable() {
+        getServer().getPluginManager().registerEvents(new PluginEvents(), this);
+        getCommand("heal").setExecutor(new PluginCommands(this));
+        getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[MyFirstPlugin]: Plugin is enabled!");
+    }
+
+    @Override
+    public void onDisable() {
+        // Plugin shutdown logic
+        getServer().getConsoleSender().sendMessage(ChatColor.RED + "[MyFirstPlugin]: Plugin is disabled!");
+    }
+}
\ No newline at end of file