Allergy reaction kicked in. This commit removes the Spout features. I have nothing against spout but if we are going to have them we should do them properly. They should be coded in such a way that they could be in an external plugin alltogether. Also removed netbeans stuff from IDE that should not be in the github repo.
This commit is contained in:
@ -1,303 +0,0 @@
|
||||
package com.massivecraft.factions.integration;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.factions.ConfServer;
|
||||
import com.massivecraft.factions.Factions;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.util.HealthBarUtil;
|
||||
import com.massivecraft.mcore.ps.PS;
|
||||
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
|
||||
|
||||
public class SpoutFeatures
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static SpoutMainListener mainListener;
|
||||
|
||||
private static boolean enabled = false;
|
||||
public static boolean isEnabled() { return enabled; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SETUP AND AVAILABILITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static boolean setup()
|
||||
{
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin("Spout");
|
||||
if (plugin == null || ! plugin.isEnabled())
|
||||
{
|
||||
if (enabled == false) return false;
|
||||
enabled = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (enabled == true) return true;
|
||||
enabled = true;
|
||||
|
||||
Factions.get().log("Found and will use features of "+plugin.getDescription().getFullName());
|
||||
mainListener = new SpoutMainListener();
|
||||
Bukkit.getPluginManager().registerEvents(mainListener, Factions.get());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CAPES
|
||||
// -------------------------------------------- //
|
||||
// Capes look the same to everyone.
|
||||
|
||||
public static void updateCape(final Object ofrom, final Object oto, boolean onlyIfDifferent)
|
||||
{
|
||||
// Enabled and non-null?
|
||||
if ( ! isEnabled()) return;
|
||||
if ( ! ConfServer.spoutCapes) return;
|
||||
|
||||
Set<Player> fromPlayers = getPlayersFromObject(ofrom);
|
||||
Set<Player> toPlayers = getPlayersFromObject(oto);
|
||||
|
||||
for (Player player : fromPlayers)
|
||||
{
|
||||
UPlayer uplayer = UPlayer.get(player);
|
||||
SpoutPlayer splayer = SpoutManager.getPlayer(player);
|
||||
Faction faction = uplayer.getFaction();
|
||||
|
||||
String cape = faction.getCape();
|
||||
if (cape == null)
|
||||
{
|
||||
// TODO: This URL is outdated?
|
||||
cape = "http://s3.amazonaws.com/MinecraftCloaks/" + player.getName() + ".png";
|
||||
}
|
||||
|
||||
for (Player playerTo : toPlayers)
|
||||
{
|
||||
SpoutPlayer splayerTo = SpoutManager.getPlayer(playerTo);
|
||||
|
||||
boolean skip = onlyIfDifferent && cape.equals(splayer.getCape(splayerTo));
|
||||
//Bukkit.getConsoleSender().sendMessage(P.p.txt.parse("<i>CAPE SKIP:<h>%s <i>FROM <h>%s <i>TO <h>%s <i>URL <h>%s", String.valueOf(skip), player.getDisplayName(), playerTo.getDisplayName(), cape));
|
||||
if (skip) continue;
|
||||
//Bukkit.getConsoleSender().sendMessage(P.p.txt.parse("<i>CAPE FROM <h>%s <i>TO <h>%s <i>URL <h>%s", player.getDisplayName(), playerTo.getDisplayName(), cape));
|
||||
|
||||
// Set the cape
|
||||
try
|
||||
{
|
||||
splayer.setCapeFor(splayerTo, cape);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateCape(final Object ofrom, final Object oto)
|
||||
{
|
||||
updateCape(ofrom, oto, true);
|
||||
}
|
||||
|
||||
public static void updateCapeShortly(final Object ofrom, final Object oto)
|
||||
{
|
||||
Factions.get().getServer().getScheduler().scheduleSyncDelayedTask(Factions.get(), new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
updateCape(ofrom, oto, false);
|
||||
}
|
||||
}, 5);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TITLE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static void updateTitle(final Object ofrom, final Object oto, boolean onlyIfDifferent)
|
||||
{
|
||||
// Enabled and non-null?
|
||||
if ( ! isEnabled()) return;
|
||||
if ( ! (ConfServer.spoutFactionTagsOverNames || ConfServer.spoutFactionTitlesOverNames || ConfServer.spoutHealthBarUnderNames)) return;
|
||||
|
||||
Set<Player> fromPlayers = getPlayersFromObject(ofrom);
|
||||
Set<Player> toPlayers = getPlayersFromObject(oto);
|
||||
|
||||
for (Player player : fromPlayers)
|
||||
{
|
||||
UPlayer uplayer = UPlayer.get(player);
|
||||
SpoutPlayer splayer = SpoutManager.getPlayer(player);
|
||||
Faction faction = uplayer.getFaction();
|
||||
|
||||
for (Player playerTo : toPlayers)
|
||||
{
|
||||
UPlayer uplayerTo = UPlayer.get(playerTo);
|
||||
SpoutPlayer splayerTo = SpoutManager.getPlayer(playerTo);
|
||||
Faction factionTo = uplayerTo.getFaction();
|
||||
|
||||
ChatColor relationColor = faction.getRelationTo(factionTo).getColor();
|
||||
|
||||
String title = generateTitle(player, uplayer, faction, relationColor);
|
||||
|
||||
boolean skip = onlyIfDifferent && title.equals(splayer.getTitleFor(splayerTo));
|
||||
//Bukkit.getConsoleSender().sendMessage(P.p.txt.parse("<i>TITLE SKIP:<h>%s <i>FROM <h>%s <i>TO <h>%s <i>TITLE <h>%s", String.valueOf(skip), player.getDisplayName(), playerTo.getDisplayName(), title));
|
||||
if (skip) continue;
|
||||
//Bukkit.getConsoleSender().sendMessage(P.p.txt.parse("<i>TITLE FROM <h>%s <i>TO <h>%s <i>TITLE <h>%s", player.getDisplayName(), playerTo.getDisplayName(), title));
|
||||
|
||||
splayer.setTitleFor(splayerTo, title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateTitle(final Object ofrom, final Object oto)
|
||||
{
|
||||
updateTitle(ofrom, oto, true);
|
||||
}
|
||||
|
||||
public static void updateTitleShortly(final Object ofrom, final Object oto)
|
||||
{
|
||||
Factions.get().getServer().getScheduler().scheduleSyncDelayedTask(Factions.get(), new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
updateTitle(ofrom, oto, false);
|
||||
}
|
||||
}, 5);
|
||||
}
|
||||
|
||||
public static String generateTitle(Player player, UPlayer uplayer, Faction faction, ChatColor relationColor)
|
||||
{
|
||||
String ret = null;
|
||||
|
||||
ret = player.getDisplayName();
|
||||
|
||||
if (faction.isNormal())
|
||||
{
|
||||
String addTag = "";
|
||||
if (ConfServer.spoutFactionTagsOverNames)
|
||||
{
|
||||
addTag += relationColor.toString() + uplayer.getRole().getPrefix() + faction.getTag();
|
||||
}
|
||||
|
||||
if (ConfServer.spoutFactionTitlesOverNames && uplayer.hasTitle())
|
||||
{
|
||||
addTag += (addTag.isEmpty() ? "" : " ") + uplayer.getTitle();
|
||||
}
|
||||
|
||||
ret = addTag + "\n" + ret;
|
||||
}
|
||||
|
||||
if (ConfServer.spoutHealthBarUnderNames)
|
||||
{
|
||||
ret += "\n";
|
||||
ret += HealthBarUtil.getHealthbar(player.getHealth() / 20d);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static Set<Player> getPlayersFromObject(Object o)
|
||||
{
|
||||
Set<Player> ret = new HashSet<Player>();
|
||||
if (o instanceof Player)
|
||||
{
|
||||
ret.add((Player)o);
|
||||
}
|
||||
else if (o instanceof UPlayer)
|
||||
{
|
||||
UPlayer uplayer = (UPlayer)o;
|
||||
Player player = uplayer.getPlayer();
|
||||
if (player != null)
|
||||
{
|
||||
ret.add(player);
|
||||
}
|
||||
}
|
||||
else if (o instanceof Faction)
|
||||
{
|
||||
ret.addAll(((Faction)o).getOnlinePlayers());
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.addAll(Arrays.asList(Bukkit.getOnlinePlayers()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TERRITORY DISPLAY
|
||||
// -------------------------------------------- //
|
||||
|
||||
// update displayed current territory for all players inside a specified chunk; if specified chunk is null, then simply update everyone online
|
||||
public static void updateTerritoryDisplayLoc(PS chunk)
|
||||
{
|
||||
if ( ! isEnabled()) return;
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
UPlayer uplayer = UPlayer.get(player);
|
||||
if (chunk == null)
|
||||
{
|
||||
mainListener.updateTerritoryDisplay(uplayer, false);
|
||||
}
|
||||
else if (uplayer.getCurrentChunk().equals(chunk))
|
||||
{
|
||||
mainListener.updateTerritoryDisplay(uplayer, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update displayed current territory for specified player; returns false if unsuccessful
|
||||
public static boolean updateTerritoryDisplay(UPlayer player)
|
||||
{
|
||||
if ( ! isEnabled()) return false;
|
||||
return mainListener.updateTerritoryDisplay(player, true);
|
||||
}
|
||||
|
||||
// update access info for all players inside a specified chunk; if specified chunk is null, then simply update everyone online
|
||||
public static void updateAccessInfoLoc(PS chunk)
|
||||
{
|
||||
if ( ! isEnabled()) return;
|
||||
|
||||
chunk = chunk.getChunk(true);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
UPlayer uplayer = UPlayer.get(player);
|
||||
if (chunk == null || uplayer.getCurrentChunk().equals(chunk))
|
||||
{
|
||||
mainListener.updateAccessInfo(uplayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update owner list for specified player
|
||||
public static boolean updateAccessInfo(UPlayer player)
|
||||
{
|
||||
if ( ! isEnabled()) return false;
|
||||
return mainListener.updateAccessInfo(player);
|
||||
}
|
||||
|
||||
public static void playerDisconnect(UPlayer player)
|
||||
{
|
||||
if ( ! isEnabled()) return;
|
||||
mainListener.removeTerritoryLabels(player.getName());
|
||||
}
|
||||
}
|
@ -1,263 +0,0 @@
|
||||
package com.massivecraft.factions.integration;
|
||||
|
||||
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.ConfServer;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.mcore.ps.PS;
|
||||
|
||||
import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent;
|
||||
import org.getspout.spoutapi.gui.Color;
|
||||
import org.getspout.spoutapi.gui.GenericLabel;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
|
||||
|
||||
public class SpoutMainListener implements Listener
|
||||
{
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onSpoutCraftEnable(SpoutCraftEnableEvent event)
|
||||
{
|
||||
final UPlayer me = UPlayer.get(event.getPlayer());
|
||||
|
||||
SpoutFeatures.updateTitle(me, null);
|
||||
SpoutFeatures.updateTitle(null, me);
|
||||
updateTerritoryDisplay(me, true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------//
|
||||
// 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 transient static Map<String, NoticeLabel> territoryChangeLabels = new HashMap<String, NoticeLabel>();
|
||||
private transient static Map<String, GenericLabel> accessLabels = new HashMap<String, GenericLabel>();
|
||||
private final static int SCREEN_WIDTH = 427;
|
||||
// private final static int SCREEN_HEIGHT = 240;
|
||||
|
||||
|
||||
public boolean updateTerritoryDisplay(UPlayer player, boolean notify)
|
||||
{
|
||||
Player p = player.getPlayer();
|
||||
if (p == null)
|
||||
return false;
|
||||
|
||||
SpoutPlayer sPlayer = SpoutManager.getPlayer(p);
|
||||
if (!sPlayer.isSpoutCraftEnabled() || (ConfServer.spoutTerritoryDisplaySize <= 0 && ! ConfServer.spoutTerritoryNoticeShow))
|
||||
return false;
|
||||
|
||||
doLabels(player, sPlayer, notify);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean updateAccessInfo(UPlayer player)
|
||||
{
|
||||
Player p = player.getPlayer();
|
||||
if (p == null)
|
||||
return false;
|
||||
|
||||
SpoutPlayer sPlayer = SpoutManager.getPlayer(p);
|
||||
if (!sPlayer.isSpoutCraftEnabled() || (ConfServer.spoutTerritoryDisplaySize <= 0 && ! ConfServer.spoutTerritoryNoticeShow))
|
||||
return false;
|
||||
|
||||
PS here = player.getCurrentChunk();
|
||||
|
||||
this.doAccessInfo(player, sPlayer, here);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void removeTerritoryLabels(String playerName)
|
||||
{
|
||||
territoryLabels.remove(playerName);
|
||||
territoryChangeLabels.remove(playerName);
|
||||
accessLabels.remove(playerName);
|
||||
}
|
||||
|
||||
|
||||
private void doLabels(UPlayer player, SpoutPlayer sPlayer, boolean notify)
|
||||
{
|
||||
PS here = player.getCurrentChunk();
|
||||
Faction factionHere = BoardColls.get().getFactionAt(here);
|
||||
String tag = factionHere.getColorTo(player).toString() + factionHere.getTag();
|
||||
|
||||
// ----------------------
|
||||
// Main territory display
|
||||
// ----------------------
|
||||
if (ConfServer.spoutTerritoryDisplayPosition > 0 && ConfServer.spoutTerritoryDisplaySize > 0)
|
||||
{
|
||||
GenericLabel label;
|
||||
if (territoryLabels.containsKey(player.getName()))
|
||||
label = territoryLabels.get(player.getName());
|
||||
else
|
||||
{
|
||||
label = new GenericLabel();
|
||||
label.setWidth(1).setHeight(1); // prevent Spout's questionable new "no default size" warning
|
||||
label.setScale(ConfServer.spoutTerritoryDisplaySize);
|
||||
|
||||
sPlayer.getMainScreen().attachWidget(Factions.get(), label);
|
||||
territoryLabels.put(player.getName(), label);
|
||||
}
|
||||
|
||||
String msg = tag;
|
||||
|
||||
if (ConfServer.spoutTerritoryDisplayShowDescription && factionHere.hasDescription())
|
||||
{
|
||||
msg += " - " + factionHere.getDescription();
|
||||
}
|
||||
|
||||
label.setText(msg);
|
||||
alignLabel(label, msg);
|
||||
label.setDirty(true);
|
||||
}
|
||||
|
||||
// -----------------------
|
||||
// Fading territory notice
|
||||
// -----------------------
|
||||
if (notify && ConfServer.spoutTerritoryNoticeShow && ConfServer.spoutTerritoryNoticeSize > 0)
|
||||
{
|
||||
NoticeLabel label;
|
||||
if (territoryChangeLabels.containsKey(player.getName()))
|
||||
label = territoryChangeLabels.get(player.getName());
|
||||
else
|
||||
{
|
||||
label = new NoticeLabel(ConfServer.spoutTerritoryNoticeLeaveAfterSeconds);
|
||||
label.setWidth(1).setHeight(1); // prevent Spout's questionable new "no default size" warning
|
||||
label.setScale(ConfServer.spoutTerritoryNoticeSize);
|
||||
label.setY(ConfServer.spoutTerritoryNoticeTop);
|
||||
sPlayer.getMainScreen().attachWidget(Factions.get(), label);
|
||||
territoryChangeLabels.put(player.getName(), label);
|
||||
}
|
||||
|
||||
String msg = tag;
|
||||
|
||||
if (ConfServer.spoutTerritoryNoticeShowDescription && factionHere.hasDescription())
|
||||
{
|
||||
msg += " - " + factionHere.getDescription();
|
||||
}
|
||||
|
||||
label.setText(msg);
|
||||
alignLabel(label, msg, 2);
|
||||
label.resetNotice();
|
||||
label.setDirty(true);
|
||||
}
|
||||
|
||||
// and access info, of course
|
||||
doAccessInfo(player, sPlayer, here);
|
||||
}
|
||||
|
||||
private static final Color accessGrantedColor = new Color(0.2f, 1.0f, 0.2f);
|
||||
private static final Color accessDeniedColor = new Color(1.0f, 0.2f, 0.2f);
|
||||
private void doAccessInfo(UPlayer player, SpoutPlayer sPlayer, PS here)
|
||||
{
|
||||
if (ConfServer.spoutTerritoryDisplayPosition <= 0 || ConfServer.spoutTerritoryDisplaySize <= 0 || ! ConfServer.spoutTerritoryAccessShow) return;
|
||||
|
||||
// -----------
|
||||
// Access Info
|
||||
// -----------
|
||||
GenericLabel label;
|
||||
if (accessLabels.containsKey(player.getName()))
|
||||
label = accessLabels.get(player.getName());
|
||||
else
|
||||
{
|
||||
label = new GenericLabel();
|
||||
label.setWidth(1).setHeight(1); // prevent Spout's questionable new "no default size" warning
|
||||
label.setScale(ConfServer.spoutTerritoryDisplaySize);
|
||||
label.setY((int)(10 * ConfServer.spoutTerritoryDisplaySize));
|
||||
sPlayer.getMainScreen().attachWidget(Factions.get(), label);
|
||||
accessLabels.put(player.getName(), label);
|
||||
}
|
||||
|
||||
String msg = "";
|
||||
TerritoryAccess access = BoardColls.get().getTerritoryAccessAt(here);
|
||||
|
||||
if ( ! access.isDefault())
|
||||
{
|
||||
if (access.subjectHasAccess(player))
|
||||
{
|
||||
msg = "access granted";
|
||||
label.setTextColor(accessGrantedColor);
|
||||
}
|
||||
else if (access.subjectAccessIsRestricted(player))
|
||||
{
|
||||
msg = "access restricted";
|
||||
label.setTextColor(accessDeniedColor);
|
||||
}
|
||||
}
|
||||
|
||||
label.setText(msg);
|
||||
alignLabel(label, msg);
|
||||
label.setDirty(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)
|
||||
{
|
||||
alignLabel(label, text, ConfServer.spoutTerritoryDisplayPosition);
|
||||
}
|
||||
public void alignLabel(GenericLabel label, String text, int alignment)
|
||||
{
|
||||
int labelWidth = (int)((float)GenericLabel.getStringWidth(text) * ConfServer.spoutTerritoryDisplaySize);
|
||||
if (labelWidth > SCREEN_WIDTH)
|
||||
{
|
||||
label.setX(0);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (alignment)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class NoticeLabel extends GenericLabel
|
||||
{
|
||||
private int initial;
|
||||
private int countdown; // current delay countdown
|
||||
|
||||
public NoticeLabel(float secondsOfLife)
|
||||
{
|
||||
initial = (int)(secondsOfLife * 20);
|
||||
resetNotice();
|
||||
}
|
||||
|
||||
public final void resetNotice()
|
||||
{
|
||||
countdown = initial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
if (countdown <= 0)
|
||||
return;
|
||||
|
||||
this.countdown -= 1;
|
||||
|
||||
if (this.countdown <= 0)
|
||||
{
|
||||
this.setText("");
|
||||
this.setDirty(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user