mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 07:06:45 +01:00
Added McMMOPartyChangeEvent for API usage - fires whenever a player
joins or leaves a party
This commit is contained in:
parent
aaa63a7f5d
commit
fd6610f966
@ -12,6 +12,7 @@ Version 1.3.04-dev
|
||||
+ 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.
|
||||
+ Added McMMOPartyChangeEvent for API usage - fires whenever a player joins or leaves a party
|
||||
= 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.
|
||||
|
@ -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;
|
||||
@ -9,6 +10,8 @@ import org.bukkit.entity.Player;
|
||||
import com.gmail.nossr50.Users;
|
||||
import com.gmail.nossr50.mcPermissions;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
|
||||
import com.gmail.nossr50.locale.mcLocale;
|
||||
import com.gmail.nossr50.party.Party;
|
||||
|
||||
@ -33,10 +36,25 @@ public class AcceptCommand implements CommandExecutor {
|
||||
Party Pinstance = Party.getInstance();
|
||||
|
||||
if (PP.inParty()) {
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, PP.getParty(), PP.getInvite(), EventReason.CHANGED_PARTIES);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Pinstance.removeFromParty(player, PP);
|
||||
}
|
||||
PP.acceptInvite();
|
||||
Pinstance.addToParty(player, PP, PP.getParty(), true);
|
||||
else {
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, PP.getInvite(), EventReason.JOINED_PARTY);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
PP.acceptInvite();
|
||||
Pinstance.addToParty(player, PP, PP.getParty(), true);
|
||||
|
||||
} else {
|
||||
player.sendMessage(mcLocale.getString("mcPlayerListener.NoInvites"));
|
||||
|
@ -10,6 +10,8 @@ import org.bukkit.entity.Player;
|
||||
import com.gmail.nossr50.Users;
|
||||
import com.gmail.nossr50.mcPermissions;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
|
||||
import com.gmail.nossr50.locale.mcLocale;
|
||||
import com.gmail.nossr50.party.Party;
|
||||
|
||||
@ -109,10 +111,18 @@ public class PartyCommand implements CommandExecutor {
|
||||
return true;
|
||||
} else if (args.length == 1) {
|
||||
if (args[0].equals("q") && PP.inParty()) {
|
||||
Pinstance.removeFromParty(player, PP);
|
||||
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, PP.getParty(), null, EventReason.LEFT_PARTY);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Pinstance.removeFromParty(player, PP);
|
||||
player.sendMessage(mcLocale.getString("mcPlayerListener.LeftParty"));
|
||||
return true;
|
||||
|
||||
} else if (args[0].equalsIgnoreCase("?")) {
|
||||
player.sendMessage(mcLocale.getString("Party.Help4", new Object[] { "/party " }));
|
||||
player.sendMessage(mcLocale.getString("Party.Help2", new Object[] { "/party " }));
|
||||
@ -148,8 +158,23 @@ public class PartyCommand implements CommandExecutor {
|
||||
// Pinstance.dump(player);
|
||||
} else {
|
||||
if (PP.inParty()) {
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, PP.getParty(), args[0], EventReason.CHANGED_PARTIES);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Pinstance.removeFromParty(player, PP);
|
||||
}
|
||||
else {
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, args[0], EventReason.JOINED_PARTY);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Pinstance.addToParty(player, PP, args[0], false);
|
||||
return true;
|
||||
}
|
||||
@ -186,6 +211,13 @@ public class PartyCommand implements CommandExecutor {
|
||||
}
|
||||
PlayerProfile tPP = Users.getProfile(tPlayer);
|
||||
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, tPP.getParty(), null, EventReason.KICKED_FROM_PARTY);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Pinstance.removeFromParty(tPlayer, tPP);
|
||||
|
||||
tPlayer.sendMessage(mcLocale.getString("mcPlayerListener.LeftParty"));
|
||||
@ -213,10 +245,22 @@ public class PartyCommand implements CommandExecutor {
|
||||
player.sendMessage(mcLocale.getString("Party.NotOwner"));
|
||||
}
|
||||
} else {
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, PP.getParty(), args[0], EventReason.CHANGED_PARTIES);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
Pinstance.removeFromParty(player, PP);
|
||||
Pinstance.addToParty(player, PP, args[0], false, args[1]);
|
||||
}
|
||||
} else if (args.length == 2 && !PP.inParty()) {
|
||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, args[0], EventReason.JOINED_PARTY);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
Pinstance.addToParty(player, PP, args[0], false, args[1]);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,65 @@
|
||||
package com.gmail.nossr50.events.party;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
public class McMMOPartyChangeEvent extends PlayerEvent implements Cancellable{
|
||||
|
||||
protected String oldParty;
|
||||
protected String newParty;
|
||||
protected EventReason reason;
|
||||
protected boolean cancelled;
|
||||
|
||||
public McMMOPartyChangeEvent(Player player, String oldParty, String newParty, EventReason reason) {
|
||||
super(player);
|
||||
newParty = newParty.replace(":", ".");
|
||||
this.oldParty = oldParty;
|
||||
this.newParty = newParty;
|
||||
this.reason = reason;
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
public String getOldParty() {
|
||||
return oldParty;
|
||||
}
|
||||
|
||||
public String getNewParty() {
|
||||
return newParty;
|
||||
}
|
||||
|
||||
public EventReason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
/** 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;
|
||||
}
|
||||
|
||||
/** Following are required for Cancellable **/
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public enum EventReason{
|
||||
JOINED_PARTY,
|
||||
LEFT_PARTY,
|
||||
KICKED_FROM_PARTY,
|
||||
CHANGED_PARTIES;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user