Adds new constructor to NotePlayer, to be able to send the song to specific players

Some WindUp costume fixes
Added actionbar and song to WindUp suit
Created new booster manager
This commit is contained in:
LCastr0 2016-04-26 23:21:59 -03:00
parent f0cfac8e73
commit a7ef8bec49
11 changed files with 233 additions and 57 deletions

View File

@ -10,6 +10,7 @@ import mineplex.core.gadget.commands.AmmoCommand;
import mineplex.core.gadget.commands.UnlockCosmeticsCommand;
import mineplex.core.gadget.gadgets.item.*;
import mineplex.core.gadget.gadgets.outfit.*;
import mineplex.core.gadget.gadgets.outfit.windupsuit.*;
import mineplex.core.gadget.set.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -169,6 +170,7 @@ public class GadgetManager extends MiniPlugin
private MountManager _mountManager;
private PacketHandler _packetManager;
private HologramManager _hologramManager;
private OutfitWindUpSuitBoosterManager _boosterManager;
private NautHashMap<GadgetType, List<Gadget>> _gadgets;
@ -200,6 +202,7 @@ public class GadgetManager extends MiniPlugin
_packetManager = packetHandler;
_mountManager = mountManager;
_hologramManager = hologramManager;
_boosterManager = new OutfitWindUpSuitBoosterManager(this);
CreateGadgets();
createSets();
@ -633,6 +636,11 @@ public class GadgetManager extends MiniPlugin
return _inventoryManager;
}
public OutfitWindUpSuitBoosterManager getBoosterManager()
{
return _boosterManager;
}
public boolean collideEvent(Player shooter, Gadget gadget, Player other)
{
GadgetCollideEntityEvent collideEvent = new GadgetCollideEntityEvent(shooter, gadget, other);

View File

@ -24,6 +24,13 @@ public class AmmoCommand extends CommandBase<GadgetManager>
@Override
public void Execute(Player caller, String[] args)
{
boolean testServer = _plugin.getPlugin().getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing");
if(!testServer)
{
UtilPlayer.message(caller, F.elem("This command can only be used on test servers!"));
}
if(args.length == 2)
{
String gadgetName = args[0];
@ -111,5 +118,4 @@ public class AmmoCommand extends CommandBase<GadgetManager>
}
return null;
}
}

View File

@ -23,8 +23,12 @@ public class UnlockCosmeticsCommand extends CommandBase<GadgetManager>
@Override
public void Execute(Player caller, String[] args)
{
boolean testServer = _plugin.getPlugin().getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing");
// TODO ADD TO SPECIFIC TARGET PLAYER
if(!testServer)
{
UtilPlayer.message(caller, F.elem("This command can only be used on test servers!"));
}
// Adds all cosmetic types
if (args.length == 0)
@ -71,5 +75,4 @@ public class UnlockCosmeticsCommand extends CommandBase<GadgetManager>
}
UtilPlayer.message(caller, F.main("Cosmetics", "Added all the " + gadgetType.name() + " cosmetics!"));
}
}

View File

