file_name
stringlengths 6
86
| file_path
stringlengths 45
249
| content
stringlengths 47
6.26M
| file_size
int64 47
6.26M
| language
stringclasses 1
value | extension
stringclasses 1
value | repo_name
stringclasses 767
values | repo_stars
int64 8
14.4k
| repo_forks
int64 0
1.17k
| repo_open_issues
int64 0
788
| repo_created_at
stringclasses 767
values | repo_pushed_at
stringclasses 767
values |
---|---|---|---|---|---|---|---|---|---|---|---|
ItemRabbitCooked.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/ItemRabbitCooked.java | package cn.nukkit.item;
/**
* Created by Snake1999 on 2016/1/14.
* Package cn.nukkit.item in project nukkit.
*/
public class ItemRabbitCooked extends ItemEdible {
public ItemRabbitCooked() {
this(0, 1);
}
public ItemRabbitCooked(Integer meta) {
this(meta, 1);
}
public ItemRabbitCooked(Integer meta, int count) {
super(COOKED_RABBIT, meta, count, "Cooked Rabbit");
}
}
| 424 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
ItemShovelStone.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/ItemShovelStone.java | package cn.nukkit.item;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class ItemShovelStone extends ItemTool {
public ItemShovelStone() {
this(0, 1);
}
public ItemShovelStone(Integer meta) {
this(meta, 1);
}
public ItemShovelStone(Integer meta, int count) {
super(STONE_SHOVEL, meta, count, "Stone Shovel");
}
@Override
public int getMaxDurability() {
return ItemTool.DURABILITY_STONE;
}
@Override
public boolean isShovel() {
return true;
}
@Override
public int getTier() {
return ItemTool.TIER_STONE;
}
@Override
public int getAttackDamage() {
return 2;
}
}
| 705 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
ItemHoeDiamond.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/ItemHoeDiamond.java | package cn.nukkit.item;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class ItemHoeDiamond extends ItemTool {
public ItemHoeDiamond() {
this(0, 1);
}
public ItemHoeDiamond(Integer meta) {
this(meta, 1);
}
public ItemHoeDiamond(Integer meta, int count) {
super(DIAMOND_HOE, meta, count, "Diamond Hoe");
}
@Override
public int getMaxDurability() {
return ItemTool.DURABILITY_DIAMOND;
}
@Override
public boolean isHoe() {
return true;
}
@Override
public int getTier() {
return ItemTool.TIER_DIAMOND;
}
}
| 626 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentKnockback.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/EnchantmentKnockback.java | package cn.nukkit.item.enchantment;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentKnockback extends Enchantment {
protected EnchantmentKnockback() {
super(ID_KNOCKBACK, "knockback", 5, EnchantmentType.SWORD);
}
@Override
public int getMinEnchantAbility(int level) {
return 5 + (level - 1) * 20;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 50;
}
@Override
public int getMaxLevel() {
return 2;
}
}
| 558 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentDurability.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/EnchantmentDurability.java | package cn.nukkit.item.enchantment;
import cn.nukkit.item.Item;
import java.util.Random;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentDurability extends Enchantment {
protected EnchantmentDurability() {
super(ID_DURABILITY, "durability", 5, EnchantmentType.BREAKABLE);
}
@Override
public int getMinEnchantAbility(int level) {
return 5 + (level - 1) * 8;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 50;
}
@Override
public int getMaxLevel() {
return 3;
}
@Override
public boolean isCompatibleWith(Enchantment enchantment) {
return super.isCompatibleWith(enchantment) && enchantment.id != ID_FORTUNE_DIGGING;
}
@Override
public boolean canEnchant(Item item) {
return item.getMaxDurability() >= 0 || super.canEnchant(item);
}
public static boolean negateDamage(Item item, int level, Random random) {
return !(item.isArmor() && random.nextFloat() < 0.6f) && random.nextInt(level + 1) > 0;
}
}
| 1,112 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentEfficiency.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/EnchantmentEfficiency.java | package cn.nukkit.item.enchantment;
import cn.nukkit.item.Item;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentEfficiency extends Enchantment {
protected EnchantmentEfficiency() {
super(ID_EFFICIENCY, "digging", 10, EnchantmentType.DIGGER);
}
@Override
public int getMinEnchantAbility(int level) {
return 1 + (level - 1) * 10;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 50;
}
@Override
public int getMaxLevel() {
return 5;
}
@Override
public boolean canEnchant(Item item) {
return item.isShears() || super.canEnchant(item);
}
}
| 713 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentFireAspect.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/EnchantmentFireAspect.java | package cn.nukkit.item.enchantment;
import cn.nukkit.entity.Entity;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentFireAspect extends Enchantment {
protected EnchantmentFireAspect() {
super(ID_FIRE_ASPECT, "fire", 2, EnchantmentType.SWORD);
}
@Override
public int getMinEnchantAbility(int level) {
return 10 + (level - 1) * 20;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 50;
}
@Override
public int getMaxLevel() {
return 2;
}
@Override
public void doPostAttack(Entity attacker, Entity entity) {
entity.setOnFire(Math.max(entity.fireTicks * 20, getLevel() * 4));
}
}
| 750 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentWaterWalker.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/EnchantmentWaterWalker.java | package cn.nukkit.item.enchantment;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentWaterWalker extends Enchantment {
protected EnchantmentWaterWalker() {
super(ID_WATER_WALKER, "waterWalker", 2, EnchantmentType.ARMOR_FEET);
}
@Override
public int getMinEnchantAbility(int level) {
return level * 10;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 15;
}
@Override
public int getMaxLevel() {
return 3;
}
}
| 562 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentEntry.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/EnchantmentEntry.java | package cn.nukkit.item.enchantment;
/**
* @author Nukkit Project Team
*/
public class EnchantmentEntry {
private final Enchantment[] enchantments;
private final int cost;
private final String randomName;
public EnchantmentEntry(Enchantment[] enchantments, int cost, String randomName) {
this.enchantments = enchantments;
this.cost = cost;
this.randomName = randomName;
}
public Enchantment[] getEnchantments() {
return enchantments;
}
public int getCost() {
return cost;
}
public String getRandomName() {
return randomName;
}
}
| 629 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentType.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/EnchantmentType.java | package cn.nukkit.item.enchantment;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemArmor;
import cn.nukkit.item.ItemBow;
import cn.nukkit.item.ItemFishingRod;
/**
* author: MagicDroidX
* Nukkit Project
*/
public enum EnchantmentType {
ALL,
ARMOR,
ARMOR_HEAD,
ARMOR_TORSO,
ARMOR_LEGS,
ARMOR_FEET,
SWORD,
DIGGER,
FISHING_ROD,
BREAKABLE,
BOW;
public boolean canEnchantItem(Item item) {
if (this == ALL) {
return true;
} else if (this == BREAKABLE && item.getMaxDurability() >= 0) {
return true;
} else if (item instanceof ItemArmor) {
if (this == ARMOR) {
return true;
}
switch (this) {
case ARMOR_HEAD:
return item.isHelmet();
case ARMOR_TORSO:
return item.isChestplate();
case ARMOR_LEGS:
return item.isLeggings();
case ARMOR_FEET:
return item.isBoots();
default:
return false;
}
} else {
switch (this) {
case SWORD:
return item.isSword();
case DIGGER:
return item.isPickaxe() || item.isShovel() || item.isAxe();
case BOW:
return item instanceof ItemBow;
case FISHING_ROD:
return item instanceof ItemFishingRod;
default:
return false;
}
}
}
}
| 1,623 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentSilkTouch.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/EnchantmentSilkTouch.java | package cn.nukkit.item.enchantment;
import cn.nukkit.item.Item;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentSilkTouch extends Enchantment {
protected EnchantmentSilkTouch() {
super(ID_SILK_TOUCH, "untouching", 1, EnchantmentType.DIGGER);
}
@Override
public int getMinEnchantAbility(int level) {
return 15;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 50;
}
@Override
public int getMaxLevel() {
return 1;
}
@Override
public boolean isCompatibleWith(Enchantment enchantment) {
return super.isCompatibleWith(enchantment) && enchantment.id != ID_FORTUNE_DIGGING;
}
@Override
public boolean canEnchant(Item item) {
return item.isShears() || super.canEnchant(item);
}
}
| 870 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentLure.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/EnchantmentLure.java | package cn.nukkit.item.enchantment;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentLure extends Enchantment {
protected EnchantmentLure() {
super(ID_LURE, "fishingSpeed", 2, EnchantmentType.FISHING_ROD);
}
@Override
public int getMinEnchantAbility(int level) {
return 15 + (level - 1) * 9;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 50;
}
@Override
public int getMaxLevel() {
return 3;
}
}
| 553 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentThorns.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/EnchantmentThorns.java | package cn.nukkit.item.enchantment;
import cn.nukkit.entity.Entity;
import cn.nukkit.entity.EntityHumanType;
import cn.nukkit.event.entity.EntityDamageEvent;
import cn.nukkit.event.entity.EntityDamageEvent.DamageCause;
import cn.nukkit.item.Item;
import java.util.Random;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentThorns extends Enchantment {
protected EnchantmentThorns() {
super(ID_THORNS, "thorns", 2, EnchantmentType.ARMOR_TORSO);
}
@Override
public int getMinEnchantAbility(int level) {
return 10 + (level - 1) * 20;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 50;
}
@Override
public int getMaxLevel() {
return 3;
}
@Override
public void doPostAttack(Entity attacker, Entity entity) {
if (!(entity instanceof EntityHumanType)) {
return;
}
EntityHumanType human = (EntityHumanType) entity;
int thornsDamage = 0;
Random rnd = new Random();
for (Item armor : human.getInventory().getArmorContents()) {
Enchantment thorns = armor.getEnchantment(Enchantment.ID_THORNS);
if (thorns != null && thorns.getLevel() > 0) {
int chance = thorns.getLevel() * 15;
if (chance > 90) {
chance = 90;
}
if (rnd.nextInt(100) + 1 <= chance) {
thornsDamage += rnd.nextInt(4) + 1;
}
}
}
if (thornsDamage > 0) {
attacker.attack(new EntityDamageEvent(attacker, DamageCause.MAGIC, rnd.nextInt(4) + 1));
}
}
}
| 1,727 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentWaterWorker.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/EnchantmentWaterWorker.java | package cn.nukkit.item.enchantment;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentWaterWorker extends Enchantment {
protected EnchantmentWaterWorker() {
super(ID_WATER_WORKER, "waterWorker", 2, EnchantmentType.ARMOR_HEAD);
}
@Override
public int getMinEnchantAbility(int level) {
return 1;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 40;
}
@Override
public int getMaxLevel() {
return 1;
}
}
| 553 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
Enchantment.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/Enchantment.java | package cn.nukkit.item.enchantment;
import cn.nukkit.entity.Entity;
import cn.nukkit.event.entity.EntityDamageEvent;
import cn.nukkit.item.Item;
import cn.nukkit.item.enchantment.bow.EnchantmentBowFlame;
import cn.nukkit.item.enchantment.bow.EnchantmentBowInfinity;
import cn.nukkit.item.enchantment.bow.EnchantmentBowKnockback;
import cn.nukkit.item.enchantment.bow.EnchantmentBowPower;
import cn.nukkit.item.enchantment.damage.EnchantmentDamageAll;
import cn.nukkit.item.enchantment.damage.EnchantmentDamageArthropods;
import cn.nukkit.item.enchantment.damage.EnchantmentDamageSmite;
import cn.nukkit.item.enchantment.loot.EnchantmentLootDigging;
import cn.nukkit.item.enchantment.loot.EnchantmentLootFishing;
import cn.nukkit.item.enchantment.loot.EnchantmentLootWeapon;
import cn.nukkit.item.enchantment.protection.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.concurrent.ThreadLocalRandom;
/**
* author: MagicDroidX
* Nukkit Project
*/
public abstract class Enchantment implements Cloneable {
protected static Enchantment[] enchantments;
//http://minecraft.gamepedia.com/Enchanting#Aqua_Affinity
public static final int ID_PROTECTION_ALL = 0;
public static final int ID_PROTECTION_FIRE = 1;
public static final int ID_PROTECTION_FALL = 2;
public static final int ID_PROTECTION_EXPLOSION = 3;
public static final int ID_PROTECTION_PROJECTILE = 4;
public static final int ID_THORNS = 5;
public static final int ID_WATER_BREATHING = 6;
public static final int ID_WATER_WALKER = 7;
public static final int ID_WATER_WORKER = 8;
public static final int ID_DAMAGE_ALL = 9;
public static final int ID_DAMAGE_SMITE = 10;
public static final int ID_DAMAGE_ARTHROPODS = 11;
public static final int ID_KNOCKBACK = 12;
public static final int ID_FIRE_ASPECT = 13;
public static final int ID_LOOTING = 14;
public static final int ID_EFFICIENCY = 15;
public static final int ID_SILK_TOUCH = 16;
public static final int ID_DURABILITY = 17;
public static final int ID_FORTUNE_DIGGING = 18;
public static final int ID_BOW_POWER = 19;
public static final int ID_BOW_KNOCKBACK = 20;
public static final int ID_BOW_FLAME = 21;
public static final int ID_BOW_INFINITY = 22;
public static final int ID_FORTUNE_FISHING = 23;
public static final int ID_LURE = 24;
public static void init() {
enchantments = new Enchantment[256];
enchantments[ID_PROTECTION_ALL] = new EnchantmentProtectionAll();
enchantments[ID_PROTECTION_FIRE] = new EnchantmentProtectionFire();
enchantments[ID_PROTECTION_FALL] = new EnchantmentProtectionFall();
enchantments[ID_PROTECTION_EXPLOSION] = new EnchantmentProtectionExplosion();
enchantments[ID_PROTECTION_PROJECTILE] = new EnchantmentProtectionProjectile();
enchantments[ID_THORNS] = new EnchantmentThorns();
enchantments[ID_WATER_BREATHING] = new EnchantmentWaterBreath();
enchantments[ID_WATER_WORKER] = new EnchantmentWaterWorker();
enchantments[ID_WATER_WALKER] = new EnchantmentWaterWalker();
enchantments[ID_DAMAGE_ALL] = new EnchantmentDamageAll();
enchantments[ID_DAMAGE_SMITE] = new EnchantmentDamageSmite();
enchantments[ID_DAMAGE_ARTHROPODS] = new EnchantmentDamageArthropods();
enchantments[ID_KNOCKBACK] = new EnchantmentKnockback();
enchantments[ID_FIRE_ASPECT] = new EnchantmentFireAspect();
enchantments[ID_LOOTING] = new EnchantmentLootWeapon();
enchantments[ID_EFFICIENCY] = new EnchantmentEfficiency();
enchantments[ID_SILK_TOUCH] = new EnchantmentSilkTouch();
enchantments[ID_DURABILITY] = new EnchantmentDurability();
enchantments[ID_FORTUNE_DIGGING] = new EnchantmentLootDigging();
enchantments[ID_BOW_POWER] = new EnchantmentBowPower();
enchantments[ID_BOW_KNOCKBACK] = new EnchantmentBowKnockback();
enchantments[ID_BOW_FLAME] = new EnchantmentBowFlame();
enchantments[ID_BOW_INFINITY] = new EnchantmentBowInfinity();
enchantments[ID_FORTUNE_FISHING] = new EnchantmentLootFishing();
enchantments[ID_LURE] = new EnchantmentLure();
}
public static Enchantment get(int id) {
return id >= 0 && id < enchantments.length ? enchantments[id] : null;
}
public static Enchantment getEnchantment(int id) {
return get(id).clone();
}
public static Enchantment[] getEnchantments() {
ArrayList<Enchantment> list = new ArrayList<>();
for (Enchantment enchantment : enchantments) {
if (enchantment == null) {
break;
}
list.add(enchantment);
}
return list.stream().toArray(Enchantment[]::new);
}
public final int id;
private final int weight;
public EnchantmentType type;
protected int level = 1;
protected final String name;
protected Enchantment(int id, String name, int weight, EnchantmentType type) {
this.id = id;
this.weight = weight;
this.type = type;
this.name = name;
}
public int getLevel() {
return level;
}
public Enchantment setLevel(int level) {
return this.setLevel(level, true);
}
public Enchantment setLevel(int level, boolean safe) {
if (!safe) {
this.level = level;
return this;
}
if (level > this.getMaxLevel()) {
this.level = this.getMaxLevel();
} else if (level < this.getMinLevel()) {
this.level = this.getMaxLevel();
} else {
this.level = level;
}
return this;
}
public int getId() {
return id;
}
public int getWeight() {
return weight;
}
public int getMinLevel() {
return 1;
}
public int getMaxLevel() {
return 1;
}
public int getMaxEnchantableLevel() {
return getMaxLevel();
}
public int getMinEnchantAbility(int level) {
return 1 + level * 10;
}
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 5;
}
public float getDamageProtection(EntityDamageEvent event) {
return 0;
}
public double getDamageBonus(Entity entity) {
return 0;
}
public void doPostAttack(Entity attacker, Entity entity) {
}
public void doPostHurt(Entity attacker, Entity entity) {
}
public boolean isCompatibleWith(Enchantment enchantment) {
return this != enchantment;
}
public String getName() {
return "%enchantment." + this.name;
}
public boolean canEnchant(Item item) {
return this.type.canEnchantItem(item);
}
public boolean isMajor() {
return false;
}
@Override
protected Enchantment clone() {
try {
return (Enchantment) super.clone();
} catch (CloneNotSupportedException e) {
return null;
}
}
public static final String[] words = {"the", "elder", "scrolls", "klaatu", "berata", "niktu", "xyzzy", "bless", "curse", "light", "darkness", "fire", "air", "earth", "water", "hot", "dry", "cold", "wet", "ignite", "snuff", "embiggen", "twist", "shorten", "stretch", "fiddle", "destroy", "imbue", "galvanize", "enchant", "free", "limited", "range", "of", "towards", "inside", "sphere", "cube", "self", "other", "ball", "mental", "physical", "grow", "shrink", "demon", "elemental", "spirit", "animal", "creature", "beast", "humanoid", "undead", "fresh", "stale"};
public static String getRandomName() {
int count = ThreadLocalRandom.current().nextInt(3, 6);
HashSet<String> set = new HashSet<>();
while (set.size() < count) {
set.add(Enchantment.words[ThreadLocalRandom.current().nextInt(0, Enchantment.words.length)]);
}
String[] words = set.stream().toArray(String[]::new);
return String.join(" ", words);
}
}
| 8,055 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentList.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/EnchantmentList.java | package cn.nukkit.item.enchantment;
/**
* @author Nukkit Project Team
*/
public class EnchantmentList {
private final EnchantmentEntry[] enchantments;
public EnchantmentList(int size) {
this.enchantments = new EnchantmentEntry[size];
}
/**
* @param slot The index of enchantment.
* @param entry The given enchantment entry.
*/
public EnchantmentList setSlot(int slot, EnchantmentEntry entry) {
enchantments[slot] = entry;
return this;
}
public EnchantmentEntry getSlot(int slot) {
return enchantments[slot];
}
public int getSize() {
return enchantments.length;
}
}
| 670 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentWaterBreath.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/EnchantmentWaterBreath.java | package cn.nukkit.item.enchantment;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentWaterBreath extends Enchantment {
protected EnchantmentWaterBreath() {
super(ID_WATER_BREATHING, "oxygen", 2, EnchantmentType.ARMOR_TORSO);
}
@Override
public int getMinEnchantAbility(int level) {
return 10 + (level - 1) * 20;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 50;
}
@Override
public int getMaxLevel() {
return 3;
}
}
| 572 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentLootDigging.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/loot/EnchantmentLootDigging.java | package cn.nukkit.item.enchantment.loot;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.item.enchantment.EnchantmentType;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentLootDigging extends EnchantmentLoot {
public EnchantmentLootDigging() {
super(Enchantment.ID_FORTUNE_DIGGING, "lootBonusDigger", 2, EnchantmentType.DIGGER);
}
}
| 391 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentLootFishing.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/loot/EnchantmentLootFishing.java | package cn.nukkit.item.enchantment.loot;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.item.enchantment.EnchantmentType;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentLootFishing extends EnchantmentLoot {
public EnchantmentLootFishing() {
super(Enchantment.ID_FORTUNE_FISHING, "lootBonusFishing", 2, EnchantmentType.FISHING_ROD);
}
}
| 397 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentLootWeapon.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/loot/EnchantmentLootWeapon.java | package cn.nukkit.item.enchantment.loot;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.item.enchantment.EnchantmentType;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentLootWeapon extends EnchantmentLoot {
public EnchantmentLootWeapon() {
super(Enchantment.ID_LOOTING, "lootBonus", 2, EnchantmentType.SWORD);
}
}
| 374 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentLoot.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/loot/EnchantmentLoot.java | package cn.nukkit.item.enchantment.loot;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.item.enchantment.EnchantmentType;
/**
* author: MagicDroidX
* Nukkit Project
*/
public abstract class EnchantmentLoot extends Enchantment {
protected EnchantmentLoot(int id, String name, int weight, EnchantmentType type) {
super(id, name, weight, type);
}
@Override
public int getMinEnchantAbility(int level) {
return 15 + (level - 1) * 9;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 50;
}
@Override
public int getMaxLevel() {
return 3;
}
@Override
public boolean isCompatibleWith(Enchantment enchantment) {
return super.isCompatibleWith(enchantment) && enchantment.id != Enchantment.ID_SILK_TOUCH;
}
}
| 869 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentProtectionFire.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/protection/EnchantmentProtectionFire.java | package cn.nukkit.item.enchantment.protection;
import cn.nukkit.event.entity.EntityDamageEvent;
import cn.nukkit.event.entity.EntityDamageEvent.DamageCause;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentProtectionFire extends EnchantmentProtection {
public EnchantmentProtectionFire() {
super(ID_PROTECTION_FIRE, "fire", 5, TYPE.FIRE);
}
@Override
public int getMinEnchantAbility(int level) {
return 10 + (level - 1) * 8;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 12;
}
@Override
public double getTypeModifier() {
return 2;
}
@Override
public float getDamageProtection(EntityDamageEvent e) {
DamageCause cause = e.getCause();
if (level <= 0 || (cause != DamageCause.LAVA && cause != DamageCause.FIRE && cause != DamageCause.FIRE_TICK)) {
return 0;
}
return (float) (getLevel() * getTypeModifier());
}
}
| 1,028 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentProtection.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/protection/EnchantmentProtection.java | package cn.nukkit.item.enchantment.protection;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.item.enchantment.EnchantmentType;
/**
* author: MagicDroidX
* Nukkit Project
*/
public abstract class EnchantmentProtection extends Enchantment {
public enum TYPE {
ALL,
FIRE,
FALL,
EXPLOSION,
PROJECTILE
}
protected final TYPE protectionType;
protected EnchantmentProtection(int id, String name, int weight, EnchantmentProtection.TYPE type) {
super(id, name, weight, EnchantmentType.ARMOR);
this.protectionType = type;
if (protectionType == TYPE.FALL) {
this.type = EnchantmentType.ARMOR_FEET;
}
}
@Override
public boolean isCompatibleWith(Enchantment enchantment) {
if (enchantment instanceof EnchantmentProtection) {
if (((EnchantmentProtection) enchantment).protectionType == this.protectionType) {
return false;
}
return ((EnchantmentProtection) enchantment).protectionType == TYPE.FALL || this.protectionType == TYPE.FALL;
}
return super.isCompatibleWith(enchantment);
}
@Override
public int getMaxLevel() {
return 4;
}
@Override
public String getName() {
return "%enchantment.protect." + this.name;
}
public double getTypeModifier() {
return 0;
}
@Override
public boolean isMajor() {
return true;
}
}
| 1,499 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentProtectionProjectile.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/protection/EnchantmentProtectionProjectile.java | package cn.nukkit.item.enchantment.protection;
import cn.nukkit.event.entity.EntityDamageEvent;
import cn.nukkit.event.entity.EntityDamageEvent.DamageCause;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentProtectionProjectile extends EnchantmentProtection {
public EnchantmentProtectionProjectile() {
super(ID_PROTECTION_PROJECTILE, "projectile", 5, TYPE.PROJECTILE);
}
@Override
public int getMinEnchantAbility(int level) {
return 3 + (level - 1) * 6;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 15;
}
@Override
public double getTypeModifier() {
return 3;
}
@Override
public float getDamageProtection(EntityDamageEvent e) {
DamageCause cause = e.getCause();
if (level <= 0 || (cause != DamageCause.PROJECTILE)) {
return 0;
}
return (float) (getLevel() * getTypeModifier());
}
}
| 1,000 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentProtectionFall.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/protection/EnchantmentProtectionFall.java | package cn.nukkit.item.enchantment.protection;
import cn.nukkit.event.entity.EntityDamageEvent;
import cn.nukkit.event.entity.EntityDamageEvent.DamageCause;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentProtectionFall extends EnchantmentProtection {
public EnchantmentProtectionFall() {
super(ID_PROTECTION_FALL, "fall", 5, TYPE.FALL);
}
@Override
public int getMinEnchantAbility(int level) {
return 5 + (level - 1) * 6;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 10;
}
@Override
public double getTypeModifier() {
return 2;
}
@Override
public float getDamageProtection(EntityDamageEvent e) {
DamageCause cause = e.getCause();
if (level <= 0 || (cause != DamageCause.FALL)) {
return 0;
}
return (float) (getLevel() * getTypeModifier());
}
}
| 964 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentProtectionExplosion.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/protection/EnchantmentProtectionExplosion.java | package cn.nukkit.item.enchantment.protection;
import cn.nukkit.event.entity.EntityDamageEvent;
import cn.nukkit.event.entity.EntityDamageEvent.DamageCause;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentProtectionExplosion extends EnchantmentProtection {
public EnchantmentProtectionExplosion() {
super(ID_PROTECTION_EXPLOSION, "explosion", 2, TYPE.EXPLOSION);
}
@Override
public int getMinEnchantAbility(int level) {
return 5 + (level - 1) * 8;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 12;
}
@Override
public double getTypeModifier() {
return 2;
}
@Override
public float getDamageProtection(EntityDamageEvent e) {
DamageCause cause = e.getCause();
if (level <= 0 || (cause != DamageCause.ENTITY_EXPLOSION && cause != DamageCause.BLOCK_EXPLOSION)) {
return 0;
}
return (float) (getLevel() * getTypeModifier());
}
}
| 1,041 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentProtectionAll.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/protection/EnchantmentProtectionAll.java | package cn.nukkit.item.enchantment.protection;
import cn.nukkit.event.entity.EntityDamageEvent;
import cn.nukkit.event.entity.EntityDamageEvent.DamageCause;
import cn.nukkit.item.enchantment.Enchantment;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentProtectionAll extends EnchantmentProtection {
public EnchantmentProtectionAll() {
super(Enchantment.ID_PROTECTION_ALL, "all", 10, TYPE.ALL);
}
@Override
public int getMinEnchantAbility(int level) {
return 1 + (level - 1) * 11;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 20;
}
@Override
public double getTypeModifier() {
return 1;
}
@Override
public float getDamageProtection(EntityDamageEvent e) {
DamageCause cause = e.getCause();
if (level <= 0 || cause == DamageCause.VOID || cause == DamageCause.CUSTOM || cause == DamageCause.MAGIC) {
return 0;
}
return (float) (getLevel() * getTypeModifier());
}
}
| 1,079 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentBowKnockback.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/bow/EnchantmentBowKnockback.java | package cn.nukkit.item.enchantment.bow;
import cn.nukkit.item.enchantment.Enchantment;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentBowKnockback extends EnchantmentBow {
public EnchantmentBowKnockback() {
super(Enchantment.ID_BOW_KNOCKBACK, "arrowKnockback", 2);
}
@Override
public int getMinEnchantAbility(int level) {
return 12 + (level - 1) * 20;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 50;
}
@Override
public int getMaxLevel() {
return 2;
}
}
| 615 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentBow.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/bow/EnchantmentBow.java | package cn.nukkit.item.enchantment.bow;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.item.enchantment.EnchantmentType;
/**
* author: MagicDroidX
* Nukkit Project
*/
public abstract class EnchantmentBow extends Enchantment {
protected EnchantmentBow(int id, String name, int weight) {
super(id, name, weight, EnchantmentType.BOW);
}
}
| 375 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentBowPower.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/bow/EnchantmentBowPower.java | package cn.nukkit.item.enchantment.bow;
import cn.nukkit.item.enchantment.Enchantment;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentBowPower extends EnchantmentBow {
public EnchantmentBowPower() {
super(Enchantment.ID_BOW_POWER, "arrowDamage", 10);
}
@Override
public int getMinEnchantAbility(int level) {
return 1 + (level - 1) * 20;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 15;
}
@Override
public int getMaxLevel() {
return 5;
}
}
| 600 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentBowFlame.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/bow/EnchantmentBowFlame.java | package cn.nukkit.item.enchantment.bow;
import cn.nukkit.item.enchantment.Enchantment;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentBowFlame extends EnchantmentBow {
public EnchantmentBowFlame() {
super(Enchantment.ID_BOW_FLAME, "arrowFire", 2);
}
@Override
public int getMinEnchantAbility(int level) {
return 20;
}
@Override
public int getMaxEnchantAbility(int level) {
return 50;
}
@Override
public int getMaxLevel() {
return 1;
}
}
| 544 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentBowInfinity.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/bow/EnchantmentBowInfinity.java | package cn.nukkit.item.enchantment.bow;
import cn.nukkit.item.enchantment.Enchantment;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentBowInfinity extends EnchantmentBow {
public EnchantmentBowInfinity() {
super(Enchantment.ID_BOW_INFINITY, "arrowInfinite", 1);
}
@Override
public int getMinEnchantAbility(int level) {
return 20;
}
@Override
public int getMaxEnchantAbility(int level) {
return 50;
}
@Override
public int getMaxLevel() {
return 1;
}
}
| 557 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentDamageArthropods.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/damage/EnchantmentDamageArthropods.java | package cn.nukkit.item.enchantment.damage;
import cn.nukkit.entity.Entity;
import cn.nukkit.entity.EntityArthropod;
import cn.nukkit.potion.Effect;
import java.util.concurrent.ThreadLocalRandom;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentDamageArthropods extends EnchantmentDamage {
public EnchantmentDamageArthropods() {
super(ID_DAMAGE_ARTHROPODS, "arthropods", 5, TYPE.SMITE);
}
@Override
public int getMinEnchantAbility(int level) {
return 5 + (level - 1) * 8;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 20;
}
@Override
public double getDamageBonus(Entity entity) {
if (entity instanceof EntityArthropod) {
return getLevel() * 2.5;
}
return 0;
}
@Override
public void doPostAttack(Entity attacker, Entity entity) {
if (entity instanceof EntityArthropod) {
int duration = 20 + ThreadLocalRandom.current().nextInt(10 * this.level);
entity.addEffect(Effect.getEffect(Effect.SLOWNESS).setDuration(duration).setAmplifier(3));
}
}
}
| 1,182 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentDamage.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/damage/EnchantmentDamage.java | package cn.nukkit.item.enchantment.damage;
import cn.nukkit.item.Item;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.item.enchantment.EnchantmentType;
/**
* author: MagicDroidX
* Nukkit Project
*/
public abstract class EnchantmentDamage extends Enchantment {
public enum TYPE {
ALL,
SMITE,
ARTHROPODS
}
protected final TYPE damageType;
protected EnchantmentDamage(int id, String name, int weight, TYPE type) {
super(id, name, weight, EnchantmentType.SWORD);
this.damageType = type;
}
@Override
public boolean isCompatibleWith(Enchantment enchantment) {
return !(enchantment instanceof EnchantmentDamage);
}
@Override
public boolean canEnchant(Item item) {
return item.isAxe() || super.canEnchant(item);
}
@Override
public int getMaxLevel() {
return 5;
}
@Override
public String getName() {
return "%enchantment.damage." + this.name;
}
@Override
public boolean isMajor() {
return true;
}
}
| 1,080 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentDamageAll.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/damage/EnchantmentDamageAll.java | package cn.nukkit.item.enchantment.damage;
import cn.nukkit.entity.Entity;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentDamageAll extends EnchantmentDamage {
public EnchantmentDamageAll() {
super(ID_DAMAGE_ALL, "all", 10, TYPE.ALL);
}
@Override
public int getMinEnchantAbility(int level) {
return 1 + (level - 1) * 11;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 20;
}
@Override
public int getMaxEnchantableLevel() {
return 4;
}
@Override
public double getDamageBonus(Entity entity) {
if (this.getLevel() <= 0) {
return 0;
}
return 0.5 + getLevel() * 0.5;
}
}
| 775 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
EnchantmentDamageSmite.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/enchantment/damage/EnchantmentDamageSmite.java | package cn.nukkit.item.enchantment.damage;
import cn.nukkit.entity.Entity;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class EnchantmentDamageSmite extends EnchantmentDamage {
public EnchantmentDamageSmite() {
super(ID_DAMAGE_SMITE, "undead", 5, TYPE.SMITE);
}
@Override
public int getMinEnchantAbility(int level) {
return 5 + (level - 1) * 8;
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 20;
}
@Override
public double getDamageBonus(Entity entity) {
/*if(entity instanceof EntityZombie) {
return getLevel() * 2.5;
}*/
return 0;
}
}
| 710 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
FoodInBowl.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/food/FoodInBowl.java | package cn.nukkit.item.food;
import cn.nukkit.Player;
import cn.nukkit.item.ItemBowl;
/**
* Created by Snake1999 on 2016/1/14.
* Package cn.nukkit.item.food in project nukkit.
*/
public class FoodInBowl extends Food {
public FoodInBowl(int restoreFood, float restoreSaturation) {
this.setRestoreFood(restoreFood);
this.setRestoreSaturation(restoreSaturation);
}
@Override
protected boolean onEatenBy(Player player) {
super.onEatenBy(player);
player.getInventory().addItem(new ItemBowl());
return true;
}
}
| 574 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
FoodMilk.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/food/FoodMilk.java | package cn.nukkit.item.food;
import cn.nukkit.Player;
import cn.nukkit.item.ItemBucket;
/**
* Created by Snake1999 on 2016/1/21.
* Package cn.nukkit.item.food in project nukkit.
*/
public class FoodMilk extends Food {
@Override
protected boolean onEatenBy(Player player) {
super.onEatenBy(player);
player.getInventory().addItem(new ItemBucket());
player.removeAllEffects();
return true;
}
}
| 440 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
FoodEffective.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/food/FoodEffective.java | package cn.nukkit.item.food;
import cn.nukkit.Player;
import cn.nukkit.potion.Effect;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* Created by Snake1999 on 2016/1/13.
* Package cn.nukkit.item.food in project nukkit.
*/
public class FoodEffective extends Food {
protected final Map<Effect, Float> effects = new LinkedHashMap<>();
public FoodEffective(int restoreFood, float restoreSaturation) {
this.setRestoreFood(restoreFood);
this.setRestoreSaturation(restoreSaturation);
}
public FoodEffective addEffect(Effect effect) {
return addChanceEffect(1F, effect);
}
public FoodEffective addChanceEffect(float chance, Effect effect) {
if (chance > 1f) chance = 1f;
if (chance < 0f) chance = 0f;
effects.put(effect, chance);
return this;
}
@Override
protected boolean onEatenBy(Player player) {
super.onEatenBy(player);
List<Effect> toApply = new LinkedList<>();
effects.forEach((effect, chance) -> {
if (chance >= Math.random()) toApply.add(effect.clone());
});
toApply.forEach(player::addEffect);
return true;
}
}
| 1,243 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
Food.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/food/Food.java | package cn.nukkit.item.food;
import cn.nukkit.Player;
import cn.nukkit.block.Block;
import cn.nukkit.event.player.PlayerEatFoodEvent;
import cn.nukkit.item.Item;
import cn.nukkit.plugin.Plugin;
import cn.nukkit.potion.Effect;
import java.util.*;
/**
* Created by Snake1999 on 2016/1/13.
* Package cn.nukkit.item.food in project nukkit.
*/
public abstract class Food {
private static final Map<NodeIDMetaPlugin, Food> registryCustom = new LinkedHashMap<>();
private static final Map<NodeIDMeta, Food> registryDefault = new LinkedHashMap<>();
public static final Food apple = registerDefaultFood(new FoodNormal(4, 2.4F).addRelative(Item.APPLE));
public static final Food apple_golden = registerDefaultFood(new FoodEffective(4, 9.6F)
.addEffect(Effect.getEffect(Effect.REGENERATION).setAmplifier(1).setDuration(5 * 20))
.addEffect(Effect.getEffect(Effect.ABSORPTION).setDuration(2 * 60 * 20))
.addRelative(Item.GOLDEN_APPLE));
public static final Food apple_golden_enchanted = registerDefaultFood(new FoodEffective(4, 9.6F)
.addEffect(Effect.getEffect(Effect.REGENERATION).setAmplifier(4).setDuration(30 * 20))
.addEffect(Effect.getEffect(Effect.ABSORPTION).setDuration(2 * 60 * 20).setAmplifier(3))
.addEffect(Effect.getEffect(Effect.DAMAGE_RESISTANCE).setDuration(5 * 60 * 20))
.addEffect(Effect.getEffect(Effect.FIRE_RESISTANCE).setDuration(5 * 60 * 20))
.addRelative(Item.GOLDEN_APPLE_ENCHANTED));
public static final Food beef_raw = registerDefaultFood(new FoodNormal(3, 1.8F).addRelative(Item.RAW_BEEF));
public static final Food beetroot = registerDefaultFood(new FoodNormal(1, 1.2F).addRelative(Item.BEETROOT));
public static final Food beetroot_soup = registerDefaultFood(new FoodNormal(6, 7.2F).addRelative(Item.BEETROOT_SOUP));
public static final Food bread = registerDefaultFood(new FoodNormal(5, 6F).addRelative(Item.BREAD));
public static final Food cake_slice = registerDefaultFood(new FoodNormal(2, 0.4F)
.addRelative(Block.CAKE_BLOCK, 0).addRelative(Block.CAKE_BLOCK, 1).addRelative(Block.CAKE_BLOCK, 2)
.addRelative(Block.CAKE_BLOCK, 3).addRelative(Block.CAKE_BLOCK, 4).addRelative(Block.CAKE_BLOCK, 5)
.addRelative(Block.CAKE_BLOCK, 6));
public static final Food carrot = registerDefaultFood(new FoodNormal(3, 4.8F).addRelative(Item.CARROT));
public static final Food carrot_golden = registerDefaultFood(new FoodNormal(6, 14.4F).addRelative(Item.GOLDEN_CARROT));
public static final Food chicken_raw = registerDefaultFood(new FoodEffective(2, 1.2F)
.addChanceEffect(0.3F, Effect.getEffect(Effect.HUNGER).setDuration(30 * 20))
.addRelative(Item.RAW_CHICKEN));
public static final Food chicken_cooked = registerDefaultFood(new FoodNormal(6, 7.2F).addRelative(Item.COOKED_CHICKEN));
public static final Food chorus_fruit = registerDefaultFood(new FoodNormal(4, 2.4F));
public static final Food cookie = registerDefaultFood(new FoodNormal(2, 0.4F).addRelative(Item.COOKIE));
public static final Food melon_slice = registerDefaultFood(new FoodNormal(2, 1.2F).addRelative(Item.MELON_SLICE));
public static final Food milk = registerDefaultFood(new FoodMilk().addRelative(Item.BUCKET, 1));
public static final Food mushroom_stew = registerDefaultFood(new FoodInBowl(6, 7.2F).addRelative(Item.MUSHROOM_STEW));
public static final Food mutton_cooked = registerDefaultFood(new FoodNormal(6, 9.6F).addRelative(Item.COOKED_MUTTON));
public static final Food mutton_raw = registerDefaultFood(new FoodNormal(2, 1.2F).addRelative(Item.RAW_MUTTON));
public static final Food porkchop_cooked = registerDefaultFood(new FoodNormal(8, 12.8F).addRelative(Item.COOKED_PORKCHOP));
public static final Food porkchop_raw = registerDefaultFood(new FoodNormal(3, 1.8F).addRelative(Item.RAW_PORKCHOP));
public static final Food potato_raw = registerDefaultFood(new FoodNormal(1, 0.6F).addRelative(Item.POTATO));
public static final Food potato_baked = registerDefaultFood(new FoodNormal(5, 7.2F).addRelative(Item.BAKED_POTATO));
public static final Food potato_poisonous = registerDefaultFood(new FoodEffective(2, 1.2F)
.addChanceEffect(0.6F, Effect.getEffect(Effect.POISON).setDuration(4 * 20))
.addRelative(Item.POISONOUS_POTATO));
public static final Food pumpkin_pie = registerDefaultFood(new FoodNormal(8, 4.8F).addRelative(Item.PUMPKIN_PIE));
public static final Food rabbit_cooked = registerDefaultFood(new FoodNormal(5, 6F).addRelative(Item.COOKED_RABBIT));
public static final Food rabbit_raw = registerDefaultFood(new FoodNormal(3, 1.8F).addRelative(Item.RAW_RABBIT));
public static final Food rabbit_stew = registerDefaultFood(new FoodInBowl(10, 12F).addRelative(Item.RABBIT_STEW));
public static final Food rotten_flesh = registerDefaultFood(new FoodEffective(4, 0.8F)
.addChanceEffect(0.8F, Effect.getEffect(Effect.HUNGER).setDuration(30 * 20))
.addRelative(Item.ROTTEN_FLESH));
public static final Food spider_eye = registerDefaultFood(new FoodEffective(2, 3.2F)
.addEffect(Effect.getEffect(Effect.POISON).setDuration(4 * 20))
.addRelative(Item.SPIDER_EYE));
public static final Food steak = registerDefaultFood(new FoodNormal(8, 12.8F).addRelative(Item.COOKED_BEEF));
//different kinds of fishes
public static final Food clownfish = registerDefaultFood(new FoodNormal(1, 0.2F).addRelative(Item.CLOWNFISH));
public static final Food fish_cooked = registerDefaultFood(new FoodNormal(5, 6F).addRelative(Item.COOKED_FISH));
public static final Food fish_raw = registerDefaultFood(new FoodNormal(2, 0.4F).addRelative(Item.RAW_FISH));
public static final Food salmon_cooked = registerDefaultFood(new FoodNormal(6, 9.6F).addRelative(Item.COOKED_SALMON));
public static final Food salmon_raw = registerDefaultFood(new FoodNormal(2, 0.4F).addRelative(Item.RAW_SALMON));
public static final Food pufferfish = registerDefaultFood(new FoodEffective(1, 0.2F)
.addEffect(Effect.getEffect(Effect.HUNGER).setAmplifier(2).setDuration(15 * 20))
.addEffect(Effect.getEffect(Effect.NAUSEA).setAmplifier(1).setDuration(15 * 20))
.addEffect(Effect.getEffect(Effect.POISON).setAmplifier(4).setDuration(60 * 20))
.addRelative(Item.PUFFERFISH));
//Opened API for plugins
public static Food registerFood(Food food, Plugin plugin) {
Objects.requireNonNull(food);
Objects.requireNonNull(plugin);
food.relativeIDs.forEach(n -> registryCustom.put(new NodeIDMetaPlugin(n.id, n.meta, plugin), food));
return food;
}
private static Food registerDefaultFood(Food food) {
food.relativeIDs.forEach(n -> registryDefault.put(n, food));
return food;
}
public static Food getByRelative(Item item) {
Objects.requireNonNull(item);
return getByRelative(item.getId(), item.getDamage());
}
public static Food getByRelative(Block block) {
Objects.requireNonNull(block);
return getByRelative(block.getId(), block.getDamage());
}
public static Food getByRelative(int relativeID, int meta) {
final Food[] result = {null};
registryCustom.forEach((n, f) -> {
if (n.id == relativeID && n.meta == meta && n.plugin.isEnabled()) result[0] = f;
});
if (result[0] == null) {
registryDefault.forEach((n, f) -> {
if (n.id == relativeID && n.meta == meta) result[0] = f;
});
}
return result[0];
}
protected int restoreFood = 0;
protected float restoreSaturation = 0;
protected final List<NodeIDMeta> relativeIDs = new ArrayList<>();
public final boolean eatenBy(Player player) {
PlayerEatFoodEvent event = new PlayerEatFoodEvent(player, this);
player.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return false;
return event.getFood().onEatenBy(player);
}
protected boolean onEatenBy(Player player) {
player.getFoodData().addFoodLevel(this);
return true;
}
public Food addRelative(int relativeID) {
return addRelative(relativeID, 0);
}
public Food addRelative(int relativeID, int meta) {
NodeIDMeta node = new NodeIDMeta(relativeID, meta);
return addRelative(node);
}
private Food addRelative(NodeIDMeta node) {
if (!relativeIDs.contains(node)) relativeIDs.add(node);
return this;
}
public int getRestoreFood() {
return restoreFood;
}
public Food setRestoreFood(int restoreFood) {
this.restoreFood = restoreFood;
return this;
}
public float getRestoreSaturation() {
return restoreSaturation;
}
public Food setRestoreSaturation(float restoreSaturation) {
this.restoreSaturation = restoreSaturation;
return this;
}
static class NodeIDMeta {
final int id;
final int meta;
NodeIDMeta(int id, int meta) {
this.id = id;
this.meta = meta;
}
}
static class NodeIDMetaPlugin extends NodeIDMeta {
final Plugin plugin;
NodeIDMetaPlugin(int id, int meta, Plugin plugin) {
super(id, meta);
this.plugin = plugin;
}
}
}
| 9,504 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
FoodNormal.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/food/FoodNormal.java | package cn.nukkit.item.food;
/**
* Created by Snake1999 on 2016/1/13.
* Package cn.nukkit.item.food in project nukkit.
*/
public class FoodNormal extends Food {
public FoodNormal(int restoreFood, float restoreSaturation) {
this.setRestoreFood(restoreFood);
this.setRestoreSaturation(restoreSaturation);
}
}
| 336 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
ConstantItemSelector.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/randomitem/ConstantItemSelector.java | package cn.nukkit.item.randomitem;
import cn.nukkit.item.Item;
/**
* Created by Snake1999 on 2016/1/15.
* Package cn.nukkit.item.randomitem in project nukkit.
*/
public class ConstantItemSelector extends Selector {
protected final Item item;
public ConstantItemSelector(int id, Selector parent) {
this(id, 0, parent);
}
public ConstantItemSelector(int id, Integer meta, Selector parent) {
this(id, meta, 1, parent);
}
public ConstantItemSelector(int id, Integer meta, int count, Selector parent) {
this(new Item(id, meta, count), parent);
}
public ConstantItemSelector(Item item, Selector parent) {
super(parent);
this.item = item;
}
public Item getItem() {
return item;
}
public Object select() {
return getItem();
}
}
| 840 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
Fishing.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/randomitem/Fishing.java | package cn.nukkit.item.randomitem;
import cn.nukkit.item.Item;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.potion.Potion;
import cn.nukkit.utils.DyeColor;
import static cn.nukkit.item.randomitem.RandomItem.*;
/**
* Created by Snake1999 on 2016/1/15.
* Package cn.nukkit.item.randomitem in project nukkit.
*/
public final class Fishing {
public static final Selector ROOT_FISHING = putSelector(new Selector(ROOT));
public static final Selector FISHES = putSelector(new Selector(ROOT_FISHING), 0.85F);
public static final Selector TREASURES = putSelector(new Selector(ROOT_FISHING), 0.05F);
public static final Selector JUNKS = putSelector(new Selector(ROOT_FISHING), 0.1F);
public static final Selector FISH = putSelector(new ConstantItemSelector(Item.RAW_FISH, FISHES), 0.6F);
public static final Selector SALMON = putSelector(new ConstantItemSelector(Item.RAW_SALMON, FISHES), 0.25F);
public static final Selector CLOWNFISH = putSelector(new ConstantItemSelector(Item.CLOWNFISH, FISHES), 0.02F);
public static final Selector PUFFERFISH = putSelector(new ConstantItemSelector(Item.PUFFERFISH, FISHES), 0.13F);
public static final Selector TREASURE_BOW = putSelector(new ConstantItemSelector(Item.BOW, TREASURES), 0.1667F);
//public static final Selector TREASURE_ENCHANTED_BOOK = putSelector(Item.get(Item.ENCHANTED_BOOK, TREASURES), 0.1667F);
public static final Selector TREASURE_FISHING_ROD = putSelector(new ConstantItemSelector(Item.FISHING_ROD, TREASURES), 0.1667F);
//public static final Selector TREASURE_NAME_TAG = putSelector(Item.get(Item.NAME_TAG, TREASURES), 0.1667F);
//public static final Selector TREASURE_SADDLE = putSelector(Item.get(Item.SADDLE, TREASURES), 0.1667F);
public static final Selector JUNK_BOWL = putSelector(new ConstantItemSelector(Item.BOWL, JUNKS), 0.12F);
public static final Selector JUNK_FISHING_ROD = putSelector(new ConstantItemSelector(Item.FISHING_ROD, JUNKS), 0.024F);
public static final Selector JUNK_LEATHER = putSelector(new ConstantItemSelector(Item.LEATHER, JUNKS), 0.12F);
public static final Selector JUNK_LEATHER_BOOTS = putSelector(new ConstantItemSelector(Item.LEATHER_BOOTS, JUNKS), 0.12F);
public static final Selector JUNK_ROTTEN_FLESH = putSelector(new ConstantItemSelector(Item.ROTTEN_FLESH, JUNKS), 0.12F);
public static final Selector JUNK_STICK = putSelector(new ConstantItemSelector(Item.STICK, JUNKS), 0.06F);
public static final Selector JUNK_STRING_ITEM = putSelector(new ConstantItemSelector(Item.STRING, JUNKS), 0.06F);
public static final Selector JUNK_WATTER_BOTTLE = putSelector(new ConstantItemSelector(Item.POTION, Potion.NO_EFFECTS, JUNKS), 0.12F);
public static final Selector JUNK_BONE = putSelector(new ConstantItemSelector(Item.BONE, JUNKS), 0.12F);
public static final Selector JUNK_INK_SAC = putSelector(new ConstantItemSelector(Item.DYE, DyeColor.BLACK.getDyeData(), 10, JUNKS), 0.012F);
public static final Selector JUNK_TRIPWIRE_HOOK = putSelector(new ConstantItemSelector(Item.TRIPWIRE_HOOK, JUNKS), 0.12F);
public static Item getFishingResult(Item rod) {
int fortuneLevel = 0;
int lureLevel = 0;
if (rod != null) {
fortuneLevel = rod.getEnchantment(Enchantment.ID_FORTUNE_FISHING).getLevel();
lureLevel = rod.getEnchantment(Enchantment.ID_LURE).getLevel();
}
return getFishingResult(fortuneLevel, lureLevel);
}
public static Item getFishingResult(int fortuneLevel, int lureLevel) {
float treasureChance = limitRange(0, 1, 0.05f + 0.01f * fortuneLevel - 0.01f * lureLevel);
float junkChance = limitRange(0, 1, 0.05f - 0.025f * fortuneLevel - 0.01f * lureLevel);
float fishChance = limitRange(0, 1, 1 - treasureChance - junkChance);
putSelector(FISHES, fishChance);
putSelector(TREASURES, treasureChance);
putSelector(JUNKS, junkChance);
Object result = selectFrom(ROOT_FISHING);
if (result instanceof Item) return (Item) result;
return null;
}
private static float limitRange(float min, float max, float value) {
if (value >= max) return max;
if (value <= min) return min;
return value;
}
}
| 4,288 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
RandomItem.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/randomitem/RandomItem.java | package cn.nukkit.item.randomitem;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* Created by Snake1999 on 2016/1/15.
* Package cn.nukkit.item.randomitem in project nukkit.
*/
public final class RandomItem {
private static final Map<Selector, Float> selectors = new HashMap<>();
public static final Selector ROOT = new Selector(null);
public static Selector putSelector(Selector selector) {
return putSelector(selector, 1);
}
public static Selector putSelector(Selector selector, float chance) {
if (selector.getParent() == null) selector.setParent(ROOT);
selectors.put(selector, chance);
return selector;
}
static Object selectFrom(Selector selector) {
Objects.requireNonNull(selector);
Map<Selector, Float> child = new HashMap<>();
selectors.forEach((s, f) -> {
if (s.getParent() == selector) child.put(s, f);
});
if (child.size() == 0) return selector.select();
return selectFrom(Selector.selectRandom(child));
}
}
| 1,084 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
Selector.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/item/randomitem/Selector.java | package cn.nukkit.item.randomitem;
import java.util.Map;
/**
* Created by Snake1999 on 2016/1/15.
* Package cn.nukkit.item.randomitem in project nukkit.
*/
public class Selector {
private Selector parent;
public Selector(Selector parent) {
this.setParent(parent);
}
public Selector setParent(Selector parent) {
this.parent = parent;
return parent;
}
public Selector getParent() {
return parent;
}
public Object select() {
return this;
}
public static Selector selectRandom(Map<Selector, Float> selectorChanceMap) {
final float[] totalChance = {0};
selectorChanceMap.values().forEach(f -> totalChance[0] += f);
float resultChance = (float) (Math.random() * totalChance[0]);
final float[] flag = {0};
final boolean[] found = {false};
final Selector[] temp = {null};
selectorChanceMap.forEach((o, f) -> {
flag[0] += f;
if (flag[0] > resultChance && !found[0]) {
temp[0] = o;
found[0] = true;
}
});
return temp[0];
}
}
| 1,150 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
PrimitiveList.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/collection/PrimitiveList.java | package cn.nukkit.collection;
import java.lang.reflect.Array;
import java.util.AbstractList;
/**
* @author https://github.com/boy0001/
*/
public class PrimitiveList<T> extends AbstractList<T> {
private final Class<?> primitive;
private final Type type;
private int length;
private int totalLength;
private Object arr;
private enum Type {
Byte,
Boolean,
Short,
Character,
Integer,
Float,
Long,
Double
}
public PrimitiveList(Class<T> type) {
try {
Class<T> boxed;
if (type.isPrimitive()) {
this.primitive = type;
boxed = (Class<T>) Array.get(Array.newInstance(primitive, 1), 0).getClass();
} else {
this.primitive = (Class<?>) type.getField("TYPE").get(null);
boxed = type;
}
this.type = Type.valueOf(boxed.getSimpleName());
} catch (Throwable e) {
throw new RuntimeException(e);
}
length = 0;
totalLength = 0;
arr = Array.newInstance(primitive, 0);
}
public PrimitiveList(T[] arr) {
try {
Class<T> boxed = (Class<T>) arr.getClass().getComponentType();
this.primitive = (Class<?>) boxed.getField("TYPE").get(null);
this.type = Type.valueOf(boxed.getSimpleName());
} catch (Throwable e) {
throw new RuntimeException(e);
}
this.arr = Array.newInstance(primitive, arr.length);
for (int i = 0; i < arr.length; i++) {
T val = arr[i];
if (val != null) setFast(i, val);
}
this.length = arr.length;
this.totalLength = length;
}
public PrimitiveList(Object arr) {
if (!arr.getClass().isArray()) {
throw new IllegalArgumentException("Argument must be an array!");
}
this.primitive = arr.getClass().getComponentType();
Class<T> boxed = (Class<T>) Array.get(Array.newInstance(primitive, 1), 0).getClass();
this.type = Type.valueOf(boxed.getSimpleName());
this.arr = arr;
this.length = Array.getLength(arr);
this.totalLength = length;
}
public <R> R getArray() {
return (R) arr;
}
@Override
public T get(int index) {
return (T) getFast(index);
}
public byte getByte(int index) {
return type == Type.Double ? ((byte[]) arr)[index] : (byte) getFast(index);
}
public boolean getBoolean(int index) {
return type == Type.Boolean ? ((boolean[]) arr)[index] : (boolean) getFast(index);
}
public short getShort(int index) {
return type == Type.Short ? ((short[]) arr)[index] : (short) getFast(index);
}
public char getCharacter(int index) {
return type == Type.Character ? ((char[]) arr)[index] : (char) getFast(index);
}
public int getInt(int index) {
return type == Type.Integer ? ((int[]) arr)[index] : (int) getFast(index);
}
public float getFloat(int index) {
return type == Type.Float ? ((float[]) arr)[index] : (float) getFast(index);
}
public long getLong(int index) {
return type == Type.Long ? ((long[]) arr)[index] : (long) getFast(index);
}
public double getDouble(int index) {
return type == Type.Double ? ((double[]) arr)[index] : (double) getFast(index);
}
private final Object getFast(int index) {
switch (type) {
case Byte:
return ((byte[]) arr)[index];
case Boolean:
return ((boolean[]) arr)[index];
case Short:
return ((short[]) arr)[index];
case Character:
return ((char[]) arr)[index];
case Integer:
return ((int[]) arr)[index];
case Float:
return ((float[]) arr)[index];
case Long:
return ((long[]) arr)[index];
case Double:
return ((double[]) arr)[index];
}
return null;
}
@Override
public T set(int index, T element) {
T value = get(index);
setFast(index, element);
return value;
}
public void set(int index, char value) {
switch (type) {
default:
setFast(index, value);
return;
case Character:
((char[]) arr)[index] = value;
return;
}
}
public void set(int index, byte value) {
switch (type) {
default:
setFast(index, value);
return;
case Byte:
((byte[]) arr)[index] = value;
return;
}
}
public void set(int index, int value) {
switch (type) {
default:
setFast(index, value);
return;
case Integer:
((int[]) arr)[index] = value;
return;
case Long:
((long[]) arr)[index] = (long) value;
return;
case Double:
((double[]) arr)[index] = (double) value;
return;
}
}
public void set(int index, long value) {
switch (type) {
default:
setFast(index, value);
return;
case Integer:
((int[]) arr)[index] = (int) value;
return;
case Long:
((long[]) arr)[index] = value;
return;
case Double:
((double[]) arr)[index] = (double) value;
return;
}
}
public void set(int index, double value) {
switch (type) {
default:
setFast(index, value);
return;
case Float:
((float[]) arr)[index] = (float) value;
return;
case Long:
((long[]) arr)[index] = (long) value;
return;
case Double:
((double[]) arr)[index] = value;
return;
}
}
public final void setFast(int index, Object element) {
switch (type) {
case Byte:
((byte[]) arr)[index] = (byte) element;
return;
case Boolean:
((boolean[]) arr)[index] = (boolean) element;
return;
case Short:
((short[]) arr)[index] = (short) element;
return;
case Character:
((char[]) arr)[index] = (char) element;
return;
case Integer:
((int[]) arr)[index] = (int) element;
return;
case Float:
((float[]) arr)[index] = (float) element;
return;
case Long:
((long[]) arr)[index] = (long) element;
return;
case Double:
((double[]) arr)[index] = (double) element;
return;
}
}
@Override
public void add(int index, T element) {
if (index == length) {
if (totalLength == length) {
Object tmp = arr;
totalLength = (length << 1) + 16;
arr = Array.newInstance(primitive, totalLength);
System.arraycopy(tmp, 0, arr, 0, length);
}
setFast(length, element);
length++;
} else {
if (totalLength == length) {
Object tmp = arr;
totalLength = (length << 1) + 16;
arr = Array.newInstance(primitive, totalLength);
System.arraycopy(tmp, 0, arr, 0, index);
}
System.arraycopy(arr, index, arr, index + 1, length - index);
set(index, element);
length++;
}
}
private void ensureAddCapacity() {
if (totalLength == length) {
Object tmp = arr;
totalLength = (length << 1) + 16;
arr = Array.newInstance(primitive, totalLength);
System.arraycopy(tmp, 0, arr, 0, length);
}
}
@Override
public boolean add(T element) {
ensureAddCapacity();
setFast(length++, element);
return true;
}
public boolean add(int element) {
ensureAddCapacity();
set(length++, element);
return true;
}
public boolean add(long element) {
ensureAddCapacity();
set(length++, element);
return true;
}
public boolean add(double element) {
ensureAddCapacity();
set(length++, element);
return true;
}
public boolean add(byte element) {
ensureAddCapacity();
set(length++, element);
return true;
}
public boolean add(char element) {
ensureAddCapacity();
set(length++, element);
return true;
}
@Override
public T remove(int index) {
if (index < 0 || index > length) throw new IndexOutOfBoundsException(index + " not in [0, " + length + "]");
T value = get(index);
if (index != length) {
System.arraycopy(arr, index + 1, arr, index, length - index - 1);
}
length--;
return value;
}
@Override
public int size() {
return length;
}
@Override
public void clear() {
if (length != 0) {
this.arr = Array.newInstance(primitive, 0);
}
length = 0;
}
}
| 9,670 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
AsyncTask.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/scheduler/AsyncTask.java | package cn.nukkit.scheduler;
import cn.nukkit.Server;
import cn.nukkit.utils.ThreadStore;
import co.aikar.timings.Timings;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
/**
* @author Nukkit Project Team
*/
public abstract class AsyncTask implements Runnable {
public static final Queue<AsyncTask> FINISHED_LIST = new ConcurrentLinkedQueue<>();
private Object result;
private int taskId;
private boolean finished = false;
public void run() {
this.result = null;
this.onRun();
this.finished = true;
FINISHED_LIST.offer(this);
}
public boolean isFinished() {
return this.finished;
}
public Object getResult() {
return this.result;
}
public boolean hasResult() {
return this.result != null;
}
public void setResult(Object result) {
this.result = result;
}
public void setTaskId(int taskId) {
this.taskId = taskId;
}
public int getTaskId() {
return this.taskId;
}
public Object getFromThreadStore(String identifier) {
return this.isFinished() ? null : ThreadStore.store.get(identifier);
}
public void saveToThreadStore(String identifier, Object value) {
if (!this.isFinished()) {
if (value == null) {
ThreadStore.store.remove(identifier);
} else {
ThreadStore.store.put(identifier, value);
}
}
}
public abstract void onRun();
public void onCompletion(Server server) {
}
public void cleanObject() {
this.result = null;
this.taskId = 0;
this.finished = false;
}
public static void collectTask() {
Timings.schedulerAsyncTimer.startTiming();
while (!FINISHED_LIST.isEmpty()) {
AsyncTask task = FINISHED_LIST.poll();
try {
task.onCompletion(Server.getInstance());
} catch (Exception e) {
Server.getInstance().getLogger().critical("Exception while async task "
+ task.getTaskId()
+ " invoking onCompletion", e);
}
}
Timings.schedulerAsyncTimer.stopTiming();
}
}
| 2,274 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
ServerScheduler.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/scheduler/ServerScheduler.java | package cn.nukkit.scheduler;
import cn.nukkit.Server;
import cn.nukkit.plugin.Plugin;
import cn.nukkit.utils.PluginException;
import cn.nukkit.utils.Utils;
import java.util.ArrayDeque;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author Nukkit Project Team
*/
public class ServerScheduler {
public static int WORKERS = 4;
private final AsyncPool asyncPool;
private final Queue<TaskHandler> pending;
private final Map<Integer, ArrayDeque<TaskHandler>> queueMap;
private final Map<Integer, TaskHandler> taskMap;
private final AtomicInteger currentTaskId;
private volatile int currentTick = -1;
public ServerScheduler() {
this.pending = new ConcurrentLinkedQueue<>();
this.currentTaskId = new AtomicInteger();
this.queueMap = new ConcurrentHashMap<>();
this.taskMap = new ConcurrentHashMap<>();
this.asyncPool = new AsyncPool(Server.getInstance(), WORKERS);
}
public TaskHandler scheduleTask(Task task) {
return addTask(task, 0, 0, false);
}
/**
* @deprecated Use {@link #scheduleTask(Plugin, Runnable)
*/
@Deprecated
public TaskHandler scheduleTask(Runnable task) {
return addTask(null, task, 0, 0, false);
}
public TaskHandler scheduleTask(Plugin plugin, Runnable task) {
return addTask(plugin, task, 0, 0, false);
}
/**
* @deprecated Use {@link #scheduleTask(Plugin, Runnable, boolean)
*/
@Deprecated
public TaskHandler scheduleTask(Runnable task, boolean asynchronous) {
return addTask(null, task, 0, 0, asynchronous);
}
public TaskHandler scheduleTask(Plugin plugin, Runnable task, boolean asynchronous) {
return addTask(plugin, task, 0, 0, asynchronous);
}
/**
* @deprecated Use {@link #scheduleAsyncTask(Plugin, AsyncTask)
*/
@Deprecated
public TaskHandler scheduleAsyncTask(AsyncTask task) {
return addTask(null, task, 0, 0, true);
}
public TaskHandler scheduleAsyncTask(Plugin plugin, AsyncTask task) {
return addTask(plugin, task, 0, 0, true);
}
@Deprecated
public void scheduleAsyncTaskToWorker(AsyncTask task, int worker) {
scheduleAsyncTask(task);
}
public int getAsyncTaskPoolSize() {
return asyncPool.getCorePoolSize();
}
public void increaseAsyncTaskPoolSize(int newSize) {
throw new UnsupportedOperationException("Cannot increase a working pool size."); //wtf?
}
public TaskHandler scheduleDelayedTask(Task task, int delay) {
return this.addTask(task, delay, 0, false);
}
public TaskHandler scheduleDelayedTask(Task task, int delay, boolean asynchronous) {
return this.addTask(task, delay, 0, asynchronous);
}
/**
* @deprecated Use {@link #scheduleDelayedTask(Plugin, Runnable, int)
*/
@Deprecated
public TaskHandler scheduleDelayedTask(Runnable task, int delay) {
return addTask(null, task, delay, 0, false);
}
public TaskHandler scheduleDelayedTask(Plugin plugin, Runnable task, int delay) {
return addTask(plugin, task, delay, 0, false);
}
/**
* @deprecated Use {@link #scheduleDelayedTask(Plugin, Runnable, int, boolean)
*/
@Deprecated
public TaskHandler scheduleDelayedTask(Runnable task, int delay, boolean asynchronous) {
return addTask(null, task, delay, 0, asynchronous);
}
public TaskHandler scheduleDelayedTask(Plugin plugin, Runnable task, int delay, boolean asynchronous) {
return addTask(plugin, task, delay, 0, asynchronous);
}
/**
* @deprecated Use {@link #scheduleRepeatingTask(Plugin, Runnable, int)
*/
@Deprecated
public TaskHandler scheduleRepeatingTask(Runnable task, int period) {
return addTask(null, task, 0, period, false);
}
public TaskHandler scheduleRepeatingTask(Plugin plugin, Runnable task, int period) {
return addTask(plugin, task, 0, period, false);
}
/**
* @deprecated Use {@link #scheduleRepeatingTask(Plugin, Runnable, int, boolean)
*/
@Deprecated
public TaskHandler scheduleRepeatingTask(Runnable task, int period, boolean asynchronous) {
return addTask(null, task, 0, period, asynchronous);
}
public TaskHandler scheduleRepeatingTask(Plugin plugin, Runnable task, int period, boolean asynchronous) {
return addTask(plugin, task, 0, period, asynchronous);
}
public TaskHandler scheduleRepeatingTask(Task task, int period) {
return addTask(task, 0, period, false);
}
public TaskHandler scheduleRepeatingTask(Task task, int period, boolean asynchronous) {
return addTask(task, 0, period, asynchronous);
}
public TaskHandler scheduleDelayedRepeatingTask(Task task, int delay, int period) {
return addTask(task, delay, period, false);
}
public TaskHandler scheduleDelayedRepeatingTask(Task task, int delay, int period, boolean asynchronous) {
return addTask(task, delay, period, asynchronous);
}
/**
* @deprecated Use {@link #scheduleDelayedRepeatingTask(Plugin, Runnable, int, int)
*/
@Deprecated
public TaskHandler scheduleDelayedRepeatingTask(Runnable task, int delay, int period) {
return addTask(null, task, delay, period, false);
}
public TaskHandler scheduleDelayedRepeatingTask(Plugin plugin, Runnable task, int delay, int period) {
return addTask(plugin, task, delay, period, false);
}
/**
* @deprecated Use {@link #scheduleDelayedRepeatingTask(Plugin, Runnable, int, int, boolean)
*/
@Deprecated
public TaskHandler scheduleDelayedRepeatingTask(Runnable task, int delay, int period, boolean asynchronous) {
return addTask(null, task, delay, period, asynchronous);
}
public TaskHandler scheduleDelayedRepeatingTask(Plugin plugin, Runnable task, int delay, int period, boolean asynchronous) {
return addTask(plugin, task, delay, period, asynchronous);
}
public void cancelTask(int taskId) {
if (taskMap.containsKey(taskId)) {
try {
taskMap.remove(taskId).cancel();
} catch (RuntimeException ex) {
Server.getInstance().getLogger().critical("Exception while invoking onCancel", ex);
}
}
}
public void cancelTask(Plugin plugin) {
if (plugin == null) {
throw new NullPointerException("Plugin cannot be null!");
}
for (Map.Entry<Integer, TaskHandler> entry : taskMap.entrySet()) {
TaskHandler taskHandler = entry.getValue();
// TODO: Remove the "taskHandler.getPlugin() == null" check
// It is only there for backwards compatibility!
if (taskHandler.getPlugin() == null || plugin.equals(taskHandler.getPlugin())) {
try {
taskHandler.cancel(); /* It will remove from task map automatic in next main heartbeat. */
} catch (RuntimeException ex) {
Server.getInstance().getLogger().critical("Exception while invoking onCancel", ex);
}
}
}
}
public void cancelAllTasks() {
for (Map.Entry<Integer, TaskHandler> entry : this.taskMap.entrySet()) {
try {
entry.getValue().cancel();
} catch (RuntimeException ex) {
Server.getInstance().getLogger().critical("Exception while invoking onCancel", ex);
}
}
this.taskMap.clear();
this.queueMap .clear();
this.currentTaskId.set(0);
}
public boolean isQueued(int taskId) {
return this.taskMap.containsKey(taskId);
}
private TaskHandler addTask(Task task, int delay, int period, boolean asynchronous) {
return addTask(task instanceof PluginTask ? ((PluginTask) task).getOwner() : null, task, delay, period, asynchronous);
}
private TaskHandler addTask(Plugin plugin, Runnable task, int delay, int period, boolean asynchronous) {
if (plugin != null && plugin.isDisabled()) {
throw new PluginException("Plugin '" + plugin.getName() + "' attempted to register a task while disabled.");
}
if (delay < 0 || period < 0) {
throw new PluginException("Attempted to register a task with negative delay or period.");
}
TaskHandler taskHandler = new TaskHandler(plugin, task, nextTaskId(), asynchronous);
taskHandler.setDelay(delay);
taskHandler.setPeriod(period);
taskHandler.setNextRunTick(taskHandler.isDelayed() ? currentTick + taskHandler.getDelay() : currentTick);
if (task instanceof Task) {
((Task) task).setHandler(taskHandler);
}
pending.offer(taskHandler);
taskMap.put(taskHandler.getTaskId(), taskHandler);
return taskHandler;
}
public void mainThreadHeartbeat(int currentTick) {
// Accepts pending.
TaskHandler task;
while ((task = pending.poll()) != null) {
int tick = Math.max(currentTick, task.getNextRunTick()); // Do not schedule in the past
ArrayDeque<TaskHandler> queue = Utils.getOrCreate(queueMap, ArrayDeque.class, tick);
queue.add(task);
}
if (currentTick - this.currentTick > queueMap.size()) { // A large number of ticks have passed since the last execution
for (Map.Entry<Integer, ArrayDeque<TaskHandler>> entry : queueMap.entrySet()) {
int tick = entry.getKey();
if (tick <= currentTick) {
runTasks(tick);
}
}
} else { // Normal server tick
for (int i = this.currentTick + 1; i <= currentTick; i++) {
runTasks(currentTick);
}
}
this.currentTick = currentTick;
AsyncTask.collectTask();
}
private void runTasks(int currentTick) {
ArrayDeque<TaskHandler> queue = queueMap.remove(currentTick);
if (queue != null) {
for (TaskHandler taskHandler : queue) {
if (taskHandler.isCancelled()) {
taskMap.remove(taskHandler.getTaskId());
continue;
} else if (taskHandler.isAsynchronous()) {
asyncPool.execute(taskHandler.getTask());
} else {
taskHandler.timing.startTiming();
try {
taskHandler.run(currentTick);
} catch (Throwable e) {
Server.getInstance().getLogger().critical("Could not execute taskHandler " + taskHandler.getTaskId() + ": " + e.getMessage());
Server.getInstance().getLogger().logException(e instanceof Exception ? (Exception) e : new RuntimeException(e));
}
taskHandler.timing.stopTiming();
}
if (taskHandler.isRepeating()) {
taskHandler.setNextRunTick(currentTick + taskHandler.getPeriod());
pending.offer(taskHandler);
} else {
try {
TaskHandler removed = taskMap.remove(taskHandler.getTaskId());
if (removed != null) removed.cancel();
} catch (RuntimeException ex) {
Server.getInstance().getLogger().critical("Exception while invoking onCancel", ex);
}
}
}
}
}
public int getQueueSize() {
int size = pending.size();
for (ArrayDeque<TaskHandler> queue : queueMap.values()) {
size += queue.size();
}
return size;
}
private int nextTaskId() {
return currentTaskId.incrementAndGet();
}
}
| 12,065 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
AsyncWorker.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/scheduler/AsyncWorker.java | package cn.nukkit.scheduler;
import cn.nukkit.InterruptibleThread;
import java.util.LinkedList;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class AsyncWorker extends Thread implements InterruptibleThread {
private final LinkedList<AsyncTask> stack = new LinkedList<>();
public AsyncWorker() {
this.setName("Asynchronous Worker");
}
public void stack(AsyncTask task) {
synchronized (stack) {
stack.addFirst(task);
}
}
public void unstack() {
synchronized (stack) {
stack.clear();
}
}
public void unstack(AsyncTask task) {
synchronized (stack) {
stack.remove(task);
}
}
public void run() {
while (true) {
synchronized (stack) {
for (AsyncTask task : stack) {
if (!task.isFinished()) {
task.run();
}
}
}
try {
sleep(5);
} catch (InterruptedException e) {
//igonre
}
}
}
}
| 1,130 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
FileWriteTask.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/scheduler/FileWriteTask.java | package cn.nukkit.scheduler;
import cn.nukkit.Server;
import cn.nukkit.utils.Utils;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class FileWriteTask extends AsyncTask {
private final File file;
private final InputStream contents;
public FileWriteTask(String path, String contents) {
this(new File(path), contents);
}
public FileWriteTask(String path, byte[] contents) {
this(new File(path), contents);
}
public FileWriteTask(String path, InputStream contents) {
this.file = new File(path);
this.contents = contents;
}
public FileWriteTask(File file, String contents) {
this.file = file;
this.contents = new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8));
}
public FileWriteTask(File file, byte[] contents) {
this.file = file;
this.contents = new ByteArrayInputStream(contents);
}
public FileWriteTask(File file, InputStream contents) {
this.file = file;
this.contents = contents;
}
@Override
public void onRun() {
try {
Utils.writeFile(file, contents);
} catch (IOException e) {
Server.getInstance().getLogger().logException(e);
}
}
}
| 1,426 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
AsyncPool.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/scheduler/AsyncPool.java | package cn.nukkit.scheduler;
import cn.nukkit.Server;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* @author Nukkit Project Team
*/
public class AsyncPool extends ThreadPoolExecutor {
private final Server server;
public AsyncPool(Server server, int size) {
super(size, Integer.MAX_VALUE, 60, TimeUnit.MILLISECONDS, new SynchronousQueue<>());
this.setThreadFactory(runnable -> new Thread(runnable) {{
setDaemon(true);
setName(String.format("Nukkit Asynchronous Task Handler #%s", getPoolSize()));
}});
this.server = server;
}
@Override
protected void afterExecute(Runnable runnable, Throwable throwable) {
if (throwable != null) {
server.getLogger().critical("Exception in asynchronous task", throwable);
}
}
public Server getServer() {
return server;
}
}
| 978 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
TaskHandler.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/scheduler/TaskHandler.java | package cn.nukkit.scheduler;
import cn.nukkit.Server;
import cn.nukkit.plugin.Plugin;
import co.aikar.timings.Timing;
import co.aikar.timings.Timings;
/**
* @author MagicDroidX
*/
public class TaskHandler {
private final int taskId;
private final boolean asynchronous;
private final Plugin plugin;
private final Runnable task;
private int delay;
private int period;
private int lastRunTick;
private int nextRunTick;
private boolean cancelled;
public final Timing timing;
public TaskHandler(Plugin plugin, Runnable task, int taskId, boolean asynchronous) {
this.asynchronous = asynchronous;
this.plugin = plugin;
this.task = task;
this.taskId = taskId;
this.timing = Timings.getTaskTiming(this, period);
}
public boolean isCancelled() {
return this.cancelled;
}
public int getNextRunTick() {
return this.nextRunTick;
}
public void setNextRunTick(int nextRunTick) {
this.nextRunTick = nextRunTick;
}
public int getTaskId() {
return this.taskId;
}
public Runnable getTask() {
return this.task;
}
public int getDelay() {
return this.delay;
}
public boolean isDelayed() {
return this.delay > 0;
}
public boolean isRepeating() {
return this.period > 0;
}
public int getPeriod() {
return this.period;
}
public Plugin getPlugin() {
return plugin;
}
public int getLastRunTick() {
return lastRunTick;
}
public void setLastRunTick(int lastRunTick) {
this.lastRunTick = lastRunTick;
}
public void cancel() {
if (!this.isCancelled() && this.task instanceof Task) {
((Task) this.task).onCancel();
}
this.cancelled = true;
}
@Deprecated
public void remove() {
this.cancelled = true;
}
public void run(int currentTick) {
try {
setLastRunTick(currentTick);
getTask().run();
} catch (RuntimeException ex) {
Server.getInstance().getLogger().critical("Exception while invoking run", ex);
}
}
@Deprecated
public String getTaskName() {
return "Unknown";
}
public boolean isAsynchronous() {
return asynchronous;
}
public void setDelay(int delay) {
this.delay = delay;
}
public void setPeriod(int period) {
this.period = period;
}
}
| 2,519 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
NukkitRunnable.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/scheduler/NukkitRunnable.java | package cn.nukkit.scheduler;
import cn.nukkit.Server;
import cn.nukkit.plugin.Plugin;
/**
* This class is provided as an easy way to handle scheduling tasks.
*/
public abstract class NukkitRunnable implements Runnable {
private TaskHandler taskHandler;
/**
* Attempts to cancel this task.
*
* @throws IllegalStateException if task was not scheduled yet
*/
public synchronized void cancel() throws IllegalStateException {
taskHandler.cancel();
}
public synchronized Runnable runTask(Plugin plugin) throws IllegalArgumentException, IllegalStateException {
checkState();
this.taskHandler = Server.getInstance().getScheduler().scheduleTask(plugin, this);
return taskHandler.getTask();
}
public synchronized Runnable runTaskAsynchronously(Plugin plugin) throws IllegalArgumentException, IllegalStateException {
checkState();
this.taskHandler = Server.getInstance().getScheduler().scheduleTask(plugin, this, true);
return taskHandler.getTask();
}
public synchronized Runnable runTaskLater(Plugin plugin, int delay) throws IllegalArgumentException, IllegalStateException {
checkState();
this.taskHandler = Server.getInstance().getScheduler().scheduleDelayedTask(plugin, this, delay);
return taskHandler.getTask();
}
public synchronized Runnable runTaskLaterAsynchronously(Plugin plugin, int delay) throws IllegalArgumentException, IllegalStateException {
checkState();
this.taskHandler = Server.getInstance().getScheduler().scheduleDelayedTask(plugin, this, delay, true);
return taskHandler.getTask();
}
public synchronized Runnable runTaskTimer(Plugin plugin, int delay, int period) throws IllegalArgumentException, IllegalStateException {
checkState();
this.taskHandler = Server.getInstance().getScheduler().scheduleDelayedRepeatingTask(plugin, this, delay, period);
return taskHandler.getTask();
}
public synchronized Runnable runTaskTimerAsynchronously(Plugin plugin, int delay, int period) throws IllegalArgumentException, IllegalStateException {
checkState();
this.taskHandler = Server.getInstance().getScheduler().scheduleDelayedRepeatingTask(plugin, this, delay, period, true);
return taskHandler.getTask();
}
/**
* Gets the task id for this runnable.
*
* @return the task id that this runnable was scheduled as
* @throws IllegalStateException if task was not scheduled yet
*/
public synchronized int getTaskId() throws IllegalStateException {
if (taskHandler == null) {
throw new IllegalStateException("Not scheduled yet");
}
final int id = taskHandler.getTaskId();
return id;
}
private void checkState() {
if (taskHandler != null) {
throw new IllegalStateException("Already scheduled as " + taskHandler.getTaskId());
}
}
} | 2,991 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockUpdateScheduler.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/scheduler/BlockUpdateScheduler.java | package cn.nukkit.scheduler;
import cn.nukkit.block.Block;
import cn.nukkit.level.Level;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.NukkitMath;
import cn.nukkit.math.Vector3;
import cn.nukkit.utils.BlockUpdateEntry;
import com.google.common.collect.Maps;
import java.util.*;
public class BlockUpdateScheduler {
private final Level level;
private long lastTick;
private Map<Long, LinkedHashSet<BlockUpdateEntry>> queuedUpdates;
private Set<BlockUpdateEntry> pendingUpdates;
public BlockUpdateScheduler(Level level, long currentTick) {
queuedUpdates = Maps.newHashMap(); // Change to ConcurrentHashMap if this needs to be concurrent
lastTick = currentTick;
this.level = level;
}
public synchronized void tick(long currentTick) {
// Should only perform once, unless ticks were skipped
if (currentTick - lastTick < Short.MAX_VALUE) {// Arbitrary
for (long tick = lastTick + 1; tick <= currentTick; tick++) {
perform(tick);
}
} else {
ArrayList<Long> times = new ArrayList<>(queuedUpdates.keySet());
Collections.sort(times);
for (long tick : times) {
if (tick <= currentTick) {
perform(tick);
} else {
break;
}
}
}
lastTick = currentTick;
}
private void perform(long tick) {
try {
lastTick = tick;
Set<BlockUpdateEntry> updates = pendingUpdates = queuedUpdates.remove(tick);
if (updates != null) {
for (BlockUpdateEntry entry : updates) {
Vector3 pos = entry.pos;
if (level.isChunkLoaded(NukkitMath.floorDouble(pos.x) >> 4, NukkitMath.floorDouble(pos.z) >> 4)) {
Block block = level.getBlock(entry.pos);
if (Block.equals(block, entry.block, false)) {
block.onUpdate(level.BLOCK_UPDATE_SCHEDULED);
}
} else {
level.scheduleUpdate(entry.block, entry.pos, 0);
}
}
}
} finally {
pendingUpdates = null;
}
}
public Set<BlockUpdateEntry> getPendingBlockUpdates(AxisAlignedBB boundingBox) {
Set<BlockUpdateEntry> set = null;
for (Map.Entry<Long, LinkedHashSet<BlockUpdateEntry>> tickEntries : this.queuedUpdates.entrySet()) {
LinkedHashSet<BlockUpdateEntry> tickSet = tickEntries.getValue();
for (BlockUpdateEntry update : tickSet) {
Vector3 pos = update.pos;
if (pos.getX() >= boundingBox.getMinX() && pos.getX() < boundingBox.getMaxX() && pos.getZ() >= boundingBox.getMinZ() && pos.getZ() < boundingBox.getMaxZ()) {
if (set == null) {
set = new LinkedHashSet<>();
}
set.add(update);
}
}
}
return set;
}
public boolean isBlockTickPending(Vector3 pos, Block block) {
Set<BlockUpdateEntry> tmpUpdates = pendingUpdates;
if (tmpUpdates == null || tmpUpdates.isEmpty()) return false;
return tmpUpdates.contains(new BlockUpdateEntry(pos, block));
}
private long getMinTime(BlockUpdateEntry entry) {
return Math.max(entry.delay, lastTick + 1);
}
public void add(BlockUpdateEntry entry) {
long time = getMinTime(entry);
LinkedHashSet<BlockUpdateEntry> updateSet = queuedUpdates.get(time);
if (updateSet == null) {
LinkedHashSet<BlockUpdateEntry> tmp = queuedUpdates.putIfAbsent(time, updateSet = new LinkedHashSet<>());
if (tmp != null) updateSet = tmp;
}
updateSet.add(entry);
}
public boolean contains(BlockUpdateEntry entry) {
for (Map.Entry<Long, LinkedHashSet<BlockUpdateEntry>> tickUpdateSet : queuedUpdates.entrySet()) {
if (tickUpdateSet.getValue().contains(entry)) {
return true;
}
}
return false;
}
public boolean remove(BlockUpdateEntry entry) {
for (Map.Entry<Long, LinkedHashSet<BlockUpdateEntry>> tickUpdateSet : queuedUpdates.entrySet()) {
if (tickUpdateSet.getValue().remove(entry)) {
return true;
}
}
return false;
}
public boolean remove(Vector3 pos) {
for (Map.Entry<Long, LinkedHashSet<BlockUpdateEntry>> tickUpdateSet : queuedUpdates.entrySet()) {
if (tickUpdateSet.getValue().remove(pos)) {
return true;
}
}
return false;
}
}
| 4,806 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
PluginTask.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/scheduler/PluginTask.java | package cn.nukkit.scheduler;
import cn.nukkit.plugin.Plugin;
/**
* 插件创建的任务。<br>Task that created by a plugin.
* <p>
* <p>对于插件作者,通过继承这个类创建的任务,可以在插件被禁用时不被执行。<br>
* For plugin developers: Tasks that extend this class, won't be executed when the plugin is disabled.</p>
* <p>
* <p>另外,继承这个类的任务可以通过{@link #getOwner()}来获得这个任务所属的插件。<br>
* Otherwise, tasks that extend this class can use {@link #getOwner()} to get its owner.</p>
* <p>
* <p>下面是一个插件创建任务的例子:<br>An example for plugin create a task:
* <pre>
* public class ExampleTask extends PluginTask<ExamplePlugin>{
* public ExampleTask(ExamplePlugin plugin){
* super(plugin);
* }
*
* {@code @Override}
* public void onRun(int currentTick){
* getOwner().getLogger().info("Task is executed in tick "+currentTick);
* }
* }
* </pre></p>
*
* <p>如果要让Nukkit能够延时或循环执行这个任务,请使用{@link ServerScheduler}。<br>
* If you want Nukkit to execute this task with delay or repeat, use {@link ServerScheduler}.</p>
*
* @param <T> 这个任务所属的插件。<br>The plugin that owns this task.
* @author MagicDroidX(code) @ Nukkit Project
* @author 粉鞋大妈(javadoc) @ Nukkit Project
* @since Nukkit 1.0 | Nukkit API 1.0.0
*/
public abstract class PluginTask<T extends Plugin> extends Task {
protected final T owner;
/**
* 构造一个插件拥有的任务的方法。<br>Constructs a plugin-owned task.
*
* @param owner 这个任务的所有者插件。<br>The plugin object that owns this task.
* @since Nukkit 1.0 | Nukkit API 1.0.0
*/
public PluginTask(T owner) {
this.owner = owner;
}
/**
* 返回这个任务的所有者插件。<br>
* Returns the owner of this task.
*
* @return 这个任务的所有者插件。<br>The plugin that owns this task.
* @since Nukkit 1.0 | Nukkit API 1.0.0
*/
public final T getOwner() {
return this.owner;
}
}
| 2,206 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
Task.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/scheduler/Task.java | package cn.nukkit.scheduler;
import cn.nukkit.Server;
/**
* 表达一个任务的类。<br>A class that describes a task.
* <p>
* <p>一个任务可以被Nukkit服务器立即,延时,循环或延时循环执行。参见:{@link ServerScheduler}<br>
* A task can be executed by Nukkit server with a/an express, delay, repeat or delay&repeat.
* See:{@link ServerScheduler}</p>
* <p>
* <p>对于插件开发者,为确保自己任务能够在安全的情况下执行(比如:在插件被禁用时不执行),
* 建议让任务继承{@link PluginTask}类而不是这个类。<br>
* For plugin developers: To make sure your task will only be executed in the case of safety
* (such as: prevent this task from running if its owner plugin is disabled),
* it's suggested to use {@link PluginTask} instead of extend this class.</p>
*
* @author MagicDroidX(code) @ Nukkit Project
* @author 粉鞋大妈(javadoc) @ Nukkit Project
* @since Nukkit 1.0 | Nukkit API 1.0.0
*/
public abstract class Task implements Runnable {
private TaskHandler taskHandler = null;
public final TaskHandler getHandler() {
return this.taskHandler;
}
public final int getTaskId() {
return this.taskHandler != null ? this.taskHandler.getTaskId() : -1;
}
public final void setHandler(TaskHandler taskHandler) {
if (this.taskHandler == null || taskHandler == null) {
this.taskHandler = taskHandler;
}
}
/**
* 这个任务被执行时,会调用的过程。<br>
* What will be called when the task is executed.
*
* @param currentTick 服务器从开始运行到现在所经过的tick数,20ticks = 1秒,1tick = 0.05秒。<br>
* The elapsed tick count from the server is started. 20ticks = 1second, 1tick = 0.05second.
* @since Nukkit 1.0 | Nukkit API 1.0.0
*/
public abstract void onRun(int currentTick);
@Override
public final void run() {
this.onRun(taskHandler.getLastRunTick());
}
public void onCancel() {
}
public void cancel() {
try {
this.getHandler().cancel();
} catch (RuntimeException ex) {
Server.getInstance().getLogger().critical("Exception while invoking onCancel", ex);
}
}
}
| 2,311 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
PermissionAttachmentInfo.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/permission/PermissionAttachmentInfo.java | package cn.nukkit.permission;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class PermissionAttachmentInfo {
private Permissible permissible;
private String permission;
private PermissionAttachment attachment;
private boolean value;
public PermissionAttachmentInfo(Permissible permissible, String permission, PermissionAttachment attachment, boolean value) {
if (permission == null) {
throw new IllegalStateException("Permission may not be null");
}
this.permissible = permissible;
this.permission = permission;
this.attachment = attachment;
this.value = value;
}
public Permissible getPermissible() {
return permissible;
}
public String getPermission() {
return permission;
}
public PermissionAttachment getAttachment() {
return attachment;
}
public boolean getValue() {
return value;
}
}
| 959 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
PermissionRemovedExecutor.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/permission/PermissionRemovedExecutor.java | package cn.nukkit.permission;
/**
* author: MagicDroidX
* Nukkit Project
*/
public interface PermissionRemovedExecutor {
void attachmentRemoved(PermissionAttachment attachment);
}
| 189 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
Permission.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/permission/Permission.java | package cn.nukkit.permission;
import cn.nukkit.Server;
import java.util.*;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class Permission {
public final static String DEFAULT_OP = "op";
public final static String DEFAULT_NOT_OP = "notop";
public final static String DEFAULT_TRUE = "true";
public final static String DEFAULT_FALSE = "false";
public static final String DEFAULT_PERMISSION = DEFAULT_OP;
public static String getByName(String value) {
switch (value.toLowerCase()) {
case "op":
case "isop":
case "operator":
case "isoperator":
case "admin":
case "isadmin":
return DEFAULT_OP;
case "!op":
case "notop":
case "!operator":
case "notoperator":
case "!admin":
case "notadmin":
return DEFAULT_NOT_OP;
case "true":
return DEFAULT_TRUE;
default:
return DEFAULT_FALSE;
}
}
private final String name;
private String description;
private Map<String, Boolean> children = new HashMap<>();
private String defaultValue;
public Permission(String name) {
this(name, null, null, new HashMap<>());
}
public Permission(String name, String description) {
this(name, description, null, new HashMap<>());
}
public Permission(String name, String description, String defualtValue) {
this(name, description, defualtValue, new HashMap<>());
}
public Permission(String name, String description, String defualtValue, Map<String, Boolean> children) {
this.name = name;
this.description = description != null ? description : "";
this.defaultValue = defualtValue != null ? defualtValue : DEFAULT_PERMISSION;
this.children = children;
this.recalculatePermissibles();
}
public String getName() {
return name;
}
public Map<String, Boolean> getChildren() {
return children;
}
public String getDefault() {
return defaultValue;
}
public void setDefault(String value) {
if (!value.equals(this.defaultValue)) {
this.defaultValue = value;
this.recalculatePermissibles();
}
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Set<Permissible> getPermissibles() {
return Server.getInstance().getPluginManager().getPermissionSubscriptions(this.name);
}
public void recalculatePermissibles() {
Set<Permissible> perms = this.getPermissibles();
Server.getInstance().getPluginManager().recalculatePermissionDefaults(this);
for (Permissible p : perms) {
p.recalculatePermissions();
}
}
public void addParent(Permission permission, boolean value) {
this.getChildren().put(this.getName(), value);
permission.recalculatePermissibles();
}
public Permission addParent(String name, boolean value) {
Permission perm = Server.getInstance().getPluginManager().getPermission(name);
if (perm == null) {
perm = new Permission(name);
Server.getInstance().getPluginManager().addPermission(perm);
}
this.addParent(perm, value);
return perm;
}
public static List<Permission> loadPermissions(Map<String, Object> data) {
return loadPermissions(data, DEFAULT_OP);
}
public static List<Permission> loadPermissions(Map<String, Object> data, String defaultValue) {
List<Permission> result = new ArrayList<>();
if (data != null) {
for (Map.Entry e : data.entrySet()) {
String key = (String) e.getKey();
Map<String, Object> entry = (Map<String, Object>) e.getValue();
result.add(loadPermission(key, entry, defaultValue, result));
}
}
return result;
}
public static Permission loadPermission(String name, Map<String, Object> data) {
return loadPermission(name, data, DEFAULT_OP, new ArrayList<>());
}
public static Permission loadPermission(String name, Map<String, Object> data, String defaultValue) {
return loadPermission(name, data, defaultValue, new ArrayList<>());
}
public static Permission loadPermission(String name, Map<String, Object> data, String defaultValue, List<Permission> output) {
String desc = null;
Map<String, Boolean> children = new HashMap<>();
if (data.containsKey("default")) {
String value = Permission.getByName(String.valueOf(data.get("default")));
if (value != null) {
defaultValue = value;
} else {
throw new IllegalStateException("'default' key contained unknown value");
}
}
if (data.containsKey("children")) {
if (data.get("children") instanceof Map) {
for (Map.Entry entry : ((Map<String, Object>) data.get("children")).entrySet()) {
String k = (String) entry.getKey();
Object v = entry.getValue();
if (v instanceof Map) {
Permission permission = loadPermission(k, (Map<String, Object>) v, defaultValue, output);
if (permission != null) {
output.add(permission);
}
}
children.put(k, true);
}
} else {
throw new IllegalStateException("'children' key is of wrong type");
}
}
if (data.containsKey("description")) {
desc = (String) data.get("description");
}
return new Permission(name, desc, defaultValue, children);
}
}
| 6,033 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
DefaultPermissions.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/permission/DefaultPermissions.java | package cn.nukkit.permission;
import cn.nukkit.Server;
/**
* author: MagicDroidX
* Nukkit Project
*/
public abstract class DefaultPermissions {
public static final String ROOT = "nukkit";
public static Permission registerPermission(Permission perm) {
return registerPermission(perm, null);
}
public static Permission registerPermission(Permission perm, Permission parent) {
if (parent != null) {
parent.getChildren().put(perm.getName(), true);
}
Server.getInstance().getPluginManager().addPermission(perm);
return Server.getInstance().getPluginManager().getPermission(perm.getName());
}
public static void registerCorePermissions() {
Permission parent = registerPermission(new Permission(ROOT, "Allows using all Nukkit commands and utilities"));
Permission broadcasts = registerPermission(new Permission(ROOT + ".broadcast", "Allows the user to receive all broadcast messages"), parent);
registerPermission(new Permission(ROOT + ".broadcast.admin", "Allows the user to receive administrative broadcasts", Permission.DEFAULT_OP), broadcasts);
registerPermission(new Permission(ROOT + ".broadcast.user", "Allows the user to receive user broadcasts", Permission.DEFAULT_TRUE), broadcasts);
broadcasts.recalculatePermissibles();
Permission commands = registerPermission(new Permission(ROOT + ".command", "Allows using all Nukkit commands"), parent);
Permission whitelist = registerPermission(new Permission(ROOT + ".command.whitelist", "Allows the user to modify the server whitelist", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.whitelist.add", "Allows the user to add a player to the server whitelist"), whitelist);
registerPermission(new Permission(ROOT + ".command.whitelist.remove", "Allows the user to remove a player to the server whitelist"), whitelist);
registerPermission(new Permission(ROOT + ".command.whitelist.reload", "Allows the user to reload the server whitelist"), whitelist);
registerPermission(new Permission(ROOT + ".command.whitelist.enable", "Allows the user to enable the server whitelist"), whitelist);
registerPermission(new Permission(ROOT + ".command.whitelist.disable", "Allows the user to disable the server whitelist"), whitelist);
registerPermission(new Permission(ROOT + ".command.whitelist.list", "Allows the user to list all the players on the server whitelist"), whitelist);
whitelist.recalculatePermissibles();
Permission ban = registerPermission(new Permission(ROOT + ".command.ban", "Allows the user to ban people", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.ban.player", "Allows the user to ban players"), ban);
registerPermission(new Permission(ROOT + ".command.ban.ip", "Allows the user to ban IP addresses"), ban);
registerPermission(new Permission(ROOT + ".command.ban.list", "Allows the user to list all the banned ips or players"), ban);
ban.recalculatePermissibles();
Permission unban = registerPermission(new Permission(ROOT + ".command.unban", "Allows the user to unban people", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.unban.player", "Allows the user to unban players"), unban);
registerPermission(new Permission(ROOT + ".command.unban.ip", "Allows the user to unban IP addresses"), unban);
unban.recalculatePermissibles();
Permission op = registerPermission(new Permission(ROOT + ".command.op", "Allows the user to change operators", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.op.give", "Allows the user to give a player operator status"), op);
registerPermission(new Permission(ROOT + ".command.op.take", "Allows the user to take a players operator status"), op);
op.recalculatePermissibles();
Permission save = registerPermission(new Permission(ROOT + ".command.save", "Allows the user to save the worlds", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.save.enable", "Allows the user to enable automatic saving"), save);
registerPermission(new Permission(ROOT + ".command.save.disable", "Allows the user to disable automatic saving"), save);
registerPermission(new Permission(ROOT + ".command.save.perform", "Allows the user to perform a manual save"), save);
save.recalculatePermissibles();
Permission time = registerPermission(new Permission(ROOT + ".command.time", "Allows the user to alter the time", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.time.add", "Allows the user to fast-forward time"), time);
registerPermission(new Permission(ROOT + ".command.time.set", "Allows the user to change the time"), time);
registerPermission(new Permission(ROOT + ".command.time.start", "Allows the user to restart the time"), time);
registerPermission(new Permission(ROOT + ".command.time.stop", "Allows the user to stop the time"), time);
registerPermission(new Permission(ROOT + ".command.time.query", "Allows the user query the time"), time);
time.recalculatePermissibles();
Permission kill = registerPermission(new Permission(ROOT + ".command.kill", "Allows the user to kill players", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.kill.self", "Allows the user to commit suicide", Permission.DEFAULT_TRUE), kill);
registerPermission(new Permission(ROOT + ".command.kill.other", "Allows the user to kill other players"), kill);
kill.recalculatePermissibles();
Permission gamemode = registerPermission(new Permission(ROOT + ".command.gamemode", "Allows the user to change the gamemode of players", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.gamemode.survival", "Allows the user to change the gamemode to survival", Permission.DEFAULT_OP), gamemode);
registerPermission(new Permission(ROOT + ".command.gamemode.creative", "Allows the user to change the gamemode to creative", Permission.DEFAULT_OP), gamemode);
registerPermission(new Permission(ROOT + ".command.gamemode.adventure", "Allows the user to change the gamemode to adventure", Permission.DEFAULT_OP), gamemode);
registerPermission(new Permission(ROOT + ".command.gamemode.spectator", "Allows the user to change the gamemode to spectator", Permission.DEFAULT_OP), gamemode);
registerPermission(new Permission(ROOT + ".command.gamemode.other", "Allows the user to change the gamemode of other players", Permission.DEFAULT_OP), gamemode);
gamemode.recalculatePermissibles();
registerPermission(new Permission(ROOT + ".command.me", "Allows the user to perform a chat action", Permission.DEFAULT_TRUE), commands);
registerPermission(new Permission(ROOT + ".command.tell", "Allows the user to privately message another player", Permission.DEFAULT_TRUE), commands);
registerPermission(new Permission(ROOT + ".command.say", "Allows the user to talk as the console", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.give", "Allows the user to give items to players", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.effect", "Allows the user to give/take potion effects", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.particle", "Allows the user to create particle effects", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.teleport", "Allows the user to teleport players", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.kick", "Allows the user to kick players", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.stop", "Allows the user to stop the server", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.list", "Allows the user to list all online players", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.help", "Allows the user to view the help menu", Permission.DEFAULT_TRUE), commands);
registerPermission(new Permission(ROOT + ".command.plugins", "Allows the user to view the list of plugins", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.reload", "Allows the user to reload the server settings", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.version", "Allows the user to view the version of the server", Permission.DEFAULT_TRUE), commands);
registerPermission(new Permission(ROOT + ".command.defaultgamemode", "Allows the user to change the default gamemode", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.seed", "Allows the user to view the seed of the world", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.status", "Allows the user to view the server performance", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.gc", "Allows the user to fire garbage collection tasks", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.dumpmemory", "Allows the user to dump memory contents", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.gamerule", "Sets or queries a game rule value", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.timings", "Allows the user to records timings for all plugin events", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.title", "Allows the user to send titles to players", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.spawnpoint", "Allows the user to change player's spawnpoint", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.setworldspawn", "Allows the user to change the world spawn", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.weather", "Allows the user to change the weather", Permission.DEFAULT_OP), commands);
registerPermission(new Permission(ROOT + ".command.xp", "Allows the user to give experience", Permission.DEFAULT_OP), commands);
commands.recalculatePermissibles();
parent.recalculatePermissibles();
}
}
| 10,885 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BanList.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/permission/BanList.java | package cn.nukkit.permission;
import cn.nukkit.utils.MainLogger;
import cn.nukkit.utils.Utils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BanList {
private LinkedHashMap<String, BanEntry> list = new LinkedHashMap<>();
private final String file;
private boolean enable = true;
public BanList(String file) {
this.file = file;
}
public boolean isEnable() {
return enable;
}
public void setEnable(boolean enable) {
this.enable = enable;
}
public LinkedHashMap<String, BanEntry> getEntires() {
removeExpired();
return this.list;
}
public boolean isBanned(String name) {
if (!this.isEnable() || name == null) {
return false;
} else {
this.removeExpired();
return this.list.containsKey(name.toLowerCase());
}
}
public void add(BanEntry entry) {
this.list.put(entry.getName(), entry);
this.save();
}
public BanEntry addBan(String target) {
return this.addBan(target, null);
}
public BanEntry addBan(String target, String reason) {
return this.addBan(target, reason, null);
}
public BanEntry addBan(String target, String reason, Date expireDate) {
return this.addBan(target, reason, expireDate, null);
}
public BanEntry addBan(String target, String reason, Date expireDate, String source) {
BanEntry entry = new BanEntry(target);
entry.setSource(source != null ? source : entry.getSource());
entry.setExpirationDate(expireDate);
entry.setReason(reason != null ? reason : entry.getReason());
this.add(entry);
return entry;
}
public void remove(String name) {
name = name.toLowerCase();
if (this.list.containsKey(name)) {
this.list.remove(name);
this.save();
}
}
public void removeExpired() {
for (String name : new ArrayList<>(this.list.keySet())) {
BanEntry entry = this.list.get(name);
if (entry.hasExpired()) {
list.remove(name);
}
}
}
public void load() {
this.list = new LinkedHashMap<>();
File file = new File(this.file);
try {
if (!file.exists()) {
file.createNewFile();
this.save();
} else {
LinkedList<TreeMap<String, String>> list = new Gson().fromJson(Utils.readFile(this.file), new TypeToken<LinkedList<TreeMap<String, String>>>() {
}.getType());
for (TreeMap<String, String> map : list) {
BanEntry entry = BanEntry.fromMap(map);
this.list.put(entry.getName(), entry);
}
}
} catch (IOException e) {
MainLogger.getLogger().error("Could not load ban list: ", e);
}
}
public void save() {
this.removeExpired();
try {
File file = new File(this.file);
if (!file.exists()) {
file.createNewFile();
}
LinkedList<LinkedHashMap<String, String>> list = new LinkedList<>();
for (BanEntry entry : this.list.values()) {
list.add(entry.getMap());
}
Utils.writeFile(this.file, new ByteArrayInputStream(new GsonBuilder().setPrettyPrinting().create().toJson(list).getBytes(StandardCharsets.UTF_8)));
} catch (IOException e) {
MainLogger.getLogger().error("Could not save ban list ", e);
}
}
}
| 3,891 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
PermissionAttachment.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/permission/PermissionAttachment.java | package cn.nukkit.permission;
import cn.nukkit.plugin.Plugin;
import cn.nukkit.utils.PluginException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class PermissionAttachment {
private PermissionRemovedExecutor removed = null;
private final Map<String, Boolean> permissions = new HashMap<>();
private Permissible permissible;
private Plugin plugin;
public PermissionAttachment(Plugin plugin, Permissible permissible) {
if (!plugin.isEnabled()) {
throw new PluginException("Plugin " + plugin.getDescription().getName() + " is disabled");
}
this.permissible = permissible;
this.plugin = plugin;
}
public Plugin getPlugin() {
return plugin;
}
public void setRemovalCallback(PermissionRemovedExecutor executor) {
this.removed = executor;
}
public PermissionRemovedExecutor getRemovalCallback() {
return removed;
}
public Map<String, Boolean> getPermissions() {
return permissions;
}
public void clearPermissions() {
this.permissions.clear();
this.permissible.recalculatePermissions();
}
public void setPermissions(Map<String, Boolean> permissions) {
for (Map.Entry<String, Boolean> entry : permissions.entrySet()) {
String key = entry.getKey();
Boolean value = entry.getValue();
this.permissions.put(key, value);
}
this.permissible.recalculatePermissions();
}
public void unsetPermissions(List<String> permissions) {
for (String node : permissions) {
this.permissions.remove(node);
}
this.permissible.recalculatePermissions();
}
public void setPermission(Permission permission, boolean value) {
this.setPermission(permission.getName(), value);
}
public void setPermission(String name, boolean value) {
if (this.permissions.containsKey(name)) {
if (this.permissions.get(name).equals(value)) {
return;
}
this.permissions.remove(name);
}
this.permissions.put(name, value);
this.permissible.recalculatePermissions();
}
public void unsetPermission(Permission permission, boolean value) {
this.unsetPermission(permission.getName(), value);
}
public void unsetPermission(String name, boolean value) {
if (this.permissions.containsKey(name)) {
this.permissions.remove(name);
this.permissible.recalculatePermissions();
}
}
public void remove() {
this.permissible.removeAttachment(this);
}
}
| 2,736 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
ServerOperator.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/permission/ServerOperator.java | package cn.nukkit.permission;
/**
* 能成为服务器管理员(OP)的对象。<br>
* Who can be an operator(OP).
*
* @author MagicDroidX(code) @ Nukkit Project
* @author 粉鞋大妈(javadoc) @ Nukkit Project
* @see cn.nukkit.permission.Permissible
* @since Nukkit 1.0 | Nukkit API 1.0.0
*/
public interface ServerOperator {
/**
* 返回这个对象是不是服务器管理员。<br>
* Returns if this object is an operator.
*
* @return 这个对象是不是服务器管理员。<br>if this object is an operator.
* @since Nukkit 1.0 | Nukkit API 1.0.0
*/
boolean isOp();
/**
* 把这个对象设置成服务器管理员。<br>
* Sets this object to be an operator or not to be.
*
* @param value {@code true}为授予管理员,{@code false}为取消管理员。<br>
* {@code true} for giving this operator or {@code false} for cancelling.
* @since Nukkit 1.0 | Nukkit API 1.0.0
*/
void setOp(boolean value);
}
| 1,018 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
Permissible.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/permission/Permissible.java | package cn.nukkit.permission;
import cn.nukkit.plugin.Plugin;
import java.util.Map;
/**
* author: MagicDroidX
* Nukkit Project
*/
public interface Permissible extends ServerOperator {
boolean isPermissionSet(String name);
boolean isPermissionSet(Permission permission);
boolean hasPermission(String name);
boolean hasPermission(Permission permission);
PermissionAttachment addAttachment(Plugin plugin);
PermissionAttachment addAttachment(Plugin plugin, String name);
PermissionAttachment addAttachment(Plugin plugin, String name, Boolean value);
void removeAttachment(PermissionAttachment attachment);
void recalculatePermissions();
Map<String, PermissionAttachmentInfo> getEffectivePermissions();
}
| 757 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BanEntry.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/permission/BanEntry.java | package cn.nukkit.permission;
import cn.nukkit.Server;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BanEntry {
public static final String format = "yyyy-MM-dd hh:mm:ss Z";
private final String name;
private Date creationDate = null;
private String source = "(Unknown)";
private Date expirationDate = null;
private String reason = "Banned by an operator.";
public BanEntry(String name) {
this.name = name.toLowerCase();
this.creationDate = new Date();
}
public String getName() {
return name;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public Date getExpirationDate() {
return expirationDate;
}
public void setExpirationDate(Date expirationDate) {
this.expirationDate = expirationDate;
}
public boolean hasExpired() {
Date now = new Date();
return this.expirationDate != null && this.expirationDate.before(now);
}
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
public LinkedHashMap<String, String> getMap() {
LinkedHashMap<String, String> map = new LinkedHashMap<>();
map.put("name", getName());
map.put("creationDate", new SimpleDateFormat(format).format(getCreationDate()));
map.put("source", this.getSource());
map.put("expireDate", getExpirationDate() != null ? new SimpleDateFormat(format).format(getExpirationDate()) : "Forever");
map.put("reason", this.getReason());
return map;
}
public static BanEntry fromMap(Map<String, String> map) {
BanEntry banEntry = new BanEntry(map.get("name"));
try {
banEntry.setCreationDate(new SimpleDateFormat(format).parse(map.get("creationDate")));
banEntry.setExpirationDate(!map.get("expireDate").equals("Forever") ? new SimpleDateFormat(format).parse(map.get("expireDate")) : null);
} catch (ParseException e) {
Server.getInstance().getLogger().logException(e);
}
banEntry.setSource(map.get("source"));
banEntry.setReason(map.get("reason"));
return banEntry;
}
public String getString() {
return new Gson().toJson(this.getMap());
}
public static BanEntry fromString(String str) {
Map<String, String> map = new Gson().fromJson(str, new TypeToken<TreeMap<String, String>>() {
}.getType());
BanEntry banEntry = new BanEntry(map.get("name"));
try {
banEntry.setCreationDate(new SimpleDateFormat(format).parse(map.get("creationDate")));
banEntry.setExpirationDate(!map.get("expireDate").equals("Forever") ? new SimpleDateFormat(format).parse(map.get("expireDate")) : null);
} catch (ParseException e) {
Server.getInstance().getLogger().logException(e);
}
banEntry.setSource(map.get("source"));
banEntry.setReason(map.get("reason"));
return banEntry;
}
}
| 3,551 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
PermissibleBase.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/permission/PermissibleBase.java | package cn.nukkit.permission;
import cn.nukkit.Server;
import cn.nukkit.plugin.Plugin;
import cn.nukkit.utils.PluginException;
import cn.nukkit.utils.ServerException;
import co.aikar.timings.Timings;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class PermissibleBase implements Permissible {
ServerOperator opable = null;
private Permissible parent = null;
private final Set<PermissionAttachment> attachments = new HashSet<>();
private final Map<String, PermissionAttachmentInfo> permissions = new HashMap<>();
public PermissibleBase(ServerOperator opable) {
this.opable = opable;
if (opable instanceof Permissible) {
this.parent = (Permissible) opable;
}
}
@Override
public boolean isOp() {
return this.opable != null && this.opable.isOp();
}
@Override
public void setOp(boolean value) {
if (this.opable == null) {
throw new ServerException("Cannot change op value as no ServerOperator is set");
} else {
this.opable.setOp(value);
}
}
@Override
public boolean isPermissionSet(String name) {
return this.permissions.containsKey(name);
}
@Override
public boolean isPermissionSet(Permission permission) {
return this.isPermissionSet(permission.getName());
}
@Override
public boolean hasPermission(String name) {
if (this.isPermissionSet(name)) {
return this.permissions.get(name).getValue();
}
Permission perm = Server.getInstance().getPluginManager().getPermission(name);
if (perm != null) {
String permission = perm.getDefault();
return Permission.DEFAULT_TRUE.equals(permission) || (this.isOp() && Permission.DEFAULT_OP.equals(permission)) || (!this.isOp() && Permission.DEFAULT_NOT_OP.equals(permission));
} else {
return Permission.DEFAULT_TRUE.equals(Permission.DEFAULT_PERMISSION) || (this.isOp() && Permission.DEFAULT_OP.equals(Permission.DEFAULT_PERMISSION)) || (!this.isOp() && Permission.DEFAULT_NOT_OP.equals(Permission.DEFAULT_PERMISSION));
}
}
@Override
public boolean hasPermission(Permission permission) {
return this.hasPermission(permission.getName());
}
@Override
public PermissionAttachment addAttachment(Plugin plugin) {
return this.addAttachment(plugin, null, null);
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name) {
return this.addAttachment(plugin, name, null);
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name, Boolean value) {
if (!plugin.isEnabled()) {
throw new PluginException("Plugin " + plugin.getDescription().getName() + " is disabled");
}
PermissionAttachment result = new PermissionAttachment(plugin, this.parent != null ? this.parent : this);
this.attachments.add(result);
if (name != null && value != null) {
result.setPermission(name, value);
}
this.recalculatePermissions();
return result;
}
@Override
public void removeAttachment(PermissionAttachment attachment) {
if (this.attachments.contains(attachment)) {
this.attachments.remove(attachment);
PermissionRemovedExecutor ex = attachment.getRemovalCallback();
if (ex != null) {
ex.attachmentRemoved(attachment);
}
this.recalculatePermissions();
}
}
@Override
public void recalculatePermissions() {
Timings.permissibleCalculationTimer.startTiming();
this.clearPermissions();
Map<String, Permission> defaults = Server.getInstance().getPluginManager().getDefaultPermissions(this.isOp());
Server.getInstance().getPluginManager().subscribeToDefaultPerms(this.isOp(), this.parent != null ? this.parent : this);
for (Permission perm : defaults.values()) {
String name = perm.getName();
this.permissions.put(name, new PermissionAttachmentInfo(this.parent != null ? this.parent : this, name, null, true));
Server.getInstance().getPluginManager().subscribeToPermission(name, this.parent != null ? this.parent : this);
this.calculateChildPermissions(perm.getChildren(), false, null);
}
for (PermissionAttachment attachment : this.attachments) {
this.calculateChildPermissions(attachment.getPermissions(), false, attachment);
}
Timings.permissibleCalculationTimer.stopTiming();
}
public void clearPermissions() {
for (String name : this.permissions.keySet()) {
Server.getInstance().getPluginManager().unsubscribeFromPermission(name, this.parent != null ? this.parent : this);
}
Server.getInstance().getPluginManager().unsubscribeFromDefaultPerms(false, this.parent != null ? this.parent : this);
Server.getInstance().getPluginManager().unsubscribeFromDefaultPerms(true, this.parent != null ? this.parent : this);
this.permissions.clear();
}
private void calculateChildPermissions(Map<String, Boolean> children, boolean invert, PermissionAttachment attachment) {
for (Map.Entry<String, Boolean> entry : children.entrySet()) {
String name = entry.getKey();
Permission perm = Server.getInstance().getPluginManager().getPermission(name);
boolean v = entry.getValue();
boolean value = (v ^ invert);
this.permissions.put(name, new PermissionAttachmentInfo(this.parent != null ? this.parent : this, name, attachment, value));
Server.getInstance().getPluginManager().subscribeToPermission(name, this.parent != null ? this.parent : this);
if (perm != null) {
this.calculateChildPermissions(perm.getChildren(), !value, attachment);
}
}
}
@Override
public Map<String, PermissionAttachmentInfo> getEffectivePermissions() {
return this.permissions;
}
}
| 6,236 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
TranslationContainer.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/lang/TranslationContainer.java | package cn.nukkit.lang;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class TranslationContainer extends TextContainer implements Cloneable {
protected String[] params;
public TranslationContainer(String text) {
this(text, new String[]{});
}
public TranslationContainer(String text, String params) {
super(text);
this.setParameters(new String[]{params});
}
public TranslationContainer(String text, String... params) {
super(text);
this.setParameters(params);
}
public String[] getParameters() {
return params;
}
public void setParameters(String[] params) {
this.params = params;
}
public String getParameter(int i) {
return (i >= 0 && i < this.params.length) ? this.params[i] : null;
}
public void setParameter(int i, String str) {
if (i >= 0 && i < this.params.length) {
this.params[i] = str;
}
}
@Override
public TranslationContainer clone() {
return new TranslationContainer(this.text, this.params.clone());
}
}
| 1,107 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
TextContainer.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/lang/TextContainer.java | package cn.nukkit.lang;
import cn.nukkit.Server;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class TextContainer implements Cloneable {
protected String text;
public TextContainer(String text) {
this.text = text;
}
public void setText(String text) {
this.text = text;
}
public String getText() {
return text;
}
@Override
public String toString() {
return this.getText();
}
@Override
public TextContainer clone() {
try {
return (TextContainer) super.clone();
} catch (CloneNotSupportedException e) {
Server.getInstance().getLogger().logException(e);
}
return null;
}
}
| 727 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BaseLang.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/lang/BaseLang.java | package cn.nukkit.lang;
import cn.nukkit.Server;
import cn.nukkit.utils.Utils;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BaseLang {
public static final String FALLBACK_LANGUAGE = "eng";
protected final String langName;
protected Map<String, String> lang = new HashMap<>();
protected Map<String, String> fallbackLang = new HashMap<>();
public BaseLang(String lang) {
this(lang, null);
}
public BaseLang(String lang, String path) {
this(lang, path, FALLBACK_LANGUAGE);
}
public BaseLang(String lang, String path, String fallback) {
this.langName = lang.toLowerCase();
boolean useFallback = !lang.equals(fallback);
if (path == null) {
path = "lang/";
this.lang = this.loadLang(this.getClass().getClassLoader().getResourceAsStream(path + this.langName + "/lang.ini"));
if (useFallback) this.fallbackLang = this.loadLang(this.getClass().getClassLoader().getResourceAsStream(path + fallback + "/lang.ini"));
} else {
this.lang = this.loadLang(path + this.langName + "/lang.ini");
if (useFallback) this.fallbackLang = this.loadLang(path + fallback + "/lang.ini");
}
if (this.fallbackLang == null) this.fallbackLang = this.lang;
}
public Map<String, String> getLangMap() {
return lang;
}
public Map<String, String> getFallbackLangMap() {
return fallbackLang;
}
public String getName() {
return this.get("language.name");
}
public String getLang() {
return langName;
}
protected Map<String, String> loadLang(String path) {
try {
String content = Utils.readFile(path);
Map<String, String> d = new HashMap<>();
for (String line : content.split("\n")) {
line = line.trim();
if (line.equals("") || line.charAt(0) == '#') {
continue;
}
String[] t = line.split("=");
if (t.length < 2) {
continue;
}
String key = t[0];
String value = "";
for (int i = 1; i < t.length - 1; i++) {
value += t[i] + "=";
}
value += t[t.length - 1];
if (value.equals("")) {
continue;
}
d.put(key, value);
}
return d;
} catch (IOException e) {
Server.getInstance().getLogger().logException(e);
return null;
}
}
protected Map<String, String> loadLang(InputStream stream) {
try {
String content = Utils.readFile(stream);
Map<String, String> d = new HashMap<>();
for (String line : content.split("\n")) {
line = line.trim();
if (line.equals("") || line.charAt(0) == '#') {
continue;
}
String[] t = line.split("=");
if (t.length < 2) {
continue;
}
String key = t[0];
String value = "";
for (int i = 1; i < t.length - 1; i++) {
value += t[i] + "=";
}
value += t[t.length - 1];
if (value.equals("")) {
continue;
}
d.put(key, value);
}
return d;
} catch (IOException e) {
Server.getInstance().getLogger().logException(e);
return null;
}
}
public String translateString(String str) {
return this.translateString(str, new String[]{}, null);
}
public String translateString(String str, String... params) {
return this.translateString(str, params, null);
}
public String translateString(String str, String param, String onlyPrefix) {
return this.translateString(str, new String[]{param}, onlyPrefix);
}
public String translateString(String str, String[] params, String onlyPrefix) {
String baseText = this.get(str);
baseText = this.parseTranslation((baseText != null && (onlyPrefix == null || str.indexOf(onlyPrefix) == 0)) ? baseText : str, onlyPrefix);
for (int i = 0; i < params.length; i++) {
baseText = baseText.replace("{%" + i + "}", this.parseTranslation(String.valueOf(params[i])));
}
return baseText;
}
public String translate(TextContainer c) {
String baseText = this.parseTranslation(c.getText());
if (c instanceof TranslationContainer) {
baseText = this.internalGet(c.getText());
baseText = this.parseTranslation(baseText != null ? baseText : c.getText());
for (int i = 0; i < ((TranslationContainer) c).getParameters().length; i++) {
baseText = baseText.replace("{%" + i + "}", this.parseTranslation(((TranslationContainer) c).getParameters()[i]));
}
}
return baseText;
}
public String internalGet(String id) {
if (this.lang.containsKey(id)) {
return this.lang.get(id);
} else if (this.fallbackLang.containsKey(id)) {
return this.fallbackLang.get(id);
}
return null;
}
public String get(String id) {
if (this.lang.containsKey(id)) {
return this.lang.get(id);
} else if (this.fallbackLang.containsKey(id)) {
return this.fallbackLang.get(id);
}
return id;
}
protected String parseTranslation(String text) {
return this.parseTranslation(text, null);
}
protected String parseTranslation(String text, String onlyPrefix) {
String newString = "";
text = String.valueOf(text);
String replaceString = null;
int len = text.length();
for (int i = 0; i < len; ++i) {
char c = text.charAt(i);
if (replaceString != null) {
int ord = c;
if ((ord >= 0x30 && ord <= 0x39) // 0-9
|| (ord >= 0x41 && ord <= 0x5a) // A-Z
|| (ord >= 0x61 && ord <= 0x7a) || // a-z
c == '.' || c == '-') {
replaceString += String.valueOf(c);
} else {
String t = this.internalGet(replaceString.substring(1));
if (t != null && (onlyPrefix == null || replaceString.indexOf(onlyPrefix) == 1)) {
newString += t;
} else {
newString += replaceString;
}
replaceString = null;
if (c == '%') {
replaceString = String.valueOf(c);
} else {
newString += String.valueOf(c);
}
}
} else if (c == '%') {
replaceString = String.valueOf(c);
} else {
newString += String.valueOf(c);
}
}
if (replaceString != null) {
String t = this.internalGet(replaceString.substring(1));
if (t != null && (onlyPrefix == null || replaceString.indexOf(onlyPrefix) == 1)) {
newString += t;
} else {
newString += replaceString;
}
}
return newString;
}
}
| 7,684 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockNoteblock.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockNoteblock.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.level.Sound;
import cn.nukkit.network.protocol.BlockEventPacket;
/**
* Created by Snake1999 on 2016/1/17.
* Package cn.nukkit.block in project nukkit.
*/
public class BlockNoteblock extends BlockSolidMeta {
public BlockNoteblock() {
this(0);
}
public BlockNoteblock(int meta) {
super(meta);
}
@Override
public String getName() {
return "Note Block";
}
@Override
public int getId() {
return NOTEBLOCK;
}
@Override
public int getToolType() {
return ItemTool.TYPE_AXE;
}
@Override
public double getHardness() {
return 0.8D;
}
@Override
public double getResistance() {
return 4D;
}
public boolean canBeActivated() {
return true;
}
public int getStrength() {
return this.getDamage();
}
public void increaseStrength() {
if (this.getDamage() < 24) {
this.setDamage(this.getDamage() + 1);
} else {
this.setDamage(0);
}
}
public Instrument getInstrument() {
Block below = this.down();
switch (below.getId()) {
case WOODEN_PLANK:
case NOTEBLOCK:
case CRAFTING_TABLE:
return Instrument.BASS;
case SAND:
case SANDSTONE:
case SOUL_SAND:
return Instrument.DRUM;
case GLASS:
case GLASS_PANEL:
case GLOWSTONE_BLOCK:
return Instrument.STICKS;
case COAL_ORE:
case DIAMOND_ORE:
case EMERALD_ORE:
case GLOWING_REDSTONE_ORE:
case GOLD_ORE:
case IRON_ORE:
case LAPIS_ORE:
case REDSTONE_ORE:
return Instrument.BASS_DRUM;
default:
return Instrument.PIANO;
}
}
public void emitSound() {
Instrument instrument = getInstrument();
BlockEventPacket pk = new BlockEventPacket();
pk.x = (int) this.x;
pk.y = (int) this.y;
pk.z = (int) this.z;
pk.case1 = instrument.ordinal();
pk.case2 = this.getStrength();
this.getLevel().addChunkPacket((int) this.x >> 4, (int) this.z >> 4, pk);
this.getLevel().addSound(this, instrument.getSound(), 1, this.getStrength()); //TODO: correct pitch
}
public boolean onActivate(Item item) {
return this.onActivate(item, null);
}
public boolean onActivate(Item item, Player player) {
Block up = this.up();
if (up.getId() == Block.AIR) {
this.increaseStrength();
this.emitSound();
return true;
} else {
return false;
}
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) {
//TODO: redstone
}
return 0;
}
public enum Instrument {
PIANO(Sound.NOTE_HARP),
BASS_DRUM(Sound.NOTE_BD),
STICKS(Sound.NOTE_HAT),
DRUM(Sound.NOTE_SNARE),
BASS(Sound.NOTE_BASS);
private final Sound sound;
Instrument(Sound sound) {
this.sound = sound;
}
public Sound getSound() {
return sound;
}
}
}
| 3,515 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTerracottaGlazedGreen.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTerracottaGlazedGreen.java | package cn.nukkit.block;
/**
* Created by CreeperFace on 2.6.2017.
*/
public class BlockTerracottaGlazedGreen extends BlockTerracottaGlazed {
public BlockTerracottaGlazedGreen() {
this(0);
}
public BlockTerracottaGlazedGreen(int meta) {
super(meta);
}
@Override
public int getId() {
return GREEN_GLAZED_TERRACOTTA;
}
@Override
public String getName() {
return "Green Glazed Terracotta";
}
}
| 470 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockFarmland.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockFarmland.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.math.Vector3;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/12/2 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockFarmland extends BlockTransparentMeta {
public BlockFarmland() {
this(0);
}
public BlockFarmland(int meta) {
super(meta);
}
@Override
public String getName() {
return "Farmland";
}
@Override
public int getId() {
return FARMLAND;
}
@Override
public double getResistance() {
return 3;
}
@Override
public double getHardness() {
return 0.6;
}
@Override
public int getToolType() {
return ItemTool.TYPE_SHOVEL;
}
@Override
public double getMaxY() {
return this.y + 0.9375;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_RANDOM) {
Vector3 v = new Vector3();
if (this.level.getBlock(v.setComponents(x, this.y + 1, z)) instanceof BlockCrops) {
return 0;
}
if (this.level.getBlock(v.setComponents(x, this.y + 1, z)).isSolid()) {
this.level.setBlock(this, new BlockDirt(), false, true);
return Level.BLOCK_UPDATE_RANDOM;
}
boolean found = false;
if (this.level.isRaining()) {
found = true;
} else {
for (int x = (int) this.x - 4; x <= this.x + 4; x++) {
for (int z = (int) this.z - 4; z <= this.z + 4; z++) {
for (int y = (int) this.y; y <= this.y + 1; y++) {
if (z == this.z && x == this.x && y == this.y) {
continue;
}
v.setComponents(x, y, z);
int block = this.level.getBlockIdAt(v.getFloorX(), v.getFloorY(), v.getFloorZ());
if (block == WATER || block == STILL_WATER) {
found = true;
break;
}
}
}
}
}
Block block = this.level.getBlock(v.setComponents(x, y - 1, z));
if (found || block instanceof BlockWater) {
if (this.getDamage() < 7) {
this.setDamage(7);
this.level.setBlock(this, this, false, false);
}
return Level.BLOCK_UPDATE_RANDOM;
}
if (this.getDamage() > 0) {
this.setDamage(this.getDamage() - 1);
this.level.setBlock(this, this, false, false);
} else {
this.level.setBlock(this, Block.get(Block.DIRT), false, true);
}
return Level.BLOCK_UPDATE_RANDOM;
}
return 0;
}
@Override
public Item[] getDrops(Item item) {
return new Item[]{
new ItemBlock(new BlockDirt())
};
}
@Override
public BlockColor getColor() {
return BlockColor.DIRT_BLOCK_COLOR;
}
}
| 3,354 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockMeta.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockMeta.java | package cn.nukkit.block;
public abstract class BlockMeta extends Block {
private int meta;
protected BlockMeta(int meta) {
this.meta = meta;
}
@Override
public int getFullId() {
return (getId() << 4) + getDamage();
}
@Override
public final int getDamage() {
return this.meta;
}
@Override
public void setDamage(int meta) {
this.meta = meta;
}
} | 429 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockSnowLayer.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockSnowLayer.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemSnowball;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/12/6 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockSnowLayer extends BlockFlowable {
public BlockSnowLayer() {
this(0);
}
public BlockSnowLayer(int meta) {
super(meta);
}
@Override
public String getName() {
return "Snow Layer";
}
@Override
public int getId() {
return SNOW_LAYER;
}
@Override
public double getHardness() {
return 0.1;
}
@Override
public double getResistance() {
return 0.5;
}
@Override
public int getToolType() {
return ItemTool.TYPE_SHOVEL;
}
@Override
public boolean canBeReplaced() {
return true;
}
//TODO:雪片叠垒乐
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
Block down = this.down();
if (down.isSolid()) {
this.getLevel().setBlock(block, this, true);
return true;
}
return false;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (this.down().isTransparent()) {
this.getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
} else if (type == Level.BLOCK_UPDATE_RANDOM) {
if (this.getLevel().getBlockLightAt((int) this.x, (int) this.y, (int) this.z) >= 10) {
this.getLevel().setBlock(this, new BlockAir(), true);
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
@Override
public Item[] getDrops(Item item) {
if (item.isShovel() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
new ItemSnowball()
};
} else {
return new Item[0];
}
}
@Override
public BlockColor getColor() {
return BlockColor.SNOW_BLOCK_COLOR;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 2,389 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTerracottaGlazedLightBlue.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTerracottaGlazedLightBlue.java | package cn.nukkit.block;
/**
* Created by CreeperFace on 2.6.2017.
*/
public class BlockTerracottaGlazedLightBlue extends BlockTerracottaGlazed {
public BlockTerracottaGlazedLightBlue() {
this(0);
}
public BlockTerracottaGlazedLightBlue(int meta) {
super(meta);
}
@Override
public int getId() {
return LIGHT_BLUE_GLAZED_TERRACOTTA;
}
@Override
public String getName() {
return "Light Blue Glazed Terracotta";
}
}
| 492 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockSolid.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockSolid.java | package cn.nukkit.block;
import cn.nukkit.utils.BlockColor;
/**
* author: MagicDroidX
* Nukkit Project
*/
public abstract class BlockSolid extends Block {
protected BlockSolid() {
}
@Override
public boolean isSolid() {
return true;
}
@Override
public BlockColor getColor() {
return BlockColor.STONE_BLOCK_COLOR;
}
}
| 372 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTerracottaStained.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTerracottaStained.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
import cn.nukkit.utils.DyeColor;
/**
* Created on 2015/12/2 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockTerracottaStained extends BlockSolidMeta {
public BlockTerracottaStained() {
this(0);
}
public BlockTerracottaStained(int meta) {
super(meta);
}
public BlockTerracottaStained(DyeColor dyeColor) {
this(dyeColor.getWoolData());
}
@Override
public String getName() {
return getDyeColor().getName() + " Terracotta";
}
@Override
public int getId() {
return STAINED_TERRACOTTA;
}
@Override
public double getHardness() {
return 1.25;
}
@Override
public double getResistance() {
return 0.75;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{toItem()};
} else {
return new Item[0];
}
}
@Override
public BlockColor getColor() {
return DyeColor.getByWoolData(getDamage()).getColor();
}
public DyeColor getDyeColor() {
return DyeColor.getByWoolData(getDamage());
}
}
| 1,425 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTerracottaGlazed.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTerracottaGlazed.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.math.BlockFace;
/**
* Created by CreeperFace on 2.6.2017.
*/
public abstract class BlockTerracottaGlazed extends BlockSolidMeta {
public BlockTerracottaGlazed() {
this(0);
}
public BlockTerracottaGlazed(int meta) {
super(meta);
}
@Override
public double getResistance() {
return 7;
}
@Override
public double getHardness() {
return 1.4;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public Item[] getDrops(Item item) {
return item.getTier() >= ItemTool.TIER_WOODEN ? new Item[]{this.toItem()} : new Item[0];
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
int faces[] = {2, 5, 3, 4};
this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
return this.getLevel().setBlock(block, this, true, true);
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,228 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTallGrass.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTallGrass.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemSeedsWheat;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
import java.util.Random;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockTallGrass extends BlockFlowable {
public BlockTallGrass() {
this(1);
}
public BlockTallGrass(int meta) {
super(meta);
}
@Override
public int getId() {
return TALL_GRASS;
}
@Override
public String getName() {
String[] names = new String[]{
"Dead Shrub",
"Tall Grass",
"Fern",
""
};
return names[this.getDamage() & 0x03];
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public boolean canBeReplaced() {
return true;
}
@Override
public int getBurnChance() {
return 60;
}
@Override
public int getBurnAbility() {
return 100;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
Block down = this.down();
if (down.getId() == Block.GRASS || down.getId() == Block.DIRT || down.getId() == Block.PODZOL) {
this.getLevel().setBlock(block, this, true);
return true;
}
return false;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (this.down().isTransparent()) {
this.getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
@Override
public boolean onActivate(Item item) {
return this.onActivate(item, null);
}
@Override
public boolean onActivate(Item item, Player player) {
//todo bonemeal
return false;
}
@Override
public Item[] getDrops(Item item) {
boolean dropSeeds = new Random().nextInt(10) == 0;
if (item.isShears()) {
//todo enchantment
if (dropSeeds) {
return new Item[]{
new ItemSeedsWheat(),
Item.get(Item.TALL_GRASS, this.getDamage(), 1)
};
} else {
return new Item[]{
Item.get(Item.TALL_GRASS, this.getDamage(), 1)
};
}
}
if (dropSeeds) {
return new Item[]{
new ItemSeedsWheat()
};
} else {
return new Item[0];
}
}
@Override
public int getToolType() {
return ItemTool.TYPE_SHEARS;
}
@Override
public BlockColor getColor() {
return BlockColor.FOLIAGE_BLOCK_COLOR;
}
}
| 2,974 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockPrismarine.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockPrismarine.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
public class BlockPrismarine extends BlockSolidMeta {
public static final int NORMAL = 0;
public static final int BRICKS = 1;
public static final int DARK = 2;
public BlockPrismarine() {
this(0);
}
public BlockPrismarine(int meta) {
super(meta);
}
@Override
public int getId() {
return PRISMARINE;
}
@Override
public double getHardness() {
return 1.5;
}
@Override
public double getResistance() {
return 30;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public String getName() {
String[] names = new String[]{
"Prismarine",
"Prismarine bricks",
"Dark prismarine"
};
return names[this.getDamage() & 0x07];
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,303 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockThin.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockThin.java | package cn.nukkit.block;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.SimpleAxisAlignedBB;
import cn.nukkit.utils.LevelException;
/**
* Created on 2015/12/6 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public abstract class BlockThin extends BlockTransparent {
protected BlockThin() {
}
@Override
public boolean isSolid() {
return false;
}
protected AxisAlignedBB recalculateBoundingBox() {
double f = 0.4375;
double f1 = 0.5625;
double f2 = 0.4375;
double f3 = 0.5625;
try {
boolean flag = this.canConnect(this.north());
boolean flag1 = this.canConnect(this.south());
boolean flag2 = this.canConnect(this.west());
boolean flag3 = this.canConnect(this.east());
if ((!flag2 || !flag3) && (flag2 || flag3 || flag || flag1)) {
if (flag2) {
f = 0;
} else if (flag3) {
f1 = 1;
}
} else {
f = 0;
f1 = 1;
}
if ((!flag || !flag1) && (flag2 || flag3 || flag || flag1)) {
if (flag) {
f2 = 0;
} else if (flag1) {
f3 = 1;
}
} else {
f2 = 0;
f3 = 1;
}
} catch (LevelException ignore) {
//null sucks
}
return new SimpleAxisAlignedBB(
this.x + f,
this.y,
this.z + f2,
this.x + f1,
this.y + 1,
this.z + f3
);
}
public boolean canConnect(Block block) {
return block.isSolid() || block.getId() == this.getId() || block.getId() == GLASS_PANE || block.getId() == GLASS;
}
}
| 1,884 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockFire.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockFire.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.entity.Entity;
import cn.nukkit.entity.projectile.EntityArrow;
import cn.nukkit.event.block.BlockBurnEvent;
import cn.nukkit.event.block.BlockIgniteEvent;
import cn.nukkit.event.entity.EntityCombustByBlockEvent;
import cn.nukkit.event.entity.EntityDamageByBlockEvent;
import cn.nukkit.event.entity.EntityDamageEvent.DamageCause;
import cn.nukkit.item.Item;
import cn.nukkit.level.GameRule;
import cn.nukkit.level.Level;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.Vector3;
import cn.nukkit.potion.Effect;
import cn.nukkit.utils.BlockColor;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockFire extends BlockFlowable {
public BlockFire() {
this(0);
}
public BlockFire(int meta) {
super(meta);
}
@Override
public int getId() {
return FIRE;
}
@Override
public boolean hasEntityCollision() {
return true;
}
@Override
public String getName() {
return "Fire Block";
}
@Override
public int getLightLevel() {
return 15;
}
@Override
public boolean isBreakable(Item item) {
return false;
}
@Override
public boolean canBeReplaced() {
return true;
}
@Override
public void onEntityCollide(Entity entity) {
if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) {
entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.FIRE, 1));
}
EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 8);
if (entity instanceof EntityArrow) {
ev.setCancelled();
}
Server.getInstance().getPluginManager().callEvent(ev);
if (!ev.isCancelled() && entity instanceof Player && !((Player) entity).isCreative()) {
entity.setOnFire(ev.getDuration());
}
}
@Override
public Item[] getDrops(Item item) {
return new Item[0];
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_RANDOM) {
if (!this.isBlockTopFacingSurfaceSolid(this.down()) && !this.canNeighborBurn()) {
this.getLevel().setBlock(this, new BlockAir(), true);
}
return Level.BLOCK_UPDATE_NORMAL;
} else if (type == Level.BLOCK_UPDATE_SCHEDULED && this.level.gameRules.getBoolean(GameRule.DO_FIRE_TICK)) {
boolean forever = this.down().getId() == Block.NETHERRACK;
ThreadLocalRandom random = ThreadLocalRandom.current();
//TODO: END
if (!this.isBlockTopFacingSurfaceSolid(this.down()) && !this.canNeighborBurn()) {
this.getLevel().setBlock(this, new BlockAir(), true);
}
if (!forever && this.getLevel().isRaining() &&
(this.getLevel().canBlockSeeSky(this) ||
this.getLevel().canBlockSeeSky(this.east()) ||
this.getLevel().canBlockSeeSky(this.west()) ||
this.getLevel().canBlockSeeSky(this.south()) ||
this.getLevel().canBlockSeeSky(this.north()))
) {
this.getLevel().setBlock(this, new BlockAir(), true);
} else {
int meta = this.getDamage();
if (meta < 15) {
this.setDamage(meta + random.nextInt(3));
this.getLevel().setBlock(this, this, true);
}
this.getLevel().scheduleUpdate(this, this.tickRate() + random.nextInt(10));
if (!forever && !this.canNeighborBurn()) {
if (!this.isBlockTopFacingSurfaceSolid(this.down()) || meta > 3) {
this.getLevel().setBlock(this, new BlockAir(), true);
}
} else if (!forever && !(this.down().getBurnAbility() > 0) && meta == 15 && random.nextInt(4) == 0) {
this.getLevel().setBlock(this, new BlockAir(), true);
} else {
int o = 0;
//TODO: decrease the o if the rainfall values are high
this.tryToCatchBlockOnFire(this.east(), 300 + o, meta);
this.tryToCatchBlockOnFire(this.west(), 300 + o, meta);
this.tryToCatchBlockOnFire(this.down(), 250 + o, meta);
this.tryToCatchBlockOnFire(this.up(), 250 + o, meta);
this.tryToCatchBlockOnFire(this.south(), 300 + o, meta);
this.tryToCatchBlockOnFire(this.north(), 300 + o, meta);
for (int x = (int) (this.x - 1); x <= (int) (this.x + 1); ++x) {
for (int z = (int) (this.z - 1); z <= (int) (this.z + 1); ++z) {
for (int y = (int) (this.y - 1); y <= (int) (this.y + 4); ++y) {
if (x != (int) this.x || y != (int) this.y || z != (int) this.z) {
int k = 100;
if (y > this.y + 1) {
k += (y - (this.y + 1)) * 100;
}
Block block = this.getLevel().getBlock(new Vector3(x, y, z));
int chance = this.getChanceOfNeighborsEncouragingFire(block);
if (chance > 0) {
int t = (chance + 40 + this.getLevel().getServer().getDifficulty() * 7) / (meta + 30);
//TODO: decrease the t if the rainfall values are high
if (t > 0 && random.nextInt(k) <= t) {
int damage = meta + random.nextInt(5) / 4;
if (damage > 15) {
damage = 15;
}
BlockIgniteEvent e = new BlockIgniteEvent(block, this, null, BlockIgniteEvent.BlockIgniteCause.SPREAD);
this.level.getServer().getPluginManager().callEvent(e);
if (!e.isCancelled()) {
this.getLevel().setBlock(block, new BlockFire(damage), true);
this.getLevel().scheduleUpdate(block, this.tickRate());
}
}
}
}
}
}
}
}
}
}
return 0;
}
private void tryToCatchBlockOnFire(Block block, int bound, int damage) {
int burnAbility = block.getBurnAbility();
Random random = ThreadLocalRandom.current();
if (random.nextInt(bound) < burnAbility) {
if (random.nextInt(damage + 10) < 5) {
int meta = damage + random.nextInt(5) / 4;
if (meta > 15) {
meta = 15;
}
BlockIgniteEvent e = new BlockIgniteEvent(block, this, null, BlockIgniteEvent.BlockIgniteCause.SPREAD);
this.level.getServer().getPluginManager().callEvent(e);
if (!e.isCancelled()) {
this.getLevel().setBlock(block, new BlockFire(meta), true);
this.getLevel().scheduleUpdate(block, this.tickRate());
}
} else {
BlockBurnEvent ev = new BlockBurnEvent(block);
this.getLevel().getServer().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
this.getLevel().setBlock(block, new BlockAir(), true);
}
}
if (block instanceof BlockTNT) {
((BlockTNT) block).prime();
}
}
}
private int getChanceOfNeighborsEncouragingFire(Block block) {
if (block.getId() != AIR) {
return 0;
} else {
int chance = 0;
chance = Math.max(chance, block.east().getBurnChance());
chance = Math.max(chance, block.west().getBurnChance());
chance = Math.max(chance, block.down().getBurnChance());
chance = Math.max(chance, block.up().getBurnChance());
chance = Math.max(chance, block.south().getBurnChance());
chance = Math.max(chance, block.north().getBurnChance());
return chance;
}
}
public boolean canNeighborBurn() {
for (BlockFace face : BlockFace.values()) {
if (this.getSide(face).getBurnChance() > 0) {
return true;
}
}
return false;
}
public boolean isBlockTopFacingSurfaceSolid(Block block) {
if (block != null) {
if (block.isSolid()) {
return true;
} else {
if (block instanceof BlockStairs &&
(block.getDamage() & 4) == 4) {
return true;
} else if (block instanceof BlockSlab &&
(block.getDamage() & 8) == 8) {
return true;
} else if (block instanceof BlockSnowLayer &&
(block.getDamage() & 7) == 7) {
return true;
}
}
}
return false;
}
@Override
public int tickRate() {
return 30;
}
@Override
public BlockColor getColor() {
return BlockColor.AIR_BLOCK_COLOR;
}
@Override
protected AxisAlignedBB recalculateCollisionBoundingBox() {
return this;
}
}
| 10,169 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockSoulSand.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockSoulSand.java | package cn.nukkit.block;
import cn.nukkit.entity.Entity;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* Created by Pub4Game on 27.12.2015.
*/
public class BlockSoulSand extends BlockSolid {
public BlockSoulSand() {
}
@Override
public String getName() {
return "Soul Sand";
}
@Override
public int getId() {
return SOUL_SAND;
}
@Override
public double getHardness() {
return 0.5;
}
@Override
public double getResistance() {
return 2.5;
}
@Override
public int getToolType() {
return ItemTool.TYPE_SHOVEL;
}
@Override
public double getMaxY() {
return this.y + 1 - 0.125;
}
@Override
public boolean hasEntityCollision() {
return true;
}
@Override
public void onEntityCollide(Entity entity) {
entity.motionX *= 0.4d;
entity.motionZ *= 0.4d;
}
@Override
public BlockColor getColor() {
return BlockColor.SAND_BLOCK_COLOR;
}
}
| 1,055 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockStairsBirch.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockStairsBirch.java | package cn.nukkit.block;
/**
* Created on 2015/11/25 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockStairsBirch extends BlockStairsWood {
public BlockStairsBirch() {
this(0);
}
public BlockStairsBirch(int meta) {
super(meta);
}
@Override
public int getId() {
return BIRCH_WOOD_STAIRS;
}
@Override
public String getName() {
return "Birch Wood Stairs";
}
}
| 466 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockBricksStone.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockBricksStone.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockBricksStone extends BlockSolid {
public static final int NORMAL = 0;
public static final int MOSSY = 1;
public static final int CRACKED = 2;
public static final int CHISELED = 3;
public BlockBricksStone() {
}
@Override
public int getId() {
return STONE_BRICKS;
}
@Override
public double getHardness() {
return 1.5;
}
@Override
public double getResistance() {
return 30;
}
@Override
public String getName() {
String[] names = new String[]{
"Stone Bricks",
"Mossy Stone Bricks",
"Cracked Stone Bricks",
"Chiseled Stone Bricks"
};
return names[this.getDamage() & 0x03];
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
Item.get(Item.STONE_BRICKS, this.getDamage() & 0x03, 1)
};
} else {
return new Item[0];
}
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,407 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockPodzol.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockPodzol.java | package cn.nukkit.block;
/**
* Created on 2015/11/22 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockPodzol extends BlockDirt {
public BlockPodzol() {
}
@Override
public int getId() {
return PODZOL;
}
@Override
public String getName() {
return "Podzol";
}
}
| 343 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockWood2.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockWood2.java | package cn.nukkit.block;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockWood2 extends BlockWood {
public static final int ACACIA = 0;
public static final int DARK_OAK = 1;
public BlockWood2() {
this(0);
}
public BlockWood2(int meta) {
super(meta);
}
@Override
public int getId() {
return WOOD2;
}
@Override
public String getName() {
String[] names = new String[]{
"Acacia Wood",
"Dark Oak Wood",
""
};
return names[this.getDamage() & 0x03];
}
}
| 617 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockStairsRedSandstone.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockStairsRedSandstone.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
/**
* Created by CreeperFace on 26. 11. 2016.
*/
public class BlockStairsRedSandstone extends BlockStairs {
public BlockStairsRedSandstone() {
this(0);
}
public BlockStairsRedSandstone(int meta) {
super(meta);
}
@Override
public int getId() {
return RED_SANDSTONE_STAIRS;
}
@Override
public double getHardness() {
return 0.8;
}
@Override
public double getResistance() {
return 4;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public String getName() {
return "Red Sandstone Stairs";
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public Item toItem() {
return new ItemBlock(this, this.getDamage() & 0x07);
}
@Override
public boolean canHarvestWithHand() {
return false;
}
} | 1,245 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockDaylightDetectorInverted.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockDaylightDetectorInverted.java | package cn.nukkit.block;
/**
* Created on 2015/11/22 by CreeperFace.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockDaylightDetectorInverted extends BlockDaylightDetector {
public BlockDaylightDetectorInverted() {
}
@Override
public int getId() {
return DAYLIGHT_DETECTOR_INVERTED;
}
@Override
public String getName() {
return "Daylight Detector Inverted";
}
protected boolean invertDetect() {
return true;
}
}
| 504 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockFurnace.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockFurnace.java | package cn.nukkit.block;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockFurnace extends BlockFurnaceBurning {
public BlockFurnace() {
this(0);
}
public BlockFurnace(int meta) {
super(meta);
}
@Override
public String getName() {
return "Furnace";
}
@Override
public int getId() {
return FURNACE;
}
@Override
public int getLightLevel() {
return 0;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
} | 550 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockDragonEgg.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockDragonEgg.java | package cn.nukkit.block;
import cn.nukkit.utils.BlockColor;
public class BlockDragonEgg extends BlockTransparent {
public BlockDragonEgg() {
}
@Override
public String getName() {
return "Dragon Egg";
}
@Override
public int getId() {
return DRAGON_EGG;
}
@Override
public double getHardness() {
return 3;
}
@Override
public double getResistance() {
return 45;
}
@Override
public int getLightLevel() {
return 1;
}
@Override
public BlockColor getColor() {
return BlockColor.OBSIDIAN_BLOCK_COLOR;
}
} | 633 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
Block.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/Block.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.entity.Entity;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.level.Level;
import cn.nukkit.level.MovingObjectPosition;
import cn.nukkit.level.Position;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.Vector3;
import cn.nukkit.metadata.MetadataValue;
import cn.nukkit.metadata.Metadatable;
import cn.nukkit.plugin.Plugin;
import cn.nukkit.potion.Effect;
import cn.nukkit.utils.BlockColor;
import java.lang.reflect.Constructor;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* author: MagicDroidX
* Nukkit Project
*/
public abstract class Block extends Position implements Metadatable, Cloneable, AxisAlignedBB {
public static final int AIR = 0;
public static final int STONE = 1;
public static final int GRASS = 2;
public static final int DIRT = 3;
public static final int COBBLESTONE = 4;
public static final int COBBLE = 4;
public static final int PLANK = 5;
public static final int PLANKS = 5;
public static final int WOODEN_PLANK = 5;
public static final int WOODEN_PLANKS = 5;
public static final int SAPLING = 6;
public static final int SAPLINGS = 6;
public static final int BEDROCK = 7;
public static final int WATER = 8;
public static final int STILL_WATER = 9;
public static final int LAVA = 10;
public static final int STILL_LAVA = 11;
public static final int SAND = 12;
public static final int GRAVEL = 13;
public static final int GOLD_ORE = 14;
public static final int IRON_ORE = 15;
public static final int COAL_ORE = 16;
public static final int LOG = 17;
public static final int WOOD = 17;
public static final int TRUNK = 17;
public static final int LEAVES = 18;
public static final int LEAVE = 18;
public static final int SPONGE = 19;
public static final int GLASS = 20;
public static final int LAPIS_ORE = 21;
public static final int LAPIS_BLOCK = 22;
public static final int DISPENSER = 23;
public static final int SANDSTONE = 24;
public static final int NOTEBLOCK = 25;
public static final int BED_BLOCK = 26;
public static final int POWERED_RAIL = 27;
public static final int DETECTOR_RAIL = 28;
public static final int STICKY_PISTON = 29;
public static final int COBWEB = 30;
public static final int TALL_GRASS = 31;
public static final int BUSH = 32;
public static final int DEAD_BUSH = 32;
public static final int PISTON = 33;
public static final int PISTON_HEAD = 34;
public static final int WOOL = 35;
public static final int DANDELION = 37;
public static final int POPPY = 38;
public static final int ROSE = 38;
public static final int FLOWER = 38;
public static final int RED_FLOWER = 38;
public static final int BROWN_MUSHROOM = 39;
public static final int RED_MUSHROOM = 40;
public static final int GOLD_BLOCK = 41;
public static final int IRON_BLOCK = 42;
public static final int DOUBLE_SLAB = 43;
public static final int DOUBLE_STONE_SLAB = 43;
public static final int DOUBLE_SLABS = 43;
public static final int SLAB = 44;
public static final int STONE_SLAB = 44;
public static final int SLABS = 44;
public static final int BRICKS = 45;
public static final int BRICKS_BLOCK = 45;
public static final int TNT = 46;
public static final int BOOKSHELF = 47;
public static final int MOSS_STONE = 48;
public static final int MOSSY_STONE = 48;
public static final int OBSIDIAN = 49;
public static final int TORCH = 50;
public static final int FIRE = 51;
public static final int MONSTER_SPAWNER = 52;
public static final int WOOD_STAIRS = 53;
public static final int WOODEN_STAIRS = 53;
public static final int OAK_WOOD_STAIRS = 53;
public static final int OAK_WOODEN_STAIRS = 53;
public static final int CHEST = 54;
public static final int REDSTONE_WIRE = 55;
public static final int DIAMOND_ORE = 56;
public static final int DIAMOND_BLOCK = 57;
public static final int CRAFTING_TABLE = 58;
public static final int WORKBENCH = 58;
public static final int WHEAT_BLOCK = 59;
public static final int FARMLAND = 60;
public static final int FURNACE = 61;
public static final int BURNING_FURNACE = 62;
public static final int LIT_FURNACE = 62;
public static final int SIGN_POST = 63;
public static final int DOOR_BLOCK = 64;
public static final int WOODEN_DOOR_BLOCK = 64;
public static final int WOOD_DOOR_BLOCK = 64;
public static final int LADDER = 65;
public static final int RAIL = 66;
public static final int COBBLE_STAIRS = 67;
public static final int COBBLESTONE_STAIRS = 67;
public static final int WALL_SIGN = 68;
public static final int LEVER = 69;
public static final int STONE_PRESSURE_PLATE = 70;
public static final int IRON_DOOR_BLOCK = 71;
public static final int WOODEN_PRESSURE_PLATE = 72;
public static final int REDSTONE_ORE = 73;
public static final int GLOWING_REDSTONE_ORE = 74;
public static final int LIT_REDSTONE_ORE = 74;
public static final int UNLIT_REDSTONE_TORCH = 75;
public static final int REDSTONE_TORCH = 76;
public static final int STONE_BUTTON = 77;
public static final int SNOW = 78;
public static final int SNOW_LAYER = 78;
public static final int ICE = 79;
public static final int SNOW_BLOCK = 80;
public static final int CACTUS = 81;
public static final int CLAY_BLOCK = 82;
public static final int REEDS = 83;
public static final int SUGARCANE_BLOCK = 83;
public static final int JUKEBOX = 84;
public static final int FENCE = 85;
public static final int PUMPKIN = 86;
public static final int NETHERRACK = 87;
public static final int SOUL_SAND = 88;
public static final int GLOWSTONE = 89;
public static final int GLOWSTONE_BLOCK = 89;
public static final int NETHER_PORTAL = 90;
public static final int LIT_PUMPKIN = 91;
public static final int JACK_O_LANTERN = 91;
public static final int CAKE_BLOCK = 92;
public static final int UNPOWERED_REPEATER = 93;
public static final int POWERED_REPEATER = 94;
public static final int INVISIBLE_BEDROCK = 95;
public static final int TRAPDOOR = 96;
public static final int MONSTER_EGG = 97;
public static final int STONE_BRICKS = 98;
public static final int STONE_BRICK = 98;
public static final int BROWN_MUSHROOM_BLOCK = 99;
public static final int RED_MUSHROOM_BLOCK = 100;
public static final int IRON_BAR = 101;
public static final int IRON_BARS = 101;
public static final int GLASS_PANE = 102;
public static final int GLASS_PANEL = 102;
public static final int MELON_BLOCK = 103;
public static final int PUMPKIN_STEM = 104;
public static final int MELON_STEM = 105;
public static final int VINE = 106;
public static final int VINES = 106;
public static final int FENCE_GATE = 107;
public static final int FENCE_GATE_OAK = 107;
public static final int BRICK_STAIRS = 108;
public static final int STONE_BRICK_STAIRS = 109;
public static final int MYCELIUM = 110;
public static final int WATER_LILY = 111;
public static final int LILY_PAD = 111;
public static final int NETHER_BRICKS = 112;
public static final int NETHER_BRICK_BLOCK = 112;
public static final int NETHER_BRICK_FENCE = 113;
public static final int NETHER_BRICKS_STAIRS = 114;
public static final int NETHER_WART_BLOCK = 115;
public static final int ENCHANTING_TABLE = 116;
public static final int ENCHANT_TABLE = 116;
public static final int ENCHANTMENT_TABLE = 116;
public static final int BREWING_STAND_BLOCK = 117;
public static final int BREWING_BLOCK = 117;
public static final int CAULDRON_BLOCK = 118;
public static final int END_PORTAL = 119;
public static final int END_PORTAL_FRAME = 120;
public static final int END_STONE = 121;
public static final int DRAGON_EGG = 122;
public static final int REDSTONE_LAMP = 123;
public static final int LIT_REDSTONE_LAMP = 124;
//Note: dropper CAN NOT BE HARVESTED WITH HAND -- canHarvestWithHand method should be overridden FALSE.
public static final int DROPPER = 125;
public static final int ACTIVATOR_RAIL = 126;
public static final int COCOA = 127;
public static final int COCOA_BLOCK = 127;
public static final int SANDSTONE_STAIRS = 128;
public static final int EMERALD_ORE = 129;
public static final int ENDER_CHEST = 130;
public static final int TRIPWIRE_HOOK = 131;
public static final int TRIPWIRE = 132;
public static final int EMERALD_BLOCK = 133;
public static final int SPRUCE_WOOD_STAIRS = 134;
public static final int SPRUCE_WOODEN_STAIRS = 134;
public static final int BIRCH_WOOD_STAIRS = 135;
public static final int BIRCH_WOODEN_STAIRS = 135;
public static final int JUNGLE_WOOD_STAIRS = 136;
public static final int JUNGLE_WOODEN_STAIRS = 136;
public static final int BEACON = 138;
public static final int COBBLE_WALL = 139;
public static final int STONE_WALL = 139;
public static final int COBBLESTONE_WALL = 139;
public static final int FLOWER_POT_BLOCK = 140;
public static final int CARROT_BLOCK = 141;
public static final int POTATO_BLOCK = 142;
public static final int WOODEN_BUTTON = 143;
public static final int SKULL_BLOCK = 144;
public static final int ANVIL = 145;
public static final int TRAPPED_CHEST = 146;
public static final int LIGHT_WEIGHTED_PRESSURE_PLATE = 147;
public static final int HEAVY_WEIGHTED_PRESSURE_PLATE = 148;
public static final int UNPOWERED_COMPARATOR = 149;
public static final int POWERED_COMPARATOR = 150;
public static final int DAYLIGHT_DETECTOR = 151;
public static final int REDSTONE_BLOCK = 152;
public static final int QUARTZ_ORE = 153;
public static final int HOPPER_BLOCK = 154;
public static final int QUARTZ_BLOCK = 155;
public static final int QUARTZ_STAIRS = 156;
public static final int DOUBLE_WOOD_SLAB = 157;
public static final int DOUBLE_WOODEN_SLAB = 157;
public static final int DOUBLE_WOOD_SLABS = 157;
public static final int DOUBLE_WOODEN_SLABS = 157;
public static final int WOOD_SLAB = 158;
public static final int WOODEN_SLAB = 158;
public static final int WOOD_SLABS = 158;
public static final int WOODEN_SLABS = 158;
public static final int STAINED_TERRACOTTA = 159;
public static final int STAINED_HARDENED_CLAY = 159;
public static final int STAINED_GLASS_PANE = 160;
public static final int LEAVES2 = 161;
public static final int LEAVE2 = 161;
public static final int WOOD2 = 162;
public static final int TRUNK2 = 162;
public static final int LOG2 = 162;
public static final int ACACIA_WOOD_STAIRS = 163;
public static final int ACACIA_WOODEN_STAIRS = 163;
public static final int DARK_OAK_WOOD_STAIRS = 164;
public static final int DARK_OAK_WOODEN_STAIRS = 164;
public static final int SLIME_BLOCK = 165;
public static final int IRON_TRAPDOOR = 167;
public static final int PRISMARINE = 168;
public static final int SEA_LANTERN = 169;
public static final int HAY_BALE = 170;
public static final int CARPET = 171;
public static final int TERRACOTTA = 172;
public static final int COAL_BLOCK = 173;
public static final int PACKED_ICE = 174;
public static final int DOUBLE_PLANT = 175;
public static final int DAYLIGHT_DETECTOR_INVERTED = 178;
public static final int RED_SANDSTONE = 179;
public static final int RED_SANDSTONE_STAIRS = 180;
public static final int DOUBLE_RED_SANDSTONE_SLAB = 181;
public static final int RED_SANDSTONE_SLAB = 182;
public static final int FENCE_GATE_SPRUCE = 183;
public static final int FENCE_GATE_BIRCH = 184;
public static final int FENCE_GATE_JUNGLE = 185;
public static final int FENCE_GATE_DARK_OAK = 186;
public static final int FENCE_GATE_ACACIA = 187;
public static final int SPRUCE_DOOR_BLOCK = 193;
public static final int BIRCH_DOOR_BLOCK = 194;
public static final int JUNGLE_DOOR_BLOCK = 195;
public static final int ACACIA_DOOR_BLOCK = 196;
public static final int DARK_OAK_DOOR_BLOCK = 197;
public static final int GRASS_PATH = 198;
public static final int ITEM_FRAME_BLOCK = 199;
public static final int CHORUS_FLOWER = 200;
public static final int PURPUR_BLOCK = 201;
public static final int PURPUR_STAIRS = 203;
public static final int DOUBLE_PURPUR_SLAB = 204;
public static final int PURPUR_SLAB = 205;
public static final int END_BRICKS = 206;
//Note: frosted ice CAN NOT BE HARVESTED WITH HAND -- canHarvestWithHand method should be overridden FALSE.
public static final int ICE_FROSTED = 207;
public static final int END_ROD = 208;
public static final int END_GATEWAY = 209;
public static final int MAGMA = 213;
public static final int BLOCK_NETHER_WART_BLOCK = 214;
public static final int RED_NETHER_BRICK = 215;
public static final int BONE_BLOCK = 216;
public static final int SHULKER_BOX = 218;
public static final int PURPLE_GLAZED_TERRACOTTA = 219;
public static final int WHITE_GLAZED_TERRACOTTA = 220;
public static final int ORANGE_GLAZED_TERRACOTTA = 221;
public static final int MAGENTA_GLAZED_TERRACOTTA = 222;
public static final int LIGHT_BLUE_GLAZED_TERRACOTTA = 223;
public static final int YELLOW_GLAZED_TERRACOTTA = 224;
public static final int LIME_GLAZED_TERRACOTTA = 225;
public static final int PINK_GLAZED_TERRACOTTA = 226;
public static final int GRAY_GLAZED_TERRACOTTA = 227;
public static final int SILVER_GLAZED_TERRACOTTA = 228;
public static final int CYAN_GLAZED_TERRACOTTA = 229;
public static final int BLUE_GLAZED_TERRACOTTA = 231;
public static final int BROWN_GLAZED_TERRACOTTA = 232;
public static final int GREEN_GLAZED_TERRACOTTA = 233;
public static final int RED_GLAZED_TERRACOTTA = 234;
public static final int BLACK_GLAZED_TERRACOTTA = 235;
public static final int CONCRETE = 236;
public static final int CONCRETE_POWDER = 237;
public static final int CHORUS_PLANT = 240;
public static final int STAINED_GLASS = 241;
public static final int PODZOL = 243;
public static final int BEETROOT_BLOCK = 244;
public static final int STONECUTTER = 245;
public static final int GLOWING_OBSIDIAN = 246;
public static final int NETHER_REACTOR = 247; //Should not be removed
public static final int PISTON_EXTENSION = 250;
public static final int OBSERVER = 251;
public static Class[] list = null;
public static Block[] fullList = null;
public static int[] light = null;
public static int[] lightFilter = null;
public static boolean[] solid = null;
public static double[] hardness = null;
public static boolean[] transparent = null;
/**
* if a block has can have variants
*/
public static boolean[] hasMeta = null;
protected Block() {}
@SuppressWarnings("unchecked")
public static void init() {
if (list == null) {
list = new Class[256];
fullList = new Block[4096];
light = new int[256];
lightFilter = new int[256];
solid = new boolean[256];
hardness = new double[256];
transparent = new boolean[256];
hasMeta = new boolean[256];
list[AIR] = BlockAir.class; //0
list[STONE] = BlockStone.class; //1
list[GRASS] = BlockGrass.class; //2
list[DIRT] = BlockDirt.class; //3
list[COBBLESTONE] = BlockCobblestone.class; //4
list[PLANKS] = BlockPlanks.class; //5
list[SAPLING] = BlockSapling.class; //6
list[BEDROCK] = BlockBedrock.class; //7
list[WATER] = BlockWater.class; //8
list[STILL_WATER] = BlockWaterStill.class; //9
list[LAVA] = BlockLava.class; //10
list[STILL_LAVA] = BlockLavaStill.class; //11
list[SAND] = BlockSand.class; //12
list[GRAVEL] = BlockGravel.class; //13
list[GOLD_ORE] = BlockOreGold.class; //14
list[IRON_ORE] = BlockOreIron.class; //15
list[COAL_ORE] = BlockOreCoal.class; //16
list[WOOD] = BlockWood.class; //17
list[LEAVES] = BlockLeaves.class; //18
list[SPONGE] = BlockSponge.class; //19
list[GLASS] = BlockGlass.class; //20
list[LAPIS_ORE] = BlockOreLapis.class; //21
list[LAPIS_BLOCK] = BlockLapis.class; //22
//TODO: list[DISPENSER] = BlockDispenser.class; //23
list[SANDSTONE] = BlockSandstone.class; //24
list[NOTEBLOCK] = BlockNoteblock.class; //25
list[BED_BLOCK] = BlockBed.class; //26
list[POWERED_RAIL] = BlockRailPowered.class; //27
list[DETECTOR_RAIL] = BlockRailDetector.class; //28
list[STICKY_PISTON] = BlockPistonSticky.class; //29
list[COBWEB] = BlockCobweb.class; //30
list[TALL_GRASS] = BlockTallGrass.class; //31
list[DEAD_BUSH] = BlockDeadBush.class; //32
list[PISTON] = BlockPiston.class; //33
list[PISTON_HEAD] = BlockPistonHead.class; //34
list[WOOL] = BlockWool.class; //35
list[DANDELION] = BlockDandelion.class; //37
list[FLOWER] = BlockFlower.class; //38
list[BROWN_MUSHROOM] = BlockMushroomBrown.class; //39
list[RED_MUSHROOM] = BlockMushroomRed.class; //40
list[GOLD_BLOCK] = BlockGold.class; //41
list[IRON_BLOCK] = BlockIron.class; //42
list[DOUBLE_STONE_SLAB] = BlockDoubleSlabStone.class; //43
list[STONE_SLAB] = BlockSlabStone.class; //44
list[BRICKS_BLOCK] = BlockBricks.class; //45
list[TNT] = BlockTNT.class; //46
list[BOOKSHELF] = BlockBookshelf.class; //47
list[MOSS_STONE] = BlockMossStone.class; //48
list[OBSIDIAN] = BlockObsidian.class; //49
list[TORCH] = BlockTorch.class; //50
list[FIRE] = BlockFire.class; //51
list[MONSTER_SPAWNER] = BlockMobSpawner.class; //52
list[WOOD_STAIRS] = BlockStairsWood.class; //53
list[CHEST] = BlockChest.class; //54
list[REDSTONE_WIRE] = BlockRedstoneWire.class; //55
list[DIAMOND_ORE] = BlockOreDiamond.class; //56
list[DIAMOND_BLOCK] = BlockDiamond.class; //57
list[WORKBENCH] = BlockCraftingTable.class; //58
list[WHEAT_BLOCK] = BlockWheat.class; //59
list[FARMLAND] = BlockFarmland.class; //60
list[FURNACE] = BlockFurnace.class; //61
list[BURNING_FURNACE] = BlockFurnaceBurning.class; //62
list[SIGN_POST] = BlockSignPost.class; //63
list[WOOD_DOOR_BLOCK] = BlockDoorWood.class; //64
list[LADDER] = BlockLadder.class; //65
list[RAIL] = BlockRail.class; //66
list[COBBLESTONE_STAIRS] = BlockStairsCobblestone.class; //67
list[WALL_SIGN] = BlockWallSign.class; //68
list[LEVER] = BlockLever.class; //69
list[STONE_PRESSURE_PLATE] = BlockPressurePlateStone.class; //70
list[IRON_DOOR_BLOCK] = BlockDoorIron.class; //71
list[WOODEN_PRESSURE_PLATE] = BlockPressurePlateWood.class; //72
list[REDSTONE_ORE] = BlockOreRedstone.class; //73
list[GLOWING_REDSTONE_ORE] = BlockOreRedstoneGlowing.class; //74
list[UNLIT_REDSTONE_TORCH] = BlockRedstoneTorchUnlit.class;
list[REDSTONE_TORCH] = BlockRedstoneTorch.class; //76
list[STONE_BUTTON] = BlockButtonStone.class; //77
list[SNOW_LAYER] = BlockSnowLayer.class; //78
list[ICE] = BlockIce.class; //79
list[SNOW_BLOCK] = BlockSnow.class; //80
list[CACTUS] = BlockCactus.class; //81
list[CLAY_BLOCK] = BlockClay.class; //82
list[SUGARCANE_BLOCK] = BlockSugarcane.class; //83
list[JUKEBOX] = BlockJukebox.class; //84
list[FENCE] = BlockFence.class; //85
list[PUMPKIN] = BlockPumpkin.class; //86
list[NETHERRACK] = BlockNetherrack.class; //87
list[SOUL_SAND] = BlockSoulSand.class; //88
list[GLOWSTONE_BLOCK] = BlockGlowstone.class; //89
list[NETHER_PORTAL] = BlockNetherPortal.class; //90
list[LIT_PUMPKIN] = BlockPumpkinLit.class; //91
list[CAKE_BLOCK] = BlockCake.class; //92
list[UNPOWERED_REPEATER] = BlockRedstoneRepeaterUnpowered.class; //93
list[POWERED_REPEATER] = BlockRedstoneRepeaterPowered.class; //94
list[INVISIBLE_BEDROCK] = BlockBedrockInvisible.class; //95
list[TRAPDOOR] = BlockTrapdoor.class; //96
list[MONSTER_EGG] = BlockMonsterEgg.class; //97
list[STONE_BRICKS] = BlockBricksStone.class; //98
list[BROWN_MUSHROOM_BLOCK] = BlockHugeMushroomBrown.class; //99
list[RED_MUSHROOM_BLOCK] = BlockHugeMushroomRed.class; //100
list[IRON_BARS] = BlockIronBars.class; //101
list[GLASS_PANE] = BlockGlassPane.class; //102
list[MELON_BLOCK] = BlockMelon.class; //103
list[PUMPKIN_STEM] = BlockStemPumpkin.class; //104
list[MELON_STEM] = BlockStemMelon.class; //105
list[VINE] = BlockVine.class; //106
list[FENCE_GATE] = BlockFenceGate.class; //107
list[BRICK_STAIRS] = BlockStairsBrick.class; //108
list[STONE_BRICK_STAIRS] = BlockStairsStoneBrick.class; //109
list[MYCELIUM] = BlockMycelium.class; //110
list[WATER_LILY] = BlockWaterLily.class; //111
list[NETHER_BRICKS] = BlockBricksNether.class; //112
list[NETHER_BRICK_FENCE] = BlockFenceNetherBrick.class; //113
list[NETHER_BRICKS_STAIRS] = BlockStairsNetherBrick.class; //114
list[NETHER_WART_BLOCK] = BlockNetherWart.class; //115
list[ENCHANTING_TABLE] = BlockEnchantingTable.class; //116
list[BREWING_STAND_BLOCK] = BlockBrewingStand.class; //117
list[CAULDRON_BLOCK] = BlockCauldron.class; //118
list[END_PORTAL] = BlockEndPortal.class; //119
list[END_PORTAL_FRAME] = BlockEndPortalFrame.class; //120
list[END_STONE] = BlockEndStone.class; //121
list[DRAGON_EGG] = BlockDragonEgg.class; //122
list[REDSTONE_LAMP] = BlockRedstoneLamp.class; //123
list[LIT_REDSTONE_LAMP] = BlockRedstoneLampLit.class; //124
//TODO: list[DROPPER] = BlockDropper.class; //125
list[ACTIVATOR_RAIL] = BlockRailActivator.class; //126
list[COCOA] = BlockCocoa.class; //127
list[SANDSTONE_STAIRS] = BlockStairsSandstone.class; //128
list[EMERALD_ORE] = BlockOreEmerald.class; //129
list[ENDER_CHEST] = BlockEnderChest.class; //130
list[TRIPWIRE_HOOK] = BlockTripWireHook.class;
list[TRIPWIRE] = BlockTripWire.class; //132
list[EMERALD_BLOCK] = BlockEmerald.class; //133
list[SPRUCE_WOOD_STAIRS] = BlockStairsSpruce.class; //134
list[BIRCH_WOOD_STAIRS] = BlockStairsBirch.class; //135
list[JUNGLE_WOOD_STAIRS] = BlockStairsJungle.class; //136
list[BEACON] = BlockBeacon.class; //138
list[STONE_WALL] = BlockWall.class; //139
list[FLOWER_POT_BLOCK] = BlockFlowerPot.class; //140
list[CARROT_BLOCK] = BlockCarrot.class; //141
list[POTATO_BLOCK] = BlockPotato.class; //142
list[WOODEN_BUTTON] = BlockButtonWooden.class; //143
list[SKULL_BLOCK] = BlockSkull.class; //144
list[ANVIL] = BlockAnvil.class; //145
list[TRAPPED_CHEST] = BlockTrappedChest.class; //146
list[LIGHT_WEIGHTED_PRESSURE_PLATE] = BlockWeightedPressurePlateLight.class; //147
list[HEAVY_WEIGHTED_PRESSURE_PLATE] = BlockWeightedPressurePlateHeavy.class; //148
list[UNPOWERED_COMPARATOR] = BlockRedstoneComparatorUnpowered.class; //149
list[POWERED_COMPARATOR] = BlockRedstoneComparatorPowered.class; //149
list[DAYLIGHT_DETECTOR] = BlockDaylightDetector.class; //151
list[REDSTONE_BLOCK] = BlockRedstone.class; //152
list[QUARTZ_ORE] = BlockOreQuartz.class; //153
list[HOPPER_BLOCK] = BlockHopper.class; //154
list[QUARTZ_BLOCK] = BlockQuartz.class; //155
list[QUARTZ_STAIRS] = BlockStairsQuartz.class; //156
list[DOUBLE_WOOD_SLAB] = BlockDoubleSlabWood.class; //157
list[WOOD_SLAB] = BlockSlabWood.class; //158
list[STAINED_TERRACOTTA] = BlockTerracottaStained.class; //159
list[STAINED_GLASS_PANE] = BlockGlassPaneStained.class; //160
list[LEAVES2] = BlockLeaves2.class; //161
list[WOOD2] = BlockWood2.class; //162
list[ACACIA_WOOD_STAIRS] = BlockStairsAcacia.class; //163
list[DARK_OAK_WOOD_STAIRS] = BlockStairsDarkOak.class; //164
list[SLIME_BLOCK] = BlockSlime.class; //165
list[IRON_TRAPDOOR] = BlockTrapdoorIron.class; //167
list[PRISMARINE] = BlockPrismarine.class; //168
list[SEA_LANTERN] = BlockSeaLantern.class; //169
list[HAY_BALE] = BlockHayBale.class; //170
list[CARPET] = BlockCarpet.class; //171
list[TERRACOTTA] = BlockTerracotta.class; //172
list[COAL_BLOCK] = BlockCoal.class; //173
list[PACKED_ICE] = BlockIcePacked.class; //174
list[DOUBLE_PLANT] = BlockDoublePlant.class; //175
list[DAYLIGHT_DETECTOR_INVERTED] = BlockDaylightDetectorInverted.class; //178
list[RED_SANDSTONE] = BlockRedSandstone.class; //179
list[RED_SANDSTONE_STAIRS] = BlockStairsRedSandstone.class; //180
list[DOUBLE_RED_SANDSTONE_SLAB] = BlockDoubleSlabRedSandstone.class; //181
list[RED_SANDSTONE_SLAB] = BlockSlabRedSandstone.class; //182
list[FENCE_GATE_SPRUCE] = BlockFenceGateSpruce.class; //183
list[FENCE_GATE_BIRCH] = BlockFenceGateBirch.class; //184
list[FENCE_GATE_JUNGLE] = BlockFenceGateJungle.class; //185
list[FENCE_GATE_DARK_OAK] = BlockFenceGateDarkOak.class; //186
list[FENCE_GATE_ACACIA] = BlockFenceGateAcacia.class; //187
list[SPRUCE_DOOR_BLOCK] = BlockDoorSpruce.class; //193
list[BIRCH_DOOR_BLOCK] = BlockDoorBirch.class; //194
list[JUNGLE_DOOR_BLOCK] = BlockDoorJungle.class; //195
list[ACACIA_DOOR_BLOCK] = BlockDoorAcacia.class; //196
list[DARK_OAK_DOOR_BLOCK] = BlockDoorDarkOak.class; //197
list[GRASS_PATH] = BlockGrassPath.class; //198
list[ITEM_FRAME_BLOCK] = BlockItemFrame.class; //199
//TODO: list[CHORUS_FLOWER] = BlockChorusFlower.class; //200
list[PURPUR_BLOCK] = BlockPurpur.class; //201
list[PURPUR_STAIRS] = BlockStairsPurpur.class; //203
list[END_BRICKS] = BlockBricksEndStone.class; //206
list[END_ROD] = BlockEndRod.class; //208
list[END_GATEWAY] = BlockEndGateway.class; //209
list[BONE_BLOCK] = BlockBone.class; //216
//TODO: list[SHULKER_BOX] = BlockShulkerBox.class; //218
list[PURPLE_GLAZED_TERRACOTTA] = BlockTerracottaGlazedPurple.class; //219
list[WHITE_GLAZED_TERRACOTTA] = BlockTerracottaGlazedWhite.class; //220
list[ORANGE_GLAZED_TERRACOTTA] = BlockTerracottaGlazedOrange.class; //221
list[MAGENTA_GLAZED_TERRACOTTA] = BlockTerracottaGlazedMagenta.class; //222
list[LIGHT_BLUE_GLAZED_TERRACOTTA] = BlockTerracottaGlazedLightBlue.class; //223
list[YELLOW_GLAZED_TERRACOTTA] = BlockTerracottaGlazedYellow.class; //224
list[LIME_GLAZED_TERRACOTTA] = BlockTerracottaGlazedLime.class; //225
list[PINK_GLAZED_TERRACOTTA] = BlockTerracottaGlazedPink.class; //226
list[GRAY_GLAZED_TERRACOTTA] = BlockTerracottaGlazedGray.class; //227
list[SILVER_GLAZED_TERRACOTTA] = BlockTerracottaGlazedSilver.class; //228
list[CYAN_GLAZED_TERRACOTTA] = BlockTerracottaGlazedCyan.class; //229
list[BLUE_GLAZED_TERRACOTTA] = BlockTerracottaGlazedBlue.class; //231
list[BROWN_GLAZED_TERRACOTTA] = BlockTerracottaGlazedBrown.class; //232
list[GREEN_GLAZED_TERRACOTTA] = BlockTerracottaGlazedGreen.class; //233
list[RED_GLAZED_TERRACOTTA] = BlockTerracottaGlazedRed.class; //234
list[BLACK_GLAZED_TERRACOTTA] = BlockTerracottaGlazedBlack.class; //235
list[CONCRETE] = BlockConcrete.class; //236
list[CONCRETE_POWDER] = BlockConcretePowder.class; //237
//TODO: list[CHORUS_PLANT] = BlockChorusPlant.class; //240
list[STAINED_GLASS] = BlockGlassStained.class; //241
list[PODZOL] = BlockPodzol.class; //243
list[BEETROOT_BLOCK] = BlockBeetroot.class; //244
list[GLOWING_OBSIDIAN] = BlockObsidianGlowing.class; //246
//TODO: list[NETHER_REACTOR] = BlockNetherReactor.class; //247 Should not be removed
//TODO: list[PISTON_EXTENSION] = BlockPistonExtension.class; //250
//TODO: list[OBSERVER] = BlockObserver.class; //251
for (int id = 0; id < 256; id++) {
Class c = list[id];
if (c != null) {
Block block;
try {
block = (Block) c.newInstance();
try {
Constructor constructor = c.getDeclaredConstructor(int.class);
constructor.setAccessible(true);
for (int data = 0; data < 16; ++data) {
fullList[(id << 4) | data] = (Block) constructor.newInstance(data);
}
hasMeta[id] = true;
} catch (NoSuchMethodException ignore) {
for (int data = 0; data < 16; ++data) {
fullList[(id << 4) | data] = block;
}
}
} catch (Exception e) {
Server.getInstance().getLogger().error("Error while registering " + c.getName(), e);
for (int data = 0; data < 16; ++data) {
fullList[(id << 4) | data] = new BlockUnknown(id, data);
}
return;
}
solid[id] = block.isSolid();
transparent[id] = block.isTransparent();
hardness[id] = block.getHardness();
light[id] = block.getLightLevel();
if (block.isSolid()) {
if (block.isTransparent()) {
if (block instanceof BlockLiquid || block instanceof BlockIce) {
lightFilter[id] = 2;
} else {
lightFilter[id] = 1;
}
} else {
lightFilter[id] = 15;
}
} else {
lightFilter[id] = 1;
}
} else {
lightFilter[id] = 1;
for (int data = 0; data < 16; ++data) {
fullList[(id << 4) | data] = new BlockUnknown(id, data);
}
}
}
}
}
public static Block get(int id) {
return fullList[id << 4].clone();
}
public static Block get(int id, Integer meta) {
if (meta != null) {
return fullList[(id << 4) + meta].clone();
} else {
return fullList[id << 4].clone();
}
}
@SuppressWarnings("unchecked")
public static Block get(int id, Integer meta, Position pos) {
Block block = fullList[(id << 4) | (meta == null ? 0 : meta)].clone();
if (pos != null) {
block.x = pos.x;
block.y = pos.y;
block.z = pos.z;
block.level = pos.level;
}
return block;
}
public static Block get(int id, int data) {
return fullList[(id << 4) + data].clone();
}
public static Block get(int fullId, Level level, int x, int y, int z) {
Block block = fullList[fullId].clone();
block.x = x;
block.y = y;
block.z = z;
block.level = level;
return block;
}
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
return this.place(item, block, target, face, fx, fy, fz, null);
}
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
return this.getLevel().setBlock(this, this, true, true);
}
//http://minecraft.gamepedia.com/Breaking
public boolean canHarvestWithHand() { //used for calculating breaking time
return true;
}
public boolean isBreakable(Item item) {
return true;
}
public int tickRate() {
return 10;
}
public boolean onBreak(Item item) {
return this.getLevel().setBlock(this, new BlockAir(), true, true);
}
public int onUpdate(int type) {
return 0;
}
public boolean onActivate(Item item) {
return this.onActivate(item, null);
}
public boolean onActivate(Item item, Player player) {
return false;
}
public double getHardness() {
return 10;
}
public double getResistance() {
return 1;
}
public int getBurnChance() {
return 0;
}
public int getBurnAbility() {
return 0;
}
public int getToolType() {
return ItemTool.TYPE_NONE;
}
public double getFrictionFactor() {
return 0.6;
}
public int getLightLevel() {
return 0;
}
public boolean canBePlaced() {
return true;
}
public boolean canBeReplaced() {
return false;
}
public boolean isTransparent() {
return false;
}
public boolean isSolid() {
return true;
}
public boolean canBeFlowedInto() {
return false;
}
public boolean canBeActivated() {
return false;
}
public boolean hasEntityCollision() {
return false;
}
public boolean canPassThrough() {
return false;
}
public boolean canBePushed() {
return true;
}
public boolean hasComparatorInputOverride() {
return false;
}
public int getComparatorInputOverride() {
return 0;
}
public boolean canBeClimbed() {
return false;
}
public BlockColor getColor() {
return BlockColor.VOID_BLOCK_COLOR;
}
public abstract String getName();
public abstract int getId();
/**
* The full id is a combination of the id and data.
* @return
*/
public int getFullId() {
return (getId() << 4);
}
public void addVelocityToEntity(Entity entity, Vector3 vector) {
}
public int getDamage() {
return 0;
}
public void setDamage(int meta) {
// Do nothing
}
public final void setDamage(Integer meta) {
setDamage((meta == null ? 0 : meta & 0x0f));
}
final public void position(Position v) {
this.x = (int) v.x;
this.y = (int) v.y;
this.z = (int) v.z;
this.level = v.level;
}
public Item[] getDrops(Item item) {
if (this.getId() < 0 || this.getId() > list.length) { //Unknown blocks
return new Item[0];
} else {
return new Item[]{
this.toItem()
};
}
}
private static double toolBreakTimeBonus0(
int toolType, int toolTier, boolean isWoolBlock, boolean isCobweb) {
if (toolType == ItemTool.TYPE_SWORD) return isCobweb ? 15.0 : 1.0;
if (toolType == ItemTool.TYPE_SHEARS) return isWoolBlock ? 5.0 : 15.0;
if (toolType == ItemTool.TYPE_NONE) return 1.0;
switch (toolTier) {
case ItemTool.TIER_WOODEN:
return 2.0;
case ItemTool.TIER_STONE:
return 4.0;
case ItemTool.TIER_IRON:
return 6.0;
case ItemTool.TIER_DIAMOND:
return 8.0;
case ItemTool.TIER_GOLD:
return 12.0;
default:
return 1.0;
}
}
private static double speedBonusByEfficiencyLore0(int efficiencyLoreLevel) {
if (efficiencyLoreLevel == 0) return 0;
return efficiencyLoreLevel * efficiencyLoreLevel + 1;
}
private static double speedRateByHasteLore0(int hasteLoreLevel) {
return 1.0 + (0.2 * hasteLoreLevel);
}
private static int toolType0(Item item) {
if (item.isSword()) return ItemTool.TYPE_SWORD;
if (item.isShovel()) return ItemTool.TYPE_SHOVEL;
if (item.isPickaxe()) return ItemTool.TYPE_PICKAXE;
if (item.isAxe()) return ItemTool.TYPE_AXE;
if (item.isShears()) return ItemTool.TYPE_SHEARS;
return ItemTool.TYPE_NONE;
}
private static boolean correctTool0(int blockToolType, Item item) {
return (blockToolType == ItemTool.TYPE_SWORD && item.isSword()) ||
(blockToolType == ItemTool.TYPE_SHOVEL && item.isShovel()) ||
(blockToolType == ItemTool.TYPE_PICKAXE && item.isPickaxe()) ||
(blockToolType == ItemTool.TYPE_AXE && item.isAxe()) ||
(blockToolType == ItemTool.TYPE_SHEARS && item.isShears()) ||
blockToolType == ItemTool.TYPE_NONE;
}
//http://minecraft.gamepedia.com/Breaking
private static double breakTime0(double blockHardness, boolean correctTool, boolean canHarvestWithHand,
int blockId, int toolType, int toolTier, int efficiencyLoreLevel, int hasteEffectLevel,
boolean insideOfWaterWithoutAquaAffinity, boolean outOfWaterButNotOnGround) {
double baseTime = ((correctTool || canHarvestWithHand) ? 1.5 : 5.0) * blockHardness;
double speed = 1.0 / baseTime;
boolean isWoolBlock = blockId == Block.WOOL, isCobweb = blockId == Block.COBWEB;
if (correctTool) speed *= toolBreakTimeBonus0(toolType, toolTier, isWoolBlock, isCobweb);
speed += speedBonusByEfficiencyLore0(efficiencyLoreLevel);
speed *= speedRateByHasteLore0(hasteEffectLevel);
if (insideOfWaterWithoutAquaAffinity) speed *= 0.2;
if (outOfWaterButNotOnGround) speed *= 0.2;
return 1.0 / speed;
}
public double getBreakTime(Item item, Player player) {
Objects.requireNonNull(item, "getBreakTime: Item can not be null");
Objects.requireNonNull(player, "getBreakTime: Player can not be null");
double blockHardness = getHardness();
boolean correctTool = correctTool0(getToolType(), item);
boolean canHarvestWithHand = canHarvestWithHand();
int blockId = getId();
int itemToolType = toolType0(item);
int itemTier = item.getTier();
int efficiencyLoreLevel = Optional.ofNullable(item.getEnchantment(Enchantment.ID_EFFICIENCY))
.map(Enchantment::getLevel).orElse(0);
int hasteEffectLevel = Optional.ofNullable(player.getEffect(Effect.HASTE))
.map(Effect::getAmplifier).orElse(0);
boolean insideOfWaterWithoutAquaAffinity = player.isInsideOfWater() &&
Optional.ofNullable(player.getInventory().getHelmet().getEnchantment(Enchantment.ID_WATER_WORKER))
.map(Enchantment::getLevel).map(l -> l >= 1).orElse(false);
boolean outOfWaterButNotOnGround = (!player.isInsideOfWater()) && (!player.isOnGround());
return breakTime0(blockHardness, correctTool, canHarvestWithHand, blockId, itemToolType, itemTier,
efficiencyLoreLevel, hasteEffectLevel, insideOfWaterWithoutAquaAffinity, outOfWaterButNotOnGround);
}
/**
* @deprecated This function is lack of Player class and is not accurate enough, use #getBreakTime(Item, Player)
*/
@Deprecated
public double getBreakTime(Item item) {
double base = this.getHardness() * 1.5;
if (this.canBeBrokenWith(item)) {
if (this.getToolType() == ItemTool.TYPE_SHEARS && item.isShears()) {
base /= 15;
} else if (
(this.getToolType() == ItemTool.TYPE_PICKAXE && item.isPickaxe()) ||
(this.getToolType() == ItemTool.TYPE_AXE && item.isAxe()) ||
(this.getToolType() == ItemTool.TYPE_SHOVEL && item.isShovel())
) {
int tier = item.getTier();
switch (tier) {
case ItemTool.TIER_WOODEN:
base /= 2;
break;
case ItemTool.TIER_STONE:
base /= 4;
break;
case ItemTool.TIER_IRON:
base /= 6;
break;
case ItemTool.TIER_DIAMOND:
base /= 8;
break;
case ItemTool.TIER_GOLD:
base /= 12;
break;
}
}
} else {
base *= 3.33;
}
if (item.isSword()) {
base *= 0.5;
}
return base;
}
public boolean canBeBrokenWith(Item item) {
return this.getHardness() != -1;
}
public Block getSide(BlockFace face) {
return this.getSide(face, 1);
}
public Block getSide(BlockFace face, int step) {
if (this.isValid()) {
return this.getLevel().getBlock(super.getSide(face, step));
}
return Block.get(Item.AIR, 0, Position.fromObject(new Vector3(this.x, this.y, this.z).getSide(face, step)));
}
public Block up() {
return up(1);
}
public Block up(int step) {
return getSide(BlockFace.UP, step);
}
public Block down() {
return down(1);
}
public Block down(int step) {
return getSide(BlockFace.DOWN, step);
}
public Block north() {
return north(1);
}
public Block north(int step) {
return getSide(BlockFace.NORTH, step);
}
public Block south() {
return south(1);
}
public Block south(int step) {
return getSide(BlockFace.SOUTH, step);
}
public Block east() {
return east(1);
}
public Block east(int step) {
return getSide(BlockFace.EAST, step);
}
public Block west() {
return west(1);
}
public Block west(int step) {
return getSide(BlockFace.WEST, step);
}
@Override
public String toString() {
return "Block[" + this.getName() + "] (" + this.getId() + ":" + this.getDamage() + ")";
}
public boolean collidesWithBB(AxisAlignedBB bb) {
return collidesWithBB(bb, false);
}
public boolean collidesWithBB(AxisAlignedBB bb, boolean collisionBB) {
AxisAlignedBB bb1 = collisionBB ? this.getCollisionBoundingBox() : this.getBoundingBox();
return bb1 != null && bb.intersectsWith(bb1);
}
public void onEntityCollide(Entity entity) {
}
public AxisAlignedBB getBoundingBox() {
return this.recalculateBoundingBox();
}
public AxisAlignedBB getCollisionBoundingBox() {
return this.recalculateCollisionBoundingBox();
}
protected AxisAlignedBB recalculateBoundingBox() {
return this;
}
@Override
public double getMinX() {
return this.x;
}
@Override
public double getMinY() {
return this.y;
}
@Override
public double getMinZ() {
return this.z;
}
@Override
public double getMaxX() {
return this.x + 1;
}
@Override
public double getMaxY() {
return this.y + 1;
}
@Override
public double getMaxZ() {
return this.z + 1;
}
protected AxisAlignedBB recalculateCollisionBoundingBox() {
return getBoundingBox();
}
public MovingObjectPosition calculateIntercept(Vector3 pos1, Vector3 pos2) {
AxisAlignedBB bb = this.getBoundingBox();
if (bb == null) {
return null;
}
Vector3 v1 = pos1.getIntermediateWithXValue(pos2, bb.getMinX());
Vector3 v2 = pos1.getIntermediateWithXValue(pos2, bb.getMaxX());
Vector3 v3 = pos1.getIntermediateWithYValue(pos2, bb.getMinY());
Vector3 v4 = pos1.getIntermediateWithYValue(pos2, bb.getMaxY());
Vector3 v5 = pos1.getIntermediateWithZValue(pos2, bb.getMinZ());
Vector3 v6 = pos1.getIntermediateWithZValue(pos2, bb.getMaxZ());
if (v1 != null && !bb.isVectorInYZ(v1)) {
v1 = null;
}
if (v2 != null && !bb.isVectorInYZ(v2)) {
v2 = null;
}
if (v3 != null && !bb.isVectorInXZ(v3)) {
v3 = null;
}
if (v4 != null && !bb.isVectorInXZ(v4)) {
v4 = null;
}
if (v5 != null && !bb.isVectorInXY(v5)) {
v5 = null;
}
if (v6 != null && !bb.isVectorInXY(v6)) {
v6 = null;
}
Vector3 vector = v1;
if (v2 != null && (vector == null || pos1.distanceSquared(v2) < pos1.distanceSquared(vector))) {
vector = v2;
}
if (v3 != null && (vector == null || pos1.distanceSquared(v3) < pos1.distanceSquared(vector))) {
vector = v3;
}
if (v4 != null && (vector == null || pos1.distanceSquared(v4) < pos1.distanceSquared(vector))) {
vector = v4;
}
if (v5 != null && (vector == null || pos1.distanceSquared(v5) < pos1.distanceSquared(vector))) {
vector = v5;
}
if (v6 != null && (vector == null || pos1.distanceSquared(v6) < pos1.distanceSquared(vector))) {
vector = v6;
}
if (vector == null) {
return null;
}
int f = -1;
if (vector == v1) {
f = 4;
} else if (vector == v2) {
f = 5;
} else if (vector == v3) {
f = 0;
} else if (vector == v4) {
f = 1;
} else if (vector == v5) {
f = 2;
} else if (vector == v6) {
f = 3;
}
return MovingObjectPosition.fromBlock((int) this.x, (int) this.y, (int) this.z, f, vector.add(this.x, this.y, this.z));
}
public String getSaveId() {
String name = getClass().getName();
return name.substring(16, name.length());
}
@Override
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) throws Exception {
if (this.getLevel() != null) {
this.getLevel().getBlockMetadata().setMetadata(this, metadataKey, newMetadataValue);
}
}
@Override
public List<MetadataValue> getMetadata(String metadataKey) throws Exception {
if (this.getLevel() != null) {
return this.getLevel().getBlockMetadata().getMetadata(this, metadataKey);
}
return null;
}
@Override
public boolean hasMetadata(String metadataKey) throws Exception {
return this.getLevel() != null && this.getLevel().getBlockMetadata().hasMetadata(this, metadataKey);
}
@Override
public void removeMetadata(String metadataKey, Plugin owningPlugin) throws Exception {
if (this.getLevel() != null) {
this.getLevel().getBlockMetadata().removeMetadata(this, metadataKey, owningPlugin);
}
}
public Block clone() {
return (Block) super.clone();
}
public int getWeakPower(BlockFace face) {
return 0;
}
public int getStrongPower(BlockFace side) {
return 0;
}
public boolean isPowerSource() {
return false;
}
public String getLocationHash() {
return this.getFloorX() + ":" + this.getFloorY() + ":" + this.getFloorZ();
}
public int getDropExp() {
return 0;
}
public boolean isNormalBlock() {
return !isTransparent() && isSolid() && !isPowerSource();
}
public static boolean equals(Block b1, Block b2) {
return equals(b1, b2, true);
}
public static boolean equals(Block b1, Block b2, boolean checkDamage) {
return b1 != null && b2 != null && b1.getId() == b2.getId() && (!checkDamage || b1.getDamage() == b2.getDamage());
}
public Item toItem() {
return new ItemBlock(this, this.getDamage(), 1);
}
}
| 49,857 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockSlabStone.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockSlabStone.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* Created by CreeperFace on 26. 11. 2016.
*/
public class BlockSlabStone extends BlockSlab {
public static final int STONE = 0;
public static final int SANDSTONE = 1;
public static final int WOODEN = 2;
public static final int COBBLESTONE = 3;
public static final int BRICK = 4;
public static final int STONE_BRICK = 5;
public static final int QUARTZ = 6;
public static final int NETHER_BRICK = 7;
public BlockSlabStone() {
this(0);
}
public BlockSlabStone(int meta) {
super(meta, DOUBLE_STONE_SLAB);
}
@Override
public int getId() {
return STONE_SLAB;
}
@Override
public String getName() {
String[] names = new String[]{
"Stone",
"Sandstone",
"Wooden",
"Cobblestone",
"Brick",
"Stone Brick",
"Quartz",
"Nether Brick"
};
return ((this.getDamage() & 0x08) > 0 ? "Upper " : "") + names[this.getDamage() & 0x07] + " Slab";
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public Item toItem() {
return new ItemBlock(this, this.getDamage() & 0x07);
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public BlockColor getColor() {
switch (this.getDamage() & 0x07) {
case STONE:
return BlockColor.STONE_BLOCK_COLOR;
case SANDSTONE:
return BlockColor.SAND_BLOCK_COLOR;
case WOODEN:
return BlockColor.WOOD_BLOCK_COLOR;
case COBBLESTONE:
return BlockColor.STONE_BLOCK_COLOR;
case BRICK:
return BlockColor.STONE_BLOCK_COLOR;
case STONE_BRICK:
return BlockColor.STONE_BLOCK_COLOR;
case QUARTZ:
return BlockColor.QUARTZ_BLOCK_COLOR;
case NETHER_BRICK:
return BlockColor.NETHERRACK_BLOCK_COLOR;
default:
return BlockColor.STONE_BLOCK_COLOR; //unreachable
}
}
@Override
public boolean canHarvestWithHand() {
return false;
}
} | 2,637 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTrappedChest.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTrappedChest.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.blockentity.BlockEntity;
import cn.nukkit.blockentity.BlockEntityChest;
import cn.nukkit.item.Item;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.BlockFace.Plane;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.nbt.tag.ListTag;
import cn.nukkit.nbt.tag.Tag;
import java.util.Map;
public class BlockTrappedChest extends BlockChest {
public BlockTrappedChest() {
this(0);
}
public BlockTrappedChest(int meta) {
super(meta);
}
@Override
public int getId() {
return TRAPPED_CHEST;
}
@Override
public String getName() {
return "Trapped Chest";
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
int[] faces = {2, 5, 3, 4};
BlockEntityChest chest = null;
this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
for (BlockFace side : Plane.HORIZONTAL) {
if ((this.getDamage() == 4 || this.getDamage() == 5) && (side == BlockFace.WEST || side == BlockFace.EAST)) {
continue;
} else if ((this.getDamage() == 3 || this.getDamage() == 2) && (side == BlockFace.NORTH || side == BlockFace.SOUTH)) {
continue;
}
Block c = this.getSide(side);
if (c instanceof BlockTrappedChest && c.getDamage() == this.getDamage()) {
BlockEntity blockEntity = this.getLevel().getBlockEntity(c);
if (blockEntity instanceof BlockEntityChest && !((BlockEntityChest) blockEntity).isPaired()) {
chest = (BlockEntityChest) blockEntity;
break;
}
}
}
this.getLevel().setBlock(block, this, true, true);
CompoundTag nbt = new CompoundTag("")
.putList(new ListTag<>("Items"))
.putString("id", BlockEntity.CHEST)
.putInt("x", (int) this.x)
.putInt("y", (int) this.y)
.putInt("z", (int) this.z);
if (item.hasCustomName()) {
nbt.putString("CustomName", item.getCustomName());
}
if (item.hasCustomBlockData()) {
Map<String, Tag> customData = item.getCustomBlockData().getTags();
for (Map.Entry<String, Tag> tag : customData.entrySet()) {
nbt.put(tag.getKey(), tag.getValue());
}
}
BlockEntity blockEntity = new BlockEntityChest(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
if (chest != null) {
chest.pairWith(((BlockEntityChest) blockEntity));
((BlockEntityChest) blockEntity).pairWith(chest);
}
return true;
}
@Override
public int getWeakPower(BlockFace face) {
int playerCount = 0;
BlockEntity blockEntity = this.level.getBlockEntity(this);
if (blockEntity instanceof BlockEntityChest) {
playerCount = ((BlockEntityChest) blockEntity).getInventory().getViewers().size();
}
return playerCount < 0 ? 0 : playerCount > 15 ? 15 : playerCount;
}
@Override
public int getStrongPower(BlockFace side) {
return side == BlockFace.UP ? this.getWeakPower(side) : 0;
}
@Override
public boolean isPowerSource() {
return true;
}
}
| 3,492 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockStairsQuartz.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockStairsQuartz.java | package cn.nukkit.block;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/11/25 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockStairsQuartz extends BlockStairs {
public BlockStairsQuartz() {
this(0);
}
public BlockStairsQuartz(int meta) {
super(meta);
}
@Override
public int getId() {
return QUARTZ_STAIRS;
}
@Override
public double getHardness() {
return 0.8;
}
@Override
public double getResistance() {
return 4;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public String getName() {
return "Quartz Stairs";
}
@Override
public BlockColor getColor() {
return BlockColor.QUARTZ_BLOCK_COLOR;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 950 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockBedrock.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockBedrock.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
/**
* author: Angelic47
* Nukkit Project
*/
public class BlockBedrock extends BlockSolid {
public BlockBedrock() {
}
@Override
public int getId() {
return BEDROCK;
}
@Override
public double getHardness() {
return -1;
}
@Override
public double getResistance() {
return 18000000;
}
@Override
public String getName() {
return "Bedrock";
}
@Override
public boolean isBreakable(Item item) {
return false;
}
@Override
public boolean canBePushed() {
return false;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 739 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockTripWire.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockTripWire.java | package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.entity.Entity;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemString;
import cn.nukkit.level.Level;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
/**
* @author CreeperFace
*/
public class BlockTripWire extends BlockFlowable {
public BlockTripWire(int meta) {
super(meta);
}
public BlockTripWire() {
this(0);
}
@Override
public int getId() {
return TRIPWIRE;
}
@Override
public String getName() {
return "Tripwire";
}
@Override
public boolean canPassThrough() {
return true;
}
@Override
public double getResistance() {
return 0;
}
@Override
public double getHardness() {
return 0;
}
@Override
public AxisAlignedBB getBoundingBox() {
return null;
}
@Override
public Item toItem() {
return new ItemString();
}
public boolean isPowered() {
return (this.getDamage() & 1) > 0;
}
public boolean isAttached() {
return (this.getDamage() & 4) > 0;
}
public boolean isDisarmed() {
return (this.getDamage() & 8) > 0;
}
public void setPowered(boolean value) {
if (value ^ this.isPowered()) {
this.setDamage(this.getDamage() ^ 0x01);
}
}
public void setAttached(boolean value) {
if (value ^ this.isAttached()) {
this.setDamage(this.getDamage() ^ 0x04);
}
}
public void setDisarmed(boolean value) {
if (value ^ this.isDisarmed()) {
this.setDamage(this.getDamage() ^ 0x08);
}
}
@Override
public void onEntityCollide(Entity entity) {
if (!entity.doesTriggerPressurePlate()) {
return;
}
boolean powered = this.isPowered();
if (!powered) {
this.setPowered(true);
this.level.setBlock(this, this, true, false);
this.updateHook(false);
this.level.scheduleUpdate(this, 10);
}
}
public void updateHook(boolean scheduleUpdate) {
for (BlockFace side : new BlockFace[]{BlockFace.SOUTH, BlockFace.WEST}) {
for (int i = 1; i < 42; ++i) {
Block block = this.getSide(side, i);
if (block instanceof BlockTripWireHook) {
BlockTripWireHook hook = (BlockTripWireHook) block;
if (hook.getFacing() == side.getOpposite()) {
hook.calculateState(false, true, i, this);
}
/*if(scheduleUpdate) {
this.level.scheduleUpdate(hook, 10);
}*/
break;
}
if (block.getId() != Block.TRIPWIRE) {
break;
}
}
}
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_SCHEDULED) {
if (!isPowered()) {
return type;
}
boolean found = false;
for (Entity entity : this.level.getCollidingEntities(this.getCollisionBoundingBox())) {
if (!entity.doesTriggerPressurePlate()) {
continue;
}
found = true;
}
if (found) {
this.level.scheduleUpdate(this, 10);
} else {
this.setPowered(false);
this.level.setBlock(this, this, true, false);
this.updateHook(false);
}
return type;
}
return 0;
}
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
this.getLevel().setBlock(this, this, true, true);
this.updateHook(false);
return true;
}
@Override
public boolean onBreak(Item item) {
if (item.getId() == Item.SHEARS) {
this.setDisarmed(true);
this.level.setBlock(this, this, true, false);
this.updateHook(false);
this.getLevel().setBlock(this, new BlockAir(), true, true);
} else {
this.setPowered(true);
this.getLevel().setBlock(this, new BlockAir(), true, true);
this.updateHook(true);
}
return true;
}
@Override
public double getMaxY() {
return this.y + 0.5;
}
@Override
protected AxisAlignedBB recalculateCollisionBoundingBox() {
return this;
}
}
| 4,668 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockDoorWood.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockDoorWood.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemDoorWood;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* author: MagicDroidX
* Nukkit Project
*/
public class BlockDoorWood extends BlockDoor {
public BlockDoorWood() {
this(0);
}
public BlockDoorWood(int meta) {
super(meta);
}
@Override
public String getName() {
return "Wood Door Block";
}
@Override
public int getId() {
return WOOD_DOOR_BLOCK;
}
@Override
public double getHardness() {
return 3;
}
@Override
public double getResistance() {
return 15;
}
@Override
public int getToolType() {
return ItemTool.TYPE_AXE;
}
@Override
public Item toItem() {
return new ItemDoorWood();
}
@Override
public BlockColor getColor() {
return BlockColor.WOOD_BLOCK_COLOR;
}
}
| 955 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockNetherrack.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockNetherrack.java | package cn.nukkit.block;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.utils.BlockColor;
/**
* Created on 2015/12/26 by Pub4Game.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockNetherrack extends BlockSolid {
public BlockNetherrack() {
}
@Override
public int getId() {
return NETHERRACK;
}
@Override
public double getResistance() {
return 2;
}
@Override
public double getHardness() {
return 0.4;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public String getName() {
return "Netherrack";
}
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
return new Item[]{
toItem()
};
} else {
return new Item[0];
}
}
@Override
public BlockColor getColor() {
return BlockColor.NETHERRACK_BLOCK_COLOR;
}
@Override
public boolean canHarvestWithHand() {
return false;
}
}
| 1,159 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
BlockFenceGateSpruce.java | /FileExtraction/Java_unseen/Nukkit_Nukkit/src/main/java/cn/nukkit/block/BlockFenceGateSpruce.java | package cn.nukkit.block;
/**
* Created on 2015/11/23 by xtypr.
* Package cn.nukkit.block in project Nukkit .
*/
public class BlockFenceGateSpruce extends BlockFenceGate {
public BlockFenceGateSpruce() {
this(0);
}
public BlockFenceGateSpruce(int meta) {
super(meta);
}
@Override
public int getId() {
return FENCE_GATE_SPRUCE;
}
@Override
public String getName() {
return "Spruce Fence Gate";
}
}
| 475 | Java | .java | Nukkit/Nukkit | 821 | 272 | 171 | 2015-05-23T09:51:41Z | 2024-03-21T12:28:05Z |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.