mirror of
https://github.com/PEXPlugins/Modifyworld.git
synced 2025-01-22 21:11:29 +01:00
Begin port/rewrite for Sponge
This commit is contained in:
parent
fa508d8a31
commit
a89fa7af33
11
README.md
Normal file
11
README.md
Normal file
@ -0,0 +1,11 @@
|
||||
modifyworld is a plugin for Sponge that provides world protection functionality
|
||||
|
||||
File locations
|
||||
--------------
|
||||
- `src/site/markdown`: Markdown files that will be included in the generated site
|
||||
- `src/main/kotlin`: Main plugin source files
|
||||
- `src/test/kotlin`: Test source files
|
||||
|
||||
Building
|
||||
--------
|
||||
`mvn clean install`. The built jar is located in `target/`
|
325
pom.xml
325
pom.xml
@ -1,101 +1,232 @@
|
||||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>ru.tehkode</groupId>
|
||||
<artifactId>Modifyworld</artifactId>
|
||||
<version>1.20-SNAPSHOT</version>
|
||||
<name>Modifyworld</name>
|
||||
<url>https://github.com/t3hk0d3/Modifyworld</url>
|
||||
<issueManagement>
|
||||
<system>GitHub</system>
|
||||
<url>https://github.com/t3hk0d3/Modifyworld/issues</url>
|
||||
</issueManagement>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/PEXPlugins/Modifyworld.git</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com/PEXPlugins/Modifyworld.git</developerConnection>
|
||||
<url>https://github.com/PEXPlugins/PermissionsEx.git</url>
|
||||
</scm>
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.basedir}/src/main/resources</directory>
|
||||
<!--<targetPath>/</targetPath>-->
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>ninja.leaping</groupId>
|
||||
<artifactId>modifyworld</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<name>Modifyworld</name>
|
||||
<description>
|
||||
A permission-based world protection plugin for Sponge
|
||||
</description>
|
||||
<properties>
|
||||
<siteUrlSuffix>${project.version}</siteUrlSuffix>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<kotlin.version>1.0.0-beta-4584</kotlin.version>
|
||||
<ghUser>PEXPlugins</ghUser>
|
||||
<ghRepo>Modifyworld</ghRepo>
|
||||
<ghProject>${ghUser}/${ghRepo}</ghProject>
|
||||
|
||||
</properties>
|
||||
|
||||
<url>https://${ghUser}.github.io/${ghRepo}</url>
|
||||
<issueManagement>
|
||||
<system>GitHub</system>
|
||||
<url>https://github.com/${ghProject}/issues</url>
|
||||
</issueManagement>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/${ghProject}.git</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com:${ghProject}.git</developerConnection>
|
||||
<url>https://github.com/${ghProject}</url>
|
||||
</scm>
|
||||
<distributionManagement>
|
||||
<site>
|
||||
<id>gh-pages</id>
|
||||
<name>GitHub Pages</name>
|
||||
<url>github:http://${ghUser}.github.io/${ghRepo}/${siteUrlSuffix}/</url>
|
||||
</site>
|
||||
</distributionManagement>
|
||||
<prerequisites>
|
||||
<maven>3.0.3</maven>
|
||||
</prerequisites>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>release</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>src/main/assembly/package.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>build</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<configuration>
|
||||
<preparationGoals>assembly:assembly</preparationGoals>
|
||||
<goals>assembly:assembly</goals>
|
||||
<tagNameFormat>STABLE-@{project.version}</tagNameFormat>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.dokka</groupId>
|
||||
<artifactId>dokka-maven-plugin</artifactId>
|
||||
<version>${dokka.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>pre-site</phase>
|
||||
<goals>
|
||||
<goal>dokka</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.6.2-R0.1</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.tehkode</groupId>
|
||||
<artifactId>PermissionsEx</artifactId>
|
||||
<version>1.22</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl</groupId>
|
||||
<artifactId>vault</artifactId>
|
||||
<version>1.2.27</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/groups/public</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://ci.herocraftonline.com/plugin/repository/everything</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>pex-repo</id>
|
||||
<url>http://pex-repo.zachsthings.com</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.basedir}/src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>templating-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<configuration>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin-templates</sourceDirectory>
|
||||
<outputDirectory>${project.build.directory}/generated-sources/kotlin-templates</outputDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/java-templates</testSourceDirectory>
|
||||
<testOutputDirectory>${project.build.directory}/generated-test-sources/kotlin-templates</testOutputDirectory>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>filter-src</id>
|
||||
<goals>
|
||||
<goal>filter-sources</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.4.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<phase>package</phase>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||
<shadedClassifierName>shaded</shadedClassifierName>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.trajano.wagon</groupId>
|
||||
<artifactId>wagon-git</artifactId>
|
||||
<version>2.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.doxia</groupId>
|
||||
<artifactId>doxia-module-markdown</artifactId>
|
||||
<version>1.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<configuration>
|
||||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||
<tagNameFormat>@{project.version}</tagNameFormat>
|
||||
<scmCommentPrefix xml:space="preserve">[RELEASE] </scmCommentPrefix>
|
||||
<goals>install deploy site-deploy</goals> <!-- install is here to fix javadoc generation in multi-module projects -->
|
||||
<releaseProfiles>release</releaseProfiles>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>[3.0.0,3.1.0)</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.aoeu</groupId>
|
||||
<artifactId>spongekt</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sponge-repo</id>
|
||||
<url>http://repo.spongepowered.org/maven</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>pex-repo</id>
|
||||
<url>https://pex-repo.aoeu.xyz</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.3</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
</project>
|
||||
|
@ -1,25 +0,0 @@
|
||||
|
||||
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
||||
<id>bin</id>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<includes>
|
||||
<include>README*</include>
|
||||
<include>CHANGELOG*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
<files>
|
||||
<file>
|
||||
<source>${project.build.directory}/${project.build.finalName}.jar</source>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<destName>${project.build.finalName}.jar</destName>
|
||||
</file>
|
||||
</files>
|
||||
</assembly>
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Modifyworld - PermissionsEx ruleset plugin for Bukkit
|
||||
* Copyright (C) 2011 t3hk0d3 http://www.tehkode.ru
|
||||
*
|
||||
* 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 2
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package ru.tehkode.modifyworld;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
|
||||
public enum EntityCategory {
|
||||
PLAYER("player", Player.class),
|
||||
ITEM("item", Item.class),
|
||||
ANIMAL("animal", Animals.class, Squid.class),
|
||||
MONSTER("monster", Monster.class, Slime.class, EnderDragon.class, Ghast.class ),
|
||||
NPC("npc", NPC.class),
|
||||
PROJECTILE("projectile", Projectile.class);
|
||||
|
||||
private String name;
|
||||
private Class<? extends Entity> classes[];
|
||||
|
||||
private final static Map<Class<? extends Entity>, EntityCategory> map = new HashMap<Class<? extends Entity>, EntityCategory>();
|
||||
|
||||
static {
|
||||
for (EntityCategory cat : EntityCategory.values()) {
|
||||
for (Class<? extends Entity> catClass : cat.getClasses()) {
|
||||
map.put(catClass, cat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private EntityCategory(String name, Class<? extends Entity>... classes) {
|
||||
this.name = name;
|
||||
this.classes = classes;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getNameDot() {
|
||||
return this.getName() + ".";
|
||||
}
|
||||
|
||||
public Class<? extends Entity>[] getClasses() {
|
||||
return this.classes;
|
||||
}
|
||||
|
||||
public static EntityCategory fromEntity(Entity entity) {
|
||||
for (Class<? extends Entity> entityClass : map.keySet()) {
|
||||
if (entityClass.isAssignableFrom(entity.getClass())) {
|
||||
return map.get(entityClass);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,186 +0,0 @@
|
||||
/*
|
||||
* Modifyworld - PermissionsEx ruleset plugin for Bukkit
|
||||
* Copyright (C) 2011 t3hk0d3 http://www.tehkode.ru
|
||||
*
|
||||
* 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 2
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
package ru.tehkode.modifyworld;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author t3hk0d3
|
||||
*/
|
||||
public abstract class ModifyworldListener implements Listener {
|
||||
|
||||
protected PlayerInformer informer;
|
||||
protected ConfigurationSection config;
|
||||
protected boolean informPlayers = false;
|
||||
protected boolean useMaterialNames = true;
|
||||
protected boolean checkMetadata = false;
|
||||
protected boolean checkItemUse = false;
|
||||
protected boolean enableWhitelist = false;
|
||||
|
||||
public ModifyworldListener(Plugin plugin, ConfigurationSection config, PlayerInformer informer) {
|
||||
this.informer = informer;
|
||||
this.config = config;
|
||||
|
||||
this.registerEvents(plugin);
|
||||
|
||||
this.informPlayers = config.getBoolean("informPlayers", informPlayers);
|
||||
this.useMaterialNames = config.getBoolean("use-material-names", useMaterialNames);
|
||||
this.checkMetadata = config.getBoolean("check-metadata", checkMetadata);
|
||||
this.checkItemUse = config.getBoolean("item-use-check", checkItemUse);
|
||||
this.enableWhitelist = config.getBoolean("whitelist", enableWhitelist);
|
||||
}
|
||||
|
||||
private String getEntityName(Entity entity) {
|
||||
|
||||
if (entity instanceof ComplexEntityPart) {
|
||||
return getEntityName(((ComplexEntityPart) entity).getParent());
|
||||
}
|
||||
|
||||
String entityName = formatEnumString(entity.getType().toString());
|
||||
|
||||
if (entity instanceof Item) {
|
||||
entityName = getItemPermission(((Item) entity).getItemStack());
|
||||
}
|
||||
|
||||
if (entity instanceof Player) {
|
||||
return "player." + ((Player) entity).getName();
|
||||
} else if (entity instanceof Tameable) {
|
||||
Tameable animal = (Tameable) entity;
|
||||
|
||||
return "animal." + entityName + (animal.isTamed() && animal.getOwner() != null ? "." + animal.getOwner().getName() : "");
|
||||
}
|
||||
|
||||
|
||||
EntityCategory category = EntityCategory.fromEntity(entity);
|
||||
|
||||
if (category == null) {
|
||||
return entityName; // category unknown (ender crystal)
|
||||
}
|
||||
|
||||
return category.getNameDot() + entityName;
|
||||
}
|
||||
|
||||
private String getInventoryTypePermission(InventoryType type) {
|
||||
return formatEnumString(type.name());
|
||||
}
|
||||
|
||||
// Functional programming fuck yeah
|
||||
private String getMaterialPermission(Material type) {
|
||||
return this.useMaterialNames ? formatEnumString(type.name()) : Integer.toString(type.getId());
|
||||
}
|
||||
|
||||
private String getMaterialPermission(Material type, byte metadata) {
|
||||
return getMaterialPermission(type) + (checkMetadata && metadata > 0 ? ":" + metadata : "");
|
||||
}
|
||||
|
||||
private String getBlockPermission(Block block) {
|
||||
return getMaterialPermission(block.getType(), block.getData());
|
||||
}
|
||||
|
||||
public String getItemPermission(ItemStack item) {
|
||||
return getMaterialPermission(item.getType(), item.getData().getData());
|
||||
}
|
||||
|
||||
/*
|
||||
protected boolean permissionDenied(Player player, String basePermission, Entity entity) {
|
||||
if (entity instanceof Player && PermissionsEx.isAvailable()) {
|
||||
PermissionUser entityUser = PermissionsEx.getUser((Player)entity);
|
||||
|
||||
for (PermissionGroup group : entityUser.getGroups()) {
|
||||
if (permissionDenied(player, basePermission, "group", group.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return permissionDenied(player, basePermission, "player", entityUser.getName());
|
||||
}
|
||||
|
||||
return permissionDenied(player, basePermission, entity);
|
||||
}
|
||||
*/
|
||||
|
||||
protected boolean permissionDenied(Player player, String basePermission, Object... arguments) {
|
||||
String permission = assemblePermission(basePermission, arguments);
|
||||
boolean isDenied = !player.hasPermission(permission);
|
||||
|
||||
if (isDenied) {
|
||||
this.informer.informPlayer(player, permission, arguments);
|
||||
}
|
||||
|
||||
return isDenied;
|
||||
}
|
||||
|
||||
protected boolean _permissionDenied(Player player, String permission, Object... arguments) {
|
||||
return !player.hasPermission(assemblePermission(permission, arguments));
|
||||
}
|
||||
|
||||
protected String assemblePermission(String permission, Object... arguments) {
|
||||
StringBuilder builder = new StringBuilder(permission);
|
||||
|
||||
if (arguments != null) {
|
||||
for (Object obj : arguments) {
|
||||
if (obj == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.append('.');
|
||||
builder.append(getObjectPermission(obj));
|
||||
}
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
protected String getObjectPermission(Object obj) {
|
||||
if (obj instanceof Entity) {
|
||||
return (getEntityName((Entity) obj));
|
||||
} else if (obj instanceof EntityType) {
|
||||
return formatEnumString(((EntityType)obj).name());
|
||||
} else if (obj instanceof BlockState) {
|
||||
return (getBlockPermission(((BlockState)obj).getBlock()));
|
||||
} else if (obj instanceof ItemStack) {
|
||||
return (getItemPermission((ItemStack) obj));
|
||||
} else if (obj instanceof Material) {
|
||||
return (getMaterialPermission((Material) obj));
|
||||
} else if (obj instanceof Block) {
|
||||
return (getBlockPermission((Block) obj));
|
||||
} else if (obj instanceof InventoryType) {
|
||||
return getInventoryTypePermission((InventoryType)obj);
|
||||
}
|
||||
|
||||
return (obj.toString());
|
||||
}
|
||||
|
||||
private void registerEvents(Plugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
private String formatEnumString(String enumName) {
|
||||
return enumName.toLowerCase().replace("_", "");
|
||||
}
|
||||
}
|
@ -1,215 +0,0 @@
|
||||
package ru.tehkode.modifyworld;
|
||||
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.ComplexEntityPart;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import ru.tehkode.permissions.PermissionUser;
|
||||
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PlayerInformer {
|
||||
|
||||
public final static String PERMISSION_DENIED = "Sorry, you don't have enough permissions";
|
||||
public final static String DEFAULT_MESSAGE_FORMAT = "&f[&2Modifyworld&f]&4 %s";
|
||||
// Default message format
|
||||
protected String messageFormat = DEFAULT_MESSAGE_FORMAT;
|
||||
protected Map<String, String> messages = new HashMap<String, String>();
|
||||
// Flags
|
||||
protected boolean enabled = false;
|
||||
protected boolean individualMessages = false;
|
||||
protected String defaultMessage = PERMISSION_DENIED;
|
||||
|
||||
public PlayerInformer(ConfigurationSection config) {
|
||||
this.enabled = config.getBoolean("inform-players", enabled);
|
||||
|
||||
this.loadConfig(config.getConfigurationSection("messages"));
|
||||
}
|
||||
|
||||
private void loadConfig(ConfigurationSection config) {
|
||||
|
||||
this.defaultMessage = config.getString("default-message", this.defaultMessage);
|
||||
this.messageFormat = config.getString("message-format", this.messageFormat);
|
||||
this.individualMessages = config.getBoolean("individual-messages", this.individualMessages);
|
||||
|
||||
this.importMessages(config);
|
||||
|
||||
for (String permission : config.getKeys(true)) {
|
||||
if (!config.isString(permission)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
setMessage(permission, config.getString(permission.replace("/", ".")));
|
||||
}
|
||||
}
|
||||
|
||||
public void setMessage(String permission, String message) {
|
||||
messages.put(permission, message);
|
||||
}
|
||||
|
||||
public String getMessage(String permission) {
|
||||
if (messages.containsKey(permission)) {
|
||||
return messages.get(permission);
|
||||
}
|
||||
|
||||
String perm = permission;
|
||||
int index;
|
||||
|
||||
while ((index = perm.lastIndexOf(".")) != -1) {
|
||||
perm = perm.substring(0, index);
|
||||
|
||||
if (messages.containsKey(perm)) {
|
||||
String message = messages.get(perm);
|
||||
messages.put(permission, message);
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
return this.defaultMessage;
|
||||
}
|
||||
|
||||
public String getMessage(Player player, String permission) {
|
||||
String message = null;
|
||||
if (Bukkit.getServer().getPluginManager().isPluginEnabled("Vault")) {
|
||||
message = getMessageVault(player, permission);
|
||||
}
|
||||
if (message == null) {
|
||||
try {
|
||||
Class.forName("ru.tehkode.permissions.bukkit.PermissionsEx");
|
||||
message = getMessagePEX(player, permission);
|
||||
} catch (ClassNotFoundException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
if (message != null) {
|
||||
return message;
|
||||
}
|
||||
|
||||
return getMessage(permission);
|
||||
}
|
||||
|
||||
public String getMessagePEX(Player player, String permission) {
|
||||
if (PermissionsEx.isAvailable()) {
|
||||
PermissionUser user = PermissionsEx.getUser(player);
|
||||
|
||||
String message;
|
||||
String perm = permission;
|
||||
int index;
|
||||
|
||||
while ((index = perm.lastIndexOf(".")) != -1) {
|
||||
perm = perm.substring(0, index);
|
||||
|
||||
message = user.getOption("permission-denied-" + perm, player.getWorld().getName(), null);
|
||||
if (message == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
message = user.getOption("permission-denied", player.getWorld().getName(), null);
|
||||
|
||||
if (message != null) {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getMessageVault(Player player, String permission) {
|
||||
Chat chat = Bukkit.getServer().getServicesManager().load(Chat.class);
|
||||
if (chat != null) {
|
||||
String message;
|
||||
String perm = permission;
|
||||
int index;
|
||||
|
||||
while ((index = perm.lastIndexOf(".")) != -1) {
|
||||
perm = perm.substring(0, index);
|
||||
|
||||
message = chat.getPlayerInfoString(player.getWorld(), player.getName(), "permission-denied-" + perm, null);
|
||||
if (message == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
message = chat.getPlayerInfoString(player.getWorld(), player.getName(), "permission-denied", null);
|
||||
if (message != null) {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void informPlayer(Player player, String permission, Object... args) {
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
String message = getMessage(player, permission).replace("$permission", permission);
|
||||
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
message = message.replace("$" + (i + 1), describeObject(args[i]));
|
||||
}
|
||||
|
||||
if (message != null && !message.isEmpty()) {
|
||||
player.sendMessage(String.format(messageFormat, message).replaceAll("&([a-z0-9])", "\u00A7$1"));
|
||||
}
|
||||
}
|
||||
|
||||
protected String describeObject(Object obj) {
|
||||
if (obj instanceof ComplexEntityPart) { // Complex entities
|
||||
return describeObject(((ComplexEntityPart) obj).getParent());
|
||||
} else if (obj instanceof Item) { // Dropped items
|
||||
return describeMaterial(((Item) obj).getItemStack().getType());
|
||||
} else if (obj instanceof ItemStack) { // Items
|
||||
return describeMaterial(((ItemStack) obj).getType());
|
||||
} else if (obj instanceof Entity) { // Entities
|
||||
return ((Entity) obj).getType().toString().toLowerCase().replace("_", " ");
|
||||
} else if (obj instanceof Block) { // Blocks
|
||||
return describeMaterial(((Block) obj).getType());
|
||||
} else if (obj instanceof Material) { // Just material
|
||||
return describeMaterial((Material) obj);
|
||||
}
|
||||
|
||||
return obj.toString();
|
||||
}
|
||||
|
||||
private String describeMaterial(Material material) {
|
||||
// TODO: implement data id
|
||||
|
||||
if (material == Material.INK_SACK) {
|
||||
return "dye";
|
||||
}
|
||||
|
||||
return material.toString().toLowerCase().replace("_", " ");
|
||||
}
|
||||
|
||||
// For backward compatibility
|
||||
private void importMessages(ConfigurationSection config) {
|
||||
// This should NOT be refactored, because it would be stupid :D
|
||||
if (config.isString("whitelistMessage")) {
|
||||
setMessage("modifyworld.login", config.getString("whitelistMessage"));
|
||||
config.set("whitelistMessage", null);
|
||||
}
|
||||
|
||||
if (config.isString("prohibitedItem")) {
|
||||
setMessage("modifyworld.items.have", config.getString("prohibitedItem"));
|
||||
config.set("prohibitedItem", null);
|
||||
}
|
||||
|
||||
if (config.isString("permissionDenied")) {
|
||||
setMessage("modifyworld", config.getString("permissionDenied"));
|
||||
config.set("permissionDenied", null);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,225 +0,0 @@
|
||||
/*
|
||||
* Modifyworld - PermissionsEx ruleset plugin for Bukkit
|
||||
* Copyright (C) 2011 t3hk0d3 http://www.tehkode.ru
|
||||
*
|
||||
* 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 2
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
package ru.tehkode.modifyworld.bukkit;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import ru.tehkode.modifyworld.ModifyworldListener;
|
||||
import ru.tehkode.modifyworld.PlayerInformer;
|
||||
import ru.tehkode.modifyworld.handlers.BlockListener;
|
||||
import ru.tehkode.modifyworld.handlers.EntityListener;
|
||||
import ru.tehkode.modifyworld.handlers.PlayerListener;
|
||||
import ru.tehkode.modifyworld.handlers.VehicleListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author t3hk0d3
|
||||
*/
|
||||
public class Modifyworld extends JavaPlugin {
|
||||
|
||||
protected final static Class<? extends ModifyworldListener>[] LISTENERS = new Class[]{
|
||||
PlayerListener.class,
|
||||
EntityListener.class,
|
||||
BlockListener.class,
|
||||
VehicleListener.class
|
||||
};
|
||||
protected List<ModifyworldListener> listeners = new ArrayList<ModifyworldListener>();
|
||||
protected PlayerInformer informer;
|
||||
protected File configFile;
|
||||
protected FileConfiguration config;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
configFile = new File(this.getDataFolder(), "config.yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.config = this.getConfig();
|
||||
|
||||
if (!config.isConfigurationSection("messages")) {
|
||||
this.getLogger().severe("Deploying default config");
|
||||
this.initializeConfiguration(config);
|
||||
}
|
||||
|
||||
this.informer = new PlayerInformer(config);
|
||||
|
||||
this.registerListeners();
|
||||
this.getLogger().info("Modifyworld enabled!");
|
||||
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.listeners.clear();
|
||||
this.config = null;
|
||||
|
||||
this.getLogger().info("Modifyworld successfully disabled!");
|
||||
}
|
||||
|
||||
protected void initializeConfiguration(FileConfiguration config) {
|
||||
// Flags
|
||||
config.set("item-restrictions", false);
|
||||
config.set("inform-players", true);
|
||||
config.set("whitelist", false);
|
||||
config.set("use-material-names", true);
|
||||
config.set("drop-restricted-item", false);
|
||||
config.set("item-use-check", false);
|
||||
config.set("check-metadata", true);
|
||||
}
|
||||
|
||||
protected void registerListeners() {
|
||||
for (Class listenerClass : LISTENERS) {
|
||||
try {
|
||||
Constructor constructor = listenerClass.getConstructor(Plugin.class, ConfigurationSection.class, PlayerInformer.class);
|
||||
ModifyworldListener listener = (ModifyworldListener) constructor.newInstance(this, this.getConfig(), this.informer);
|
||||
this.listeners.add(listener);
|
||||
} catch (Throwable e) {
|
||||
this.getLogger().warning("Failed to initialize \"" + listenerClass.getName() + "\" listener");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream getLocalizedResource(String path) {
|
||||
return getLocalizedResource(path, Locale.getDefault());
|
||||
}
|
||||
|
||||
public InputStream getLocalizedResource(String path, Locale locale) {
|
||||
InputStream ret;
|
||||
ret = getResource("lang/" + locale.toString() + "/" + path); // Country-specific
|
||||
if (ret == null && !locale.getCountry().isEmpty()) { // Available without country-specific variant
|
||||
ret = getResource("lang/" + locale.getLanguage() + "/" + path);
|
||||
}
|
||||
if (ret == null) { // Unlocalized
|
||||
ret = getResource(path);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private YamlConfiguration loadBaseLanguage(String path, Locale locale) throws IOException, InvalidConfigurationException {
|
||||
InputStream load = getResource("lang/" + locale.getLanguage() + "/" + path);
|
||||
if (load != null) {
|
||||
YamlConfiguration conf = new YamlConfiguration();
|
||||
conf.options().copyDefaults(true);
|
||||
conf.load(load);
|
||||
YamlConfiguration def = loadUnlocalized(path);
|
||||
if (def != null) {
|
||||
conf.setDefaults(def);
|
||||
}
|
||||
return conf;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private YamlConfiguration loadUnlocalized(String path) throws IOException, InvalidConfigurationException {
|
||||
InputStream load = getResource(path);
|
||||
if (load != null) {
|
||||
YamlConfiguration conf = new YamlConfiguration();
|
||||
conf.load(load);
|
||||
return conf;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public YamlConfiguration getLocalizedConfig(String path) throws InvalidConfigurationException, IOException {
|
||||
return getLocalizedConfig(path, Locale.getDefault());
|
||||
}
|
||||
|
||||
public YamlConfiguration getLocalizedConfig(String path, Locale locale) throws InvalidConfigurationException, IOException {
|
||||
YamlConfiguration base = new YamlConfiguration();
|
||||
InputStream load = getResource("lang/" + locale.toString() + "/" + path); // Country-specific
|
||||
if (load != null) {
|
||||
base.load(load);
|
||||
base.options().copyDefaults(true);
|
||||
YamlConfiguration def = loadBaseLanguage(path, locale);
|
||||
if (def == null) {
|
||||
def = loadUnlocalized(path);
|
||||
}
|
||||
if (def != null) {
|
||||
base.setDefaults(def);
|
||||
}
|
||||
} else {
|
||||
base = loadBaseLanguage(path, locale);
|
||||
if (base == null) {
|
||||
base = loadUnlocalized(path);
|
||||
}
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileConfiguration getConfig() {
|
||||
if (this.config == null) {
|
||||
this.reloadConfig();
|
||||
}
|
||||
|
||||
return this.config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveConfig() {
|
||||
try {
|
||||
this.config.save(configFile);
|
||||
} catch (IOException e) {
|
||||
this.getLogger().severe("Failed to save configuration file: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
this.config = new YamlConfiguration();
|
||||
config.options().pathSeparator('/');
|
||||
|
||||
try {
|
||||
config.load(configFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
this.getLogger().severe("Configuration file not found - deploying default one");
|
||||
InputStream defConfigStream = getLocalizedResource("config.yml");
|
||||
if (defConfigStream != null) {
|
||||
try {
|
||||
this.config.load(defConfigStream);
|
||||
} catch (Exception de) {
|
||||
this.getLogger().severe("Default config file is broken. Please tell this to Modifyworld author.");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.getLogger().severe("Failed to load configuration file: " + e.getMessage());
|
||||
}
|
||||
|
||||
InputStream defConfigStream = getLocalizedResource("config.yml");
|
||||
if (defConfigStream != null) {
|
||||
this.config.setDefaults(YamlConfiguration.loadConfiguration(defConfigStream));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Modifyworld - PermissionsEx ruleset plugin for Bukkit
|
||||
* Copyright (C) 2011 t3hk0d3 http://www.tehkode.ru
|
||||
*
|
||||
* 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 2
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
package ru.tehkode.modifyworld.handlers;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakEvent;
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import ru.tehkode.modifyworld.ModifyworldListener;
|
||||
import ru.tehkode.modifyworld.PlayerInformer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author t3hk0d3
|
||||
*/
|
||||
public class BlockListener extends ModifyworldListener {
|
||||
|
||||
public BlockListener(Plugin plugin, ConfigurationSection config, PlayerInformer informer) {
|
||||
super(plugin, config, informer);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (permissionDenied(event.getPlayer(), "modifyworld.blocks.destroy", event.getBlock())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (permissionDenied(event.getPlayer(), "modifyworld.blocks.place", event.getBlock())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onHangingBreakByEntity(HangingBreakByEntityEvent event) {
|
||||
if (event.getRemover() instanceof Player
|
||||
&& permissionDenied((Player) event.getRemover(), "modifyworld.blocks.destroy", event.getEntity().getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPaintingPlace(HangingPlaceEvent event) {
|
||||
if (permissionDenied(event.getPlayer(), "modifyworld.blocks.place", event.getEntity().getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Modifyworld - PermissionsEx ruleset plugin for Bukkit
|
||||
* Copyright (C) 2011 t3hk0d3 http://www.tehkode.ru
|
||||
*
|
||||
* 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 2
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
package ru.tehkode.modifyworld.handlers;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import ru.tehkode.modifyworld.ModifyworldListener;
|
||||
import ru.tehkode.modifyworld.PlayerInformer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author t3hk0d3
|
||||
*/
|
||||
public class EntityListener extends ModifyworldListener {
|
||||
|
||||
public EntityListener(Plugin plugin, ConfigurationSection config, PlayerInformer informer) {
|
||||
super(plugin, config, informer);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
EntityDamageByEntityEvent edbe = (EntityDamageByEntityEvent) event;
|
||||
|
||||
Player player;
|
||||
if (edbe.getDamager() instanceof Player) { // Prevent from damaging by player
|
||||
player = (Player) edbe.getDamager();
|
||||
if (permissionDenied(player, "modifyworld.damage.deal", event.getEntity())) {
|
||||
cancelDamageEvent(player, event);
|
||||
}
|
||||
}
|
||||
|
||||
if (edbe.getEntity() instanceof Player) {
|
||||
player = (Player) edbe.getEntity();
|
||||
if (edbe.getDamager() != null && player.isOnline()) { // Prevent from taking damage by entity
|
||||
if (_permissionDenied(player, "modifyworld.damage.take", edbe.getDamager())) {
|
||||
cancelDamageEvent(player, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (event.getEntity() instanceof Player) { // player are been damaged by enviroment
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if (_permissionDenied(player, "modifyworld.damage.take", event.getCause().name().toLowerCase().replace("_", ""))) {
|
||||
cancelDamageEvent(player, event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void cancelDamageEvent(Player player, EntityDamageEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onEntityTame(EntityTameEvent event) {
|
||||
if (!(event.getOwner() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getOwner();
|
||||
|
||||
if (permissionDenied(player, "modifyworld.tame", event.getEntity())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onEntityTarget(EntityTargetEvent event) {
|
||||
if (event.getTarget() instanceof Player) {
|
||||
Player player = (Player) event.getTarget();
|
||||
if (_permissionDenied(player, "modifyworld.mobtarget", event.getEntity())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,350 +0,0 @@
|
||||
/*
|
||||
* Modifyworld - PermissionsEx ruleset plugin for Bukkit
|
||||
* Copyright (C) 2011 t3hk0d3 http://www.tehkode.ru
|
||||
*
|
||||
* 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 2
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
package ru.tehkode.modifyworld.handlers;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.enchantment.EnchantItemEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.material.SpawnEgg;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.Vector;
|
||||
import ru.tehkode.modifyworld.ModifyworldListener;
|
||||
import ru.tehkode.modifyworld.PlayerInformer;
|
||||
|
||||
/**
|
||||
* @author t3hk0d3
|
||||
*/
|
||||
public class PlayerListener extends ModifyworldListener {
|
||||
|
||||
protected boolean checkInventory = false;
|
||||
protected boolean dropRestrictedItem = false;
|
||||
|
||||
public PlayerListener(Plugin plugin, ConfigurationSection config, PlayerInformer informer) {
|
||||
super(plugin, config, informer);
|
||||
|
||||
this.checkInventory = config.getBoolean("item-restrictions", this.checkInventory);
|
||||
this.dropRestrictedItem = config.getBoolean("drop-restricted-item", this.dropRestrictedItem);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerSneak(PlayerToggleSneakEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (event.isSneaking() && _permissionDenied(player, "modifyworld.sneak")) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().setSneaking(false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerSprint(PlayerToggleSprintEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (event.isSprinting() && _permissionDenied(player, "modifyworld.sprint")) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().setSprinting(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
if (!enableWhitelist) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (_permissionDenied(player, "modifyworld.login")) {
|
||||
// String whiteListMessage = user.getOption("kick-message", worldName, this.whitelistKickMessage);
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, informer.getMessage(player, "modifyworld.login"));
|
||||
Logger.getLogger("Minecraft").info("Player \"" + player.getName() + "\" were kicked by Modifyworld - lack of 'modifyworld.login' permission");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
|
||||
if (permissionDenied(event.getPlayer(), "modifyworld.usebeds")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
String bucketName = event.getBucket().toString().toLowerCase().replace("_bucket", ""); // WATER_BUCKET -> water
|
||||
if (permissionDenied(event.getPlayer(), "modifyworld.bucket.empty", bucketName)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
||||
String materialName = event.getBlockClicked().getType().toString().toLowerCase().replace("stationary_", ""); // STATIONARY_WATER -> water
|
||||
|
||||
if ("air".equals(materialName)) { // This should be milk
|
||||
materialName = "milk";
|
||||
}
|
||||
|
||||
if (permissionDenied(event.getPlayer(), "modifyworld.bucket.fill", materialName)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if (event.getMessage().startsWith("/tell") && permissionDenied(event.getPlayer(), "modifyworld.chat.private")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
if (permissionDenied(event.getPlayer(), "modifyworld.chat")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
// No inform to avoid spam
|
||||
if (_permissionDenied(event.getPlayer(), "modifyworld.items.pickup", event.getItem().getItemStack())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
this.checkPlayerInventory(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (permissionDenied(event.getPlayer(), "modifyworld.items.drop", event.getItemDrop().getItemStack())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
this.checkPlayerInventory(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onItemHeldChange(PlayerItemHeldEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
ItemStack item = player.getInventory().getItem(event.getNewSlot());
|
||||
|
||||
if (item != null && item.getType() != Material.AIR &&
|
||||
permissionDenied(player, "modifyworld.items.hold", item)) {
|
||||
int freeSlot = getFreeSlot(player.getInventory());
|
||||
|
||||
if (freeSlot != 0) {
|
||||
player.getInventory().setItem(freeSlot, item);
|
||||
} else {
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), item);
|
||||
}
|
||||
|
||||
player.getInventory().setItem(event.getNewSlot(), new ItemStack(Material.AIR));
|
||||
}
|
||||
|
||||
this.checkPlayerInventory(player);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerInventoryClick(InventoryClickEvent event) {
|
||||
InventoryHolder holder = event.getInventory().getHolder();
|
||||
|
||||
if (holder instanceof Player || // do not track inter-inventory stuff
|
||||
event.getRawSlot() >= event.getView().getTopInventory().getSize() || // top inventory only
|
||||
event.getSlotType() == InventoryType.SlotType.OUTSIDE || // do not track drop
|
||||
event.getSlot() == -999) { // temporary fix for bukkit bug (BUKKIT-2768)
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack take = event.getCurrentItem();
|
||||
|
||||
String action;
|
||||
ItemStack item;
|
||||
|
||||
if (take == null) {
|
||||
action = "put";
|
||||
item = event.getCursor();
|
||||
} else {
|
||||
action = "take";
|
||||
item = take;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
if (permissionDenied(player, "modifyworld.items", action, item, "of", event.getInventory().getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerInventoryEvent(InventoryClickEvent event) {
|
||||
ItemStack item = event.getCursor();
|
||||
|
||||
if (item == null || item.getType() == Material.AIR || event.getSlotType() != InventoryType.SlotType.QUICKBAR) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
int targetSlot = player.getInventory().getHeldItemSlot();
|
||||
|
||||
if (event.getSlot() == targetSlot && permissionDenied(player, "modifyworld.items.hold", item)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (this.checkItemUse) {
|
||||
if (permissionDenied(event.getPlayer(), "modifyworld.items.use", event.getPlayer().getItemInHand(), "on.entity", event.getRightClicked())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.isCancelled() && permissionDenied(event.getPlayer(), "modifyworld.interact", event.getRightClicked())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Action action = event.getAction();
|
||||
|
||||
if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) { // item restriction check
|
||||
this.checkPlayerInventory(event.getPlayer());
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) { //RIGHT_CLICK_AIR is cancelled by default.
|
||||
switch (player.getItemInHand().getType()) {
|
||||
case POTION: //Only check splash potions.
|
||||
if ((player.getItemInHand().getDurability() & 0x4000) != 0x4000) {
|
||||
break;
|
||||
}
|
||||
case EGG:
|
||||
case SNOW_BALL:
|
||||
case EXP_BOTTLE:
|
||||
if (permissionDenied(player, "modifyworld.items.throw", player.getItemInHand())) {
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
//Denying a potion works fine, but the client needs to be updated because it already reduced the item.
|
||||
if (player.getItemInHand().getType() == Material.POTION) {
|
||||
event.getPlayer().updateInventory();
|
||||
}
|
||||
}
|
||||
return; // no need to check further
|
||||
case MONSTER_EGG: // don't add MONSTER_EGGS here
|
||||
if (permissionDenied(player, "modifyworld.spawn", ((SpawnEgg)player.getItemInHand().getData()).getSpawnedType())) {
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
}
|
||||
return; // no need to check further
|
||||
}
|
||||
}
|
||||
|
||||
if (action != Action.LEFT_CLICK_BLOCK && action != Action.RIGHT_CLICK_BLOCK && action != Action.PHYSICAL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.checkItemUse && action != Action.PHYSICAL) {
|
||||
if (permissionDenied(event.getPlayer(), "modifyworld.items.use", player.getItemInHand(), "on.block", event.getClickedBlock())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.isCancelled() && permissionDenied(player, "modifyworld.blocks.interact", event.getClickedBlock())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onItemEnchant(EnchantItemEvent event) {
|
||||
if (permissionDenied(event.getEnchanter(), "modifyworld.items.enchant", event.getItem())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onItemCraft(CraftItemEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
if (permissionDenied(player, "modifyworld.items.craft", event.getRecipe().getResult())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
||||
Player player = event.getEntity() instanceof Player ? (Player) event.getEntity() : null;
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_permissionDenied(player, "modifyworld.digestion")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkPlayerInventory(Player player) {
|
||||
if (!checkInventory) {
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory inventory = player.getInventory();
|
||||
for (ItemStack stack : inventory.getContents()) {
|
||||
if (stack != null && permissionDenied(player, "modifyworld.items.have", stack)) {
|
||||
inventory.remove(stack);
|
||||
|
||||
if (this.dropRestrictedItem) {
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getFreeSlot(Inventory inventory) {
|
||||
for (int i = 9; i <= 35; i++) {
|
||||
if (inventory.getItem(i) == null || inventory.getItem(i).getType() == Material.AIR) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Modifyworld - PermissionsEx ruleset plugin for Bukkit
|
||||
* Copyright (C) 2011 t3hk0d3 http://www.tehkode.ru
|
||||
*
|
||||
* 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 2
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
package ru.tehkode.modifyworld.handlers;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.vehicle.VehicleDamageEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEntityCollisionEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import ru.tehkode.modifyworld.ModifyworldListener;
|
||||
import ru.tehkode.modifyworld.PlayerInformer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author t3hk0d3
|
||||
*/
|
||||
public class VehicleListener extends ModifyworldListener {
|
||||
|
||||
public VehicleListener(Plugin plugin, ConfigurationSection config, PlayerInformer informer) {
|
||||
super(plugin, config, informer);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onVehicleDamage(VehicleDamageEvent event) {
|
||||
if (!(event.getAttacker() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getAttacker();
|
||||
if (permissionDenied(player, "modifyworld.vehicle.destroy", event.getVehicle())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onVehicleEnter(VehicleEnterEvent event) {
|
||||
if (!(event.getEntered() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntered();
|
||||
if (permissionDenied(player, "modifyworld.vehicle.enter", event.getVehicle())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onVehicleEntityCollision(VehicleEntityCollisionEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
if (_permissionDenied(player, "modifyworld.vehicle.collide", event.getVehicle())) {
|
||||
event.setCancelled(true);
|
||||
event.setCollisionCancelled(true);
|
||||
event.setPickupCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package ninja.leaping.modifyworld
|
||||
|
||||
internal object PomData {
|
||||
const val ARTIFACT_ID = "${project.artifactId}";
|
||||
const val NAME = "${project.name}";
|
||||
const val VERSION = "${project.version}";
|
||||
}
|
31
src/main/kotlin/ninja/leaping/modifyworld/Listeners.kt
Normal file
31
src/main/kotlin/ninja/leaping/modifyworld/Listeners.kt
Normal file
@ -0,0 +1,31 @@
|
||||
package ninja.leaping.modifyworld
|
||||
|
||||
import org.spongepowered.api.entity.living.player.Player
|
||||
import org.spongepowered.api.event.Listener
|
||||
import org.spongepowered.api.event.message.MessageChannelEvent
|
||||
import org.spongepowered.api.event.network.ClientConnectionEvent
|
||||
|
||||
import xyz.aoeu.spongekt.*;
|
||||
|
||||
/**
|
||||
* Event listeners for Modifyworld checks
|
||||
*/
|
||||
|
||||
class Listeners(private val plugin: ModifyworldPlugin) {
|
||||
@Listener
|
||||
fun whitelistListener(event: ClientConnectionEvent.Login) {
|
||||
if (!event.targetUser.hasPermission(Permissions.WHITELIST)) {
|
||||
event.setMessage(+"You are not whitelisted! Make sure you've been invited!")
|
||||
event.isCancelled = true
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
fun chatListener(event: MessageChannelEvent.Chat) {
|
||||
event.cause.first(Player::class.java).ifPresent {
|
||||
if (!it.hasPermission(Permissions.CHAT)) { // TODO: Figure out notification
|
||||
event.isCancelled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package ninja.leaping.modifyworld
|
||||
|
||||
import com.google.inject.Inject
|
||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode
|
||||
import ninja.leaping.configurate.loader.ConfigurationLoader
|
||||
import org.slf4j.Logger
|
||||
import org.spongepowered.api.Game
|
||||
import org.spongepowered.api.event.game.state.GamePreInitializationEvent
|
||||
import org.spongepowered.api.event.game.state.GameStoppingServerEvent
|
||||
import org.spongepowered.api.plugin.Plugin
|
||||
import org.spongepowered.api.config.DefaultConfig
|
||||
import org.spongepowered.api.event.Listener
|
||||
|
||||
/**
|
||||
* A simple sponge plugin
|
||||
*/
|
||||
@Plugin(id = PomData.ARTIFACT_ID, name = PomData.NAME, version = PomData.VERSION)
|
||||
class ModifyworldPlugin @Inject constructor(private val logger: Logger, val game: Game) {
|
||||
// Give us a configuration to work from
|
||||
@Inject @DefaultConfig(sharedRoot = true) private lateinit var configLoader: ConfigurationLoader<CommentedConfigurationNode>
|
||||
|
||||
@Listener
|
||||
fun onPreInit(event: GamePreInitializationEvent) {
|
||||
game.eventManager.registerListeners(this, Listeners(this))
|
||||
// Perform initialization tasks here
|
||||
}
|
||||
|
||||
@Listener
|
||||
fun disable(event: GameStoppingServerEvent) {
|
||||
// Perform shutdown tasks here
|
||||
}
|
||||
}
|
||||
|
||||
internal object Permissions {
|
||||
const val ROOT = "modifyworld"
|
||||
const val WHITELIST = "$ROOT.login"
|
||||
const val CHAT = "$ROOT.chat"
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
messages:
|
||||
message-format: '&f[&2Modifyworld&f]&4 %s'
|
||||
default-message: Sorry, you don't have enough permissions
|
||||
modifyworld.items.use: Stop, &a$1&4 won't fit into &a$3
|
||||
modifyworld.login: You are not allowed to join this server. Goodbye!
|
||||
modifyworld.blocks.interact: You are too jelly for &2$1
|
||||
modifyworld.blocks.place: This is wrong place for &a$1
|
||||
modifyworld.blocks.destroy: '&a$1&4 is tough for you'
|
||||
modifyworld.damage.deal: Your level is too low for &5$1
|
||||
modifyworld.chat: Your mouth is too dry
|
||||
modifyworld.chat.private: Listener is deaf :(
|
||||
modifyworld.items.have: Prohibited item &a$1&4 has been removed from your inventory.
|
||||
modifyworld.items.drop: This is indecent to scatter &a$1&4 around
|
||||
modifyworld.items.hold: Beware, &a$1&4 is cursed!
|
||||
modifyworld.items.craft: Sorry, but &a$1&4 is too complicated
|
||||
modifyworld.items.enchant: Sorry, &a$1&4 is too dangerous
|
||||
modifyworld.vehicle.enter.boat: You are too heavy for this &a$1
|
||||
modifyworld.vehicle.enter.minecart: Sorry, but &a$1&4 is too small
|
||||
modifyworld.vehicle.destroy: This &a$1&4 is legal property of &bUnited States of America
|
||||
modifyworld.tame: This &a$1&4 is too ferocious
|
||||
modifyworld.bucket.fill: This bucket is holey
|
||||
modifyworld.bucket.empty: You suddenly realized you still need &a$1
|
||||
modifyworld.usebeds: You can't sleep yet, there are monsters nearby
|
@ -1,7 +0,0 @@
|
||||
name: Modifyworld
|
||||
main: ru.tehkode.modifyworld.bukkit.Modifyworld
|
||||
soft-depend: [ PermissionsEx, Vault ]
|
||||
version: "${project.version}"
|
||||
author: t3hk0d3
|
||||
website: www.bukkit.org
|
||||
description: World modification permission ruleset
|
25
src/site/site.xml
Normal file
25
src/site/site.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/DECORATION/1.3.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.3.0 http://maven.apache.org/xsd/decoration-1.3.0.xsd"
|
||||
name="${project.name} - ${project.version}">
|
||||
<version position="right" />
|
||||
<body>
|
||||
<menu title="Overview">
|
||||
<item name="Home" href="index.html" />
|
||||
</menu>
|
||||
<menu ref="reports" />
|
||||
</body>
|
||||
<skin>
|
||||
<groupId>org.apache.maven.skins</groupId>
|
||||
<artifactId>maven-fluido-skin</artifactId>
|
||||
<version>1.3.1</version>
|
||||
</skin>
|
||||
<custom>
|
||||
<fluidoSkin>
|
||||
<sourceLineNumbersEnabled>true</sourceLineNumbersEnabled>
|
||||
<leftColumnClass>span2</leftColumnClass>
|
||||
<bodyColumnClass>span10</bodyColumnClass>
|
||||
</fluidoSkin>
|
||||
</custom>
|
||||
</project>
|
75
to-port.md
Normal file
75
to-port.md
Normal file
@ -0,0 +1,75 @@
|
||||
In porting to Sponge, the goals for the plugin are to match Bukkit functionality where possible, as well as take into account user requests made
|
||||
|
||||
# Sponge-specific items
|
||||
|
||||
- How to incorporate data API? (block metadata values) -- check with all possible combinations?
|
||||
|
||||
# Requests
|
||||
|
||||
- Restrict anvil functionality (only enchant, not rename) #95
|
||||
- Don't drop restricted items (a dropper)
|
||||
- Mod compatibility -- don't restrict mod compatibility where possible?
|
||||
- Armor stands?
|
||||
- Taming horses?
|
||||
-
|
||||
|
||||
|
||||
# Other features
|
||||
|
||||
- Port over configuration
|
||||
- Customizable messages (keyed by permission)
|
||||
|
||||
# Entity name formatting
|
||||
|
||||
- Complex? get parent
|
||||
- Item? get permission for block
|
||||
- Player? `player.<name>`
|
||||
- Tameable? `animal.<name>[.<owner>]`
|
||||
|
||||
**Categories**: Player (Player.class), Item (Item.class), Animal (Animals.class, Squid.class), Monster (Monster.class, Slime.class, EnderDragon.class, Ghast.class), NPC (NPC.class), Projectile (Projectile.class)
|
||||
|
||||
# Permissions
|
||||
|
||||
**Default message**: Sorry, you don't have enough permissions
|
||||
**Message format**: `&f[&2Modifyworld&f]&4 %s`
|
||||
|
||||
Check | Permission (omitting `modifyworld.`) | Message | Commentary
|
||||
------------------- | ---------------------------------------- | ----------------------------- | ----------
|
||||
Break block/hanging | `blocks.destroy.<material>` | `&a$1&4 is too tough for you`
|
||||
Place block/hanging | `blocks.place.<material>` | `This is the wrong place for &a$1`
|
||||
Interact block | `blocks.interact.` | `You are too jelly for &2$1`
|
||||
Player deal damage | `damage.deal.<entity>` | `Your level is too low for &5$1`
|
||||
Player take damage | `damage.take.<entity>` | (none)
|
||||
Player enviro dmg | `damage.take.<cause>` | (none)
|
||||
Player tame entity | `tame.<entity>` | `This &a$1&4 is too ferocious`
|
||||
Ent. target player | `mobtarget.<targeter>` | (none)
|
||||
Sneak | `sneak` | (none) | Split out into on/off?
|
||||
Sprint | `sprint` | (none)
|
||||
Login/Whitelist | `login` | `You are not allowed to join this server. Goodbye!` (Log message as well)
|
||||
Enter bed | `usebeds` | `You can't sleep yet, there are monsters nearby`
|
||||
Empty bucket | `bucket.empty.<bucket-type>` | `You suddenly realized you still need &a$1`
|
||||
Fill bucket | `bucket.fill.<bucket-type>` | `This bucket is holey`
|
||||
Block PM (/tell) | `modifyworld.chat.private` | `Listener is deaf`
|
||||
Chat | `chat` | `Your mouth is too dry`
|
||||
Pick up item | `items.pickup.<item>` | (none)
|
||||
Drop item | `items.drop.<item>` | `This is indecent to scatter &a$1&4 around`
|
||||
Hold item | `items.hold.<item>` | `Beware, &a$1&4 is cursed!`
|
||||
Transfer items | `items.<put|take>.<item>.of.<inventory>` | (none)
|
||||
Use item on entity | `items.use.<item>.on.entity.<target>` | `Stop, &a$1&4 won't fit into &a$3`
|
||||
Interact (similar) | `interact.<target>` | (none)
|
||||
Right click/throw | `items.throw.<item>` | (none) | Potion (splash only), egg, snowball, expbottle
|
||||
Right click/spawn | `spawn.<entity-type>` | (none)
|
||||
Click on block | `items.use.<item>.on.block.<clicked>` | (none)
|
||||
Click on block | `blocks.interact.<clicked>` | `You are too jelly for &2$1`
|
||||
Enchant item | `items.enchant.<item>` |
|
||||
Craft item | `items.craft.<result>` | `Sorry. but &a$1&4 is too complicated`
|
||||
Change food level | `digestion` | (none) | Possible split ount into eating/deterioriation
|
||||
Dmg/destroy vehicle | `vehicle.destry.<vehicle>` | `This &a$1&4 is legal property of &bUnited States of America`
|
||||
Enter vehicle | `vehicle.enter.<vehicle>` | Boat: `You are too heavy for this &a$1` Minecart: `Sorry, but &a$1&4 is too small`
|
||||
Vehice collide w/ply| `vehicle.collide.<vehicle>` |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-
|
Loading…
Reference in New Issue
Block a user