Merge branch 'master' of github.com:MassiveCraft/Factions
This commit is contained in:
@ -185,6 +185,8 @@ public class Conf
|
||||
public static boolean spoutFactionAdminCapes = true; // TODO: What are these for?
|
||||
public static boolean spoutFactionModeratorCapes = true;
|
||||
public static int spoutTerritoryDisplayPosition = 3;
|
||||
public static float spoutTerritoryDisplaySize = 1.0f;
|
||||
public static boolean spoutTerritoryDisplayShowDescription = true;
|
||||
public static String capeAlly = "https://github.com/MassiveCraft/Factions/raw/master/capes/ally.png";
|
||||
public static String capeEnemy = "https://github.com/MassiveCraft/Factions/raw/master/capes/enemy.png";
|
||||
public static String capeMember = "https://github.com/MassiveCraft/Factions/raw/master/capes/member.png";
|
||||
|
@ -26,8 +26,6 @@ public class CmdConfig extends FCommand
|
||||
|
||||
this.requiredArgs.add("setting");
|
||||
this.requiredArgs.add("value");
|
||||
this.requiredArgs.add("");
|
||||
//this.optionalArgs.put("", "");
|
||||
|
||||
this.permission = Permission.CONFIG.node;
|
||||
this.disableOnLock = true;
|
||||
|
@ -1,35 +1,32 @@
|
||||
package com.massivecraft.factions.integration;
|
||||
|
||||
import com.massivecraft.factions.Board;
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.P;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
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.gui.GenericLabel;
|
||||
import org.getspout.spoutapi.player.AppearanceManager;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.gui.WidgetAnchor;
|
||||
|
||||
|
||||
public class SpoutFeatures
|
||||
{
|
||||
private transient static AppearanceManager spoutApp;
|
||||
private transient static boolean spoutMe = false;
|
||||
private transient static Map<String, GenericLabel> territoryLabels = new HashMap<String, GenericLabel>();
|
||||
private transient static SpoutMainListener mainListener;
|
||||
private transient static boolean listenersHooked;
|
||||
|
||||
// set integration availability
|
||||
public static void setAvailable(boolean enable, String pluginName)
|
||||
@ -39,6 +36,13 @@ public class SpoutFeatures
|
||||
{
|
||||
spoutApp = SpoutManager.getAppearanceManager();
|
||||
P.p.log("Found and will use features of "+pluginName);
|
||||
|
||||
if (!listenersHooked)
|
||||
{
|
||||
listenersHooked = true;
|
||||
mainListener = new SpoutMainListener();
|
||||
P.p.getServer().getPluginManager().registerEvent(Event.Type.CUSTOM_EVENT, mainListener, Event.Priority.Normal, P.p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -62,46 +66,12 @@ public class SpoutFeatures
|
||||
// update displayed current territory for specified player; returns false if unsuccessful
|
||||
public static boolean updateTerritoryDisplay(FPlayer player)
|
||||
{
|
||||
if (!spoutMe || Conf.spoutTerritoryDisplayPosition == 0)
|
||||
if (!enabled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
SpoutPlayer sPlayer = SpoutManager.getPlayer(player.getPlayer());
|
||||
if (!sPlayer.isSpoutCraftEnabled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
GenericLabel label;
|
||||
if (territoryLabels.containsKey(player.getName()))
|
||||
{
|
||||
label = territoryLabels.get(player.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
label = new GenericLabel();
|
||||
sPlayer.getMainScreen().attachWidget(P.p, label);
|
||||
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);
|
||||
}
|
||||
territoryLabels.put(player.getName(), label);
|
||||
}
|
||||
|
||||
Faction factionHere = Board.getFactionAt(new FLocation(player));
|
||||
String msg = factionHere.getTag();
|
||||
if (factionHere.getDescription().length() > 0)
|
||||
{
|
||||
msg += " - "+factionHere.getDescription();
|
||||
}
|
||||
label.setTextColor(getSpoutColor(player.getRelationColor(factionHere), 0));
|
||||
label.setText(msg);
|
||||
label.setDirty(true);
|
||||
|
||||
return true;
|
||||
return mainListener.updateTerritoryDisplay(player);
|
||||
}
|
||||
|
||||
public static void playerDisconnect(FPlayer player)
|
||||
@ -110,7 +80,8 @@ public class SpoutFeatures
|
||||
{
|
||||
return;
|
||||
}
|
||||
territoryLabels.remove(player.getName());
|
||||
|
||||
mainListener.removeTerritoryLabel(player.getName());
|
||||
}
|
||||
|
||||
|
||||
@ -294,7 +265,7 @@ public class SpoutFeatures
|
||||
}
|
||||
|
||||
// method to convert a Bukkit ChatColor to a Spout Color
|
||||
private static Color getSpoutColor(ChatColor inColor, int alpha)
|
||||
protected static Color getSpoutColor(ChatColor inColor, int alpha)
|
||||
{
|
||||
if (inColor == null)
|
||||
{
|
||||
|
112
src/com/massivecraft/factions/integration/SpoutMainListener.java
Normal file
112
src/com/massivecraft/factions/integration/SpoutMainListener.java
Normal file
@ -0,0 +1,112 @@
|
||||
package com.massivecraft.factions.integration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
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
|
||||
{
|
||||
@Override
|
||||
public void onSpoutCraftEnable(SpoutCraftEnableEvent event)
|
||||
{
|
||||
final FPlayer me = FPlayers.i.get(event.getPlayer());
|
||||
|
||||
SpoutFeatures.updateAppearances(me.getPlayer());
|
||||
updateTerritoryDisplay(me);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------//
|
||||
// Everything below this is handled in here to prevent errors on servers not running Spout
|
||||
//-----------------------------------------------------------------------------------------//
|
||||
|
||||
private transient static Map<String, GenericLabel> territoryLabels = new HashMap<String, GenericLabel>();
|
||||
private final static int SCREEN_WIDTH = 427;
|
||||
// private final static int SCREEN_HEIGHT = 240;
|
||||
|
||||
|
||||
public boolean updateTerritoryDisplay(FPlayer player)
|
||||
{
|
||||
SpoutPlayer sPlayer = SpoutManager.getPlayer(player.getPlayer());
|
||||
if (!sPlayer.isSpoutCraftEnabled() || Conf.spoutTerritoryDisplaySize <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
GenericLabel label;
|
||||
if (territoryLabels.containsKey(player.getName()))
|
||||
{
|
||||
label = territoryLabels.get(player.getName());
|
||||
} else {
|
||||
label = new GenericLabel();
|
||||
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);
|
||||
}
|
||||
|
||||
Faction factionHere = Board.getFactionAt(new FLocation(player));
|
||||
String msg = factionHere.getTag();
|
||||
|
||||
if (Conf.spoutTerritoryDisplayShowDescription && factionHere.getDescription().length() > 0)
|
||||
{
|
||||
msg += " - "+factionHere.getDescription();
|
||||
}
|
||||
|
||||
label.setTextColor(SpoutFeatures.getSpoutColor(player.getRelationColor(factionHere), 0));
|
||||
label.setText(msg);
|
||||
alignLabel(label, msg);
|
||||
label.setDirty(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// this is only necessary because Spout text size scaling is currently bugged and breaks their built-in alignment methods
|
||||
public void alignLabel(GenericLabel label, String text)
|
||||
{
|
||||
int labelWidth = (int)((float)GenericLabel.getStringWidth(text) * Conf.spoutTerritoryDisplaySize);
|
||||
if (labelWidth > SCREEN_WIDTH)
|
||||
{
|
||||
label.setX(0);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (Conf.spoutTerritoryDisplayPosition)
|
||||
{
|
||||
case 1: // left aligned
|
||||
label.setX(0);
|
||||
break;
|
||||
case 2: // center aligned
|
||||
label.setX((SCREEN_WIDTH - labelWidth) / 2);
|
||||
break;
|
||||
default: // right aligned
|
||||
label.setX(SCREEN_WIDTH - labelWidth);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeTerritoryLabel(String playerName)
|
||||
{
|
||||
territoryLabels.remove(playerName);
|
||||
}
|
||||
}
|
@ -155,16 +155,6 @@ public class FactionsPlayerListener extends PlayerListener
|
||||
// Run the member auto kick routine. Twice to get to the admins...
|
||||
FPlayers.i.autoLeaveOnInactivityRoutine();
|
||||
FPlayers.i.autoLeaveOnInactivityRoutine();
|
||||
|
||||
SpoutFeatures.updateTerritoryDisplay(me);
|
||||
|
||||
// Appearance updates which are run when a player joins don't apply properly for other clients, so they need to be delayed slightly
|
||||
P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, new Runnable() {
|
||||
public void run() {
|
||||
SpoutFeatures.updateAppearances(me.getPlayer());
|
||||
SpoutFeatures.updateTerritoryDisplay(me);
|
||||
}
|
||||
}, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -138,7 +138,7 @@ public class Persist {
|
||||
// LOAD BY TYPE
|
||||
public <T> T load(Type typeOfT, String name)
|
||||
{
|
||||
return load(typeOfT, getFile(name));
|
||||
return (T) load(typeOfT, getFile(name));
|
||||
}
|
||||
|
||||
public <T> T load(Type typeOfT, File file)
|
||||
@ -148,7 +148,7 @@ public class Persist {
|
||||
return null;
|
||||
}
|
||||
|
||||
return p.gson.fromJson(content, typeOfT);
|
||||
return (T) p.gson.fromJson(content, typeOfT);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user