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:
parent
347085e8e0
commit
76d91d361f
|
|
@ -2394,28 +2394,40 @@ public class GriefPrevention extends JavaPlugin
|
|||
if(player.hasPermission("griefprevention.nopvpimmunity")) return;
|
||||
|
||||
//check inventory for well, anything
|
||||
if(GriefPrevention.isInventoryEmpty(player))
|
||||
{
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
if(!(generalStacks[i] == null || generalStacks[i].getType() == Material.AIR)) return false;
|
||||
}
|
||||
|
||||
//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);
|
||||
return true;
|
||||
}
|
||||
|
||||
//checks whether players siege in a world
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user