76 lines
2.3 KiB
Java
76 lines
2.3 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;
|
|
|
|
/**
|
|
* @author tschuliaehn
|
|
* @version 1.0
|
|
*/
|
|
|
|
public class FloatingText {
|
|
private String spacedText;
|
|
|
|
public FloatingText(String text, int between) {
|
|
StringBuilder builder = new StringBuilder();
|
|
for (int i = 0; i < between; i++) {
|
|
builder.append(" ");
|
|
}
|
|
builder.append(text);
|
|
this.spacedText = builder.toString();
|
|
}
|
|
|
|
private int pointer = -1;
|
|
private boolean start = true;
|
|
|
|
public String next() {
|
|
this.pointer += 1;
|
|
|
|
int index = this.spacedText.length() - this.pointer;
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
if (index < 1) {
|
|
this.pointer = 0;
|
|
if (this.start) {
|
|
this.start = false;
|
|
}
|
|
}
|
|
char[] characters = this.spacedText.toCharArray();
|
|
|
|
String current = "";
|
|
boolean changed = false;
|
|
for (int i = 0; i < index; i++) {
|
|
if ((characters[i] == '§') &&
|
|
(characters[(i + 1)] == 'F')) {
|
|
current = String.valueOf(characters[i] + characters[(i + 1)] + characters[(i + 2)]);
|
|
if ((i == index) || (i + 1 == index) || (i + 2 == index)) {
|
|
this.pointer += index - i;
|
|
changed = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
String currentBackground = "";
|
|
for (int i = 0; i < index; i++) {
|
|
if ((characters[i] == '§') &&
|
|
(characters[(i + 1)] == 'B')) {
|
|
currentBackground = String.valueOf(characters[i] + characters[(i + 1)] + characters[(i + 2)]);
|
|
if ((i == index) || (i + 1 == index) || (i + 2 == index)) {
|
|
this.pointer += index - i;
|
|
changed = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
builder.append(current + currentBackground);
|
|
|
|
builder.append(changed ? next() : this.spacedText.substring(index, this.spacedText.length()));
|
|
if (!this.start) {
|
|
builder.append(this.spacedText);
|
|
}
|
|
return builder.toString();
|
|
}
|
|
}
|