Get rid of Essentials integrations, use MCore teleporter for now and PS homes. As for chat I need to rewrite the chat system. Essentials integration can be readded later if needed.

This commit is contained in:
Olof Larsson
2013-04-17 11:47:48 +02:00
parent 4449b56246
commit 109d6059ce
15 changed files with 88 additions and 291 deletions

View File

@ -36,8 +36,10 @@ public class ConfServer extends SimpleConfig
//public static ChatColor colorWilderness = ChatColor.DARK_GREEN;
public static Map<FFlag, Boolean> factionFlagDefaults;
public static Map<FFlag, Boolean> factionFlagIsChangeable;
//public static Map<FFlag, Boolean> factionFlagIsChangeable;
public static Map<FPerm, Set<Rel>> factionPermDefaults;
// TODO: Shouldn't this be a constant rather?
public static Rel factionRankDefault = Rel.RECRUIT;
// Power
@ -108,6 +110,10 @@ public class ConfServer extends SimpleConfig
public static String herochatAllyName = "Allies";
// TODO: Does anyone toggle this feature on I wonder?
// It could work for small servers but never for big ones.
// Why not conform to big server setups at once?
// POSSIBLY: Remove this option
public static boolean broadcastDescriptionChanges = false;
public static double autoLeaveAfterDaysOfInactivity = 10.0;
@ -140,18 +146,15 @@ public class ConfServer extends SimpleConfig
public static boolean homesEnabled = true;
public static boolean homesMustBeInClaimedTerritory = true;
public static boolean homesTeleportToOnDeath = true;
public static boolean homesRespawnFromNoPowerLossWorlds = true;
public static boolean homesTeleportCommandEnabled = true;
public static boolean homesTeleportCommandEssentialsIntegration = true;
public static boolean homesTeleportCommandSmokeEffectEnabled = true;
public static boolean homesTeleportAllowedFromEnemyTerritory = true;
public static boolean homesTeleportAllowedFromDifferentWorld = true;
public static double homesTeleportAllowedEnemyDistance = 32.0;
public static boolean homesTeleportIgnoreEnemiesIfInOwnTerritory = true;
// TODO: This one should not be in the config should it? It should be built into the enum?
public static Rel friendlyFireFromRel = Rel.TRUCE;
public static boolean disablePVPForFactionlessPlayers = false;
public static boolean enablePVPAgainstFactionlessInAttackersLand = false;
@ -261,6 +264,8 @@ public class ConfServer extends SimpleConfig
public static Set<String> playersWhoBypassAllProtection = new LinkedHashSet<String>();
public static Set<String> worldsNoClaiming = new LinkedHashSet<String>();
// TODO: Should worldsNoPowerLoss rather be a bukkit permission node?
public static Set<String> worldsNoPowerLoss = new LinkedHashSet<String>();
public static Set<String> worldsIgnorePvP = new LinkedHashSet<String>();
// TODO: A better solution Would be to have One wilderness faction per world.

View File

@ -5,7 +5,6 @@ import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -73,31 +72,12 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
private Map<String, Rel> relationWish = null;
// FIELD: home
// TODO: Use a PS instead!
private LazyLocation home;
public void setHome(Location home) { this.home = new LazyLocation(home); }
public boolean hasHome() { return this.getHome() != null; }
public Location getHome()
{
confirmValidHome();
return (this.home != null) ? this.home.getLocation() : null;
}
public void confirmValidHome()
{
if (!ConfServer.homesMustBeInClaimedTerritory || this.home == null || (this.home.getLocation() != null && BoardColl.get().getFactionAt(PS.valueOf(this.home.getLocation())) == this))
return;
msg("<b>Your faction home has been un-set since it is no longer in your territory.");
this.home = null;
}
private PS home = null;
// FIELD: cape
private String cape;
public String getCape() { return cape; }
public void setCape(String val) { this.cape = val; SpoutFeatures.updateCape(this, null); }
// The cape field is a URL used by the Spout integration features.
private String cape = null;
// The powerBoost is a custom increase/decrease to default and max power for this faction
// The powerBoost is a custom increase/decrease to default and max power for this faction.
private Double powerBoost = null;
// The flag overrides are the modifications to the default values
@ -455,6 +435,58 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
this.deinvite(fplayer.getId());
}
// -------------------------------------------- //
// FIELD: home
// -------------------------------------------- //
// TODO: Checkery is a bit weird?
public PS getHome()
{
this.verifyHomeIsValid();
return this.home;
}
public void verifyHomeIsValid()
{
if (this.isValidHome(this.home)) return;
this.home = null;
msg("<b>Your faction home has been un-set since it is no longer in your territory.");
}
public boolean isValidHome(PS ps)
{
if (ps == null) return true;
if (!ConfServer.homesMustBeInClaimedTerritory) return true;
if (BoardColl.get().getFactionAt(ps) == this) return true;
return false;
}
public boolean hasHome()
{
return this.getHome() != null;
}
public void setHome(PS home)
{
this.home = home;
}
// -------------------------------------------- //
// FIELD: cape
// -------------------------------------------- //
public String getCape()
{
return cape;
}
public void setCape(String cape)
{
this.cape = cape;
SpoutFeatures.updateCape(this, null);
}
// -------------------------------------------- //
// FIELD: powerBoost
// -------------------------------------------- //

