mirror of
https://github.com/PEXPlugins/Modifyworld.git
synced 2025-01-02 18:07:59 +01:00
Initial commit
This commit is contained in:
commit
5d8a9c045f
21
src/main/java/ru/tehkode/modifyworld/EventHandler.java
Normal file
21
src/main/java/ru/tehkode/modifyworld/EventHandler.java
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package ru.tehkode.modifyworld;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author code
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface EventHandler {
|
||||
Event.Type value();
|
||||
}
|
125
src/main/java/ru/tehkode/modifyworld/ModifyworldListener.java
Normal file
125
src/main/java/ru/tehkode/modifyworld/ModifyworldListener.java
Normal file
@ -0,0 +1,125 @@
|
||||
package ru.tehkode.modifyworld;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.EventExecutor;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.util.config.ConfigurationNode;
|
||||
import ru.tehkode.permissions.PermissionManager;
|
||||
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author code
|
||||
*/
|
||||
public class ModifyworldListener implements Listener {
|
||||
|
||||
public final static String PERMISSION_DENIED = "Sorry, you don't have enough permissions";
|
||||
protected String permissionDenied = PERMISSION_DENIED;
|
||||
protected PermissionManager permissionsManager;
|
||||
protected ConfigurationNode config;
|
||||
protected boolean informPlayers = false;
|
||||
|
||||
public ModifyworldListener(Plugin plugin, ConfigurationNode config) {
|
||||
this.permissionsManager = PermissionsEx.getPermissionManager();
|
||||
this.config = config;
|
||||
|
||||
this.registerEvents(plugin);
|
||||
|
||||
this.informPlayers = config.getBoolean("informplayers", informPlayers);
|
||||
this.permissionDenied = config.getString("messages.permissionDenied", this.permissionDenied);
|
||||
}
|
||||
|
||||
protected void informPlayer(Player player, String message) {
|
||||
if (this.informPlayers) {
|
||||
player.sendMessage(ChatColor.RED + message);
|
||||
}
|
||||
}
|
||||
|
||||
protected void informPlayerAboutDenial(Player player) {
|
||||
this.informPlayer(player, this.permissionDenied);
|
||||
}
|
||||
|
||||
protected String getEntityName(Entity entity) {
|
||||
if (entity instanceof Player) {
|
||||
return "player." + ((Player) entity).getName();
|
||||
} else if (entity instanceof Wolf) {
|
||||
Wolf wolf = (Wolf) entity;
|
||||
|
||||
if (!wolf.isTamed()) {
|
||||
return "animal.wolf.untamed";
|
||||
} else if (wolf.getOwner() instanceof Player) {
|
||||
return "animal.wolf." + ((Player) wolf.getOwner()).getName();
|
||||
} else {
|
||||
return "animal.wolf";
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return entityName;
|
||||
}
|
||||
|
||||
protected boolean canInteractWithMaterial(Player player, String basePermission, Material type) {
|
||||
if (permissionsManager.has(player, basePermission + type.getId())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (permissionsManager.has(player, basePermission + type.name().toLowerCase().replace("_", ""))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void registerEvents(Plugin plugin) {
|
||||
PluginManager pluginManager = plugin.getServer().getPluginManager();
|
||||
for (Method method : this.getClass().getMethods()) {
|
||||
if (!method.isAnnotationPresent(EventHandler.class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
EventHandler handler = method.getAnnotation(EventHandler.class);
|
||||
|
||||
if (method.isAnnotationPresent(Toggleable.class)) {
|
||||
Toggleable toggle = method.getAnnotation(Toggleable.class);
|
||||
if (!config.getBoolean(toggle.value(), toggle.byDefault())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
pluginManager.registerEvent(handler.value(), this, this.getEventExecutor(method), Event.Priority.Normal, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
private EventExecutor getEventExecutor(final Method eventHandlerMethod) {
|
||||
return new EventExecutor() {
|
||||
|
||||
@Override
|
||||
public void execute(Listener listener, Event event) {
|
||||
try {
|
||||
eventHandlerMethod.invoke(listener, event);
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger("Minecraft").warning("[Modifyworld] Failed to execute Modifyworld event handler");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
21
src/main/java/ru/tehkode/modifyworld/Toggleable.java
Normal file
21
src/main/java/ru/tehkode/modifyworld/Toggleable.java
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package ru.tehkode.modifyworld;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author code
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Toggleable {
|
||||
String value();
|
||||
boolean byDefault() default false;
|
||||
}
|
99
src/main/java/ru/tehkode/modifyworld/bukkit/Modifyworld.java
Normal file
99
src/main/java/ru/tehkode/modifyworld/bukkit/Modifyworld.java
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package ru.tehkode.modifyworld.bukkit;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
import org.bukkit.util.config.ConfigurationNode;
|
||||
import ru.tehkode.modifyworld.ModifyworldListener;
|
||||
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 ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author code
|
||||
*/
|
||||
public class Modifyworld extends JavaPlugin {
|
||||
|
||||
protected final static Logger logger = Logger.getLogger("Minecraft");
|
||||
protected final static Class<? extends ModifyworldListener>[] LISTENERS = new Class[]{
|
||||
PlayerListener.class, EntityListener.class, BlockListener.class, VehicleListener.class
|
||||
};
|
||||
protected List<ModifyworldListener> listeners = new ArrayList<ModifyworldListener>();
|
||||
|
||||
public Modifyworld() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// At first check PEX existance
|
||||
try {
|
||||
PermissionsEx.getPermissionManager();
|
||||
} catch (Throwable e) {
|
||||
logger.severe("[Modifyworld] PermissionsEx not found, disabling");
|
||||
this.getPluginLoader().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
Configuration config = this.getConfiguration();
|
||||
|
||||
if (config.getProperty("enabled") == null) { // Migrate
|
||||
this.initializeConfiguration(config);
|
||||
}
|
||||
|
||||
|
||||
if (config.getBoolean("enable", false)) {
|
||||
logger.info("[Modifyworld] Modifyworld enabled!");
|
||||
this.registerListeners();
|
||||
}
|
||||
|
||||
config.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
logger.info("[Modifyworld] Modifyworld disabled!");
|
||||
}
|
||||
|
||||
protected void initializeConfiguration(Configuration config) {
|
||||
// At migrate and setup defaults
|
||||
PermissionsEx pex = (PermissionsEx) this.getServer().getPluginManager().getPlugin("PermissionsEx");
|
||||
|
||||
ru.tehkode.permissions.config.Configuration pexConfig = pex.getConfig();
|
||||
|
||||
// Flags
|
||||
config.setProperty("enable", pexConfig.getBoolean("permissions.modifyworld.enabled", false));
|
||||
config.setProperty("itemRestrictions", pexConfig.getBoolean("permissions.modifyworld.itemRestrictions", false));
|
||||
config.setProperty("informPlayers", pexConfig.getBoolean("permissions.informplayers.modifyworld", false));
|
||||
config.setProperty("whitelist", pexConfig.getBoolean("permissions.modifyworld.whitelist", false));
|
||||
|
||||
// Messages
|
||||
config.setProperty("message.whitelistMessage", pexConfig.getString("permissions.modifyworld.whitelistMessage", PlayerListener.WHITELIST_MESSAGE));
|
||||
config.setProperty("message.prohibitedItem", PlayerListener.PROHIBITED_ITEM);
|
||||
config.setProperty("message.permissionDenied", ModifyworldListener.PERMISSION_DENIED);
|
||||
|
||||
}
|
||||
|
||||
protected void registerListeners() {
|
||||
for (Class listenerClass : LISTENERS) {
|
||||
try {
|
||||
Constructor constructor = listenerClass.getConstructor(Plugin.class, ConfigurationNode.class);
|
||||
ModifyworldListener listener = (ModifyworldListener) constructor.newInstance(this, this.getConfiguration());
|
||||
this.listeners.add(listener);
|
||||
} catch (Throwable e) {
|
||||
logger.warning("[Modifyworld] Failed to initialize \"" + listenerClass.getName() + "\" listener");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* PermissionsEx - Permissions 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.ChatColor;
|
||||
import org.bukkit.event.Event.Type;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.config.ConfigurationNode;
|
||||
import ru.tehkode.modifyworld.EventHandler;
|
||||
import ru.tehkode.modifyworld.ModifyworldListener;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author t3hk0d3
|
||||
*/
|
||||
public class BlockListener extends ModifyworldListener {
|
||||
|
||||
public BlockListener(Plugin plugin, ConfigurationNode config) {
|
||||
super(plugin, config);
|
||||
}
|
||||
|
||||
@EventHandler(Type.BLOCK_BREAK)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.blocks.destroy.", event.getBlock().getType())) {
|
||||
informPlayerAboutDenial(event.getPlayer());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(Type.BLOCK_PLACE)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.blocks.place.", event.getBlock().getType())) {
|
||||
informPlayerAboutDenial(event.getPlayer());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* PermissionsEx - Permissions 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.ChatColor;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Type;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.config.ConfigurationNode;
|
||||
import ru.tehkode.modifyworld.EventHandler;
|
||||
import ru.tehkode.modifyworld.ModifyworldListener;
|
||||
import ru.tehkode.permissions.PermissionGroup;
|
||||
import ru.tehkode.permissions.PermissionUser;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author t3hk0d3
|
||||
*/
|
||||
public class EntityListener extends ModifyworldListener {
|
||||
|
||||
public EntityListener(Plugin plugin, ConfigurationNode config) {
|
||||
super(plugin, config);
|
||||
}
|
||||
|
||||
protected boolean canMessWithEntity(Player player, String basePermission, Entity entity) {
|
||||
if (entity instanceof Player) {
|
||||
PermissionUser entityUser = permissionsManager.getUser(((Player) entity).getName());
|
||||
|
||||
if (entityUser == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (PermissionGroup group : entityUser.getGroups()) {
|
||||
if (permissionsManager.has(player, basePermission + "group." + group.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return permissionsManager.has(player, basePermission + "player." + entityUser.getName());
|
||||
}
|
||||
|
||||
return permissionsManager.has(player, basePermission + getEntityName(entity));
|
||||
}
|
||||
|
||||
@EventHandler(Type.ENTITY_DAMAGE)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event instanceof EntityDamageByEntityEvent) { // player is damager
|
||||
EntityDamageByEntityEvent edbe = (EntityDamageByEntityEvent) event;
|
||||
if (!(edbe.getDamager() instanceof Player)) { // not caused by player
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) edbe.getDamager();
|
||||
if (!canMessWithEntity(player, "modifyworld.entity.damage.deal.", event.getEntity())) {
|
||||
informPlayerAboutDenial(player);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (event.getEntity() instanceof Player) { // player are been damaged by someone
|
||||
Player player = (Player) event.getEntity();
|
||||
if (!canMessWithEntity(player, "modifyworld.entity.damage.take.", event.getEntity())) {
|
||||
informPlayerAboutDenial(player);
|
||||
event.setCancelled(true);
|
||||
event.setDamage(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(Type.ENTITY_TARGET)
|
||||
public void onEntityTarget(EntityTargetEvent event) {
|
||||
if (event.getTarget() instanceof Player) {
|
||||
Player player = (Player) event.getTarget();
|
||||
if (!permissionsManager.has(player, "modifyworld.entity.mobtarget." + getEntityName(event.getEntity()))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,186 @@
|
||||
/*
|
||||
* PermissionsEx - Permissions 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.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Type;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.config.ConfigurationNode;
|
||||
import ru.tehkode.modifyworld.EventHandler;
|
||||
import ru.tehkode.modifyworld.ModifyworldListener;
|
||||
import ru.tehkode.modifyworld.Toggleable;
|
||||
import ru.tehkode.permissions.PermissionUser;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author code
|
||||
*/
|
||||
public class PlayerListener extends ModifyworldListener {
|
||||
|
||||
public final static String WHITELIST_MESSAGE = "You are not allowed to join this server. Goodbye!";
|
||||
public final static String PROHIBITED_ITEM = "You have prohibited item \"%s\".";
|
||||
|
||||
|
||||
protected boolean checkInventory = false;
|
||||
protected String whitelistKickMessage = WHITELIST_MESSAGE;
|
||||
protected String prohibitedItemMessage = PROHIBITED_ITEM;
|
||||
|
||||
public PlayerListener(Plugin plugin, ConfigurationNode config) {
|
||||
super(plugin, config);
|
||||
|
||||
this.whitelistKickMessage = config.getString("messages.whitelist", this.whitelistKickMessage);
|
||||
this.prohibitedItemMessage = config.getString("messages.prohibitedItem", this.prohibitedItemMessage);
|
||||
this.checkInventory = config.getBoolean("itemRestrictions", this.checkInventory);
|
||||
}
|
||||
|
||||
@EventHandler(Type.PLAYER_PRELOGIN)
|
||||
@Toggleable("whitelist")
|
||||
public void onPlayerPreLogin(PlayerPreLoginEvent event) {
|
||||
PermissionUser user = this.permissionsManager.getUser(event.getName());
|
||||
|
||||
if (user != null && !user.has("modifyworld.login", Bukkit.getServer().getWorlds().get(0).getName())) {
|
||||
event.disallow(PlayerPreLoginEvent.Result.KICK_WHITELIST, whitelistKickMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(Type.PLAYER_LOGIN)
|
||||
@Toggleable("whitelist")
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
PermissionUser user = this.permissionsManager.getUser(event.getPlayer());
|
||||
|
||||
if (user != null && !user.has("modifyworld.login", Bukkit.getServer().getWorlds().get(0).getName())) {
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, whitelistKickMessage);
|
||||
event.getPlayer().kickPlayer(whitelistKickMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(Type.PLAYER_BED_ENTER)
|
||||
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
|
||||
if (!permissionsManager.has(event.getPlayer(), "modifyworld.usebeds")) {
|
||||
informPlayer(event.getPlayer(), ChatColor.RED + "Sorry, you don't have enough permissions");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(Type.PLAYER_BUCKET_EMPTY)
|
||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
String bucketName = event.getBucket().toString().toLowerCase().replace("_bucket", ""); // WATER_BUCKET -> water
|
||||
if (!permissionsManager.has(event.getPlayer(), "modifyworld.bucket.empty." + bucketName)) {
|
||||
informPlayerAboutDenial(event.getPlayer());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(Type.PLAYER_BUCKET_FILL)
|
||||
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
||||
String materialName = event.getBlockClicked().getType().toString().toLowerCase().replace("stationary_", ""); // STATIONARY_WATER -> water
|
||||
if (!permissionsManager.has(event.getPlayer(), "modifyworld.bucket.fill." + materialName)) {
|
||||
informPlayerAboutDenial(event.getPlayer());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(Type.PLAYER_COMMAND_PREPROCESS)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if (event.getMessage().startsWith("/tell") && !permissionsManager.has(event.getPlayer(), "modifyworld.chat.private")) {
|
||||
informPlayerAboutDenial(event.getPlayer());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(Type.PLAYER_CHAT)
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
if (!permissionsManager.has(event.getPlayer(), "modifyworld.chat")) {
|
||||
informPlayerAboutDenial(event.getPlayer());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(Type.PLAYER_PICKUP_ITEM)
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.items.pickup.", event.getItem().getItemStack().getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
this.checkPlayerInventory(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(Type.PLAYER_DROP_ITEM)
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.items.drop.", event.getItemDrop().getItemStack().getType())) {
|
||||
informPlayerAboutDenial(event.getPlayer());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
this.checkPlayerInventory(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(Type.PLAYER_INVENTORY)
|
||||
public void onInventoryOpen(PlayerInventoryEvent event) {
|
||||
this.checkPlayerInventory(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(Type.PLAYER_ITEM_HELD)
|
||||
public void onItemHeldChange(PlayerItemHeldEvent event) {
|
||||
this.checkPlayerInventory(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(Type.PLAYER_INTERACT_ENTITY)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (!permissionsManager.has(event.getPlayer(), "modifyworld.entity.interact." + getEntityName(event.getRightClicked()))) {
|
||||
event.setCancelled(true);
|
||||
informPlayerAboutDenial(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(Type.PLAYER_INTERACT)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Action action = event.getAction();
|
||||
if (action != Action.LEFT_CLICK_BLOCK && action != Action.RIGHT_CLICK_BLOCK) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.blocks.interact.", event.getClickedBlock().getType())) {
|
||||
informPlayerAboutDenial(event.getPlayer());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkPlayerInventory(Player player) {
|
||||
if (!checkInventory) {
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory inventory = player.getInventory();
|
||||
for (ItemStack stack : inventory.getContents()) {
|
||||
if (stack != null && !permissionsManager.has(player, "modifyworld.items.have." + stack.getTypeId())) {
|
||||
inventory.remove(stack);
|
||||
informPlayer(player, String.format(this.prohibitedItemMessage, stack.getType().name()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* PermissionsEx - Permissions 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.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Type;
|
||||
import org.bukkit.event.vehicle.VehicleDamageEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEntityCollisionEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.config.ConfigurationNode;
|
||||
import ru.tehkode.modifyworld.EventHandler;
|
||||
import ru.tehkode.modifyworld.ModifyworldListener;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author t3hk0d3
|
||||
*/
|
||||
public class VehicleListener extends ModifyworldListener {
|
||||
|
||||
public VehicleListener(Plugin plugin, ConfigurationNode config) {
|
||||
super(plugin, config);
|
||||
}
|
||||
|
||||
@EventHandler(Type.VEHICLE_DESTROY)
|
||||
public void onVehicleDamage(VehicleDamageEvent event) {
|
||||
if (!(event.getAttacker() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getAttacker();
|
||||
if (!permissionsManager.has(player, "modifyworld.vehicle.destroy")) {
|
||||
informPlayerAboutDenial(player);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(Type.VEHICLE_ENTER)
|
||||
public void onVehicleEnter(VehicleEnterEvent event) {
|
||||
if (!(event.getEntered() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntered();
|
||||
if (!permissionsManager.has(player, "modifyworld.vehicle.enter")) {
|
||||
informPlayerAboutDenial(player);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(Type.VEHICLE_COLLISION_ENTITY)
|
||||
public void onVehicleEntityCollision(VehicleEntityCollisionEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
if (!permissionsManager.has(player, "modifyworld.vehicle.collide")) {
|
||||
event.setCancelled(true);
|
||||
event.setCollisionCancelled(true);
|
||||
event.setPickupCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
7
src/main/resources/plugin.yml
Normal file
7
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,7 @@
|
||||
name: Modifyworld
|
||||
main: ru.tehkode.modifyworld.bukkit.Modifyworld
|
||||
depend: [ PermissionsEx ]
|
||||
version: 1.13
|
||||
author: t3hk0d3
|
||||
website: www.bukkit.org
|
||||
description: World modification permission ruleset
|
Loading…
Reference in New Issue
Block a user