Java Code Examples for com.dsh105.commodus.StringUtil

The following examples show how to use com.dsh105.commodus.StringUtil. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: HoloAPI   Source File: CommandTouchAction.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onTouch(Player who, Action action) {
    String command = this.command.replace("%name%", who.getName());
    command = command.replace("%world%", who.getWorld().getName());

    if (command.startsWith("server ")) {
        String serverName = StringUtil.combineSplit(1, command.split(" "), " ");
        ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(byteOutput);
        try {
            out.writeUTF("Connect");
            out.writeUTF(serverName);
            who.sendPluginMessage(HoloAPI.getCore(), "BungeeCord", byteOutput.toByteArray());
            return;
        } catch (IOException ignored) {
        }
    }

    if (this.shouldPerformAsConsole()) {
        HoloAPI.getCore().getServer().dispatchCommand(HoloAPI.getCore().getServer().getConsoleSender(), command);
    } else {
        who.performCommand(command);
    }
}
 
Example 2
Source Project: HoloAPI   Source File: VisibilityCommand.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Command(
        command = "visibility <id> <type>",
        description = "Set the visibility of a particular hologram",
        permission = "holoapi.holo.visibility.set",
        help = {"Valid types for HoloAPI are: all, permission.", "Visibility types dynamically registered using the API may be defined using this command.", "See the Wiki for more information"}
)
public boolean set(CommandEvent event) {
    Hologram hologram = HoloAPI.getManager().getHologram(event.variable("id"));
    if (hologram == null) {
        event.respond(Lang.HOLOGRAM_NOT_FOUND.getValue("id", event.variable("id")));
        return true;
    }

    Visibility visibility = HoloAPI.getVisibilityMatcher().get(event.variable("type"));
    if (visibility == null) {
        event.respond(Lang.INVALID_VISIBILITY.getValue("visibility", event.variable("type")));
        event.respond(Lang.VALID_VISIBILITIES.getValue("vis", StringUtil.combine(", ", HoloAPI.getVisibilityMatcher().getValidVisibilities().keySet())));
        return true;
    }

    hologram.setVisibility(visibility);
    event.respond(Lang.HOLOGRAM_VISIBILITY_SET.getValue("id", event.variable("id"), "visibility", event.variable("type")));
    return true;
}
 
Example 3
Source Project: HoloAPI   Source File: ClearCommand.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Command(
        command = "clear <type>",
        description = "Clear all holograms of a certain type",
        permission = "holoapi.holo.clear",
        help = "Valid types are: COMPLEX, SIMPLE, ALL"
)
public boolean clearType(CommandEvent event) {
    if (!VALID_TYPES.contains(event.variable("type").toLowerCase())) {
        event.respond(Lang.INVALID_CLEAR_TYPE.getValue("type", event.variable("type"), "valid", StringUtil.combine(", ", VALID_TYPES)));
        return true;
    }
    clear(event.variable("type"));
    if (event.variable("type").equalsIgnoreCase("COMPLEX")) {
        event.respond(Lang.COMPLEX_HOLOGRAMS_CLEARED.getValue());
    } else if (event.variable("type").equalsIgnoreCase("SIMPLE")) {
        event.respond(Lang.SIMPLE_HOLOGRAMS_CLEARED.getValue());
    } else {
        event.respond(Lang.ALL_HOLOGRAMS_CLEARED.getValue());
    }
    return true;
}
 
Example 4
Source Project: EchoPet   Source File: NameSuccessPrompt.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getPromptText(ConversationContext context) {
    String name = (String) context.getSessionData("name");
    boolean success = this.pet.setPetName(name, false);
    if (success) {
        return this.admin ? Lang.ADMIN_NAME_PET.toString()
                .replace("%player%", this.pet.getNameOfOwner())
                .replace("%type%", StringUtil.capitalise(this.pet.getPetType().toString().replace("_", " ")))
                .replace("%name%", name)

                : Lang.NAME_PET.toString()
                .replace("%type%", StringUtil.capitalise(this.pet.getPetType().toString().replace("_", " ")))
                .replace("%name%", name);
    } else {
        return Lang.NAME_NOT_ALLOWED.toString().replace("%name%", name);
    }
}
 
