145 lines
4.2 KiB
Java
145 lines
4.2 KiB
Java
/*
|
|
* Copyright (c) 2017 univento.eu - All rights reserved
|
|
* You are not allowed to use, distribute or modify this code
|
|
*/
|
|
|
|
package eu.univento.core.api.blocks.banners;
|
|
|
|
import org.bukkit.block.Banner;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
|
|
/**
|
|
* @author tschuliaehn
|
|
* @version 1.0
|
|
*/
|
|
|
|
public class BannerString {
|
|
private HashMap<Integer, Banner> bannerSequence;
|
|
private boolean autoClear = true;
|
|
private BannerColor clearColor = BannerColor.WHITE;
|
|
private BannerColor standardForegroundColor = BannerColor.NORMAL_FOREGROUND;
|
|
private BannerColor standardBackgroundColor = BannerColor.NORMAL_BACKGROUND;
|
|
|
|
public BannerString() {
|
|
this(new HashMap<>());
|
|
}
|
|
|
|
public BannerString(ArrayList<Banner> banners) {
|
|
this.bannerSequence = new HashMap<>();
|
|
for (int i = 0; i < banners.size(); i++) {
|
|
this.bannerSequence.put(i, banners.get(i));
|
|
}
|
|
}
|
|
|
|
public BannerString(HashMap<Integer, Banner> bannerSequence) {
|
|
this.bannerSequence = bannerSequence;
|
|
}
|
|
|
|
public void insertNextBanner(Banner banner) {
|
|
Iterator<Integer> iterator = this.bannerSequence.keySet().iterator();
|
|
int last = 0;
|
|
while (iterator.hasNext()) {
|
|
last = iterator.next();
|
|
}
|
|
this.bannerSequence.put(++last, banner);
|
|
}
|
|
|
|
public void draw(String text) {
|
|
draw(text, 0, 0);
|
|
}
|
|
|
|
public void draw(String text, int skip) {
|
|
draw(text, skip, 0);
|
|
}
|
|
|
|
public void draw(String text, int skip, int ending) {
|
|
if (this.autoClear) {
|
|
clear();
|
|
}
|
|
char[] chars = text.toCharArray();
|
|
|
|
Collection<Banner> values = this.bannerSequence.values();
|
|
Banner[] banners = values.toArray(new Banner[this.bannerSequence.values().size()]);
|
|
|
|
BannerColor inUseForeground = this.standardForegroundColor;
|
|
BannerColor inUseBackground = this.standardBackgroundColor;
|
|
|
|
int i = skip;
|
|
for (int counter = 0; i < banners.length - ending; ) {
|
|
if (counter == chars.length) {
|
|
return;
|
|
}
|
|
Banner banner = banners[i];
|
|
char pointed = chars[counter];
|
|
if ((pointed == '§') && (chars.length > counter + 3)) {
|
|
char whichSide = chars[(counter + 1)];
|
|
BannerColor color = BannerColor.translate(chars[(counter + 2)]);
|
|
if (whichSide == 'F') {
|
|
inUseForeground = color;
|
|
counter += 3;
|
|
continue;
|
|
}
|
|
if (whichSide == 'B') {
|
|
inUseBackground = color;
|
|
counter += 3;
|
|
continue;
|
|
}
|
|
}
|
|
ShapeRegistry.paint(Character.toUpperCase(pointed), banner, inUseForeground.getColor(), inUseBackground.getColor());
|
|
banner.update();
|
|
counter++;
|
|
i++;
|
|
}
|
|
}
|
|
|
|
public void setAutoClear(boolean autoClear) {
|
|
this.autoClear = autoClear;
|
|
}
|
|
|
|
public void setClearColor(BannerColor clearColor) {
|
|
this.clearColor = clearColor;
|
|
}
|
|
|
|
public void setStandardForegroundColor(BannerColor standardForegroundColor) {
|
|
this.standardForegroundColor = standardForegroundColor;
|
|
}
|
|
|
|
public void setStandardBackgroundColor(BannerColor standardBackgroundColor) {
|
|
this.standardBackgroundColor = standardBackgroundColor;
|
|
}
|
|
|
|
public void clear() {
|
|
Iterator<Banner> iterator = this.bannerSequence.values().iterator();
|
|
while (iterator.hasNext()) {
|
|
Banner banner = (Banner) iterator.next();
|
|
banner.setPatterns(new ArrayList());
|
|
banner.setBaseColor(this.clearColor.getColor());
|
|
banner.update();
|
|
}
|
|
}
|
|
|
|
public HashMap<Integer, Banner> getBannerSequence() {
|
|
return this.bannerSequence;
|
|
}
|
|
|
|
public boolean isAutoClear() {
|
|
return this.autoClear;
|
|
}
|
|
|
|
public BannerColor getClearColor() {
|
|
return this.clearColor;
|
|
}
|
|
|
|
public BannerColor getStandardForegroundColor() {
|
|
return this.standardForegroundColor;
|
|
}
|
|
|
|
public BannerColor getStandardBackgroundColor() {
|
|
return this.standardBackgroundColor;
|
|
}
|
|
}
|