TinyTools 1.0

Permission based custom commands, join-kick-leave commands, chat formatting, and much more

  1. gyurix
    Native Minecraft Version:
    Legacy (< 1.13)
    Tested Minecraft Versions:
    • 1.7
    • 1.8
    • 1.9
    • 1.10
    • 1.11
    • 1.12
    Contributors:
    gyuriX

    Description
    I made this plugin for competition: LINK, but it can actually be pretty useful for anyones server, so I have uploaded it as a resource, as you can see it.
    This plugin allows you to do some useful things on your server:

    - setup permission based join, leave and kick commands

    - trigger commands, when someone clicks to a block

    - setup permission based chat formatting and command+chat color support (per color permission nodes)

    - make any kind of custom commands with some prebuilt types (MSG, BC, MC, CHAT, OP, CONSOLE, VEL, REMBLOCK, ADDCMD)

    - possibility to make custom commands with some reflection calls

    - replace words in the chat or in the commands with randomly selected ones from the config (useful for i.e. grammar corrections or anti swearing)



    Default configuration
    Code (YAML):
    chat-format:
      default
    : §9§lChat ► §b%1$s§9 ► §f%2$s
      admin
    : §9§lChat ► §c%1$s§9 ► §e%2$s
    blocks
    :
    join
    :
      default
    :
      - MSG §6Welcome <player> on the server!
       - CHAT Hi everyone
       - BC §6§l<player> §ejoined the game
      admin
    :
      - MSG §6Welcome <player> on the server!
    kick
    :
      default
    :
       - BC §4<player> §chas been kicked for
    : §f<cmd>§f.
      admin
    :
      - BC §7Oops, an admin has been kicked?
    quit
    :
      default
    :
       - BC §4<player> §cquit the game.
      admin
    :
       - BC §7Someone has left the game silently
    commands
    :
      remblock
    :
      - REMBLOCK §cThe block you are looking at does not have any commands
       - MSG §6The block you are looking at has been removed successfully
      addcmd
    :
      - ADDCMD §cYou are not looking at a block
       - MSG §aCommand <cmd> has been added to the block you are looking at
      bc
    :
      - BC <cmd>
      vel
    :
      - VEL <cmd>
      tt
    :
      - MSG §b/addcmd [player] <command>:§f Add a command to the block you or the given player is looking at
       - MSG §b/remblock [player]:§f Remove all the commands from a block you are looking at
       - MSG §b/bc [player] <message>:§f Broadcast a message, and send the success message to you or a given player
       - MSG §b/vel [player] <x> <y> <z>:§f Set your or other players velocity
       - MSG §b/tt [player]:§f List the available commands for you or for the given player
       - MSG §b/gm [player] <0-3>:§f Set your or other players gamemode
       - MSG §b/hp [player] hp<=maxhp:§f Set your or other players health
       - MSG §b/maxhp [player] <maxhp>:§f Set your or other players gamemode
       - MSG §b/ws [player] <0.0-1.0>:§f Set your or other players walk speed
       - MSG §b/fs [player] <0.0-1.0>:§f Set your or other players fly speed
       - MSG §b/console [player] <command>:§f Execute a command from the console (the success message is sent to you / to the given player)
      gm
    :
      - MC setGameMode org.bukkit.GameMode
       - MSG §e§lYour gamemode has been changed successfully.
      hp
    :
      - MC setHealth java.lang.Double
       - MSG §e§lYour hp has been set to <cmd>.
      maxhp
    :
      - MC setMaxHealth java.lang.Double
       - MSG §e§lYour maximal hp has been set to <cmd>.
      ws
    :
      - MC setWalkSpeed java.lang.Float
       - MSG §e§lYour walkspeed has been successfully changed to <cmd>.
      fs
    :
      - MC setFlySpeed java.lang.Float
       - MSG §e§lYour flyspeed has been successfully changed to <cmd>.
      console
    :
      - CONSOLE <cmd>
      - MSG §e§lExecuted command §6<cmd>§e§l from console.
    replacements
    :
     - |
       k
        ok
        okay

      - |
       nm
        never mind
        do not care about it

    cmd-replacements
    :
     - |
       cmd
        command
        instruction

    Permissions
    tinytools.join.<category>: Execute the configured join commands of the categories, the player have permission for.

    tinytools.quit.<category>: Execute the configured quit commands of the categories, the player have permission for.


    tinytools.kick.<category>: Execute the configured kick commands of the categories, the player have permission for.


    tinytools.chatcolor.<colorcodechar>: Allow the access for using a colorcode in the chat (available colorcodes: 0123456789abcdefklmnor)


    tinytools.commandcolor.<colorcodechar>: Allow the access for using a colorcode in a command


    tinytools.chatformat.<category>: Allow the access for having a chat format (the last chat format, which the player has perm for will be used)


    tinytools.command.<command-name>: Allow the access for using one of the configured custom commands.

    License

    You are allowed change the plugins source code or include it in another plugin ONLY FOR YOUR OWN SERVER/NETWORK.

    You are allowed to share this plugin, ONLY BY SHARING THE LINK OF THIS SITE.

    You are NOT allowed to share / send to anyone / distribute your plugin, if it contains anything of this plugins source code.


    Source code

    Code (Java):
    package gyurix.tinytools;
    import com.google.common.primitives.Primitives;
    import org.bukkit.*;
    import org.bukkit.entity.Player;
    import org.bukkit.event.*;
    import org.bukkit.event.player.*;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;

    import java.util.*;
    public class Main extends JavaPlugin implements Listener {
        Random r=new Random();
        public void onEnable(){
            saveDefaultConfig();
            Bukkit.getPluginManager().registerEvents(this,this);
        }
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onJoin(PlayerJoinEvent e) throws Throwable{
            e.setJoinMessage(null);
            for (String s:getConfig().getConfigurationSection("join").getKeys(false)){
                if (e.getPlayer().hasPermission("tinytools.join."+s)) execute(e.getPlayer(), "", getConfig().getStringList(s)); }
        }
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onQuit(PlayerQuitEvent e) throws Throwable{
            e.setQuitMessage(null);
            for (String s:getConfig().getConfigurationSection("quit").getKeys(false)){
                if (e.getPlayer().hasPermission("tinytools.quit."+s)) execute(e.getPlayer(), "", getConfig().getStringList(s)); }
        }
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onKick(PlayerKickEvent e) throws Throwable{
            for (String s:getConfig().getConfigurationSection("kick").getKeys(false)){
              if (e.getPlayer().hasPermission("tinytools.kick."+s)) execute(e.getPlayer(), e.getLeaveMessage(), getConfig().getStringList(s));}
        }
        @EventHandler(priority = EventPriority.LOWEST)
        public void onChat(AsyncPlayerChatEvent e){
            String msg=" "+e.getMessage()+" ";
            for (String s:getConfig().getStringList("replacements")){
                String[] d=s.split("\n");
                while (msg.contains(" "+d[0]+" "))
                    msg=msg.replaceFirst(" " + d[0] + " ", " " + d[r.nextInt(d.length - 1) + 1] + " ");}
            e.setMessage(msg.substring(1,msg.length()-1));
            for (char c:"0123456789abcdefklmnor".toCharArray())
                if (e.getPlayer().hasPermission("tinytools.chatcolor."+c)) e.setMessage(e.getMessage().replace("&"+c,"§"+c));
            for (String s:getConfig().getConfigurationSection("chat-format").getKeys(false)){
                if (e.getPlayer().hasPermission("tinytools.chatformat."+s)) e.setFormat(getConfig().getString("chat-format." + s));}}
        public String locToStr(Location l){
            return l.getWorld().getName()+" "+l.getBlockX()+" "+l.getBlockY()+" "+l.getBlockZ();}
        @EventHandler
        public void onClick(PlayerInteractEvent e) throws Throwable{
            if (e.getClickedBlock()!=null)
                execute(e.getPlayer(),"",getConfig().getStringList("blocks." + locToStr(e.getClickedBlock().getLocation())));}
        @EventHandler
        public void onCommand(PlayerCommandPreprocessEvent e) throws Throwable{
            String msg=" "+e.getMessage()+" ";
            for (String s:getConfig().getStringList("cmd-replacements")){
                String[] d=s.split("\n");
                while (msg.contains(" "+d[0]+" "))
                    msg=msg.replaceFirst(" " + d[0] + " ", " " + d[r.nextInt(d.length - 1) + 1] + " ");}
            e.setMessage(msg.substring(1,msg.length()-1));
            for (char c:"0123456789abcdefklmnor".toCharArray())
                if (e.getPlayer().hasPermission("tinytools.commandcolor."+c)) e.setMessage(e.getMessage().replace("&"+c,"§"+c));
            String[] a=e.getMessage().substring(1).split(" ",3);
            for (String s:getConfig().getConfigurationSection("commands").getKeys(false))
                if (a[0].equalsIgnoreCase(s)&&e.getPlayer().hasPermission("tinytools.command."+s)) {
                    execute(a.length <= 2 ? e.getPlayer():Bukkit.getPlayer(a[1]),a[a.length-1],getConfig().getStringList("commands." + s));
                    e.setCancelled(true);}}
        private void execute(Player plr,String cmd,List<String> l) throws Throwable{
            if (l==null) return;
            for (String s:l){if (s==null) continue;
                s=s.replace("<player>",""+plr.getName()).replace("<cmd>",""+cmd);
                if (s.startsWith("MSG "))
                    plr.sendMessage(s.substring(4));
                else if (s.startsWith("BC "))
                    for (Player p:Bukkit.getOnlinePlayers()) p.sendMessage(s.substring(3));
                else if (s.startsWith("MC ")){
                    String[] args = cmd.split(" ");String[] d=s.split(" ");
                    Class[] c= new Class[d.length-2];Object[] o= new Object[d.length-2];
                    for (int i=2;i<d.length;i++){ c[i-2]=Primitives.unwrap(Class.forName(d[i]));
                        o[i-2]=c[i-2].isEnum()? c[i-2].getEnumConstants()[Integer.valueOf(args[i-2])]:
                          Primitives.wrap(c[i - 2]).getMethod("valueOf",String.class).invoke(null,args[i-2]);}
                    if (d[1].equals("CONST")) plr.getClass().getConstructor(c).newInstance(o); else
                        plr.getClass().getMethod(d[1], c).invoke(plr, o);
                } else if (s.startsWith("CHAT ")) plr.chat(s.substring(5));
                else if (s.startsWith("OP ")) { boolean was=plr.isOp();plr.setOp(true);plr.chat(s.substring(3));plr.setOp(was);}
                else if (s.startsWith("CONSOLE ")) Bukkit.dispatchCommand(Bukkit.getConsoleSender(),s.substring(8));
                else if (s.startsWith("VEL ")){ String[] d=s.split(" ");
                    plr.setVelocity(new Vector(Double.valueOf(d[1]), Double.valueOf(d[2]), Double.valueOf(d[3])));}
                else if (s.startsWith("REMBLOCK "))
                    if (getConfig().isSet("blocks."+locToStr(plr.getTargetBlock((Set) null, 20).getLocation()))){
                        getConfig().set("blocks." + locToStr(plr.getTargetBlock((Set) null, 20).getLocation()), null);saveConfig();}
                    else{ plr.sendMessage(s.substring(9));return;}
                else if (s.startsWith("ADDCMD ")){
                    List<String> ls=getConfig().getStringList("blocks."+locToStr(plr.getTargetBlock((Set) null, 20).getLocation()));
                    ls.add(cmd);
                    getConfig().set("blocks."+locToStr(plr.getTargetBlock((Set) null, 20).getLocation()),ls);saveConfig();}
    }}}
    Contact

    Before complaining about any problem / issue of the plugin, if you have any questions/ideas, or if you need a custom plugin, before doing anything else, please CONTACT me on Discord. My Discord name is gyurix#8413
    ENCOM likes this.

Recent Reviews

  1. Vilicius
    Vilicius
    5/5,
    Version: 1.0
    Good JOB!!!! Its really neccesary in a Minecraft Server!!! Keep going!!!

    Probably the best spigot dev.
  2. JACKEARS
    JACKEARS
    5/5,
    Version: 1.0
    Great plugin, very well developed and very configurable. It's great for a smp server as it holds some things that essentials has but lightweight.
    1. gyurix
      Author's Response
      Thanks for your possitive review, if you would like to, you can also take a look at my other plugins.