Search in sources :

Example 1 with GroupEntityData

use of de.dytanic.cloudnet.lib.player.permission.GroupEntityData in project CloudNet by Dytanic.

the class BukkitListener method handle.

@EventHandler(priority = EventPriority.LOWEST)
public void handle(PlayerLoginEvent event) {
    if (CloudServer.getInstance().getCloudPlayers().containsKey(event.getPlayer().getUniqueId()) && requests.contains(event.getPlayer().getUniqueId())) {
        requests.remove(event.getPlayer().getUniqueId());
        if (CloudAPI.getInstance().getPermissionPool() != null && CloudAPI.getInstance().getPermissionPool().isAvailable())
            try {
                Field field;
                Class<?> clazz = ReflectionUtil.reflectCraftClazz(".entity.CraftHumanEntity");
                if (clazz != null)
                    field = clazz.getDeclaredField("perm");
                else
                    field = Class.forName("net.glowstone.entity.GlowHumanEntity").getDeclaredField("permissions");
                field.setAccessible(true);
                field.set(event.getPlayer(), new CloudPermissble(event.getPlayer()));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
    } else {
        event.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("server-kick-proxy-disallow")));
        event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("server-kick-proxy-disallow")));
        return;
    }
    if (CloudServer.getInstance().getGroupData() != null) {
        if (CloudAPI.getInstance().getServerGroupData(CloudAPI.getInstance().getGroup()).isMaintenance()) {
            if (!event.getPlayer().hasPermission("cloudnet.group.maintenance")) {
                event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("server-group-maintenance-kick")));
                return;
            }
        }
        if (CloudAPI.getInstance().getServerGroupData(CloudAPI.getInstance().getGroup()).getJoinPower() > 0 && (!CloudAPI.getInstance().getServerGroupData(CloudAPI.getInstance().getGroup()).getMode().equals(ServerGroupMode.LOBBY) || !CloudAPI.getInstance().getServerGroupData(CloudAPI.getInstance().getGroup()).getMode().equals(ServerGroupMode.STATIC_LOBBY))) {
            CloudPlayer cloudPlayer = CloudServer.getInstance().getCloudPlayers().get(event.getPlayer().getUniqueId());
            int joinPower = CloudAPI.getInstance().getServerGroupData(CloudAPI.getInstance().getGroup()).getJoinPower();
            boolean acceptLogin = false;
            for (GroupEntityData entityData : cloudPlayer.getPermissionEntity().getGroups()) {
                if (CloudAPI.getInstance().getPermissionGroup(entityData.getGroup()).getJoinPower() >= joinPower)
                    acceptLogin = true;
                if (event.getPlayer().hasPermission("cloudnet.joinpower." + CloudAPI.getInstance().getPermissionGroup(entityData.getGroup()).getJoinPower()))
                    acceptLogin = true;
            }
            if (!acceptLogin) {
                CloudServer.getInstance().getCloudPlayers().remove(event.getPlayer().getUniqueId());
                event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("joinpower-deny")));
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) CloudPermissble(de.dytanic.cloudnet.bridge.internal.util.CloudPermissble) GroupEntityData(de.dytanic.cloudnet.lib.player.permission.GroupEntityData) EventHandler(org.bukkit.event.EventHandler)

Example 2 with GroupEntityData

use of de.dytanic.cloudnet.lib.player.permission.GroupEntityData in project CloudNet by Dytanic.

the class VaultPermissionImpl method playerRemoveGroup.

@Override
public boolean playerRemoveGroup(String s, String s1, String s2) {
    OfflinePlayer offlinePlayer = getPlayer(s1);
    PermissionEntity permissionEntity = offlinePlayer.getPermissionEntity();
    GroupEntityData groupEntityData = CollectionWrapper.filter(permissionEntity.getGroups(), new Acceptable<GroupEntityData>() {

        @Override
        public boolean isAccepted(GroupEntityData groupEntityData) {
            return groupEntityData.getGroup().equalsIgnoreCase(s2);
        }
    });
    if (groupEntityData != null)
        permissionEntity.getGroups().remove(groupEntityData);
    offlinePlayer.setPermissionEntity(permissionEntity);
    updatePlayer(offlinePlayer);
    return true;
}
Also used : OfflinePlayer(de.dytanic.cloudnet.lib.player.OfflinePlayer) PermissionEntity(de.dytanic.cloudnet.lib.player.permission.PermissionEntity) GroupEntityData(de.dytanic.cloudnet.lib.player.permission.GroupEntityData)

