mirror of
https://github.com/darksaid98/Builders-Utilities.git
synced 2026-12-02 06:28:53 +00:00
Little cleanup & setup (#4)
* Setup project * Update namespace - Relocate bstats * Some reformatting and documentation * Setup issue templates * chmod+x gradlew * Create pull request template * Apply license * Exclude XMaterial from licensing
This commit is contained in:
1 parent
f763d4c472
commit
9806a083bc
129 files changed
+5068
-1506
No files matched your search
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* ____ _ _ _ _ _ _ _ _ _ _ _
|
||||
* | _ \ (_) | | | | | | | | (_) (_) | (_)
|
||||
* | |_) |_ _ _| | __| | ___ _ __ ___ ______| | | | |_ _| |_| |_ _ ___ ___
|
||||
* | _ <| | | | | |/ _` |/ _ \ '__/ __|______| | | | __| | | | __| |/ _ \/ __|
|
||||
* | |_) | |_| | | | (_| | __/ | \__ \ | |__| | |_| | | | |_| | __/\__ \
|
||||
* |____/ \__,_|_|_|\__,_|\___|_| |___/ \____/ \__|_|_|_|\__|_|\___||___/
|
||||
*
|
||||
* Builder's Utilities is a collection of a lot of tiny features that help with building.
|
||||
* Copyright (C) 2020 Arcaniax
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.arcaniax.buildersutilities.utils;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Items {
|
||||
|
||||
public static ItemStack create(Material mat, String name, String lore) {
|
||||
return Items.create(mat, (short) 0, 1, name, lore);
|
||||
}
|
||||
|
||||
public static ItemStack create(Material mat, short data, int amount, String name, String lore) {
|
||||
ItemStack is = new ItemStack(mat);
|
||||
is.setAmount(amount);
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
if (!lore.equals("")) {
|
||||
String[] loreListArray = lore.split("__");
|
||||
List<String> loreList = new ArrayList<>();
|
||||
for (String s : loreListArray) {
|
||||
loreList.add(s.replace('&', ChatColor.COLOR_CHAR));
|
||||
}
|
||||
meta.setLore(loreList);
|
||||
}
|
||||
if (!name.equals("")) {
|
||||
meta.setDisplayName(name.replace('&', ChatColor.COLOR_CHAR));
|
||||
}
|
||||
is.setItemMeta(meta);
|
||||
is.setDurability(data);
|
||||
return is;
|
||||
}
|
||||
|
||||
public static ItemStack color(ItemStack is, int r, int g, int b) {
|
||||
LeatherArmorMeta lam = (LeatherArmorMeta) is.getItemMeta();
|
||||
Color c = Color.fromRGB(r, g, b);
|
||||
lam.setColor(c);
|
||||
is.setItemMeta(lam);
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
public static ItemStack createHead(String data, int amount, String name, String lore) {
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
item.setAmount(amount);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (!lore.equals("")) {
|
||||
String[] loreListArray = lore.split("__");
|
||||
List<String> loreList = new ArrayList<>();
|
||||
for (String s : loreListArray) {
|
||||
loreList.add(s.replace('&', ChatColor.COLOR_CHAR));
|
||||
}
|
||||
meta.setLore(loreList);
|
||||
}
|
||||
if (!name.equals("")) {
|
||||
meta.setDisplayName(name.replace('&', ChatColor.COLOR_CHAR));
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
SkullMeta headMeta = (SkullMeta) item.getItemMeta();
|
||||
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
|
||||
profile.getProperties().put("textures", new Property("textures", data));
|
||||
Field profileField;
|
||||
try {
|
||||
profileField = headMeta.getClass().getDeclaredField("profile");
|
||||
profileField.setAccessible(true);
|
||||
profileField.set(headMeta, profile);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
item.setItemMeta(headMeta);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user