TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/blocking/PVPBlocker.java

89 lines
2.7 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.blocking;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player;
import org.bukkit.entity.Trident;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
public class PVPBlocker extends FreedomService
{
public PVPBlocker(TotalFreedomMod plugin)
{
super(plugin);
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
@EventHandler(priority = EventPriority.LOW)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
{
2018-03-10 20:51:19 +00:00
Player player = null;
Player target = null;
if (event.getEntity() instanceof Player)
{
target = (Player)event.getEntity();
2018-03-10 20:51:19 +00:00
if (event.getDamager() instanceof Player)
{
player = (Player)event.getDamager();
}
2018-03-10 20:51:19 +00:00
else if (event.getDamager() instanceof Arrow)
{
Arrow arrow = (Arrow)event.getDamager();
2018-03-10 20:51:19 +00:00
if (arrow.getShooter() instanceof Player)
{
player = (Player)arrow.getShooter();
2018-03-10 20:51:19 +00:00
}
2018-07-25 02:08:29 +00:00
}
else if (event.getDamager() instanceof Trident)
{
Trident trident = (Trident)event.getDamager();
2018-07-25 02:08:29 +00:00
if (trident.getShooter() instanceof Player)
{
player = (Player)trident.getShooter();
2018-07-25 02:08:29 +00:00
}
}
}
if (player != null & !plugin.al.isAdmin(player))
{
2018-03-10 20:51:19 +00:00
if (player.getGameMode() == GameMode.CREATIVE)
{
2018-03-10 20:51:19 +00:00
player.sendMessage(ChatColor.RED + "Creative PvP is not allowed!");
event.setCancelled(true);
}
2018-03-10 20:51:19 +00:00
else if (plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled())
{
2018-03-10 20:51:19 +00:00
player.sendMessage(ChatColor.RED + "God mode PvP is not allowed!");
event.setCancelled(true);
}
2018-03-10 20:51:19 +00:00
else if (plugin.pl.getPlayer(target).isPvpBlocked())
{
2018-03-10 20:51:19 +00:00
player.sendMessage(ChatColor.RED + target.getName() + " has PvP disabled!");
event.setCancelled(true);
}
2018-03-10 20:51:19 +00:00
else if (plugin.pl.getPlayer(player).isPvpBlocked())
{
2018-03-10 20:51:19 +00:00
player.sendMessage(ChatColor.RED + "You have PvP disabled!");
event.setCancelled(true);
}
}
2018-03-10 20:51:19 +00:00
}
}