@ -1,4 +1,4 @@
package mineplex.core.gadget.gadgets.outfit;
package mineplex.core.gadget.gadgets.outfit.windupsuit;
import mineplex.core.common.util.*;
import mineplex.core.gadget.GadgetManager;
@ -11,41 +11,44 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
public class OutfitWindUpSuit extends OutfitGadget
{
private HashMap<String, Integer> _colorPhase = new HashMap<String, Integer>();
private HashMap<Player, Integer> _colorPhase = new HashMap<Player, Integer>();
private HashMap<Player, Integer> _percentage = new HashMap<Player, Integer>();
private HashSet<Player> _booster = new HashSet<Player>();
private OutfitWindUpSuitBoosterManager _boosterManager;
public OutfitWindUpSuit(GadgetManager manager, String name, int cost, ArmorSlot slot, Material mat, byte data)
public OutfitWindUpSuit(GadgetManager manager, String name, int cost, ArmorSlot slot, Material mat, byte data, OutfitWindUpSuitBoosterManager boosterManager)
{
super(manager, name,
UtilText.splitLineToArray(C.cGray + "Placeholder", LineFormat.LORE),
cost, slot, mat, data);
_boosterManager = boosterManager;
}
@Override
public void EnableCustom(Player player)
{
ApplyArmor(player);
_colorPhase.put(player.getName(), 0);
_colorPhase.put(player, 0);
_percentage.put(player, 0);
}
@Override
public void DisableCustom(Player player)
{
RemoveArmor(player);
_colorPhase.remove(player.getName());
_colorPhase.remove(player);
_percentage.remove(player);
if (_booster.contains(player))
_booster.remove(player);
if (_boosterManager.hasEffects(player))
_boosterManager.removeEffects(player);
if (UtilPlayer.hasWorldBorder(player))
UtilPlayer.removeWorldBorder(player);
@ -68,11 +71,15 @@ public class OutfitWindUpSuit extends OutfitGadget
if (!IsActive(player))
return;
// Checks if player has jump and speed effects (booster)
if (player.hasPotionEffect(PotionEffectType.JUMP) && player.hasPotionEffect(PotionEffectType.SPEED))
// Checks if player has effects
if (_boosterManager.hasEffects(player))
return;
int phase = _colorPhase.get(player.getName());
int phase = _colorPhase.get(player);
int percentage = _percentage.get(player);
if (phase == 4 || percentage == 888)
return;
Color color = getColor(player);
@ -84,22 +91,26 @@ public class OutfitWindUpSuit extends OutfitGadget
if (phase == 0)
{
updateNextColor(color, colors[phase], player, phase);
percentage += 5;
}
else if (phase == 1)
{
updateNextColor(color, colors[phase], player, phase);
percentage += 5;
}
else if (phase == 2)
{
updateNextColor(color, colors[phase], player, phase);
percentage += 5;
}
else if (phase == 3)
{
_booster.add(player);
UtilPlayer.sendRedScreen(player, 100000);
percentage = 888;
_colorPhase.put(player, phase + 1);
}
else
return;
_percentage.put(player, percentage);
sendPercentageChange(player);
}
// Activates boost (Jump + Speed 3 for 90 seconds)
@ -112,20 +123,17 @@ public class OutfitWindUpSuit extends OutfitGadget
if (!IsActive(player))
return;
int phase = _colorPhase.get(player.getName());
int phase = _colorPhase.get(player);
if(phase != 3)
if(phase != 4)
return;
_colorPhase.put(player.getName(), 0);
_colorPhase.put(player, 0);
_percentage.put(player, 0);
sendPercentageChange(player);
updateColor(player, UtilColor.defaultLeatherColor);
_booster.remove(player);
UtilPlayer.sendRedScreen(player, 0);
PotionEffect speed = new PotionEffect(PotionEffectType.SPEED, 20 * 90, 2, false);
PotionEffect jump = new PotionEffect(PotionEffectType.JUMP, 20 * 90, 2, false);
player.addPotionEffect(speed);
player.addPotionEffect(jump);
_boosterManager.applyEffects(player);
}
// Plays fast music when player is red
@ -135,11 +143,24 @@ public class OutfitWindUpSuit extends OutfitGadget
if (event.getType() != UpdateType.TICK)
return;
if (event.getTick() % 5 != 0)
return;
for (Player player : _booster)
for (Iterator<Player> i = _boosterManager.getPlayers().iterator(); i.hasNext();)
{
Player player = i.next();
// Checks if effects are over
if (_boosterManager.getTicks(player) >= 1800)
{
_boosterManager.removeEffects(player);
}
else
{
_boosterManager.incrementTicks(player);
}
}
for (Player player : _colorPhase.keySet())
{
if (_colorPhase.get(player) == 4)
if (event.getTick() % 5 == 0)
player.playSound(player.getLocation(), Sound.NOTE_BASS_DRUM, 1f, 1f);
}
}
@ -156,7 +177,6 @@ public class OutfitWindUpSuit extends OutfitGadget
private void updateColor(Player player, Color color)
{
ItemStack stack = getStack(player);
if (stack == null)
@ -170,12 +190,6 @@ public class OutfitWindUpSuit extends OutfitGadget
}
UtilColor.applyColor(stack, color);
/*LeatherArmorMeta meta = (LeatherArmorMeta) stack.getItemMeta();
meta.setColor(color);
stack.setItemMeta(meta);*/
}
private void updateNextColor(Color original, Color finalColor, Player player, int phase)
@ -184,7 +198,7 @@ public class OutfitWindUpSuit extends OutfitGadget
Color nextColor = UtilColor.getNextColor(original, finalColor, 5);
if (nextColor.getRed() == finalColor.getRed() && nextColor.getGreen() == finalColor.getGreen() && nextColor.getBlue() == finalColor.getBlue())
_colorPhase.put(player.getName(), phase + 1);
_colorPhase.put(player, phase + 1);
updateColor(player, nextColor);
}
@ -215,4 +229,13 @@ public class OutfitWindUpSuit extends OutfitGadget
return stack;
}
private void sendPercentageChange(Player player)
{
if (!_percentage.containsKey(player))
return;
// 888 = Max number of color changes (100%)
double percent = ((_percentage.get(player) * 100d) / 888d) / 100d;
UtilTextBottom.displayProgress(C.Bold + getSet().getName(), percent, "", player);
}
}

