mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 10:05:59 +00:00
Merge pull request #3 from marcocorriero/TFM1.12-Alpha
Adds PVP Filtering
This commit is contained in:
commit
8c8c5360c2
@ -0,0 +1,81 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Projectile;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class PvpMonitor extends FreedomService {
|
||||||
|
|
||||||
|
public PvpMonitor(TotalFreedomMod plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
|
||||||
|
|
||||||
|
public void hit(final EntityDamageByEntityEvent event) {
|
||||||
|
Entity damager = event.getDamager();
|
||||||
|
Entity entity = event.getEntity();
|
||||||
|
// This checks if the player is actually hitting a other player with any item , it filters his gamemode.
|
||||||
|
if (damager instanceof Player && entity instanceof Player) {
|
||||||
|
final Player player = (Player) damager;
|
||||||
|
|
||||||
|
// Bypasses the block if Player is actually a Supered-Admin.
|
||||||
|
if (plugin.al.isAdmin((player))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Checks 4 cases
|
||||||
|
if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on creative and god mode on.
|
||||||
|
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP with God Mode and creative!");
|
||||||
|
} else if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on creative and god mode off.
|
||||||
|
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP in creative!");
|
||||||
|
} else if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on survival with god mode on.
|
||||||
|
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
|
||||||
|
} else if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on Adventure with god mode on.
|
||||||
|
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IF player shoots an arrow this prevents the damage if player is on creative or with godmode on.
|
||||||
|
if (damager instanceof Projectile && entity instanceof Player) {
|
||||||
|
|
||||||
|
ProjectileSource ps = ((Projectile) damager).getShooter();
|
||||||
|
|
||||||
|
Player player = (Player) ps;
|
||||||
|
|
||||||
|
// Bypasses the block if Player is actually a Supered-Admin.
|
||||||
|
if (plugin.al.isAdmin((player))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on creative and god mode on.
|
||||||
|
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP with God Mode and creative!");
|
||||||
|
} else if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on creative and god mode off.
|
||||||
|
player.sendMessage(ChatColor.RED + "Hey! You cannot PVP in creative!");
|
||||||
|
} else if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on survival with god mode on.
|
||||||
|
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
|
||||||
|
} else if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { // This checks if player is on Adventure with god mode on.
|
||||||
|
player.sendMessage(ChatColor.RED + "Hey! You can't PVP with godmode!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -75,6 +75,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
|||||||
public AntiNuke nu;
|
public AntiNuke nu;
|
||||||
public PotionMonitorer pmn;
|
public PotionMonitorer pmn;
|
||||||
public DropMonitor dmn;
|
public DropMonitor dmn;
|
||||||
|
public PvpMonitor pvp;
|
||||||
public AntiSpam as;
|
public AntiSpam as;
|
||||||
public PlayerList pl;
|
public PlayerList pl;
|
||||||
public Announcer an;
|
public Announcer an;
|
||||||
@ -198,6 +199,8 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
|||||||
ae = services.registerService(AutoEject.class);
|
ae = services.registerService(AutoEject.class);
|
||||||
dmn = services.registerService(DropMonitor.class);
|
dmn = services.registerService(DropMonitor.class);
|
||||||
cmon = services.registerService(ChestMonitor.class);
|
cmon = services.registerService(ChestMonitor.class);
|
||||||
|
pvp = services.registerService(PvpMonitor.class);
|
||||||
|
|
||||||
|
|
||||||
mv = services.registerService(MovementValidator.class);
|
mv = services.registerService(MovementValidator.class);
|
||||||
ew = services.registerService(EntityWiper.class);
|
ew = services.registerService(EntityWiper.class);
|
||||||
|
Loading…
Reference in New Issue
Block a user