mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-09 01:48:15 +01:00
[trunk] New /powertool command
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1112 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
parent
3f4df23144
commit
7d0e9a26b0
@ -164,6 +164,7 @@ public class Essentials extends JavaPlugin
|
||||
pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.High, this);
|
||||
pm.registerEvent(Type.PLAYER_EGG_THROW, playerListener, Priority.High, this);
|
||||
pm.registerEvent(Type.PLAYER_BUCKET_EMPTY, playerListener, Priority.High, this);
|
||||
pm.registerEvent(Type.PLAYER_ANIMATION, playerListener, Priority.High, this);
|
||||
|
||||
blockListener = new EssentialsBlockListener(this);
|
||||
pm.registerEvent(Type.SIGN_CHANGE, blockListener, Priority.Low, this);
|
||||
|
@ -2,13 +2,16 @@ package com.earth2me.essentials;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityListener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class EssentialsEntityListener extends EntityListener
|
||||
@ -25,6 +28,24 @@ public class EssentialsEntityListener extends EntityListener
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event)
|
||||
{
|
||||
if (event instanceof EntityDamageByEntityEvent)
|
||||
{
|
||||
EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event;
|
||||
Entity eAttack = edEvent.getDamager();
|
||||
Entity eDefend = edEvent.getEntity();
|
||||
if (eDefend instanceof Player && eAttack instanceof Player)
|
||||
{
|
||||
User defender = User.get(eDefend);
|
||||
User attacker = User.get(eAttack);
|
||||
ItemStack is = attacker.getItemInHand();
|
||||
String command = attacker.getPowertool(is);
|
||||
if (command != null && !command.isEmpty()) {
|
||||
attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event instanceof EntityDamageEvent || event instanceof EntityDamageByBlockEvent || event instanceof EntityDamageByProjectileEvent)
|
||||
{
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.server.InventoryPlayer;
|
||||
import org.bukkit.*;
|
||||
@ -429,4 +430,29 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerAnimation(PlayerAnimationEvent event) {
|
||||
usePowertools(event);
|
||||
}
|
||||
|
||||
private void usePowertools(PlayerAnimationEvent event) {
|
||||
if (event.getAnimationType() != PlayerAnimationType.ARM_SWING) {
|
||||
return;
|
||||
}
|
||||
User user = User.get(event.getPlayer());
|
||||
ItemStack is = user.getItemInHand();
|
||||
if (is.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
String command = user.getPowertool(is);
|
||||
if (command == null || command.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (command.matches(".*\\{player\\}.*")) {
|
||||
user.sendMessage("Click a player to use this command");
|
||||
return;
|
||||
}
|
||||
user.getServer().dispatchCommand(user, command);
|
||||
}
|
||||
}
|
||||
|
@ -722,4 +722,27 @@ public class User extends PlayerExtension implements Comparable<User>
|
||||
data.put("unlimited", items);
|
||||
flush();
|
||||
}
|
||||
|
||||
public String getPowertool(ItemStack stack) {
|
||||
if (!data.containsKey("powertools")) {
|
||||
return null;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Integer, String> tools = (Map<Integer, String>)data.get("powertools");
|
||||
return tools.get(stack.getTypeId());
|
||||
}
|
||||
|
||||
public void setPowertool(ItemStack stack, String command) {
|
||||
Map<Integer, String> tools = new HashMap<Integer, String>();
|
||||
if (data.containsKey("powertools")) {
|
||||
tools = (Map<Integer, String>)data.get("powertools");
|
||||
}
|
||||
if (command == null || command.trim().isEmpty()) {
|
||||
tools.remove(Integer.valueOf(stack.getTypeId()));
|
||||
return;
|
||||
}
|
||||
tools.put(Integer.valueOf(stack.getTypeId()), command.trim());
|
||||
data.put("powertools", tools);
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Commandpowertool extends EssentialsCommand {
|
||||
|
||||
public Commandpowertool() {
|
||||
super("powertool");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception {
|
||||
|
||||
ItemStack is = user.getItemInHand();
|
||||
if (is.getType() == Material.AIR) {
|
||||
user.sendMessage("Command can't be attached to air.");
|
||||
}
|
||||
String command = getFinalArg(args, 0);
|
||||
if (command != null && !command.isEmpty()) {
|
||||
user.sendMessage("Command assigned to "+is.getType().toString().toLowerCase().replaceAll("_", " "));
|
||||
} else {
|
||||
user.sendMessage("Command removed from "+is.getType().toString().toLowerCase().replaceAll("_", " "));
|
||||
}
|
||||
user.setPowertool(is, command);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -153,6 +153,9 @@ commands:
|
||||
plugin:
|
||||
description: Enables, disables, or reloads a plugin.
|
||||
usage: /<command> [enable|disable|reload] [plugin]
|
||||
powertool:
|
||||
description: Assigns a command to the item in hand, {player} will be replaced by the name of the player that you click.
|
||||
usage: /<command> [command] <arguments>
|
||||
r:
|
||||
description: Quickly reply to the last player to message you.
|
||||
usage: /<command> [message]
|
||||
|
Loading…
Reference in New Issue
Block a user