Search in sources :

Example 1 with URunnable

use of xyz.derkades.ublisk.utils.URunnable in project Ublisk by Derkades.

the class PlayerInteract method staffTool.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOW)
public void staffTool(PlayerInteractEvent event) {
    ItemStack itemInHand = event.getPlayer().getInventory().getItemInMainHand();
    if (itemInHand.getType() != Material.COAL_ORE || event.getAction() != Action.RIGHT_CLICK_BLOCK) {
        return;
    }
    Player player = event.getPlayer();
    String itemName = itemInHand.getItemMeta().getDisplayName();
    final Block block = event.getClickedBlock();
    event.setCancelled(true);
    if (itemName == null) {
        sendStaffToolInfoMessage(player);
        return;
    }
    if (itemName.contains("farmland")) {
        block.setType(Material.SOIL);
        block.setData((byte) 7);
        Location loc = block.getLocation();
        Block wheat = new Location(Var.WORLD, loc.getX(), loc.getY() + 1, loc.getZ()).getBlock();
        wheat.setType(Material.CROPS);
        wheat.setData((byte) 7);
    } else if (itemName.contains("invis")) {
        block.setData((byte) 0);
        block.setType(Material.PISTON_MOVING_PIECE);
        event.getPlayer().sendMessage("Placed invisible block. To remove invisible block, type /u rinv while standing inside an invisible block.");
    } else if (itemName.contains("coal")) {
        block.setType(Material.GLASS);
        new URunnable() {

            public void run() {
                block.setType(Material.COAL_ORE);
            }
        }.runLater(1 * 20);
    } else if (itemName.contains("lighting")) {
        Chunk chunk = ((CraftChunk) block.getChunk()).getHandle();
        chunk.initLighting();
    } else {
        sendStaffToolInfoMessage(player);
    }
}
Also used : URunnable(xyz.derkades.ublisk.utils.URunnable) UPlayer(xyz.derkades.ublisk.utils.UPlayer) Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) ItemStack(org.bukkit.inventory.ItemStack) Chunk(net.minecraft.server.v1_12_R1.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 2 with URunnable

use of xyz.derkades.ublisk.utils.URunnable in project Ublisk by Derkades.

the class Loot method onEnable.

@Override
public void onEnable() {
    new URunnable() {

        public void run() {
            int random = Random.getRandomInteger(0, 5);
            if (random == 0) {
                Loot.getRandomLoot().spawn();
            }
        }
    }.runTimer(5 * 60 * 20, 5 * 60 * 20);
    // Spawn particles
    new URunnable() {

        public void run() {
            for (Location location : SPAWNED_LOOT_LOCATIONS) {
                Ublisk.spawnParticle(Particle.TOTEM, location.add(0.5, 0.5, 0.5), 2, 0, 0, 0, 0.35);
            }
        }
    }.runTimer(3);
}
Also used : URunnable(xyz.derkades.ublisk.utils.URunnable) Location(org.bukkit.Location)

Example 3 with URunnable

use of xyz.derkades.ublisk.utils.URunnable in project Ublisk by Derkades.

the class Main method onEnable.

@Override
public void onEnable() {
    instance = this;
    Ublisk.RESTART_ERROR = false;
    PacketListener.RUNNING = true;
    Listeners.register();
    Command.registerAll();
    Mobs.clearMobs();
    MobSpawn.startMobSpawning();
    for (Task task : Task.values()) task.start();
    Logger.startSiteLogger();
    TodoList.initialize(DataFile.MYSQL.getConfig().getString("todo.ip"), DataFile.MYSQL.getConfig().getInt("todo.port"), DataFile.MYSQL.getConfig().getString("todo.database"), DataFile.MYSQL.getConfig().getString("todo.user"), DataFile.MYSQL.getConfig().getString("todo.password"));
    for (UModule module : UModule.ALL_MODULES) {
        try {
            module.initialize();
        } catch (Exception e) {
            Logger.log(LogLevel.SEVERE, "Modules", "An error occured while initializing " + module.getClass().getSimpleName() + ": " + e.getMessage());
            e.printStackTrace();
        }
    }
    Bukkit.clearRecipes();
    Ublisk.NMS = new V1_12_R1();
    new SidebarAPI().onEnable();
    new URunnable() {

        public void run() {
            Logger.log(LogLevel.INFO, "Cache", "Building up cache, expect some lag..");
            for (Guild guild : Guild.getGuildsList()) {
                guild.getDescription();
                guild.getMembers();
                guild.getOwner();
                guild.getPoints();
            }
            for (UPlayer player : Ublisk.getOnlinePlayers()) {
                player.getXP();
            }
            Logger.log(LogLevel.INFO, "Cache", "Complete! Now containing " + Cache.size() + " objects.");
            Logger.log(LogLevel.INFO, "Guilds", "Deleting empty guilds...");
            for (Guild guild : Guild.getGuildsList()) {
                if (guild.getMembers().size() == 0) {
                    Logger.log(LogLevel.WARNING, "Guilds", "Automatically deleted " + guild.getName() + ", because it does not have any members.");
                    guild.remove();
                }
            }
        }
    }.runLater(10 * 20);
    for (UPlayer player : Ublisk.getOnlinePlayers()) {
        PlayerInfo.resetHashMaps(player);
    }
    Ublisk.openDatabaseConnection();
}
Also used : URunnable(xyz.derkades.ublisk.utils.URunnable) Task(xyz.derkades.ublisk.task.Task) UModule(xyz.derkades.ublisk.modules.UModule) UPlayer(xyz.derkades.ublisk.utils.UPlayer) V1_12_R1(xyz.derkades.ublisk.utils.version_helper.V1_12_R1) SidebarAPI(xyz.derkades.ublisk.ext.com.coloredcarrot.api.sidebar.SidebarAPI) Guild(xyz.derkades.ublisk.utils.Guild)

Example 4 with URunnable

use of xyz.derkades.ublisk.utils.URunnable in project Ublisk by Derkades.

the class GitHubCommand method onCommand.

@Override
protected void onCommand(UPlayer player, String[] args) {
    if (args.length == 0) {
        player.sendMessage("Wrong usage: /u " + this.getAliases()[0] + " [description]");
        return;
    }
    final String description = String.join(" ", args);
    new URunnable() {

        public void run() {
            try {
                GHIssue issue = GitHubModule.createIssue(player.getName(), description);
                player.sendMessage(Ublisk.getPrefix() + "Your message has been recorded. We'll take a look at it soon! View your issue at " + issue.getHtmlUrl());
            } catch (IOException e) {
                player.sendMessage(ChatColor.RED + "An error has occured :(");
                e.printStackTrace();
            }
        }
    }.runAsync();
}
Also used : URunnable(xyz.derkades.ublisk.utils.URunnable) GHIssue(org.kohsuke.github.GHIssue) IOException(java.io.IOException)

Example 5 with URunnable

use of xyz.derkades.ublisk.utils.URunnable in project Ublisk by Derkades.

the class PlayerInteract method removePinkWool.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGH)
public void removePinkWool(final PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getMaterial() == Material.WOOL && event.getItem().getData().getData() == 6) {
        event.setCancelled(true);
        new URunnable() {

            public void run() {
                event.getPlayer().kickPlayer("java.net.ConnectException: Connection refused no further information");
            }
        }.runLater(2 * 20);
    }
}
Also used : URunnable(xyz.derkades.ublisk.utils.URunnable) EventHandler(org.bukkit.event.EventHandler)

Aggregations

URunnable (xyz.derkades.ublisk.utils.URunnable)9 EventHandler (org.bukkit.event.EventHandler)4 UPlayer (xyz.derkades.ublisk.utils.UPlayer)3 Location (org.bukkit.Location)2 Block (org.bukkit.block.Block)2 Player (org.bukkit.entity.Player)2 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 UUID (java.util.UUID)1 Chunk (net.minecraft.server.v1_12_R1.Chunk)1 Material (org.bukkit.Material)1 BossBar (org.bukkit.boss.BossBar)1 CraftChunk (org.bukkit.craftbukkit.v1_12_R1.CraftChunk)1 FallingBlock (org.bukkit.entity.FallingBlock)1 ItemStack (org.bukkit.inventory.ItemStack)1 PlayerInventory (org.bukkit.inventory.PlayerInventory)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1 GHIssue (org.kohsuke.github.GHIssue)1