Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex

This commit is contained in:
Jonathan Williams 2014-10-23 23:58:24 -07:00
commit 27dc9f7693
20 changed files with 422 additions and 87 deletions

View File

@ -85,7 +85,7 @@ public class UtilBlock
return !blockPassSet.contains(block);
}
public static HashSet<Byte> blockAirFoliageSet = new HashSet<Byte>();
public static boolean airFoliage(Block block)
{
@ -119,13 +119,13 @@ public class UtilBlock
return blockAirFoliageSet.contains(block);
}
public static HashSet<Byte> fullSolid = new HashSet<Byte>();
public static boolean fullSolid(Block block)
{
if (block == null)
return false;
return fullSolid(block.getTypeId());
}
public static boolean fullSolid(int block)
@ -215,7 +215,7 @@ public class UtilBlock
{
if (block == null)
return false;
return usable(block.getTypeId());
}
public static boolean usable(int block)
@ -253,7 +253,7 @@ public class UtilBlock
return blockUseSet.contains(block);
}
public static HashMap<Block, Double> getInRadius(Location loc, double dR)
{
return getInRadius(loc, dR, 9999);
@ -270,7 +270,7 @@ public class UtilBlock
{
if (Math.abs(y) > maxHeight)
continue;
Block curBlock = loc.getWorld().getBlockAt((int)(loc.getX()+x), (int)(loc.getY()+y), (int)(loc.getZ()+z));
double offset = UtilMath.offset(loc, curBlock.getLocation().add(0.5, 0.5, 0.5));;
@ -281,7 +281,7 @@ public class UtilBlock
return blockList;
}
public static HashMap<Block, Double> getInRadius(Block block, double dR)
{
HashMap<Block, Double> blockList = new HashMap<Block, Double>();
@ -301,7 +301,7 @@ public class UtilBlock
return blockList;
}
public static ArrayList<Block> getInSquare(Block block, double dR)
{
ArrayList<Block> blockList = new ArrayList<Block>();
@ -316,38 +316,41 @@ public class UtilBlock
return blockList;
}
public static boolean isBlock(ItemStack item)
{
if (item == null)
return false;
return item.getTypeId() > 0 && item.getTypeId() < 256;
}
public static Block getHighest(World world, int x, int z)
{
return getHighest(world, x, z, null);
}
public static Block getHighest(World world, int x, int z, HashSet<Material> ignore)
{
Block block = world.getHighestBlockAt(x, z);
//Shuffle Down
while (airFoliage(block) ||
block.getType() == Material.LEAVES ||
(ignore != null && ignore.contains(block.getType())))
while (block.getY() > 0 &&
(
airFoliage(block) ||
block.getType() == Material.LEAVES ||
(ignore != null && ignore.contains(block.getType()))
))
{
block = block.getRelative(BlockFace.DOWN);
}
return block.getRelative(BlockFace.UP);
}
public static ArrayList<Block> getSurrounding(Block block, boolean diagonals)
{
ArrayList<Block> blocks = new ArrayList<Block>();
if (diagonals)
{
for (int x=-1 ; x<= 1 ; x++)
@ -356,7 +359,7 @@ public class UtilBlock
{
if (x == 0 && y == 0 && z == 0)
continue;
blocks.add(block.getRelative(x, y, z));
}
}
@ -369,10 +372,10 @@ public class UtilBlock
blocks.add(block.getRelative(BlockFace.EAST));
blocks.add(block.getRelative(BlockFace.WEST));
}
return blocks;
}
public static boolean isVisible(Block block)
{
for (Block other : UtilBlock.getSurrounding(block, false))
@ -382,7 +385,7 @@ public class UtilBlock
return true;
}
}
return false;
}
}

View File

