Skip to content
This repository has been archived by the owner on Jan 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #40 from reformcloudproject/progress
Browse files Browse the repository at this point in the history
Version 1.7
  • Loading branch information
derklaro committed May 10, 2019
2 parents 80763d5 + c9644db commit 69b5ff9
Show file tree
Hide file tree
Showing 65 changed files with 1,450 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ReformCloud 1.6
# ReformCloud 1.7

Official Cloud System

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>systems.reformcloud</groupId>
<artifactId>reformcloud-parent</artifactId>
<version>1.6</version>
<version>1.7</version>

<modules>
<module>reformcloud-library</module>
Expand Down Expand Up @@ -39,7 +39,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.targetEncoding>UTF-8</project.build.targetEncoding>

<service.version>1.6</service.version>
<service.version>1.7</service.version>
<service.type>BETA</service.type>

<plugin.shade.version>3.2.1</plugin.shade.version>
Expand Down
2 changes: 1 addition & 1 deletion reformcloud-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>reformcloud-parent</artifactId>
<groupId>systems.reformcloud</groupId>
<version>1.6</version>
<version>1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion reformcloud-common/reformcloud-yaml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>reformcloud-common</artifactId>
<groupId>systems.reformcloud</groupId>
<version>1.6</version>
<version>1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 2 additions & 2 deletions reformcloud-global/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>reformcloud-parent</artifactId>
<groupId>systems.reformcloud</groupId>
<version>1.6</version>
<version>1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -22,7 +22,7 @@
<dependency>
<groupId>systems.reformcloud</groupId>
<artifactId>reformcloud-library</artifactId>
<version>1.6</version>
<version>1.7</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion reformcloud-global/reformcloud-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>reformcloud-global</artifactId>
<groupId>systems.reformcloud</groupId>
<version>1.6</version>
<version>1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>reformcloud-api</artifactId>
<groupId>systems.reformcloud</groupId>
<version>1.6</version>
<version>1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,28 @@ public void createWebUser(WebUser webUser) {
channelHandler.sendPacketSynchronized("ReformCloudController", new PacketOutCreateWebUser(webUser));
}

@Override
public void dispatchConsoleCommand(String commandLine) {
this.channelHandler.sendPacketSynchronized("ReformCloudController", new PacketOutDispatchConsoleCommand(commandLine));
}

@Override
public void dispatchConsoleCommand(CharSequence commandLine) {
this.dispatchConsoleCommand(String.valueOf(commandLine));
}

@Override
public String dispatchConsoleCommandAndGetResult(String commandLine) {
return this.createPacketFuture(
new PacketOutExecuteCommandSilent(commandLine), "ReformCloudController"
).sendOnCurrentThread().syncUninterruptedly().getConfiguration().getStringValue("result");
}

@Override
public String dispatchConsoleCommandAndGetResult(CharSequence commandLine) {
return this.dispatchConsoleCommandAndGetResult(String.valueOf(commandLine));
}