Example 3 with GroupEntityData

use of de.dytanic.cloudnet.lib.player.permission.GroupEntityData in project CloudNet by Dytanic.

the class VaultPermissionImpl method getPlayerGroups.

@Override
public String[] getPlayerGroups(String s, String s1) {
    PermissionEntity permissionEntity = getPlayer(s1).getPermissionEntity();
    String[] data = new String[permissionEntity.getGroups().size()];
    short i = 0;
    for (GroupEntityData groupEntityData : permissionEntity.getGroups()) {
        data[i++] = groupEntityData.getGroup();
    }
    return data;
}
Also used : PermissionEntity(de.dytanic.cloudnet.lib.player.permission.PermissionEntity) GroupEntityData(de.dytanic.cloudnet.lib.player.permission.GroupEntityData)

Example 4 with GroupEntityData

use of de.dytanic.cloudnet.lib.player.permission.GroupEntityData in project CloudNet by Dytanic.

the class CommandPermissions method onExecuteCommand.

@Override
public void onExecuteCommand(CommandSender sender, String[] args) {
    PermissionPool permissionPool = PermissionModule.getInstance().getPermissionPool();
    if (args.length > 0) {
        if (args[0].equalsIgnoreCase("group")) {
            if (args.length == 1) {
                sender.sendMessage(NetworkUtils.SPACE_STRING, "Permission groups:");
                for (PermissionGroup permissionGroup : PermissionModule.getInstance().getPermissionPool().getGroups().values()) {
                    sender.sendMessage(permissionGroup.getName() + " [" + permissionGroup.getJoinPower() + "] implements " + permissionGroup.getImplementGroups());
                }
                sender.sendMessage(NetworkUtils.SPACE_STRING);
                return;
            }
            if (args.length == 2) {
                if (permissionPool.getGroups().containsKey(args[1])) {
                    sender.sendMessage(NetworkUtils.SPACE_STRING);
                    PermissionGroup permissionGroup = permissionPool.getGroups().get(args[1]);
                    sender.sendMessage("Name: " + permissionGroup.getName());
                    sender.sendMessage("Implementations: " + permissionGroup.getImplementGroups());
                    sender.sendMessage("TagId: " + permissionGroup.getTagId());
                    sender.sendMessage("JoinPower: " + permissionGroup.getJoinPower());
                    for (Map.Entry<String, Boolean> x : permissionGroup.getPermissions().entrySet()) sender.sendMessage("- " + x.getKey() + ":" + x.getValue());
                    sender.sendMessage(NetworkUtils.SPACE_STRING);
                    sender.sendMessage("Permissions for server groups:");
                    for (Map.Entry<String, List<String>> x : permissionGroup.getServerGroupPermissions().entrySet()) {
                        sender.sendMessage(x.getKey() + ":");
                        CollectionWrapper.iterator(x.getValue(), new Runnabled<String>() {

                            @Override
                            public void run(String obj) {
                                sender.sendMessage("- " + obj);
                            }
                        });
                    }
                    sender.sendMessage(NetworkUtils.SPACE_STRING);
                } else {
                    sender.sendMessage("The specified permission group doesn't exist");
                }
            }
            if (args.length == 4) {
                if (args[2].equalsIgnoreCase("setDisplay")) {
                    if (permissionPool.getGroups().containsKey(args[1])) {
                        PermissionGroup permissionGroup = permissionPool.getGroups().get(args[1]);
                        permissionGroup.setDisplay(args[3].replace("_", NetworkUtils.SPACE_STRING));
                        PermissionModule.getInstance().getConfigPermission().updatePermissionGroup(permissionGroup);
                        CloudNet.getInstance().getNetworkManager().reload();
                        CloudNet.getInstance().getNetworkManager().updateAll0();
                        sender.sendMessage("You set the display for the permission group " + permissionGroup.getName() + " to \"" + permissionGroup.getDisplay() + "\"");
                    } else {
                        sender.sendMessage("The specified permission group doesn't exist");
                    }
                }
                if (args[2].equalsIgnoreCase("setPrefix")) {
                    if (permissionPool.getGroups().containsKey(args[1])) {
                        PermissionGroup permissionGroup = permissionPool.getGroups().get(args[1]);
                        permissionGroup.setPrefix(args[3].replace("_", NetworkUtils.SPACE_STRING));
                        PermissionModule.getInstance().getConfigPermission().updatePermissionGroup(permissionGroup);
                        CloudNet.getInstance().getNetworkManager().reload();
                        CloudNet.getInstance().getNetworkManager().updateAll0();
                        sender.sendMessage("You set the prefix for the permission group " + permissionGroup.getName() + " to \"" + permissionGroup.getPrefix() + "\"");
                    } else {
                        sender.sendMessage("The specified permission group doesn't exist");
                    }
                }
                if (args[2].equalsIgnoreCase("setSuffix")) {
                    if (permissionPool.getGroups().containsKey(args[1])) {
                        PermissionGroup permissionGroup = permissionPool.getGroups().get(args[1]);
                        permissionGroup.setSuffix(args[3].replace("_", NetworkUtils.SPACE_STRING));
                        PermissionModule.getInstance().getConfigPermission().updatePermissionGroup(permissionGroup);
                        CloudNet.getInstance().getNetworkManager().reload();
                        CloudNet.getInstance().getNetworkManager().updateAll0();
                        sender.sendMessage("You set the suffix for the permission group " + permissionGroup.getName() + " to \"" + permissionGroup.getSuffix() + "\"");
                    } else {
                        sender.sendMessage("The specified permission group doesn't exist");
                    }
                }
                if (args[2].equalsIgnoreCase("setDefault")) {
                    if (permissionPool.getGroups().containsKey(args[1])) {
                        PermissionGroup permissionGroup = permissionPool.getGroups().get(args[1]);
                        permissionGroup.setDefaultGroup(args[3].equalsIgnoreCase("true"));
                        PermissionModule.getInstance().getConfigPermission().updatePermissionGroup(permissionGroup);
                        CloudNet.getInstance().getNetworkManager().reload();
                        CloudNet.getInstance().getNetworkManager().updateAll0();
                        sender.sendMessage("You set the default group attribute for the permission group " + permissionGroup.getName() + " to \"" + permissionGroup.isDefaultGroup() + "\"");
                    } else {
                        sender.sendMessage("The specified permission group doesn't exist");
                    }
                }
                if (args[2].equalsIgnoreCase("setJoinPower")) {
                    if (permissionPool.getGroups().containsKey(args[1]) && NetworkUtils.checkIsNumber(args[3])) {
                        PermissionGroup permissionGroup = permissionPool.getGroups().get(args[1]);
                        permissionGroup.setJoinPower(Integer.parseInt(args[3]));
                        PermissionModule.getInstance().getConfigPermission().updatePermissionGroup(permissionGroup);
                        CloudNet.getInstance().getNetworkManager().reload();
                        CloudNet.getInstance().getNetworkManager().updateAll0();
                        sender.sendMessage("You set the join power for the permission group " + permissionGroup.getName() + " to \"" + permissionGroup.getJoinPower() + "\"");
                    } else {
                        sender.sendMessage("The specified permission group doesn't exist");
                    }
                }
                if (args[2].equalsIgnoreCase("setTagId")) {
                    if (permissionPool.getGroups().containsKey(args[1]) && NetworkUtils.checkIsNumber(args[3])) {
                        PermissionGroup permissionGroup = permissionPool.getGroups().get(args[1]);
                        permissionGroup.setTagId(Integer.parseInt(args[3]));
                        PermissionModule.getInstance().getConfigPermission().updatePermissionGroup(permissionGroup);
                        CloudNet.getInstance().getNetworkManager().reload();
                        CloudNet.getInstance().getNetworkManager().updateAll0();
                        sender.sendMessage("You set the tagID for the permission group " + permissionGroup.getName() + " to \"" + permissionGroup.getTagId() + "\"");
                    } else {
                        sender.sendMessage("The specified permission group doesn't exist");
                    }
                }
                return;
            }
            if (args.length == 5) {
                if (args[2].equalsIgnoreCase("add") && args[3].equalsIgnoreCase("permission")) {
                    if (permissionPool.getGroups().containsKey(args[1])) {
                        PermissionGroup permissionGroup = permissionPool.getGroups().get(args[1]);
                        permissionGroup.getPermissions().put(args[4].replaceFirst("-", ""), !args[4].startsWith("-"));
                        PermissionModule.getInstance().getConfigPermission().updatePermissionGroup(permissionGroup);
                        CloudNet.getInstance().getNetworkManager().reload();
                        CloudNet.getInstance().getNetworkManager().updateAll0();
                        sender.sendMessage("You added the permission " + args[4] + " to the permission group \"" + permissionGroup.getName() + "\"");
                    } else {
                        sender.sendMessage("The specified permission group doesn't exist");
                    }
                }
                if (args[2].equalsIgnoreCase("remove") && args[3].equalsIgnoreCase("permission")) {
                    if (permissionPool.getGroups().containsKey(args[1])) {
                        PermissionGroup permissionGroup = permissionPool.getGroups().get(args[1]);
                        permissionGroup.getPermissions().remove(args[4]);
                        PermissionModule.getInstance().getConfigPermission().updatePermissionGroup(permissionGroup);
                        CloudNet.getInstance().getNetworkManager().reload();
                        CloudNet.getInstance().getNetworkManager().updateAll0();
                        sender.sendMessage("You removed the permission " + args[4] + " from the permission group \"" + permissionGroup.getName() + "\"");
                    } else {
                        sender.sendMessage("The specified permission group doesn't exist");
                    }
                }
            }
            if (args.length == 6) {
                if (args[2].equalsIgnoreCase("add") && args[3].equalsIgnoreCase("permission")) {
                    if (permissionPool.getGroups().containsKey(args[1])) {
                        PermissionGroup permissionGroup = permissionPool.getGroups().get(args[1]);
                        if (!permissionGroup.getServerGroupPermissions().containsKey(args[5])) {
                            permissionGroup.getServerGroupPermissions().put(args[5], new ArrayList<>());
                        }
                        permissionGroup.getServerGroupPermissions().get(args[5]).add(args[4].replaceFirst("-", ""));
                        PermissionModule.getInstance().getConfigPermission().updatePermissionGroup(permissionGroup);
                        CloudNet.getInstance().getNetworkManager().reload();
                        CloudNet.getInstance().getNetworkManager().updateAll0();
                        sender.sendMessage("You added the permission " + args[4] + " to the permission group \"" + permissionGroup.getName() + "\" on the server group " + args[5]);
                    } else {
                        sender.sendMessage("The specified permission group doesn't exist");
                    }
                }
                if (args[2].equalsIgnoreCase("remove") && args[3].equalsIgnoreCase("permission")) {
                    if (permissionPool.getGroups().containsKey(args[1])) {
                        PermissionGroup permissionGroup = permissionPool.getGroups().get(args[1]);
                        if (!permissionGroup.getServerGroupPermissions().containsKey(args[5])) {
                            permissionGroup.getServerGroupPermissions().put(args[5], new ArrayList<>());
                        }
                        permissionGroup.getServerGroupPermissions().get(args[5]).remove(args[4].replaceFirst("-", ""));
                        PermissionModule.getInstance().getConfigPermission().updatePermissionGroup(permissionGroup);
                        CloudNet.getInstance().getNetworkManager().reload();
                        CloudNet.getInstance().getNetworkManager().updateAll0();
                        sender.sendMessage("You removed the permission " + args[4] + " from the permission group \"" + permissionGroup.getName() + "\" on the server group " + args[5]);
                    } else {
                        sender.sendMessage("The specified permission group doesn't exist");
                    }
                }
            }
            return;
        }
        if (args[0].equalsIgnoreCase("user")) {
            if (args.length == 2) {
                UUID uniqueId = CloudNet.getInstance().getDbHandlers().getNameToUUIDDatabase().get(args[1]);
                if (uniqueId != null) {
                    OfflinePlayer offlinePlayer = CloudNet.getInstance().getDbHandlers().getPlayerDatabase().getPlayer(uniqueId);
                    if (offlinePlayer != null && offlinePlayer.getPermissionEntity() != null) {
                        StringBuilder stringBuilder = new StringBuilder();
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
                        for (GroupEntityData groupEntityData : offlinePlayer.getPermissionEntity().getGroups()) {
                            stringBuilder.append(groupEntityData.getGroup() + "@" + (groupEntityData.getTimeout() == 0 || groupEntityData.getTimeout() == -1 ? "LIFETIME" : simpleDateFormat.format(groupEntityData.getTimeout())) + NetworkUtils.SPACE_STRING);
                        }
                        sender.sendMessage(NetworkUtils.SPACE_STRING, "Player " + offlinePlayer.getName() + ": " + offlinePlayer.getUniqueId(), "Groups: " + stringBuilder.substring(0), NetworkUtils.SPACE_STRING);
                        for (Map.Entry<String, Boolean> booleanEntry : offlinePlayer.getPermissionEntity().getPermissions().entrySet()) {
                            sender.sendMessage("- " + booleanEntry.getKey() + " [" + booleanEntry.getValue() + "]");
                        }
                        sender.sendMessage(NetworkUtils.SPACE_STRING);
                    } else {
                        sender.sendMessage("The player isn't registered in permissions database");
                    }
                } else {
                    sender.sendMessage("The player isn't registered in permissions database");
                }
                return;
            }
            if (args.length == 5) {
                // perms user Dytanic group remove Admin
                UUID uniqueId = CloudNet.getInstance().getDbHandlers().getNameToUUIDDatabase().get(args[1]);
                if (uniqueId != null) {
                    OfflinePlayer offlinePlayer = CloudNet.getInstance().getDbHandlers().getPlayerDatabase().getPlayer(uniqueId);
                    if (offlinePlayer != null && offlinePlayer.getPermissionEntity() != null) {
                        if (args[2].equalsIgnoreCase("GROUP")) {
                            if (args[3].equalsIgnoreCase("REMOVE")) {
                                if (PermissionModule.getInstance().getPermissionPool().getGroups().containsKey(args[4])) {
                                    GroupEntityData groupEntityData = null;
                                    for (GroupEntityData groupEntity : offlinePlayer.getPermissionEntity().getGroups()) {
                                        if (groupEntity.getGroup().equalsIgnoreCase(args[4])) {
                                            groupEntityData = groupEntity;
                                        }
                                    }
                                    if (groupEntityData != null) {
                                        offlinePlayer.getPermissionEntity().getGroups().remove(groupEntityData);
                                    }
                                    if (offlinePlayer.getPermissionEntity().getGroups().size() == 0) {
                                        offlinePlayer.getPermissionEntity().getGroups().add(new GroupEntityData(permissionPool.getDefaultGroup().getName(), 0));
                                    }
                                    updatePlayer(offlinePlayer);
                                    sender.sendMessage("The player " + offlinePlayer.getName() + " is no longer a member of the group " + args[4]);
                                }
                            }
                        }
                        if (args[2].equalsIgnoreCase("ADD")) {
                            if (args[3].equalsIgnoreCase("PERMISSION")) {
                                offlinePlayer.getPermissionEntity().getPermissions().put(args[4].replaceFirst("-", ""), !args[4].startsWith("-"));
                                updatePlayer(offlinePlayer);
                                sender.sendMessage("The player \"" + offlinePlayer.getName() + "\" now has the permission " + args[4]);
                            }
                        }
                        if (args[2].equalsIgnoreCase("REMOVE")) {
                            if (args[3].equalsIgnoreCase("PERMISSION")) {
                                offlinePlayer.getPermissionEntity().getPermissions().remove(args[4]);
                                updatePlayer(offlinePlayer);
                                sender.sendMessage("The players \"" + offlinePlayer.getName() + "\" no longer has the permission " + args[4]);
                            }
                        }
                    } else {
                        sender.sendMessage("The player isn't registered in permissions database");
                    }
                } else {
                    sender.sendMessage("The player isn't registered in permissions database");
                }
                return;
            }
            if (args.length == 6) {
                UUID uniqueId = CloudNet.getInstance().getDbHandlers().getNameToUUIDDatabase().get(args[1]);
                if (uniqueId != null) {
                    OfflinePlayer offlinePlayer = CloudNet.getInstance().getDbHandlers().getPlayerDatabase().getPlayer(uniqueId);
                    if (offlinePlayer != null && offlinePlayer.getPermissionEntity() != null) {
                        if (args[2].equalsIgnoreCase("GROUP")) {
                            if (args[3].equalsIgnoreCase("SET")) {
                                if (permissionPool.getGroups().containsKey(args[4])) {
                                    offlinePlayer.getPermissionEntity().getGroups().clear();
                                    offlinePlayer.getPermissionEntity().getGroups().add(new GroupEntityData(args[4], (args[5].equalsIgnoreCase("lifetime") ? 0L : NetworkUtils.checkIsNumber(args[5]) ? calcDays(Integer.parseInt(args[5])) : 0L)));
                                    updatePlayer(offlinePlayer);
                                    sender.sendMessage("The central group of " + offlinePlayer.getName() + " is now " + args[4]);
                                } else {
                                    sender.sendMessage("The specified permission group doesn't exist");
                                }
                                return;
                            }
                            if (args[3].equalsIgnoreCase("ADD")) {
                                if (permissionPool.getGroups().containsKey(args[4])) {
                                    offlinePlayer.getPermissionEntity().getGroups().add(new GroupEntityData(args[4], (args[5].equalsIgnoreCase("lifetime") ? 0L : NetworkUtils.checkIsNumber(args[4]) ? calcDays(Integer.parseInt(args[4])) : 0L)));
                                    updatePlayer(offlinePlayer);
                                    sender.sendMessage("The player " + offlinePlayer.getName() + " is now also a member of the group " + args[4]);
                                } else {
                                    sender.sendMessage("The specified permission group doesn't exist");
                                }
                                return;
                            }
                        }
                    } else {
                        sender.sendMessage("The player isn't registered in permissions database");
                    }
                } else {
                    sender.sendMessage("The player isn't registered in permissions database");
                }
                return;
            }
            return;
        }
        if (args[0].equalsIgnoreCase("create")) {
            if (args.length == 2) {
                if (!permissionPool.getGroups().containsKey(args[1])) {
                    PermissionGroup permissionGroup = new DefaultPermissionGroup(args[1]);
                    PermissionModule.getInstance().getConfigPermission().updatePermissionGroup(permissionGroup);
                    CloudNet.getInstance().getNetworkManager().reload();
                    CloudNet.getInstance().getNetworkManager().updateAll0();
                    sender.sendMessage("The group " + args[1] + " was created!");
                } else {
                    sender.sendMessage("The permission group already exists");
                }
            }
        }
    } else {
        sender.sendMessage("CloudNet-Permissions: [\"_\" = \" \"]", NetworkUtils.SPACE_STRING, "perms CREATE <groupName>", "perms GROUP", "perms GROUP <name>", "perms GROUP <name> add permission <permission>", "perms GROUP <name> remove permission <permission>", "perms GROUP <name> add permission <permission> <group>", "perms GROUP <name> remove permission <permission> <group>", "perms GROUP <name> setDisplay <display>", "perms GROUP <name> setJoinPower <joinPower>", "perms GROUP <name> setSuffix <joinPower>", "perms GROUP <name> setPrefix <prefix>", "perms GROUP <name> setTagId <tagId>", "perms GROUP <name> setDefault <true : false>", "perms GROUP <name> setJoinPower <joinPower>", "perms USER <user>", "perms USER <user> GROUP SET <name> <lifetime | time in days>", "perms USER <user> GROUP ADD <name> <lifetime | time in days>", "perms USER <user> GROUP REMOVE <name>", "perms USER <user> ADD PERMISSION <permission>", "perms USER <user> REMOVE PERMISSION <permission>");
    }
}
Also used : PermissionPool(de.dytanic.cloudnet.lib.player.permission.PermissionPool) DefaultPermissionGroup(de.dytanic.cloudnet.lib.player.permission.DefaultPermissionGroup) PermissionGroup(de.dytanic.cloudnet.lib.player.permission.PermissionGroup) OfflinePlayer(de.dytanic.cloudnet.lib.player.OfflinePlayer) PacketOutUpdateOfflinePlayer(de.dytanic.cloudnetcore.network.packet.out.PacketOutUpdateOfflinePlayer) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) Map(java.util.Map) SimpleDateFormat(java.text.SimpleDateFormat) GroupEntityData(de.dytanic.cloudnet.lib.player.permission.GroupEntityData) DefaultPermissionGroup(de.dytanic.cloudnet.lib.player.permission.DefaultPermissionGroup)

