From 40bcb592a674d89a15bef7ca4d9a377f538c3191 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sun, 13 May 2018 02:18:28 +0300 Subject: [PATCH] Bed Event Command added a command to enable/disable bed leave event --- plugin.yml | 5 ++++- src/i/hesh/greet/commands.java | 33 +++++++++++++++++++++++++++++++-- src/i/hesh/greet/events.java | 4 +++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/plugin.yml b/plugin.yml index 8da7983..6c4b0ba 100644 --- a/plugin.yml +++ b/plugin.yml @@ -15,4 +15,7 @@ commands: description: Basic survival kit. setspwan: usage: / - description: sets your current location as bed spwan. \ No newline at end of file + description: sets your current location as bed spwan. + beds: + usage: / + description: enable or disable bed feature. \ No newline at end of file diff --git a/src/i/hesh/greet/commands.java b/src/i/hesh/greet/commands.java index 9e0566b..5f3d19f 100644 --- a/src/i/hesh/greet/commands.java +++ b/src/i/hesh/greet/commands.java @@ -11,8 +11,10 @@ import org.bukkit.plugin.java.JavaPlugin; public class commands extends JavaPlugin { + protected static boolean IsBedEvent; + public void onEnable() { - + IsBedEvent = true; Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "greet plugin is Enabled"); Bukkit.getServer().getPluginManager().registerEvents(new events(), this); @@ -57,7 +59,34 @@ public class commands extends JavaPlugin { p.getInventory().addItem(new ItemStack(Material.STONE_SWORD)); p.getInventory().addItem(new ItemStack(Material.STONE_SWORD)); p.getInventory().addItem(new ItemStack(Material.STONE_SWORD)); - } + } + + if (cmd.getName().equalsIgnoreCase("beds")){ + + if (args[0].equalsIgnoreCase("disable")) { + if (!IsBedEvent) p.sendMessage(greetprefix + "Bed feature is already disabled!"); + else { + + IsBedEvent = false; + Bukkit.getServer().broadcastMessage(greetprefix + ChatColor.BOLD + ChatColor.DARK_RED + p.getDisplayName() + " has Disabled bed feature"); + } + + } + else if (args[0].equalsIgnoreCase("enable")) { + + if (IsBedEvent) p.sendMessage(greetprefix + "Bed feature is already enabled!"); + + else { + IsBedEvent = true; + Bukkit.getServer().broadcastMessage(greetprefix + ChatColor.BOLD + ChatColor.DARK_RED + p.getDisplayName() + " has Enabled bed feature"); + + } + + } + + else p.sendMessage(greetprefix + "Unknown argument\n Try disable/enable"); + } + /*if(cmd.getName().equalsIgnoreCase("setspwan")) { // TODO: give option of new arg to set cords & p.setBedSpawnLocation(p.getLocation()); p.sendMessage(ChatColor.GREEN +"Your bed Spwan has been updated to currnet location"); diff --git a/src/i/hesh/greet/events.java b/src/i/hesh/greet/events.java index 7442cab..13ef65e 100644 --- a/src/i/hesh/greet/events.java +++ b/src/i/hesh/greet/events.java @@ -47,9 +47,11 @@ public class events implements Listener { @EventHandler public void player(PlayerBedLeaveEvent e) { + if (commands.IsBedEvent) { p = e.getPlayer(); Bukkit.getWorld("world").setFullTime(1); - p.sendMessage(PREFIX+" Good Morning!"); + p.sendMessage(PREFIX+" Good Morning!"); + } } @EventHandler