View File

@ -0,0 +1,129 @@
package mineplex.core.gadget.gadgets.outfit.windupsuit;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.types.OutfitGadget;
import mineplex.core.noteblock.INoteVerifier;
import mineplex.core.noteblock.NBSReader;
import mineplex.core.noteblock.NotePlayer;
import mineplex.core.noteblock.NoteSong;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Set;
public class OutfitWindUpSuitBoosterManager
{
private GadgetManager _gadget;
private HashMap<Player, Integer> _players = new HashMap<Player, Integer>();
private HashMap<Player, NotePlayer> _notePlayers = new HashMap<Player, NotePlayer>();
public OutfitWindUpSuitBoosterManager(GadgetManager gadget)
{
_gadget = gadget;
}
public void applyEffects(Player player)
{
if (hasEffects(player))
return;
_players.put(player, 0);
// Applies potion effects
PotionEffect speed = new PotionEffect(PotionEffectType.SPEED, 1800, 2, false);
PotionEffect jump = new PotionEffect(PotionEffectType.JUMP, 1800, 2, false);
player.addPotionEffect(speed);
player.addPotionEffect(jump);
// Resets red screen
UtilPlayer.sendRedScreen(player, 0);
// Plays firework effect
UtilFirework.playFirework(player.getLocation(), FireworkEffect.builder().withColor(Color.RED).withFade(Color.BLACK).flicker(true).build());
// Starts the song
playSong(player);
}
public void removeEffects(Player player)
{
if (!hasEffects(player))
return;
_players.remove(player);
// Removes potion effetcs
player.removePotionEffect(PotionEffectType.JUMP);
player.removePotionEffect(PotionEffectType.SPEED);
// Stops song
if (_notePlayers.containsKey(player))
{
NotePlayer notePlayer = _notePlayers.get(player);
notePlayer.cancel();
_notePlayers.remove(player);
}
}
public boolean hasEffects(Player player)
{
return _players.containsKey(player);
}
public Set<Player> getPlayers()
{
return _players.keySet();
}
public int getTicks(Player player)
{
if (!hasEffects(player))
return -1;
return _players.get(player);
}
public void incrementTicks(Player player)
{
_players.put(player, getTicks(player) + 1);
}
private void playSong(Player player)
{
String songName = "tetris.nbs";
try
{
File songFile = new File("../../update/songs/" + songName);
if (songFile.exists())
{
NoteSong song = NBSReader.loadSong(new DataInputStream(new FileInputStream(songFile)), songFile.getName().replace("_", " ").replace(".nbs", ""));
if (song != null)
{
NotePlayer notePlayer = new NotePlayer(_gadget.getPlugin(), song, new INoteVerifier() {
@Override
public boolean shouldPlay(Player toPlay) {
return true;
}
}, 0.5F, true, player);
_notePlayers.put(player, notePlayer);
}
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
}

View File

@ -1,4 +1,4 @@
package mineplex.core.gadget.gadgets.outfit;
package mineplex.core.gadget.gadgets.outfit.windupsuit;
import mineplex.core.gadget.GadgetManager;
import org.bukkit.Material;
@ -8,7 +8,7 @@ public class OutfitWindUpSuitBoots extends OutfitWindUpSuit
public OutfitWindUpSuitBoots(GadgetManager manager)
{
super(manager, "Wind Up Boots", -2, ArmorSlot.Boots, Material.LEATHER_BOOTS, (byte)0);
super(manager, "Wind Up Boots", -2, ArmorSlot.Boots, Material.LEATHER_BOOTS, (byte)0, manager.getBoosterManager());
}
}

View File

@ -1,4 +1,4 @@
package mineplex.core.gadget.gadgets.outfit;
package mineplex.core.gadget.gadgets.outfit.windupsuit;
import mineplex.core.gadget.GadgetManager;
import org.bukkit.Material;
@ -8,7 +8,7 @@ public class OutfitWindUpSuitChestplate extends OutfitWindUpSuit
public OutfitWindUpSuitChestplate(GadgetManager manager)
{
super(manager, "Wind Up Shirt", -2, ArmorSlot.Chest, Material.LEATHER_CHESTPLATE, (byte)0);
super(manager, "Wind Up Shirt", -2, ArmorSlot.Chest, Material.LEATHER_CHESTPLATE, (byte)0, manager.getBoosterManager());
}
}

View File

@ -1,4 +1,4 @@
package mineplex.core.gadget.gadgets.outfit;
package mineplex.core.gadget.gadgets.outfit.windupsuit;
import mineplex.core.gadget.GadgetManager;
import org.bukkit.Material;
@ -8,7 +8,7 @@ public class OutfitWindUpSuitHelmet extends OutfitWindUpSuit
public OutfitWindUpSuitHelmet(GadgetManager manager)
{
super(manager, "Wind Up Hat", -2, ArmorSlot.Helmet, Material.LEATHER_HELMET, (byte)0);
super(manager, "Wind Up Hat", -2, ArmorSlot.Helmet, Material.LEATHER_HELMET, (byte)0, manager.getBoosterManager());
}
}

