Java Code Examples for org.bukkit.Material#values()

The following examples show how to use org.bukkit.Material#values() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DuctListener.java    From Transport-Pipes with MIT License 6 votes vote down vote up
@Inject
public DuctListener(ItemService itemService, JavaPlugin plugin, DuctRegister ductRegister, GlobalDuctManager globalDuctManager, TPContainerListener tpContainerListener, GeneralConf generalConf, SentryService sentry, TransportPipes transportPipes, ThreadService threadService, PlayerSettingsService playerSettingsService) {
    this.itemService = itemService;
    this.ductRegister = ductRegister;
    this.globalDuctManager = globalDuctManager;
    this.tpContainerListener = tpContainerListener;
    this.generalConf = generalConf;
    this.sentry = sentry;
    this.transportPipes = transportPipes;
    this.threadService = threadService;
    this.playerSettingsService = playerSettingsService;

    for (Material m : Material.values()) {
        if (m.isInteractable()) {
            interactables.add(m);
        }
    }

    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::updateInteractSet, 0L, 1L);
}
 
Example 2
Source File: BurgerHelper.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
public static Map<Integer,Material> mapIds() {
if (typeIdMethod == null) {
	throw new IllegalStateException("requires Minecraft 1.12.2 or older");
}
  	
  	Map<Integer,Material> ids = new HashMap<>();
  	for (Material mat : Material.values()) {
  		try {
		ids.put((int) typeIdMethod.invokeExact(mat), mat);
	} catch (Throwable e) {
		throw new RuntimeException(e);
	}
  	}
  	
  	return ids;
  }
 
Example 3
Source File: ImportManager.java    From Statz with GNU General Public License v3.0 6 votes vote down vote up
private void importItemsDropped(PlayerInfo playerInfo, String worldName) {
    Optional<JSONObject> object = getCustomSection(playerInfo.getUUID(), worldName);

    if (!object.isPresent()) {
        return;
    }

    Optional<JSONObject> droppedSection = getDroppedSection(playerInfo.getUUID(), worldName);

    if (!droppedSection.isPresent()) return;

    for (Material material : Material.values()) {
        long dropped = (Long) getStatistic(droppedSection.get(), material.getKey().toString()).orElse(0L);

        if (dropped <= 0) continue;

        playerInfo.addRow(PlayerStat.ITEMS_DROPPED,
                StatzUtil.makeQuery(playerInfo.getUUID(), "value", dropped, "world",
                        worldName, "item", material));
    }
}
 
Example 4
Source File: ImportManager.java    From Statz with GNU General Public License v3.0 6 votes vote down vote up
private void importBlocksPlaced(PlayerInfo playerInfo, String worldName) {
    Optional<JSONObject> object = getCustomSection(playerInfo.getUUID(), worldName);

    if (!object.isPresent()) {
        return;
    }

    Optional<JSONObject> placedSection = getUsedSection(playerInfo.getUUID(), worldName);

    if (!placedSection.isPresent()) return;

    for (Material material : Material.values()) {
        if (material.isBlock()) {

            long placed = (Long) getStatistic(placedSection.get(), material.getKey().toString()).orElse(0L);

            if (placed <= 0) continue;

            playerInfo.addRow(PlayerStat.BLOCKS_PLACED,
                    StatzUtil.makeQuery(playerInfo.getUUID(), "value", placed, "world",
                            worldName, "block", material));
        }
    }
}
 
Example 5
Source File: ImportManager.java    From Statz with GNU General Public License v3.0 6 votes vote down vote up
private void importBlocksBroken(PlayerInfo playerInfo, String worldName) {
    Optional<JSONObject> object = getCustomSection(playerInfo.getUUID(), worldName);

    if (!object.isPresent()) {
        return;
    }

    Optional<JSONObject> minedSection = getMinedSection(playerInfo.getUUID(), worldName);

    if (!minedSection.isPresent()) return;

    for (Material material : Material.values()) {
        if (material.isBlock()) {

            long broken = (Long) getStatistic(minedSection.get(), material.getKey().toString()).orElse(0L);

            if (broken <= 0) continue;

            playerInfo.addRow(PlayerStat.BLOCKS_BROKEN,
                    StatzUtil.makeQuery(playerInfo.getUUID(), "value", broken, "world",
                            worldName, "block", material));
        }
    }
}
 
