From 312fe5105bec36f3191efbb55fa4e3b160d943ce Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Wed, 10 Jun 2015 15:31:42 -0500 Subject: [PATCH] Don't throw the async jail exception, we run it sync --- .../com/graywolf336/jail/PrisonerManager.java | 13 ++++++------ .../AsyncJailingNotSupportedException.java | 21 ------------------- 2 files changed, 7 insertions(+), 27 deletions(-) delete mode 100644 src/main/java/com/graywolf336/jail/exceptions/AsyncJailingNotSupportedException.java diff --git a/src/main/java/com/graywolf336/jail/PrisonerManager.java b/src/main/java/com/graywolf336/jail/PrisonerManager.java index c18e543..be81cc2 100644 --- a/src/main/java/com/graywolf336/jail/PrisonerManager.java +++ b/src/main/java/com/graywolf336/jail/PrisonerManager.java @@ -23,7 +23,6 @@ import com.graywolf336.jail.events.PrePrisonerReleasedEvent; import com.graywolf336.jail.events.PrisonerJailedEvent; import com.graywolf336.jail.events.PrisonerReleasedEvent; import com.graywolf336.jail.events.PrisonerTransferredEvent; -import com.graywolf336.jail.exceptions.AsyncJailingNotSupportedException; import com.graywolf336.jail.exceptions.AsyncUnJailingNotSupportedException; import com.graywolf336.jail.exceptions.JailRequiredException; import com.graywolf336.jail.exceptions.PrisonerAlreadyJailedException; @@ -86,15 +85,12 @@ public class PrisonerManager { * @param cell The name of the {@link ICell cell} we are sending this prisoner to * @param player The {@link Player player} we are preparing the jail for. * @param prisoner The {@link Prisoner prisoner} file. - * @throws AsyncJailingNotSupportedException if the method is called from a thread that is not the primary one (call it sync). * @throws JailRequiredException if the jail provided is null. * @throws PrisonerAlreadyJailedException if the prisoner is already jailed. * @throws PrisonerRequiredException if the prisoner's data provided is null. * */ - public void prepareJail(Jail jail, ICell cell, Player player, Prisoner prisoner) throws AsyncJailingNotSupportedException, JailRequiredException, PrisonerAlreadyJailedException, PrisonerRequiredException { - if(!pl.getServer().isPrimaryThread()) throw new AsyncJailingNotSupportedException(); - + public void prepareJail(final Jail jail, ICell cell, final Player player, final Prisoner prisoner) throws JailRequiredException, PrisonerAlreadyJailedException, PrisonerRequiredException { //Do some checks of whether the passed params are null. if(jail == null) throw new JailRequiredException("jailing a prisoner"); @@ -130,7 +126,12 @@ public class PrisonerManager { if(prisoner.isOfflinePending()) { pl.getServer().getPluginManager().callEvent(new OfflinePrisonerJailedEvent(jail, cell, prisoner)); }else { - jailPrisoner(jail, cell, player, prisoner); + final ICell c = cell; + pl.getServer().getScheduler().runTask(pl, new Runnable() { + public void run() { + jailPrisoner(jail, c, player, prisoner); + } + }); } //Get a message ready for broadcasting or logging. diff --git a/src/main/java/com/graywolf336/jail/exceptions/AsyncJailingNotSupportedException.java b/src/main/java/com/graywolf336/jail/exceptions/AsyncJailingNotSupportedException.java deleted file mode 100644 index 1206aa0..0000000 --- a/src/main/java/com/graywolf336/jail/exceptions/AsyncJailingNotSupportedException.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.graywolf336.jail.exceptions; - -/** - * - * The exception thrown trying to jail via a thread that is NOT the primary thread. - * - * @author graywolf336 - * @since 3.0.0 - * @version 1.0.0 - */ -public class AsyncJailingNotSupportedException extends Exception { - private static final long serialVersionUID = 2746426914894618352L; - - /** - * Creation of an exception from jailing via a thread that is not the primary one. - * - */ - public AsyncJailingNotSupportedException() { - super("Jailing via a thread that is NOT the primary thread is not supported."); - } -}