New Spout feature, for Spoutcraft client users only: current territory info will now be permanently shown at top of screen, instead of being echoed out to chat as you move around
New conf.json setting "spoutTerritoryDisplayPosition" to set the screen position at which the current territory is shown. 0 = disabled, 1 = top left, 2 = top center, 3 (default) = top right. Moved all integration code to separate package, ofr better code organization. Also moved EssentialsChat integration code out to separate file in there, allowing us to safely remove our copy IEssentialsChatListener.java file (which is otherwise needed to prevent a nasty NoClassDefFoundError).
This commit is contained in:
276
src/com/massivecraft/factions/integration/Econ.java
Normal file
276
src/com/massivecraft/factions/integration/Econ.java
Normal file
@ -0,0 +1,276 @@
|
||||
package com.massivecraft.factions.integration;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.massivecraft.factions.listeners.FactionsServerListener;
|
||||
import com.massivecraft.factions.commands.FCommandHelp;
|
||||
|
||||
import com.earth2me.essentials.api.Economy;
|
||||
import com.nijikokun.register.payment.Methods;
|
||||
import com.nijikokun.register.payment.Method.MethodAccount;
|
||||
import com.iConomy.*;
|
||||
import com.iConomy.system.*;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.Factions;
|
||||
|
||||
|
||||
public class Econ {
|
||||
private static boolean registerUse = false;
|
||||
private static boolean iConomyUse = false;
|
||||
private static boolean essEcoUse = false;
|
||||
|
||||
public static void monitorPlugins() {
|
||||
Factions.instance.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_ENABLE, new FactionsServerListener(), Event.Priority.Monitor, Factions.instance);
|
||||
Factions.instance.getServer().getPluginManager().registerEvent(Event.Type.PLUGIN_DISABLE, new FactionsServerListener(), Event.Priority.Monitor, Factions.instance);
|
||||
}
|
||||
|
||||
public static void setup(Factions factions) {
|
||||
if (enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!registerHooked()) {
|
||||
Plugin plug = factions.getServer().getPluginManager().getPlugin("Register");
|
||||
if (plug != null && plug.getClass().getName().equals("com.nijikokun.register.Register") && plug.isEnabled()) {
|
||||
registerSet(true);
|
||||
}
|
||||
}
|
||||
if (!iConomyHooked()) {
|
||||
Plugin plug = factions.getServer().getPluginManager().getPlugin("iConomy");
|
||||
if (plug != null && plug.getClass().getName().equals("com.iConomy.iConomy") && plug.isEnabled()) {
|
||||
iConomySet(true);
|
||||
}
|
||||
}
|
||||
if (!essentialsEcoHooked()) {
|
||||
Plugin plug = factions.getServer().getPluginManager().getPlugin("Essentials");
|
||||
if (plug != null && plug.isEnabled()) {
|
||||
essentialsEcoSet(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerSet(boolean enable) {
|
||||
registerUse = enable;
|
||||
if (enable) {
|
||||
Factions.log("Register hook available, "+(Conf.econRegisterEnabled ? "and interface is enabled" : "but disabled (\"econRegisterEnabled\": false)")+".");
|
||||
}
|
||||
else {
|
||||
Factions.log("Un-hooked from Register.");
|
||||
}
|
||||
FCommandHelp.updateHelp();
|
||||
}
|
||||
|
||||
public static void iConomySet(boolean enable) {
|
||||
iConomyUse = enable;
|
||||
if (enable && !registerUse) {
|
||||
Factions.log("iConomy hook available, "+(Conf.econIConomyEnabled ? "and interface is enabled" : "but disabled (\"econIConomyEnabled\": false)")+".");
|
||||
}
|
||||
else {
|
||||
Factions.log("Un-hooked from iConomy.");
|
||||
}
|
||||
FCommandHelp.updateHelp();
|
||||
}
|
||||
|
||||
public static void essentialsEcoSet(boolean enable) {
|
||||
essEcoUse = enable;
|
||||
if (enable && !registerUse) {
|
||||
Factions.log("EssentialsEco hook available, "+(Conf.econEssentialsEcoEnabled ? "and interface is enabled" : "but disabled (\"econEssentialsEcoEnabled\": false)")+".");
|
||||
}
|
||||
else {
|
||||
Factions.log("Un-hooked from EssentialsEco.");
|
||||
}
|
||||
FCommandHelp.updateHelp();
|
||||
}
|
||||
|
||||
public static boolean registerHooked() {
|
||||
return registerUse;
|
||||
}
|
||||
|
||||
public static boolean iConomyHooked() {
|
||||
return iConomyUse;
|
||||
}
|
||||
|
||||
public static boolean essentialsEcoHooked() {
|
||||
return essEcoUse;
|
||||
}
|
||||
|
||||
public static boolean registerAvailable() {
|
||||
return Conf.econRegisterEnabled && registerUse && Methods.hasMethod();
|
||||
}
|
||||
|
||||
// If economy is enabled in conf.json, and we're successfully hooked into an economy plugin
|
||||
public static boolean enabled() {
|
||||
return (Conf.econRegisterEnabled && registerUse && Methods.hasMethod())
|
||||
|| (Conf.econIConomyEnabled && iConomyUse)
|
||||
|| (Conf.econEssentialsEcoEnabled && essEcoUse);
|
||||
}
|
||||
|
||||
// mainly for internal use, for a little less code repetition
|
||||
public static Holdings getIconomyHoldings(String playerName) {
|
||||
if (!enabled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Account account = iConomy.getAccount(playerName);
|
||||
if (account == null) {
|
||||
return null;
|
||||
}
|
||||
Holdings holdings = account.getHoldings();
|
||||
return holdings;
|
||||
}
|
||||
public static MethodAccount getRegisterAccount(String playerName) {
|
||||
if (!enabled()) {
|
||||
return null;
|
||||
}
|
||||
if (!Methods.getMethod().hasAccount(playerName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MethodAccount account = Methods.getMethod().getAccount(playerName);
|
||||
return account;
|
||||
}
|
||||
|
||||
|
||||
// format money string based on server's set currency type, like "24 gold" or "$24.50"
|
||||
public static String moneyString(double amount) {
|
||||
return registerAvailable() ? Methods.getMethod().format(amount)
|
||||
: (iConomyUse ? iConomy.format(amount) : Economy.format(amount));
|
||||
}
|
||||
|
||||
// whether a player can afford specified amount
|
||||
public static boolean canAfford(String playerName, double amount) {
|
||||
// if Economy support is not enabled, they can certainly afford to pay nothing
|
||||
if (!enabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (registerAvailable()) {
|
||||
MethodAccount holdings = getRegisterAccount(playerName);
|
||||
if (holdings == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return holdings.hasEnough(amount);
|
||||
}
|
||||
else if (iConomyUse) {
|
||||
Holdings holdings = getIconomyHoldings(playerName);
|
||||
if (holdings == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return holdings.hasEnough(amount);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
return Economy.hasEnough(playerName, amount);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// deduct money from their account; returns true if successful
|
||||
public static boolean deductMoney(String playerName, double amount) {
|
||||
if (!enabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (registerAvailable()) {
|
||||
MethodAccount holdings = getRegisterAccount(playerName);
|
||||
if (holdings == null || !holdings.hasEnough(amount)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return holdings.subtract(amount);
|
||||
}
|
||||
else if (iConomyUse) {
|
||||
Holdings holdings = getIconomyHoldings(playerName);
|
||||
if (holdings == null || !holdings.hasEnough(amount)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
holdings.subtract(amount);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
if (!Economy.hasEnough(playerName, amount)) {
|
||||
return false;
|
||||
}
|
||||
Economy.subtract(playerName, amount);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add money to their account; returns true if successful
|
||||
public static boolean addMoney(String playerName, double amount) {
|
||||
if (!enabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (registerAvailable()) {
|
||||
MethodAccount holdings = getRegisterAccount(playerName);
|
||||
if (holdings == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return holdings.add(amount);
|
||||
}
|
||||
else if (iConomyUse) {
|
||||
Holdings holdings = getIconomyHoldings(playerName);
|
||||
if (holdings == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
holdings.add(amount);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Economy.add(playerName, amount);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// calculate the cost for claiming land
|
||||
public static double calculateClaimCost(int ownedLand, boolean takingFromAnotherFaction) {
|
||||
if (!enabled()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// basic claim cost, plus land inflation cost, minus the potential bonus given for claiming from another faction
|
||||
return Conf.econCostClaimWilderness
|
||||
+ (Conf.econCostClaimWilderness * Conf.econClaimAdditionalMultiplier * ownedLand)
|
||||
- (takingFromAnotherFaction ? Conf.econCostClaimFromFactionBonus: 0);
|
||||
}
|
||||
|
||||
// calculate refund amount for unclaiming land
|
||||
public static double calculateClaimRefund(int ownedLand) {
|
||||
return calculateClaimCost(ownedLand - 1, false) * Conf.econClaimRefundMultiplier;
|
||||
}
|
||||
|
||||
// calculate value of all owned land
|
||||
public static double calculateTotalLandValue(int ownedLand) {
|
||||
double amount = 0;
|
||||
for (int x = 0; x < ownedLand; x++) {
|
||||
amount += calculateClaimCost(x, false);
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
// calculate refund amount for all owned land
|
||||
public static double calculateTotalLandRefund(int ownedLand) {
|
||||
return calculateTotalLandValue(ownedLand) * Conf.econClaimRefundMultiplier;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.massivecraft.factions.integration;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
|
||||
import com.earth2me.essentials.chat.EssentialsChat;
|
||||
import com.earth2me.essentials.chat.IEssentialsChatListener;
|
||||
|
||||
|
||||
public class EssentialsFeatures {
|
||||
private static EssentialsChat essChat;
|
||||
|
||||
public static void integrateChat(EssentialsChat instance) {
|
||||
essChat = instance;
|
||||
try {
|
||||
essChat.addEssentialsChatListener("Factions", new IEssentialsChatListener() {
|
||||
public boolean shouldHandleThisChat(PlayerChatEvent event)
|
||||
{
|
||||
return Factions.instance.shouldLetFactionsHandleThisChat(event);
|
||||
}
|
||||
public String modifyMessage(PlayerChatEvent event, Player target, String message)
|
||||
{
|
||||
return message.replace("{FACTION}", Factions.instance.getPlayerFactionTagRelation(event.getPlayer(), target)).replace("{FACTION_TITLE}", Factions.instance.getPlayerTitle(event.getPlayer()));
|
||||
}
|
||||
});
|
||||
Factions.log("Found and will integrate chat with "+essChat.getDescription().getFullName());
|
||||
}
|
||||
catch (NoSuchMethodError ex) {
|
||||
essChat = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void unhookChat() {
|
||||
if (essChat != null) {
|
||||
essChat.removeEssentialsChatListener("Factions");
|
||||
}
|
||||
}
|
||||
}
|
261
src/com/massivecraft/factions/integration/SpoutFeatures.java
Normal file
261
src/com/massivecraft/factions/integration/SpoutFeatures.java
Normal file
@ -0,0 +1,261 @@
|
||||
package com.massivecraft.factions.integration;
|
||||
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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>();
|
||||
|
||||
// set integration availability
|
||||
public static void setAvailable(boolean enable, String pluginName) {
|
||||
spoutMe = enable;
|
||||
if (spoutMe) {
|
||||
spoutApp = SpoutManager.getAppearanceManager();
|
||||
Factions.log("Found and will use features of "+pluginName);
|
||||
}
|
||||
else {
|
||||
spoutApp = null;
|
||||
}
|
||||
}
|
||||
|
||||
// If any Spout feature is enabled in conf.json, and we're successfully hooked into it
|
||||
public static boolean enabled() {
|
||||
return spoutMe && (
|
||||
Conf.spoutFactionTagsOverNames
|
||||
|| Conf.spoutFactionTitlesOverNames
|
||||
|| Conf.spoutFactionAdminCapes
|
||||
|| Conf.spoutFactionModeratorCapes
|
||||
|| Conf.spoutTerritoryDisplayPosition > 0
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// update displayed current territory for specified player; returns false if unsuccessful
|
||||
public static boolean updateTerritoryDisplay(FPlayer player) {
|
||||
if (!spoutMe || Conf.spoutTerritoryDisplayPosition == 0) {
|
||||
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(Factions.instance, 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;
|
||||
}
|
||||
|
||||
public static void playerDisconnect(FPlayer player) {
|
||||
if (!enabled()) {
|
||||
return;
|
||||
}
|
||||
territoryLabels.remove(player.getName());
|
||||
}
|
||||
|
||||
|
||||
// update all appearances between every player
|
||||
public static void updateAppearances() {
|
||||
if (!enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<FPlayer> players = FPlayer.getAllOnline();
|
||||
Faction factionA;
|
||||
|
||||
for (FPlayer playerA : players) {
|
||||
factionA = playerA.getFaction();
|
||||
for (FPlayer playerB : players) {
|
||||
updateSingle(playerB.getPlayer(), playerA.getPlayer(), factionA.getRelation(playerB), factionA, playerA.getTitle(), playerA.getRole());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update all appearances related to a specific player
|
||||
public static void updateAppearances(Player player) {
|
||||
if (!enabled() || player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<FPlayer> players = FPlayer.getAllOnline();
|
||||
FPlayer playerA = FPlayer.get(player);
|
||||
Faction factionA = playerA.getFaction();
|
||||
|
||||
for (FPlayer playerB : players) {
|
||||
Player player2 = playerB.getPlayer();
|
||||
Relation rel = factionA.getRelation(playerB);
|
||||
updateSingle(player2, player, rel, factionA, playerA.getTitle(), playerA.getRole());
|
||||
updateSingle(player, player2, rel, playerB.getFaction(), playerB.getTitle(), playerB.getRole());
|
||||
}
|
||||
}
|
||||
|
||||
// update all appearances related to a single faction
|
||||
public static void updateAppearances(Faction faction) {
|
||||
if (!enabled() || faction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<FPlayer> players = FPlayer.getAllOnline();
|
||||
Faction factionA, factionB;
|
||||
|
||||
for (FPlayer playerA : players) {
|
||||
factionA = playerA.getFaction();
|
||||
|
||||
for (FPlayer playerB : players) {
|
||||
factionB = playerB.getFaction();
|
||||
if (factionA != faction && factionB != faction) {
|
||||
continue;
|
||||
}
|
||||
updateSingle(playerB.getPlayer(), playerA.getPlayer(), factionA.getRelation(factionB), factionA, playerA.getTitle(), playerA.getRole());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update all appearances between two factions
|
||||
public static void updateAppearances(Faction factionA, Faction factionB) {
|
||||
if (!enabled() || factionA == null || factionB == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (FPlayer playerA : factionA.getFPlayersWhereOnline(true)) {
|
||||
for (FPlayer playerB : factionB.getFPlayersWhereOnline(true)) {
|
||||
Player player1 = playerA.getPlayer();
|
||||
Player player2 = playerB.getPlayer();
|
||||
Relation rel = factionA.getRelation(factionB);
|
||||
updateSingle(player2, player1, rel, factionA, playerA.getTitle(), playerA.getRole());
|
||||
updateSingle(player1, player2, rel, factionB, playerB.getTitle(), playerB.getRole());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// update a single appearance; internal use only by above public methods
|
||||
private static void updateSingle(Player viewer, Player viewed, Relation relation, Faction viewedFaction, String viewedTitle, Role viewedRole) {
|
||||
if (viewer == null || viewed == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
SpoutPlayer sPlayer = SpoutManager.getPlayer(viewer);
|
||||
|
||||
if (Conf.spoutFactionTagsOverNames || Conf.spoutFactionTitlesOverNames) {
|
||||
if (viewedFaction.isNormal()) {
|
||||
String addTag = "";
|
||||
if (Conf.spoutFactionTagsOverNames) {
|
||||
addTag += viewedFaction.getTag(relation.getColor().toString() + "[") + "]";
|
||||
}
|
||||
String rolePrefix = viewedRole.getPrefix();
|
||||
if (Conf.spoutFactionTitlesOverNames && (!viewedTitle.isEmpty() || !rolePrefix.isEmpty())) {
|
||||
addTag += (addTag.isEmpty() ? "" : " ") + viewedRole.getPrefix() + viewedTitle;
|
||||
}
|
||||
spoutApp.setPlayerTitle(sPlayer, viewed, addTag + "\n" + viewed.getDisplayName());
|
||||
}
|
||||
else {
|
||||
spoutApp.setPlayerTitle(sPlayer, viewed, viewed.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
(Conf.spoutFactionAdminCapes && viewedRole.equals(Role.ADMIN))
|
||||
|| (Conf.spoutFactionModeratorCapes && viewedRole.equals(Role.MODERATOR))
|
||||
) {
|
||||
String cape = "";
|
||||
if (!viewedFaction.isNormal()) {
|
||||
// yeah, no cape if no faction
|
||||
}
|
||||
else if (viewedFaction.isPeaceful()) {
|
||||
cape = Conf.capePeaceful;
|
||||
}
|
||||
else if (relation.isNeutral()) {
|
||||
cape = Conf.capeNeutral;
|
||||
}
|
||||
else if (relation.isMember()) {
|
||||
cape = Conf.capeMember;
|
||||
}
|
||||
else if (relation.isEnemy()) {
|
||||
cape = Conf.capeEnemy;
|
||||
}
|
||||
else if (relation.isAlly()) {
|
||||
cape = Conf.capeAlly;
|
||||
}
|
||||
|
||||
if (cape.isEmpty()) {
|
||||
spoutApp.resetPlayerCloak(sPlayer, viewed);
|
||||
} else {
|
||||
spoutApp.setPlayerCloak(sPlayer, viewed, cape);
|
||||
}
|
||||
}
|
||||
else if (Conf.spoutFactionAdminCapes || Conf.spoutFactionModeratorCapes) {
|
||||
spoutApp.resetPlayerCloak(sPlayer, viewed);
|
||||
}
|
||||
}
|
||||
|
||||
// method to convert a Bukkit ChatColor to a Spout Color
|
||||
private static Color getSpoutColor(ChatColor inColor, int alpha) {
|
||||
if (inColor == null) {
|
||||
return new Color(191, 191, 191, alpha);
|
||||
}
|
||||
switch (inColor.getCode()) {
|
||||
case 0x1: return new Color(0, 0, 191, alpha);
|
||||
case 0x2: return new Color(0, 191, 0, alpha);
|
||||
case 0x3: return new Color(0, 191, 191, alpha);
|
||||
case 0x4: return new Color(191, 0, 0, alpha);
|
||||
case 0x5: return new Color(191, 0, 191, alpha);
|
||||
case 0x6: return new Color(191, 191, 0, alpha);
|
||||
case 0x7: return new Color(191, 191, 191, alpha);
|
||||
case 0x8: return new Color(64, 64, 64, alpha);
|
||||
case 0x9: return new Color(64, 64, 255, alpha);
|
||||
case 0xA: return new Color(64, 255, 64, alpha);
|
||||
case 0xB: return new Color(64, 255, 255, alpha);
|
||||
case 0xC: return new Color(255, 64, 64, alpha);
|
||||
case 0xD: return new Color(255, 64, 255, alpha);
|
||||
case 0xE: return new Color(255, 255, 64, alpha);
|
||||
case 0xF: return new Color(255, 255, 255, alpha);
|
||||
default: return new Color(0, 0, 0, alpha);
|
||||
}
|
||||
}
|
||||
}
|
117
src/com/massivecraft/factions/integration/Worldguard.java
Normal file
117
src/com/massivecraft/factions/integration/Worldguard.java
Normal file
@ -0,0 +1,117 @@
|
||||
package com.massivecraft.factions.integration;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/*
|
||||
* Worldguard Region Checking
|
||||
* Author: Spathizilla
|
||||
*/
|
||||
|
||||
public class Worldguard {
|
||||
private static WorldGuardPlugin wg;
|
||||
private static boolean enabled = false;
|
||||
|
||||
public static void init(Plugin plugin) {
|
||||
Plugin wgplug = plugin.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
if (wgplug == null || !(wgplug instanceof WorldGuardPlugin)) {
|
||||
enabled = false;
|
||||
wg = null;
|
||||
Factions.log("Could not hook to WorldGuard. WorldGuard checks are disabled.");
|
||||
} else {
|
||||
wg = (WorldGuardPlugin) wgplug;
|
||||
enabled = true;
|
||||
Factions.log("Successfully hooked to WorldGuard.");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// PVP Flag check
|
||||
// Returns:
|
||||
// True: PVP is allowed
|
||||
// False: PVP is disallowed
|
||||
public static boolean isPVP(Player player) {
|
||||
if(!enabled) {
|
||||
// No WG hooks so we'll always bypass this check.
|
||||
return true;
|
||||
}
|
||||
|
||||
Location loc = player.getLocation();
|
||||
World world = loc.getWorld();
|
||||
Vector pt = toVector(loc);
|
||||
|
||||
RegionManager regionManager = wg.getRegionManager(world);
|
||||
ApplicableRegionSet set = regionManager.getApplicableRegions(pt);
|
||||
return set.allows(DefaultFlag.PVP);
|
||||
}
|
||||
|
||||
// Check for Regions in chunk the chunk
|
||||
// Returns:
|
||||
// True: Regions found within chunk
|
||||
// False: No regions found within chunk
|
||||
public static boolean checkForRegionsInChunk(Location loc) {
|
||||
if(!enabled) {
|
||||
// No WG hooks so we'll always bypass this check.
|
||||
return false;
|
||||
}
|
||||
|
||||
World world = loc.getWorld();
|
||||
Chunk chunk = world.getChunkAt(loc);
|
||||
int minChunkX = chunk.getX() << 4;
|
||||
int minChunkZ = chunk.getZ() << 4;
|
||||
int maxChunkX = minChunkX + 15;
|
||||
int maxChunkZ = minChunkZ + 15;
|
||||
|
||||
int worldHeight = world.getMaxHeight(); // Allow for heights other than default
|
||||
|
||||
BlockVector minChunk = new BlockVector(minChunkX, 0, minChunkZ);
|
||||
BlockVector maxChunk = new BlockVector(maxChunkX, worldHeight, maxChunkZ);
|
||||
|
||||
RegionManager regionManager = wg.getRegionManager(world);
|
||||
ProtectedCuboidRegion region = new ProtectedCuboidRegion("wgfactionoverlapcheck", minChunk, maxChunk);
|
||||
Map<String, ProtectedRegion> allregions = regionManager.getRegions();
|
||||
List<ProtectedRegion> allregionslist = new ArrayList<ProtectedRegion>(allregions.values());
|
||||
List<ProtectedRegion> overlaps;
|
||||
boolean foundregions = false;
|
||||
|
||||
try {
|
||||
overlaps = region.getIntersectingRegions(allregionslist);
|
||||
if(overlaps == null || overlaps.isEmpty()) {
|
||||
foundregions = false;
|
||||
} else {
|
||||
foundregions = true;
|
||||
}
|
||||
} catch (UnsupportedIntersectionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
region = null;
|
||||
allregionslist = null;
|
||||
overlaps = null;
|
||||
|
||||
return foundregions;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user