mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Teleport tamed mobs to the nearest plot.
This commit is contained in:
parent
46342a7ff8
commit
e65d20d5f1
@ -10,6 +10,7 @@
|
|||||||
package com.intellectualcrafters.plot;
|
package com.intellectualcrafters.plot;
|
||||||
|
|
||||||
import ca.mera.CameraAPI;
|
import ca.mera.CameraAPI;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.Logger.LogLevel;
|
import com.intellectualcrafters.plot.Logger.LogLevel;
|
||||||
import com.intellectualcrafters.plot.Settings.Web;
|
import com.intellectualcrafters.plot.Settings.Web;
|
||||||
import com.intellectualcrafters.plot.commands.Camera;
|
import com.intellectualcrafters.plot.commands.Camera;
|
||||||
@ -23,14 +24,19 @@ import com.intellectualcrafters.plot.events.PlotDeleteEvent;
|
|||||||
import com.intellectualcrafters.plot.listeners.PlayerEvents;
|
import com.intellectualcrafters.plot.listeners.PlayerEvents;
|
||||||
import com.intellectualcrafters.plot.listeners.WorldEditListener;
|
import com.intellectualcrafters.plot.listeners.WorldEditListener;
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
|
|
||||||
import me.confuser.barapi.BarAPI;
|
import me.confuser.barapi.BarAPI;
|
||||||
|
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Tameable;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
@ -724,10 +730,11 @@ public class PlotMain extends JavaPlugin {
|
|||||||
public void run() {
|
public void run() {
|
||||||
if(ticked > 36000l) {
|
if(ticked > 36000l) {
|
||||||
ticked = 0l;
|
ticked = 0l;
|
||||||
sendConsoleSenderMessage(C.PREFIX.s() + "KillAllEntities has been running for 60 minutes. Error-count: " + error);
|
sendConsoleSenderMessage(C.PREFIX.s() + "KillAllEntities has been running for 60 minutes. Errors: " + error);
|
||||||
error = 0l;
|
error = 0l;
|
||||||
}
|
}
|
||||||
for (String w: getPlotWorlds()) {
|
for (String w: getPlotWorlds()) {
|
||||||
|
PlotWorld plotworld = getWorldSettings(w);
|
||||||
World world = Bukkit.getServer().getWorld(w);
|
World world = Bukkit.getServer().getWorld(w);
|
||||||
try {
|
try {
|
||||||
if(world.getLoadedChunks().length < 1) {
|
if(world.getLoadedChunks().length < 1) {
|
||||||
@ -740,8 +747,65 @@ public class PlotMain extends JavaPlugin {
|
|||||||
if (entity.getType() == EntityType.PLAYER)
|
if (entity.getType() == EntityType.PLAYER)
|
||||||
continue;
|
continue;
|
||||||
location = entity.getLocation();
|
location = entity.getLocation();
|
||||||
if (!PlayerEvents.isInPlot(location))
|
if (!PlayerEvents.isInPlot(location)) {
|
||||||
entity.remove();
|
boolean tamed = false;
|
||||||
|
if (Settings.MOB_PATHFINDING) {
|
||||||
|
if (entity instanceof Tameable) {
|
||||||
|
Tameable tameable = (Tameable) entity;
|
||||||
|
if (tameable.isTamed()) {
|
||||||
|
tamed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (entity instanceof LivingEntity) {
|
||||||
|
LivingEntity livingEntity = ((LivingEntity) entity);
|
||||||
|
if (livingEntity.getCustomName()!=null) {
|
||||||
|
tamed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tamed) {
|
||||||
|
boolean found = false;
|
||||||
|
int radius = 1;
|
||||||
|
int dir = 0;
|
||||||
|
int x = location.getBlockX();
|
||||||
|
int y = location.getBlockY();
|
||||||
|
int z = location.getBlockZ();
|
||||||
|
while (!found || radius > PlotWorld.ROAD_WIDTH_DEFAULT) {
|
||||||
|
Location pos;
|
||||||
|
switch (dir) {
|
||||||
|
case 0:
|
||||||
|
pos = new Location(world, x+radius, y, z);
|
||||||
|
dir++;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
pos = new Location(world, x, y, z+radius);
|
||||||
|
dir++;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
pos = new Location(world, x-radius, y, z);
|
||||||
|
dir++;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
pos = new Location(world, x, y, z-radius);
|
||||||
|
dir = 0;
|
||||||
|
radius++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
pos = location;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (PlayerEvents.isInPlot(pos)) {
|
||||||
|
entity.teleport(pos.add(0.5,0,0.5));
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!tamed) {
|
||||||
|
entity.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -763,6 +827,7 @@ public class PlotMain extends JavaPlugin {
|
|||||||
Map<String, Object> options = new HashMap<String, Object>();
|
Map<String, Object> options = new HashMap<String, Object>();
|
||||||
//options.put("auto_update", false);
|
//options.put("auto_update", false);
|
||||||
options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT);
|
options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT);
|
||||||
|
options.put("mob_pathfinding", Settings.MOB_PATHFINDING_DEFAULT);
|
||||||
options.put("web.enabled", Web.ENABLED);
|
options.put("web.enabled", Web.ENABLED);
|
||||||
options.put("web.port", Web.PORT);
|
options.put("web.port", Web.PORT);
|
||||||
options.put("metrics", true);
|
options.put("metrics", true);
|
||||||
@ -774,6 +839,8 @@ public class PlotMain extends JavaPlugin {
|
|||||||
Web.ENABLED = config.getBoolean("web.enabled");
|
Web.ENABLED = config.getBoolean("web.enabled");
|
||||||
Web.PORT = config.getInt("web.port");
|
Web.PORT = config.getInt("web.port");
|
||||||
Settings.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs");
|
Settings.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs");
|
||||||
|
Settings.MOB_PATHFINDING = config.getBoolean("mob_pathfinding");
|
||||||
|
Settings.METRICS = config.getBoolean("metrics");
|
||||||
|
|
||||||
for (String node:config.getConfigurationSection("worlds").getKeys(false)) {
|
for (String node:config.getConfigurationSection("worlds").getKeys(false)) {
|
||||||
World world = Bukkit.getWorld(node);
|
World world = Bukkit.getWorld(node);
|
||||||
|
@ -29,6 +29,14 @@ public class Settings {
|
|||||||
* Default kill road mobs: true
|
* Default kill road mobs: true
|
||||||
*/
|
*/
|
||||||
public static boolean KILL_ROAD_MOBS_DEFAULT = true;
|
public static boolean KILL_ROAD_MOBS_DEFAULT = true;
|
||||||
|
/**
|
||||||
|
* mob pathfinding?
|
||||||
|
*/
|
||||||
|
public static boolean MOB_PATHFINDING;
|
||||||
|
/**
|
||||||
|
* Default mob pathfinding: true
|
||||||
|
*/
|
||||||
|
public static boolean MOB_PATHFINDING_DEFAULT = true;
|
||||||
/**
|
/**
|
||||||
* Update settings
|
* Update settings
|
||||||
* @author Citymonstret
|
* @author Citymonstret
|
||||||
|
Loading…
Reference in New Issue
Block a user