Flings hostile mobs away from player on teleport.
This commit is contained in:
parent
2bc825d3a3
commit
361a61da5d
|
@ -147,6 +147,14 @@ public class Settings implements ConfigObject {
|
|||
@ConfigComment("Add other fake player names here if required")
|
||||
@ConfigEntry(path = "general.fakeplayers", experimental = true)
|
||||
private Set<String> fakePlayers = new HashSet<>();
|
||||
|
||||
@ConfigComment("Flingback power. How far hostile mobs will be flung back when a player teleports into them.")
|
||||
@ConfigEntry(path = "general.flingback")
|
||||
private double flingback = 5D;
|
||||
|
||||
@ConfigComment("Kill mobs on teleport. If thw world flag is set, then they will be killed/removed instead of flung.")
|
||||
@ConfigEntry(path = "general.teleport-remove-mobs")
|
||||
private boolean teleportRemoveMobs = false;
|
||||
|
||||
/* PANELS */
|
||||
|
||||
|
@ -1038,4 +1046,32 @@ public class Settings implements ConfigObject {
|
|||
{
|
||||
this.safeSpotSearchRange = safeSpotSearchRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the flingback
|
||||
*/
|
||||
public double getFlingback() {
|
||||
return flingback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param flingback the flingback to set
|
||||
*/
|
||||
public void setFlingback(double flingback) {
|
||||
this.flingback = flingback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the teleportRemoveMobs
|
||||
*/
|
||||
public boolean isTeleportRemoveMobs() {
|
||||
return teleportRemoveMobs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param teleportRemoveMobs the teleportRemoveMobs to set
|
||||
*/
|
||||
public void setTeleportRemoveMobs(boolean teleportRemoveMobs) {
|
||||
this.teleportRemoveMobs = teleportRemoveMobs;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Map.Entry;
|
|||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Queue;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
@ -20,25 +21,20 @@ import java.util.stream.Collectors;
|
|||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.AbstractArrow.PickupStatus;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.Boat.Type;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.PufferFish;
|
||||
import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
@ -72,6 +68,7 @@ import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
|
|||
public class IslandsManager {
|
||||
|
||||
private final BentoBox plugin;
|
||||
private final Random rand = new Random();
|
||||
|
||||
// Tree species to boat material map
|
||||
private static final Map<Type, Material> TREE_TO_BOAT = ImmutableMap.<Type, Material>builder().
|
||||
|
@ -1639,6 +1636,7 @@ public class IslandsManager {
|
|||
*/
|
||||
public void clearArea(Location loc) {
|
||||
if (!plugin.getIWM().inWorld(loc)) return;
|
||||
|
||||
loc.getWorld().getNearbyEntities(loc, plugin.getSettings().getClearRadius(),
|
||||
plugin.getSettings().getClearRadius(),
|
||||
plugin.getSettings().getClearRadius()).stream()
|
||||
|
@ -1648,26 +1646,29 @@ public class IslandsManager {
|
|||
&& !(en instanceof PufferFish)
|
||||
&& ((LivingEntity)en).getRemoveWhenFarAway())
|
||||
.filter(en -> en.getCustomName() == null)
|
||||
.forEach(e -> fireArrowOfPower(e, loc));
|
||||
.forEach(e -> flingOrKill(e, loc));
|
||||
}
|
||||
|
||||
private void fireArrowOfPower(Entity e, Location loc) {
|
||||
Vector direction = e.getLocation().toVector().subtract(loc.toVector()).normalize();
|
||||
if (e instanceof Zombie z) {
|
||||
plugin.logDebug("Health = " + z.getHealth() + " direction " + direction);
|
||||
private void flingOrKill(Entity e, Location loc) {
|
||||
if (plugin.getSettings().isTeleportRemoveMobs()) {
|
||||
e.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
Arrow arrow = loc.getWorld().spawnArrow(loc, direction, 0.7F, 0);
|
||||
arrow.setDamage(0);
|
||||
arrow.setPierceLevel(0);
|
||||
PotionData pd = new PotionData(PotionType.INSTANT_HEAL, false, false);
|
||||
arrow.setBasePotionData(pd);
|
||||
arrow.setCritical(false);
|
||||
arrow.setKnockbackStrength(50);
|
||||
Color color = Color.AQUA;
|
||||
//color.setAlpha(0);
|
||||
arrow.setColor(color);
|
||||
arrow.setPickupStatus(PickupStatus.DISALLOWED);
|
||||
Vector entVec = e.getLocation().toVector();
|
||||
double dist = plugin.getSettings().getFlingback() - entVec.distance(loc.toVector());
|
||||
if (dist < 1) {
|
||||
dist = 1;
|
||||
}
|
||||
Vector direction = entVec.subtract(loc.toVector());
|
||||
if (direction.lengthSquared() < 3) {
|
||||
// On top of us
|
||||
direction.add(new Vector(rand.nextDouble(), 0, rand.nextDouble()));
|
||||
}
|
||||
// Add a bit of lift
|
||||
direction.add(new Vector(0, rand.nextDouble(), 0));
|
||||
direction.multiply(dist);
|
||||
loc.getWorld().playSound(e, Sound.ENTITY_ILLUSIONER_HURT, 1F, 5F);
|
||||
e.setVelocity(direction);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -82,8 +82,8 @@ general:
|
|||
prefix-character: ''
|
||||
# Custom connection datasource properties that will be applied to connection pool.
|
||||
# Check available values to your SQL driver implementation.
|
||||
# Example: ")
|
||||
# custom-properties:
|
||||
# Example:
|
||||
# custom-properties:
|
||||
# cachePrepStmts: 'true'
|
||||
# prepStmtCacheSize: '250'
|
||||
# prepStmtCacheSqlLimit: '2048'
|
||||
|
@ -98,6 +98,10 @@ general:
|
|||
# /!\ This feature is experimental and might not work as expected or might not work at all.
|
||||
fakeplayers:
|
||||
- '[CoFH]'
|
||||
# Flingback power. How far hostile mobs will be flung back when a player teleports into them.
|
||||
flingback: 5.0
|
||||
# Remove mobs on teleport.
|
||||
teleport-remove-mobs: false
|
||||
panel:
|
||||
# Toggle whether panels should be closed or not when the player clicks anywhere outside of the inventory view.
|
||||
close-on-click-outside: true
|
||||
|
|
Loading…
Reference in New Issue