mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-24 11:36:11 +01:00
Added fallback support for those who don't have a version of CommandBook with GodComponent
This commit is contained in:
parent
da9bc4a138
commit
e25049b1d6
@ -25,6 +25,8 @@
|
|||||||
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;
|
||||||
@ -73,11 +75,19 @@ public class ConfigurationManager {
|
|||||||
*/
|
*/
|
||||||
private Map<String, WorldConfiguration> worlds;
|
private Map<String, WorldConfiguration> worlds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 suppressTickSyncWarnings;
|
public boolean suppressTickSyncWarnings;
|
||||||
public boolean useRegionsScheduler;
|
public boolean useRegionsScheduler;
|
||||||
public boolean activityHaltToggle = false;
|
public boolean activityHaltToggle = false;
|
||||||
@ -171,9 +181,47 @@ public void forgetPlayer(LocalPlayer player) {
|
|||||||
bl.forgetPlayer(player);
|
bl.forgetPlayer(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasGodMode.remove(player.getName());
|
||||||
hasAmphibious.remove(player.getName());
|
hasAmphibious.remove(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable god mode for a player.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public void enableGodMode(Player player) {
|
||||||
|
hasGodMode.add(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable god mode for a player.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public void disableGodMode(Player player) {
|
||||||
|
hasGodMode.remove(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if god mode is enabled for a player.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean hasGodMode(Player player) {
|
||||||
|
if (hasCommandBookGodMode) {
|
||||||
|
GodComponent god = CommandBook.inst().getComponentManager().getComponent(GodComponent.class);
|
||||||
|
if (god != null) {
|
||||||
|
return god.hasGodMode(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hasGodMode.contains(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable amphibious mode for a player.
|
* Enable amphibious mode for a player.
|
||||||
*
|
*
|
||||||
@ -201,4 +249,19 @@ public void disableAmphibiousMode(Player player) {
|
|||||||
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() {
|
||||||
|
return hasCommandBookGodMode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ public static void migrateRegions(WorldGuardPlugin plugin) {
|
|||||||
|
|
||||||
logger.info("WorldGuard: The regions database has changed in 5.x. "
|
logger.info("WorldGuard: The regions database has changed in 5.x. "
|
||||||
+ "Your old regions database will be converted to the new format "
|
+ "Your old regions database will be converted to the new format "
|
||||||
+ "and set as your primarily world's database.");
|
+ "and set as your primary world's database.");
|
||||||
|
|
||||||
World w = plugin.getServer().getWorlds().get(0);
|
World w = plugin.getServer().getWorlds().get(0);
|
||||||
RegionManager mgr = plugin.getGlobalRegionManager().get(w);
|
RegionManager mgr = plugin.getGlobalRegionManager().get(w);
|
||||||
|
@ -530,7 +530,7 @@ public void onEntityCombust(EntityCombustEvent event) {
|
|||||||
if (entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
Player player = (Player) entity;
|
Player player = (Player) entity;
|
||||||
|
|
||||||
if ((wcfg.useRegions && RegionQueryUtil.isInvincible(plugin, player))) {
|
if (cfg.hasGodMode(player) || (wcfg.useRegions && RegionQueryUtil.isInvincible(plugin, player))) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -914,7 +914,7 @@ private boolean isInvincible(Player player) {
|
|||||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||||
|
|
||||||
boolean god = RegionQueryUtil.hasGodMode(player, plugin);
|
boolean god = cfg.hasGodMode(player);
|
||||||
if (wcfg.useRegions) {
|
if (wcfg.useRegions) {
|
||||||
Boolean flag = RegionQueryUtil.isAllowedInvinciblity(plugin, player);
|
Boolean flag = RegionQueryUtil.isAllowedInvinciblity(plugin, player);
|
||||||
boolean allowed = flag == null || flag == Boolean.TRUE;
|
boolean allowed = flag == null || flag == Boolean.TRUE;
|
||||||
|
@ -133,6 +133,7 @@ private void registerEvent(String typeName, Priority priority) {
|
|||||||
/**
|
/**
|
||||||
* Called when a player joins a server.
|
* Called when a player joins a server.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
@ -165,6 +166,11 @@ public void onPlayerJoin(PlayerJoinEvent event) {
|
|||||||
+ "Fire spread is currently globally disabled for this world.");
|
+ "Fire spread is currently globally disabled for this world.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cfg.hasCommandBookGodMode() && cfg.autoGodMode && (plugin.inGroup(player, "wg-invincible")
|
||||||
|
|| plugin.hasPermission(player, "worldguard.auto-invincible"))) {
|
||||||
|
cfg.enableGodMode(player);
|
||||||
|
}
|
||||||
|
|
||||||
if (plugin.inGroup(player, "wg-amphibious")) {
|
if (plugin.inGroup(player, "wg-amphibious")) {
|
||||||
cfg.enableAmphibiousMode(player);
|
cfg.enableAmphibiousMode(player);
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
import com.sk89q.worldguard.TickSyncDelayLoggerFilter;
|
import com.sk89q.worldguard.TickSyncDelayLoggerFilter;
|
||||||
|
import com.sk89q.worldguard.bukkit.commands.GeneralCommands;
|
||||||
import com.sk89q.worldguard.bukkit.commands.ProtectionCommands;
|
import com.sk89q.worldguard.bukkit.commands.ProtectionCommands;
|
||||||
import com.sk89q.worldguard.bukkit.commands.ToggleCommands;
|
import com.sk89q.worldguard.bukkit.commands.ToggleCommands;
|
||||||
import com.sk89q.worldguard.protection.GlobalRegionManager;
|
import com.sk89q.worldguard.protection.GlobalRegionManager;
|
||||||
@ -108,6 +109,7 @@ public boolean hasPermission(CommandSender player, String perm) {
|
|||||||
/**
|
/**
|
||||||
* Called on plugin enable.
|
* Called on plugin enable.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
|
||||||
// Set the proper command injector
|
// Set the proper command injector
|
||||||
@ -118,6 +120,15 @@ public void onEnable() {
|
|||||||
reg.register(ToggleCommands.class);
|
reg.register(ToggleCommands.class);
|
||||||
reg.register(ProtectionCommands.class);
|
reg.register(ProtectionCommands.class);
|
||||||
|
|
||||||
|
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!getGlobalStateManager().hasCommandBookGodMode()) {
|
||||||
|
reg.register(GeneralCommands.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0L);
|
||||||
|
|
||||||
// Need to create the plugins/WorldGuard folder
|
// Need to create the plugins/WorldGuard folder
|
||||||
getDataFolder().mkdirs();
|
getDataFolder().mkdirs();
|
||||||
|
|
||||||
@ -156,6 +167,7 @@ public void onEnable() {
|
|||||||
(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();
|
||||||
|
|
||||||
// handle worlds separately to initialize already loaded worlds
|
// handle worlds separately to initialize already loaded worlds
|
||||||
WorldGuardWorldListener worldListener = (new WorldGuardWorldListener(this));
|
WorldGuardWorldListener worldListener = (new WorldGuardWorldListener(this));
|
||||||
@ -164,6 +176,16 @@ public void onEnable() {
|
|||||||
}
|
}
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("WorldGuard " + this.getDescription().getVersion() + " enabled.");
|
logger.info("WorldGuard " + this.getDescription().getVersion() + " enabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
package com.sk89q.worldguard.bukkit;
|
||||||
|
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
|
import org.bukkit.event.server.ServerListener;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zml2008
|
||||||
|
*/
|
||||||
|
public class WorldGuardServerListener extends ServerListener {
|
||||||
|
|
||||||
|
private final WorldGuardPlugin plugin;
|
||||||
|
|
||||||
|
public WorldGuardServerListener(WorldGuardPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerEvents() {
|
||||||
|
registerEvent("PLUGIN_ENABLE");
|
||||||
|
registerEvent("PLUGIN_DISABLE");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register an event, but not failing if the event is not implemented.
|
||||||
|
*
|
||||||
|
* @param typeName
|
||||||
|
*/
|
||||||
|
private void registerEvent(String typeName) {
|
||||||
|
try {
|
||||||
|
Event.Type type = Event.Type.valueOf(typeName);
|
||||||
|
PluginManager pm = plugin.getServer().getPluginManager();
|
||||||
|
pm.registerEvent(type, this, Event.Priority.Normal, plugin);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
WorldGuardPlugin.logger.info("WorldGuard: Unable to register missing event type " + typeName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPluginEnable(PluginEnableEvent event) {
|
||||||
|
plugin.getGlobalStateManager().updateCommandBookGodMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPluginDisable(PluginDisableEvent event) {
|
||||||
|
plugin.getGlobalStateManager().updateCommandBookGodMode();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,303 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldGuard
|
||||||
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldguard.bukkit.commands;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import com.sk89q.minecraft.util.commands.Command;
|
||||||
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||||
|
import com.sk89q.minecraft.util.commands.CommandException;
|
||||||
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||||
|
import com.sk89q.worldedit.blocks.ItemType;
|
||||||
|
import com.sk89q.worldguard.bukkit.ConfigurationManager;
|
||||||
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
|
||||||
|
public class GeneralCommands {
|
||||||
|
private final WorldGuardPlugin plugin;
|
||||||
|
|
||||||
|
public GeneralCommands(WorldGuardPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Command(aliases = {"god"}, usage = "[player]",
|
||||||
|
desc = "Enable godmode on a player", flags = "s", max = 1)
|
||||||
|
public void god(CommandContext args, CommandSender sender) throws CommandException {
|
||||||
|
ConfigurationManager config = plugin.getGlobalStateManager();
|
||||||
|
|
||||||
|
Iterable<Player> targets = null;
|
||||||
|
boolean included = false;
|
||||||
|
|
||||||
|
// Detect arguments based on the number of arguments provided
|
||||||
|
if (args.argsLength() == 0) {
|
||||||
|
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
||||||
|
|
||||||
|
// Check permissions!
|
||||||
|
plugin.checkPermission(sender, "worldguard.god");
|
||||||
|
} else if (args.argsLength() == 1) {
|
||||||
|
targets = plugin.matchPlayers(sender, args.getString(0));
|
||||||
|
|
||||||
|
// Check permissions!
|
||||||
|
plugin.checkPermission(sender, "worldguard.god.other");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player player : targets) {
|
||||||
|
config.enableGodMode(player);
|
||||||
|
player.setFireTicks(0);
|
||||||
|
|
||||||
|
// Tell the user
|
||||||
|
if (player.equals(sender)) {
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "God mode enabled! Use /ungod to disable.");
|
||||||
|
|
||||||
|
// Keep track of this
|
||||||
|
included = true;
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "God enabled by "
|
||||||
|
+ plugin.toName(sender) + ".");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
if (!included && args.hasFlag('s')) {
|
||||||
|
sender.sendMessage(ChatColor.YELLOW.toString() + "Players now have god mode.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Command(aliases = {"ungod"}, usage = "[player]",
|
||||||
|
desc = "Disable godmode on a player", flags = "s", max = 1)
|
||||||
|
public void ungod(CommandContext args, CommandSender sender) throws CommandException {
|
||||||
|
ConfigurationManager config = plugin.getGlobalStateManager();
|
||||||
|
|
||||||
|
Iterable<Player> targets = null;
|
||||||
|
boolean included = false;
|
||||||
|
|
||||||
|
// Detect arguments based on the number of arguments provided
|
||||||
|
if (args.argsLength() == 0) {
|
||||||
|
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
||||||
|
|
||||||
|
// Check permissions!
|
||||||
|
plugin.checkPermission(sender, "worldguard.god");
|
||||||
|
} else if (args.argsLength() == 1) {
|
||||||
|
targets = plugin.matchPlayers(sender, args.getString(0));
|
||||||
|
|
||||||
|
// Check permissions!
|
||||||
|
plugin.checkPermission(sender, "worldguard.god.other");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player player : targets) {
|
||||||
|
config.disableGodMode(player);
|
||||||
|
|
||||||
|
// Tell the user
|
||||||
|
if (player.equals(sender)) {
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "God mode disabled!");
|
||||||
|
|
||||||
|
// Keep track of this
|
||||||
|
included = true;
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "God disabled by "
|
||||||
|
+ plugin.toName(sender) + ".");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
if (!included && args.hasFlag('s')) {
|
||||||
|
sender.sendMessage(ChatColor.YELLOW.toString() + "Players no longer have god mode.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command(aliases = {"heal"}, usage = "[player]", desc = "Heal a player", flags = "s", max = 1)
|
||||||
|
public void heal(CommandContext args,CommandSender sender) throws CommandException {
|
||||||
|
|
||||||
|
Iterable<Player> targets = null;
|
||||||
|
boolean included = false;
|
||||||
|
|
||||||
|
// Detect arguments based on the number of arguments provided
|
||||||
|
if (args.argsLength() == 0) {
|
||||||
|
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
||||||
|
|
||||||
|
// Check permissions!
|
||||||
|
plugin.checkPermission(sender, "worldguard.heal");
|
||||||
|
} else if (args.argsLength() == 1) {
|
||||||
|
targets = plugin.matchPlayers(sender, args.getString(0));
|
||||||
|
|
||||||
|
// Check permissions!
|
||||||
|
plugin.checkPermission(sender, "worldguard.heal.other");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player player : targets) {
|
||||||
|
player.setHealth(20);
|
||||||
|
player.setFoodLevel(20);
|
||||||
|
|
||||||
|
// Tell the user
|
||||||
|
if (player.equals(sender)) {
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "Healed!");
|
||||||
|
|
||||||
|
// Keep track of this
|
||||||
|
included = true;
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "Healed by "
|
||||||
|
+ plugin.toName(sender) + ".");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
if (!included && args.hasFlag('s')) {
|
||||||
|
sender.sendMessage(ChatColor.YELLOW.toString() + "Players healed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command(aliases = {"slay"}, usage = "[player]", desc = "Slay a player", flags = "s", max = 1)
|
||||||
|
public void slay(CommandContext args, CommandSender sender) throws CommandException {
|
||||||
|
|
||||||
|
Iterable<Player> targets = null;
|
||||||
|
boolean included = false;
|
||||||
|
|
||||||
|
// Detect arguments based on the number of arguments provided
|
||||||
|
if (args.argsLength() == 0) {
|
||||||
|
targets = plugin.matchPlayers(plugin.checkPlayer(sender));
|
||||||
|
|
||||||
|
// Check permissions!
|
||||||
|
plugin.checkPermission(sender, "worldguard.slay");
|
||||||
|
} else if (args.argsLength() == 1) {
|
||||||
|
targets = plugin.matchPlayers(sender, args.getString(0));
|
||||||
|
|
||||||
|
// Check permissions!
|
||||||
|
plugin.checkPermission(sender, "worldguard.slay.other");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player player : targets) {
|
||||||
|
player.setHealth(0);
|
||||||
|
|
||||||
|
// Tell the user
|
||||||
|
if (player.equals(sender)) {
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "Slain!");
|
||||||
|
|
||||||
|
// Keep track of this
|
||||||
|
included = true;
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "Slain by "
|
||||||
|
+ plugin.toName(sender) + ".");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
if (!included && args.hasFlag('s')) {
|
||||||
|
sender.sendMessage(ChatColor.YELLOW.toString() + "Players slain.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command(aliases = {"locate"}, usage = "[player]", desc = "Locate a player", max = 1)
|
||||||
|
@CommandPermissions({"worldguard.locate"})
|
||||||
|
public void locate(CommandContext args, CommandSender sender) throws CommandException {
|
||||||
|
|
||||||
|
Player player = plugin.checkPlayer(sender);
|
||||||
|
|
||||||
|
if (args.argsLength() == 0) {
|
||||||
|
player.setCompassTarget(player.getWorld().getSpawnLocation());
|
||||||
|
|
||||||
|
sender.sendMessage(ChatColor.YELLOW.toString() + "Compass reset to spawn.");
|
||||||
|
} else {
|
||||||
|
Player target = plugin.matchSinglePlayer(sender, args.getString(0));
|
||||||
|
player.setCompassTarget(target.getLocation());
|
||||||
|
|
||||||
|
sender.sendMessage(ChatColor.YELLOW.toString() + "Compass repointed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command(aliases = {"stack", ";"}, usage = "", desc = "Stack items", max = 0)
|
||||||
|
@CommandPermissions({"worldguard.stack"})
|
||||||
|
public void stack(CommandContext args, CommandSender sender) throws CommandException {
|
||||||
|
|
||||||
|
Player player = plugin.checkPlayer(sender);
|
||||||
|
boolean ignoreMax = plugin.hasPermission(player, "worldguard.stack.illegitimate");
|
||||||
|
boolean ignoreDamaged = plugin.hasPermission(player, "worldguard.stack.damaged");
|
||||||
|
|
||||||
|
ItemStack[] items = player.getInventory().getContents();
|
||||||
|
int len = items.length;
|
||||||
|
|
||||||
|
int affected = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
ItemStack item = items[i];
|
||||||
|
|
||||||
|
// Avoid infinite stacks and stacks with durability
|
||||||
|
if (item == null || item.getAmount() <= 0
|
||||||
|
|| (!ignoreMax && item.getMaxStackSize() == 1)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int max = ignoreMax ? 64 : item.getMaxStackSize();
|
||||||
|
|
||||||
|
if (item.getAmount() < max) {
|
||||||
|
int needed = max - item.getAmount(); // Number of needed items until max
|
||||||
|
|
||||||
|
// Find another stack of the same type
|
||||||
|
for (int j = i + 1; j < len; j++) {
|
||||||
|
ItemStack item2 = items[j];
|
||||||
|
|
||||||
|
// Avoid infinite stacks and stacks with durability
|
||||||
|
if (item2 == null || item2.getAmount() <= 0
|
||||||
|
|| (!ignoreMax && item.getMaxStackSize() == 1)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Same type?
|
||||||
|
// Blocks store their color in the damage value
|
||||||
|
if (item2.getTypeId() == item.getTypeId() &&
|
||||||
|
((!ItemType.usesDamageValue(item.getTypeId()) && ignoreDamaged)
|
||||||
|
|| item.getDurability() == item2.getDurability()) &&
|
||||||
|
item.getEnchantments().equals(item2.getEnchantments())) {
|
||||||
|
// This stack won't fit in the parent stack
|
||||||
|
if (item2.getAmount() > needed) {
|
||||||
|
item.setAmount(64);
|
||||||
|
item2.setAmount(item2.getAmount() - needed);
|
||||||
|
break;
|
||||||
|
// This stack will
|
||||||
|
} else {
|
||||||
|
items[j] = null;
|
||||||
|
item.setAmount(item.getAmount() + item2.getAmount());
|
||||||
|
needed = 64 - item.getAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
affected++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (affected > 0) {
|
||||||
|
player.getInventory().setContents(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "Items compacted into stacks!");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user