Example 6
Source File: ImportManager.java    From Statz with GNU General Public License v3.0 6 votes vote down vote up
private void importFoodEaten(PlayerInfo playerInfo, String worldName) {
    Optional<JSONObject> object = getCustomSection(playerInfo.getUUID(), worldName);

    if (!object.isPresent()) {
        return;
    }

    Optional<JSONObject> foodSection = getUsedSection(playerInfo.getUUID(), worldName);

    if (!foodSection.isPresent()) return;

    for (Material material : Material.values()) {
        if (material.isEdible()) {

            long eaten = (Long) getStatistic(foodSection.get(), material.getKey().toString()).orElse(0L);

            if (eaten <= 0) continue;

            playerInfo.addRow(PlayerStat.FOOD_EATEN,
                    StatzUtil.makeQuery(playerInfo.getUUID(), "value", eaten, "world",
                            worldName, "foodEaten", material));
        }
    }
}
 
Example 7
Source File: ImportManager.java    From Statz with GNU General Public License v3.0 6 votes vote down vote up
private void importToolsBroken(PlayerInfo playerInfo, String worldName) {
    Optional<JSONObject> object = getCustomSection(playerInfo.getUUID(), worldName);

    if (!object.isPresent()) {
        return;
    }

    Optional<JSONObject> brokenSection = getBrokenSection(playerInfo.getUUID(), worldName);

    if (!brokenSection.isPresent()) return;

    for (Material material : Material.values()) {
        if (material.isItem()) {

            long broken = (Long) getStatistic(brokenSection.get(), material.getKey().toString()).orElse(0L);

            if (broken <= 0) continue;

            playerInfo.addRow(PlayerStat.TOOLS_BROKEN,
                    StatzUtil.makeQuery(playerInfo.getUUID(), "value", broken, "world",
                            worldName, "item", material));
        }
    }
}
 
Example 8
Source File: FuelModelTest.java    From GlobalWarming with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void fuelModelContainsAllMaterials() {
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    FuelModel model = new FuelModel(gson, "world");
    Map<Material, Double> existingFuelMap = model.getFuelMap();
    for (Material material : Material.values()) {
        if (material.isFuel()) {
            Assert.assertTrue(existingFuelMap.containsKey(material), material.name());
        }
    }
}
 
Example 9
Source File: BlockSelector.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return material
 * <p>
 * If we match multiple materials we will return the first match
 */
public Material getMaterial() {
    for (Material m : Material.values()) {
        if (match(m)) {
            return m;
        }
    }
    return null;
}
 
Example 10
Source File: MaterialDataMatcher.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
private Material matchMaterialByName(String name) {
	name = name.replace("_", "");
	
	for (Material material : Material.values()) {
		String materialName = material.name().replace("_", "");
		
		if (name.equalsIgnoreCase(materialName)) {
			return material;
		}
	}
	
	return null;
}
 
Example 11
Source File: CompatibilityUtils.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets material by id
 *
 * @param id id
 * @return material enum
 */
public static Material getMaterial(int id) {
	for(Material material : Material.values()) {
		if(material.getId() == id) {
			return material;
		}
	}

	return null;
}
 
Example 12
Source File: ItemDatabase.java    From SaneEconomy with GNU General Public License v3.0 5 votes vote down vote up
private static Optional<Material> parseMaterialFromName(String materialName) {
    for (Material mat : Material.values()) {
        if (normalizeItemName(mat.name()).equals(normalizeItemName(materialName))) {
            return Optional.of(mat);
        }
    }

    return Optional.empty();
}
 
Example 13
Source File: AliasesMap.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Clears all data from this aliases map.
 */
public void clear() {
	materialEntries = new MaterialEntry[Material.values().length];
	for (int i = 0; i < materialEntries.length; i++) {
		materialEntries[i] = new MaterialEntry();
	}
}
 