View File

@ -1,4 +1,4 @@
package mineplex.core.gadget.gadgets.outfit;
package mineplex.core.gadget.gadgets.outfit.windupsuit;
import mineplex.core.gadget.GadgetManager;
import org.bukkit.Material;
@ -8,7 +8,7 @@ public class OutfitWindUpSuitLeggings extends OutfitWindUpSuit
public OutfitWindUpSuitLeggings(GadgetManager manager)
{
super(manager, "Wind Up Pants", -2, ArmorSlot.Legs, Material.LEATHER_LEGGINGS, (byte)0);
super(manager, "Wind Up Pants", -2, ArmorSlot.Legs, Material.LEATHER_LEGGINGS, (byte)0, manager.getBoosterManager());
}
}

View File

@ -1,10 +1,10 @@
package mineplex.core.gadget.set;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.outfit.OutfitWindUpSuitBoots;
import mineplex.core.gadget.gadgets.outfit.OutfitWindUpSuitChestplate;
import mineplex.core.gadget.gadgets.outfit.OutfitWindUpSuitHelmet;
import mineplex.core.gadget.gadgets.outfit.OutfitWindUpSuitLeggings;
import mineplex.core.gadget.gadgets.outfit.windupsuit.OutfitWindUpSuitBoots;
import mineplex.core.gadget.gadgets.outfit.windupsuit.OutfitWindUpSuitChestplate;
import mineplex.core.gadget.gadgets.outfit.windupsuit.OutfitWindUpSuitHelmet;
import mineplex.core.gadget.gadgets.outfit.windupsuit.OutfitWindUpSuitLeggings;
import mineplex.core.gadget.types.GadgetSet;
public class SetWindUpSuit extends GadgetSet

View File

@ -20,6 +20,13 @@ public class NotePlayer
private volatile boolean _loop;
private volatile int _tick;
private volatile boolean _finished;
private volatile Player[] _players = null;
public NotePlayer(JavaPlugin plugin, NoteSong song, INoteVerifier verifier, float volumeMult, boolean loop, Player... players)
{
this(plugin, song, verifier, volumeMult, loop);
_players = players;
}
public NotePlayer(JavaPlugin plugin, NoteSong song, INoteVerifier verifier, float volumeMult, boolean loop)
{
@ -92,7 +99,7 @@ public class NotePlayer
private void playTick(int tick)
{
Player[] playerArray = UtilServer.getPlayers();
Player[] playerArray = (_players != null) ? _players : UtilServer.getPlayers();
List<Player> players = new ArrayList<>(playerArray.length);
for (Player player : playerArray)
{
@ -108,6 +115,7 @@ public class NotePlayer
float volume = _volumeMult * (layer.getVolume() / 100F);
for (Player player : players)
{
if (!_finished)
player.playSound(player.getEyeLocation(), UtilNote.getInstrumentSound(note.getInstrument()), volume, (float) UtilNote.getPitch(note.getNote() - 33));
}
}
@ -118,5 +126,4 @@ public class NotePlayer
{
_finished = true;
}
}