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;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
2018-03-10 20:51:19 +00:00
|
|
|
import org.bukkit.entity.Arrow;
|
2017-12-28 05:50:39 +00:00
|
|
|
|
|
|
|
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-03-10 20:51:19 +00:00
|
|
|
target = (Player)event.getEntity();
|
|
|
|
if (event.getDamager() instanceof Player)
|
2017-12-28 05:50:39 +00:00
|
|
|
{
|
2018-03-10 20:51:19 +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-03-10 20:51:19 +00:00
|
|
|
Arrow arrow = (Arrow) event.getDamager();
|
|
|
|
if (arrow.getShooter() instanceof Player)
|
|
|
|
{
|
|
|
|
player = (Player) arrow.getShooter();
|
|
|
|
}
|
2017-12-28 05:50:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-10 20:51:19 +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
|
|
|
}
|
|
|
|
|
|
|
|
}
|