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(); }
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)); }
public CraftVisibilityManager(CraftHologram hologram) { Validator.notNull(hologram, "hologram"); this.hologram = hologram; this.visibleByDefault = true; }
public PluginHologram(Location source, Plugin plugin) { super(source); Validator.notNull(plugin, "plugin"); this.plugin = plugin; }
@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; }
protected CraftHologramLine(double height, CraftHologram parent) { Validator.notNull(parent, "parent hologram"); this.height = height; this.parent = parent; }
@Override public void removeLine(int index) { Validator.isTrue(!deleted, "hologram already deleted"); lines.remove(index).despawn(); refreshSingleLines(); }
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[] getFloatingItems(Plugin plugin) { Validator.notNull(plugin, "plugin cannot be null"); return new FloatingItem[0]; }
public void removeLine(CraftHologramLine line) { Validator.isTrue(!deleted, "hologram already deleted"); lines.remove(line); line.despawn(); refreshSingleLines(); }
@Override public CraftTextLine appendTextLine(String text) { Validator.isTrue(!deleted, "hologram already deleted"); CraftTextLine line = new CraftTextLine(this, text); lines.add(line); refreshSingleLines(); return line; }
@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); }
public void spawn(World world, double x, double y, double z) { Validator.notNull(world, "world"); // Remove the old entities when spawning the new ones. despawn(); isSpawned = true; // Do nothing, there are no entities in this class. }
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; }
@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); }
@Override public void setItemStack(ItemStack itemStack) { Validator.notNull(itemStack, "itemStack"); this.itemStack = itemStack; if (nmsItem != null) { nmsItem.setItemStackNMS(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; }