Use Vault to get message options, bump to 1.19.7-SNAPSHOT

This commit is contained in:
zml 2013-08-31 13:19:20 -07:00
parent 0bfc70e98a
commit 86b6d12c01
3 changed files with 82 additions and 35 deletions

15
pom.xml
View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ru.tehkode</groupId>
<artifactId>Modifyworld</artifactId>
<version>1.19.6</version>
<version>1.19.7-SNAPSHOT</version>
<name>Modifyworld</name>
<url>https://github.com/t3hk0d3/Modifyworld</url>
<issueManagement>
@ -67,7 +67,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.4.7-R1.0</version>
<version>1.6.2-R0.1</version>
<type>jar</type>
</dependency>
<dependency>
@ -75,12 +75,21 @@
<artifactId>PermissionsEx</artifactId>
<version>1.19.6</version>
</dependency>
<dependency>
<groupId>net.milkbowl</groupId>
<artifactId>vault</artifactId>
<version>1.2.27</version>
</dependency>
</dependencies>
<repositories>
<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>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -1,5 +1,7 @@
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;
@ -37,9 +39,7 @@ public class PlayerInformer {
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);
@ -79,41 +79,79 @@ public class PlayerInformer {
}
public String getMessage(Player player, String permission) {
boolean permissionsExExists = true;
try {
Class permissionsExClass = Class.forName("ru.tehkode.permissions.bukkit.PermissionsEx");
} catch (ClassNotFoundException e) {
permissionsExExists = false;
String message = null;
if (Bukkit.getServer().getPluginManager().isPluginEnabled("Vault")) {
message = getMessageVault(player, permission);
}
if (permissionsExExists) {
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;
}
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;

View File

@ -1,6 +1,6 @@
name: Modifyworld
main: ru.tehkode.modifyworld.bukkit.Modifyworld
soft-depend: [ PermissionsEx ]
soft-depend: [ PermissionsEx, Vault ]
version: "${project.version}"
author: t3hk0d3
website: www.bukkit.org