View File

@ -4,13 +4,11 @@ import com.massivecraft.factions.adapters.BoardAdapter;
import com.massivecraft.factions.adapters.BoardMapAdapter;
import com.massivecraft.factions.adapters.FFlagAdapter;
import com.massivecraft.factions.adapters.FPermAdapter;
import com.massivecraft.factions.adapters.LazyLocationAdapter;
import com.massivecraft.factions.adapters.RelAdapter;
import com.massivecraft.factions.adapters.TerritoryAccessAdapter;
import com.massivecraft.factions.cmd.*;
import com.massivecraft.factions.integration.herochat.HerochatFeatures;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.EssentialsFeatures;
import com.massivecraft.factions.integration.LWCFeatures;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.integration.Worldguard;
@ -21,7 +19,6 @@ import com.massivecraft.factions.listeners.FactionsExploitListener;
import com.massivecraft.factions.listeners.FactionsPlayerListener;
import com.massivecraft.factions.util.AutoLeaveTask;
import com.massivecraft.factions.util.EconLandRewardTask;
import com.massivecraft.factions.util.LazyLocation;
import com.massivecraft.mcore.MPlugin;
import com.massivecraft.mcore.xlib.gson.GsonBuilder;
@ -77,7 +74,6 @@ public class Factions extends MPlugin
this.outerCmdFactions = new CmdFactions();
this.outerCmdFactions.register(this);
EssentialsFeatures.setup();
SpoutFeatures.setup();
Econ.setup();
HerochatFeatures.setup();
@ -119,7 +115,6 @@ public class Factions extends MPlugin
public GsonBuilder getGsonBuilder()
{
return super.getGsonBuilder()
.registerTypeAdapter(LazyLocation.class, new LazyLocationAdapter())
.registerTypeAdapter(TerritoryAccess.class, TerritoryAccessAdapter.get())
.registerTypeAdapter(Board.class, BoardAdapter.get())
.registerTypeAdapter(Board.MAP_TYPE, BoardMapAdapter.get())
@ -132,7 +127,6 @@ public class Factions extends MPlugin
@Override
public void onDisable()
{
EssentialsFeatures.unhookChat();
if (AutoLeaveTask != null)
{
this.getServer().getScheduler().cancelTask(AutoLeaveTask);

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions;
import java.util.LinkedHashSet;
import java.util.Set;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class TerritoryAccess
@ -98,7 +99,7 @@ public class TerritoryAccess
{
if (testSubject instanceof String)
return hostFactionId.equals((String)testSubject);
else if (testSubject instanceof Player)
else if (testSubject instanceof CommandSender)
return hostFactionId.equals(FPlayerColl.get().get(testSubject).getFactionId());
else if (testSubject instanceof FPlayer)
return hostFactionId.equals(((FPlayer)testSubject).getFactionId());

View File

@ -1,74 +0,0 @@
package com.massivecraft.factions.adapters;
import java.lang.reflect.Type;
import java.util.logging.Level;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.util.LazyLocation;
import com.massivecraft.mcore.xlib.gson.JsonDeserializationContext;
import com.massivecraft.mcore.xlib.gson.JsonDeserializer;
import com.massivecraft.mcore.xlib.gson.JsonElement;
import com.massivecraft.mcore.xlib.gson.JsonObject;
import com.massivecraft.mcore.xlib.gson.JsonParseException;
import com.massivecraft.mcore.xlib.gson.JsonSerializationContext;
import com.massivecraft.mcore.xlib.gson.JsonSerializer;
public class LazyLocationAdapter implements JsonDeserializer<LazyLocation>, JsonSerializer<LazyLocation>
{
private static final String WORLD = "world";
private static final String X = "x";
private static final String Y = "y";
private static final String Z = "z";
private static final String YAW = "yaw";
private static final String PITCH = "pitch";
@Override
public LazyLocation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
try
{
JsonObject obj = json.getAsJsonObject();
String worldName = obj.get(WORLD).getAsString();
double x = obj.get(X).getAsDouble();
double y = obj.get(Y).getAsDouble();
double z = obj.get(Z).getAsDouble();
float yaw = obj.get(YAW).getAsFloat();
float pitch = obj.get(PITCH).getAsFloat();
return new LazyLocation(worldName, x, y, z, yaw, pitch);
}
catch (Exception ex)
{
ex.printStackTrace();
Factions.get().log(Level.WARNING, "Error encountered while deserializing a LazyLocation.");
return null;
}
}
@Override
public JsonElement serialize(LazyLocation src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject obj = new JsonObject();
try
{
obj.addProperty(WORLD, src.getWorldName());
obj.addProperty(X, src.getX());
obj.addProperty(Y, src.getY());
obj.addProperty(Z, src.getZ());
obj.addProperty(YAW, src.getYaw());
obj.addProperty(PITCH, src.getPitch());
return obj;
}
catch (Exception ex)
{
ex.printStackTrace();
Factions.get().log(Level.WARNING, "Error encountered while serializing a LazyLocation.");
return obj;
}
}
}

View File

@ -1,8 +1,5 @@
package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -17,11 +14,11 @@ import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
import com.massivecraft.factions.integration.EssentialsFeatures;
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
import com.massivecraft.mcore.mixin.Mixin;
import com.massivecraft.mcore.mixin.TeleporterException;
import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.util.SmokeUtil;
public class CmdFactionsHome extends FCommand
@ -64,7 +61,7 @@ public class CmdFactionsHome extends FCommand
return;
}
if ( ! ConfServer.homesTeleportAllowedFromDifferentWorld && me.getWorld().getUID() != myFaction.getHome().getWorld().getUID())
if (!ConfServer.homesTeleportAllowedFromDifferentWorld && !me.getWorld().getName().equalsIgnoreCase(myFaction.getHome().getWorld()))
{
fme.msg("<b>You cannot teleport to your faction home while in a different world.");
return;
@ -121,24 +118,17 @@ public class CmdFactionsHome extends FCommand
}
}
// if Essentials teleport handling is enabled and available, pass the teleport off to it (for delay and cooldown)
if (EssentialsFeatures.handleTeleport(me, myFaction.getHome())) return;
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(ConfServer.econCostHome, "to teleport to your faction home", "for teleporting to your faction home")) return;
// Create a smoke effect
if (ConfServer.homesTeleportCommandSmokeEffectEnabled)
try
{
List<Location> smokeLocations = new ArrayList<Location>();
smokeLocations.add(loc);
smokeLocations.add(loc.add(0, 1, 0));
smokeLocations.add(myFaction.getHome());
smokeLocations.add(myFaction.getHome().clone().add(0, 1, 0));
SmokeUtil.spawnCloudRandom(smokeLocations, 3f);
Mixin.teleport(me, myFaction.getHome(), "your faction home", sender);
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(ConfServer.econCostHome, "to teleport to your faction home", "for teleporting to your faction home")) return;
}
catch (TeleporterException e)
{
me.sendMessage(e.getMessage());
}
me.teleport(myFaction.getHome());
}
}

