Dateien nach "src/main/java/de/nexuslobby/modules/actionbar" hochladen
This commit is contained in:
@@ -0,0 +1,82 @@
|
|||||||
|
package de.nexuslobby.modules.actionbar;
|
||||||
|
|
||||||
|
import de.nexuslobby.NexusLobby;
|
||||||
|
import de.nexuslobby.api.Module;
|
||||||
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ActionBarModule implements Module {
|
||||||
|
|
||||||
|
private int messageIndex = 0;
|
||||||
|
private int charIndex = 0;
|
||||||
|
private int pauseCounter = 0;
|
||||||
|
private boolean isWaiting = false;
|
||||||
|
private BukkitRunnable task;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() { return "ActionBar"; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
FileConfiguration vConfig = NexusLobby.getInstance().getVisualsConfig();
|
||||||
|
if (!vConfig.getBoolean("actionbar.enabled", true)) return;
|
||||||
|
|
||||||
|
List<String> messages = vConfig.getStringList("actionbar.messages");
|
||||||
|
if (messages.isEmpty()) return;
|
||||||
|
|
||||||
|
startTask(messages, vConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startTask(List<String> messages, FileConfiguration vConfig) {
|
||||||
|
int speed = vConfig.getInt("actionbar.animation-speed", 2);
|
||||||
|
int holdDuration = vConfig.getInt("actionbar.hold-duration", 100);
|
||||||
|
|
||||||
|
task = new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String currentMessage = messages.get(messageIndex);
|
||||||
|
|
||||||
|
if (!isWaiting) {
|
||||||
|
if (charIndex < currentMessage.length()) {
|
||||||
|
charIndex++;
|
||||||
|
} else {
|
||||||
|
isWaiting = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pauseCounter++;
|
||||||
|
if (pauseCounter >= holdDuration) {
|
||||||
|
pauseCounter = 0;
|
||||||
|
charIndex = 0;
|
||||||
|
isWaiting = false;
|
||||||
|
messageIndex = (messageIndex + 1) % messages.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String textToSend = currentMessage.substring(0, charIndex);
|
||||||
|
sendToAll(colorize(textToSend));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
task.runTaskTimer(NexusLobby.getInstance(), 0L, (long) speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendToAll(String message) {
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String colorize(String s) {
|
||||||
|
return s == null ? "" : s.replace("&", "§");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
if (task != null) task.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user