Fixed kit commands abusing PvP immunity.

Repeating check of inventory, just in case a plugin delivered items to a
PvP-immune player.
This commit is contained in:
ryanhamshire 2015-03-03 20:50:47 -08:00
parent 347085e8e0
commit 76d91d361f
2 changed files with 88 additions and 21 deletions

View File

@ -2394,31 +2394,43 @@ public class GriefPrevention extends JavaPlugin
if(player.hasPermission("griefprevention.nopvpimmunity")) return; if(player.hasPermission("griefprevention.nopvpimmunity")) return;
//check inventory for well, anything //check inventory for well, anything
PlayerInventory inventory = player.getInventory(); if(GriefPrevention.isInventoryEmpty(player))
ItemStack [] armorStacks = inventory.getArmorContents();
//check armor slots, stop if any items are found
for(int i = 0; i < armorStacks.length; i++)
{ {
if(!(armorStacks[i] == null || armorStacks[i].getType() == Material.AIR)) return; //if empty, apply immunity
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
playerData.pvpImmune = true;
//inform the player after he finishes respawning
GriefPrevention.sendMessage(player, TextMode.Success, Messages.PvPImmunityStart, 5L);
//start a task to re-check this player's inventory every minute until his immunity is gone
PvPImmunityValidationTask task = new PvPImmunityValidationTask(player);
this.getServer().getScheduler().scheduleSyncDelayedTask(this, task, 1200L);
} }
//check other slots, stop if any items are found
ItemStack [] generalStacks = inventory.getContents();
for(int i = 0; i < generalStacks.length; i++)
{
if(!(generalStacks[i] == null || generalStacks[i].getType() == Material.AIR)) return;
}
//otherwise, apply immunity
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
playerData.pvpImmune = true;
//inform the player after he finishes respawning
GriefPrevention.sendMessage(player, TextMode.Success, Messages.PvPImmunityStart, 5L);
} }
//checks whether players siege in a world static boolean isInventoryEmpty(Player player)
{
PlayerInventory inventory = player.getInventory();
ItemStack [] armorStacks = inventory.getArmorContents();
//check armor slots, stop if any items are found
for(int i = 0; i < armorStacks.length; i++)
{
if(!(armorStacks[i] == null || armorStacks[i].getType() == Material.AIR)) return false;
}
//check other slots, stop if any items are found
ItemStack [] generalStacks = inventory.getContents();
for(int i = 0; i < generalStacks.length; i++)
{
if(!(generalStacks[i] == null || generalStacks[i].getType() == Material.AIR)) return false;
}
return true;
}
//checks whether players siege in a world
public boolean siegeEnabledForWorld(World world) public boolean siegeEnabledForWorld(World world)
{ {
return this.config_siege_enabledWorlds.contains(world); return this.config_siege_enabledWorlds.contains(world);

View File

@ -0,0 +1,55 @@
/*
GriefPrevention Server Plugin for Minecraft
Copyright (C) 2012 Ryan Hamshire
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 me.ryanhamshire.GriefPrevention;
import org.bukkit.entity.Player;
//sends a message to a player
//used to send delayed messages, for example help text triggered by a player's chat
class PvPImmunityValidationTask implements Runnable
{
private Player player;
public PvPImmunityValidationTask(Player player)
{
this.player = player;
}
@Override
public void run()
{
if(!player.isOnline()) return;
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
if(!playerData.pvpImmune) return;
//check the player's inventory for anything
if(!GriefPrevention.isInventoryEmpty(player))
{
//if found, cancel invulnerability and notify
playerData.pvpImmune = false;
GriefPrevention.sendMessage(player, TextMode.Warn, Messages.PvPImmunityEnd);
}
else
{
//otherwise check again in one minute
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, this, 1200L);
}
}
}