下面列出了怎么用org.bukkit.DyeColor的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Wool and Dye. But Dye is not a block itself.
*/
public static DyeColor getColor(Block block) {
if (XMaterial.ISFLAT) {
if (!(block.getBlockData() instanceof Colorable)) return null;
Colorable colorable = (Colorable) block.getBlockData();
return colorable.getColor();
}
BlockState state = block.getState();
MaterialData data = state.getData();
if (data instanceof Wool) {
Wool wool = (Wool) data;
return wool.getColor();
}
return null;
}
public ItemBuilder addPattern(String stringPattern) {
try {
String[] split = stringPattern.split(":");
for (PatternType pattern : PatternType.values()) {
if (split[0].equalsIgnoreCase(pattern.name()) || split[0].equalsIgnoreCase(pattern.getIdentifier())) {
DyeColor color = getDyeColor(split[1]);
if (color != null) {
addPattern(new Pattern(color, pattern));
}
break;
}
}
} catch (Exception e) {
}
return this;
}
/**
* Creates an instance.
*
* @since 5.7.1
* @param collarColor The collar is invisible unless the state is {@link State#TAMED}.
*/
public WolfDisguise(boolean adult, State state, DyeColor collarColor, boolean sitting) {
super(DisguiseType.WOLF, adult);
this.state = state;
this.collarColor = collarColor;
this.sitting = sitting;
}
private static DyeColor getDyeColor(String color) {
if (color != null) {
try {
return DyeColor.valueOf(color.toUpperCase());
} catch (Exception e) {
try {
String[] rgb = color.split(",");
return DyeColor.getByColor(Color.fromRGB(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2])));
} catch (Exception ignore) {
}
}
}
return null;
}
@Override
public String serialize(BannerMeta bannerMeta) {
if(bannerMeta == null) {
return "";
}
StringBuilder builder = new StringBuilder();
builder.append((bannerMeta.getBaseColor() == null ? DyeColor.BLACK : bannerMeta.getBaseColor()).name());
if(bannerMeta.numberOfPatterns() > 0) {
builder.append(':');
}
int index = 1;
for(Pattern pattern : bannerMeta.getPatterns()) {
builder.append(pattern.getColor().name());
builder.append('-');
builder.append(pattern.getPattern().getIdentifier());
if(index < bannerMeta.numberOfPatterns()) {
builder.append("|");
}
index++;
}
return builder.toString();
}
/**
* Creates a GUI button made of a wool.
*
* @param dc
* @param name
* @return
*/
public static ItemStack createButton(DyeColor dc, String name) {
ItemStack i = new Wool(dc).toItemStack(1);
ItemMeta im = i.getItemMeta();
im.setDisplayName(name);
i.setItemMeta(im);
return i;
}
public Team getTeamByDyeColor(DyeColor color) {
for (Team t : this.teams.values()) {
if (t.getColor().getDyeColor().equals(color)) {
return t;
}
}
return null;
}
private short getSubItemData(Ocelot.Type catType) {
switch (catType) {
case BLACK_CAT:
return DyeColor.BLACK.getWoolData();
case RED_CAT:
return DyeColor.RED.getWoolData();
case SIAMESE_CAT:
return DyeColor.SILVER.getWoolData();
case WILD_OCELOT:
default:
return DyeColor.ORANGE.getWoolData();
}
}
@Override
public void setCollarColor(DyeColor dc) {
if (((IWolfPet) pet).isTamed()) {
byte colour = dc.getWoolData();
this.datawatcher.watch(20, colour);
}
}
@Override
public void cycleSubType() {
byte colorByte = color.getWoolData();
colorByte += 1;
color = DyeColor.getByWoolData(colorByte);
if (color == null) {
color = DyeColor.WHITE;
}
this.applySubType();
}
/**
* Returns the GroupColor matching the DyeColor or null if none exists.
*
* @param color the DyeColor to check
* @return the GroupColor matching the DyeColor or null if none exists.
*/
public static Color getByDyeColor(DyeColor color) {
for (Color groupColor : values()) {
if (groupColor.dye == color) {
return groupColor;
}
}
return null;
}
public static DyeColor parseDyeColor(Attribute attr) throws InvalidXMLException {
String name = attr.getValue().replace(" ", "_").toUpperCase();
try {
return DyeColor.valueOf(name);
}
catch(IllegalArgumentException e) {
throw new InvalidXMLException("Invalid dye color '" + attr.getValue() + "'", attr);
}
}
public void spawn() {
Sheep sheep = (Sheep) loc.getWorld().spawnEntity(loc, EntityType.SHEEP);
TeamColor color = TeamColor.fromApiColor(team.getColor());
Player target = MiscUtils.findTarget(game, player, maxTargetDistance);
sheep.setColor(DyeColor.getByWoolData((byte) color.woolData));
if (target == null) {
player.sendMessage(i18n("specials_tntsheep_no_target_found"));
sheep.remove();
return;
}
entity = sheep;
EntityUtils.makeMobAttackTarget(sheep, speed, followRange, 0)
.getTargetSelector().attackTarget(target);
tnt = (TNTPrimed) loc.getWorld().spawnEntity(loc, EntityType.PRIMED_TNT);
tnt.setFuseTicks(explosionTime);
tnt.setIsIncendiary(false);
sheep.addPassenger(tnt);
game.registerSpecialItem(this);
Main.registerGameEntity(sheep, (org.screamingsandals.bedwars.game.Game) game);
Main.registerGameEntity(tnt, (org.screamingsandals.bedwars.game.Game) game);
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
} else {
player.getInventory().remove(item);
}
player.updateInventory();
new BukkitRunnable() {
@Override
public void run() {
tnt.remove();
sheep.remove();
game.unregisterSpecialItem(TNTSheep.this);
}
}.runTaskLater(Main.getInstance(), (explosionTime + 13));
}
public static StainedClayItemData create(DyeColor color) {
return create(color, Bukkit.getItemFactory().getItemMeta(Material.STAINED_CLAY));
}
@Override
public DyeColor getCollarColor() {
return this.collar;
}
private boolean testDestroy(Player player, DyeColor dye) {
TeamModule team = Teams.getTeamByPlayer(player).orNull();
return team != null && GameHandler.getGameHandler().getMatch().getModules().getModules(WoolObjective.class)
.stream().anyMatch(wool -> wool.getTeam() != team && !wool.isComplete() && wool.getColor().equals(dye)
&& !(destroyed.containsKey(player) && destroyed.get(player).contains(dye)));
}
public static String makeName(DyeColor color) {
return makeColorName(color) + " Wool";
}
public static Component makeComponentName(DyeColor color) {
return TextComponent.of(
makeName(color), TextFormatter.convert((BukkitUtils.dyeColorToChatColor(color))));
}
public DyeColor getColor() {
return this.color;
}
@SuppressWarnings("deprecation")
private static boolean isValidWool(DyeColor expectedColor, BlockState state) {
return state.getType() == Material.WOOL && expectedColor.getWoolData() == state.getRawData();
}
public DyeColor getDyeColor() {
return this.definition.getColor();
}
@Override
public DyeColor getDyeColor() {
return DyeColor.WHITE;
}
@Override
public DyeColor getDyeColor() {
return owner != null ? BukkitUtils.chatColorToDyeColor(owner.getColor()) : DyeColor.WHITE;
}
public CutCleanListener(){
Dye d = new Dye();
d.setColor(DyeColor.BLUE);
this.lapis = d.toItemStack();
this.lapis.setAmount(64);
}
public FlagDefinition(
@Nullable String id,
@Nullable String name,
@Nullable Boolean required,
boolean visible,
@Nullable DyeColor color,
Post defaultPost,
ImmutableList<Post> posts,
@Nullable FeatureReference<TeamFactory> owner,
double pointsPerCapture,
double pointsPerSecond,
Filter pickupFilter,
Filter captureFilter,
@Nullable Kit pickupKit,
@Nullable Kit dropKit,
@Nullable Kit carryKit,
boolean multiCarrier,
@Nullable Component carryMessage,
boolean dropOnWater,
boolean showBeam,
ProximityMetric flagProximityMetric,
ProximityMetric netProximityMetric,
boolean sequential) {
// We can't use the owner field in OwnedGoal because our owner
// is a reference that can't be resolved until after parsing.
super(
id,
makeName(name, color),
required,
visible,
null,
flagProximityMetric,
netProximityMetric);
this.color = color;
this.defaultPost = defaultPost;
this.posts = posts;
this.owner = owner;
this.pointsPerCapture = pointsPerCapture;
this.pointsPerSecond = pointsPerSecond;
this.pickupFilter = pickupFilter;
this.captureFilter = captureFilter;
this.pickupKit = pickupKit;
this.dropKit = dropKit;
this.carryKit = carryKit;
this.multiCarrier = multiCarrier;
this.carryMessage = carryMessage;
this.dropOnWater = dropOnWater;
this.showBeam = showBeam;
this.sequential = sequential;
}
@Override
public BannerMeta deserialize(String string) {
BannerMeta meta = (BannerMeta) Bukkit.getItemFactory().getItemMeta(CompatibilityUtils.Mat.WHITE_BANNER.get());
if(string == null || string.isEmpty()) {
return meta;
}
String baseColorString;
String patternsString;
if(StringUtils.contains(string, ':')) {
String[] baseSplit = StringUtils.split(string, ':');
baseColorString = baseSplit[0];
patternsString = baseSplit[1];
}
else {
baseColorString = string;
patternsString = "";
}
meta.setBaseColor(DyeColor.valueOf(baseColorString));
if(!patternsString.isEmpty()) {
String[] patternsSplit;
if(StringUtils.contains(patternsString, '|')) {
patternsSplit = StringUtils.split(patternsString, '|');
}
else {
patternsSplit = new String[]{
patternsString
};
}
for(String patternString : patternsSplit) {
String[] patternSplit = StringUtils.split(patternString, '-');
meta.addPattern(new Pattern(DyeColor.valueOf(patternSplit[0]), PatternType.getByIdentifier(patternSplit[1])));
}
}
return meta;
}
@Override
public void setCollarColor(DyeColor dc) {
if (((IWolfPet) pet).isTamed()) {
this.datawatcher.watch(20, Byte.valueOf((byte) (((int)dc.getWoolData()) & 15)));
}
}
@Override
public ITNTSheep spawnCreature(
final io.github.bedwarsrel.shop.Specials.TNTSheep specialItem,
final Location location, final Player owner, Player target, final DyeColor color) {
final TNTSheep sheep = new TNTSheep(location, target);
((CraftWorld) location.getWorld()).getHandle().addEntity(sheep, SpawnReason.NATURAL);
sheep.setPosition(location.getX(), location.getY(), location.getZ());
((CraftSheep) sheep.getBukkitEntity()).setColor(color);
new BukkitRunnable() {
@Override
public void run() {
TNTPrimed primedTnt = (TNTPrimed) location.getWorld()
.spawnEntity(location.add(0.0, 1.0, 0.0), EntityType.PRIMED_TNT);
((CraftSheep) sheep.getBukkitEntity()).setPassenger(primedTnt);
sheep.setTNT(primedTnt);
try {
Field sourceField = EntityTNTPrimed.class.getDeclaredField("source");
sourceField.setAccessible(true);
sourceField.set(((CraftTNTPrimed) primedTnt).getHandle(),
((CraftLivingEntity) owner).getHandle());
} catch (Exception ex) {
BedwarsRel.getInstance().getBugsnag().notify(ex);
ex.printStackTrace();
}
sheep.getTNT().setYield((float) (sheep.getTNT().getYield()
* BedwarsRel
.getInstance().getConfig().getDouble("specials.tntsheep.explosion-factor", 1.0)));
sheep.getTNT().setFuseTicks((int) Math.round(
BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.fuse-time", 8) * 20));
sheep.getTNT().setIsIncendiary(false);
specialItem.getGame().getRegion().addRemovingEntity(sheep.getTNT());
specialItem.getGame().getRegion().addRemovingEntity(sheep.getBukkitEntity());
specialItem.updateTNT();
}
}.runTaskLater(BedwarsRel.getInstance(), 5L);
return sheep;
}
@SuppressWarnings("deprecation")
@Override
public ItemStack b(EntityHuman entityhuman, int i) {
ItemStack itemstack = null;
Slot slot = (Slot) this.c.get(i);
if ((slot != null) && (slot.hasItem())) {
ItemStack itemstack1 = slot.getItem();
itemstack = itemstack1.cloneItemStack();
if (i == 0) {
if (!a(itemstack1, 2, 38, true)) {
return null;
}
} else if (i == 1) {
if (!this.a(itemstack1, 2, 38, true)) {
return null;
}
} else if (itemstack1.getItem() == Items.INK_SACK && DyeColor.getByData((byte) itemstack1.getData()) == DyeColor.BLUE) {
if (!this.a(itemstack1, 1, 2, true)) {
return null;
}
} else {
if ((((Slot) this.c.get(0)).hasItem()) || (!((Slot) this.c.get(0)).isAllowed(itemstack1))) {
return null;
}
if ((itemstack1.hasTag()) && (itemstack1.count == 1)) {
((Slot) this.c.get(0)).set(itemstack1.cloneItemStack());
itemstack1.count = 0;
} else if (itemstack1.count >= 1) {
((Slot) this.c.get(0)).set(new ItemStack(itemstack1.getItem(), 1, itemstack.getData()));
itemstack1.count -= 1;
}
}
if (itemstack1.count == 0) {
slot.set((ItemStack) null);
} else {
slot.f();
}
if (itemstack1.count == itemstack.count) {
return null;
}
slot.a(entityhuman, itemstack1);
}
return itemstack;
}
public DyeColor getPatternColor() {
return patternColor;
}