Example 5
Source Project: EchoPet   Source File: PetManager.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public IPet createPet(Player owner, PetType petType, PetType riderType) {
    if (ReflectionUtil.BUKKIT_VERSION_NUMERIC == 178 && (petType == PetType.HUMAN) || riderType == PetType.HUMAN) {
        Lang.sendTo(owner, Lang.HUMAN_PET_DISABLED.toString());
        return null;
    }
    removePets(owner, true);
    if (!WorldUtil.allowPets(owner.getLocation())) {
        Lang.sendTo(owner, Lang.PETS_DISABLED_HERE.toString().replace("%world%", StringUtil.capitalise(owner.getWorld().getName())));
        return null;
    }
    if (!EchoPet.getOptions().allowPetType(petType)) {
        Lang.sendTo(owner, Lang.PET_TYPE_DISABLED.toString().replace("%type%", StringUtil.capitalise(petType.toString())));
        return null;
    }
    IPet pi = petType.getNewPetInstance(owner);
    if (pi == null) {
        Lang.sendTo(owner, Lang.PET_TYPE_NOT_COMPATIBLE.toString().replace("%type%", StringUtil.capitalise(petType.toString())));
        return null;
    }
    pi.createRider(riderType, true);
    forceAllValidData(pi);
    pets.add(pi);
    return pi;
}
 
Example 6
Source Project: EchoPet   Source File: PetOwnerListener.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
    final Player p = event.getPlayer();
    final IPet pi = EchoPet.getManager().getPet(p);
    Iterator<IPet> i = EchoPet.getManager().getPets().iterator();
    while (i.hasNext()) {
        IPet pet = i.next();
        if (pet.getEntityPet() instanceof IEntityPacketPet && ((IEntityPacketPet) pet.getEntityPet()).hasInititiated()) {
            if (GeometryUtil.getNearbyEntities(event.getTo(), 50).contains(pet)) {
                ((IEntityPacketPet) pet.getEntityPet()).updatePosition();
            }
        }
    }
    if (pi != null) {
        if (!WorldUtil.allowPets(event.getTo())) {
            Lang.sendTo(p, Lang.PETS_DISABLED_HERE.toString().replace("%world%", StringUtil.capitalise(event.getTo().getWorld().getName())));
            EchoPet.getManager().saveFileData("autosave", pi);
            EchoPet.getSqlManager().saveToDatabase(pi, false);
            EchoPet.getManager().removePet(pi, false);
        }
    }
}
 
Example 7
Source Project: EchoPet   Source File: PetUtil.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static ArrayList<String> generatePetInfo(IPet pt) {
    ArrayList<String> info = new ArrayList<String>();
    info.add(ChatColor.GOLD + " - Pet Type: " + ChatColor.YELLOW + StringUtil.capitalise(pt.getPetType().toString()));
    info.add(ChatColor.GOLD + " - Name: " + ChatColor.YELLOW + pt.getPetName());
    if (pt instanceof IAgeablePet) {
        info.add(ChatColor.GOLD + " - Baby: " + ChatColor.YELLOW + ((IAgeablePet) pt).isBaby());
    }
    if (pt.getPetType() == PetType.ZOMBIE) {
        info.add(ChatColor.GOLD + " - Baby: " + ChatColor.YELLOW + ((IZombiePet) pt).isBaby());
    }
    if (pt.getPetType() == PetType.PIGZOMBIE) {
        info.add(ChatColor.GOLD + " - Baby: " + ChatColor.YELLOW + ((IPigZombiePet) pt).isBaby());
    }
    info.addAll(generatePetDataInfo(pt));

    if (pt.getRider() != null) {
        info.add(ChatColor.RED + "Rider:");
        info.addAll(generatePetInfo(pt.getRider()));
    }

    return info;
}
 
Example 8
Source Project: HoloAPI   Source File: IndicatorListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void showPotionHologram(Entity e, Collection<PotionEffect> effects) {
    for (PotionEffect effect : effects) {
        int amp = (effect.getAmplifier() < 1 ? 1 : effect.getAmplifier()) + 1;
        String content = Settings.INDICATOR_FORMAT.getValue("potion", effect.getType().getName().toLowerCase());
        content = content.replace("%effect%", StringUtil.capitalise(effect.getType().getName().replace("_", " "))).replace("%amp%", "" + new RomanNumeral(amp));
        Location l = e.getLocation().clone();
        l.setY(l.getY() + Settings.INDICATOR_Y_OFFSET.getValue("potion"));
        HoloAPI.getManager().createSimpleHologram(l, Settings.INDICATOR_TIME_VISIBLE.getValue("potion"), true, content);
    }
}
 
