Events + Alias (not really fix) fix

Changed Bukkit events to new event system
Changed aliasing to send both the mcmmo command and the command used.
This commit is contained in:
NuclearW 2012-01-26 18:42:46 -05:00
parent 85fe839e91
commit 5863efbdd8
5 changed files with 52 additions and 47 deletions

View File

@ -134,7 +134,7 @@
</dependency>
<dependency>
<groupId>org.getspout</groupId>
<artifactId>spoutplugin</artifactId>
<artifactId>spoutpluginapi</artifactId>
<version>dev-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>

View File

@ -29,10 +29,12 @@ import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.SpoutManager;
@ -44,7 +46,7 @@ import com.gmail.nossr50.skills.*;
import com.gmail.nossr50.datatypes.FakeBlockBreakEvent;
public class mcBlockListener extends BlockListener
public class mcBlockListener implements Listener
{
private final mcMMO plugin;
@ -53,6 +55,7 @@ public class mcBlockListener extends BlockListener
this.plugin = plugin;
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event)
{
//Setup some basic vars
@ -112,6 +115,7 @@ public class mcBlockListener extends BlockListener
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event)
{
Player player = event.getPlayer();
@ -275,6 +279,7 @@ public class mcBlockListener extends BlockListener
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockDamage(BlockDamageEvent event)
{
if(event.isCancelled())
@ -439,6 +444,7 @@ public class mcBlockListener extends BlockListener
}
}
@EventHandler
public void onBlockFromTo(BlockFromToEvent event)
{
Block blockFrom = event.getBlock();

View File

@ -20,13 +20,15 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.Combat;
@ -42,7 +44,7 @@ import com.gmail.nossr50.skills.Skills;
import com.gmail.nossr50.skills.Taming;
public class mcEntityListener extends EntityListener
public class mcEntityListener implements Listener
{
private final mcMMO plugin;
@ -50,6 +52,7 @@ public class mcEntityListener extends EntityListener
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDamage(EntityDamageEvent event)
{
if(event.isCancelled())
@ -159,6 +162,7 @@ public class mcEntityListener extends EntityListener
}
}
@EventHandler
public void onEntityDeath(EntityDeathEvent event)
{
Entity x = event.getEntity();
@ -181,6 +185,7 @@ public class mcEntityListener extends EntityListener
}
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event)
{
SpawnReason reason = event.getSpawnReason();

View File

@ -32,6 +32,9 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
@ -39,7 +42,6 @@ import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerFishEvent.State;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@ -64,7 +66,7 @@ import com.gmail.nossr50.skills.Repair;
import com.gmail.nossr50.skills.Skills;
public class mcPlayerListener extends PlayerListener
public class mcPlayerListener implements Listener
{
protected static final Logger log = Logger.getLogger("Minecraft"); //$NON-NLS-1$
public Location spawn = null;
@ -75,6 +77,7 @@ public class mcPlayerListener extends PlayerListener
plugin = instance;
}
@EventHandler
public void onPlayerFish(PlayerFishEvent event)
{
if(mcPermissions.getInstance().fishing(event.getPlayer()))
@ -95,14 +98,16 @@ public class mcPlayerListener extends PlayerListener
}
}
public void onPlayerPickupItem(PlayerPickupItemEvent event)
{
if(Users.getProfile(event.getPlayer()).getBerserkMode())
{
@EventHandler
public void onPlayerPickupItem(PlayerPickupItemEvent event)
{
if(Users.getProfile(event.getPlayer()).getBerserkMode())
{
event.setCancelled(true);
}
}
}
}
@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event)
{
@ -126,11 +131,13 @@ public class mcPlayerListener extends PlayerListener
}
}
@EventHandler
public void onPlayerLogin(PlayerLoginEvent event)
{
Users.addUser(event.getPlayer());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
@ -151,6 +158,7 @@ public class mcPlayerListener extends PlayerListener
Users.removeUser(event.getPlayer());
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
Player player = event.getPlayer();
@ -164,6 +172,7 @@ public class mcPlayerListener extends PlayerListener
player.sendMessage(ChatColor.GOLD+"mcMMO is currently in an XP rate event! XP rate is "+LoadProperties.xpGainMultiplier+"x!");
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerInteract(PlayerInteractEvent event)
{
Player player = event.getPlayer();
@ -298,6 +307,7 @@ public class mcPlayerListener extends PlayerListener
}
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerChat(PlayerChatEvent event)
{
Player player = event.getPlayer();
@ -334,13 +344,16 @@ public class mcPlayerListener extends PlayerListener
}
}
// Dynamically aliasing commands need to be re-done.
// For now, using a command with an alias will send both the original command, and the mcMMO command
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
String message = event.getMessage();
if(!message.startsWith("/")) return;
String command = message.substring(1).split(" ")[0];
if(plugin.aliasMap.containsKey(command)) {
if(command.equalsIgnoreCase(plugin.aliasMap.get(command))) return;
event.setCancelled(true);
//event.setCancelled(true);
event.getPlayer().chat(message.replaceFirst(command, plugin.aliasMap.get(command)));
}
}

View File

@ -49,8 +49,6 @@ import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.PluginManager;
@ -140,27 +138,10 @@ public class mcMMO extends JavaPlugin
else
LoadProperties.spoutEnabled = false;
//Player Stuff
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Lowest, this);
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_FISH, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Lowest, this);
//Block Stuff
pm.registerEvent(Event.Type.BLOCK_DAMAGE, blockListener, Priority.Highest, this);
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.BLOCK_FROMTO, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Normal, this);
//Entity Stuff
pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.Normal, this);
//Register events
pm.registerEvents(playerListener, this);
pm.registerEvents(blockListener, this);
pm.registerEvents(entityListener, this);
PluginDescriptionFile pdfFile = this.getDescription();
mcPermissions.initialize(getServer());