Skip to content

Commit

Permalink
Initial Commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ElgarL committed Aug 15, 2020
1 parent 769986b commit 9f67eca
Show file tree
Hide file tree
Showing 24 changed files with 3,739 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PermTrigger</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
675 changes: 675 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.palmergames.spigot.permtrigger</groupId>
<artifactId>PermTrigger</artifactId>
<version>1.0.0</version>
<description>Trigger commands based upon permission states</description>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.bukkitAPIVersion>1.14</project.bukkitAPIVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jar.finalName>${project.name}</jar.finalName>
</properties>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
<repository>
<id>apache</id>
<url>https://maven.apache.org/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
<!--Bukkit/Spigot API -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--GroupManager API -->
<dependency>
<groupId>com.github.ElgarL</groupId>
<artifactId>groupmanager</artifactId>
<version>2.5</version>
</dependency>
<!--LuckPerms API -->
<dependency>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.1</version>
<scope>provided</scope>
</dependency>
<!-- bStats -->
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.7</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<defaultGoal>clean package</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<resources>
<!-- Include all resources -->
<resource>
<directory>resources</directory>
<filtering>true</filtering>
<includes>
<include>*.yml</include>
<include>*.txt</include>
<include>*.json</include>
<include>*.properties</include>
</includes>
</resource>
</resources>
</build>

</project>
10 changes: 10 additions & 0 deletions resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
data:
# Acceptable entries are (HTTP or JSON)
type: JSON
URL: http://example.site/perm_triggers.json

# If refresh is enabled the plugin will attempt to reload
# the triggers at an interval of minutes as specified below.
refresh:
enabled: true
interval: 60
39 changes: 39 additions & 0 deletions resources/perm_triggers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This file contains permission triggers.
#
# Triggers are sets of commands to be issue at the console
# when a permission is added to, or removed from a player.
#
# Commands can have prefixes to perform specific tasks.
# '#broadcast' '#tell'
{
"player.creative": {
"added": [
"gamemode creative {player}",
"#broadcast {player} has become enlightened!"
],
"removed": [
"gamemode survival {player}",
"#broadcast {player} has equipped leaded boots."
]
},
"player.speed": {
"added": [
"effect give {player} speed 1700 5 true",
"effect give {player} haste 1700 3 true",
"#tell You have become fast!"
],
"removed": [
"effect clear {player} speed",
"effect clear {player} haste",
"#tell Slow down speedy!"
]
},
"player.op": {
"added": [
"op {player}"
],
"removed": [
"deop {player}"
]
}
}
23 changes: 23 additions & 0 deletions resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: PermTrigger
main: com.palmergames.spigot.permtrigger.PermTrigger
version: ${project.version}
api-version: ${project.bukkitAPIVersion}

author: ElgarL
website: http://palmergames.com

description: >
Trigger commands based upon permission states
softdepend: [GroupManager,LuckPerms]

############################################################
# +------------------------------------------------------+ #
# | Commands | #
# +------------------------------------------------------+ #
############################################################

commands:
ptreload:
permission: pt.command.reload
default: op
115 changes: 115 additions & 0 deletions src/com/palmergames/spigot/permtrigger/DataCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* PermTrigger - A plug-in for Spigot/Bukkit based Minecraft servers.
* Copyright (C) 2020 ElgarL
*
* 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 <https://www.gnu.org/licenses/>.
*/
package com.palmergames.spigot.permtrigger;

import java.util.Set;
import java.util.UUID;

import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;

/**
* @author ElgarL
*
*/
public class DataCache {

private NamespacedKey key;
private PermTrigger plugin;
private Player player;

/**
*
*/
public DataCache(PermTrigger plugin) {

this.plugin = plugin;
}

/**
* Set the state of a Trigger. Or delete if false.
*
* @param uid UUID of the Player
* @param triggerPerm String permission to trigger on.
* @param state true or false.
*/
public void setTriggerState(UUID uid, String triggerPerm, boolean state) {

player = plugin.getServer().getPlayer(uid);
key = new NamespacedKey(plugin, triggerPerm);

if (player == null)
return;

if (state == true)
player.getPersistentDataContainer().set(key, PersistentDataType.BYTE, (byte) 1);
else
player.getPersistentDataContainer().remove(key);
}

/**
* Is this trigger currently set on the Player.
*
* @param uid UUID of the Player
* @param triggerPerm String permission to trigger on.
* @return true if set.
*/
public boolean hasTrigger(UUID uid, String triggerPerm) {

player = plugin.getServer().getPlayer(uid);
key = new NamespacedKey(plugin, triggerPerm);

if (player == null)
return false;

Byte node = player.getPersistentDataContainer().get(key, PersistentDataType.BYTE);

if (node != null)
return node.byteValue() == 1;

return false;
}

/**
* Called when a player disconnects to purge any old/unknown triggers.
*
* @param uid UUID of the Player
*/
public void purgeOldTriggers(UUID uid) {

player = plugin.getServer().getPlayer(uid);

if (player == null)
return;

Set<String> triggers = plugin.getDatabase().getTriggerKeys();

PersistentDataContainer container = player.getPersistentDataContainer();

for (NamespacedKey keys : container.getKeys()) {
if (!triggers.contains(keys.getKey())) {
plugin.getLogger().warning(String.format("Unknown trigger removed! %s.", keys.getKey()));
container.remove(keys);
}
}


}
}
Loading

0 comments on commit 9f67eca

Please sign in to comment.