use of org.bukkit.scheduler.BukkitRunnable in project TotalFreedomMod by TotalFreedom.
the class Command_lockup method startLockup.
private void startLockup(final Player player) {
final FPlayer playerdata = plugin.pl.getPlayer(player);
cancelLockup(playerdata);
playerdata.setLockupScheduleId(new BukkitRunnable() {
@Override
public void run() {
if (player.isOnline()) {
player.openInventory(player.getInventory());
} else {
cancelLockup(playerdata);
}
}
}.runTaskTimer(plugin, 0L, 5L));
}
use of org.bukkit.scheduler.BukkitRunnable in project TotalFreedomMod by TotalFreedom.
the class FSync method playerMsg.
public static void playerMsg(final Player player, final String message) {
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
new BukkitRunnable() {
@Override
public void run() {
FUtil.playerMsg(player, message);
}
}.runTask(plugin);
}
use of org.bukkit.scheduler.BukkitRunnable in project TotalFreedomMod by TotalFreedom.
the class RollbackManager method rollback.
public int rollback(final String playerName) {
final List<RollbackEntry> entries = getEntriesByPlayer(playerName);
if (entries == null) {
return 0;
}
int count = entries.size();
for (RollbackEntry entry : entries) {
if (entry != null) {
entry.restore();
}
}
if (!removeHistory.contains(playerName.toLowerCase())) {
removeHistory.add(playerName.toLowerCase());
}
new BukkitRunnable() {
@Override
public void run() {
if (removeHistory.contains(playerName.toLowerCase())) {
removeHistory.remove(playerName.toLowerCase());
purgeEntries(playerName);
}
}
}.runTaskLater(plugin, 40L * 20L);
return count;
}
use of org.bukkit.scheduler.BukkitRunnable in project GameCore by Warvale.
the class GlobalEvent method onBlockBreak.
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
if (event.getBlock().getType().equals(Material.IRON_ORE)) {
event.getPlayer().giveExp(10);
for (int i = 0; i < NumberUtils.random(3, 1); i++) {
event.getPlayer().getInventory().addItem(new ItemStack(Material.IRON_INGOT));
}
event.setCancelled(true);
Location blockLoc = event.getBlock().getLocation();
event.getBlock().setType(Material.STONE);
List<Entity> entityList = new ArrayList<>();
for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
ItemStack stack = new ItemStack(Material.IRON_NUGGET);
stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
}
new BukkitRunnable() {
@Override
public void run() {
entityList.forEach(Entity::remove);
}
}.runTaskLater(Main.get(), 60L);
new BukkitRunnable() {
@Override
public void run() {
event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.IRON_ORE);
event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 5, 1);
}
}.runTaskLater(Main.get(), 400L);
}
if (event.getBlock().getType().equals(Material.GOLD_ORE)) {
event.getPlayer().giveExp(30);
for (int i = 0; i < NumberUtils.random(2, 0); i++) {
event.getPlayer().getInventory().addItem(new ItemStack(Material.GOLD_INGOT));
}
event.setCancelled(true);
Location blockLoc = event.getBlock().getLocation();
event.getBlock().setType(Material.STONE);
List<Entity> entityList = new ArrayList<>();
for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
ItemStack stack = new ItemStack(Material.GOLD_NUGGET);
stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
}
new BukkitRunnable() {
@Override
public void run() {
entityList.stream().forEach(entity -> entity.remove());
}
}.runTaskLater(Main.get(), 60L);
new BukkitRunnable() {
@Override
public void run() {
event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.GOLD_ORE);
event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 10, 1);
}
}.runTaskLater(Main.get(), 400L);
}
if (event.getBlock().getType().equals(Material.DIAMOND_ORE)) {
event.getPlayer().giveExp(50);
for (int i = 0; i < NumberUtils.random(1, 0); i++) {
event.getPlayer().getInventory().addItem(new ItemStack(Material.DIAMOND));
}
event.setCancelled(true);
Location blockLoc = event.getBlock().getLocation();
event.getBlock().setType(Material.STONE);
List<Entity> entityList = new ArrayList<>();
for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
ItemStack stack = new ItemStack(Material.PRISMARINE_CRYSTALS);
stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
}
new BukkitRunnable() {
@Override
public void run() {
entityList.stream().forEach(entity -> entity.remove());
}
}.runTaskLater(Main.get(), 60L);
new BukkitRunnable() {
@Override
public void run() {
event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.DIAMOND_ORE);
event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 25, 1);
}
}.runTaskLater(Main.get(), 400L);
}
if (event.getBlock().getType().equals(Material.LAPIS_ORE)) {
event.getPlayer().giveExp(50);
for (int i = 0; i < NumberUtils.random(1, 0); i++) {
event.getPlayer().getInventory().addItem(new ItemStack(Material.LAPIS_BLOCK));
}
event.setCancelled(true);
Location blockLoc = event.getBlock().getLocation();
event.getBlock().setType(Material.STONE);
List<Entity> entityList = new ArrayList<>();
for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
ItemStack stack = new ItemStack(Material.EYE_OF_ENDER);
stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
}
new BukkitRunnable() {
@Override
public void run() {
entityList.stream().forEach(entity -> entity.remove());
}
}.runTaskLater(Main.get(), 60L);
new BukkitRunnable() {
@Override
public void run() {
event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.LAPIS_ORE);
event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 15, 1);
}
}.runTaskLater(Main.get(), 400L);
}
}
use of org.bukkit.scheduler.BukkitRunnable in project Denizen-For-Bukkit by DenizenScript.
the class RotateCommand method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
final List<dEntity> entities = new ArrayList<dEntity>((List<dEntity>) scriptEntry.getObject("entities"));
final Duration duration = (Duration) scriptEntry.getObject("duration");
final Duration frequency = (Duration) scriptEntry.getObject("frequency");
final Element yaw = (Element) scriptEntry.getObject("yaw");
final Element pitch = (Element) scriptEntry.getObject("pitch");
boolean cancel = scriptEntry.hasObject("cancel");
final boolean infinite = scriptEntry.hasObject("infinite");
// Report to dB
dB.report(scriptEntry, getName(), (cancel ? aH.debugObj("cancel", cancel) : "") + aH.debugObj("entities", entities.toString()) + (infinite ? aH.debugObj("duration", "infinite") : duration.debug()) + frequency.debug() + yaw.debug() + pitch.debug());
// them from it
for (dEntity entity : entities) {
if (cancel) {
rotatingEntities.remove(entity.getUUID());
} else {
rotatingEntities.add(entity.getUUID());
}
}
// Go no further if we are canceling a rotation
if (cancel) {
return;
}
// Run a task that will keep rotating the entities
BukkitRunnable task = new BukkitRunnable() {
int ticks = 0;
int maxTicks = duration.getTicksAsInt();
// Track entities that are no longer used, to remove them from
// the regular list
Collection<dEntity> unusedEntities = new LinkedList<dEntity>();
@Override
public void run() {
if (entities.isEmpty()) {
scriptEntry.setFinished(true);
this.cancel();
} else if (infinite || ticks < maxTicks) {
for (dEntity entity : entities) {
if (entity.isSpawned() && rotatingEntities.contains(entity.getUUID())) {
NMSHandler.getInstance().getEntityHelper().rotate(entity.getBukkitEntity(), NMSHandler.getInstance().getEntityHelper().normalizeYaw(entity.getLocation().getYaw() + yaw.asFloat()), entity.getLocation().getPitch() + pitch.asFloat());
} else {
rotatingEntities.remove(entity.getUUID());
unusedEntities.add(entity);
}
}
// Remove any entities that are no longer spawned
if (!unusedEntities.isEmpty()) {
for (dEntity unusedEntity : unusedEntities) {
entities.remove(unusedEntity);
}
unusedEntities.clear();
}
ticks = (int) (ticks + frequency.getTicks());
} else {
scriptEntry.setFinished(true);
this.cancel();
}
}
};
task.runTaskTimer(DenizenAPI.getCurrentInstance(), 0, frequency.getTicks());
}
Aggregations