Browse Source

End of day commit. This is big work.

NOW USING TEMPORARY repo for VaultAPI (https://github.com/MilkBowl/VaultAPI/issues/24).
master
Stanislav Usenkov 9 years ago
parent
commit
8312a81608
  1. 31
      pom.xml
  2. 6
      src/main/java/ru/simsonic/rscPermissions/Bukkit/BukkitPermissionManager.java
  3. 38
      src/main/java/ru/simsonic/rscPermissions/Bukkit/Commands/BukkitCommands.java
  4. 117
      src/main/java/ru/simsonic/rscPermissions/Bukkit/Commands/CommandEntity.java
  5. 2
      src/main/java/ru/simsonic/rscPermissions/Engine/IntermediateResult.java
  6. 22
      src/main/java/ru/simsonic/rscPermissions/Engine/InternalCache.java
  7. 5
      src/main/java/ru/simsonic/rscPermissions/Engine/ResolutionResult.java

31
pom.xml

@ -12,13 +12,13 @@
<repositories>
<!-- Sponge API -->
<!--repository>
<repository>
<id>sponge-repo</id>
<url>http://repo.spongepowered.org/maven/</url>
</repository-->
</repository>
<!-- Bukkit API / Spigot API -->
<repository>
<id>spigot-repo</id>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<!-- Metrics (mcstats.org) -->
@ -27,9 +27,13 @@
<url>http://repo.mcstats.org/content/repositories/public/</url>
</repository>
<!-- VaultAPI -->
<repository>
<!--repository>
<id>vault-repo</id>
<url>http://nexus.theyeticave.net/content/repositories/pub_releases/</url>
</repository-->
<repository>
<id>scarsz-repo</id>
<url>https://dl.bintray.com/scarsz/maven</url>
</repository>
<!-- Region list providers: WorldGuard, Residence -->
<repository>
@ -48,6 +52,13 @@
</repositories>
<dependencies>
<!-- Sponge API (for the future) -->
<!--dependency>
<groupId>org.spongepowered</groupId>
<artifactId>spongeapi</artifactId>
<version>6.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency-->
<!-- MySQL JDBC -->
<dependency>
<groupId>mysql</groupId>
@ -69,13 +80,6 @@
<version>1.10.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- Sponge API (for the future) -->
<dependency>
<groupId>org.spongepowered</groupId>
<artifactId>spongeapi</artifactId>
<version>6.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- Reality_SC's libraries -->
<dependency>
<groupId>ru.simsonic</groupId>
@ -98,9 +102,10 @@
</dependency>
<!-- Integrations -->
<dependency>
<groupId>net.milkbowl.vault</groupId>
<!--groupId>net.milkbowl.vault</groupId-->
<groupId>com.scarsz</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.6</version>
<version>1.5</version>
<scope>compile</scope>
</dependency>
<dependency>

6
src/main/java/ru/simsonic/rscPermissions/Bukkit/BukkitPermissionManager.java

@ -48,21 +48,21 @@ public class BukkitPermissionManager extends RestartableThread
}
public ResolutionResult getResult(String playerIdentifier)
{
return (resolutions.containsKey(playerIdentifier))
return resolutions.containsKey(playerIdentifier)
? resolutions.get(playerIdentifier)
: resolvePlayerIdentifier(playerIdentifier);
}
public ResolutionResult getResult(OfflinePlayer offline)
{
final String key = offline.toString();
return (resolutions.containsKey(key))
return resolutions.containsKey(key)
? resolutions.get(key)
: resolveOfflinePlayer(offline);
}
public ResolutionResult getResult(Player player)
{
final String key = player.toString();
return (resolutions.containsKey(key))
return resolutions.containsKey(key)
? resolutions.get(key)
: resolvePlayer(player);
}

38
src/main/java/ru/simsonic/rscPermissions/Bukkit/Commands/BukkitCommands.java

