commit 07bf3fe8212c1c64fb035801bcb62adf8fee2118
parent b5c49268339d168a12a3c3e7f3be2004f4d2b98c
Author: luca-luca <reisingerluca@gmail.com>
Date: Sat, 14 Nov 2020 21:23:02 +0100
Added head, standby command
Diffstat:
3 files changed, 104 insertions(+), 21 deletions(-)
diff --git a/plugin.yml b/plugin.yml
@@ -1,7 +1,9 @@
-main: de.typable.minecrafthub.Main
-name: MinecraftHub
-version: 0.0.1
-author: typable
-api-version: 1.16
-commands:
-
-\ No newline at end of file
+main: de.typable.minecrafthub.Main
+name: MinecraftHub
+version: 0.0.1
+author: typable
+api-version: 1.16
+commands:
+ head:
+ standby:
+ usage: /standby <true, false>
+\ No newline at end of file
diff --git a/src/de/typable/minecrafthub/Main.java b/src/de/typable/minecrafthub/Main.java
@@ -1,13 +1,85 @@
-package de.typable.minecrafthub;
-
-import org.bukkit.plugin.java.JavaPlugin;
-
-
-public class Main extends JavaPlugin
-{
- @Override
- public void onEnable()
- {
- // TODO onEnable
- }
-}
+package de.typable.minecrafthub;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.GameMode;
+import org.bukkit.Material;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.plugin.PluginManager;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import de.typable.minecrafthub.constant.DefaultConstants;
+import de.typable.minecrafthub.event.StandbyListener;
+
+
+public class Main extends JavaPlugin
+{
+ private PluginManager pluginManager;
+ private StandbyListener standbyListener;
+
+ @Override
+ public void onEnable()
+ {
+ pluginManager = Bukkit.getPluginManager();
+
+ standbyListener = new StandbyListener(this);
+ pluginManager.registerEvents(standbyListener, this);
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
+ {
+ if(sender instanceof Player)
+ {
+ Player player = (Player) sender;
+
+ if(label.equals("head"))
+ {
+ ItemStack handitem = player.getInventory().getItemInMainHand();
+ ItemStack headitem = player.getInventory().getHelmet();
+ player.getInventory().setHelmet(handitem);
+ player.getInventory().setItemInMainHand((new ItemStack(Material.AIR)));
+
+ if(player.getGameMode() == GameMode.SURVIVAL)
+ {
+ if(headitem != null)
+ {
+ player.getInventory().addItem(headitem);
+ }
+ }
+ }
+
+ if(label.equals("standby"))
+ {
+ if(!player.isOp())
+ {
+ player.sendMessage(DefaultConstants.Messages.NOT_ENOUGH_PERMISSION);
+ return true;
+ }
+
+ if(args.length != 1)
+ {
+ return false;
+ }
+
+ String argument = args[0];
+
+ if(!argument.equals("true") && !argument.equals("false"))
+ {
+ return false;
+ }
+
+ boolean enabled = Boolean.getBoolean(argument);
+ standbyListener.setEnabled(enabled);
+
+ player.sendMessage(ChatColor.GRAY + "Standby mode is now "
+ + (enabled ? "enabled" : "disabled"));
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/src/de/typable/minecrafthub/constant/DefaultConstants.java b/src/de/typable/minecrafthub/constant/DefaultConstants.java
@@ -1,6 +1,15 @@
package de.typable.minecrafthub.constant;
+import org.bukkit.ChatColor;
+
+
public class DefaultConstants
{
public static final long TICK = 20;
+
+ public static final class Messages
+ {
+ public static final String NOT_ENOUGH_PERMISSION = ChatColor.RED
+ + "You don't have enough Permission to perform this command!";
+ }
}