Experimental Feature: Per GameMode Permission (Vault, Perm-Groups)

Readme update
Removed dep. provided by plib
This commit is contained in:
Jascha Starke 2013-03-24 22:26:53 +01:00
parent aa13a91c2c
commit ee0a78a2fe
9 changed files with 273 additions and 14 deletions

View file

@ -4,13 +4,13 @@ http://dev.bukkit.org/server-mods/limited-creative/
Required dependencies
---------------------
* [plib](https://github.com/possi/plib)
* [Bukkit](https://github.com/Bukkit/Bukkit)
Dependencies for optional integrations
--------------------------------------
* [WorldGuard](https://github.com/sk89q/worldguard)
* [WorldEdit](https://github.com/sk89q/worldedit)
* [xAuth](http://dev.bukkit.org/server-mods/xauth/)
* [AuthMe](http://dev.bukkit.org/server-mods/authme-reloaded/) ([GitSource](https://github.com/Multiplayer-italia/AuthMe-Reloaded))
* [Multiverse-Core](http://dev.bukkit.org/server-mods/multiverse-core/)

11
pom.xml
View file

@ -55,11 +55,6 @@
<id>onarandombox</id>
<url>http://repo.onarandombox.com/content/groups/public</url>
</repository>
<!-- Official Vault repository -->
<repository>
<id>vault-repo</id>
<url>http://ci.herocraftonline.com/plugin/repository/everything</url>
</repository>
<!-- Official xAuth repository; it is no good! we keep our own dep-files of it - ->
<repository>
<id>luricos.de-repo</id>
@ -73,12 +68,6 @@
<artifactId>plib</artifactId>
<version>${plib.version}</version>
</dependency>
<dependency>
<!-- http://dl.bukkit.org/ -->
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.5.1-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<!-- http://dev.bukkit.org/server-mods/worldguard/ -->
<groupId>com.sk89q</groupId>

View file

@ -29,6 +29,7 @@ public class LimitedCreative extends Core {
addModule(new ModCreativeLimits(this));
addModule(new ModRegions(this));
addModule(new ModCmdBlocker(this));
addModule(new ModGameModePerm(this));
addModule(new FeatureMetrics(this));
config.setModuleStates();

View file

@ -0,0 +1,66 @@
package de.jaschastarke.minecraft.limitedcreative;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.plugin.RegisteredServiceProvider;
import de.jaschastarke.bukkit.lib.CoreModule;
import de.jaschastarke.minecraft.limitedcreative.gmperm.GMPermConfig;
import de.jaschastarke.minecraft.limitedcreative.gmperm.PlayerListener;
import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
public class ModGameModePerm extends CoreModule<LimitedCreative> {
private GMPermConfig config;
private Permission permission = null;
private RegisteredServiceProvider<Permission> permissionProvider;
public ModGameModePerm(LimitedCreative plugin) {
super(plugin);
}
@Override
public String getName() {
return "GameModePerm";
}
@Override
public void initialize(ModuleEntry<IModule> entry) {
super.initialize(entry);
listeners.addListener(new PlayerListener(this));
config = new GMPermConfig(this, entry);
plugin.getPluginConfig().registerSection(config);
permissionProvider = plugin.getServer().getServicesManager().getRegistration(Permission.class);
if (config.getEnabled()) {
if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault")) {
getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", getName()));
entry.initialState = ModuleState.NOT_INITIALIZED;
} /*else if (!getVaultPermission().hasGroupSupport()) {
getLog().warn(plugin.getLocale().trans("gmperm.warning.no_group_support", getName()));
entry.initialState = ModuleState.NOT_INITIALIZED;
}*/
}
}
@Override
public void onEnable() {
super.onEnable();
getLog().info(plugin.getLocale().trans("basic.loaded.module"));
}
@Override
public void onDisable() {
super.onDisable();
permission = null;
}
public GMPermConfig getConfig() {
return config;
}
public Permission getVaultPermission() {
if (permissionProvider != null && permission == null) {
permission = permissionProvider.getProvider();
}
return permission;
}
}

View file

@ -47,7 +47,7 @@ public class ModInventories extends CoreModule<LimitedCreative> {
}
String incomp = Hooks.InventoryIncompatible.test();
if (incomp != null) {
if (config.getEnabled() && incomp != null) {
getLog().warn(plugin.getLocale().trans("inventory.warning.conflict", incomp, this.getName()));
entry.initialState = ModuleState.NOT_INITIALIZED;
}

View file

@ -53,7 +53,7 @@ public class ModRegions extends CoreModule<LimitedCreative> {
FlagList.addFlags(Flags.getList());
if (!plugin.getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
if (config.getEnabled() && !plugin.getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
getLog().warn(plugin.getLocale().trans("region.warning.worldguard_not_found", getName()));
entry.initialState = ModuleState.NOT_INITIALIZED;
}

View file

@ -0,0 +1,106 @@
package de.jaschastarke.minecraft.limitedcreative.gmperm;
import org.bukkit.configuration.ConfigurationSection;
import de.jaschastarke.bukkit.lib.configuration.Configuration;
import de.jaschastarke.configuration.IConfigurationNode;
import de.jaschastarke.configuration.IConfigurationSubGroup;
import de.jaschastarke.configuration.InvalidValueException;
import de.jaschastarke.configuration.annotations.IsConfigurationNode;
import de.jaschastarke.maven.ArchiveDocComments;
import de.jaschastarke.minecraft.limitedcreative.ModGameModePerm;
import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
/**
* GameMode-Permissions-Feature
*
* This Feature requires Vault-Plugin to be active.
*
* http://dev.bukkit.org/server-mods/limited-creative/pages/features/gmperm/
*/
@ArchiveDocComments
public class GMPermConfig extends Configuration implements IConfigurationSubGroup {
protected ModGameModePerm mod;
protected ModuleEntry<IModule> entry;
public GMPermConfig(ModGameModePerm modGameModePerm, ModuleEntry<IModule> modEntry) {
mod = modGameModePerm;
entry = modEntry;
}
@Override
public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException {
super.setValue(node, pValue);
if (node.getName().equals("enabled")) {
if (getEnabled()) {
if (entry.initialState != ModuleState.NOT_INITIALIZED)
entry.enable();
} else {
entry.disable();
}
}
}
@Override
public void setValues(ConfigurationSection sect) {
super.setValues(sect);
if (entry.initialState != ModuleState.NOT_INITIALIZED)
entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED;
}
@Override
public String getName() {
return "gmperm";
}
@Override
public int getOrder() {
return 600;
}
/**
* GMPermEnabled
*
* Activates that players are put in a special permission group while in creative mode.
*
* default: false
*/
@IsConfigurationNode(order = 100)
public boolean getEnabled() {
return config.getBoolean("enabled", false);
}
/**
* GMPermCreativeGroup
*
* Defines the Permission-Group which the player gets added to on entering creative-mode. If this value is changed
* the old group won't be automatically removed from players already in it. So be sure to delete the old group or
* remove all player of it, that they don't get stuck with that permissions.
*/
@IsConfigurationNode(order = 200)
public String getCreativeGroup() {
return config.getString("creativeGroup", "");
}
/**
* GMPermAdventureGroup
*
* Like GMPermCreativeGroup but for adventure users. This is optional, so you don't have to set any group.
*
* default: false
*/
@IsConfigurationNode(order = 300)
public String getAdventureGroup() {
return config.getString("adventureGroup");
}
@Override
public Object getValue(final IConfigurationNode node) {
Object val = super.getValue(node);
if (node.getName().equals("adventureGroup") && val == null) {
return new Boolean(false);
} else {
return val;
}
}
}

View file

@ -0,0 +1,95 @@
/*
* Limited Creative - (Bukkit Plugin)
* Copyright (C) 2012 jascha@ja-s.de
*
* 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 de.jaschastarke.minecraft.limitedcreative.gmperm;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import de.jaschastarke.minecraft.limitedcreative.ModGameModePerm;
public class PlayerListener implements Listener {
private ModGameModePerm mod;
public PlayerListener(ModGameModePerm mod) {
this.mod = mod;
}
protected Permission v() {
return mod.getVaultPermission();
}
@EventHandler(priority = EventPriority.MONITOR)
public void onGameModeChange(PlayerGameModeChangeEvent event) {
if (event.isCancelled())
return;
ensureGroup(event.getPlayer(), event.getNewGameMode());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLogin(PlayerLoginEvent event) {
if (event.getResult() == Result.ALLOWED)
return;
ensureGroup(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerTeleport(PlayerTeleportEvent event) {
if (!event.getFrom().getWorld().equals(event.getTo().getWorld())) {
ensureGroup(event.getPlayer());
}
}
protected void ensureGroup(Player player) {
ensureGroup(player, player.getGameMode());
}
protected void ensureGroup(Player player, GameMode gm) {
String cgroup = mod.getConfig().getCreativeGroup();
String agroup = mod.getConfig().getAdventureGroup();
if (gm == GameMode.CREATIVE) {
if (!v().playerInGroup(player, cgroup)) {
v().playerAddGroup(player, cgroup);
}
if (agroup != null && v().playerInGroup(player, agroup)) {
v().playerRemoveGroup(player, agroup);
}
} else if (gm == GameMode.ADVENTURE) {
if (v().playerInGroup(player, cgroup)) {
v().playerRemoveGroup(player, cgroup);
}
if (agroup != null && !v().playerInGroup(player, agroup)) {
v().playerAddGroup(player, agroup);
}
} else if (gm == GameMode.SURVIVAL) {
if (v().playerInGroup(player, cgroup)) {
v().playerRemoveGroup(player, cgroup);
}
if (agroup != null && v().playerInGroup(player, agroup)) {
v().playerRemoveGroup(player, agroup);
}
}
}
}

View file

@ -2,6 +2,8 @@ basic.loaded.module: Module loaded.
inventory.warning.conflict: Due to conflict with the plugin {0}, the feature {1} is disabled
region.warning.worldguard_not_found: WorldGuard isn't found, the feature {0} is disabled
gmperm.warning.vault_not_found: Vault isn't found, the feature {0} is disabled
gmperm.warning.no_group_support: Your Permission-Plugin doesn't support groups, the feature {0} is disabled
command.general: LimitedCreative: GameMode-Switch, Creative-Regions, Config and more
command.regions: LimitedCreative-Region-Command: configure creative regions