Search in sources :

Example 1 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project TotalFreedomMod by TotalFreedom.

the class FreezeData method setFrozen.

public void setFrozen(boolean freeze) {
    final Player player = fPlayer.getPlayer();
    if (player == null) {
        FLog.info("Could not freeze " + fPlayer.getName() + ". Player not online!");
        return;
    }
    FUtil.cancel(unfreeze);
    unfreeze = null;
    location = null;
    if (!freeze) {
        if (fPlayer.getPlayer().getGameMode() != GameMode.CREATIVE) {
            FUtil.setFlying(player, false);
        }
        return;
    }
    // Blockify location
    location = player.getLocation();
    // Avoid infinite falling
    FUtil.setFlying(player, true);
    if (fPlayer.getPlugin().al.isAdminImpostor(player)) {
        // Don't run unfreeze task for impostors
        return;
    }
    unfreeze = new BukkitRunnable() {

        @Override
        public void run() {
            FUtil.adminAction("TotalFreedom", "Unfreezing " + player.getName(), false);
            setFrozen(false);
        }
    }.runTaskLater(fPlayer.getPlugin(), AUTO_PURGE_TICKS);
}
Also used : FPlayer(me.totalfreedom.totalfreedommod.player.FPlayer) Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 2 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project TotalFreedomMod by TotalFreedom.

the class Command_premium method run.

@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    if (args.length != 1) {
        return false;
    }
    final Player player = getPlayer(args[0]);
    final String name;
    if (player != null) {
        name = player.getName();
    } else {
        name = args[0];
    }
    new BukkitRunnable() {

        @Override
        public void run() {
            try {
                final URL getUrl = new URL("http://axis.iaero.me/accstatus?username=" + name + "&format=plain");
                final URLConnection urlConnection = getUrl.openConnection();
                final String message;
                try (// Read the response
                BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()))) {
                    message = (!"PREMIUM".equalsIgnoreCase(in.readLine()) ? ChatColor.RED + "No" : ChatColor.DARK_GREEN + "Yes");
                }
                if (!plugin.isEnabled()) {
                    return;
                }
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        msg("Player " + name + " is premium: " + message);
                    }
                }.runTask(plugin);
            } catch (Exception ex) {
                FLog.severe(ex);
                msg("There was an error querying the mojang server.", ChatColor.RED);
            }
        }
    }.runTaskAsynchronously(plugin);
    return true;
}
Also used : Player(org.bukkit.entity.Player) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 3 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project TotalFreedomMod by TotalFreedom.

the class LoginProcess method onPlayerJoin.

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
    final Player player = event.getPlayer();
    new BukkitRunnable() {

        @Override
        public void run() {
            if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean()) {
                player.sendMessage(ChatColor.RED + "Server is currently closed to non-superadmins.");
            }
            if (lockdownEnabled) {
                FUtil.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED);
            }
        }
    }.runTaskLater(plugin, 20L * 1L);
}
Also used : Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EventHandler(org.bukkit.event.EventHandler)

Example 4 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project TotalFreedomMod by TotalFreedom.

the class Command_doom method run.