@Override
public DevProcess startQueuedProcess(ServerGroup serverGroup) {
return this.createPacketFuture(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,12 @@
import systems.reformcloud.meta.proxy.ProxyGroup;
import systems.reformcloud.meta.proxy.settings.ProxySettings;
import systems.reformcloud.network.packets.PacketOutCommandExecute;
import systems.reformcloud.network.packets.PacketOutUpdatePermissionHolder;
import systems.reformcloud.player.permissions.group.PermissionGroup;
import systems.reformcloud.player.permissions.player.PermissionHolder;
import systems.reformcloud.permissions.PermissionUtil;
import systems.reformcloud.player.version.SpigotVersion;
import systems.reformcloud.utility.StringUtil;
import systems.reformcloud.utility.map.maps.Double;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

/**
* @author _Klaro | Pasqual K. / created on 07.11.2018
Expand Down Expand Up @@ -63,45 +57,7 @@ public void handle(final PermissionCheckEvent event) {
if (ReformCloudAPIBungee.getInstance().getPermissionCache() == null)
return;

if (event.getSender() instanceof ProxiedPlayer) {
PermissionHolder permissionHolder = ReformCloudAPIBungee.getInstance()
.getCachedPermissionHolders().get(((ProxiedPlayer) event.getSender()).getUniqueId());
if (permissionHolder == null) {
event.setHasPermission(false);
return;
}

Map<String, Long> copyOf = new HashMap<>(permissionHolder.getPermissionGroups());

copyOf.forEach((groupName, timeout) -> {
if (timeout != -1 && timeout <= System.currentTimeMillis())
permissionHolder.getPermissionGroups().remove(groupName);
});

if (copyOf.size() != permissionHolder.getPermissionGroups().size()) {
if (permissionHolder.getPermissionGroups().size() == 0) {
permissionHolder.getPermissionGroups().put(
ReformCloudAPIBungee.getInstance().getPermissionCache().getDefaultGroup().getName(), -1L
);
}

ReformCloudAPIBungee.getInstance().getChannelHandler().sendPacketSynchronized(
"ReformCloudController", new PacketOutUpdatePermissionHolder(permissionHolder)
);
}

List<PermissionGroup> permissionGroups = ReformCloudAPIBungee.getInstance()
.getPermissionCache().getAllRegisteredGroups().stream().filter(e -> permissionHolder
.getPermissionGroups().containsKey(e.getName()))
.collect(Collectors.toList());
if (permissionHolder.getPermissionGroups().containsKey(ReformCloudAPIBungee.getInstance()
.getPermissionCache().getDefaultGroup().getName())) {
permissionGroups.add(ReformCloudAPIBungee.getInstance().getPermissionCache().getDefaultGroup());
}

event.setHasPermission(permissionHolder.hasPermission(event.getPermission(), permissionGroups));
} else
event.setHasPermission(true);
event.setHasPermission(PermissionUtil.hasPermission(event.getSender(), event.getPermission()));
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright © 2019 Pasqual K. | All rights reserved
*/

package systems.reformcloud.permissions;

import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.command.ConsoleCommandSender;
import systems.reformcloud.ReformCloudAPIBungee;
import systems.reformcloud.player.permissions.group.PermissionGroup;
import systems.reformcloud.player.permissions.player.PermissionHolder;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

/**
* @author _Klaro | Pasqual K. / created on 06.05.2019
*/

public final class PermissionUtil implements Serializable {
public static boolean hasPermission(CommandSender commandSender, String permission) {
if (permission == null)
return false;

if (commandSender instanceof ProxiedPlayer)
return hasPermission0((ProxiedPlayer) commandSender, permission);

return commandSender instanceof ConsoleCommandSender;
}

private static boolean hasPermission0(ProxiedPlayer proxiedPlayer, String permission) {
if (proxiedPlayer == null)
return false;

return hasPermission1(proxiedPlayer.getUniqueId(), permission);
}

private static boolean hasPermission1(UUID uniqueID, String permission) {
if (uniqueID == null)
return false;

PermissionHolder permissionHolder = ReformCloudAPIBungee.getInstance().getCachedPermissionHolders().get(uniqueID);
return hasPermission2(permissionHolder, permission);
}

private static boolean hasPermission2(PermissionHolder permissionHolder, String permission) {
if (permissionHolder == null)
return false;

List<PermissionGroup> permissionGroups = new ArrayList<>();
permissionHolder.getPermissionGroups().keySet()
.stream()
.filter(permissionHolder::isPermissionGroupPresent)
.map(g -> ReformCloudAPIBungee.getInstance().getPermissionCache().getGroup(g))
.filter(Objects::nonNull)
.forEach(permissionGroups::add);
return hasPermission3(permissionHolder, permissionGroups, permission);
}

private static boolean hasPermission3(PermissionHolder permissionHolder, List<PermissionGroup> permissionGroups, String permission) {
if (permissionGroups == null || permissionGroups.isEmpty())
return false;

return permissionHolder.hasPermission(permission, permissionGroups);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>reformcloud-api</artifactId>
<groupId>systems.reformcloud</groupId>
<version>1.6</version>
<version>1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,28 @@ public void createWebUser(WebUser webUser) {
channelHandler.sendPacketSynchronized("ReformCloudController", new PacketOutCreateWebUser(webUser));
}

@Override
public void dispatchConsoleCommand(String commandLine) {
this.channelHandler.sendPacketSynchronized("ReformCloudController", new PacketOutDispatchConsoleCommand(commandLine));
}

@Override
public void dispatchConsoleCommand(CharSequence commandLine) {
this.dispatchConsoleCommand(String.valueOf(commandLine));
}

@Override
public String dispatchConsoleCommandAndGetResult(String commandLine) {
return this.createPacketFuture(
new PacketOutExecuteCommandSilent(commandLine), "ReformCloudController"
).sendOnCurrentThread().syncUninterruptedly().getConfiguration().getStringValue("result");
}

@Override
public String dispatchConsoleCommandAndGetResult(CharSequence commandLine) {
return this.dispatchConsoleCommandAndGetResult(String.valueOf(commandLine));
}

@Override
public DevProcess startQueuedProcess(ServerGroup serverGroup) {
return this.createPacketFuture(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright © 2018 Pasqual K. | All rights reserved
*/

package systems.reformcloud.network.packets;

import systems.reformcloud.configurations.Configuration;
import systems.reformcloud.network.packet.Packet;

/**
* @author _Klaro | Pasqual K. / created on 16.12.2018
*/

public final class PacketOutDispatchConsoleCommand extends Packet {
public PacketOutDispatchConsoleCommand(final String command) {
super("DispatchCommandLine", new Configuration().addValue("command", command));
}
}
Loading

0 comments on commit 69b5ff9

Please sign in to comment.