Improve PvP blocker

This commit is contained in:
ZeroEpoch1969 2018-03-10 13:51:19 -07:00
parent 664c56dfd5
commit 5223339a9e
No known key found for this signature in database
GPG key ID: E0AAB104FB9F8FDF
2 changed files with 27 additions and 87 deletions

View file

@ -2,17 +2,13 @@ package me.totalfreedom.totalfreedommod.blocking;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.util.FSync;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.entity.Arrow;
public class PVPBlocker extends FreedomService
{
@ -35,105 +31,49 @@ public class PVPBlocker extends FreedomService
@EventHandler(priority = EventPriority.LOW)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
{
Entity damager = event.getDamager();
FPlayer fPlayer = null;
if (damager instanceof Player)
Player player = null;
Player target = null;
if (event.getEntity() instanceof Player)
{
fPlayer = plugin.pl.getPlayerSync((Player) damager);
}
if (damager instanceof Projectile)
{
ProjectileSource projectileSource = ((Projectile) damager).getShooter();
if (projectileSource instanceof Player)
target = (Player)event.getEntity();
if (event.getDamager() instanceof Player)
{
fPlayer = plugin.pl.getPlayerSync((Player) projectileSource);
player = (Player) event.getDamager();
}
else if (event.getDamager() instanceof Arrow)
{
Arrow arrow = (Arrow) event.getDamager();
if (arrow.getShooter() instanceof Player)
{
player = (Player) arrow.getShooter();
}
}
}
if (fPlayer == null || !fPlayer.isPvpBlocked())
if (player != null &! plugin.al.isAdmin(player))
{
return;
}
if (plugin.al.isAdminSync(event.getDamager()))
{
fPlayer.setPvpBlocked(false);
return;
}
Player player = (Player) damager;
event.setCancelled(true);
FSync.playerMsg(player, ChatColor.RED + "You are forbidden to engage in PVP combat.");
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerAttack(final EntityDamageByEntityEvent event)
{
final Entity damager = event.getDamager();
final Entity entity = event.getEntity();
if (damager instanceof Player && entity instanceof Player)
{
final Player player = (Player) damager;
if (plugin.al.isAdmin((player)))
if (player.getGameMode() == GameMode.CREATIVE)
{
return;
}
if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled())
{
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP with God Mode and creative!");
player.sendMessage(ChatColor.RED + "Creative PvP is not allowed!");
event.setCancelled(true);
}
else if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled())
else if (plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled())
{
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP in creative!");
player.sendMessage(ChatColor.RED + "God mode PvP is not allowed!");
event.setCancelled(true);
}
else if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled())
else if (plugin.pl.getPlayer(target).isPvpBlocked())
{
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
player.sendMessage(ChatColor.RED + target.getName() + " has PvP disabled!");
event.setCancelled(true);
}
else if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled())
else if (plugin.pl.getPlayer(player).isPvpBlocked())
{
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
player.sendMessage(ChatColor.RED + "You have PvP disabled!");
event.setCancelled(true);
}
}
if (damager instanceof Projectile && entity instanceof Player)
{
ProjectileSource projectileSource = ((Projectile) damager).getShooter();
Player player = (Player) projectileSource;
if (plugin.al.isAdmin((player)))
{
return;
}
if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled())
{
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP with God Mode and creative!");
event.setCancelled(true);
}
else if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled())
{
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP in creative!");
event.setCancelled(true);
}
else if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled())
{
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
event.setCancelled(true);
}
else if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled())
{
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
event.setCancelled(true);
}
}
}
}

View file

@ -38,7 +38,7 @@ public class Command_cartsit extends FreedomCommand
}
else if (targetPlayer != playerSender && !isAdmin(sender))
{
sender.sendMessage("Only superadmins can select another player as a /cartsit target.");
sender.sendMessage("Only admins can select another player as a /cartsit target.");
return true;
}
@ -69,11 +69,11 @@ public class Command_cartsit extends FreedomCommand
if (nearest_cart != null)
{
nearest_cart.setPassenger(targetPlayer);
nearest_cart.addPassenger(targetPlayer);
}
else
{
sender.sendMessage("There are no empty minecarts in the target world.");
msg("There are no empty minecarts in the target world.");
}
}