Added a new years countdown to the hub.
This commit is contained in:
parent
55cdf4148a
commit
1b40cece80
@ -54,6 +54,7 @@ import mineplex.core.updater.FileUpdater;
|
||||
import mineplex.core.updater.Updater;
|
||||
import mineplex.core.velocity.VelocityFix;
|
||||
import mineplex.core.visibility.VisibilityManager;
|
||||
import mineplex.hub.modules.NewYearCountdown;
|
||||
import mineplex.hub.modules.StackerManager;
|
||||
import mineplex.hub.queue.QueueManager;
|
||||
import mineplex.hub.server.ServerManager;
|
||||
@ -183,6 +184,8 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
|
||||
//Updates
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
|
||||
|
||||
new NewYearCountdown(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,50 @@
|
||||
package mineplex.hub.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.hub.modules.NewYearCountdown;
|
||||
|
||||
/**
|
||||
* Created by William (WilliamTiger).
|
||||
* 29/12/15
|
||||
*/
|
||||
public class NewYearCommand extends CommandBase<NewYearCountdown>
|
||||
{
|
||||
public NewYearCommand(NewYearCountdown plugin)
|
||||
{
|
||||
super(plugin, Rank.JNR_DEV, "newyear", "nycountdown", "nyc");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
if (Plugin.isInProgress())
|
||||
{
|
||||
caller.sendMessage(ChatColor.RED + "A new year countdown event is already in progress!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length != 1)
|
||||
{
|
||||
caller.sendMessage(ChatColor.RED + "/newyear <minutes>");
|
||||
return;
|
||||
}
|
||||
|
||||
int mins = 0;
|
||||
try
|
||||
{
|
||||
mins = Integer.parseInt(args[0]);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
caller.sendMessage(ChatColor.RED + "That is not a valid amount of minutes!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Plugin.start(caller, mins);
|
||||
}
|
||||
}
|
@ -0,0 +1,249 @@
|
||||
package mineplex.hub.modules;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.command.CommandCenter;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilParticle;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilShapes;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.commands.NewYearCommand;
|
||||
|
||||
/**
|
||||
* Created by William (WilliamTiger).
|
||||
* 29/12/15
|
||||
*/
|
||||
public class NewYearCountdown extends MiniPlugin
|
||||
{
|
||||
private boolean _inProgress;
|
||||
private Location _center;
|
||||
private int _stage;
|
||||
private BufferedImage _currentFrame;
|
||||
|
||||
public NewYearCountdown(JavaPlugin plugin)
|
||||
{
|
||||
super("New Year Countdown", plugin);
|
||||
|
||||
_inProgress = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCommands()
|
||||
{
|
||||
CommandCenter.Instance.AddCommand(new NewYearCommand(this));
|
||||
}
|
||||
|
||||
public boolean isInProgress()
|
||||
{
|
||||
return _inProgress;
|
||||
}
|
||||
|
||||
public void start(Player player, int mins)
|
||||
{
|
||||
_inProgress = true;
|
||||
_center = player.getLocation();
|
||||
_stage = mins * 60;
|
||||
UtilServer.broadcast(C.cGreenB + player.getName() + " has started a " + C.cAquaB + "New Year's Countdown");
|
||||
UtilWorld.getWorld("world").setTime(18000);
|
||||
|
||||
_currentFrame = stringToBufferedImage(new Font("Tahoma", Font.PLAIN, 36), formatTimer(_stage));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void cmd(PlayerCommandPreprocessEvent e)
|
||||
{
|
||||
if (e.getMessage().equalsIgnoreCase("/lmao"))
|
||||
{
|
||||
e.setCancelled(true);
|
||||
start(e.getPlayer(), 3);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void stageUpdate(UpdateEvent e)
|
||||
{
|
||||
if (e.getType() != UpdateType.SEC)
|
||||
return;
|
||||
|
||||
if (!_inProgress)
|
||||
return;
|
||||
|
||||
_stage--;
|
||||
|
||||
if (_stage <= 0)
|
||||
return;
|
||||
|
||||
_currentFrame = stringToBufferedImage(new Font("Tahoma", Font.PLAIN, 36), formatTimer(_stage));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void update(UpdateEvent e)
|
||||
{
|
||||
if (e.getType() != UpdateType.FASTER)
|
||||
return;
|
||||
|
||||
if (!_inProgress)
|
||||
return;
|
||||
|
||||
if (_stage == 0)
|
||||
{
|
||||
_currentFrame = null;
|
||||
UtilTextMiddle.display(C.cGoldB + "2016", C.cYellowB + "Happy New Year!", UtilServer.getPlayers());
|
||||
}
|
||||
|
||||
if (_stage <= -120)
|
||||
{
|
||||
//End of event.
|
||||
_inProgress = false;
|
||||
UtilWorld.getWorld("world").setTime(0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_stage <= 0)
|
||||
{
|
||||
randomFirework(offsetLoc(_center));
|
||||
randomFirework(offsetLoc(_center));
|
||||
randomFirework(offsetLoc(_center));
|
||||
}
|
||||
|
||||
new BukkitRunnable(){
|
||||
ArrayList<Location> line = UtilShapes.getLinesDistancedPoints(offsetLoc(_center), offsetLoc(_center), 0.2);
|
||||
UtilParticle.ParticleType type = getRandomParticle();
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
UtilParticle.PlayParticle(type, line.get(0), 0, 0, 0, 0, 1, UtilParticle.ViewDist.MAX);
|
||||
line.remove(0);
|
||||
|
||||
if (line.isEmpty())
|
||||
this.cancel();
|
||||
}
|
||||
}.runTaskTimer(getPlugin(), 0L, 1L);
|
||||
|
||||
if (_currentFrame == null)
|
||||
return;
|
||||
|
||||
for (int y = 0; y < _currentFrame.getHeight(); y++)
|
||||
for (int x = 0; x < _currentFrame.getWidth(); x++)
|
||||
{
|
||||
if (java.awt.Color.black.getRGB() != _currentFrame.getRGB(x, y))
|
||||
continue;
|
||||
|
||||
Vector v = new Vector((float) _currentFrame.getWidth() / 2 - x, (float) _currentFrame.getHeight() / 2 - y, 0).multiply(0.5);
|
||||
UtilParticle.PlayParticle(UtilParticle.ParticleType.FLAME, _center.add(v), 0, 0, 0, 0, 1, UtilParticle.ViewDist.MAX);
|
||||
_center.subtract(v);
|
||||
}
|
||||
}
|
||||
|
||||
private BufferedImage stringToBufferedImage(Font font, String s)
|
||||
{
|
||||
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
Graphics g = img.getGraphics();
|
||||
g.setFont(font);
|
||||
|
||||
FontRenderContext frc = g.getFontMetrics().getFontRenderContext();
|
||||
Rectangle2D rect = font.getStringBounds(s, frc);
|
||||
g.dispose();
|
||||
|
||||
img = new BufferedImage((int) Math.ceil(rect.getWidth()), (int) Math.ceil(rect.getHeight()), BufferedImage.TYPE_4BYTE_ABGR);
|
||||
g = img.getGraphics();
|
||||
g.setColor(java.awt.Color.black);
|
||||
g.setFont(font);
|
||||
|
||||
FontMetrics fm = g.getFontMetrics();
|
||||
int x = 0;
|
||||
int y = fm.getAscent();
|
||||
|
||||
g.drawString(s, x, y);
|
||||
g.dispose();
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
private String formatTimer(int seconds)
|
||||
{
|
||||
if (seconds <= 60)
|
||||
return "" + seconds;
|
||||
|
||||
int mins = seconds / 60;
|
||||
int secs = seconds % 60;
|
||||
String s = String.valueOf(secs);
|
||||
|
||||
if (s.length() == 1)
|
||||
s = "0" + s;
|
||||
|
||||
return mins + ":" + s;
|
||||
}
|
||||
|
||||
private Location offsetLoc(Location loc)
|
||||
{
|
||||
Random random = new Random();
|
||||
return loc.clone().add((random.nextInt(100) - 50) + random.nextDouble() - 0.5, random.nextInt(20) + random.nextDouble() - 0.5, (random.nextInt(100) - 50) + random.nextDouble() - 0.5);
|
||||
}
|
||||
|
||||
public static void randomFirework(Location l)
|
||||
{
|
||||
Color c = Color.RED;
|
||||
int r = new Random().nextInt(4);
|
||||
if (r == 0)
|
||||
{
|
||||
c = Color.AQUA;
|
||||
}
|
||||
else if (r == 1)
|
||||
{
|
||||
c = Color.YELLOW;
|
||||
}
|
||||
else if (r == 2)
|
||||
{
|
||||
c = Color.RED;
|
||||
} else if (r == 3)
|
||||
{
|
||||
c = Color.LIME;
|
||||
}
|
||||
FireworkEffect.Type t = FireworkEffect.Type.BALL;
|
||||
int rType = new Random().nextInt(4);
|
||||
if (rType == 0) {
|
||||
t = FireworkEffect.Type.BALL_LARGE;
|
||||
} else if (rType == 1) {
|
||||
t = FireworkEffect.Type.BURST;
|
||||
} else if (rType == 2) {
|
||||
t = FireworkEffect.Type.STAR;
|
||||
} else if (rType == 3) {
|
||||
t = FireworkEffect.Type.CREEPER;
|
||||
}
|
||||
Firework f = l.getWorld().spawn(l, Firework.class);
|
||||
FireworkMeta fm = f.getFireworkMeta();
|
||||
fm.addEffect(FireworkEffect.builder().with(t).withColor(c).build());
|
||||
fm.setPower(0 + new Random().nextInt(2));
|
||||
f.setFireworkMeta(fm);
|
||||
}
|
||||
|
||||
public UtilParticle.ParticleType getRandomParticle()
|
||||
{
|
||||
List<UtilParticle.ParticleType> types = Arrays.asList(UtilParticle.ParticleType.FLAME, UtilParticle.ParticleType.FIREWORKS_SPARK, UtilParticle.ParticleType.RED_DUST);
|
||||
return types.get(new Random().nextInt(types.size()));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user