Example 14
Source File: BurgerHelper.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
public Map<String,Material> mapMaterials() {
	Map<String,Material> materials = new HashMap<>();
	
	// Check all existing materials
       for (Material material : Material.values()) {
       	// Get id
		int id;
		try {
			id = (int) typeIdMethod.invokeExact(material);
		} catch (Throwable e) {
			throw new RuntimeException(e);
		}
		
		// Search in blocks
           String vanillaId = null;
           for (ItemOrBlock item : burger.items.item.values()) {
               if (item.numeric_id == id) {
                   vanillaId = item.text_id;
                   break;
               }
           }
           
           // Search in items
           for (ItemOrBlock block : burger.blocks.block.values()) {
               if (block.numeric_id == id) {
                   vanillaId = block.text_id;
                   break;
               }
           }
           
           materials.put(vanillaId, material);
       }
       
       return materials;
}
 
Example 15
Source File: MsgUtil.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Load Itemi18n fron file
 */
public static void loadItemi18n() {
    plugin.getLogger().info("Starting loading items translation...");
    File itemi18nFile = new File(plugin.getDataFolder(), "itemi18n.yml");
    if (!itemi18nFile.exists()) {
        plugin.getLogger().info("Creating itemi18n.yml");
        plugin.saveResource("itemi18n.yml", false);
    }
    // Store it
    itemi18n = YamlConfiguration.loadConfiguration(itemi18nFile);
    itemi18n.options().copyDefaults(false);
    YamlConfiguration itemi18nYAML =
            YamlConfiguration.loadConfiguration(
                    new InputStreamReader(Objects.requireNonNull(plugin.getResource("itemi18n.yml"))));
    itemi18n.setDefaults(itemi18nYAML);
    Util.parseColours(itemi18n);
    Material[] itemsi18n = Material.values();
    for (Material material : itemsi18n) {
        String itemi18nString = itemi18n.getString("itemi18n." + material.name());
        if (itemi18nString != null && !itemi18nString.isEmpty()) {
            continue;
        }
        String itemName = gameLanguage.getItem(material);
        itemi18n.set("itemi18n." + material.name(), itemName);
        plugin
                .getLogger()
                .info("Found new items/blocks [" + itemName + "] , adding it to the config...");
    }
    try {
        itemi18n.save(itemi18nFile);
    } catch (IOException e) {
        e.printStackTrace();
        plugin
                .getLogger()
                .log(
                        Level.WARNING,
                        "Could not load/save transaction itemname from itemi18n.yml. Skipping.");
    }
    plugin.getLogger().info("Complete to load items translation.");
}
 
Example 16
Source File: ImportManager.java    From Statz with GNU General Public License v3.0 4 votes vote down vote up
private void importItemsCrafted(PlayerInfo playerInfo, String worldName) {

        Optional<JSONObject> object = getCustomSection(playerInfo.getUUID(), worldName);

        if (!object.isPresent()) {
            return;
        }

        Optional<JSONObject> craftedSection = getCraftedSection(playerInfo.getUUID(), worldName);

        if (!craftedSection.isPresent()) return;

        for (Material material : Material.values()) {
            if (material.isItem()) {

                long itemsCrafted = (Long) getStatistic(craftedSection.get(), material.getKey().toString()).orElse(0L);

                if (itemsCrafted <= 0) continue;

                playerInfo.addRow(PlayerStat.ITEMS_CRAFTED,
                        StatzUtil.makeQuery(playerInfo.getUUID(), "value", itemsCrafted, "world",
                                worldName, "item", material));
            }
        }
    }
 
Example 17
Source File: MaterialRegistry.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new material registry.
 */
public MaterialRegistry() {
	this(Material.values());
}
 
Example 18
Source File: ImportManager.java    From Statz with GNU General Public License v3.0 4 votes vote down vote up
private void importItemsPickedUp(PlayerInfo playerInfo, String worldName) {
    Optional<JSONObject> object = getCustomSection(playerInfo.getUUID(), worldName);

    if (!object.isPresent()) {
        return;
    }

    Optional<JSONObject> pickedUpSection = getPickedUpSection(playerInfo.getUUID(), worldName);

    if (!pickedUpSection.isPresent()) return;

    for (Material material : Material.values()) {

        long pickedUp = (Long) getStatistic(pickedUpSection.get(), material.getKey().toString()).orElse(0L);

        if (pickedUp <= 0) continue;

        playerInfo.addRow(PlayerStat.ITEMS_PICKED_UP,
                StatzUtil.makeQuery(playerInfo.getUUID(), "value", pickedUp, "world",
                        worldName, "item", material));
    }
}
 