View File

@ -1,6 +1,5 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.BoardColl;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Faction;
@ -26,6 +25,7 @@ public class CmdFactionsSethome extends FCommand
@Override
public void perform()
{
// TODO: Make a command REQ instead?
if ( ! ConfServer.homesEnabled)
{
fme.msg("<b>Sorry, Faction homes are disabled on this server.");
@ -35,18 +35,13 @@ public class CmdFactionsSethome extends FCommand
Faction faction = this.arg(0, ARFaction.get(), myFaction);
if (faction == null) return;
// Can the player set the home for this faction?
// Has faction permission?
if ( ! FPerm.SETHOME.has(sender, faction, true)) return;
PS ps = PS.valueOf(me.getLocation());
// Can the player set the faction home HERE?
if
(
! fme.isUsingAdminMode()
&&
ConfServer.homesMustBeInClaimedTerritory
&&
BoardColl.get().getFactionAt(PS.valueOf(me)) != faction
)
if (!fme.isUsingAdminMode() && !faction.isValidHome(ps))
{
fme.msg("<b>Sorry, your faction home can only be set inside your own claimed territory.");
return;
@ -55,7 +50,7 @@ public class CmdFactionsSethome extends FCommand
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(ConfServer.econCostSethome, "to set the faction home", "for setting the faction home")) return;
faction.setHome(me.getLocation());
faction.setHome(ps);
faction.msg("%s<i> set the home for your faction. You can now use:", fme.describeTo(myFaction, true));
faction.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsHome.getUseageTemplate());

View File

@ -1,119 +0,0 @@
package com.massivecraft.factions.integration;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.Location;
import org.bukkit.plugin.Plugin;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.listeners.FactionsChatListener;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.Teleport;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.chat.EssentialsChat;
import com.earth2me.essentials.chat.EssentialsLocalChatEvent;
/*
* This Essentials integration handler is for newer 3.x.x versions of Essentials which don't have "IEssentialsChatListener"
* If an older version is detected in the setup() method below, handling is passed off to EssentialsOldVersionFeatures
*/
// silence deprecation warnings with this old interface
@SuppressWarnings("deprecation")
public class EssentialsFeatures
{
private static EssentialsChat essChat;
private static IEssentials essentials;
public static void setup()
{
// integrate main essentials plugin
// TODO: this is the old Essentials method not supported in 3.0... probably needs to eventually be moved to EssentialsOldVersionFeatures and new method implemented
if (essentials == null)
{
Plugin ess = Bukkit.getPluginManager().getPlugin("Essentials");
if (ess != null && ess.isEnabled())
essentials = (IEssentials)ess;
}
// integrate chat
if (essChat != null) return;
Plugin test = Bukkit.getServer().getPluginManager().getPlugin("EssentialsChat");
if (test == null || !test.isEnabled()) return;
essChat = (EssentialsChat)test;
// try newer Essentials 3.x integration method
try
{
Class.forName("com.earth2me.essentials.chat.EssentialsLocalChatEvent");
integrateChat(essChat);
}
catch (ClassNotFoundException ex)
{
}
}
public static void unhookChat()
{
if (essChat == null) return;
}
// return false if feature is disabled or Essentials isn't available
public static boolean handleTeleport(Player player, Location loc)
{
if ( ! ConfServer.homesTeleportCommandEssentialsIntegration || essentials == null) return false;
Teleport teleport = (Teleport) essentials.getUser(player).getTeleport();
Trade trade = new Trade(ConfServer.econCostHome, essentials);
try
{
teleport.teleport(loc, trade);
}
catch (Exception e)
{
player.sendMessage(ChatColor.RED.toString()+e.getMessage());
}
return true;
}
public static void integrateChat(EssentialsChat instance)
{
essChat = instance;
try
{
Bukkit.getServer().getPluginManager().registerEvents(new LocalChatListener(), Factions.get());
Factions.get().log("Found and will integrate chat with newer "+essChat.getDescription().getFullName());
}
catch (NoSuchMethodError ex)
{
essChat = null;
}
}
private static class LocalChatListener implements Listener
{
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerChat(EssentialsLocalChatEvent event)
{
Player speaker = event.getPlayer();
String format = event.getFormat();
format = FactionsChatListener.parseTags(format, speaker);
event.setFormat(format);
// NOTE: above doesn't do relation coloring. if/when we can get a local recipient list from EssentialsLocalChatEvent, we'll probably
// want to pass it on to FactionsPlayerListener.onPlayerChat(PlayerChatEvent event) rather than duplicating code
}
}
}

View File

@ -81,6 +81,7 @@ public class SpoutFeatures
String cape = faction.getCape();
if (cape == null)
{
// TODO: This URL is outdated?
cape = "http://s3.amazonaws.com/MinecraftCloaks/" + player.getName() + ".png";
}

View File

@ -21,7 +21,6 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.util.NumberConversions;
import com.massivecraft.factions.BoardColl;
@ -227,33 +226,6 @@ public class FactionsPlayerListener implements Listener
return true;
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerRespawn(PlayerRespawnEvent event)
{
FPlayer me = FPlayerColl.get().get(event.getPlayer());
me.getPower(); // update power, so they won't have gained any while dead
Location home = me.getFaction().getHome(); // TODO: WARNING FOR NPE HERE THE ORIO FOR RESPAWN SHOULD BE ASSIGNABLE FROM CONFIG.
if
(
ConfServer.homesEnabled
&&
ConfServer.homesTeleportToOnDeath
&&
home != null
&&
(
ConfServer.homesRespawnFromNoPowerLossWorlds
||
! ConfServer.worldsNoPowerLoss.contains(event.getPlayer().getWorld().getName())
)
)
{
event.setRespawnLocation(home);
}
}
// For some reason onPlayerInteract() sometimes misses bucket events depending on distance (something like 2-3 blocks away isn't detected),
// but these separate bucket events below always fire without fail
@EventHandler(priority = EventPriority.NORMAL)