Made it activate in all lobbies via command.

This commit is contained in:
William Burns 2015-12-31 00:46:31 +00:00
parent 1b40cece80
commit a64dc6a8d4
4 changed files with 131 additions and 32 deletions

View File

@ -5,7 +5,10 @@ import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.hub.modules.NewYearCountdown;
import mineplex.hub.modules.newyear.NewYearMessage;
/**
* Created by William (WilliamTiger).
@ -23,28 +26,42 @@ public class NewYearCommand extends CommandBase<NewYearCountdown>
{
if (Plugin.isInProgress())
{
caller.sendMessage(ChatColor.RED + "A new year countdown event is already in progress!");
caller.sendMessage(F.main("NYC", C.cRed + "A new year countdown event is already in progress!"));
return;
}
if (args.length != 1)
if (args.length != 3)
{
caller.sendMessage(ChatColor.RED + "/newyear <minutes>");
caller.sendMessage(F.main("NYC", C.cRed + "/newyear <hours> <minutes> <seconds>"));
return;
}
int mins = 0;
if (!(validateInteger(args[0]) && validateInteger(args[1]) && validateInteger(args[2])))
{
caller.sendMessage(F.main("NYC", C.cRed + "You have entered invalid hours/minutes/seconds."));
return;
}
int hours = Integer.valueOf(args[0]);
int mins = Integer.valueOf(args[1]);
int secs = Integer.valueOf(args[2]);
int total = secs + (mins * 60) + (hours * 60 * 60);
caller.sendMessage(F.main("NYC", "Sent command to all lobbies to start with " + F.elem(total + "") + " seconds."));
new NewYearMessage(total).publish();
}
private boolean validateInteger(String str)
{
boolean passed = false;
try
{
mins = Integer.parseInt(args[0]);
int i = Integer.valueOf(str);
passed = true;
}
catch (Exception e)
{
caller.sendMessage(ChatColor.RED + "That is not a valid amount of minutes!");
return;
}
Plugin.start(caller, mins);
return passed;
}
}

View File

@ -6,10 +6,12 @@ import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.util.*;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -30,6 +32,9 @@ import mineplex.core.common.util.UtilWorld;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.commands.NewYearCommand;
import mineplex.hub.modules.newyear.NewYearHandler;
import mineplex.hub.modules.newyear.NewYearMessage;
import mineplex.serverdata.commands.ServerCommandManager;
/**
* Created by William (WilliamTiger).
@ -46,6 +51,10 @@ public class NewYearCountdown extends MiniPlugin
{
super("New Year Countdown", plugin);
ServerCommandManager.getInstance().registerCommandType("NewYearCommand",
NewYearMessage.class, new NewYearHandler(this));
_center = new Location(UtilWorld.getWorld("world"), 0.5, 85, 37.5);
_inProgress = false;
}
@ -60,24 +69,24 @@ public class NewYearCountdown extends MiniPlugin
return _inProgress;
}
public void start(Player player, int mins)
public void start(int seconds)
{
_inProgress = true;
_center = player.getLocation();
_stage = mins * 60;
UtilServer.broadcast(C.cGreenB + player.getName() + " has started a " + C.cAquaB + "New Year's Countdown");
_stage = seconds;
UtilWorld.getWorld("world").setTime(18000);
_currentFrame = stringToBufferedImage(new Font("Tahoma", Font.PLAIN, 36), formatTimer(_stage));
}
@EventHandler
public void cmd(PlayerCommandPreprocessEvent e)
{
if (!e.getPlayer().getName().equalsIgnoreCase("WilliamTiger"))
return;
if (e.getMessage().equalsIgnoreCase("/lmao"))
{
e.setCancelled(true);
start(e.getPlayer(), 3);
start(30);
}
}
@ -92,6 +101,10 @@ public class NewYearCountdown extends MiniPlugin
_stage--;
if (_stage > 0 && _stage <= 10)
for (Player p : UtilServer.getPlayers())
p.playSound(p.getLocation(), Sound.NOTE_BASS, 1f, 1f);
if (_stage <= 0)
return;
@ -109,7 +122,7 @@ public class NewYearCountdown extends MiniPlugin
if (_stage == 0)
{
_currentFrame = null;
_currentFrame = stringToBufferedImage(new Font("Tahoma", Font.PLAIN, 20), "Happy New Year");
UtilTextMiddle.display(C.cGoldB + "2016", C.cYellowB + "Happy New Year!", UtilServer.getPlayers());
}
@ -117,6 +130,7 @@ public class NewYearCountdown extends MiniPlugin
{
//End of event.
_inProgress = false;
_currentFrame = null;
UtilWorld.getWorld("world").setTime(0);
return;
}
@ -152,7 +166,7 @@ public class NewYearCountdown extends MiniPlugin
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);
UtilParticle.PlayParticle(UtilParticle.ParticleType.HAPPY_VILLAGER, _center.add(v), 0, 0, 0, 0, 1, UtilParticle.ViewDist.MAX);
_center.subtract(v);
}
}
@ -182,19 +196,23 @@ public class NewYearCountdown extends MiniPlugin
return img;
}
private String formatTimer(int seconds)
private String formatTimer(long seconds)
{
if (seconds <= 60)
return "" + seconds;
long minutes = seconds / 60;
long hours = minutes / 60;
int mins = seconds / 60;
int secs = seconds % 60;
String s = String.valueOf(secs);
if ((hours % 60) > 0)
return zeroNumber(hours % 60) + ":" + zeroNumber(minutes % 60) + ":" + zeroNumber(seconds % 60);
if (s.length() == 1)
s = "0" + s;
if ((minutes % 60) > 0)
return zeroNumber(minutes % 60) + ":" + zeroNumber(seconds % 60);
return mins + ":" + s;
return zeroNumber(seconds % 60);
}
private String zeroNumber(long time)
{
return (time < 10 ? "0" : "") + time;
}
private Location offsetLoc(Location loc)
@ -224,13 +242,20 @@ public class NewYearCountdown extends MiniPlugin
}
FireworkEffect.Type t = FireworkEffect.Type.BALL;
int rType = new Random().nextInt(4);
if (rType == 0) {
if (rType == 0)
{
t = FireworkEffect.Type.BALL_LARGE;
} else if (rType == 1) {
}
else if (rType == 1)
{
t = FireworkEffect.Type.BURST;
} else if (rType == 2) {
}
else if (rType == 2)
{
t = FireworkEffect.Type.STAR;
} else if (rType == 3) {
}
else if (rType == 3)
{
t = FireworkEffect.Type.CREEPER;
}
Firework f = l.getWorld().spawn(l, Firework.class);
@ -242,7 +267,7 @@ public class NewYearCountdown extends MiniPlugin
public UtilParticle.ParticleType getRandomParticle()
{
List<UtilParticle.ParticleType> types = Arrays.asList(UtilParticle.ParticleType.FLAME, UtilParticle.ParticleType.FIREWORKS_SPARK, UtilParticle.ParticleType.RED_DUST);
List<UtilParticle.ParticleType> types = Arrays.asList(UtilParticle.ParticleType.FLAME, UtilParticle.ParticleType.HAPPY_VILLAGER, UtilParticle.ParticleType.RED_DUST);
return types.get(new Random().nextInt(types.size()));
}

View File

@ -0,0 +1,28 @@
package mineplex.hub.modules.newyear;
import mineplex.hub.modules.NewYearCountdown;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
/**
* Created by William (WilliamTiger).
* 31/12/15
*/
public class NewYearHandler implements CommandCallback
{
private NewYearCountdown _newYear;
public NewYearHandler(NewYearCountdown newYear)
{
_newYear = newYear;
}
@Override
public void run(ServerCommand command)
{
if (command instanceof NewYearMessage)
{
_newYear.start(((NewYearMessage)command).getSeconds());
}
}
}

View File

@ -0,0 +1,29 @@
package mineplex.hub.modules.newyear;
import mineplex.serverdata.commands.ServerCommand;
/**
* Created by William (WilliamTiger).
* 31/12/15
*/
public class NewYearMessage extends ServerCommand
{
private int seconds;
public NewYearMessage(int seconds)
{
this.seconds = seconds;
}
public int getSeconds()
{
return seconds;
}
@Override
public void run()
{
}
}