public static String join(String[] elements, String separator, int startIndex, int endIndex) { Validator.isTrue(startIndex >= 0 && startIndex < elements.length, "startIndex out of bounds"); Validator.isTrue(endIndex >= 0 && endIndex <= elements.length, "endIndex out of bounds"); Validator.isTrue(startIndex <= endIndex, "startIndex lower than endIndex"); StringBuilder result = new StringBuilder(); while (startIndex < endIndex) { if (result.length() != 0) { result.append(separator); } if (elements[startIndex] != null) { result.append(elements[startIndex]); } startIndex++; } return result.toString(); }
@Override public CraftTextLine appendTextLine(String text) { Validator.isTrue(!deleted, "hologram already deleted"); CraftTextLine line = new CraftTextLine(this, text); lines.add(line); refreshSingleLines(); return line; }
@Override public CraftTextLine insertTextLine(int index, String text) { Validator.isTrue(!deleted, "hologram already deleted"); CraftTextLine line = new CraftTextLine(this, text); lines.add(index, line); refreshSingleLines(); return line; }
@Override public void removeLine(int index) { Validator.isTrue(!deleted, "hologram already deleted"); lines.remove(index).despawn(); refreshSingleLines(); }
public void removeLine(CraftHologramLine line) { Validator.isTrue(!deleted, "hologram already deleted"); lines.remove(line); line.despawn(); refreshSingleLines(); }
@Override public CraftItemLine insertItemLine(int index, ItemStack itemStack) { Validator.isTrue(!deleted, "hologram already deleted"); Validator.notNull(itemStack, "itemStack"); CraftItemLine line = new CraftItemLine(this, itemStack); lines.add(index, line); refreshSingleLines(); return line; }
@Override public CraftItemLine appendItemLine(ItemStack itemStack) { Validator.isTrue(!deleted, "hologram already deleted"); Validator.notNull(itemStack, "itemStack"); CraftItemLine line = new CraftItemLine(this, itemStack); lines.add(line); refreshSingleLines(); return line; }
public boolean registerPlaceholder(Plugin plugin, String textPlaceholder, double refreshRate, PlaceholderReplacer replacer) { Validator.notNull(textPlaceholder, "textPlaceholder"); Validator.isTrue(refreshRate >= 0, "refreshRate should be positive"); Validator.notNull(replacer, "replacer"); return PlaceholdersRegister.register(new Placeholder(plugin, textPlaceholder, refreshRate, replacer)); }
@Deprecated public static FloatingItem createFloatingItem(Plugin plugin, Location source, ItemStack itemstack) { Validator.notNull(itemstack, "itemstack"); Validator.isTrue(itemstack.getType() != Material.AIR, "itemstack cannot be AIR"); CraftHologram hologram = (CraftHologram) BackendAPI.getImplementation().createHologram(plugin, source); hologram.appendItemLine(itemstack); return new FakeFloatingItem(hologram, itemstack); }
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0); final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); if (!nmsWorld.getChunkProviderServer().isLoaded(chunkX, chunkZ)) { // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); nmsWorld.entityList.add(nmsEntity); try { validateEntityMethod.invoke(nmsWorld, nmsEntity); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0); final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); if (!nmsWorld.getChunkProviderServer().isLoaded(chunkX, chunkZ)) { // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); nmsWorld.entityList.add(nmsEntity); try { validateEntityMethod.invoke(nmsWorld, nmsEntity); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0); final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); if (!nmsWorld.getChunkProviderServer().isLoaded(chunkX, chunkZ)) { // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); nmsWorld.entityList.add(nmsEntity); try { validateEntityMethod.invoke(nmsWorld, nmsEntity); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0); final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); if (!nmsWorld.getChunkProviderServer().isLoaded(chunkX, chunkZ)) { // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); nmsWorld.entityList.add(nmsEntity); try { validateEntityMethod.invoke(nmsWorld, nmsEntity); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0); final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); if (!nmsWorld.getChunkProviderServer().isChunkLoaded(chunkX, chunkZ)) { // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); nmsWorld.entityList.add(nmsEntity); try { validateEntityMethod.invoke(nmsWorld, nmsEntity); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); if (validateEntityMethod == null) { return nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM); } final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0); final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); if (!nmsWorld.chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) { // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); nmsWorld.entityList.add(nmsEntity); try { validateEntityMethod.invoke(nmsWorld, nmsEntity); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); if (validateEntityMethod == null) { return nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM); } final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0); final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); if (!nmsWorld.chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) { // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); nmsWorld.entityList.add(nmsEntity); try { validateEntityMethod.invoke(nmsWorld, nmsEntity); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
@SuppressWarnings("unchecked") private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) { Validator.isTrue(Bukkit.isPrimaryThread(), "Async entity add"); if (validateEntityMethod == null) { return nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM); } final int chunkX = MathHelper.floor(nmsEntity.locX / 16.0); final int chunkZ = MathHelper.floor(nmsEntity.locZ / 16.0); if (!nmsWorld.chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) { // This should never happen nmsEntity.dead = true; return false; } nmsWorld.getChunkAt(chunkX, chunkZ).a(nmsEntity); nmsWorld.entityList.add(nmsEntity); try { validateEntityMethod.invoke(nmsWorld, nmsEntity); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
/** * Forces the entities to spawn, without checking if the chunk is loaded. */ public void spawnEntities() { Validator.isTrue(!deleted, "hologram already deleted"); despawnEntities(); double currentY = this.y; boolean first = true; for (CraftHologramLine line : lines) { currentY -= line.getHeight(); if (first) { first = false; } else { currentY -= Configuration.spaceBetweenLines; } line.spawn(world, x, currentY, z); if (allowPlaceholders && line instanceof CraftTextLine) { PlaceholdersManager.trackIfNecessary((CraftTextLine) line); } } }
public Hologram createHologram(Plugin plugin, Location source) { Validator.notNull(plugin, "plugin"); Validator.notNull(source, "source"); Validator.notNull(source.getWorld(), "source's world"); Validator.isTrue(Bukkit.isPrimaryThread(), "Async hologram creation"); PluginHologram hologram = new PluginHologram(source, plugin); PluginHologramManager.addHologram(hologram); return hologram; }
@Deprecated public static FloatingItem createIndividualFloatingItem(Plugin plugin, Location source, List<Player> whoCanSee, ItemStack itemstack) { Validator.notNull(plugin, "plugin cannot be null"); Validator.notNull(source, "source cannot be null"); Validator.notNull(source.getWorld(), "source's world cannot be null"); Validator.notNull(itemstack, "itemstack cannot be null"); Validator.isTrue(itemstack.getType() != Material.AIR, "itemstack cannot be AIR"); CraftHologram hologram = (CraftHologram) BackendAPI.getImplementation().createHologram(plugin, source); hologram.appendItemLine(itemstack); hologram.getVisibilityManager().setVisibleByDefault(false); if (whoCanSee != null) { for (Player player : whoCanSee) { hologram.getVisibilityManager().showTo(player); } } return new FakeFloatingItem(hologram, itemstack); }