@ -265,7 +265,7 @@ public class NpcManager extends MiniPlugin
String inHand = itemStackToYaml(player.getInventory().getItemInHand());
NpcsRecord npcsRecord = DSL.using(connection).newRecord(Tables.npcs);
npcsRecord.setServer(GetPlugin().getClass().getSimpleName());
npcsRecord.setServer(getServerName());
npcsRecord.setName(name);
npcsRecord.setWorld(player.getWorld().getName());
npcsRecord.setX(player.getLocation().getX());
@ -410,7 +410,7 @@ public class NpcManager extends MiniPlugin
((EntityInsentient) ((CraftLivingEntity) entity).getHandle()).persistent = true;
UtilEnt.silence(entity, true);
if (!entity.getLocation().getChunk().isLoaded() || !(entity instanceof CraftCreature))
if (!entity.getLocation().getChunk().isLoaded())
continue;
if (!entity.isDead() && entity.isValid())
@ -476,7 +476,7 @@ public class NpcManager extends MiniPlugin
public void loadNpcs() throws SQLException
{
String serverType = _plugin.getClass().getSimpleName();
String serverType = getServerName();
try (Connection connection = DBPool.getInstance().getConnection())
{
@ -502,7 +502,7 @@ public class NpcManager extends MiniPlugin
{
if (deleteFromDatabase)
{
String serverType = _plugin.getClass().getSimpleName();
String serverType = getServerName();
try (Connection connection = DBPool.getInstance().getConnection())
{
@ -585,4 +585,14 @@ public class NpcManager extends MiniPlugin
if (npc != null)
npc.setEntity(null);
}
public String getServerName()
{
String serverName = GetPlugin().getClass().getSimpleName();
if (Bukkit.getMotd() != null && Bukkit.getMotd().equalsIgnoreCase("test"))
serverName += "-Test";
return serverName;
}
}

View File

@ -13,10 +13,12 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Sheep;
import org.bukkit.entity.Snowball;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.ItemSpawnEvent;
@ -24,6 +26,8 @@ import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@ -50,6 +54,7 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
@ -64,6 +69,7 @@ import mineplex.core.donation.DonationManager;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.event.GadgetActivateEvent;
import mineplex.core.gadget.event.GadgetCollideEntityEvent;
import mineplex.core.hologram.ArmorStandHologram;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.mount.MountManager;
@ -993,4 +999,41 @@ public class HubManager extends MiniClientPlugin<HubClient>
if (!_gadgetsEnabled)
event.setCancelled(true);
}
@EventHandler
public void debug(PlayerCommandPreprocessEvent event)
{
Player player = event.getPlayer();
if (event.getMessage().contains("sheep"))
{
player.setPassenger(player.getWorld().spawn(player.getLocation(), Sheep.class));
}
if (event.getMessage().contains("drop"))
{
player.eject();
}
}
@EventHandler
public void damage(EntityDamageByEntityEvent event)
{
Entity ent = UtilEvent.GetDamagerEntity(event, false);
if (ent != null && ent instanceof Player)
System.out.println("DAMAGE");
}
@EventHandler
public void interactent(PlayerInteractEntityEvent event)
{
System.out.println("ENT INTERACT");
System.out.println(event.getPlayer().getTargetBlock(null, 0));
}
@EventHandler
public void interact(PlayerInteractEvent event)
{
System.out.println("INTERACT");
}
}

View File

@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/craftbukkit.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core.Common"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/craftbukkit.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -14,9 +14,11 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Sheep;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -24,9 +26,11 @@ import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
@ -40,6 +44,7 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
@ -225,7 +230,7 @@ public class MapParser extends JavaPlugin implements Listener
}
}
@EventHandler
//@EventHandler
public void DisableCreatures(EntitySpawnEvent event)
{
if (event.getEntityType() == EntityType.DROPPED_ITEM || event.getEntity() instanceof LivingEntity)
@ -520,4 +525,41 @@ public class MapParser extends JavaPlugin implements Listener
{
event.setQuitMessage(F.sys("Player Quit", event.getPlayer().getName()));
}
@EventHandler
public void damage(EntityDamageByEntityEvent event)
{
Entity ent = UtilEvent.GetDamagerEntity(event, false);
if (ent != null && ent instanceof Player)
System.out.println("DAMAGE");
}
@EventHandler
public void interactent(PlayerInteractEntityEvent event)
{
System.out.println("ENT INTERACT");
System.out.println(event.getPlayer().getTargetBlock(null, 0));
}
@EventHandler
public void interact(PlayerInteractEvent event)
{
System.out.println("INTERACT");
}
@EventHandler
public void debug(PlayerCommandPreprocessEvent event)
{
Player player = event.getPlayer();
if (event.getMessage().contains("sheep"))
{
player.setPassenger(player.getWorld().spawn(player.getLocation(), Sheep.class));
}
if (event.getMessage().contains("drop"))
{
player.eject();
}
}
}