@Override
public boolean run(final CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    if (args.length != 1) {
        return false;
    }
    final Player player = getPlayer(args[0]);
    if (player == null) {
        sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
        return true;
    }
    FUtil.adminAction(sender.getName(), "Casting oblivion over " + player.getName(), true);
    FUtil.bcastMsg(player.getName() + " will be completely obliviated!", ChatColor.RED);
    final String ip = player.getAddress().getAddress().getHostAddress().trim();
    // Remove from superadmin
    Admin admin = getAdmin(player);
    if (admin != null) {
        FUtil.adminAction(sender.getName(), "Removing " + player.getName() + " from the superadmin list", true);
        plugin.al.removeAdmin(admin);
    }
    // Remove from whitelist
    player.setWhitelisted(false);
    // Deop
    player.setOp(false);
    // Ban player
    Ban ban = Ban.forPlayer(player, sender);
    ban.setReason("&cFUCKOFF");
    for (String playerIp : plugin.pl.getData(player).getIps()) {
        ban.addIp(playerIp);
    }
    plugin.bm.addBan(ban);
    // Set gamemode to survival
    player.setGameMode(GameMode.SURVIVAL);
    // Clear inventory
    player.closeInventory();
    player.getInventory().clear();
    // Ignite player
    player.setFireTicks(10000);
    // Generate explosion
    player.getWorld().createExplosion(player.getLocation(), 0F, false);
    // Shoot the player in the sky
    player.setVelocity(player.getVelocity().clone().add(new Vector(0, 20, 0)));
    new BukkitRunnable() {

        @Override
        public void run() {
            // strike lightning
            player.getWorld().strikeLightning(player.getLocation());
            // kill (if not done already)
            player.setHealth(0.0);
        }
    }.runTaskLater(plugin, 2L * 20L);
    new BukkitRunnable() {

        @Override
        public void run() {
            // message
            FUtil.adminAction(sender.getName(), "Banning " + player.getName() + ", IP: " + ip, true);
            // generate explosion
            player.getWorld().createExplosion(player.getLocation(), 0F, false);
            // kick player
            player.kickPlayer(ChatColor.RED + "FUCKOFF, and get your shit together!");
        }
    }.runTaskLater(plugin, 3L * 20L);
    return true;
}
Also used : Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Admin(me.totalfreedom.totalfreedommod.admin.Admin) Vector(org.bukkit.util.Vector) Ban(me.totalfreedom.totalfreedommod.banning.Ban)

Example 5 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project TotalFreedomMod by TotalFreedom.

the class Command_health method run.

@Override
public boolean run(final CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    Runtime runtime = Runtime.getRuntime();
    long usedMem = runtime.totalMemory() - runtime.freeMemory();
    msg("Reserved Memory: " + (double) runtime.totalMemory() / (double) BYTES_PER_MB + "mb");
    msg("Used Memory: " + new DecimalFormat("#").format((double) usedMem / (double) BYTES_PER_MB) + "mb (" + new DecimalFormat("#").format(((double) usedMem / (double) runtime.totalMemory()) * 100.0) + "%)");
    msg("Max Memory: " + (double) runtime.maxMemory() / (double) BYTES_PER_MB + "mb");
    msg("Calculating ticks per second, please wait...");
    new BukkitRunnable() {

        @Override
        public void run() {
            try {
                TFM_TickMeter tickMeter = new TFM_TickMeter(plugin);
                tickMeter.startTicking();
                Thread.sleep(2500);
                final double ticksPerSecond = tickMeter.stopTicking();
                // Plugin was disabled during async task
                if (!plugin.isEnabled()) {
                    return;
                }
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        msg("Ticks per second: " + (TPS_RANGE.containsDouble(ticksPerSecond) ? ChatColor.GREEN : ChatColor.RED) + ticksPerSecond);
                    }
                }.runTask(plugin);
            } catch (Exception ex) {
                FLog.severe(ex);
            }
        }
    }.runTaskAsynchronously(plugin);
    return true;
}
Also used : DecimalFormat(java.text.DecimalFormat) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Aggregations

BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)316 Player (org.bukkit.entity.Player)85 EventHandler (org.bukkit.event.EventHandler)52 Location (org.bukkit.Location)46 Vector (org.bukkit.util.Vector)45 Entity (org.bukkit.entity.Entity)29 ItemStack (org.bukkit.inventory.ItemStack)26 List (java.util.List)25 UUID (java.util.UUID)25 ArrayList (java.util.ArrayList)20 Block (org.bukkit.block.Block)18 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)17 LivingEntity (org.bukkit.entity.LivingEntity)16 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)15 HashMap (java.util.HashMap)12 MyPetFeedEvent (de.Keyle.MyPet.api.event.MyPetFeedEvent)11 Material (org.bukkit.Material)11 EliteEntity (com.magmaguy.elitemobs.mobconstructor.EliteEntity)10 File (java.io.File)10 PotionEffect (org.bukkit.potion.PotionEffect)10