2017-12-28 05:50:39 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.blocking;
|
|
|
|
|
|
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.GameMode;
|
2018-07-31 07:01:29 +00:00
|
|
|
import org.bukkit.entity.Arrow;
|
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;
|
2020-01-15 22:44:51 +00:00
|
|
|
import org.bukkit.entity.FishHook;
|
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
|
|
|
|
{
|
|
|
|
|
|
|
|
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)
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-31 06:41:56 +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
|
|
|
}
|
|
|
|
|
|
|
|
}
|