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

91 lines
2.9 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.blocking;
import me.totalfreedom.totalfreedommod.FreedomService;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.entity.Arrow;
2020-07-01 03:38:29 +00:00
import org.bukkit.entity.FishHook;
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
{
@Override
2020-07-01 01:51:06 +00:00
public void onStart()
{
}
@Override
2020-07-01 01:51:06 +00:00
public 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
}
}
else if (event.getDamager() instanceof FishHook)
{
FishHook fishhook = (FishHook)event.getDamager();
if (fishhook.getShooter() instanceof Player)
{
player = (Player)fishhook.getShooter();
}
}
}
2020-08-15 22:42:46 +00:00
if (player != null & !plugin.sl.isStaff(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
}
}