Example 9
Source Project: HoloAPI   Source File: InfoCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected static void info(CommandSender sender, Collection<Hologram> holograms) {
    for (Hologram hologram : holograms) {
        ArrayList<String> list = new ArrayList<>();
        list.add(ChatColor.GOLD + "" + ChatColor.UNDERLINE + "Hologram Preview:");
        if (hologram instanceof AnimatedHologram) {
            AnimatedHologram animatedHologram = (AnimatedHologram) hologram;
            if (animatedHologram.isImageGenerated() && (HoloAPI.getAnimationLoader().exists(animatedHologram.getAnimationKey())) || HoloAPI.getAnimationLoader().existsAsUnloadedUrl(animatedHologram.getAnimationKey())) {
                list.add(ChatColor.YELLOW + "" + ChatColor.ITALIC + animatedHologram.getAnimationKey() + " (ANIMATION)");
            } else {
                Collections.addAll(list, animatedHologram.getFrames().get(0).getLines());
            }
        } else {
            if (hologram.getLines().length > 1) {
                for (StoredTag tag : hologram.serialise()) {
                    if (tag.isImage()) {
                        if (HoloAPI.getConfig(ConfigType.MAIN).getBoolean("images." + tag.getContent() + ".requiresBorder", false)) {
                            for (String s : HoloAPI.getImageLoader().getGenerator(tag.getContent()).getLines()) {
                                list.add(HoloAPI.getTagFormatter().formatBasic(ChatColor.WHITE + s));
                            }
                        } else {
                            list.add(ChatColor.YELLOW + "" + ChatColor.ITALIC + tag.getContent() + " (IMAGE)");
                        }
                    } else {
                        list.add(HoloAPI.getTagFormatter().formatBasic(ChatColor.WHITE + tag.getContent()));
                    }
                }
            } else {
                list.add(HoloAPI.getTagFormatter().formatBasic(hologram.getLines()[0]));
            }
        }
        if (list.size() > 1) {
            new PowerMessage("•• " + ChatColor.AQUA + hologram.getSaveId() + ChatColor.DARK_AQUA + " at " + (int) hologram.getDefaultX() + ", " + (int) hologram.getDefaultY() + ", " + (int) hologram.getDefaultZ() + ", " + hologram.getWorldName()).tooltip(list.toArray(StringUtil.EMPTY_STRING_ARRAY)).suggest("/holo teleport " + hologram.getSaveId()).send(sender);
        }
    }
}
 
Example 10
Source Project: HoloAPI   Source File: TouchCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Command(
        command = "touch info <id>",
        description = "Add an action to perform when a certain hologram is touched",
        permission = "holoapi.holo.touch.info"
)
public boolean info(CommandEvent event) {
    Hologram hologram = HoloAPI.getManager().getHologram(event.variable("id"));
    if (hologram == null) {
        event.respond(Lang.HOLOGRAM_NOT_FOUND.getValue("id", event.variable("id")));
        return true;
    }

    if (hologram.getAllTouchActions().isEmpty()) {
        event.respond(Lang.NO_TOUCH_ACTIONS.getValue("id", hologram.getSaveId()));
        return true;
    }

    event.respond(Lang.TOUCH_ACTIONS.getValue("id", hologram.getSaveId()));
    for (TouchAction action : hologram.getAllTouchActions()) {
        if (action instanceof CommandTouchAction) {
            event.respond("•• " + "{c1}Command {c2}/" + ((CommandTouchAction) action).getCommand() + " {c1}" + (((CommandTouchAction) action).shouldPerformAsConsole() ? "as console" : "as player"));
            continue;
        }

        if (action.getSaveKey() == null) {
            event.respond("•• {c1}Unidentified TouchAction");
        } else {
            event.respond("•• {c2}" + StringUtil.capitalise(action.getSaveKey().replace("_", " ")));
        }
    }
    return true;
}
 
Example 11
Source Project: EchoPet   Source File: EchoPetAPI.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gives a {@link com.dsh105.echopet.api.pet.Pet} to the specified {@link Player}
 * <p/>
 * Pets will be spawned immediately next to the target player, linked until it is removed.
 *
 * @param player      the {@link org.bukkit.entity.Player} that will be provided with a {@link
 *                    com.dsh105.echopet.api.pet.Pet}
 * @param petType     the {@link com.dsh105.echopet.compat.api.entity.PetType} (type of {@link
 *                    com.dsh105.echopet.api.pet.Pet}) that will be given to the player
 * @param sendMessage defines if the plugin sends a message to the target {@link Player}
 * @return the {@link com.dsh105.echopet.api.pet.Pet} created
 */
public IPet givePet(Player player, PetType petType, boolean sendMessage) {
    if (player != null && petType != null) {
        IPet pet = EchoPet.getManager().createPet(player, petType, sendMessage);
        if (pet == null) {
            EchoPet.LOG.severe("Failed to give " + petType.toString() + " to " + player.getName() + " through the EchoPetAPI. Maybe this PetType is disabled in the Config.yml?");
            return null;
        }
        if (sendMessage) {
            Lang.sendTo(player, Lang.CREATE_PET.toString().replace("%type%", StringUtil.capitalise(petType.toString())));
        }
        return pet;
    }
    return null;
}
 
