Issues - Paul-Schliep/CraftBukkit GitHub Wiki

Issues for CraftBukkit Project

  1. Duplicate Code in GeoffCraftBukkit/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java There is duplicate code from lines 120-127 and 137-144. Specifically, this if/else block that is used in the methods runTaskTimer() and runTaskTimerAsynchronously(): if (delay < 0l) { delay = 0; } if (period == 0l) { period = 1l; } else if (period < -1l) { period = -1l; }

  2. Duplicate Code in GeoffCraftBukkit/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java There is duplicate code from lines 63-73 and 132-142. Specifically, these value declarations and while loop are in the methods contains() and remove():

int hash = hash(value); int index = (hash & 0x7FFFFFFF) % values.length; int offset = 1;

    while(values[index] != FREE && !(hash(values[index]) == hash && values[index] == value)) {
        index = ((index + offset) & 0x7FFFFFFF) % values.length;
        offset = offset * 2 + 1;

        if (offset == -1) {
            offset = 2;
        }
    }
    return index;

}

  1. Dead Code in GeoffCraftBukkit/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java This is a block of commented out (i.e. "dead") code from lines 397-422:

    int x = loc.getBlockX();
    int y = loc.getBlockY();
    int z = loc.getBlockZ();
    
    int cx = x >> 4;
    int cz = z >> 4;
    
    if (sx <= 0 || sy <= 0 || sz <= 0) {
        return false;
    }
    
    if ((x + sx - 1) >> 4 != cx || (z + sz - 1) >> 4 != cz || y < 0 || y + sy > 128) {
        return false;
    }
    
    if (data.length != (sx * sy * sz * 5) / 2) {
        return false;
    }
    
    Packet51MapChunk packet = new Packet51MapChunk(x, y, z, sx, sy, sz, data);
    
    getHandle().playerConnection.sendPacket(packet);
    
    return true;
    
  2. Long Method in GeoffCraftBukkit/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java The method handleEntityDamageEvent() is 55 lines long. Most of this is from a block of nested if/else blocks from lines 396-420:

if (source.isExplosion()) { return null; } else if (source instanceof EntityDamageSource) { Entity damager = source.getEntity(); DamageCause cause = DamageCause.ENTITY_ATTACK;

        if (source instanceof EntityDamageSourceIndirect) {
            damager = ((EntityDamageSourceIndirect) source).getProximateDamageSource();
            if (damager.getBukkitEntity() instanceof ThrownPotion) {
                cause = DamageCause.MAGIC;
            } else if (damager.getBukkitEntity() instanceof Projectile) {
                cause = DamageCause.PROJECTILE;
            }
        } else if ("thorns".equals(source.translationIndex)) {
            cause = DamageCause.THORNS;
        }

        return callEntityDamageEvent(damager, entity, cause, damage);
    } else if (source == DamageSource.OUT_OF_WORLD) {
        EntityDamageEvent event = callEvent(new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.VOID, damage));
        if (!event.isCancelled()) {
            event.getEntity().setLastDamageCause(event);
        }
        return event;
    }

as well as a long elseif block from lines 396-420:

if (source == DamageSource.FIRE) { cause = DamageCause.FIRE; } else if (source == DamageSource.STARVE) { cause = DamageCause.STARVATION; } else if (source == DamageSource.WITHER) { cause = DamageCause.WITHER; } else if (source == DamageSource.STUCK) { cause = DamageCause.SUFFOCATION; } else if (source == DamageSource.DROWN) { cause = DamageCause.DROWNING; } else if (source == DamageSource.BURN) { cause = DamageCause.FIRE_TICK; } else if (source == MELTING) { cause = DamageCause.MELTING; } else if (source == POISON) { cause = DamageCause.POISON; } else if (source == DamageSource.MAGIC) { cause = DamageCause.MAGIC; }