Example 5 with GroupEntityData

use of de.dytanic.cloudnet.lib.player.permission.GroupEntityData in project CloudNet by Dytanic.

the class PlayerExample method examplePlayer.

public void examplePlayer() {
    // Returns the CloudPlayer if the play is online or null if isn't online
    CloudPlayer cloudPlayer = CloudAPI.getInstance().getOnlinePlayer(UUID.fromString("e71d69dd-058f-4319-9ae9-8c8f0a7a61f5"));
    {
        // Returns the online player connection metadata
        PlayerConnection playerConnection = cloudPlayer.getPlayerConnection();
        // Returns the IP
        playerConnection.getHost();
        // Returns the port of the last connection
        playerConnection.getPort();
        // Returns the UUID of the connection
        playerConnection.getUniqueId();
        // Returns the legacy version
        playerConnection.getVersion();
        // Returns if the player was in onlinemode
        playerConnection.isOnlineMode();
    }
    System.out.println("The player " + cloudPlayer.getName() + " is on " + cloudPlayer.getProxy() + NetworkUtils.SLASH_STRING + cloudPlayer.getServer() + " and connected at " + cloudPlayer.getLoginTimeStamp().getTime());
    // Returns a util Class for some network methods
    PlayerExecutor playerExecutor = cloudPlayer.getPlayerExecutor();
    // writes a message to the player if the player is online
    playerExecutor.sendMessage(cloudPlayer, "Hello world!");
    // send a player to a some server
    playerExecutor.sendPlayer(cloudPlayer, "Lobby-2");
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // Kick a player from the network
            playerExecutor.kickPlayer(cloudPlayer, "you are a cool guy for the network");
        }
    }).start();
    OfflinePlayer offlinePlayer = CloudAPI.getInstance().getOfflinePlayer("Dytanic");
    if (// If the player is registered
    offlinePlayer != null) {
        // Returns the permissionentity for manage some permission systems
        PermissionEntity permissionEntity = offlinePlayer.getPermissionEntity();
        // add a permission group with the delay of 30 days
        permissionEntity.getGroups().add(new GroupEntityData("VIP", System.currentTimeMillis() + TimeUnit.DAYS.toMillis(30)));
        // add a permission for this player
        permissionEntity.getPermissions().put("minecraft.command.tp", true);
        if (permissionEntity.isInGroup("VIP")) {
            System.out.println("The player " + offlinePlayer.getUniqueId() + NetworkUtils.SLASH_STRING + offlinePlayer.getName() + " is in the group VIP");
        }
        PlayerConnection playerConnection = offlinePlayer.getLastPlayerConnection();
        // Returns the IP
        playerConnection.getHost();
        // Returns the port of the last connection
        playerConnection.getPort();
        // Returns the UUID of the connection
        playerConnection.getUniqueId();
        // Returns the legacy version
        playerConnection.getVersion();
        // Returns if the player was in onlinemode
        playerConnection.isOnlineMode();
    }
    // update the player
    // cloudplayer update
    CloudAPI.getInstance().updatePlayer(cloudPlayer);
    // update the offline player
    CloudAPI.getInstance().updatePlayer(offlinePlayer);
}
Also used : PlayerExecutor(de.dytanic.cloudnet.lib.player.PlayerExecutor) CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) OfflinePlayer(de.dytanic.cloudnet.lib.player.OfflinePlayer) PermissionEntity(de.dytanic.cloudnet.lib.player.permission.PermissionEntity) PlayerConnection(de.dytanic.cloudnet.lib.player.PlayerConnection) GroupEntityData(de.dytanic.cloudnet.lib.player.permission.GroupEntityData)

Aggregations

GroupEntityData (de.dytanic.cloudnet.lib.player.permission.GroupEntityData)6 OfflinePlayer (de.dytanic.cloudnet.lib.player.OfflinePlayer)4 PermissionEntity (de.dytanic.cloudnet.lib.player.permission.PermissionEntity)4 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)2 CloudPermissble (de.dytanic.cloudnet.bridge.internal.util.CloudPermissble)1 PlayerConnection (de.dytanic.cloudnet.lib.player.PlayerConnection)1 PlayerExecutor (de.dytanic.cloudnet.lib.player.PlayerExecutor)1 DefaultPermissionGroup (de.dytanic.cloudnet.lib.player.permission.DefaultPermissionGroup)1 PermissionGroup (de.dytanic.cloudnet.lib.player.permission.PermissionGroup)1 PermissionPool (de.dytanic.cloudnet.lib.player.permission.PermissionPool)1 PacketOutUpdateOfflinePlayer (de.dytanic.cloudnetcore.network.packet.out.PacketOutUpdateOfflinePlayer)1 Field (java.lang.reflect.Field)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 EventHandler (org.bukkit.event.EventHandler)1