View File

@ -119,13 +119,13 @@ public class Arcade extends JavaPlugin
GadgetManager gadgetManager = new GadgetManager(this, _clientManager, _donationManager, inventoryManager, mountManager, petManager, preferenceManager, disguiseManager, blockRestore, projectileManager);
CosmeticManager cosmeticManager = new CosmeticManager(this, _clientManager, _donationManager, inventoryManager, gadgetManager, mountManager, petManager, true);
cosmeticManager.setInterfaceSlot(7);
new CustomTagFix(this, packetHandler);
//Arcade Manager
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, webServerAddress);
new PlayerTracker(this, serverStatusManager.getCurrentServerName(), serverStatusManager.getUs());
new MemoryFix(this);
new CustomTagFix(this, packetHandler);
new FriendManager(this, preferenceManager);

View File

@ -98,6 +98,7 @@ import nautilus.game.arcade.managers.GamePlayerManager;
import nautilus.game.arcade.managers.GameStatManager;
import nautilus.game.arcade.managers.GameTournamentManager;
import nautilus.game.arcade.managers.GameWorldManager;
import nautilus.game.arcade.managers.HalloweenManager;
import nautilus.game.arcade.managers.IdleManager;
import nautilus.game.arcade.managers.MiscManager;
import nautilus.game.arcade.shop.ArcadeShop;
@ -253,7 +254,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_gameWorldManager = new GameWorldManager(this);
new MiscManager(this);
new IdleManager(this);
new HalloweenManager(this);
_arcadeRepository = new ArcadeRepository(plugin);
// Game Addons
new CompassAddon(plugin, this);

View File

@ -29,7 +29,7 @@ public class KitPig extends Kit
new Perk[]
{
new PerkBodySlam(6, 2),
new PerkJump(1),
//new PerkJump(1), MAC
},
EntityType.PIG,
new ItemStack(Material.PORK));

View File

@ -342,16 +342,16 @@ public class Draw extends SoloGame
if (!_drawers.HasPlayer(event.getPlayer()))
return;
if (UtilMath.offset(event.getFrom(), event.getTo()) > 0)
if (UtilMath.offset(_drawerLocation, event.getTo()) > 1)
{
event.setTo(event.getFrom());
event.setTo(_drawerLocation);
Player player = event.getPlayer();
if (Recharge.Instance.use(player, "Instruct", 1000, false, false))
{
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 0.5f);
UtilPlayer.message(player, C.cRed + C.Bold + "Block with your Sword to Draw!");
UtilPlayer.message(player, C.cRed + C.Bold + "Hold Block with a Sword to Draw!");
}
}
}

View File

@ -453,7 +453,7 @@ public class Halloween extends SoloGame
{
Material type = event.getEntity().getItemStack().getType();
if (type == Material.DIAMOND_AXE || type == Material.BLAZE_POWDER || type == Material.SNOW_BALL)
if (type == Material.DIAMOND_AXE || type == Material.BLAZE_POWDER || type == Material.SNOW_BALL || type == Material.getMaterial(175))
return;
event.setCancelled(true);
@ -609,8 +609,8 @@ public class Halloween extends SoloGame
if (player.getFoodLevel() <= 2)
{
if (Recharge.Instance.use(player, "Food Message", 4000, false, false))
UtilPlayer.message(player, F.main("Game", "Attack monsters players to restore hunger!"));
if (Recharge.Instance.use(player, "Food Message", 6000, false, false))
UtilPlayer.message(player, F.main("Game", "Attack monsters to restore hunger!"));
}
if (hungerTick == 0)

View File

@ -486,6 +486,9 @@ public class HideSeek extends TeamGame
@EventHandler
public void FallingBlockBreak(ItemSpawnEvent event)
{
if (event.getEntity().getItemStack().getType() == Material.getMaterial(175))
return;
event.setCancelled(true);
for (Form form : _forms.values())

View File

@ -2267,6 +2267,7 @@ public class MineStrike extends TeamGame
//if (Manager.GetCondition().GetActiveCondition(event.getPlayer(), ConditionType.BLINDNESS) == null)
Manager.GetCondition().Factory().Blind("Scope Blind", event.getPlayer(), null, 1, 0, false, false, false);
Manager.GetCondition().Factory().NightVision("Scope Accuracy", event.getPlayer(), null, 0.5, 0, false, false, false);
}
}
else
@ -2535,6 +2536,9 @@ public class MineStrike extends TeamGame
if (_bombItem != null && _bombItem.equals(ent))
continue;
if (ent instanceof Item && ((Item)ent).getItemStack().getTypeId() == 175)
continue;
ent.remove();
}

