mirror of
https://github.com/PEXPlugins/Modifyworld.git
synced 2024-11-15 10:25:22 +01:00
Fixed new entities classification. issue PermissionsEx/#182
This commit is contained in:
parent
913ab76139
commit
822ee7b152
74
src/main/java/ru/tehkode/modifyworld/EntityCategory.java
Normal file
74
src/main/java/ru/tehkode/modifyworld/EntityCategory.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* 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),
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -85,35 +85,14 @@ public abstract class ModifyworldListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fixtures for Bukkit dev lazyness
|
String entityName = entity.toString().substring(5).toLowerCase();
|
||||||
if (entity instanceof Ghast) {
|
EntityCategory category = EntityCategory.fromEntity(entity);
|
||||||
return "monster.ghast";
|
|
||||||
|
if (category == null) {
|
||||||
|
return entityName; // category unknown (ender crystal)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity instanceof Squid) {
|
return category.getNameDot() + entityName;
|
||||||
return "animal.squid";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof Slime) {
|
|
||||||
return "monster.slime";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
String entityName = entity.getClass().getSimpleName();
|
|
||||||
|
|
||||||
if (entityName.startsWith("Craft")) {
|
|
||||||
entityName = entityName.substring(5).toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Monster.class.isAssignableFrom(entity.getClass())) {
|
|
||||||
entityName = "monster." + entityName;
|
|
||||||
} else if (Animals.class.isAssignableFrom(entity.getClass())) {
|
|
||||||
entityName = "animal." + entityName;
|
|
||||||
} else if (Projectile.class.isAssignableFrom(entity.getClass())) {
|
|
||||||
entityName = "projectile." + entityName;
|
|
||||||
}
|
|
||||||
|
|
||||||
return entityName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Functional programming fuck yeah
|
// Functional programming fuck yeah
|
||||||
@ -143,8 +122,11 @@ public abstract class ModifyworldListener implements Listener {
|
|||||||
|
|
||||||
private void registerEvents(Plugin plugin) {
|
private void registerEvents(Plugin plugin) {
|
||||||
PluginManager pluginManager = plugin.getServer().getPluginManager();
|
PluginManager pluginManager = plugin.getServer().getPluginManager();
|
||||||
|
|
||||||
|
|
||||||
for (Method method : this.getClass().getMethods()) {
|
for (Method method : this.getClass().getMethods()) {
|
||||||
if (!method.isAnnotationPresent(EventHandler.class)) {
|
if (!method.isAnnotationPresent(EventHandler.class)) {
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,6 +134,7 @@ public abstract class ModifyworldListener implements Listener {
|
|||||||
|
|
||||||
if (method.isAnnotationPresent(Toggleable.class)) {
|
if (method.isAnnotationPresent(Toggleable.class)) {
|
||||||
Toggleable toggle = method.getAnnotation(Toggleable.class);
|
Toggleable toggle = method.getAnnotation(Toggleable.class);
|
||||||
|
|
||||||
if (!config.getBoolean(toggle.value(), toggle.byDefault())) {
|
if (!config.getBoolean(toggle.value(), toggle.byDefault())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user