Example 19
Source File: ExprItems.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
@Nullable
public Iterator<ItemStack> iterator(final Event e) {
	Iterator<ItemStack> iter;
	if (types == null) {
		iter = new Iterator<ItemStack>() {
			
			private final Iterator<Material> iter = new ArrayIterator<>(Material.values());
			
			@Override
			public boolean hasNext() {
				return iter.hasNext();
			}
			
			@Override
			public ItemStack next() {
				return new ItemStack(iter.next());
			}
			
			@Override
			public void remove() {}
			
		};
	} else {
		@SuppressWarnings("null")
		final Iterator<ItemType> it = new ArrayIterator<>(types.getArray(e));
		if (!it.hasNext())
			return null;
		iter = new Iterator<ItemStack>() {
			
			@SuppressWarnings("null")
			Iterator<ItemStack> current = it.next().getAll().iterator();
			
			@SuppressWarnings("null")
			@Override
			public boolean hasNext() {
				while (!current.hasNext() && it.hasNext()) {
					current = it.next().getAll().iterator();
				}
				return current.hasNext();
			}
			
			@SuppressWarnings("null")
			@Override
			public ItemStack next() {
				if (!hasNext())
					throw new NoSuchElementException();
				return current.next();
			}
			
			@Override
			public void remove() {}
			
		};
	}
	
	if (!blocks)
		return iter;
	
	return new CheckedIterator<>(iter, new NullableChecker<ItemStack>() {
		@Override
		public boolean check(final @Nullable ItemStack is) {
			return is != null && is.getType().isBlock();
		}
	});
}
 
Example 20
Source File: ASkyBlock.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Registers events
 */
public void registerEvents() {
    final PluginManager manager = getServer().getPluginManager();
    // Nether portal events
    manager.registerEvents(new NetherPortals(this), this);
    // Nether spawning events
    manager.registerEvents(new NetherSpawning(this), this);
    // Island Protection events
    manager.registerEvents(new IslandGuard(this), this);
    // Island Entity Limits
    entityLimits = new EntityLimits(this);
    manager.registerEvents(entityLimits, this);
    // Player events
    playerEvents = new PlayerEvents(this);
    manager.registerEvents(playerEvents, this);
    try {
        Class<?> clazz = Class.forName("org.bukkit.event.entity.EntityPickupItemEvent", false, getClassLoader());
        if (clazz != null) {
            manager.registerEvents(new PlayerEvents3(this), this);
        }
    } catch (ClassNotFoundException e) {
        manager.registerEvents(new PlayerEvents2(this), this);
    }
    // New V1.8 events
    if (onePointEight) {
        manager.registerEvents(new IslandGuard1_8(this), this);
    }
    // Check for 1.9 material
    for (Material m : Material.values()) {
        if (m.name().equalsIgnoreCase("END_CRYSTAL")) {
            manager.registerEvents(new IslandGuard1_9(this), this);
            break;
        }
    }
    // Events for when a player joins or leaves the server
    manager.registerEvents(new JoinLeaveEvents(this), this);
    // Ensures Lava flows correctly in ASkyBlock world
    lavaListener = new LavaCheck(this);
    manager.registerEvents(lavaListener, this);
    // Ensures that water is acid
    manager.registerEvents(new AcidEffect(this), this);
    // Ensures that boats are safe in ASkyBlock
    if (Settings.acidDamage > 0D) {
        manager.registerEvents(new SafeBoat(this), this);
    }
    // Enables warp signs in ASkyBlock
    warpSignsListener = new WarpSigns(this);
    manager.registerEvents(warpSignsListener, this);
    // Control panel - for future use
    // manager.registerEvents(new ControlPanel(), this);
    // Change names of inventory items
    //manager.registerEvents(new AcidInventory(this), this);
    // Schematics panel
    schematicsPanel = new SchematicsPanel(this);
    manager.registerEvents(schematicsPanel, this);
    // Track incoming world teleports
    manager.registerEvents(new WorldEnter(this), this);
    // Team chat
    chatListener = new ChatListener(this);
    manager.registerEvents(chatListener, this);
    // Wither
    if (Settings.restrictWither) {
        manager.registerEvents(new FlyingMobEvents(this), this);
    }
    if (Settings.recoverSuperFlat) {
        manager.registerEvents(new CleanSuperFlat(), this);
    }
}