View File

@ -46,7 +46,7 @@ public class Bullet
public double getDamageDropoff(Location destination)
{
return -Gun.getDamage() * (Gun.getDropOff() * UtilMath.offset(Origin, destination));
return Math.max(-Gun.getDamage() + 0.5, -Gun.getDamage() * (Gun.getDropOff() * UtilMath.offset(Origin, destination)));
}
public boolean bulletSound()

View File

@ -29,6 +29,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Snowball;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
public class Gun extends StrikeItem
@ -183,40 +184,44 @@ public class Gun extends StrikeItem
{
double cone = _cone;
//Move Penalty
if (!UtilTime.elapsed(_lastMoveTime, 75))
cone += _lastMove * _gunStats.getGunType().getMovePenalty();
//Airborne Penalty
if (!UtilEnt.isGrounded(player))
cone += _gunStats.getGunType().getJumpPenalty();
//Sprint Penalty
if (player.isSprinting())
else if (player.isSprinting())
cone += _gunStats.getGunType().getSprintPenalty();
//Airborne Penalty
else if (!UtilEnt.isGrounded(player))
cone += _gunStats.getGunType().getJumpPenalty();
//Move Penalty
else if (!UtilTime.elapsed(_lastMoveTime, 75))
cone += _lastMove * _gunStats.getGunType().getMovePenalty();
//Crouch
else if (player.isSneaking() && _gunStats.getGunType() != GunType.SNIPER)
cone = cone * 0.8;
System.out.println("Vision: " + player.hasPotionEffect(PotionEffectType.NIGHT_VISION));
//Sniper Zoomed
if (_gunStats.getScope() && UtilGear.isMat(player.getInventory().getHelmet(), Material.PUMPKIN))
if (!player.hasPotionEffect(PotionEffectType.NIGHT_VISION) && _gunStats.getScope() && UtilGear.isMat(player.getInventory().getHelmet(), Material.PUMPKIN))
{
//Snipers Perfectly Accurate if not jumping
if (_gunStats.getGunType() == GunType.SNIPER)
{
cone = 0;
//Airborne Penalty
if (!UtilEnt.isGrounded(player))
cone += _gunStats.getGunType().getJumpPenalty();
}
//30% Recoil Decrease
//25% Recoil Decrease
else
{
cone = cone * 0.7;
cone = cone * 0.75;
}
}
System.out.println("Cone: " + cone);
return cone;
}

View File

@ -152,7 +152,7 @@ public enum GunStats
10, 3, //Clip Size, Spare Ammo
1500, 3600, //ROF, Reload Time
115, 0, 0.97, //Damage, Dropoff, Armor Penetration
0.14, 0.14, //COF Min, COF Max
0.2, 0.2, //COF Min, COF Max
0, //COF Inc per Bullet
Material.GOLD_SPADE, Sound.DRINK, true, 1),
@ -176,7 +176,7 @@ public enum GunStats
1200, 5000, //Cost, Gem Cost
8, 4, //Clip Size, Spare Ammo
1000, 600, //ROF, Reload Time
26, 0.04, 0.5, //Damage, Dropoff, Armor Penetration
20, 0.04, 0.5, //Damage, Dropoff, Armor Penetration
0.1, 0.1, //COF Min, COF Max
0, //COF Inc per Bullet
Material.GOLD_AXE, Sound.BLAZE_DEATH, false, 9),
@ -188,7 +188,7 @@ public enum GunStats
2000, 5000, //Cost, Gem Cost
7, 4, //Clip Size, Spare Ammo
260, 600, //ROF, Reload Time
20, 0.04, 0.7, //Damage, Dropoff, Armor Penetration
16, 0.04, 0.7, //Damage, Dropoff, Armor Penetration
0.12, 0.12, //COF Min, COF Max
0, //COF Inc per Bullet
Material.DIAMOND_AXE, Sound.SKELETON_DEATH, false, 6),

