Add missing permissions to plugin.yml

This commit is contained in:
GeorgH93 2020-02-26 17:12:07 +01:00
parent 394ffc809d
commit 906fd41029
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
6 changed files with 117 additions and 9 deletions

2
.gitignore vendored
View File

@ -49,6 +49,8 @@ Temporary Items
*.tmp
*.sh
# =========================
# IDE Project Files
# =========================

View File

@ -20,7 +20,8 @@
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
<timestamp>${maven.build.timestamp}</timestamp>
<version>${project.version}-T${timestamp}</version>
<dependencies>depend: [ PCGF_PluginLib ]</dependencies>
<dependencies>PCGF_PluginLib</dependencies>
<soft-dependencies/>
<mainClass>${project.groupId}.${project.artifactId}.Bukkit.${project.artifactId}</mainClass>
</properties>
@ -43,10 +44,17 @@
<artifactId>BadRabbit-Bukkit</artifactId>
<version>1.4</version>
</dependency>
<!-- Tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>clean package</defaultGoal>
<defaultGoal>clean package test</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test/src</testSourceDirectory>
<resources>
@ -65,6 +73,10 @@
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
<!-- Bundle the API into the JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -218,7 +230,8 @@
</activation>
<properties>
<version>${project.version}-Release</version>
<dependencies>softdepend: [ PCGF_PluginLib ]</dependencies>
<dependencies/>
<soft-dependencies>PCGF_PluginLib</soft-dependencies>
<mainClass>${project.groupId}.${project.artifactId}.Bukkit.${project.artifactId}BadRabbit</mainClass>
</properties>
<dependencies>

View File

@ -5,7 +5,8 @@ main: "${mainClass}"
description: "${project.description}"
version: "${version}"
api-version: "1.13"
${dependencies}
depend: [${dependencies}]
softdepend: [${soft-dependencies}]
permissions:
backpack.*:
@ -32,12 +33,14 @@ permissions:
backpack.use: true
backpack.size.1: true
backpack.clean: true
backpack.sort: true
backpack.userBig:
description: This permission can be used to give a user the biggest backpack size and allow him to use the backpack.
children:
backpack.use: true
backpack.size.6: true
backpack.clean: true
backpack.sort: true
backpack.bypass:
children:
backpack.ignoreGameMode: true
@ -72,11 +75,14 @@ permissions:
backpack.size.6:
description: 6*9 backpack
default: false
backpack.sort:
description: Allows the player to sort their own backpack.
default: false
backpack.clean:
description: Allows the player to clean their own backpack.
default: false
backpack.fullpickup:
desctiption: Allows the player to automatically pick up items when their inventory is full (function needs to be enabled in the config)
description: Allows the player to automatically pick up items when their inventory is full (function needs to be enabled in the config)
defaut: true
backpack.clean.other:
description: Allows the player to clean other players backpacks.
@ -120,4 +126,12 @@ permissions:
default: op
backpack.version:
description: Allows to print the version details of the plugin and it's dependencies.
default: op
default: op
clearInventory:
description: Allows the player to clear their own inventory.
default: op
clearInventory.other:
description: Allows the player to clear the inventory of other players.
default: op
children:
clearInventory: true

View File

@ -1,2 +0,0 @@
The munge-maven-plugin requires a test source folder.
There currently are no tests so this file is here instead.

View File

@ -0,0 +1,81 @@
/*
* Copyright (C) 2020 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package at.pcgamingfreaks.Minepacks.Bukkit;
import at.pcgamingfreaks.yaml.YAML;
import at.pcgamingfreaks.yaml.YamlInvalidContentException;
import at.pcgamingfreaks.yaml.YamlKeyNotFoundException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashSet;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class PermissionsTest
{
private static Collection<String> permissions;
@BeforeAll
public static void setup() throws IllegalAccessException
{ // Collect all permissions defined in the Permissions class
permissions = new HashSet<>();
for(Field declaredField : Permissions.class.getDeclaredFields())
{
if(declaredField.getName().equals("BASE") || declaredField.getName().equals("SIZE_BASE")) continue;
permissions.add((String) declaredField.get(null));
}
}
private int countKeysStartingWith(Collection<String> keys, String startsWith)
{
int count = 0;
for(String key : keys)
{
if(key.startsWith(startsWith)) count++;
}
return count;
}
@Test
public void testPermissionsInPluginYaml() throws IOException, YamlInvalidContentException, YamlKeyNotFoundException
{
YAML pluginYaml = new YAML(new File("resources/plugin.yml"));
YAML permissionsYaml = pluginYaml.getSection("permissions");
// Check if all permissions are defined in the plugin.yml
for(String permission : permissions)
{
assertTrue(permissionsYaml.isSet(permission + ".description"), "The plugin.yml should contain the permission " + permission);
}
// Check if all the permissions defined in the plugin.yml are also defined in the Permissions class
Collection<String> keys = permissionsYaml.getKeys(true);
for(String key : keys)
{
if(!key.endsWith("description")) continue;
String perm = key.substring(0, key.length() - 12);
if(perm.contains(".size.")) continue; // Ignore size permissions
if(countKeysStartingWith(keys, perm + ".children") > 1) continue; // Skip all the permissions that are just for permission grouping
assertTrue(permissions.contains(perm), "The plugin.yml should not contain the permission " + perm);
}
}
}

View File

@ -7,7 +7,7 @@
<packaging>pom</packaging>
<properties>
<revision>2.3</revision>
<revision>2.3.1</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>