Example 12
Source Project: EchoPet   Source File: PetManager.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public IPet createPet(Player owner, PetType petType, boolean sendMessageOnFail) {
    if (ReflectionUtil.BUKKIT_VERSION_NUMERIC == 178 && petType == PetType.HUMAN) {
        if (sendMessageOnFail) {
            Lang.sendTo(owner, Lang.HUMAN_PET_DISABLED.toString());
        }
        return null;
    }
    removePets(owner, true);
    if (!WorldUtil.allowPets(owner.getLocation())) {
        if (sendMessageOnFail) {
            Lang.sendTo(owner, Lang.PETS_DISABLED_HERE.toString().replace("%world%", StringUtil.capitalise(owner.getWorld().getName())));
        }
        return null;
    }
    if (!EchoPet.getOptions().allowPetType(petType)) {
        if (sendMessageOnFail) {
            Lang.sendTo(owner, Lang.PET_TYPE_DISABLED.toString().replace("%type%", StringUtil.capitalise(petType.toString())));
        }
        return null;
    }
    IPet pi = petType.getNewPetInstance(owner);
    if (pi == null) {
        if (sendMessageOnFail) {
            Lang.sendTo(owner, Lang.PET_TYPE_NOT_COMPATIBLE.toString().replace("%type%", StringUtil.capitalise(petType.toString())));
        }
        return null;
    }
    forceAllValidData(pi);
    pets.add(pi);
    return pi;
}
 
Example 13
Source Project: EchoPet   Source File: PetMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void open(boolean sendMessage) {
    PetMenuOpenEvent menuEvent = new PetMenuOpenEvent(this.pet.getOwner(), PetMenuOpenEvent.MenuType.MAIN);
    EchoPet.getPlugin().getServer().getPluginManager().callEvent(menuEvent);
    if (menuEvent.isCancelled()) {
        return;
    }
    this.pet.getOwner().openInventory(this.inv);
    if (sendMessage) {
        Lang.sendTo(this.pet.getOwner(), Lang.OPEN_MENU.toString().replace("%type%", StringUtil.capitalise(this.pet.getPetType().toString().replace("_", " "))));
    }
}
 
Example 14
Source Project: HoloAPI   Source File: ScriptBuilderPrompt.java    License: GNU General Public License v3.0 4 votes vote down vote up
public String[] buildCompiledOutput() {
    return new ArrayList<>(lines).toArray(StringUtil.EMPTY_STRING_ARRAY);
}
 
Example 15
Source Project: EchoPet   Source File: Pet.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public Pet createRider(final PetType pt, boolean sendFailMessage) {
    if (pt == PetType.HUMAN) {
        if (sendFailMessage) {
            Lang.sendTo(this.getOwner(), Lang.RIDERS_DISABLED.toString().replace("%type%", StringUtil.capitalise(this.getPetType().toString())));
        }
        return null;
    }
    if (!EchoPet.getOptions().allowRidersFor(this.getPetType())) {
        if (sendFailMessage) {
            Lang.sendTo(this.getOwner(), Lang.RIDERS_DISABLED.toString().replace("%type%", StringUtil.capitalise(this.getPetType().toString())));
        }
        return null;
    }
    if (this.isOwnerRiding()) {
        this.ownerRidePet(false);
    }
    if (this.rider != null) {
        this.removeRider();
    }
    IPet newRider = pt.getNewPetInstance(this.getOwner());
    if (newRider == null) {
        if (sendFailMessage) {
            Lang.sendTo(getOwner(), Lang.PET_TYPE_NOT_COMPATIBLE.toString().replace("%type%", StringUtil.capitalise(getPetType().toString())));
        }
        return null;
    }
    this.rider = (Pet) newRider;
    this.rider.setRider();
    new BukkitRunnable() {
        @Override
        public void run() {
            if (getCraftPet() != null) {
                getCraftPet().setPassenger(Pet.this.getRider().getCraftPet());
            }
            EchoPet.getSqlManager().saveToDatabase(Pet.this.rider, true);
        }
    }.runTaskLater(EchoPet.getPlugin(), 5L);

    return this.rider;
}
 
Example 16
Source Project: EchoPet   Source File: PetRegistrationEntry.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static PetRegistrationEntry create(PetType petType) {
    return new PetRegistrationEntry(StringUtil.capitalise(petType.toString().toLowerCase().replace("_", " ")).replace(" ", "") + "-Pet", petType.getRegistrationId(), petType.getPetClass(), petType.getEntityClass());
}
 
Example 17
Source Project: EchoPet   Source File: DataMenu.java    License: GNU General Public License v3.0 4 votes vote down vote up
public DataMenu(MenuItem mi, IPet pet) {
    this.pet = pet;
    int size = mi == MenuItem.COLOR ? 18 : 9;
    this.inv = Bukkit.createInventory(pet.getOwner(), size, "EchoPet DataMenu - " + StringUtil.capitalise(mi.toString().replace("_", " ")));
    this.setItems(mi.getMenuType(), size);
}