From aaa63a7f5dba2c4859af03de41a967be3f3edab5 Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 27 Mar 2012 15:57:37 -0400 Subject: [PATCH] Added McMMOPartyTeleportEvent for API usage - fires before a successful teleportation would occur. --- Changelog.txt | 1 + .../nossr50/commands/party/PtpCommand.java | 14 +++++-- .../events/party/McMMOPartyTeleportEvent.java | 37 +++++++++++++++++++ .../events/skills/McMMOPlayerSkillEvent.java | 8 +++- .../java/com/gmail/nossr50/party/Party.java | 2 +- 5 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/events/party/McMMOPartyTeleportEvent.java diff --git a/Changelog.txt b/Changelog.txt index 4e8e42520..cb114e7c4 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -11,6 +11,7 @@ Version 1.3.04-dev + Added McMMOPlayerRepairEvent for API usage - fires after completion of a repair. + Added McMMOPlayerRepairCheckEvent for API usage - fires before repair process begins, can be cancelled. + Added ability to get skill level from McMMOPlayerExperience events + + Added McMMOPartyTeleportEvent for API usage - fires before a successful teleportation would occur. = Fixed Shake ability dropping bonemeal instead of ink for squids. = Fixed Green Terra & Super Breaker awarding 4x drops at high levels. = Fixed summoned ocelots never changing skins. diff --git a/src/main/java/com/gmail/nossr50/commands/party/PtpCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PtpCommand.java index ac43dfc0c..e42ed863a 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PtpCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PtpCommand.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.commands.party; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -11,6 +12,7 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; +import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.party.Party; @@ -61,10 +63,16 @@ public class PtpCommand implements CommandExecutor { if (plugin.getServer().getPlayer(args[0]) != null) { Player target = plugin.getServer().getPlayer(args[0]); PlayerProfile PPt = Users.getProfile(target); + if (PP.getParty().equals(PPt.getParty())) { - player.teleport(target); - player.sendMessage(ChatColor.GREEN + "You have teleported to " + target.getName()); //TODO: Needs more locale. - target.sendMessage(ChatColor.GREEN + player.getName() + " has teleported to you."); //TODO: Needs more locale. + McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, PP.getParty()); + Bukkit.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + player.teleport(target); + player.sendMessage(ChatColor.GREEN + "You have teleported to " + target.getName()); //TODO: Needs more locale. + target.sendMessage(ChatColor.GREEN + player.getName() + " has teleported to you."); //TODO: Needs more locale. + } } else { player.sendMessage(ChatColor.RED + "That player is in a different party than you."); //TODO: Needs more locale. } diff --git a/src/main/java/com/gmail/nossr50/events/party/McMMOPartyTeleportEvent.java b/src/main/java/com/gmail/nossr50/events/party/McMMOPartyTeleportEvent.java new file mode 100644 index 000000000..9006609cf --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/party/McMMOPartyTeleportEvent.java @@ -0,0 +1,37 @@ +package com.gmail.nossr50.events.party; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerTeleportEvent; + +public class McMMOPartyTeleportEvent extends PlayerTeleportEvent{ + + private String party; + private Player target; + + public McMMOPartyTeleportEvent(Player player, Player target, String party) { + super(player, player.getLocation(), target.getLocation(), TeleportCause.COMMAND); + this.party = party; + this.target = target; + } + + public String getParty() { + return party; + } + + public Player getTarget() { + return target; + } + + /** Rest of file is required boilerplate for custom events **/ + private static final HandlerList handlers = new HandlerList(); + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerSkillEvent.java b/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerSkillEvent.java index 8415f5fb0..0d09407ac 100644 --- a/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerSkillEvent.java +++ b/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerSkillEvent.java @@ -21,14 +21,18 @@ public class McMMOPlayerSkillEvent extends PlayerEvent{ return skill; } + public int getSkillLevel() { + return skillLevel; + } + /** Rest of file is required boilerplate for custom events **/ private static final HandlerList handlers = new HandlerList(); - + @Override public HandlerList getHandlers() { return handlers; } - + public static HandlerList getHandlerList() { return handlers; } diff --git a/src/main/java/com/gmail/nossr50/party/Party.java b/src/main/java/com/gmail/nossr50/party/Party.java index f03a1cf00..d34b51d14 100644 --- a/src/main/java/com/gmail/nossr50/party/Party.java +++ b/src/main/java/com/gmail/nossr50/party/Party.java @@ -295,7 +295,7 @@ public class Party { savePartyLocks(); } - public void deleteParty(String partyName) { + private void deleteParty(String partyName) { this.partyPlayers.remove(partyName); this.partyLocks.remove(partyName); this.partyPasswords.remove(partyName);