use of de.dytanic.cloudnet.lib.player.OfflinePlayer 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;
}
use of de.dytanic.cloudnet.lib.player.OfflinePlayer in project CloudNet by Dytanic.
the class VaultPermissionImpl method playerRemove.
@Override
public boolean playerRemove(String s, String s1, String s2) {
OfflinePlayer offlinePlayer = getPlayer(s1);
PermissionEntity permissionEntity = offlinePlayer.getPermissionEntity();
permissionEntity.getPermissions().remove(s2);
offlinePlayer.setPermissionEntity(permissionEntity);
updatePlayer(offlinePlayer);
return true;
}
use of de.dytanic.cloudnet.lib.player.OfflinePlayer 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>");
}
}
use of de.dytanic.cloudnet.lib.player.OfflinePlayer 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);
}
use of de.dytanic.cloudnet.lib.player.OfflinePlayer in project CloudNet by Dytanic.
the class VaultChatImpl method setPlayerPrefix.
@Override
public void setPlayerPrefix(String s, String s1, String s2) {
OfflinePlayer offlinePlayer = getPlayer(s1);
offlinePlayer.getPermissionEntity().setPrefix(s2);
update(offlinePlayer);
}
Aggregations