View File

@ -148,7 +148,7 @@ public class SurvivalGames extends SoloGame
C.cAqua + "Compass finds Players during day time.",
};
Manager.GetAntiStack().SetEnabled(false);
//Manager.GetAntiStack().SetEnabled(false);
this.StrictAntiHack = true;

View File

@ -27,12 +27,12 @@ public class KitNecromancer extends Kit
new PerkSkeletons(true)
},
EntityType.ZOMBIE,
new ItemStack(Material.SKULL));
new ItemStack(Material.SKULL_ITEM));
}
@Override
public void GiveItems(Player player)
public void GiveItems(Player player)
{
}

View File

@ -594,6 +594,9 @@ public class UHC extends TeamGame
if (!IsAlive(player))
return;
if (!QuitOut)
return;
//Drop Items
UtilInv.drop(player, true);

View File

@ -69,8 +69,7 @@ import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.KitSorter;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata;
import net.minecraft.server.v1_7_R4.WatchableObject;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
public class GameLobbyManager implements Listener, IPacketHandler
{
@ -1086,16 +1085,16 @@ public class GameLobbyManager implements Listener, IPacketHandler
{
if (_handlingPacket)
return;
Packet packet = packetInfo.getPacket();
Player owner = packetInfo.getPlayer();
PacketVerifier packetVerifier = packetInfo.getVerifier();
int entityId = -1;
if (packet instanceof PacketPlayOutEntityMetadata)
if (packet instanceof PacketPlayOutSpawnEntityLiving)
{
entityId = ((PacketPlayOutEntityMetadata)packet).a;
entityId = ((PacketPlayOutSpawnEntityLiving)packet).a;
}
if (entityId != -1)
@ -1116,33 +1115,12 @@ public class GameLobbyManager implements Listener, IPacketHandler
{
try
{
if (packet instanceof PacketPlayOutEntityMetadata)
if (packet instanceof PacketPlayOutSpawnEntityLiving)
{
List<WatchableObject> watchables = new ArrayList<WatchableObject>();
for (WatchableObject watchableObject : (List<WatchableObject>)((PacketPlayOutEntityMetadata) packet).b)
{
WatchableObject newWatch = new WatchableObject(watchableObject.c(), watchableObject.a(), watchableObject.b());
if (newWatch.a() == 10)
{
newWatch.a(customName);
}
watchables.add(newWatch);
}
PacketPlayOutEntityMetadata newPacket = new PacketPlayOutEntityMetadata();
newPacket.a = entityId;
newPacket.b = watchables;
_handlingPacket = true;
packetVerifier.process(newPacket);
_handlingPacket = false;
packetInfo.setCancelled(true);
((PacketPlayOutSpawnEntityLiving)packet).l.watch(2, customName);
((PacketPlayOutSpawnEntityLiving)packet).l.watch(10, customName);
}
}
}
catch (IllegalArgumentException e)
{
e.printStackTrace();

View File

@ -0,0 +1,242 @@
package nautilus.game.arcade.managers;
import java.util.HashSet;
import java.util.Iterator;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState;
import org.bukkit.Color;
import org.bukkit.Effect;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
public class HalloweenManager implements Listener
{
ArcadeManager Manager;
public HashSet<Block> _active = new HashSet<Block>();
private HashSet<Item> _coins = new HashSet<Item>();
public long _lastSpawn = System.currentTimeMillis();
public HalloweenManager(ArcadeManager manager)
{
Manager = manager;
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
}
@EventHandler
public void reset(GameStateChangeEvent event)
{
_active.clear();
_lastSpawn = System.currentTimeMillis();
}
@EventHandler
public void pumpkinEffect(UpdateEvent event)
{
if (event.getType() == UpdateType.TICK)
return;
Iterator<Block> pumpkinIterator = _active.iterator();
while (pumpkinIterator.hasNext())
{
Block pumpkin = pumpkinIterator.next();
if (pumpkin.getType() != Material.PUMPKIN && pumpkin.getType() != Material.JACK_O_LANTERN)
{
pumpkinBreak(pumpkin);
pumpkinIterator.remove();
continue;
}
UtilParticle.PlayParticle(ParticleType.FLAME, pumpkin.getLocation().add(0.5, 0.5, 0.5), 0, 0, 0, 0.06f, 4);
if (Math.random() > 0.90)
{
if (pumpkin.getType() == Material.PUMPKIN)
{
pumpkin.setType(Material.JACK_O_LANTERN);
}
else
{
pumpkin.setType(Material.PUMPKIN);
}
}
}
}
@EventHandler
public void spawnPumpkinUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
if (Manager.GetGame() == null)
return;
Game game = Manager.GetGame();
if (game.GetState() != GameState.Live)
return;
if (!UtilTime.elapsed(_lastSpawn, 120000))
return;
if (Math.random() > 0.03)
return;
int toDrop = game.GetPlayers(false).size()/6;
for (int i=0 ; i< Math.max(1, toDrop) ; i++)
{
double interval = 1 / (double)(toDrop);
if (Math.random() >= (i * interval)) // Diminishing per growth
{
spawnPumpkin(getPumpkinBlock(game));
}
}
_lastSpawn = System.currentTimeMillis();
}
private void spawnPumpkin(Block block)
{
if (block == null)
return;
block.setType(Material.PUMPKIN);
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, Material.PUMPKIN);
_active.add(block);
}
private Block getPumpkinBlock(Game game)
{
Block block = null;
int attempts = 500;
while (attempts > 0)
{
attempts--;
int x = game.WorldData.MinX + UtilMath.r(Math.abs(game.WorldData.MaxX - game.WorldData.MinX));
int z = game.WorldData.MinZ + UtilMath.r(Math.abs(game.WorldData.MaxZ - game.WorldData.MinZ));
block = UtilBlock.getHighest(game.WorldData.World, x, z, null);
if (block.getLocation().getY() <= 2 || block.getLocation().getY() < game.WorldData.MinY || block.getLocation().getY() > game.WorldData.MaxY)
continue;
if (block.getRelative(BlockFace.DOWN).isLiquid())
continue;
if (!UtilBlock.airFoliage(block) || !UtilBlock.airFoliage(block.getRelative(BlockFace.UP)))
continue;
if (!UtilBlock.solid(block.getRelative(BlockFace.DOWN)))
continue;
return block;
}
return null;
}
@EventHandler
public void pumpkinDamage(BlockDamageEvent event)
{
if (_active.contains(event.getBlock()))
pumpkinBreak(event.getBlock());
}
private void pumpkinBreak(Block block)
{
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, Material.PUMPKIN);
block.setType(Material.AIR);
//Coins
for (int i=0 ; i < 20 ; i++)
{
Item coin = block.getWorld().dropItem(block.getLocation().add(0.5, 1, 0.5), new ItemStack(Material.getMaterial(175)));
Vector vel = new Vector(
(Math.random() - 0.5) * 0.5,
0.1 + Math.random() * 0.3,
(Math.random() - 0.5) * 0.5);
coin.setVelocity(vel);
coin.setPickupDelay(20);
_coins.add(coin);
}
//Effect
block.getWorld().playSound(block.getLocation(), Sound.ZOMBIE_REMEDY, 1f, 1f);
}
@EventHandler
public void coinPickup(PlayerPickupItemEvent event)
{
if (_coins.contains(event.getItem()))
{
event.setCancelled(true);
event.getItem().remove();
Manager.GetDonation().RewardCoins(null, "Halloween Pumpkin", event.getPlayer().getName(), event.getPlayer().getUniqueId(), 4 * event.getItem().getItemStack().getAmount());
event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.ORB_PICKUP, 1f, 2f);
}
}
@EventHandler
public void coinClean(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
Iterator<Item> coinIterator = _coins.iterator();
while (coinIterator.hasNext())
{
Item coin = coinIterator.next();
if (!coin.isValid() || coin.getTicksLived() > 1200)
{
coin.remove();
coinIterator.remove();
}
}
}
}