mirror of
https://github.com/craftaro/EpicSpawners.git
synced 2025-01-09 03:57:40 +08:00
Cleaned up appearance handler so that it didn't make changes unless necessary, which should boost performance.
This commit is contained in:
parent
67c7bdb9b7
commit
341c00e07a
@ -122,7 +122,7 @@ public class EpicSpawnersPlugin extends JavaPlugin implements EpicSpawners {
|
||||
console.sendMessage(TextComponent.formatText("&a============================="));
|
||||
}
|
||||
|
||||
private void checkVersion() {
|
||||
private boolean checkVersion() {
|
||||
int workingVersion = 13;
|
||||
int currentVersion = Integer.parseInt(Bukkit.getServer().getClass()
|
||||
.getPackage().getName().split("\\.")[3].split("_")[1]);
|
||||
@ -133,13 +133,15 @@ public class EpicSpawnersPlugin extends JavaPlugin implements EpicSpawners {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "You installed the 1." + workingVersion + "+ only version of " + this.getDescription().getName() + " on a 1." + currentVersion + " server. Since you are on the wrong version we disabled the plugin for you. Please install correct version to continue using " + this.getDescription().getName() + ".");
|
||||
Bukkit.getConsoleSender().sendMessage("");
|
||||
}, 20L);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Check to make sure the Bukkit version is compatible.
|
||||
checkVersion();
|
||||
if (!checkVersion()) return;
|
||||
|
||||
INSTANCE = this;
|
||||
EpicSpawnersAPI.setImplementation(this);
|
||||
|
@ -13,6 +13,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -77,9 +78,23 @@ public class AppearanceHandler {
|
||||
public void updateDisplayItem(Spawner spawner, SpawnerData spawnerData) {
|
||||
try {
|
||||
|
||||
Location nloc = spawner.getLocation();
|
||||
nloc.add(.5, -.4, .5);
|
||||
removeDisplayItem(spawner);
|
||||
Location location = spawner.getLocation();
|
||||
location.add(.5, -.4, .5);
|
||||
|
||||
ItemStack itemStack = new ItemStack(Material.DIRT);
|
||||
if (spawner.getFirstStack().getSpawnerData().getDisplayItem() != null)
|
||||
itemStack.setType(spawnerData.getDisplayItem());
|
||||
|
||||
ArmorStand entity = (ArmorStand)getDisplayItem(spawner);
|
||||
|
||||
if (entity != null) {
|
||||
if (entity.getHelmet().getType() != itemStack.getType()) {
|
||||
entity.remove();
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
EntityType next = EntityType.valueOf(Methods.restoreType(spawnerData.getIdentifyingName()));
|
||||
@ -87,26 +102,15 @@ public class AppearanceHandler {
|
||||
} catch (Exception ex) {
|
||||
spawner.getCreatureSpawner().setSpawnedType(EntityType.DROPPED_ITEM);
|
||||
|
||||
Location location = spawner.getLocation();
|
||||
|
||||
location.setPitch(-360);
|
||||
|
||||
ArmorStand as = (ArmorStand) location.getWorld().spawnEntity(nloc, EntityType.ARMOR_STAND);
|
||||
ArmorStand as = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
|
||||
as.setSmall(true);
|
||||
as.setVisible(false);
|
||||
as.setCustomNameVisible(false);
|
||||
as.setGravity(false);
|
||||
as.setCanPickupItems(false);
|
||||
as.setBasePlate(true);
|
||||
try {
|
||||
if (spawner.getFirstStack().getSpawnerData().getDisplayItem() != null) {
|
||||
as.setHelmet(new ItemStack(spawnerData.getDisplayItem()));
|
||||
} else {
|
||||
as.setHelmet(new ItemStack(Material.DIRT));
|
||||
}
|
||||
} catch (Exception ee) {
|
||||
as.setHelmet(new ItemStack(Material.DIRT));
|
||||
}
|
||||
as.setHelmet(itemStack);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
@ -114,14 +118,21 @@ public class AppearanceHandler {
|
||||
}
|
||||
|
||||
public void removeDisplayItem(Spawner spawner) {
|
||||
Location nloc = spawner.getLocation();
|
||||
nloc.add(.5, -.4, .5);
|
||||
List<Entity> near = (List<Entity>) nloc.getWorld().getNearbyEntities(nloc, 8, 8, 8);
|
||||
for (Entity e : near) {
|
||||
if (e.getLocation().getX() == nloc.getX() && e.getLocation().getY() == nloc.getY() && e.getLocation().getZ() == nloc.getZ()) {
|
||||
e.remove();
|
||||
}
|
||||
Entity entity = getDisplayItem(spawner);
|
||||
if (entity == null) return;
|
||||
entity.remove();
|
||||
}
|
||||
|
||||
private Entity getDisplayItem(Spawner spawner) {
|
||||
Location location = spawner.getLocation();
|
||||
location.add(.5, -.4, .5);
|
||||
|
||||
List<Entity> near = (List<Entity>) location.getWorld().getNearbyEntities(location, 8, 8, 8);
|
||||
near.removeIf(e -> e.getLocation().getX() != location.getX() || e.getLocation().getY() != location.getY() || e.getLocation().getZ() != location.getZ());
|
||||
if (near.size() != 0) {
|
||||
return near.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user