mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-01 05:18:00 +01:00
Make sure dead players really "die"
This commit is contained in:
parent
3f193e212f
commit
86c640f0cc
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cc.co.evenprime.bukkit</groupId>
|
||||
<artifactId>NoCheat</artifactId>
|
||||
<version>3.4.2</version>
|
||||
<version>3.4.3</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>NoCheat</name>
|
||||
<properties>
|
||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -12,6 +13,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import cc.co.evenprime.bukkit.nocheat.EventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
@ -134,6 +136,15 @@ public class FightCheckListener implements Listener, EventManager {
|
||||
return;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
protected void death(final EntityDeathEvent event) {
|
||||
if(!(event.getEntity() instanceof CraftPlayer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
godmodeCheck.death((CraftPlayer) event.getEntity());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
protected void armSwing(final PlayerAnimationEvent event) {
|
||||
FightCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore()).armswung = true;
|
||||
|
@ -1,6 +1,9 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.fight;
|
||||
|
||||
import java.util.Locale;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
@ -20,7 +23,7 @@ public class GodmodeCheck extends FightCheck {
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
// Check at most once a second
|
||||
if(data.godmodeLastDamageTime + 1000 < time) {
|
||||
if(data.godmodeLastDamageTime + 1000L < time) {
|
||||
data.godmodeLastDamageTime = time;
|
||||
|
||||
// How old is the player now?
|
||||
@ -49,8 +52,8 @@ public class GodmodeCheck extends FightCheck {
|
||||
|
||||
if(data.godmodeBuffer < 0) {
|
||||
data.godmodeBuffer = 0;
|
||||
} else if(data.godmodeBuffer > 40) {
|
||||
data.godmodeBuffer = 40;
|
||||
} else if(data.godmodeBuffer > 30) {
|
||||
data.godmodeBuffer = 30;
|
||||
}
|
||||
|
||||
// Start age counting from a new time
|
||||
@ -73,4 +76,30 @@ public class GodmodeCheck extends FightCheck {
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* If a player apparently died, make sure he really dies after some time
|
||||
* if he didn't already.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public void death(CraftPlayer player) {
|
||||
if(player.getHealth() <= 0 && player.isDead()) {
|
||||
try {
|
||||
final EntityPlayer entity = player.getHandle();
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
if(entity.getHealth() <= 0 && !entity.dead) {
|
||||
entity.deathTicks = 19;
|
||||
entity.a(true);
|
||||
}
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
}, 30);
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,19 +39,15 @@ public class InventoryCheckListener implements Listener, EventManager {
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
protected void handlePlayerDropItemEvent(final PlayerDropItemEvent event) {
|
||||
|
||||
if(event.isCancelled())
|
||||
if(event.isCancelled() || event.getPlayer().isDead())
|
||||
return;
|
||||
|
||||
boolean cancelled = false;
|
||||
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
final InventoryConfig cc = InventoryCheck.getConfig(player.getConfigurationStore());
|
||||
final InventoryData data = InventoryCheck.getData(player.getDataStore());
|
||||
|
||||
if(player.hasPermission(Permissions.INVENTORY) || player.isDead()) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean cancelled = false;
|
||||
|
||||
// If it should be executed, do it
|
||||
if(cc.dropCheck && !player.hasPermission(Permissions.INVENTORY_DROP)) {
|
||||
cancelled = dropCheck.check(player, data, cc);
|
||||
|
@ -189,7 +189,7 @@ public class MovingCheckListener implements Listener, EventManager {
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void move(final PlayerMoveEvent event) {
|
||||
|
||||
if(event.isCancelled() || event.getPlayer().isInsideVehicle() || event.getPlayer().isDead())
|
||||
if(event.isCancelled() || event.getPlayer().isInsideVehicle())
|
||||
return;
|
||||
|
||||
if(!event.getFrom().getWorld().equals(event.getTo().getWorld()) || event.getFrom().distanceSquared(event.getTo()) > 400) {
|
||||
|
Loading…
Reference in New Issue
Block a user