Updated SpoutAPI, handled deprecated Spout AppearanceManager code, updated Spout event listener to new Bukkit event system

This commit is contained in:
Brettflan 2012-02-20 17:03:43 -06:00
parent 639dc16bf5
commit 11a4162981
3 changed files with 22 additions and 36 deletions

Binary file not shown.

View File

@ -9,22 +9,20 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.P;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import org.getspout.spoutapi.gui.Color;
import org.getspout.spoutapi.player.AppearanceManager;
import org.getspout.spoutapi.player.SpoutPlayer;
import org.getspout.spoutapi.SpoutManager;
public class SpoutFeatures
{
private transient static AppearanceManager spoutApp;
private transient static boolean spoutMe = false;
private transient static SpoutMainListener mainListener;
private transient static boolean listenersHooked;
@ -33,21 +31,15 @@ public class SpoutFeatures
public static void setAvailable(boolean enable, String pluginName)
{
spoutMe = enable;
if (spoutMe)
{
spoutApp = SpoutManager.getAppearanceManager();
if (!spoutMe) return;
P.p.log("Found and will use features of "+pluginName);
if (!listenersHooked)
{
listenersHooked = true;
mainListener = new SpoutMainListener();
P.p.registerEvent(Event.Type.CUSTOM_EVENT, mainListener, Event.Priority.Normal);
}
}
else
{
spoutApp = null;
Bukkit.getServer().getPluginManager().registerEvents(mainListener, P.p);
}
}
@ -219,12 +211,11 @@ public class SpoutFeatures
if (viewedFaction == null)
return;
Player pViewed = viewed.getPlayer();
Player pViewer = viewer.getPlayer();
SpoutPlayer pViewer = SpoutManager.getPlayer(viewer.getPlayer());
SpoutPlayer pViewed = SpoutManager.getPlayer(viewed.getPlayer());
if (pViewed == null || pViewer == null)
return;
SpoutPlayer sPlayer = SpoutManager.getPlayer(pViewer);
String viewedTitle = viewed.getTitle();
Role viewedRole = viewed.getRole();
@ -240,11 +231,11 @@ public class SpoutFeatures
if (Conf.spoutFactionTitlesOverNames && (!viewedTitle.isEmpty() || !rolePrefix.isEmpty()))
addTag += (addTag.isEmpty() ? "" : " ") + viewedRole.getPrefix() + viewedTitle;
spoutApp.setPlayerTitle(sPlayer, pViewed, addTag + "\n" + pViewed.getDisplayName());
pViewed.setTitleFor(pViewer, addTag + "\n" + pViewed.getDisplayName());
}
else
{
spoutApp.setPlayerTitle(sPlayer, pViewed, pViewed.getDisplayName());
pViewed.setTitleFor(pViewer, pViewed.getDisplayName());
}
}
@ -281,13 +272,13 @@ public class SpoutFeatures
cape = Conf.capeAlly;
if (cape.isEmpty())
spoutApp.resetPlayerCloak(sPlayer, pViewed);
pViewed.resetCapeFor(pViewer);
else
spoutApp.setPlayerCloak(sPlayer, pViewed, cape);
pViewed.setCapeFor(pViewer, cape);
}
else if (Conf.spoutFactionAdminCapes || Conf.spoutFactionModeratorCapes)
{
spoutApp.resetPlayerCloak(sPlayer, pViewed);
pViewed.resetCapeFor(pViewer);
}
}
@ -298,7 +289,7 @@ public class SpoutFeatures
if (inColor == null)
return SpoutFixedColor(191, 191, 191, alpha);
switch (inColor.getCode())
switch (inColor.getChar())
{
case 0x1: return SpoutFixedColor(0, 0, 191, alpha);
case 0x2: return SpoutFixedColor(0, 191, 0, alpha);

View File

@ -4,6 +4,9 @@ import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
@ -14,16 +17,14 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent;
import org.getspout.spoutapi.event.spout.SpoutListener;
import org.getspout.spoutapi.gui.GenericLabel;
import org.getspout.spoutapi.player.SpoutPlayer;
import org.getspout.spoutapi.SpoutManager;
//import org.getspout.spoutapi.gui.WidgetAnchor;
public class SpoutMainListener extends SpoutListener
public class SpoutMainListener implements Listener
{
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onSpoutCraftEnable(SpoutCraftEnableEvent event)
{
final FPlayer me = FPlayers.i.get(event.getPlayer());
@ -99,13 +100,7 @@ public class SpoutMainListener extends SpoutListener
label = new GenericLabel();
label.setWidth(1).setHeight(1); // prevent Spout's questionable new "no default size" warning
label.setScale(Conf.spoutTerritoryDisplaySize);
/* // this should work once the Spout team fix it to account for text scaling; we can then get rid of alignLabel method added below
switch (Conf.spoutTerritoryDisplayPosition) {
case 1: label.setAlign(WidgetAnchor.TOP_LEFT).setAnchor(WidgetAnchor.TOP_LEFT); break;
case 2: label.setAlign(WidgetAnchor.TOP_CENTER).setAnchor(WidgetAnchor.TOP_CENTER); break;
default: label.setAlign(WidgetAnchor.TOP_RIGHT).setAnchor(WidgetAnchor.TOP_RIGHT);
}
*/
sPlayer.getMainScreen().attachWidget(P.p, label);
territoryLabels.put(player.getName(), label);
}