2017-12-28 05:50:39 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.blocking;
|
|
|
|
|
|
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.GameMode;
|
2018-07-31 07:01:29 +00:00
|
|
|
import org.bukkit.entity.Arrow;
|
2020-07-01 03:38:29 +00:00
|
|
|
import org.bukkit.entity.FishHook;
|
2017-12-28 05:50:39 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2018-07-31 07:01:29 +00:00
|
|
|
import org.bukkit.entity.Trident;
|
2017-12-28 05:50:39 +00:00
|
|
|
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()
|
2017-12-28 05:50:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStop()
|
2017-12-28 05:50:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@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)
|
2017-12-28 05:50:39 +00:00
|
|
|
{
|
2018-07-31 07:01:29 +00:00
|
|
|
target = (Player)event.getEntity();
|
2018-03-10 20:51:19 +00:00
|
|
|
if (event.getDamager() instanceof Player)
|
2017-12-28 05:50:39 +00:00
|
|
|
{
|
2018-07-31 07:01:29 +00:00
|
|
|
player = (Player)event.getDamager();
|
2017-12-28 05:50:39 +00:00
|
|
|
}
|
2018-03-10 20:51:19 +00:00
|
|
|
else if (event.getDamager() instanceof Arrow)
|
2017-12-28 05:50:39 +00:00
|
|
|
{
|
2018-07-31 07:01:29 +00:00
|
|
|
Arrow arrow = (Arrow)event.getDamager();
|
2018-03-10 20:51:19 +00:00
|
|
|
if (arrow.getShooter() instanceof Player)
|
|
|
|
{
|
2018-07-31 07:01:29 +00:00
|
|
|
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)
|
|
|
|
{
|
2018-07-31 07:01:29 +00:00
|
|
|
Trident trident = (Trident)event.getDamager();
|
2018-07-25 02:08:29 +00:00
|
|
|
if (trident.getShooter() instanceof Player)
|
|
|
|
{
|
2018-07-31 07:01:29 +00:00
|
|
|
player = (Player)trident.getShooter();
|
2018-07-25 02:08:29 +00:00
|
|
|
}
|
2020-01-15 22:44:51 +00:00
|
|
|
}
|
|
|
|
else if (event.getDamager() instanceof FishHook)
|
|
|
|
{
|
|
|
|
FishHook fishhook = (FishHook)event.getDamager();
|
|
|
|
if (fishhook.getShooter() instanceof Player)
|
|
|
|
{
|
|
|
|
player = (Player)fishhook.getShooter();
|
|
|
|
}
|
2017-12-28 05:50:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-15 22:41:23 +00:00
|
|
|
if (player != null & !plugin.al.isAdmin(player))
|
2017-12-28 05:50:39 +00:00
|
|
|
{
|
2018-03-10 20:51:19 +00:00
|
|
|
if (player.getGameMode() == GameMode.CREATIVE)
|
2017-12-28 05:50:39 +00:00
|
|
|
{
|
2018-03-10 20:51:19 +00:00
|
|
|
player.sendMessage(ChatColor.RED + "Creative PvP is not allowed!");
|
2017-12-28 05:50:39 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2018-03-10 20:51:19 +00:00
|
|
|
else if (plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled())
|
2017-12-28 05:50:39 +00:00
|
|
|
{
|
2018-03-10 20:51:19 +00:00
|
|
|
player.sendMessage(ChatColor.RED + "God mode PvP is not allowed!");
|
2017-12-28 05:50:39 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2018-03-10 20:51:19 +00:00
|
|
|
else if (plugin.pl.getPlayer(target).isPvpBlocked())
|
2017-12-28 05:50:39 +00:00
|
|
|
{
|
2018-03-10 20:51:19 +00:00
|
|
|
player.sendMessage(ChatColor.RED + target.getName() + " has PvP disabled!");
|
2017-12-28 05:50:39 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2018-03-10 20:51:19 +00:00
|
|
|
else if (plugin.pl.getPlayer(player).isPvpBlocked())
|
2017-12-28 05:50:39 +00:00
|
|
|
{
|
2018-03-10 20:51:19 +00:00
|
|
|
player.sendMessage(ChatColor.RED + "You have PvP disabled!");
|
2017-12-28 05:50:39 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
2018-03-10 20:51:19 +00:00
|
|
|
|
2017-12-28 05:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|