From 119e1d54f609cf75cbb5fbc05714f6cc74aa38e7 Mon Sep 17 00:00:00 2001 From: Disclearing Date: Fri, 12 Apr 2019 19:03:09 +0100 Subject: [PATCH] a skid --- .classpath | 8 + .gitignore | 1 + .project | 17 + .settings/org.eclipse.jdt.core.prefs | 11 + plugin.yml | 11 + src/com/Rainnny/Reaper/API/API.java | 24 ++ .../Rainnny/Reaper/Commands/HideStaffCmd.java | 52 +++ .../Rainnny/Reaper/Commands/StaffModeCmd.java | 39 ++ src/com/Rainnny/Reaper/Commands/Vanish.java | 115 ++++++ .../Reaper/Listeners/HideVanishListener.java | 51 +++ .../Reaper/Listeners/StaffModeItems.java | 188 ++++++++++ .../Reaper/Listeners/StaffModeOnJoin.java | 32 ++ .../Reaper/Listeners/StaffOnlineListener.java | 38 ++ src/com/Rainnny/Reaper/StaffMode.java | 352 ++++++++++++++++++ src/com/Rainnny/Reaper/Utils/ColorUtil.java | 10 + .../Rainnny/Reaper/Utils/StaffOnlineGUI.java | 64 ++++ 16 files changed, 1013 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 plugin.yml create mode 100644 src/com/Rainnny/Reaper/API/API.java create mode 100644 src/com/Rainnny/Reaper/Commands/HideStaffCmd.java create mode 100644 src/com/Rainnny/Reaper/Commands/StaffModeCmd.java create mode 100644 src/com/Rainnny/Reaper/Commands/Vanish.java create mode 100644 src/com/Rainnny/Reaper/Listeners/HideVanishListener.java create mode 100644 src/com/Rainnny/Reaper/Listeners/StaffModeItems.java create mode 100644 src/com/Rainnny/Reaper/Listeners/StaffModeOnJoin.java create mode 100644 src/com/Rainnny/Reaper/Listeners/StaffOnlineListener.java create mode 100644 src/com/Rainnny/Reaper/StaffMode.java create mode 100644 src/com/Rainnny/Reaper/Utils/ColorUtil.java create mode 100644 src/com/Rainnny/Reaper/Utils/StaffOnlineGUI.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..cf51a2d --- /dev/null +++ b/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..43e1c33 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + Reaper-StaffMode + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..8be61c1 --- /dev/null +++ b/plugin.yml @@ -0,0 +1,11 @@ +name: ReaperSTAFFMODE +version: 1.0 +author: Rainnny +main: com.Rainnny.Reaper.StaffMode +softdepend: [WorldEdit] +commands: + staffmode: + aliases: [staff, mod, modmode, h] + vanish: + aliases: [v] + hidestaff: diff --git a/src/com/Rainnny/Reaper/API/API.java b/src/com/Rainnny/Reaper/API/API.java new file mode 100644 index 0000000..2291206 --- /dev/null +++ b/src/com/Rainnny/Reaper/API/API.java @@ -0,0 +1,24 @@ +package com.Rainnny.Reaper.API; + +import org.bukkit.entity.Player; + +import com.Rainnny.Reaper.StaffMode; + +public class API { + + public API() { + instance = this; + } + + private static API instance; + + public boolean isInStaffMode(Player player) { + + return new StaffMode().isInStaffMode(player); + } + + + + + +} diff --git a/src/com/Rainnny/Reaper/Commands/HideStaffCmd.java b/src/com/Rainnny/Reaper/Commands/HideStaffCmd.java new file mode 100644 index 0000000..bfbf1c5 --- /dev/null +++ b/src/com/Rainnny/Reaper/Commands/HideStaffCmd.java @@ -0,0 +1,52 @@ +package com.Rainnny.Reaper.Commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import com.Rainnny.Reaper.StaffMode; +import com.Rainnny.Reaper.Utils.ColorUtil; + +public class HideStaffCmd implements CommandExecutor { + + private StaffMode core; + public HideStaffCmd(StaffMode core) { + this.core = core; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if(!sender.hasPermission("hide.staff") || !(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "No permission."); + return true; + } + + if(args.length != 0) { + sender.sendMessage(ChatColor.DARK_RED + "Usage: /hidestaff"); + return true; + } + + Player p = (Player) sender; + if(!core.hiddenStaff.contains(p)) { + if(!core.getStaffOnline().isEmpty()) { + for(Player staff : core.getStaffOnline()) { + p.hidePlayer(staff); + core.hiddenStaff.add(p); + } + } + p.sendMessage("§cSuccesfully disabled visibility of all staff."); + } else { + if(!core.getStaffOnline().isEmpty()) { + for(Player staff : core.getStaffOnline()) { + p.showPlayer(staff); + core.hiddenStaff.remove(p); + } + } + p.sendMessage("§cSuccesfully enabled visibility of all staff."); + } + + return true; + } + +} diff --git a/src/com/Rainnny/Reaper/Commands/StaffModeCmd.java b/src/com/Rainnny/Reaper/Commands/StaffModeCmd.java new file mode 100644 index 0000000..9b56606 --- /dev/null +++ b/src/com/Rainnny/Reaper/Commands/StaffModeCmd.java @@ -0,0 +1,39 @@ +package com.Rainnny.Reaper.Commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.Rainnny.Reaper.StaffMode; +import com.Rainnny.Reaper.Utils.ColorUtil; + +public class StaffModeCmd implements CommandExecutor { + + private StaffMode core; + public StaffModeCmd(StaffMode core) { + this.core = core; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if(!sender.hasPermission("railed.staff") || !(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "You don't have permission to use this."); + return true; + } + if(args.length == 0) { + Player p = (Player) sender; + + if(!core.inStaffMode.contains(p)) { + core.setStaffMode(p, true); + p.sendMessage(ColorUtil.color(StaffMode.PREFIX + "Your staff mode has been &aenabled" + StaffMode.O + "!")); + } else { + core.setStaffMode(p, false); + p.sendMessage(ColorUtil.color(StaffMode.PREFIX + "Your staff mode has been &cdisabled" + StaffMode.O + "!")); + } + } + return true; + } + +} diff --git a/src/com/Rainnny/Reaper/Commands/Vanish.java b/src/com/Rainnny/Reaper/Commands/Vanish.java new file mode 100644 index 0000000..90688a6 --- /dev/null +++ b/src/com/Rainnny/Reaper/Commands/Vanish.java @@ -0,0 +1,115 @@ +package com.Rainnny.Reaper.Commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.permissions.Permissible; + +import com.Rainnny.Reaper.StaffMode; +import com.Rainnny.Reaper.Utils.ColorUtil; + +import ru.tehkode.permissions.bukkit.PermissionsEx; + +public class Vanish implements CommandExecutor { + + private StaffMode core; + public Vanish(StaffMode core) { + this.core = core; + } + + @SuppressWarnings("deprecation") + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if(!(sender instanceof Player) || !sender.hasPermission("railed.staff") || !sender.hasPermission("essentials.vanish")) { + sender.sendMessage(ChatColor.RED + "You don't have permission to use this."); + return true; + } + Player p = (Player) sender; + if(args.length == 0) { + if(core.isInStaffMode(p)) { + if(core.isVanished(p)) { + ItemStack vanish = new ItemStack(Material.INK_SACK, 1, (short) 0, (byte) 8); + ItemMeta vanishMeta = vanish.getItemMeta(); + vanishMeta.setDisplayName(ChatColor.DARK_RED + "Vanish"); + vanishMeta.setLore(core.vanishLore()); + vanish.setItemMeta(vanishMeta); + + p.getInventory().setItem(8, vanish); + p.updateInventory(); + core.setVanished(p, false); + p.sendMessage(ColorUtil.color(StaffMode.PREFIX + "Your vanish has been &cdisabled" + StaffMode.O + "!")); + } else { + ItemStack vanish = new ItemStack(Material.INK_SACK, 1, (short) 0, (byte) 10); + ItemMeta vanishMeta = vanish.getItemMeta(); + vanishMeta.setDisplayName(ChatColor.DARK_RED + "Vanish"); + vanishMeta.setLore(core.vanishLore()); + vanish.setItemMeta(vanishMeta); + + p.getInventory().setItem(8, vanish); + p.updateInventory(); + core.setVanished(p, true); + p.sendMessage(ColorUtil.color(StaffMode.PREFIX + "Your vanish has been &aenabled" + StaffMode.O + "!")); + } + } else { + if(core.isVanished(p)) { + core.setVanished(p, false); + p.sendMessage(ColorUtil.color(StaffMode.PREFIX + "Your vanish has been &cdisabled" + StaffMode.O + "!")); + } else { + core.setVanished(p, true); + p.sendMessage(ColorUtil.color(StaffMode.PREFIX + "Your vanish has been &aenabled" + StaffMode.O + "!")); + } + } + } else { + if(args.length == 1) { + Player argsPlayer = Bukkit.getPlayer(args[0]); + if(core.isInStaffMode(argsPlayer)) { + if(core.isVanished(p)) { + ItemStack vanish = new ItemStack(Material.INK_SACK, 1, (short) 0, (byte) 8); + ItemMeta vanishMeta = vanish.getItemMeta(); + vanishMeta.setDisplayName(ChatColor.DARK_RED + "Vanish"); + vanishMeta.setLore(core.vanishLore()); + vanish.setItemMeta(vanishMeta); + + p.getInventory().setItem(8, vanish); + p.updateInventory(); + core.setVanished(argsPlayer, false); + p.sendMessage(ColorUtil.color(StaffMode.PREFIX + "Set " + PermissionsEx.getUser(argsPlayer.getName()).getSuffix() + argsPlayer.getName() + "'s vanish to &cfalse")); + argsPlayer.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9&oYou have been put into vanish by " + p.getName() + ".")); + } else { + ItemStack vanish = new ItemStack(Material.INK_SACK, 1, (short) 0, (byte) 10); + ItemMeta vanishMeta = vanish.getItemMeta(); + vanishMeta.setDisplayName(ChatColor.DARK_RED + "Vanish"); + vanishMeta.setLore(core.vanishLore()); + vanish.setItemMeta(vanishMeta); + + p.getInventory().setItem(8, vanish); + p.updateInventory(); + core.setVanished(argsPlayer, true); + p.sendMessage(ColorUtil.color(StaffMode.PREFIX + "Set " + PermissionsEx.getUser(argsPlayer.getName()).getSuffix() + argsPlayer.getName() + "'s vanish to &atrue")); + argsPlayer.sendMessage(ColorUtil.color(StaffMode.PREFIX + "Your vanish has been set to &atrue" + StaffMode.O + " by " + PermissionsEx.getUser(argsPlayer.getName()).getSuffix() + argsPlayer.getName())); + } + } else { + if(core.isVanished(p)) { + core.setVanished(argsPlayer, false); + p.sendMessage(ColorUtil.color(StaffMode.PREFIX + "Set " + PermissionsEx.getUser(argsPlayer.getName()).getSuffix() + argsPlayer.getName() + "'s vanish to &cfalse")); + argsPlayer.sendMessage(ColorUtil.color(StaffMode.PREFIX + "Your vanish has been set to &cfalse" + StaffMode.O + " by " + PermissionsEx.getUser(argsPlayer.getName()).getSuffix() + argsPlayer.getName())); + } else { + core.setVanished(argsPlayer, true); + p.sendMessage(ColorUtil.color(StaffMode.PREFIX + "Set " + PermissionsEx.getUser(argsPlayer.getName()).getSuffix() + argsPlayer.getName() + "'s vanish to &atrue")); + argsPlayer.sendMessage(ColorUtil.color(StaffMode.PREFIX + "Your vanish has been set to &atrue" + StaffMode.O + " by " + PermissionsEx.getUser(argsPlayer.getName()).getSuffix() + argsPlayer.getName())); + } + } + return true; + } + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cError: &7Too many arguments! &4&oUse /vanish ")); + } + return true; + } + +} diff --git a/src/com/Rainnny/Reaper/Listeners/HideVanishListener.java b/src/com/Rainnny/Reaper/Listeners/HideVanishListener.java new file mode 100644 index 0000000..1db7527 --- /dev/null +++ b/src/com/Rainnny/Reaper/Listeners/HideVanishListener.java @@ -0,0 +1,51 @@ +package com.Rainnny.Reaper.Listeners; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import com.Rainnny.Reaper.StaffMode; + +public class HideVanishListener implements Listener { + + private StaffMode core; + public HideVanishListener(StaffMode core) { + this.core = core; + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent e) { + if(core.inVanish.size() > 0) { + for(Player p : core.inVanish) { + e.getPlayer().hidePlayer(p); + } + } + + if(e.getPlayer().hasPermission("railed.staff")) { + + if(core.hiddenStaff.contains(e.getPlayer())) { + for(Player staff : core.getStaffOnline()) { + if(staff != e.getPlayer()) { + e.getPlayer().hidePlayer(staff); + } + + } + } + + for(Player staff : core.hiddenStaff) { + staff.hidePlayer(e.getPlayer()); + } + } + + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent e) { + if(core.isVanished(e.getPlayer())) { + core.setStaffMode(e.getPlayer(), false); + } + } + +} diff --git a/src/com/Rainnny/Reaper/Listeners/StaffModeItems.java b/src/com/Rainnny/Reaper/Listeners/StaffModeItems.java new file mode 100644 index 0000000..39beaec --- /dev/null +++ b/src/com/Rainnny/Reaper/Listeners/StaffModeItems.java @@ -0,0 +1,188 @@ +package com.Rainnny.Reaper.Listeners; + +import java.util.ArrayList; +import java.util.Random; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Chest; +import org.bukkit.entity.Damageable; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.potion.PotionEffect; + +import com.Rainnny.Reaper.StaffMode; + + + +public class StaffModeItems implements Listener { + + private StaffMode core; + public StaffModeItems(StaffMode core) { + this.core = core; + } + + @EventHandler + public void onInteract(PlayerInteractEvent e) { + Player p = e.getPlayer(); + ItemStack itemInHand = p.getItemInHand(); + Inventory rm = Bukkit.createInventory(null, 54, "Silent Chest"); + + if(core.isInStaffMode(p)) { + if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) { + + + + if(itemInHand.getType().equals(Material.WATCH) && itemInHand.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.DARK_RED + "Random Teleport")) { + + if(core.toTeleportTo.size() > 0) { + Random r = new Random(); + int index = r.nextInt(core.toTeleportTo.size()); + p.teleport(core.toTeleportTo.get(index).getLocation()); + p.sendMessage(ChatColor.GRAY + "Teleported to " + ChatColor.WHITE + core.toTeleportTo.get(index).getDisplayName()); + } else { + p.sendMessage(ChatColor.RED + "Prevented teleportation since there is nobody to teleport to."); + } + } + + if(itemInHand.getType().equals(Material.INK_SACK) && itemInHand.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.DARK_RED + "Vanish")) { + Bukkit.dispatchCommand(p, "vanish"); + } + if(itemInHand.getType().equals(Material.SKULL_ITEM) && itemInHand.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.DARK_RED + "Staff Online")) { + core.staffOnlineGUI.open(p); + } + } + if(e.getAction() == Action.RIGHT_CLICK_BLOCK) { + if(e.getClickedBlock().getType().equals(Material.CHEST) || e.getClickedBlock().getType().equals(Material.TRAPPED_CHEST)) { + Chest chest = (Chest) e.getClickedBlock().getState(); + p.sendMessage(ChatColor.GRAY + "Opened chest silently."); + rm.setContents(chest.getInventory().getContents()); + p.openInventory(rm); + e.setCancelled(true); + } + } + e.setCancelled(true); + } + } + + @EventHandler + public void onBlockPlace(BlockPlaceEvent e) { + if(core.isInStaffMode(e.getPlayer())) { + e.setCancelled(true); + } + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent e) { + if(core.isInStaffMode(e.getPlayer())) { + e.setCancelled(true); + } + } + + @EventHandler + public void onInventoryDrop(PlayerDropItemEvent e) { + if(core.isInStaffMode(e.getPlayer())) { + e.setCancelled(true); + } + } + + @EventHandler + public void onInvPickup(PlayerPickupItemEvent e) { + if(core.isInStaffMode(e.getPlayer())) { + e.setCancelled(true); + } + } + + @EventHandler + public void onInvMove(InventoryClickEvent e) { + if(core.isInStaffMode((Player) e.getWhoClicked())) { + e.setCancelled(true); + } + } + + @EventHandler + public void onAttack(EntityDamageByEntityEvent e) { + if(e.getDamager() instanceof Player) { + if(core.isInStaffMode((Player) e.getDamager())) { + Player p = (Player) e.getDamager(); + e.setCancelled(true); + p.sendMessage(ChatColor.RED + "Get out of staff mode to pvp!"); + return; + } + if(core.isVanished((Player) e.getDamager())) { + Player p = (Player) e.getDamager(); + e.setCancelled(true); + p.sendMessage(ChatColor.RED + "Get out of vanish to pvp!"); + return; + } + } + } + + @EventHandler + public void onInteractEntity(PlayerInteractEntityEvent e) { + Player p = e.getPlayer(); + ItemStack itemInHand = p.getItemInHand(); + if(core.inStaffMode.contains(p)) { + if(itemInHand.getType().equals(Material.ICE)) { + if(e.getRightClicked() instanceof Player) { + Player clicked = (Player) e.getRightClicked(); + Bukkit.dispatchCommand(p, "freeze " + clicked.getName()); + } + } + if(itemInHand.getType().equals(Material.BOOK)) { + if(e.getRightClicked() instanceof Player) { + Player clicked = (Player) e.getRightClicked(); + Damageable clickedd = clicked; + Inventory rm = Bukkit.createInventory(null, 54, clicked.getName()); + rm.setContents(clicked.getInventory().getContents()); + for(int i = 36; i < 45 ; i++) { + rm.setItem(i, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 0, (byte) 5)); + } + ItemStack health = new ItemStack(Material.SPECKLED_MELON, 1); + ItemMeta healthMeta = health.getItemMeta(); + healthMeta.setDisplayName(ChatColor.RED.toString() + clickedd.getHealth() / 2 + "™¥"); + health.setItemMeta(healthMeta); + ItemStack hunger = new ItemStack(Material.COOKED_CHICKEN, 1); + ItemMeta hungerMeta = health.getItemMeta(); + hungerMeta.setDisplayName(ChatColor.RED.toString() + clicked.getFoodLevel() + " Hunger"); + hunger.setItemMeta(hungerMeta); + ItemStack potions = new ItemStack(Material.POTION, 1); + ItemMeta potionsMeta = potions.getItemMeta(); + ArrayList effects = new ArrayList(); + effects.add(" "); + for(PotionEffect effect : clicked.getActivePotionEffects()) { + if(clicked.getActivePotionEffects() != null) { + effects.add(ChatColor.WHITE + effect.getType().getName() + " " + effect.getDuration()); + } + } + + potionsMeta.setLore(effects); + potionsMeta.setDisplayName(ChatColor.RED + "Potion Effects"); + potions.setItemMeta(potionsMeta); + + rm.setItem(45, health); + rm.setItem(46, hunger); + rm.setItem(47, potions); + + p.openInventory(rm); + } + } + } + e.setCancelled(true); + } + +} diff --git a/src/com/Rainnny/Reaper/Listeners/StaffModeOnJoin.java b/src/com/Rainnny/Reaper/Listeners/StaffModeOnJoin.java new file mode 100644 index 0000000..2bcbce0 --- /dev/null +++ b/src/com/Rainnny/Reaper/Listeners/StaffModeOnJoin.java @@ -0,0 +1,32 @@ +package com.Rainnny.Reaper.Listeners; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import com.Rainnny.Reaper.StaffMode; + +import net.md_5.bungee.api.ChatColor; + +public class StaffModeOnJoin implements Listener { + + private StaffMode core; + public StaffModeOnJoin(StaffMode core) { + this.core = core; + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent e) { + Player p = e.getPlayer(); + + if(core.isStaff(p) || !core.isVanished(p)) { + p.sendMessage(ChatColor.GRAY.toString() + ChatColor.ITALIC + "You were automatically put in vanish since you joined!"); + core.setVanished(p, true); + } else { + if(core.isStaff(p) || !core.inStaffMode.contains(p)) { + core.setStaffMode(p, true); + } + } + } + +} diff --git a/src/com/Rainnny/Reaper/Listeners/StaffOnlineListener.java b/src/com/Rainnny/Reaper/Listeners/StaffOnlineListener.java new file mode 100644 index 0000000..10278b4 --- /dev/null +++ b/src/com/Rainnny/Reaper/Listeners/StaffOnlineListener.java @@ -0,0 +1,38 @@ +package com.Rainnny.Reaper.Listeners; + +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import com.Rainnny.Reaper.StaffMode; + +public class StaffOnlineListener implements Listener { + + private StaffMode core; + public StaffOnlineListener(StaffMode core) { + this.core = core; + } + + //Adds staff to online list on join. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent e) { + Player p = e.getPlayer(); + if(!core.staffOnline.contains(p) && p.hasPermission("railed.staff")) { + core.staffOnline.add(p); + } + } + + //Removes staff from online list on quit. + @EventHandler + public void onPlayerLeave(PlayerQuitEvent e) { + Player p = e.getPlayer(); + if(p.hasPermission("railed.staff") && core.staffOnline.contains(p)) { + e.getPlayer().setGameMode(GameMode.SURVIVAL); + core.staffOnline.remove(p); + } + } + +} diff --git a/src/com/Rainnny/Reaper/StaffMode.java b/src/com/Rainnny/Reaper/StaffMode.java new file mode 100644 index 0000000..df6eb7c --- /dev/null +++ b/src/com/Rainnny/Reaper/StaffMode.java @@ -0,0 +1,352 @@ +package com.Rainnny.Reaper; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.java.JavaPlugin; +import com.Rainnny.Reaper.Commands.HideStaffCmd; +import com.Rainnny.Reaper.Commands.StaffModeCmd; +import com.Rainnny.Reaper.Commands.Vanish; +import com.Rainnny.Reaper.Listeners.HideVanishListener; +import com.Rainnny.Reaper.Listeners.StaffModeItems; +import com.Rainnny.Reaper.Listeners.StaffOnlineListener; +import com.Rainnny.Reaper.Utils.StaffOnlineGUI; + + +public class StaffMode extends JavaPlugin { + + public ArrayList inStaffMode = new ArrayList(); + public ArrayList staffOnline = new ArrayList(); + public ArrayList inVanish = new ArrayList(); + public HashMap staffInventories = new HashMap(); + public HashMap staffLastGamemodes = new HashMap(); + public ArrayList onlinePlayers = new ArrayList(); + public ArrayList hiddenStaff = new ArrayList(); + public ArrayList toTeleportTo = new ArrayList(); + public ArrayList miningPlayers = new ArrayList(); + public static String PREFIX; + public static ChatColor M; + public static ChatColor M2; + public static ChatColor O; + + public static StaffMode instance; + + public StaffOnlineGUI staffOnlineGUI; + + public ArrayList getStaffInMode() { + return inStaffMode; + } + + public ArrayList getStaffOnline() { + return staffOnline; + } + + public ArrayList inVanish() { + return inVanish; + } + + public HashMap getStaffInvs() { + return staffInventories; + } + + public void setStaffMode(Player player, boolean inStaffMode) { + if(inStaffMode == true) { + this.getStaffInMode().add(player); + if(!isVanished(player)) { + this.setVanished(player, true); + player.sendMessage(ChatColor.GRAY.toString() + ChatColor.ITALIC + "You were automatically put into vanish since you weren't already."); + } + this.giveItems(player); + staffLastGamemodes.put(player, player.getGameMode()); + player.setGameMode(GameMode.CREATIVE); + } else { + this.getStaffInMode().remove(player); + this.returnOldInv(player); + this.setVanished(player, false); + player.sendMessage(ChatColor.GRAY.toString() + ChatColor.ITALIC + "Automatically removed your vanish mode."); + if(player.isOp() && staffLastGamemodes.get(player) == GameMode.CREATIVE) { + player.setGameMode(staffLastGamemodes.get(player)); + } else { + if(staffLastGamemodes.get(player) == GameMode.CREATIVE) { + player.setGameMode(GameMode.SURVIVAL); + return; + } + player.setGameMode(staffLastGamemodes.get(player)); + } + } + } + + public boolean isInStaffMode(Player player) { + return getStaffInMode().contains(player); + } + + private List compassLore() { + List lore = new ArrayList(); + lore.add(ChatColor.translateAlternateColorCodes('&', "§4&lRIGHT CLICK &cto teleport through blocks.")); + lore.add(ChatColor.translateAlternateColorCodes('&', "§4&lLEFT CLICK &cto jump through blocks.")); + + return lore; + } + + private List inspectLore() { + List lore = new ArrayList(); + + lore.add(ChatColor.translateAlternateColorCodes('&', "§4&lRIGHT CLICK &cto inspect a player's inventory.")); + + return lore; + } + + private List worldeditLore() { + List lore = new ArrayList(); + + lore.add("§4§lLEFT CLICK §cto select position 1"); + lore.add("§4§lRIGHT CLICK §cto select position 2"); + + return lore; + } + + private List freezeLore() { + List lore = new ArrayList(); + + lore.add(ChatColor.translateAlternateColorCodes('&', "&4&lRIGHT CLICK &ca player to freeze them.")); + + return lore; + } + + private List randomLore() { + List lore = new ArrayList(); + + lore.add(ChatColor.translateAlternateColorCodes('&', "&4&lRIGHT CLICK &cto randomly teleport to a player!")); + return lore; + } + + public List vanishLore() { + List lore = new ArrayList(); + + lore.add(ChatColor.translateAlternateColorCodes('&', "&4&lRIGHT CLICK &cto toggle your vanish.")); + + return lore; + } + + private List staffOnlineLore() { + List lore = new ArrayList(); + + lore.add(ChatColor.translateAlternateColorCodes('&', "&4&lRIGHT CLICK &cto view online staff.")); + + return lore; + } + + public void giveItems(Player player) { + ItemStack compass = new ItemStack(Material.COMPASS); + ItemMeta compassMeta = compass.getItemMeta(); + + compassMeta.setDisplayName(ChatColor.DARK_RED + "Teleport"); + compassMeta.setLore(compassLore()); + compass.setItemMeta(compassMeta); + + ItemStack inspect = new ItemStack(Material.BOOK); + ItemMeta inspectMeta = compass.getItemMeta(); + + inspectMeta.setDisplayName(ChatColor.DARK_RED + "Inspect Tool"); + inspectMeta.setLore(inspectLore()); + inspect.setItemMeta(inspectMeta); + + ItemStack worldedit = new ItemStack(Material.WOOD_AXE); + ItemMeta worldeditMeta = worldedit.getItemMeta(); + + worldeditMeta.setDisplayName("§4WorldEdit Wand"); + worldeditMeta.setLore(worldeditLore()); + worldedit.setItemMeta(worldeditMeta); + + + ItemStack freeze = new ItemStack(Material.ICE); + ItemMeta freezeMeta = freeze.getItemMeta(); + + freezeMeta.setDisplayName(ChatColor.DARK_RED + "Freeze Player"); + freezeMeta.setLore(freezeLore()); + freeze.setItemMeta(freezeMeta); + + ItemStack randomtp = new ItemStack(Material.WATCH, 1); + ItemMeta randomtpMeta = randomtp.getItemMeta(); + + randomtpMeta.setDisplayName(ChatColor.DARK_RED + "Random Teleport"); + randomtpMeta.setLore(randomLore()); + randomtp.setItemMeta(randomtpMeta); + + ItemStack vanish = new ItemStack(Material.INK_SACK, 1, (short)0, (byte) 8); + if(isVanished(player)) { + vanish = new ItemStack(Material.INK_SACK, 1, (short)0, (byte) 10); + } + ItemMeta vanishMeta = vanish.getItemMeta(); + + vanishMeta.setDisplayName(ChatColor.BLUE + "Vanish"); + vanishMeta.setLore(vanishLore()); + + vanish.setItemMeta(vanishMeta); + + ItemStack staffOnline = new ItemStack(Material.SKULL_ITEM, 1, (short)0, (byte) 3); + ItemMeta staffOnlineMeta = staffOnline.getItemMeta(); + + staffOnlineMeta.setDisplayName(ChatColor.BLUE + "Staff Online"); + staffOnlineMeta.setLore(staffOnlineLore()); + + staffOnline.setItemMeta(staffOnlineMeta); + + + staffInventories.put(player, player.getInventory().getContents()); + player.getInventory().clear(); + player.getInventory().setItem(0, compass); + player.getInventory().setItem(1, inspect); + player.getInventory().setItem(2, worldedit); + player.getInventory().setItem(3, freeze); + player.getInventory().setItem(7, randomtp); + player.getInventory().setItem(8, vanish); + + } + + public boolean isStaff(Player player) { + return player.hasPermission("reaper.staff"); + } + + public void returnOldInv(Player player) { + player.getInventory().clear(); + player.getInventory().setContents(getStaffInvs().get(player)); + } + + public void setVanished(Player player, boolean inVanish) { + if(inVanish == true) { + for(Player online : Bukkit.getOnlinePlayers()) { + online.hidePlayer(player); + + } + for(Player staff : this.staffOnline) { + staff.canSee(player); + } + this.inVanish.add(player); + } else { + for(Player online : Bukkit.getOnlinePlayers()) { + online.showPlayer(player); + } + this.inVanish.remove(player); + } + } + + public boolean isVanished(Player player) { + return inVanish.contains(player); + } + + public void onEnable() { + + //Config + //File file = new File(getDataFolder(), "config.yml"); + //if(!file.exists()) { + //getConfig().addDefault("Inventory", ""); + //getConfig().options().copyDefaults(true); + //saveConfig(); + //} + + instance = this; + + //Registered Commands + this.getCommand("staffmode").setExecutor(new StaffModeCmd(this)); + this.getCommand("vanish").setExecutor(new Vanish(this)); + this.getCommand("hidestaff").setExecutor(new HideStaffCmd(this)); + + //Registering Listeners + Bukkit.getPluginManager().registerEvents(new StaffModeItems(this), this); + Bukkit.getPluginManager().registerEvents(new StaffOnlineListener(this), this); + Bukkit.getPluginManager().registerEvents(new StaffOnlineListener(this), this); + Bukkit.getPluginManager().registerEvents(new HideVanishListener(this), this); + + //Online player updater + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { + + public void run() { + if(Bukkit.getOnlinePlayers().length != 0) { + for(int all = 0 ; all < onlinePlayers.size() ; all++) { + onlinePlayers.remove(all); + } + for(Player online : Bukkit.getOnlinePlayers()) { + onlinePlayers.add(online); + } + for(Player staff : staffOnline) { + onlinePlayers.remove(staff); + } + } + staffOnline.clear(); + miningPlayers.clear(); + for(Player online : Bukkit.getOnlinePlayers()) { + if(online.hasPermission("railed.staff")) { + staffOnline.add(online); + } + } + + for(Player online : Bukkit.getOnlinePlayers()) { + if(online.getLocation().getBlockY() <= 20) { + miningPlayers.add(online); + } + } + + if(!inVanish.isEmpty() && !staffOnline.isEmpty()) { + for(Player staff : staffOnline) { + for(Player vanished : inVanish) { + staff.showPlayer(vanished); + } + for(Player ops : Bukkit.getOnlinePlayers()) { + if(isVanished(ops) && ops.isOp() && !staff.isOp()) { + staff.hidePlayer(ops); + } + } + } + } + if(!hiddenStaff.isEmpty() && !staffOnline.isEmpty()) { + for(Player staff : inStaffMode) { + for(Player hidden : hiddenStaff) { + hidden.hidePlayer(staff); + } + } + } + if(Bukkit.getOnlinePlayers().length != 0) { + for(int i = 0 ; i < toTeleportTo.size() ; i++) { + toTeleportTo.remove(i); + } + for(Player online : Bukkit.getOnlinePlayers()) { + toTeleportTo.add(online); + } + } + if(!staffOnline.isEmpty()) { + for(Player staff : staffOnline) { + toTeleportTo.remove(staff); + } + } + + } + }, 20L, 20L); + + //Registering Utils + staffOnlineGUI = new StaffOnlineGUI(this); + } + + static { + StaffMode.PREFIX = "§4Railed §8» §7"; + StaffMode.M = ChatColor.DARK_RED; + StaffMode.M2 = ChatColor.RED; + StaffMode.O = ChatColor.GRAY; + } + + public void onDisable() { + for(Player pp : Bukkit.getOnlinePlayers()) { + if(isInStaffMode(pp)) { + setStaffMode(pp, false); + } + } + } + +} \ No newline at end of file diff --git a/src/com/Rainnny/Reaper/Utils/ColorUtil.java b/src/com/Rainnny/Reaper/Utils/ColorUtil.java new file mode 100644 index 0000000..d0ea3bd --- /dev/null +++ b/src/com/Rainnny/Reaper/Utils/ColorUtil.java @@ -0,0 +1,10 @@ +package com.Rainnny.Reaper.Utils; + +import org.bukkit.ChatColor; + +public class ColorUtil +{ + public static String color(final String message) { + return ChatColor.translateAlternateColorCodes('&', message); + } +} diff --git a/src/com/Rainnny/Reaper/Utils/StaffOnlineGUI.java b/src/com/Rainnny/Reaper/Utils/StaffOnlineGUI.java new file mode 100644 index 0000000..1321362 --- /dev/null +++ b/src/com/Rainnny/Reaper/Utils/StaffOnlineGUI.java @@ -0,0 +1,64 @@ +package com.Rainnny.Reaper.Utils; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.plugin.Plugin; + +import com.Rainnny.Reaper.StaffMode; + +public class StaffOnlineGUI implements Listener { + + private Inventory rm; + private ItemStack skullHead; + + private StaffMode core; + + public StaffOnlineGUI(StaffMode p) { + this.core = p; + } + + public void create_inventory() { + rm = Bukkit.createInventory(null, 18, "Staff Online"); + if (core.staffOnline == null) { + return; + } + for(Player staff : core.staffOnline) { + for(int i = 0; i < core.staffOnline.size() ; i++) { + skullHead = addStaff(staff.getName()); + rm.setItem(i, skullHead); + } + } + } + + private ItemStack addStaff(String name) { + ItemStack i = new ItemStack(Material.SKULL, 1, (short) 0, (byte) 3); + SkullMeta im = (SkullMeta) i.getItemMeta(); + + im.setDisplayName(ChatColor.RED + name); + im.setOwner(Bukkit.getPlayer(name).getName()); + i.setItemMeta(im); + + return i; + } + + public void open(Player player) { + create_inventory(); + player.openInventory(rm); + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent e) { + if (!e.getInventory().getName().equalsIgnoreCase(rm.getName())) return; + if (e.getCurrentItem().getItemMeta() == null) return; + e.setCancelled(true); + } + +} \ No newline at end of file