예제 #1
0
 public void setShard(final Block block, long delay) {
   plugin
       .getServer()
       .getScheduler()
       .scheduleSyncDelayedTask(
           plugin,
           new Runnable() {
             @Override
             public void run() {
               if (block.getType() == Material.AIR) {
                 block.setType(Material.PACKED_ICE);
               }
             }
           },
           delay);
   plugin
       .getServer()
       .getScheduler()
       .scheduleSyncDelayedTask(
           plugin,
           new Runnable() {
             @Override
             public void run() {
               if (block.getType() == Material.PACKED_ICE) {
                 block.setType(Material.AIR);
               }
             }
           },
           delay * 2);
 }
예제 #2
0
 @Override
 public boolean use(Player player) {
   BlockIterator iterator = new BlockIterator(player, 8);
   long delay = 0L;
   int i = 0;
   while (iterator.hasNext()) {
     Block block = iterator.next();
     setShard(block.getRelative(BlockFace.UP, 2).getRelative(BlockFace.DOWN, i), delay);
     float yaw = player.getLocation().getYaw();
     yaw = (yaw + 90) % 360;
     int left = (int) Math.floor((yaw - 90) / 90);
     int right = (int) Math.floor((yaw + 90) / 90);
     BlockFace leftBlockFace = BlockFace.UP;
     switch (left) {
       case 0:
         leftBlockFace = BlockFace.NORTH;
         break;
       case 1:
         leftBlockFace = BlockFace.WEST;
         break;
       case 2:
         leftBlockFace = BlockFace.SOUTH;
         break;
       case 3:
         leftBlockFace = BlockFace.EAST;
         break;
     }
     BlockFace rightBlockFace = BlockFace.UP;
     switch (right) {
       case 0:
         rightBlockFace = BlockFace.NORTH;
         break;
       case 1:
         rightBlockFace = BlockFace.WEST;
         break;
       case 2:
         rightBlockFace = BlockFace.SOUTH;
         break;
       case 3:
         rightBlockFace = BlockFace.EAST;
         break;
     }
     setShard(block.getRelative(leftBlockFace, 2).getRelative(BlockFace.DOWN, i), delay);
     setShard(block.getRelative(rightBlockFace, 2).getRelative(BlockFace.DOWN, i), delay);
     delay += 5L;
     i++;
   }
   Set<LivingEntity> invulnerableEntities = new HashSet<>();
   RegisteredServiceProvider<CharacterPlugin> characterPluginProvider =
       Bukkit.getServer().getServicesManager().getRegistration(CharacterPlugin.class);
   if (characterPluginProvider != null) {
     CharacterPlugin characterPlugin = characterPluginProvider.getProvider();
     Party party = characterPlugin.getParty(characterPlugin.getActiveCharacter(player));
     if (party != null) {
       for (Character member : party.getMembers()) {
         OfflinePlayer memberPlayer = member.getPlayer();
         if (memberPlayer.isOnline()) invulnerableEntities.add(memberPlayer.getPlayer());
       }
     }
   }
   for (LivingEntity entity : player.getWorld().getLivingEntities()) {
     if (entity.getLocation().distanceSquared(player.getLocation()) <= 64) {
       if (!invulnerableEntities.contains(entity)) {
         EntityDamageByEntityEvent event =
             new EntityDamageByEntityEvent(
                 player, entity, EntityDamageEvent.DamageCause.MAGIC, entity.getHealth() / 2D);
         plugin.getServer().getPluginManager().callEvent(event);
         if (!event.isCancelled()) {
           if (event.getEntity() instanceof LivingEntity) {
             ((LivingEntity) event.getEntity()).damage(event.getDamage(), event.getDamager());
             event.getEntity().setLastDamageCause(event);
           }
         }
       }
     }
   }
   return true;
 }