use of org.bukkit.scheduler.BukkitRunnable in project Ublisk by Derkades.
the class Voting method onInvClose.
@EventHandler
public void onInvClose(final InventoryCloseEvent event) {
if (event.getInventory().getName().contains("Box") && !event.getInventory().getName().contains("Shulker")) {
Voting.playerOpeningBox = null;
new BukkitRunnable() {
public void run() {
HumanEntity human = event.getPlayer();
human.teleport(Voting.oldPlayerLocation);
Voting.oldPlayerLocation = null;
}
}.runTaskLater(Main.getInstance(), 2L);
}
}
use of org.bukkit.scheduler.BukkitRunnable in project Ublisk by Derkades.
the class Guild method invitePlayer.
public synchronized void invitePlayer(final UPlayer source, final UPlayer target) {
if (!this.exists())
throw new UnsupportedOperationException("Cannot invite player to non-existent guild.");
final GuildInvite invite = new GuildInvite(this, source);
// Add invite to list of invites, and remove it after 60 seconds (if it hasn't been accepted)
GUILD_INVITES.put(target.getName(), invite);
new BukkitRunnable() {
public void run() {
if (GUILD_INVITES.containsKey(target.getName())) {
GUILD_INVITES.remove(target.getName());
}
}
}.runTaskLater(Main.getInstance(), 60 * 20);
TextComponent inviteMessage = new TextComponent(source.getName() + " has invited you to join " + this.getName() + ". ");
inviteMessage.setColor(ChatColor.DARK_AQUA);
inviteMessage.setBold(true);
BaseComponent[] hoverText = new ComponentBuilder("Click me!").color(ChatColor.YELLOW).create();
TextComponent clickToAccept = new TextComponent("Click here to accept.");
clickToAccept.setColor(ChatColor.AQUA);
clickToAccept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText));
clickToAccept.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/guild accept"));
BaseComponent[] components = new BaseComponent[] { inviteMessage, clickToAccept };
target.sendMessage(components);
}
use of org.bukkit.scheduler.BukkitRunnable in project Ublisk by Derkades.
the class PacketListener method listenForPacket.
public static void listenForPacket(final int port, final int packetLength, final PacketRecievedListener runnable) {
if (Var.DEBUG) {
Logger.log(LogLevel.WARNING, "PacketListener", "Packet listener on port " + port + " has not been started, because debug mode is enabled.");
return;
}
new BukkitRunnable() {
public void run() {
try (final DatagramSocket serverSocket = new DatagramSocket(port)) {
byte[] receiveData = new byte[packetLength];
Logger.log(LogLevel.INFO, "PacketListener", "Started listening on " + port);
final DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
while (RUNNING) {
serverSocket.receive(receivePacket);
final String string = new String(receivePacket.getData(), 0, receivePacket.getLength());
runnable.onPacketRecieved(string);
}
Logger.log(LogLevel.INFO, "PacketListener", "Shutting down listener on port " + port);
serverSocket.close();
this.cancel();
return;
} catch (BindException e) {
if (e.getMessage().contains("in use")) {
Logger.log(LogLevel.WARNING, "Could not start listener on port " + port + ", because this port is already in use.");
Ublisk.RESTART_ERROR = true;
} else {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}.runTaskAsynchronously(Main.getInstance());
}
use of org.bukkit.scheduler.BukkitRunnable in project Ublisk by Derkades.
the class RemoveMobs method run.
@Override
public void run() {
Ublisk.broadcastPrefixedMessage("Clearing all mobs and items in 30 seconds!");
new BukkitRunnable() {
public void run() {
Ublisk.broadcastPrefixedMessage("Clearing all mobs and items in 5 seconds!");
new BukkitRunnable() {
public void run() {
Mobs.clearMobs();
Ublisk.broadcastMessage(Message.ENTITIES_REMOVED);
}
}.runTaskLater(Main.getInstance(), 5 * 20);
}
}.runTaskLater(Main.getInstance(), 25 * 20);
}
use of org.bukkit.scheduler.BukkitRunnable in project Fusion by GummyPvP.
the class Utils method sendActionBar.
public static void sendActionBar(final Player player, final String message, int duration) {
sendActionBar(player, message);
if (duration >= 0) {
// Sends empty message at the end of the duration. Allows messages shorter than 3 seconds, ensures precision.
new BukkitRunnable() {
@Override
public void run() {
sendActionBar(player, "");
}
}.runTaskLater(plugin, duration + 1);
}
// Re-sends the messages every 3 seconds so it doesn't go away from the player's screen.
while (duration > 60) {
duration -= 60;
int sched = duration % 60;
new BukkitRunnable() {
@Override
public void run() {
sendActionBar(player, message);
}
}.runTaskLater(plugin, (long) sched);
}
}
Aggregations