Chest example gadget for shauny

This commit is contained in:
Chiss 2014-08-29 11:00:16 +10:00
parent fa56aa0843
commit c3bb0ddbcb
5 changed files with 120 additions and 3 deletions

View File

@ -115,6 +115,9 @@ public class UtilAlg
public static <T> T Random(List<T> list)
{
if (list.isEmpty())
return null;
return list.get(UtilMath.r(list.size()));
}

View File

@ -46,7 +46,7 @@ public abstract class MultiCommandBase<PluginType extends MiniPlugin> extends Co
{
newArgs = new String[args.length - 1];
for (int i = 0 ; i < newArgs.length; i++)
for (int i = 0 ; i < newArgs.length; i++)
{
newArgs[i] = args[i+1];
}

View File

@ -92,6 +92,7 @@ public class GadgetManager extends MiniPlugin
addGadget(new ItemCoinBomb(this));
//addGadget(new ItemFootball(this));
//addGadget(new ItemDuelingSword(this));
addGadget(new ItemChestExample(this));
// Costume
addGadget(new OutfitRaveSuit(this, "Rave Helmet", 10000, ArmorSlot.Helmet, Material.LEATHER_HELMET, (byte)0));

View File

@ -0,0 +1,113 @@
package mineplex.core.gadget.gadgets;
import java.util.HashMap;
import java.util.Iterator;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.types.ItemGadget;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class ItemChestExample extends ItemGadget
{
private HashMap<Block, Long> _active = new HashMap<Block, Long>();
private int _duration = 2500;
public ItemChestExample(GadgetManager manager)
{
super(manager, "Treasure Chest Example", new String[]
{
},
-1,
Material.FIREWORK, (byte)0,
10, new Ammo("Treasure Chest Example", "10 Examples", Material.FIREWORK, (byte)0, new String[] { C.cWhite + "10 Examples!" }, 0, 10));
}
@Override
public void ActivateCustom(Player player)
{
_active.put(player.getLocation().add(2, 0, 0).getBlock(), System.currentTimeMillis());
_active.put(player.getLocation().add(0, 0, 2).getBlock(), System.currentTimeMillis() + 2000);
_active.put(player.getLocation().add(-2, 0, 0).getBlock(), System.currentTimeMillis() + 4000);
_active.put(player.getLocation().add(0, 0, -2).getBlock(), System.currentTimeMillis() + 6000);
for (int x=-2 ; x<=2 ; x++)
for (int z=-2 ; z<=2 ; z++)
{
Manager.getBlockRestore().Add(player.getLocation().getBlock().getRelative(x, -1, z), 159, (Math.abs(x) == 2 || Math.abs(z) == 2) ? (byte)14 : (byte)0, 20000);
if ((Math.abs(x) == 2 || Math.abs(z) == 2) && x != 0 && z != 0)
{
Manager.getBlockRestore().Add(player.getLocation().getBlock().getRelative(x, 0, z), 160, (byte)0, 20000);
}
}
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
Iterator<Block> activeIterator = _active.keySet().iterator();
while (activeIterator.hasNext())
{
Block block = activeIterator.next();
long time = _active.get(block);
//Hasnt Started
if (System.currentTimeMillis() < time)
continue;
Location loc = block.getLocation().add(0.5, 0, 0.5);
//Finished
if (UtilTime.elapsed(time, _duration))
{
activeIterator.remove();
Manager.getBlockRestore().Add(block, 54, (byte)0, 20000);
loc.getWorld().playSound(loc, Sound.HORSE_ARMOR, 1f, 1f);
UtilParticle.PlayParticle(ParticleType.LAVA, loc.add(0, 0.5, 0), 0.2f, 0.2f, 0.2f, 0, 50);
continue;
}
//Just hacking in this so i can use my other code
int timeKey = (int) (System.currentTimeMillis() - time);
float scale = (float)((double)(_duration - timeKey)/(double)_duration);
float y = 5 * scale;
double width = 1.4 * ((double)timeKey / (double)_duration);
for (int i=0 ; i < 2 ; i++)
{
double lead = i * ((2d * Math.PI)/2);
float x = (float) (Math.sin(timeKey/200d + lead));
float z = (float) (Math.cos(timeKey/200d + lead));
UtilParticle.PlayParticle(ParticleType.FLAME, loc.clone().add(x * width, y, z * width), 0f, 0f, 0f, 0, 1);
}
}
}
}

View File

@ -26,7 +26,7 @@ import nautilus.game.arcade.game.games.halloween.Halloween;
import nautilus.game.arcade.game.games.hideseek.HideSeek;
import nautilus.game.arcade.game.games.micro.Micro;
import nautilus.game.arcade.game.games.milkcow.MilkCow;
//import nautilus.game.arcade.game.games.minestrike.MineStrike;
import nautilus.game.arcade.game.games.minestrike.MineStrike;
import nautilus.game.arcade.game.games.mineware.MineWare;
import nautilus.game.arcade.game.games.quiver.Quiver;
import nautilus.game.arcade.game.games.quiver.QuiverTeams;
@ -79,7 +79,7 @@ public class GameFactory
else if (gameType == GameType.Halloween) return new Halloween(_manager);
else if (gameType == GameType.HideSeek) return new HideSeek(_manager);
else if (gameType == GameType.Micro) return new Micro(_manager);
//else if (gameType == GameType.MineStrike) return new MineStrike(_manager);
else if (gameType == GameType.MineStrike) return new MineStrike(_manager);
else if (gameType == GameType.MineWare) return new MineWare(_manager);
else if (gameType == GameType.MilkCow) return new MilkCow(_manager);
else if (gameType == GameType.Paintball) return new Paintball(_manager);