Merge pull request #3 from marcocorriero/TFM1.12-Alpha

Adds PVP Filtering
This commit is contained in:
Lemon 2017-11-14 15:27:42 +05:00 committed by GitHub
commit 8c8c5360c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 84 additions and 0 deletions

View File

@ -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!");
}
}
}
}

View File

@ -75,6 +75,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
public AntiNuke nu;
public PotionMonitorer pmn;
public DropMonitor dmn;
public PvpMonitor pvp;
public AntiSpam as;
public PlayerList pl;
public Announcer an;
@ -198,6 +199,8 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
ae = services.registerService(AutoEject.class);
dmn = services.registerService(DropMonitor.class);
cmon = services.registerService(ChestMonitor.class);
pvp = services.registerService(PvpMonitor.class);
mv = services.registerService(MovementValidator.class);
ew = services.registerService(EntityWiper.class);