countdown titles, and possible config save for utf8

This commit is contained in:
Tyler Murphy 2022-05-05 12:22:04 -04:00
parent dbc6291397
commit 36027e007e
5 changed files with 87 additions and 29 deletions

View file

@ -22,6 +22,8 @@ package net.tylermurphy.hideAndSeek.configuration;
import com.cryptomorin.xseries.XItemStack;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.CountdownDisplay;
import net.tylermurphy.hideAndSeek.util.Version;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -137,6 +139,9 @@ public class Config {
ringingSound,
heartbeatSound;
public static CountdownDisplay
countdownDisplay;
public static void loadConfig() {
config = new ConfigManager("config.yml");
@ -249,6 +254,12 @@ public class Config {
locale = config.getString("locale", "local");
blockedCommands = config.getStringList("blockedCommands");
leaveOnEnd = config.getBoolean("leaveOnEnd");
try {
countdownDisplay = CountdownDisplay.valueOf(config.getString("hideCountdownDisplay"));
} catch (IllegalArgumentException e){
countdownDisplay = CountdownDisplay.CHAT;
Main.plugin.getLogger().warning("hideCountdownDisplay: "+config.getString("hideCountdownDisplay")+" is not a valid configuration option!");
}
blockedInteracts = new ArrayList<>();
List<String> tempInteracts = config.getStringList("blockedInteracts");
for(String id : tempInteracts){

View file

@ -52,16 +52,20 @@ public class ConfigManager {
this.config = YamlConfiguration.loadConfiguration(file);
InputStream input = Main.plugin.getResource(file.getName());
if(input == null){
FileInputStream input = null;
try{
input = new FileInputStream(file);
} catch (Exception e){
throw new RuntimeException("Could not create input stream for "+file.getPath());
}
InputStreamReader reader = new InputStreamReader(input);
InputStreamReader reader = new InputStreamReader(input, StandardCharsets.UTF_8);
this.defaultConfig = YamlConfiguration.loadConfiguration(reader);
try{
input.close();
reader.close();
} catch (IOException ignored){}
} catch (IOException ignored){
}
}
public ConfigManager(String filename, String defaultFilename){
@ -221,7 +225,7 @@ public class ConfigManager {
while((c = reader.read()) != -1){
textBuilder.append((char) c);
}
String yamlString = textBuilder.toString();
String yamlString = new String(textBuilder.toString().getBytes(), StandardCharsets.UTF_8);
Map<String, Object> temp = config.getValues(true);
for(Map.Entry<String, Object> entry: temp.entrySet()){
if(entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean || entry.getValue() instanceof List){
@ -246,26 +250,25 @@ public class ConfigManager {
if(entry.getValue() instanceof List){
if(((List<?>) entry.getValue()).isEmpty()) continue;
replace = "[";
for(Object o : (List<Object>)entry.getValue()){
replace = replace + o.toString() + ", ";
for(Object o : (List<?>)entry.getValue()){
replace = replace + new String(o.toString().getBytes(), StandardCharsets.UTF_8) + ", ";
}
replace = replace.substring(0, replace.length()-2);
replace = replace + "]";
} else {
replace = entry.getValue().toString();
replace = new String(entry.getValue().toString().getBytes(), StandardCharsets.UTF_8);
}
if(entry.getValue() instanceof String){
replace = "\"" + replace + "\"";
}
StringBuilder builder = new StringBuilder(yamlString);
builder.replace(start+1, end, replace);
yamlString = builder.toString();
yamlString = new String(builder.toString().getBytes(), StandardCharsets.UTF_8);
}
}
OutputStream os = new FileOutputStream(file);
PrintWriter out = new PrintWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8), true);
out.print(yamlString);
out.close();
Writer fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));
fileWriter.write(yamlString);
fileWriter.close();
} catch (IOException e){
e.printStackTrace();
}

View file

@ -28,9 +28,7 @@ import com.google.common.io.ByteStreams;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.configuration.Items;
import net.tylermurphy.hideAndSeek.database.Database;
import net.tylermurphy.hideAndSeek.util.Status;
import net.tylermurphy.hideAndSeek.util.Version;
import net.tylermurphy.hideAndSeek.util.WinType;
import net.tylermurphy.hideAndSeek.util.*;
import net.tylermurphy.hideAndSeek.world.WorldLoader;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
@ -41,13 +39,11 @@ import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Packet;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import javax.swing.*;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
@ -137,16 +133,18 @@ public class Game {
Board.reloadGameBoards();
status = Status.STARTING;
int temp = gameId;
broadcastMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30));
sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(20), gameId, 20 * 10);
sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(10), gameId, 20 * 20);
sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(5), gameId, 20 * 25);
sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(3), gameId, 20 * 27);
sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(2), gameId, 20 * 28);
sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(1), gameId, 20 * 29);
if(countdownDisplay != CountdownDisplay.TITLE) {
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30), gameId, 0);
}
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(20), gameId, 20 * 10);
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(10), gameId, 20 * 20);
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(5), gameId, 20 * 25);
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(3), gameId, 20 * 27);
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), gameId, 20 * 28);
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), gameId, 20 * 29);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, () -> {
if(temp != gameId) return;
broadcastMessage(messagePrefix + message("START"));
sendHideCountdownMessage(messagePrefix + message("START"), gameId, 0);
for(Player player : Board.getPlayers()) resetPlayer(player);
status = Status.PLAYING;
}, 20 * 30);
@ -422,12 +420,19 @@ public class Game {
}
}
private static void sendDelayedActionbar(String message, int gameId, int delay) {
private static void sendHideCountdownMessage(String message, int gameId, int delay) {
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, () -> {
if(gameId == Game.gameId){
for(Player player : Board.getPlayers()){
if(countdownDisplay == CountdownDisplay.CHAT){
player.sendMessage(message);
} else if(countdownDisplay == CountdownDisplay.ACTIONBAR){
ActionBar.clearActionBar(player);
ActionBar.sendActionBar(player,message);
} else if(countdownDisplay == CountdownDisplay.TITLE){
Titles.clearTitle(player);
Titles.sendTitle(player, 10, 71, 10, null, message);
}
}
}
}, delay);

View file

@ -0,0 +1,26 @@
/*
* This file is part of Kenshins Hide and Seek
*
* Copyright (c) 2022 Tyler Murphy.
*
* Kenshins Hide and Seek free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* he Free Software Foundation version 3.
*
* Kenshins Hide and Seek 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 <http://www.gnu.org/licenses/>.
*
*/
package net.tylermurphy.hideAndSeek.util;
public enum CountdownDisplay {
CHAT,
ACTIONBAR,
TITLE
}

View file

@ -14,6 +14,19 @@ gameLength: 1200
# default: true
announceMessagesToNonPlayers: true
# When the game is starting, the plugin will state there is x seconds left to hide.
# You change where countdown messages to be displayed: in the chat, action bar, or a title.
# Below you can set CHAT, ACTIONBAR, or TITLE. Any invalid option will revert to CHAT.
#
# CHAT - Messages will be displayed in the chat
#
# ACTIONBAR - Messages will be displayed in the action bar (area above the hotbar)
#
# TITLE - Messages will be displayed as a title
#
# default: CHAT
hideCountdownDisplay: CHAT
# Allow Hiders to see their own teams nametags as well as seekers. Seekers can never see nametags regardless.
# default: false
nametagsVisible: false