diff --git a/SpectatorPlus/src/com/pgcraft/spectatorplus/SpectateCommand.java b/SpectatorPlus/src/com/pgcraft/spectatorplus/SpectateCommand.java index 2c3eea6..fa0140d 100644 --- a/SpectatorPlus/src/com/pgcraft/spectatorplus/SpectateCommand.java +++ b/SpectatorPlus/src/com/pgcraft/spectatorplus/SpectateCommand.java @@ -792,12 +792,16 @@ private void doHide(CommandSender sender, Command command, String label, String[ */ private void doB(CommandSender sender, Command command, String label, String[] args) { if(sender instanceof Player && p.getPlayerData((Player) sender).spectating && ((Player) sender).getGameMode() == GameMode.SPECTATOR) { - ((Player) sender).setGameMode(GameMode.ADVENTURE); - - ((Player) sender).setAllowFlight(true); - ((Player) sender).setFlying(true); - - p.updateSpectatorInventory((Player) sender); + if(!p.vanillaSpectate) { + ((Player) sender).setGameMode(GameMode.ADVENTURE); + + ((Player) sender).setAllowFlight(true); + ((Player) sender).setFlying(true); + + p.updateSpectatorInventory((Player) sender); + } else { + sender.sendMessage(SpectatorPlus.prefix+ChatColor.DARK_RED+"Exiting no-clip mode is disabled."); + } } } diff --git a/SpectatorPlus/src/com/pgcraft/spectatorplus/SpectateListener.java b/SpectatorPlus/src/com/pgcraft/spectatorplus/SpectateListener.java index d880862..66a42eb 100644 --- a/SpectatorPlus/src/com/pgcraft/spectatorplus/SpectateListener.java +++ b/SpectatorPlus/src/com/pgcraft/spectatorplus/SpectateListener.java @@ -927,13 +927,19 @@ else if(e.getWhoClicked().getGameMode() == GameMode.SPECTATOR) { } else if(toolSelected.getItemMeta().getDisplayName().startsWith(SpectatorPlus.TOOL_NOCLIP_QUIT_NAME)) { - spectator.setGameMode(GameMode.ADVENTURE); - - spectator.setAllowFlight(true); - spectator.setFlying(true); - - spectator.closeInventory(); - p.updateSpectatorInventory(spectator); + // Take care of the vanilla spectate mode - spectators should always be in SPECTATOR gamemode then. + // (this item is removed from the GUI in this case, so technically this should never be needed) + if(!p.vanillaSpectate) { + spectator.setGameMode(GameMode.ADVENTURE); + + spectator.setAllowFlight(true); + spectator.setFlying(true); + + spectator.closeInventory(); + p.updateSpectatorInventory(spectator); + } else { + spectator.sendMessage(SpectatorPlus.prefix+ChatColor.DARK_RED+"Exiting no-clip mode is disabled."); + } } } catch(NullPointerException ex) { // This happens if there isn't any meta, aka here if the spectator diff --git a/SpectatorPlus/src/com/pgcraft/spectatorplus/SpectatorPlus.java b/SpectatorPlus/src/com/pgcraft/spectatorplus/SpectatorPlus.java index ad3e055..44a9d5c 100644 --- a/SpectatorPlus/src/com/pgcraft/spectatorplus/SpectatorPlus.java +++ b/SpectatorPlus/src/com/pgcraft/spectatorplus/SpectatorPlus.java @@ -74,7 +74,7 @@ public class SpectatorPlus extends JavaPlugin { protected Material spectatorsToolsItem; protected Boolean inspector; protected Material inspectorItem; - protected Boolean tpToDeathTool, tpToDeathToolShowCause, divingSuitTool, nightVisionTool, noClipTool, speedTool, glowOnActiveTools, inspectFromTPMenu, playersHealthInTeleportationMenu, playersLocationInTeleportationMenu, specChat, scoreboard, output, death, seeSpecs, blockCmds, adminBypass, newbieMode, teleportToSpawnOnSpecChangeWithoutLobby, useSpawnCommandToTeleport, enforceArenaBoundary; + protected Boolean tpToDeathTool, tpToDeathToolShowCause, divingSuitTool, nightVisionTool, noClipTool, speedTool, glowOnActiveTools, inspectFromTPMenu, playersHealthInTeleportationMenu, playersLocationInTeleportationMenu, specChat, scoreboard, vanillaSpectate, output, death, seeSpecs, blockCmds, adminBypass, newbieMode, teleportToSpawnOnSpecChangeWithoutLobby, useSpawnCommandToTeleport, enforceArenaBoundary; protected SpectatorMode mode = SpectatorMode.ANY; @@ -913,7 +913,8 @@ protected void enableSpectate(Player spectator, CommandSender sender, boolean si // Gamemode, 'ghost' and inventory getPlayerData(spectator).oldGameMode = spectator.getGameMode(); - spectator.setGameMode(GameMode.ADVENTURE); + GameMode gm = (vanillaSpectate)? GameMode.SPECTATOR : GameMode.ADVENTURE; + spectator.setGameMode(gm); savePlayerInv(spectator); getPlayerData(spectator).effects = spectator.getActivePotionEffects(); @@ -964,6 +965,8 @@ else if (sender instanceof Player && !spectator.getName().equals(sender.getName( specs.getConfig().set(spectator.getName(), true); specs.saveConfig(); + + } } @@ -1131,6 +1134,7 @@ protected void reloadConfig(boolean hardReload) { output = toggles.getBoolean(Toggle.OUTPUT_MESSAGES); death = toggles.getBoolean(Toggle.SPECTATOR_MODE_ON_DEATH); scoreboard = toggles.getBoolean(Toggle.SPECTATORS_TABLIST_PREFIX); + vanillaSpectate = toggles.getBoolean(Toggle.SPECTATORS_USE_VANILLA); seeSpecs = toggles.getBoolean(Toggle.SPECTATORS_SEE_OTHERS); blockCmds = toggles.getBoolean(Toggle.CHAT_BLOCKCOMMANDS_ENABLED); adminBypass = toggles.getBoolean(Toggle.CHAT_BLOCKCOMMANDS_ADMINBYPASS); @@ -1206,6 +1210,18 @@ protected void reloadConfig(boolean hardReload) { // Update all spectators' inventories updateSpectatorInventories(); + + for (Player target : getServer().getOnlinePlayers()) { + if (getPlayerData(target) != null && getPlayerData(target).spectating) { + if(vanillaSpectate) { + // Set all spectators to SPECTATOR gamemode. + target.setGameMode(GameMode.SPECTATOR); + } else { + // Set all spectators to ADVENTURE gamemode. + target.setGameMode(GameMode.ADVENTURE); + } + } + } } /** @@ -1571,9 +1587,13 @@ else if(spectator.getGameMode() == GameMode.SPECTATOR) { ItemStack quitNoClip = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); SkullMeta sMeta = (SkullMeta) quitNoClip.getItemMeta(); - sMeta.setDisplayName(TOOL_NOCLIP_QUIT_NAME + spectator.getName()); + String disableExit=""; + if(vanillaSpectate) { + disableExit = ChatColor.RED+""+ChatColor.BOLD+" DISABLED"; + } + sMeta.setDisplayName(TOOL_NOCLIP_QUIT_NAME + spectator.getName() +disableExit); List lore = new ArrayList(); - lore.add(ChatColor.GRAY + "Disables the no-clip mode"); + lore.add(ChatColor.GRAY + "Leave no-clip mode"); lore.add(ChatColor.DARK_GRAY + "You can also use /spec b"); sMeta.setLore(lore); sMeta.setOwner(spectator.getName()); diff --git a/SpectatorPlus/src/com/pgcraft/spectatorplus/Toggle.java b/SpectatorPlus/src/com/pgcraft/spectatorplus/Toggle.java index 30a8a69..d88411e 100644 --- a/SpectatorPlus/src/com/pgcraft/spectatorplus/Toggle.java +++ b/SpectatorPlus/src/com/pgcraft/spectatorplus/Toggle.java @@ -19,6 +19,14 @@ @SuppressWarnings("rawtypes") public enum Toggle { + /* Adding a toggle CHECKLIST + * - Add the toggle to toggles.yml + * - Add the toggle here in Toggle.java + * - Add it to the ToggleManager's set(Toggle, Object, Boolean) method. + * - Declare related variable in SpectatorPlus.java + * - Add the declared variable to reloadConfig(Boolean), also in SpectatorPlus.java + */ + // Tools-related toggles TOOLS_TELEPORTER_ENABLED(Boolean.class, true, "If true the teleportation menu will be available for spectators."), @@ -56,6 +64,7 @@ public enum Toggle { SPECTATORS_TABLIST_PREFIX("spectators.tabListPrefix", Boolean.class, true, "Prefix spectator names in the tab list? This will change the Scoreboard used, and restore the old one when spectator mode is disabled. If you see another plugin's sidebar/infos on players list disappearing when you enable the spectator mode, try to disable this."), SPECTATORS_SEE_OTHERS("spectators.spectatorsSeeSpectators", Boolean.class, true, "See other spectators when you're spectating? (*requires spectators.tabListPrefix to be true*)"), + SPECTATORS_USE_VANILLA("spectators.useVanillaMode", Boolean.class, false, "Use vanilla spectate mode (gamemode 3) instead of adventure mode. Same as no-clip mode tool, but mandatory."), // What to do when the spectator mode is changed (enabled or disabled)? diff --git a/SpectatorPlus/src/com/pgcraft/spectatorplus/ToggleManager.java b/SpectatorPlus/src/com/pgcraft/spectatorplus/ToggleManager.java index 4f53467..0577085 100644 --- a/SpectatorPlus/src/com/pgcraft/spectatorplus/ToggleManager.java +++ b/SpectatorPlus/src/com/pgcraft/spectatorplus/ToggleManager.java @@ -6,8 +6,10 @@ import java.util.Set; import org.apache.commons.lang.Validate; +import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.configuration.Configuration; +import org.bukkit.entity.Player; /** * This class manages the SpectatorPlus' toggles. @@ -210,6 +212,20 @@ public void set(Toggle toggle, Object value, boolean temp) { p.scoreboard = (Boolean) value; break; + case SPECTATORS_USE_VANILLA: + p.vanillaSpectate = (Boolean) value; + GameMode gm = (p.vanillaSpectate)? GameMode.SPECTATOR : GameMode.ADVENTURE; + for (Player target : p.getServer().getOnlinePlayers()) { + if (p.getPlayerData(target) != null && p.getPlayerData(target).spectating) { + // Update each player to reflect the new gamemode. + p.getPlayerData(target).gamemodeChangeAllowed=true; + target.setGameMode(gm); + p.getPlayerData(target).gamemodeChangeAllowed=false; + } + } + p.updateSpectatorInventories(); + break; + case SPECTATOR_MODE_ON_DEATH: p.death = (Boolean) value; break; @@ -330,7 +346,7 @@ public ConfigAccessor getConfigAccessor() { /** * Upgrade the configuration, populating the configuration file with new keys and the - * appropried default values. + * appropriate default values. */ protected void upgrade() { Set togglesND = getConfiguration().getKeys(true); // ND = no defaults diff --git a/SpectatorPlus/toggles.yml b/SpectatorPlus/toggles.yml index 7d71a39..99dbcd0 100644 --- a/SpectatorPlus/toggles.yml +++ b/SpectatorPlus/toggles.yml @@ -29,7 +29,7 @@ tools: glowEffectIfActive: true - # What spectators can get from the spectators' tools? + # What spectators can get from the spectators' tools? speed: true # They can get speed nightVision: true # They can get night-vision and water breathing divingSuit: true # They can get some Depth-Strider-III boots @@ -37,7 +37,7 @@ tools: tpToDeath: enabled: true - # Display the cause of the death in the tooltip? (Example: « You starved to death ».) + # Display the cause of the death in the tooltip? (Example: « You starved to death ».) displayCause: true inspector: @@ -75,6 +75,9 @@ spectators: # See other spectators when you're spectating? (*requires spectators.tabListPrefix to be true*) spectatorsSeeSpectators: true + + # Use vanilla spectate mode (gamemode 3) instead of adventure mode. Same as no-clip mode tool, but mandatory. + useVanillaMode: false # What to do when the spectator mode is changed (enabled or disabled)?