@ -111,8 +111,8 @@ public class BukkitCommands
}
if(sender.hasPermission("rscp.admin"))
{
help.add("{_YL}/rscp examplerows {_LS}-- insert some fake rows into database");
help.add("{_YL}/rscp import pex-sql {_LS}-- import data from pex's database (in the same schema)");
help.add("{_YL}/rscp {_LR}examplerows {_LS}-- insert some fake rows into database");
help.add("{_YL}/rscp {_LR}import pex-sql {_LS}-- import data from pex's database (in the same schema)");
help.add(Phrases.HELP_CMD_DEBUG.toString());
help.add(Phrases.HELP_CMD_FETCH.toString());
help.add(Phrases.HELP_CMD_RELOAD.toString());
@ -120,12 +120,22 @@ public class BukkitCommands
help.add(Phrases.HELP_CMD_HELP.toString());
switch(args[0].toLowerCase())
{
case "user":
case "player":
cmdEntity.onEntityCommandHub(sender, true, args);
case "listgroups":
case "groups":
case "lg":
cmdEntity.listGroups(sender);
return;
case "group":
cmdEntity.onEntityCommandHub(sender, false, args);
case "g":
cmdEntity.onEntityCommandHub(sender, CommandEntity.TargetType.GROUP, args);
return;
case "user":
case "u":
cmdEntity.onEntityCommandHub(sender, CommandEntity.TargetType.USER, args);
return;
case "player":
case "p":
cmdEntity.onEntityCommandHub(sender, CommandEntity.TargetType.PLAYER, args);
return;
case "lock":
cmdLock.executeLock(sender, args);
@ -160,19 +170,21 @@ public class BukkitCommands
/* DEPRECATED: rscp import pex-sql*/
if(sender.hasPermission("rscp.admin"))
{
if(args.length > 1)
if(args.length <= 1)
throw new CommandAnswerException(new String[]
{
"Usage: {_YL}/rscp import <importer> [options]",
"Available importers:",
"{_LG}pex-sql {_LS}-- (PermissionsEx's SQL backend)",
});
switch(args[1].toLowerCase())
{
case "pex-sql":
threadMigrateFromPExSQL(sender);
throw new CommandAnswerException("Trying to import PEX database into rscPermissions...");
default:
break;
}
throw new CommandAnswerException(new String[]
{
"Usage: {_YL}/rscp import <importer> [options]",
"Available importers:",
"{_LG}pex-sql {_LS}-- (PermissionsEx SQL Backend)",
});
}
return;
case "help":

117
src/main/java/ru/simsonic/rscPermissions/Bukkit/Commands/CommandEntity.java

@ -1,16 +1,19 @@
package ru.simsonic.rscPermissions.Bukkit.Commands;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import ru.simsonic.rscMinecraftLibrary.Bukkit.CommandAnswerException;
import ru.simsonic.rscPermissions.API.EntityType;
import ru.simsonic.rscPermissions.API.RowEntity;
import ru.simsonic.rscPermissions.API.RowInheritance;
import ru.simsonic.rscPermissions.API.RowPermission;
import ru.simsonic.rscPermissions.Bukkit.BukkitUtilities;
import ru.simsonic.rscPermissions.BukkitPluginMain;
import ru.simsonic.rscPermissions.Engine.Backends.DatabaseEditor;
import ru.simsonic.rscPermissions.Engine.Matchers;
import ru.simsonic.rscPermissions.Engine.ResolutionResult;
@ -21,50 +24,82 @@ public class CommandEntity
{
this.rscp = plugin;
}
public void onEntityCommandHub(CommandSender sender, boolean type, String[] args) throws CommandAnswerException
public static enum TargetType
{
if(sender.hasPermission("rscp.admin"))
GROUP,
USER,
PLAYER,
}
public void onEntityCommandHub(CommandSender sender, TargetType type, String[] args) throws CommandAnswerException
{
if(sender.hasPermission("rscp.admin") == false)
throw new CommandAnswerException("Not enough permissions.");
args = Arrays.copyOfRange(args, 1, args.length);
if(args.length == 0)
if(args.length <= 1)
throw new CommandAnswerException("Read help.");
RowEntity entity = null;
Player player = null;
if(type)
ResolutionResult result = null;
switch(type)
{
player = BukkitUtilities.findOnlinePlayer(args[0]);
case PLAYER:
final Player player = BukkitUtilities.findOnlinePlayer(args[0]);
if(player != null)
args[1] = player.getName();
} else
{
args[0] = player.getName();
result = rscp.permissionManager.getResult(player);
break;
}
result = rscp.permissionManager.getResult(args[0]);
break;
case USER:
entity = rscp.internalCache.findUserEntity(args[0]);
break;
case GROUP:
entity = rscp.internalCache.findGroupEntity(args[0]);
final ResolutionResult result = (player != null)
? rscp.permissionManager.getResult(player)
: rscp.permissionManager.getResult(args[0]);
if(player == null && entity == null)
throw new CommandAnswerException("I don't know him.");
break;
}
if(entity == null && result == null)
throw new CommandAnswerException("{_LR}I don't know such name!");
if(args[1] == null)
args[1] = "";
switch(args[1].toLowerCase())
{
case "":
case "info":
case "i":
// INFO ?
throw new CommandAnswerException("Subcommand isn't implemented.");
case "prefix":
case "p":
if(player != null)
if(result != null)
viewCalculatedPrefix(result, args[1]);
else
viewEntityPrefix(entity);
break;
case "suffix":
case "s":
if(player != null)
if(result != null)
viewCalculatedSuffix(result, args[1]);
else
viewEntitySuffix(entity);
break;
case "listpermissions":
case "permissions":
case "lp":
listFinalPlayerPermissions(result, args[1]);
if(result != null)
listFinalPlayerPermissions(result, args[0]);
else
showEntityPermissions(entity);
break;
case "listparents":
case "listgroups":
case "parents":
case "groups":
case "lg":
if(result != null)
listUserGroupsTree(result, args[1]);
else
showEntityParents(entity);
break;
case "addparent":
case "addgroup":
@ -84,6 +119,19 @@ public class CommandEntity
break;
}
}
public void listGroups(CommandSender sender) throws CommandAnswerException
{
final ArrayList<String> answer = new ArrayList<>(16);
final Set<String> groups = rscp.internalCache.getKnownGroups();
answer.add("There are following known groups in database:");
for(String group : groups)
{
if("".equals(group))
group = "{_LS}<implicit group>";
answer.add("{_WH}" + group);
}
throw new CommandAnswerException(answer);
}
private void viewEntityPrefix(RowEntity entity) throws CommandAnswerException
{
final ArrayList<String> answer = new ArrayList<>();
@ -118,6 +166,41 @@ public class CommandEntity
answer.add("{_R}\"" + result.getSuffix() + "{_R}\"");
throw new CommandAnswerException(answer);
}
private void showEntityPermissions(RowEntity entity) throws CommandAnswerException
{
final ArrayList<String> answer = new ArrayList<>();
final String typeName = entity.entityType.name().toLowerCase();
answer.add("Explicit permissions for " + typeName + " {_YL}" + entity.entity + "{_LS}:");
for(RowPermission permission : entity.permissions)
{
final StringBuilder sb = new StringBuilder();
sb.append("{_WH}").append(permission.splittedId);
sb.append(permission.value ? " {_LG}" : " {_LR}").append(permission.permission);
if(permission.destination != null)
{
final String destination = permission.destination.toString();
if(!"".equals(destination))
sb.append("{_R} {_LC}{_U}").append(destination);
}
if(permission.expirience > 0)
sb.append("{_R} {_LB}").append(permission.expirience).append(" LVLs");
if(permission.lifetime != null)
{
final String lifetime = permission.lifetime.toLocalDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME).replace("T", " ");
sb.append("{_R} {_YL}").append(lifetime);
}
answer.add(sb.toString());
}
throw new CommandAnswerException(answer);
}
private void showEntityParents(RowEntity entity) throws CommandAnswerException
{
final ArrayList<String> answer = new ArrayList<>();
answer.add("Parent groups for " + entity.entityType.name().toLowerCase() + " {_YL}" + entity.entity + "{_LS}:");
for(RowInheritance parent : entity.inheritance)
answer.add("{_WH}" + parent.splittedId + " {_LG}" + parent.parent);
throw new CommandAnswerException(answer);
}
private void listFinalPlayerPermissions(ResolutionResult result, String user) throws CommandAnswerException
{
if(Matchers.isCorrectDashlessUUID(user))

2
src/main/java/ru/simsonic/rscPermissions/Engine/IntermediateResult.java

@ -2,10 +2,12 @@ package ru.simsonic.rscPermissions.Engine;
import java.util.List;
import java.util.Map;
import ru.simsonic.rscPermissions.API.RowEntity;
class IntermediateResult
{
ResolutionParams params;
List<RowEntity> entities;
String prefix = "";
String suffix = "";
List<String> groups;

22
src/main/java/ru/simsonic/rscPermissions/Engine/InternalCache.java

@ -33,6 +33,13 @@ public class InternalCache extends InternalStorage
result.add(row.entity);
return result;
}
public synchronized Set<String> getKnownUsers()
{
final Set<String> result = new TreeSet<>();
for(RowEntity row : entities_u.values())
result.add(row.entity);
return result;
}
public synchronized ResolutionResult resolvePlayer(String player)
{
return resolvePlayer(new String[] { player });
@ -46,15 +53,17 @@ public class InternalCache extends InternalStorage
}
public synchronized ResolutionResult resolvePlayer(ResolutionParams params)
{
final ArrayList<RowEntity> applicableEntities = new ArrayList<>();
final ArrayList<RowPermission> applicablePermissions = new ArrayList<>();
final ArrayList<RowInheritance> applicableInheritance = new ArrayList<>();
if(implicit_u != null && implicit_u.permissions != null)
processPermissions(params, Arrays.asList(implicit_u.permissions));
params.groupList = new LinkedList<>();
params.finalPerms = new TreeMap<>();
params.instantiator = "";
params.depth = 0;
if(implicit_u != null && implicit_u.permissions != null)
{
processPermissions(params, Arrays.asList(implicit_u.permissions));
}
final ArrayList<RowEntity> applicableEntities = new ArrayList<>();
final ArrayList<RowPermission> applicablePermissions = new ArrayList<>();
final ArrayList<RowInheritance> applicableInheritance = new ArrayList<>();
for(RowEntity row : entities_u.values())
for(String identifier : params.applicableIdentifiers)
if(row.playerType.isEntityApplicable(row.entity, identifier))
@ -89,6 +98,9 @@ public class InternalCache extends InternalStorage
params.parentEntity = row;
result = processPrefixesAndSuffixes(params, Arrays.asList(new ResolutionResult[] { result }));
}
if(implicit_u != null)
applicableEntities.add(0, implicit_u);
result.entities = applicableEntities;
result.prefix = GenericChatCodes.processStringStatic(result.prefix);
result.suffix = GenericChatCodes.processStringStatic(result.suffix);
processPermissions(params, applicablePermissions);

5
src/main/java/ru/simsonic/rscPermissions/Engine/ResolutionResult.java

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import ru.simsonic.rscMinecraftLibrary.Bukkit.GenericChatCodes;
import ru.simsonic.rscPermissions.API.RowEntity;
import ru.simsonic.rscPermissions.API.Settings;
public class ResolutionResult extends IntermediateResult
@ -56,4 +57,8 @@ public class ResolutionResult extends IntermediateResult
}
return list.toArray(new String[list.size()]);
}
public RowEntity[] getApplicableRows()
{
return null;
}
}

Loading…
Cancel
Save