Made a fix for: SD-3068

- Changed the vanish command so all mobs stop targeting the vanished player.
- Added an listener to cancel target events on vanished players
This commit is contained in:
Stefano Haagmans 2019-07-23 22:22:44 +02:00
parent 6ba6f88d81
commit 6f0c8a8ee2
5 changed files with 36 additions and 3 deletions

5
.gitignore vendored
View File

@ -28,4 +28,7 @@ hs_err_pid*
/build/
/bin/
/target/
*.iml
*.iml
src/\.DS_Store
\.DS_Store

View File

@ -4,7 +4,7 @@ stages:
variables:
name: "UltimateModeration"
path: "/builds/$CI_PROJECT_PATH"
version: "1.1.7"
version: "1.1.8"
build:
stage: build

View File

@ -100,6 +100,7 @@ public class UltimateModeration extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new InventoryListener(this), this);
Bukkit.getPluginManager().registerEvents(new ChatListener(this), this);
Bukkit.getPluginManager().registerEvents(new LoginListener(this), this);
Bukkit.getPluginManager().registerEvents(new MobTargetLister(), this);
// Start tasks
SlowModeTask.startTask(this);

View File

@ -11,6 +11,7 @@ import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import java.util.ArrayList;
@ -51,10 +52,10 @@ public class CommandVanish extends AbstractCommand {
} else {
inVanish.add(uuid);
player.setCanPickupItems(false);
if (instance.isServerVersionAtLeast(ServerVersion.V1_9))
player.setInvulnerable(true);
player.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.vanish.toggledOn")));
}
if (Setting.VANISH_EFFECTS.getBoolean()) {
player.getWorld().playSound(player.getLocation(), Sound.valueOf(Setting.VANISH_SOUND.getString()), 1L, 1L);
@ -84,6 +85,11 @@ public class CommandVanish extends AbstractCommand {
else
p.showPlayer(player);
}
for (Entity e : player.getNearbyEntities(30, 30, 30)) {
if (e instanceof Monster) {
((Monster) e).setTarget(null);
}
}
}
public static boolean isVanished(Player player) {

View File

@ -0,0 +1,23 @@
package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.command.commands.CommandVanish;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
public class MobTargetLister implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onMobTagetEvent(EntityTargetLivingEntityEvent e) {
if (!(e.getTarget() instanceof Player)) return;
if (!(e.getEntity() instanceof Monster)) return;
if (CommandVanish.isVanished(((Player) e.getTarget()).getPlayer())) {
e.setCancelled(true);
}
}
}