Search in sources :

Example 1 with DirectoryManager

use of org.anhcraft.spaciouslib.io.DirectoryManager in project SpaciousLib by anhcraft.

the class SpaciousLibTestSpigot method onEnable.

@Override
public void onEnable() {
    new DirectoryManager("plugins/SpaciousLibTest/").mkdirs();
    try {
        new FileManager("plugins/SpaciousLibTest/test.txt").initFile(IOUtils.toByteArray(getClass().getResourceAsStream("/test.txt")));
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        new CommandBuilder("slt", new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                for (String str : sCommand.getCommandsAsString(true)) {
                    commandSender.sendMessage(str);
                }
            }
        }).addSubCommand(new SubCommandBuilder("particle spawn", "Spawn a specific type of particle at your location", new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                commandSender.sendMessage(sCommand.getCommandAsString(subCommand, true));
            }
        }).addArgument(new CommandArgument("type", new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                if (commandSender instanceof Player) {
                    Particle.Type type = StringUtils.get(strings[0].toUpperCase(), Particle.Type.values());
                    if (type == null) {
                        commandSender.sendMessage("Invalid particle type!");
                    } else {
                        Location location = ((Player) commandSender).getLocation();
                        for (int degree = 0; degree < 360; degree++) {
                            double radians = Math.toRadians(degree);
                            double x = Math.cos(radians) * 3;
                            double z = Math.sin(radians) * 3;
                            location.add(x, 0, z);
                            Particle.create(type, location, 10).sendWorld(((Player) commandSender).getWorld());
                            location.subtract(x, 0, z);
                        }
                    }
                }
            }
        }, false), CommandArgument.Type.CUSTOM).addArgument(new CommandArgument("count", new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                if (commandSender instanceof Player) {
                    Particle.Type type = StringUtils.get(strings[0], Particle.Type.values());
                    if (type == null) {
                        commandSender.sendMessage("Invalid particle type!");
                    } else {
                        Location location = ((Player) commandSender).getLocation();
                        for (int degree = 0; degree < 360; degree++) {
                            double radians = Math.toRadians(degree);
                            double x = Math.cos(radians) * 3;
                            double z = Math.sin(radians) * 3;
                            location.add(x, 0, z);
                            Particle.create(type, location, StringUtils.toIntegerNumber(strings[1])).sendWorld(((Player) commandSender).getWorld());
                            location.subtract(x, 0, z);
                        }
                    }
                }
            }
        }, true), CommandArgument.Type.INTEGER_NUMBER).hideTypeCommandString()).addSubCommand(new SubCommandBuilder("particle list", "show all types of particle", new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                StringBuilder pls = new StringBuilder();
                for (Particle.Type p : Particle.Type.values()) {
                    pls.append(p.toString()).append(" ");
                }
                commandSender.sendMessage(pls.toString());
            }
        })).addSubCommand(new SubCommandBuilder("playerlist set", null, new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                commandSender.sendMessage(sCommand.getCommandAsString(subCommand, true));
            }
        }).addArgument("header", new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                commandSender.sendMessage(sCommand.getCommandAsString(subCommand, true));
            }
        }, CommandArgument.Type.CUSTOM, false).addArgument("footer", new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                PlayerList.create(strings[0], strings[1]).sendAll();
            }
        }, CommandArgument.Type.CUSTOM, false)).addSubCommand(new SubCommandBuilder("playerlist remove", null, new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                PlayerList.remove().sendAll();
            }
        })).addSubCommand(new SubCommandBuilder("camera", "View as a random nearby entity", new CommandRunnable() {

            @Override
            public void run(CommandBuilder cmd, SubCommandBuilder subcmd, CommandSender sender, String[] strings, String s) {
                if (sender instanceof Player) {
                    Entity e = RandomUtils.pickRandom(((Player) sender).getNearbyEntities(5, 5, 5));
                    Camera.create(e).sendPlayer((Player) sender);
                }
            }
        })).addSubCommand(new SubCommandBuilder("camera reset", "Reset your view to normal", new CommandRunnable() {

            @Override
            public void run(CommandBuilder cmd, SubCommandBuilder subcmd, CommandSender sender, String[] strings, String s) {
                if (sender instanceof Player) {
                    if (sender instanceof Player) {
                        Camera.create((Player) sender).sendPlayer((Player) sender);
                    }
                }
            }
        })).addSubCommand(new SubCommandBuilder("bungee tp", "Teleport you or a specific player to a server in Bungee network", new CommandRunnable() {

            @Override
            public void run(CommandBuilder cmd, SubCommandBuilder subcmd, CommandSender sender, String[] args, String value) {
                sender.sendMessage(cmd.getCommandAsString(subcmd, true));
            }
        }).addArgument("server", new CommandRunnable() {

            @Override
            public void run(CommandBuilder cmd, SubCommandBuilder subcmd, CommandSender sender, String[] args, String value) {
                if (sender instanceof Player) {
                    BungeeManager.connect((Player) sender, value);
                }
            }
        }, CommandArgument.Type.CUSTOM, false).addArgument("player", new CommandRunnable() {

            @Override
            public void run(CommandBuilder cmd, SubCommandBuilder subcmd, CommandSender sender, String[] args, String value) {
                if (sender instanceof Player) {
                    BungeeManager.connect(value, args[0]);
                }
            }
        }, CommandArgument.Type.ONLINE_PLAYER, true)).addSubCommand(new SubCommandBuilder("bungee ip", "Get your real IP", new CommandRunnable() {

            @Override
            public void run(CommandBuilder cmd, SubCommandBuilder subcmd, CommandSender sender, String[] args, String value) {
                if (sender instanceof Player) {
                    BungeeManager.getIP((Player) sender, new BungeePlayerIPResponse() {

                        @Override
                        public void result(String ip, int port) {
                            sender.sendMessage(ip + ":" + port);
                        }
                    });
                }
            }
        })).buildExecutor(this).addSubCommand(new SubCommandBuilder("bungee data", null, new CommandRunnable() {

            @Override
            public void run(CommandBuilder cmd, SubCommandBuilder subcmd, CommandSender sender, String[] args, String value) {
                sender.sendMessage("sent successfully!");
                ByteArrayOutputStream bytedata = new ByteArrayOutputStream();
                DataOutputStream data = new DataOutputStream(bytedata);
                try {
                    data.writeUTF(sender.getName());
                } catch (IOException e) {
                    e.printStackTrace();
                }
                BungeeManager.forwardData("slt", bytedata.toByteArray());
            }
        })).buildExecutor(this).clone("sl").buildExecutor(this).clone("spaciouslib").buildExecutor(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
    getServer().getPluginManager().registerEvents(this, this);
    System.out.println("Starting socket server...");
    SocketManager.registerServer(25568, new ServerSocketRequestHandler() {

        @Override
        public void request(ServerSocketClientHandler client, String data) {
            System.out.println("Client >> " + data);
        }
    });
    for (Placeholder placeholder : PlaceholderManager.getPlaceholders()) {
        System.out.println(placeholder.getPlaceholder());
    }
}
Also used : Entity(org.bukkit.entity.Entity) Placeholder(org.anhcraft.spaciouslib.placeholder.Placeholder) DataOutputStream(java.io.DataOutputStream) CommandArgument(org.anhcraft.spaciouslib.command.CommandArgument) ServerSocketRequestHandler(org.anhcraft.spaciouslib.socket.ServerSocketRequestHandler) Particle(org.anhcraft.spaciouslib.protocol.Particle) SubCommandBuilder(org.anhcraft.spaciouslib.command.SubCommandBuilder) Player(org.bukkit.entity.Player) DirectoryManager(org.anhcraft.spaciouslib.io.DirectoryManager) CommandRunnable(org.anhcraft.spaciouslib.command.CommandRunnable) BungeePlayerIPResponse(org.anhcraft.spaciouslib.bungee.BungeePlayerIPResponse) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileManager(org.anhcraft.spaciouslib.io.FileManager) IOException(java.io.IOException) ServerSocketClientHandler(org.anhcraft.spaciouslib.socket.ServerSocketClientHandler) CommandSender(org.bukkit.command.CommandSender) CommandBuilder(org.anhcraft.spaciouslib.command.CommandBuilder) SubCommandBuilder(org.anhcraft.spaciouslib.command.SubCommandBuilder) Location(org.bukkit.Location)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 BungeePlayerIPResponse (org.anhcraft.spaciouslib.bungee.BungeePlayerIPResponse)1 CommandArgument (org.anhcraft.spaciouslib.command.CommandArgument)1 CommandBuilder (org.anhcraft.spaciouslib.command.CommandBuilder)1 CommandRunnable (org.anhcraft.spaciouslib.command.CommandRunnable)1 SubCommandBuilder (org.anhcraft.spaciouslib.command.SubCommandBuilder)1 DirectoryManager (org.anhcraft.spaciouslib.io.DirectoryManager)1 FileManager (org.anhcraft.spaciouslib.io.FileManager)1 Placeholder (org.anhcraft.spaciouslib.placeholder.Placeholder)1 Particle (org.anhcraft.spaciouslib.protocol.Particle)1 ServerSocketClientHandler (org.anhcraft.spaciouslib.socket.ServerSocketClientHandler)1 ServerSocketRequestHandler (org.anhcraft.spaciouslib.socket.ServerSocketRequestHandler)1 Location (org.bukkit.Location)1 CommandSender (org.bukkit.command.CommandSender)1 Entity (org.bukkit.entity.Entity)1 Player (org.bukkit.entity.Player)1