From 0039370f051ae720fa97b83c16a79250de3447bd Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 13 Oct 2011 12:17:23 +0200 Subject: [PATCH] Some effect for the f home teleport command --- src/com/massivecraft/factions/Conf.java | 2 + .../massivecraft/factions/cmd/CmdHome.java | 15 +++ .../listeners/FactionsEntityListener.java | 1 - .../factions/zcore/util/SmokeUtil.java | 91 +++++++++++++++++++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 src/com/massivecraft/factions/zcore/util/SmokeUtil.java diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index 5dc4f06a..5fbbb1e2 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -77,6 +77,8 @@ public class Conf public static boolean homesTeleportToOnDeath = true; public static boolean homesRespawnFromNoPowerLossWorlds = true; public static boolean homesTeleportCommandEnabled = true; + public static boolean homesTeleportCommandSmokeEffectEnabled = true; + public static float homesTeleportCommandSmokeEffectThickness = 3f; public static boolean homesTeleportAllowedFromEnemyTerritory = true; public static boolean homesTeleportAllowedFromDifferentWorld = true; public static double homesTeleportAllowedEnemyDistance = 32.0; diff --git a/src/com/massivecraft/factions/cmd/CmdHome.java b/src/com/massivecraft/factions/cmd/CmdHome.java index 79abd519..9236ffa8 100644 --- a/src/com/massivecraft/factions/cmd/CmdHome.java +++ b/src/com/massivecraft/factions/cmd/CmdHome.java @@ -1,5 +1,8 @@ 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; @@ -13,6 +16,7 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; +import com.massivecraft.factions.zcore.util.SmokeUtil; public class CmdHome extends FCommand { @@ -122,6 +126,17 @@ public class CmdHome 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(Conf.econCostHome, "to change faction home", "for changing faction home")) return; + // Create a smoke effect + if (Conf.homesTeleportCommandSmokeEffectEnabled) + { + List smokeLocations = new ArrayList(); + smokeLocations.add(me.getLocation()); + smokeLocations.add(me.getLocation().add(0, 1, 0)); + smokeLocations.add(myFaction.getHome()); + smokeLocations.add(myFaction.getHome().add(0, 1, 0)); + SmokeUtil.spawnCloudRandom(smokeLocations, Conf.homesTeleportCommandSmokeEffectThickness); + } + me.teleport(myFaction.getHome()); } diff --git a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java index 7aec88ea..5c072aa5 100644 --- a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -29,7 +29,6 @@ import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; import com.massivecraft.factions.P; -import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.util.MiscUtil; diff --git a/src/com/massivecraft/factions/zcore/util/SmokeUtil.java b/src/com/massivecraft/factions/zcore/util/SmokeUtil.java new file mode 100644 index 00000000..f0f627c0 --- /dev/null +++ b/src/com/massivecraft/factions/zcore/util/SmokeUtil.java @@ -0,0 +1,91 @@ +package com.massivecraft.factions.zcore.util; + +import java.util.Collection; +import java.util.Random; + +import org.bukkit.Effect; +import org.bukkit.Location; + +// http://mc.kev009.com/Protocol +// ----------------------------- +// Smoke Directions +// ----------------------------- +// Direction ID Direction +// 0 South - East +// 1 South +// 2 South - West +// 3 East +// 4 (Up or middle ?) +// 5 West +// 6 North - East +// 7 North +// 8 North - West +//----------------------------- + +public class SmokeUtil +{ + public static Random random = new Random(); + + // -------------------------------------------- // + // Spawn once + // -------------------------------------------- // + + // Single ======== + public static void spawnSingle(Location location, int direction) + { + if (location == null) return; + location.getWorld().playEffect(location, Effect.SMOKE, direction); + } + + public static void spawnSingle(Location location) + { + spawnSingle(location, 4); + } + + public static void spawnSingleRandom(Location location) + { + spawnSingle(location, random.nextInt(9)); + } + + // Simple Cloud ======== + public static void spawnCloudSimple(Location location) + { + for (int i = 0; i <= 8; i++) + { + spawnSingle(location, i); + } + } + + public static void spawnCloudSimple(Collection locations) + { + for (Location location : locations) + { + spawnCloudSimple(location); + } + } + + // Random Cloud ======== + public static void spawnCloudRandom(Location location, float thickness) + { + int singles = (int) Math.floor(thickness*9); + for (int i = 0; i < singles; i++) + { + spawnSingleRandom(location); + } + } + + public static void spawnCloudRandom(Collection locations, float thickness) + { + for (Location location : locations) + { + spawnCloudRandom(location, thickness); + } + } + + // -------------------------------------------- // + // Attach continuous effects to or locations + // -------------------------------------------- // + + // TODO + +}