mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
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:
parent
85fe839e91
commit
5863efbdd8
2
pom.xml
2
pom.xml
@ -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>
|
||||
|
@ -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
|
||||
@ -111,7 +114,8 @@ public class mcBlockListener extends BlockListener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
@ -274,7 +278,8 @@ 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();
|
||||
|
@ -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,14 +44,15 @@ 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;
|
||||
|
||||
public mcEntityListener(final mcMMO plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onEntityDamage(EntityDamageEvent event)
|
||||
{
|
||||
if(event.isCancelled())
|
||||
@ -158,7 +161,8 @@ public class mcEntityListener extends EntityListener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDeath(EntityDeathEvent event)
|
||||
{
|
||||
Entity x = event.getEntity();
|
||||
@ -180,7 +184,8 @@ public class mcEntityListener extends EntityListener
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event)
|
||||
{
|
||||
SpawnReason reason = event.getSpawnReason();
|
||||
|
@ -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;
|
||||
@ -74,7 +76,8 @@ public class mcPlayerListener extends PlayerListener
|
||||
{
|
||||
plugin = instance;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerFish(PlayerFishEvent event)
|
||||
{
|
||||
if(mcPermissions.getInstance().fishing(event.getPlayer()))
|
||||
@ -94,15 +97,17 @@ public class mcPlayerListener extends PlayerListener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event)
|
||||
{
|
||||
if(Users.getProfile(event.getPlayer()).getBerserkMode())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
@ -333,14 +343,17 @@ 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)));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -139,28 +137,11 @@ public class mcMMO extends JavaPlugin
|
||||
LoadProperties.spoutEnabled = true;
|
||||
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());
|
||||
|
Loading…
Reference in New Issue
Block a user