Various sender reference improvements. Fixes MassiveCraft/Factions#726.

This commit is contained in:
Olof Larsson 2014-12-10 10:27:56 +01:00
parent 3d93d07c99
commit 6ab443c8b7
2 changed files with 25 additions and 1 deletions

View File

@ -471,6 +471,20 @@ public class EngineMain extends EngineAbstract
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onChunksChange(EventFactionsChunksChange event)
{
// For security reasons we block the chunk change on any error since an error might block security checks from happening.
try
{
onChunksChangeInner(event);
}
catch (Throwable throwable)
{
event.setCancelled(true);
throwable.printStackTrace();
}
}
public void onChunksChangeInner(EventFactionsChunksChange event)
{
// Args
final MPlayer msender = event.getMSender();

View File

@ -7,6 +7,7 @@ import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.factions.EconomyParticipator;
@ -830,7 +831,16 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
// Event
// NOTE: We listen to this event ourselves at LOW.
// NOTE: That is where we apply the standard checks.
EventFactionsChunksChange event = new EventFactionsChunksChange(this.getSender(), chunks, newFaction);
CommandSender sender = this.getSender();
if (sender == null)
{
msg("<b>ERROR: Your \"CommandSender Link\" has been severed. This shouldn't happen.");
msg("<b>Help the Factions developers by reporting this at: <aqua>https://github.com/MassiveCraft/Factions/issues");
msg("<b>Describe what you were doing, what client you are using, if this is your first time on the server etc. The more the better.");
msg("<g>Relogging to the server should fix the issue.");
return false;
}
EventFactionsChunksChange event = new EventFactionsChunksChange(sender, chunks, newFaction);
event.run();
if (event.isCancelled()) return false;