mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16: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>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.getspout</groupId>
|
<groupId>org.getspout</groupId>
|
||||||
<artifactId>spoutplugin</artifactId>
|
<artifactId>spoutpluginapi</artifactId>
|
||||||
<version>dev-SNAPSHOT</version>
|
<version>dev-SNAPSHOT</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
|
@ -29,10 +29,12 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.Statistic;
|
import org.bukkit.Statistic;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
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.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockDamageEvent;
|
import org.bukkit.event.block.BlockDamageEvent;
|
||||||
import org.bukkit.event.block.BlockFromToEvent;
|
import org.bukkit.event.block.BlockFromToEvent;
|
||||||
import org.bukkit.event.block.BlockListener;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.getspout.spoutapi.SpoutManager;
|
import org.getspout.spoutapi.SpoutManager;
|
||||||
@ -44,7 +46,7 @@ import com.gmail.nossr50.skills.*;
|
|||||||
import com.gmail.nossr50.datatypes.FakeBlockBreakEvent;
|
import com.gmail.nossr50.datatypes.FakeBlockBreakEvent;
|
||||||
|
|
||||||
|
|
||||||
public class mcBlockListener extends BlockListener
|
public class mcBlockListener implements Listener
|
||||||
{
|
{
|
||||||
private final mcMMO plugin;
|
private final mcMMO plugin;
|
||||||
|
|
||||||
@ -53,6 +55,7 @@ public class mcBlockListener extends BlockListener
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
public void onBlockPlace(BlockPlaceEvent event)
|
public void onBlockPlace(BlockPlaceEvent event)
|
||||||
{
|
{
|
||||||
//Setup some basic vars
|
//Setup some basic vars
|
||||||
@ -111,7 +114,8 @@ public class mcBlockListener extends BlockListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onBlockBreak(BlockBreakEvent event)
|
public void onBlockBreak(BlockBreakEvent event)
|
||||||
{
|
{
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
@ -274,7 +278,8 @@ public class mcBlockListener extends BlockListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onBlockDamage(BlockDamageEvent event)
|
public void onBlockDamage(BlockDamageEvent event)
|
||||||
{
|
{
|
||||||
if(event.isCancelled())
|
if(event.isCancelled())
|
||||||
@ -439,6 +444,7 @@ public class mcBlockListener extends BlockListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
public void onBlockFromTo(BlockFromToEvent event)
|
public void onBlockFromTo(BlockFromToEvent event)
|
||||||
{
|
{
|
||||||
Block blockFrom = event.getBlock();
|
Block blockFrom = event.getBlock();
|
||||||
|
@ -20,13 +20,15 @@ import org.bukkit.entity.Entity;
|
|||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Wolf;
|
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;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
import org.bukkit.event.entity.EntityListener;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import com.gmail.nossr50.Combat;
|
import com.gmail.nossr50.Combat;
|
||||||
@ -42,14 +44,15 @@ import com.gmail.nossr50.skills.Skills;
|
|||||||
import com.gmail.nossr50.skills.Taming;
|
import com.gmail.nossr50.skills.Taming;
|
||||||
|
|
||||||
|
|
||||||
public class mcEntityListener extends EntityListener
|
public class mcEntityListener implements Listener
|
||||||
{
|
{
|
||||||
private final mcMMO plugin;
|
private final mcMMO plugin;
|
||||||
|
|
||||||
public mcEntityListener(final mcMMO plugin) {
|
public mcEntityListener(final mcMMO plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onEntityDamage(EntityDamageEvent event)
|
public void onEntityDamage(EntityDamageEvent event)
|
||||||
{
|
{
|
||||||
if(event.isCancelled())
|
if(event.isCancelled())
|
||||||
@ -158,7 +161,8 @@ public class mcEntityListener extends EntityListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
public void onEntityDeath(EntityDeathEvent event)
|
public void onEntityDeath(EntityDeathEvent event)
|
||||||
{
|
{
|
||||||
Entity x = event.getEntity();
|
Entity x = event.getEntity();
|
||||||
@ -180,7 +184,8 @@ public class mcEntityListener extends EntityListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
public void onCreatureSpawn(CreatureSpawnEvent event)
|
public void onCreatureSpawn(CreatureSpawnEvent event)
|
||||||
{
|
{
|
||||||
SpawnReason reason = event.getSpawnReason();
|
SpawnReason reason = event.getSpawnReason();
|
||||||
|
@ -32,6 +32,9 @@ import org.bukkit.entity.Entity;
|
|||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Wolf;
|
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.block.Action;
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
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.PlayerFishEvent.State;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerListener;
|
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
@ -64,7 +66,7 @@ import com.gmail.nossr50.skills.Repair;
|
|||||||
import com.gmail.nossr50.skills.Skills;
|
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$
|
protected static final Logger log = Logger.getLogger("Minecraft"); //$NON-NLS-1$
|
||||||
public Location spawn = null;
|
public Location spawn = null;
|
||||||
@ -74,7 +76,8 @@ public class mcPlayerListener extends PlayerListener
|
|||||||
{
|
{
|
||||||
plugin = instance;
|
plugin = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
public void onPlayerFish(PlayerFishEvent event)
|
public void onPlayerFish(PlayerFishEvent event)
|
||||||
{
|
{
|
||||||
if(mcPermissions.getInstance().fishing(event.getPlayer()))
|
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)
|
public void onPlayerRespawn(PlayerRespawnEvent event)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -126,11 +131,13 @@ public class mcPlayerListener extends PlayerListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
public void onPlayerLogin(PlayerLoginEvent event)
|
public void onPlayerLogin(PlayerLoginEvent event)
|
||||||
{
|
{
|
||||||
Users.addUser(event.getPlayer());
|
Users.addUser(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event)
|
public void onPlayerQuit(PlayerQuitEvent event)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -151,6 +158,7 @@ public class mcPlayerListener extends PlayerListener
|
|||||||
Users.removeUser(event.getPlayer());
|
Users.removeUser(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
{
|
{
|
||||||
Player player = event.getPlayer();
|
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!");
|
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)
|
public void onPlayerInteract(PlayerInteractEvent event)
|
||||||
{
|
{
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
@ -298,6 +307,7 @@ public class mcPlayerListener extends PlayerListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlayerChat(PlayerChatEvent event)
|
public void onPlayerChat(PlayerChatEvent event)
|
||||||
{
|
{
|
||||||
Player player = event.getPlayer();
|
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) {
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||||
String message = event.getMessage();
|
String message = event.getMessage();
|
||||||
if(!message.startsWith("/")) return;
|
if(!message.startsWith("/")) return;
|
||||||
String command = message.substring(1).split(" ")[0];
|
String command = message.substring(1).split(" ")[0];
|
||||||
if(plugin.aliasMap.containsKey(command)) {
|
if(plugin.aliasMap.containsKey(command)) {
|
||||||
if(command.equalsIgnoreCase(plugin.aliasMap.get(command))) return;
|
if(command.equalsIgnoreCase(plugin.aliasMap.get(command))) return;
|
||||||
event.setCancelled(true);
|
//event.setCancelled(true);
|
||||||
event.getPlayer().chat(message.replaceFirst(command, plugin.aliasMap.get(command)));
|
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.Level;
|
||||||
import java.util.logging.Logger;
|
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.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
@ -139,28 +137,11 @@ public class mcMMO extends JavaPlugin
|
|||||||
LoadProperties.spoutEnabled = true;
|
LoadProperties.spoutEnabled = true;
|
||||||
else
|
else
|
||||||
LoadProperties.spoutEnabled = false;
|
LoadProperties.spoutEnabled = false;
|
||||||
|
|
||||||
//Player Stuff
|
//Register events
|
||||||
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
|
pm.registerEvents(playerListener, this);
|
||||||
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
|
pm.registerEvents(blockListener, this);
|
||||||
pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this);
|
pm.registerEvents(entityListener, 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);
|
|
||||||
|
|
||||||
PluginDescriptionFile pdfFile = this.getDescription();
|
PluginDescriptionFile pdfFile = this.getDescription();
|
||||||
mcPermissions.initialize(getServer());
|
mcPermissions.initialize(getServer());
|
||||||
|
Loading…
Reference in New Issue
Block a user