Add 'fakepvp' config, currently untested...

This commit is contained in:
Eric Stokes 2011-07-09 22:00:07 -06:00
parent 1c3d3b0807
commit 54573889af
3 changed files with 63 additions and 2 deletions

View File

@ -2,14 +2,20 @@ package com.onarandombox.MultiverseCore;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Animals;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.Slime;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
@ -23,6 +29,57 @@ public class MVEntityListener extends EntityListener {
public MVEntityListener(MultiverseCore plugin) {
this.plugin = plugin;
}
/**
* Event - When a Entity is Damaged, we first sort out whether it is of
* importance to us, such as EntityVSEntity or EntityVSProjectile. Then we
* grab the attacked and defender and check if its a player. Then deal with
* the PVP Aspect.
*/
@Override
public void onEntityDamage(EntityDamageEvent event) {
if (event.isCancelled()) {
return;
}
Entity attacker = null;
Entity defender = null;
if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event;
attacker = sub.getDamager();
defender = sub.getEntity();
} else if (event instanceof EntityDamageByProjectileEvent) {
EntityDamageByProjectileEvent sub = (EntityDamageByProjectileEvent) event;
attacker = sub.getDamager();
defender = sub.getEntity();
} else {
return;
}
if (attacker == null || defender == null) {
return;
}
if (defender instanceof Player) {
Player player = (Player) defender;
World w = player.getWorld();
if(!this.plugin.isMVWorld(w.getName())) {
//if the world is not handled, we don't care
return;
}
MVWorld world = this.plugin.getMVWorld(w.getName());
if (attacker != null && attacker instanceof Player) {
Player pattacker = (Player) attacker;
if (!world.getPvp() && this.plugin.configMV.getBoolean("fakepvp", false)) {
pattacker.sendMessage(ChatColor.RED + "PVP is disabled in this World.");
event.setCancelled(true);
return;
}
}
}
}
@Override
public void onEntityRegainHealth(EntityRegainHealthEvent event) {

View File

@ -121,7 +121,7 @@ public class MultiverseCore extends JavaPlugin {
pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this); // To Allow/Disallow PVP as well as EnableHealth.
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.Normal, this); // To Allow/Disallow fake PVP
pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Priority.Normal, this); // To prevent all or certain animals/monsters from spawning.
pm.registerEvent(Event.Type.PLUGIN_ENABLE, this.pluginListener, Priority.Monitor, this);

View File

@ -37,4 +37,8 @@ opfallback: true
# If you have a world(s) that has monsters = false, and you want to disable the built
# in autohealing, set this to true. This will have NO EFFECT if monsters = true for a given world.
disableautoheal: false
disableautoheal: false
# This will use the old style of PVP prevention so you can have zones of PVP
# Players will be notified when they punch/shoot and it's not allowed.
fakepvp: false