Solved Tab Completer Default Minecraft Commands Not Working

Discussion in 'Spigot Plugin Development' started by Th3_DoC, Feb 10, 2020.

  1. I am having trouble finding someone with any knowledge to help me learn! Hopefully some luck this time. I have setup permissions in my plugin and the values change true/false no problem. It's the default commands that are buggy....they work...but without tabComplete...I have no other plugins on the test server aside from luckperms i was using to debug. It seems I can have the tabComplete working if i am OP or luckPerms sets "minecraft.command.*" only, i cannot set it this way via my plugin i will not get tabComplete.....However on a side note when changing worlds(PlayerChangeWorldEvent) I set permissions true/false also gamemode creative/survival.....when i go to creative permissions are true and i can use commands w/o tab complete...when i go to survival i can use tabComplete but have no permissions! Also when first joining the server in survival i do not have access to tab complete...I've been reading code/tuts/spigot forums/bukkit forums/java docs...u name it i think i have probably seen it google is nothing but purple links lol

    I feel like theirs an easy fix in the handlerList or somewhere along the lines of the WorldChangeEvent....or some code that's run just after we switch perms/worlds, therefore it doesn't register tabComplete until we switch again, as if I /op via console and /deop in game...I can still see commands but not use them....I really need some help here guys! a nudge in the right direction would be awsome I'm stuck and feeling like i have no where else to look. All i really need to-do is establish the connection with tabComplete to "refresh" it...I think I have the logic, just not any know how of implementation...

    My Code
    PermManager.java
    Code (Text):

    package me.th3doc.creativetp.playerconfigs;

    import me.th3doc.creativetp.Main;
    import me.th3doc.creativetp.Perms;
    import org.bukkit.entity.Player;
    import org.bukkit.permissions.PermissionAttachment;

    public class PermManager extends ConfigManager {
        private Player p;
        private String uuid;
        private PermissionAttachment perms;
        private Perms permission = new Perms();

        public PermManager(Main main, String uuid, String yml) {
            super(main, uuid, yml);
        }


        public void setPerms(Player player, Perms perm) {
            p = player;
            uuid = p.getUniqueId().toString();
            perms = perm.getPermAttachment(uuid);
            perms.setPermission(permission.allCommands(), true);
            p.sendMessage("Commands = " + p.hasPermission(permission.allCommands()));//debug
        }

        public void removePerms(Player player, Perms perm) {
            p = player;
            uuid = p.getUniqueId().toString();
            perms = perm.getPermAttachment(uuid);
            perms.unsetPermission(permission.allCommands());
            p.sendMessage("Commands = " + p.hasPermission(permission.allCommands()));//debug
        }
    }
     
    Events.java
    Code (Text):

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent e) {
        p = e.getPlayer();
        uuid = p.getUniqueId().toString();
        PermissionAttachment attachment = p.addAttachment(main);
        perm.resetPermAttachment(uuid);
        perm.setPermAttachment(uuid, attachment);
    }

    @EventHandler
    public void worldChange(PlayerChangedWorldEvent e) {
        p = e.getPlayer();
        uuid = p.getUniqueId().toString();
        PermManager pManage = new PermManager(main, uuid, "Perms.yml");

        if(p.getWorld().getName().equals(main.getConfig().get("CreativeWorld"))) {
            p.setGameMode(GameMode.CREATIVE);
            pManage.setPerms(p, perm);
        }
        else {
            p.setGameMode(GameMode.SURVIVAL);
            pManage.removePerms(p, perm);
        }
    }
     
    Perms.java
    Code (Text):

    package me.th3doc.creativetp;

    import org.bukkit.permissions.PermissionAttachment;

    import java.util.HashMap;

    public class Perms {
        private HashMap<String, PermissionAttachment> perms = new HashMap<String, PermissionAttachment>();

        public PermissionAttachment getPermAttachment(String uuid) {
            return perms.get(uuid);
        }

        public void resetPermAttachment(String uuid) {
            perms.remove(uuid);
        }

        public void setPermAttachment(String uuid, PermissionAttachment attachment) {
            perms.put(uuid, attachment);
        }

        //Minecraft/Bukit Perms
        public String allCommands() {
            return "minecraft.command.*";
        }

        //CreativeTP Perms
        public String modifyWorldPerm() {
            return "creativetp.modify.*";
        }

        public String createWorldPerm() {
            return "creativetp.modify.create";
        }

        public String setWorldPerm() {
            return "creativetp.modify.set";
        }

        public String creativeTeleportPerm() {
            return "creativetp.tp.*";
        }

        public String creativeVoidTeleportPerm() {
            return "creativetp.tp.void";
        }

        public String creativeFlatTeleportPerm() {
            return "creativetp.tp.flat";
        }
    }
     
     
  2. Bump
    Abstract Classes or Command Map my answer? maybe packets? I don't know much about them but I can learn if i know where to start :)
     
  3. I'm having a hard time getting the actual issue across, so I am trying one more time, here goes nothing...

    I'm having issues, I initially set permissions in my plugin, and have tried luckperms and pex to ensure it wasn't my code. I then debugged and pulled everything apart and tried everything i could, and am in search of help.

    This is hard to explain? as this is not suppose to happen from what i can understand, i'm going to try and explain it.

    When i use a permission plugin, or i set a permission within my plugin I can use the commands as expected but NOT the tab complete. The name of the command is typed in red as if invalid, however it still works.

    Now i have permission, but NOT the tabCompleter information i must manually type everything in. I want tabCompleter to send me the information like it does when i set myself, or another player as an OP.

    If i TP to another server world, or if i /op and then /deop myself I now have the TabCompleter information and permissions, I would like to know how minecraft does this so i can mimic it without the need to TP to another world or /op then /deop myself, or another player i may not know, who might find an exploit to this. Now knowing this is not intended behaviour I'm wondering if i've done something wrong can anyone take the time to skim my plugin, maybe test the code themselves and give feed back? server setting? ... Spigot's tabcomplete option is set to 0 i'm not an idiot, but thanks for thinking it :stuck_out_tongue_winking_eye: Thanks for any help in the matter :slight_smile:

    https://github.com/Th3-DoC/CreativeTP

    EDIT: So i feel stupid but 10 Days later i stumbled upon player.updateCommands() this is what i was looking for should anyone ever have issues and find this thread :)
     
    #3 Th3_DoC, Feb 11, 2020
    Last edited: Feb 21, 2020
    • Like Like x 1