Skip to content

Commit

Permalink
Finishing touches
Browse files Browse the repository at this point in the history
  • Loading branch information
Chipley committed Sep 13, 2013
1 parent 3086291 commit d839d9b
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 55 deletions.
8 changes: 8 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
######################################### Config Options #########################################

# Enabling this permission stops spectators from spectating people with
# the "spectate.cantspectate" permission and the '*' permission. (OPs included)
cantspectate-permission-enabled: false

# Enabling this will stop spectators from executing any commands except '/spectate' while spectating.
disable-commands-while-spectating: false
39 changes: 35 additions & 4 deletions src/com/Chipmunk9998/Spectate/Spectate.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
package com.Chipmunk9998.Spectate;

import java.io.File;

import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import com.Chipmunk9998.Spectate.api.SpectateManager;

public class Spectate extends JavaPlugin {

//TODO: Control command
//TODO: Fix inventory compatibility (Multiverse Inventories, Mob Arena)
//TODO: Config
//TODO: (IN THE FUTURE - DON'T HAVE TIME FOR THIS RIGHT NOW) Control command

static SpectateManager Manager;

public boolean cantspectate_permission_enabled = false;
public boolean disable_commands = false;

public void onEnable() {

Manager = new SpectateManager(this);

loadConfig();

getServer().getPluginManager().registerEvents(new SpectateListener(), this);
getCommand("spectate").setExecutor(new SpectateCommandExecutor());
getCommand("spectate").setExecutor(new SpectateCommandExecutor(this));
getAPI().startSpectateTask();

}
Expand All @@ -42,5 +49,29 @@ public static SpectateManager getAPI() {
return Manager;

}

public boolean multiverseInvEnabled() {

if (getServer().getPluginManager().getPlugin("Multiverse-Inventories") != null && getServer().getPluginManager().getPlugin("Multiverse-Inventories").isEnabled()) {

return true;

}

return false;

}

public void loadConfig() {

saveDefaultConfig();

File tutorialFile = new File(getDataFolder(), "config.yml");
FileConfiguration config = YamlConfiguration.loadConfiguration(tutorialFile);

cantspectate_permission_enabled = config.getBoolean("cantspectate-permission-enabled");
disable_commands = config.getBoolean("disable-commands-while-spectating");

}

}
27 changes: 23 additions & 4 deletions src/com/Chipmunk9998/Spectate/SpectateCommandExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
import com.Chipmunk9998.Spectate.api.SpectateMode;

public class SpectateCommandExecutor implements CommandExecutor {

Spectate plugin;

public SpectateCommandExecutor(Spectate plugin) {

this.plugin = plugin;

}

public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

Expand All @@ -27,7 +35,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,

if (args.length == 0) {

if (!cmdsender.hasPermission("spectate.help") && !cmdsender.hasPermission("spectate.use")) {
if (!cmdsender.hasPermission("spectate.help") && !cmdsender.hasPermission("spectate.on") && !cmdsender.hasPermission("spectate.off")) {

cmdsender.sendMessage(ChatColor.RED + "You do not have permission.");
return true;
Expand All @@ -41,7 +49,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,

if (args[0].equalsIgnoreCase("off")) {

if (!cmdsender.hasPermission("spectate.use")) {
if (!cmdsender.hasPermission("spectate.off")) {

cmdsender.sendMessage(ChatColor.RED + "You do not have permission.");
return true;
Expand Down Expand Up @@ -239,7 +247,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,

}else if (args[0].equalsIgnoreCase("help")) {

if (!cmdsender.hasPermission("spectate.help") && !cmdsender.hasPermission("spectate.use")) {
if (!cmdsender.hasPermission("spectate.help") && !cmdsender.hasPermission("spectate.on") && !cmdsender.hasPermission("spectate.off")) {

cmdsender.sendMessage(ChatColor.RED + "You do not have permission.");
return true;
Expand All @@ -251,7 +259,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,

}

if (!cmdsender.hasPermission("spectate.use")) {
if (!cmdsender.hasPermission("spectate.on")) {

cmdsender.sendMessage(ChatColor.RED + "You do not have permission.");
return true;
Expand All @@ -273,6 +281,17 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
return true;

}

if (plugin.cantspectate_permission_enabled) {

if (targetPlayer.hasPermission("spectate.cantspectate")) {

cmdsender.sendMessage(ChatColor.GRAY + "This person can not be spectated.");
return true;

}

}

if (Spectate.getAPI().isSpectating(cmdsender)) {

Expand Down
10 changes: 5 additions & 5 deletions src/com/Chipmunk9998/Spectate/SpectateListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ public void onPlayerQuit(PlayerQuitEvent event) {
Bukkit.getServer().getPluginManager().callEvent(scrollEvent);

ArrayList<Player> playerList = scrollEvent.getSpectateList();

playerList.remove(p);
playerList.remove(event.getPlayer());

p.sendMessage(ChatColor.GRAY + "The person you were previously spectating has disconnected.");

if (!Spectate.getAPI().scrollRight(p, playerList)) {

Spectate.getAPI().stopSpectating(p, true);
p.sendMessage(ChatColor.GRAY + "You were forced to stop spectating because there is nobody left to spectate.");

Expand Down Expand Up @@ -106,14 +106,14 @@ public void onPlayerDeath(PlayerDeathEvent event) {
Bukkit.getServer().getPluginManager().callEvent(scrollEvent);

ArrayList<Player> playerList = scrollEvent.getSpectateList();

playerList.remove(p);
playerList.remove(event.getEntity());

p.sendMessage(ChatColor.GRAY + "The person you were previously spectating has died.");

if (!Spectate.getAPI().scrollRight(p, playerList)) {

Spectate.getAPI().stopSpectating(p, true);
p.sendMessage(ChatColor.GRAY + "You were forced to stop spectating because there is nobody left to spectate.");

Expand Down Expand Up @@ -346,7 +346,7 @@ public void onInventoryClick(InventoryClickEvent event) {
}

}

@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {

Expand Down
Loading

0 comments on commit d839d9b

Please sign in to comment.