Convert godmode over to using entity metadata
Remove old CommandBook-has-GodComponent checks (mostly) Cleaned up some trailing whitespace
This commit is contained in:
parent
16ce56c1ad
commit
3d50486dac
|
@ -22,11 +22,10 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.sk89q.commandbook.CommandBook;
|
|
||||||
import com.sk89q.commandbook.GodComponent;
|
|
||||||
import com.sk89q.util.yaml.YAMLFormat;
|
import com.sk89q.util.yaml.YAMLFormat;
|
||||||
import com.sk89q.util.yaml.YAMLProcessor;
|
import com.sk89q.util.yaml.YAMLProcessor;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
@ -34,6 +33,8 @@ import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
import com.sk89q.worldguard.blacklist.Blacklist;
|
import com.sk89q.worldguard.blacklist.Blacklist;
|
||||||
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
import org.bukkit.metadata.MetadataValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the global configuration and also delegates configuration
|
* Represents the global configuration and also delegates configuration
|
||||||
|
@ -44,6 +45,8 @@ import com.sk89q.worldguard.blacklist.Blacklist;
|
||||||
*/
|
*/
|
||||||
public class ConfigurationManager {
|
public class ConfigurationManager {
|
||||||
|
|
||||||
|
public static final String GOD_METADATA_KEY = "god";
|
||||||
|
|
||||||
private static final String CONFIG_HEADER = "#\r\n" +
|
private static final String CONFIG_HEADER = "#\r\n" +
|
||||||
"# WorldGuard's main configuration file\r\n" +
|
"# WorldGuard's main configuration file\r\n" +
|
||||||
"#\r\n" +
|
"#\r\n" +
|
||||||
|
@ -80,24 +83,16 @@ public class ConfigurationManager {
|
||||||
*/
|
*/
|
||||||
private YAMLProcessor config;
|
private YAMLProcessor config;
|
||||||
|
|
||||||
/**
|
|
||||||
* List of people with god mode.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private Set<String> hasGodMode = new HashSet<String>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of people who can breathe underwater.
|
* List of people who can breathe underwater.
|
||||||
*/
|
*/
|
||||||
private Set<String> hasAmphibious = new HashSet<String>();
|
private Set<String> hasAmphibious = new HashSet<String>();
|
||||||
|
|
||||||
private boolean hasCommandBookGodMode = false;
|
|
||||||
|
|
||||||
public boolean useRegionsScheduler;
|
public boolean useRegionsScheduler;
|
||||||
public boolean activityHaltToggle = false;
|
public boolean activityHaltToggle = false;
|
||||||
public boolean autoGodMode;
|
@Deprecated public boolean autoGodMode = false;
|
||||||
public boolean usePlayerMove;
|
public boolean usePlayerMove;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Region Storage Configuration method, and config values
|
* Region Storage Configuration method, and config values
|
||||||
*/
|
*/
|
||||||
|
@ -131,14 +126,10 @@ public class ConfigurationManager {
|
||||||
plugin.getLogger().severe("Error reading configuration for global config: ");
|
plugin.getLogger().severe("Error reading configuration for global config: ");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
config.removeProperty("suppress-tick-sync-warnings");
|
config.removeProperty("suppress-tick-sync-warnings");
|
||||||
useRegionsScheduler = config.getBoolean(
|
useRegionsScheduler = config.getBoolean("regions.use-scheduler", true);
|
||||||
"regions.use-scheduler", true);
|
usePlayerMove = config.getBoolean("use-player-move-event", true);
|
||||||
autoGodMode = config.getBoolean(
|
|
||||||
"auto-invincible", config.getBoolean("auto-invincible-permission", false));
|
|
||||||
usePlayerMove = config.getBoolean(
|
|
||||||
"use-player-move-event", true);
|
|
||||||
|
|
||||||
useSqlDatabase = config.getBoolean(
|
useSqlDatabase = config.getBoolean(
|
||||||
"regions.sql.use", false);
|
"regions.sql.use", false);
|
||||||
|
@ -199,8 +190,6 @@ public class ConfigurationManager {
|
||||||
bl.forgetPlayer(player);
|
bl.forgetPlayer(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hasGodMode.remove(player.getName());
|
|
||||||
hasAmphibious.remove(player.getName());
|
hasAmphibious.remove(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +200,9 @@ public class ConfigurationManager {
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void enableGodMode(Player player) {
|
public void enableGodMode(Player player) {
|
||||||
hasGodMode.add(player.getName());
|
if (!hasGodMode(player)) {
|
||||||
|
player.setMetadata(GOD_METADATA_KEY, new FixedMetadataValue(plugin, true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -221,7 +212,7 @@ public class ConfigurationManager {
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void disableGodMode(Player player) {
|
public void disableGodMode(Player player) {
|
||||||
hasGodMode.remove(player.getName());
|
player.removeMetadata(GOD_METADATA_KEY, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -231,13 +222,20 @@ public class ConfigurationManager {
|
||||||
* @return Whether the player has godmode through WorldGuard or CommandBook
|
* @return Whether the player has godmode through WorldGuard or CommandBook
|
||||||
*/
|
*/
|
||||||
public boolean hasGodMode(Player player) {
|
public boolean hasGodMode(Player player) {
|
||||||
if (hasCommandBookGodMode) {
|
List<MetadataValue> values = player.getMetadata(GOD_METADATA_KEY);
|
||||||
GodComponent god = CommandBook.inst().getComponentManager().getComponent(GodComponent.class);
|
switch (values.size()) {
|
||||||
if (god != null) {
|
case 0:
|
||||||
return god.hasGodMode(player);
|
return false;
|
||||||
}
|
case 1:
|
||||||
|
return values.get(0).asBoolean();
|
||||||
|
default:
|
||||||
|
for (MetadataValue val : values) {
|
||||||
|
if (val.asBoolean()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return hasGodMode.contains(player.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -267,19 +265,13 @@ public class ConfigurationManager {
|
||||||
public boolean hasAmphibiousMode(Player player) {
|
public boolean hasAmphibiousMode(Player player) {
|
||||||
return hasAmphibious.contains(player.getName());
|
return hasAmphibious.contains(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateCommandBookGodMode() {
|
|
||||||
try {
|
|
||||||
if (plugin.getServer().getPluginManager().isPluginEnabled("CommandBook")) {
|
|
||||||
Class.forName("com.sk89q.commandbook.GodComponent");
|
|
||||||
hasCommandBookGodMode = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (ClassNotFoundException ignore) {}
|
|
||||||
hasCommandBookGodMode = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasCommandBookGodMode() {
|
public boolean hasCommandBookGodMode() {
|
||||||
return hasCommandBookGodMode;
|
try {
|
||||||
|
Class.forName("com.sk89q.commandbook.GodComponent");
|
||||||
|
return true;
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ public class WorldGuardPlugin extends JavaPlugin {
|
||||||
reg.register(GeneralCommands.class);
|
reg.register(GeneralCommands.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 0L);
|
}, 1L);
|
||||||
|
|
||||||
// Need to create the plugins/WorldGuard folder
|
// Need to create the plugins/WorldGuard folder
|
||||||
getDataFolder().mkdirs();
|
getDataFolder().mkdirs();
|
||||||
|
@ -153,7 +153,6 @@ public class WorldGuardPlugin extends JavaPlugin {
|
||||||
(new WorldGuardEntityListener(this)).registerEvents();
|
(new WorldGuardEntityListener(this)).registerEvents();
|
||||||
(new WorldGuardWeatherListener(this)).registerEvents();
|
(new WorldGuardWeatherListener(this)).registerEvents();
|
||||||
(new WorldGuardVehicleListener(this)).registerEvents();
|
(new WorldGuardVehicleListener(this)).registerEvents();
|
||||||
(new WorldGuardServerListener(this)).registerEvents();
|
|
||||||
|
|
||||||
if (getServer().getPluginManager().isPluginEnabled("CommandBook")) {
|
if (getServer().getPluginManager().isPluginEnabled("CommandBook")) {
|
||||||
getServer().getPluginManager().registerEvents(new WorldGuardCommandBookListener(this), this);
|
getServer().getPluginManager().registerEvents(new WorldGuardCommandBookListener(this), this);
|
||||||
|
@ -165,16 +164,6 @@ public class WorldGuardPlugin extends JavaPlugin {
|
||||||
worldListener.initWorld(world);
|
worldListener.initWorld(world);
|
||||||
}
|
}
|
||||||
worldListener.registerEvents();
|
worldListener.registerEvents();
|
||||||
|
|
||||||
if (!configuration.hasCommandBookGodMode()) {
|
|
||||||
// Check god mode for existing players, if any
|
|
||||||
for (Player player : getServer().getOnlinePlayers()) {
|
|
||||||
if (inGroup(player, "wg-invincible") ||
|
|
||||||
(configuration.autoGodMode && hasPermission(player, "worldguard.auto-invincible"))) {
|
|
||||||
configuration.enableGodMode(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
package com.sk89q.worldguard.bukkit;
|
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.server.PluginDisableEvent;
|
|
||||||
import org.bukkit.event.server.PluginEnableEvent;
|
|
||||||
import org.bukkit.plugin.PluginManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zml2008
|
|
||||||
*/
|
|
||||||
public class WorldGuardServerListener implements Listener {
|
|
||||||
|
|
||||||
private final WorldGuardPlugin plugin;
|
|
||||||
|
|
||||||
public WorldGuardServerListener(WorldGuardPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerEvents() {
|
|
||||||
PluginManager pm = plugin.getServer().getPluginManager();
|
|
||||||
pm.registerEvents(this, plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPluginEnable(PluginEnableEvent event) {
|
|
||||||
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("CommandBook")) {
|
|
||||||
plugin.getGlobalStateManager().updateCommandBookGodMode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPluginDisable(PluginDisableEvent event) {
|
|
||||||
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("CommandBook")) {
|
|
||||||
plugin.getGlobalStateManager().updateCommandBookGodMode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -38,25 +38,25 @@ public class GeneralCommands {
|
||||||
public GeneralCommands(WorldGuardPlugin plugin) {
|
public GeneralCommands(WorldGuardPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Command(aliases = {"god"}, usage = "[player]",
|
@Command(aliases = {"god"}, usage = "[player]",
|
||||||
desc = "Enable godmode on a player", flags = "s", max = 1)
|
desc = "Enable godmode on a player", flags = "s", max = 1)
|
||||||
public void god(CommandContext args, CommandSender sender) throws CommandException {
|
public void god(CommandContext args, CommandSender sender) throws CommandException {
|
||||||
ConfigurationManager config = plugin.getGlobalStateManager();
|
ConfigurationManager config = plugin.getGlobalStateManager();
|
||||||
|
|
||||||
Iterable<Player> targets = null;
|
Iterable<Player> targets = null;
|
||||||
boolean included = false;
|
boolean included = false;
|
||||||
|
|
||||||
// Detect arguments based on the number of arguments provided
|
// Detect arguments based on the number of arguments provided
|
||||||
if (args.argsLength() == 0) {
|
if (args.argsLength() == 0) {
|
||||||
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
||||||
|
|
||||||
// Check permissions!
|
// Check permissions!
|
||||||
plugin.checkPermission(sender, "worldguard.god");
|
plugin.checkPermission(sender, "worldguard.god");
|
||||||
} else if (args.argsLength() == 1) {
|
} else if (args.argsLength() == 1) {
|
||||||
targets = plugin.matchPlayers(sender, args.getString(0));
|
targets = plugin.matchPlayers(sender, args.getString(0));
|
||||||
|
|
||||||
// Check permissions!
|
// Check permissions!
|
||||||
plugin.checkPermission(sender, "worldguard.god.other");
|
plugin.checkPermission(sender, "worldguard.god.other");
|
||||||
}
|
}
|
||||||
|
@ -64,87 +64,87 @@ public class GeneralCommands {
|
||||||
for (Player player : targets) {
|
for (Player player : targets) {
|
||||||
config.enableGodMode(player);
|
config.enableGodMode(player);
|
||||||
player.setFireTicks(0);
|
player.setFireTicks(0);
|
||||||
|
|
||||||
// Tell the user
|
// Tell the user
|
||||||
if (player.equals(sender)) {
|
if (player.equals(sender)) {
|
||||||
player.sendMessage(ChatColor.YELLOW + "God mode enabled! Use /ungod to disable.");
|
player.sendMessage(ChatColor.YELLOW + "God mode enabled! Use /ungod to disable.");
|
||||||
|
|
||||||
// Keep track of this
|
// Keep track of this
|
||||||
included = true;
|
included = true;
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.YELLOW + "God enabled by "
|
player.sendMessage(ChatColor.YELLOW + "God enabled by "
|
||||||
+ plugin.toName(sender) + ".");
|
+ plugin.toName(sender) + ".");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The player didn't receive any items, then we need to send the
|
// The player didn't receive any items, then we need to send the
|
||||||
// user a message so s/he know that something is indeed working
|
// user a message so s/he know that something is indeed working
|
||||||
if (!included && args.hasFlag('s')) {
|
if (!included && args.hasFlag('s')) {
|
||||||
sender.sendMessage(ChatColor.YELLOW.toString() + "Players now have god mode.");
|
sender.sendMessage(ChatColor.YELLOW.toString() + "Players now have god mode.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Command(aliases = {"ungod"}, usage = "[player]",
|
@Command(aliases = {"ungod"}, usage = "[player]",
|
||||||
desc = "Disable godmode on a player", flags = "s", max = 1)
|
desc = "Disable godmode on a player", flags = "s", max = 1)
|
||||||
public void ungod(CommandContext args, CommandSender sender) throws CommandException {
|
public void ungod(CommandContext args, CommandSender sender) throws CommandException {
|
||||||
ConfigurationManager config = plugin.getGlobalStateManager();
|
ConfigurationManager config = plugin.getGlobalStateManager();
|
||||||
|
|
||||||
Iterable<Player> targets = null;
|
Iterable<Player> targets = null;
|
||||||
boolean included = false;
|
boolean included = false;
|
||||||
|
|
||||||
// Detect arguments based on the number of arguments provided
|
// Detect arguments based on the number of arguments provided
|
||||||
if (args.argsLength() == 0) {
|
if (args.argsLength() == 0) {
|
||||||
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
||||||
|
|
||||||
// Check permissions!
|
// Check permissions!
|
||||||
plugin.checkPermission(sender, "worldguard.god");
|
plugin.checkPermission(sender, "worldguard.god");
|
||||||
} else if (args.argsLength() == 1) {
|
} else if (args.argsLength() == 1) {
|
||||||
targets = plugin.matchPlayers(sender, args.getString(0));
|
targets = plugin.matchPlayers(sender, args.getString(0));
|
||||||
|
|
||||||
// Check permissions!
|
// Check permissions!
|
||||||
plugin.checkPermission(sender, "worldguard.god.other");
|
plugin.checkPermission(sender, "worldguard.god.other");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Player player : targets) {
|
for (Player player : targets) {
|
||||||
config.disableGodMode(player);
|
config.disableGodMode(player);
|
||||||
|
|
||||||
// Tell the user
|
// Tell the user
|
||||||
if (player.equals(sender)) {
|
if (player.equals(sender)) {
|
||||||
player.sendMessage(ChatColor.YELLOW + "God mode disabled!");
|
player.sendMessage(ChatColor.YELLOW + "God mode disabled!");
|
||||||
|
|
||||||
// Keep track of this
|
// Keep track of this
|
||||||
included = true;
|
included = true;
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.YELLOW + "God disabled by "
|
player.sendMessage(ChatColor.YELLOW + "God disabled by "
|
||||||
+ plugin.toName(sender) + ".");
|
+ plugin.toName(sender) + ".");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The player didn't receive any items, then we need to send the
|
// The player didn't receive any items, then we need to send the
|
||||||
// user a message so s/he know that something is indeed working
|
// user a message so s/he know that something is indeed working
|
||||||
if (!included && args.hasFlag('s')) {
|
if (!included && args.hasFlag('s')) {
|
||||||
sender.sendMessage(ChatColor.YELLOW.toString() + "Players no longer have god mode.");
|
sender.sendMessage(ChatColor.YELLOW.toString() + "Players no longer have god mode.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(aliases = {"heal"}, usage = "[player]", desc = "Heal a player", flags = "s", max = 1)
|
@Command(aliases = {"heal"}, usage = "[player]", desc = "Heal a player", flags = "s", max = 1)
|
||||||
public void heal(CommandContext args,CommandSender sender) throws CommandException {
|
public void heal(CommandContext args,CommandSender sender) throws CommandException {
|
||||||
|
|
||||||
Iterable<Player> targets = null;
|
Iterable<Player> targets = null;
|
||||||
boolean included = false;
|
boolean included = false;
|
||||||
|
|
||||||
// Detect arguments based on the number of arguments provided
|
// Detect arguments based on the number of arguments provided
|
||||||
if (args.argsLength() == 0) {
|
if (args.argsLength() == 0) {
|
||||||
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
||||||
|
|
||||||
// Check permissions!
|
// Check permissions!
|
||||||
plugin.checkPermission(sender, "worldguard.heal");
|
plugin.checkPermission(sender, "worldguard.heal");
|
||||||
} else if (args.argsLength() == 1) {
|
} else if (args.argsLength() == 1) {
|
||||||
targets = plugin.matchPlayers(sender, args.getString(0));
|
targets = plugin.matchPlayers(sender, args.getString(0));
|
||||||
|
|
||||||
// Check permissions!
|
// Check permissions!
|
||||||
plugin.checkPermission(sender, "worldguard.heal.other");
|
plugin.checkPermission(sender, "worldguard.heal.other");
|
||||||
}
|
}
|
||||||
|
@ -152,100 +152,100 @@ public class GeneralCommands {
|
||||||
for (Player player : targets) {
|
for (Player player : targets) {
|
||||||
player.setHealth(20);
|
player.setHealth(20);
|
||||||
player.setFoodLevel(20);
|
player.setFoodLevel(20);
|
||||||
|
|
||||||
// Tell the user
|
// Tell the user
|
||||||
if (player.equals(sender)) {
|
if (player.equals(sender)) {
|
||||||
player.sendMessage(ChatColor.YELLOW + "Healed!");
|
player.sendMessage(ChatColor.YELLOW + "Healed!");
|
||||||
|
|
||||||
// Keep track of this
|
// Keep track of this
|
||||||
included = true;
|
included = true;
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.YELLOW + "Healed by "
|
player.sendMessage(ChatColor.YELLOW + "Healed by "
|
||||||
+ plugin.toName(sender) + ".");
|
+ plugin.toName(sender) + ".");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The player didn't receive any items, then we need to send the
|
// The player didn't receive any items, then we need to send the
|
||||||
// user a message so s/he know that something is indeed working
|
// user a message so s/he know that something is indeed working
|
||||||
if (!included && args.hasFlag('s')) {
|
if (!included && args.hasFlag('s')) {
|
||||||
sender.sendMessage(ChatColor.YELLOW.toString() + "Players healed.");
|
sender.sendMessage(ChatColor.YELLOW.toString() + "Players healed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(aliases = {"slay"}, usage = "[player]", desc = "Slay a player", flags = "s", max = 1)
|
@Command(aliases = {"slay"}, usage = "[player]", desc = "Slay a player", flags = "s", max = 1)
|
||||||
public void slay(CommandContext args, CommandSender sender) throws CommandException {
|
public void slay(CommandContext args, CommandSender sender) throws CommandException {
|
||||||
|
|
||||||
Iterable<Player> targets = null;
|
Iterable<Player> targets = null;
|
||||||
boolean included = false;
|
boolean included = false;
|
||||||
|
|
||||||
// Detect arguments based on the number of arguments provided
|
// Detect arguments based on the number of arguments provided
|
||||||
if (args.argsLength() == 0) {
|
if (args.argsLength() == 0) {
|
||||||
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
||||||
|
|
||||||
// Check permissions!
|
// Check permissions!
|
||||||
plugin.checkPermission(sender, "worldguard.slay");
|
plugin.checkPermission(sender, "worldguard.slay");
|
||||||
} else if (args.argsLength() == 1) {
|
} else if (args.argsLength() == 1) {
|
||||||
targets = plugin.matchPlayers(sender, args.getString(0));
|
targets = plugin.matchPlayers(sender, args.getString(0));
|
||||||
|
|
||||||
// Check permissions!
|
// Check permissions!
|
||||||
plugin.checkPermission(sender, "worldguard.slay.other");
|
plugin.checkPermission(sender, "worldguard.slay.other");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Player player : targets) {
|
for (Player player : targets) {
|
||||||
player.setHealth(0);
|
player.setHealth(0);
|
||||||
|
|
||||||
// Tell the user
|
// Tell the user
|
||||||
if (player.equals(sender)) {
|
if (player.equals(sender)) {
|
||||||
player.sendMessage(ChatColor.YELLOW + "Slain!");
|
player.sendMessage(ChatColor.YELLOW + "Slain!");
|
||||||
|
|
||||||
// Keep track of this
|
// Keep track of this
|
||||||
included = true;
|
included = true;
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.YELLOW + "Slain by "
|
player.sendMessage(ChatColor.YELLOW + "Slain by "
|
||||||
+ plugin.toName(sender) + ".");
|
+ plugin.toName(sender) + ".");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The player didn't receive any items, then we need to send the
|
// The player didn't receive any items, then we need to send the
|
||||||
// user a message so s/he know that something is indeed working
|
// user a message so s/he know that something is indeed working
|
||||||
if (!included && args.hasFlag('s')) {
|
if (!included && args.hasFlag('s')) {
|
||||||
sender.sendMessage(ChatColor.YELLOW.toString() + "Players slain.");
|
sender.sendMessage(ChatColor.YELLOW.toString() + "Players slain.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(aliases = {"locate"}, usage = "[player]", desc = "Locate a player", max = 1)
|
@Command(aliases = {"locate"}, usage = "[player]", desc = "Locate a player", max = 1)
|
||||||
@CommandPermissions({"worldguard.locate"})
|
@CommandPermissions({"worldguard.locate"})
|
||||||
public void locate(CommandContext args, CommandSender sender) throws CommandException {
|
public void locate(CommandContext args, CommandSender sender) throws CommandException {
|
||||||
|
|
||||||
Player player = plugin.checkPlayer(sender);
|
Player player = plugin.checkPlayer(sender);
|
||||||
|
|
||||||
if (args.argsLength() == 0) {
|
if (args.argsLength() == 0) {
|
||||||
player.setCompassTarget(player.getWorld().getSpawnLocation());
|
player.setCompassTarget(player.getWorld().getSpawnLocation());
|
||||||
|
|
||||||
sender.sendMessage(ChatColor.YELLOW.toString() + "Compass reset to spawn.");
|
sender.sendMessage(ChatColor.YELLOW.toString() + "Compass reset to spawn.");
|
||||||
} else {
|
} else {
|
||||||
Player target = plugin.matchSinglePlayer(sender, args.getString(0));
|
Player target = plugin.matchSinglePlayer(sender, args.getString(0));
|
||||||
player.setCompassTarget(target.getLocation());
|
player.setCompassTarget(target.getLocation());
|
||||||
|
|
||||||
sender.sendMessage(ChatColor.YELLOW.toString() + "Compass repointed.");
|
sender.sendMessage(ChatColor.YELLOW.toString() + "Compass repointed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(aliases = {"stack", ";"}, usage = "", desc = "Stack items", max = 0)
|
@Command(aliases = {"stack", ";"}, usage = "", desc = "Stack items", max = 0)
|
||||||
@CommandPermissions({"worldguard.stack"})
|
@CommandPermissions({"worldguard.stack"})
|
||||||
public void stack(CommandContext args, CommandSender sender) throws CommandException {
|
public void stack(CommandContext args, CommandSender sender) throws CommandException {
|
||||||
|
|
||||||
Player player = plugin.checkPlayer(sender);
|
Player player = plugin.checkPlayer(sender);
|
||||||
boolean ignoreMax = plugin.hasPermission(player, "worldguard.stack.illegitimate");
|
boolean ignoreMax = plugin.hasPermission(player, "worldguard.stack.illegitimate");
|
||||||
boolean ignoreDamaged = plugin.hasPermission(player, "worldguard.stack.damaged");
|
boolean ignoreDamaged = plugin.hasPermission(player, "worldguard.stack.damaged");
|
||||||
|
|
||||||
ItemStack[] items = player.getInventory().getContents();
|
ItemStack[] items = player.getInventory().getContents();
|
||||||
int len = items.length;
|
int len = items.length;
|
||||||
|
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
|
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
ItemStack item = items[i];
|
ItemStack item = items[i];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue