countdown titles, and possible config save for utf8
This commit is contained in:
parent
dbc6291397
commit
36027e007e
5 changed files with 87 additions and 29 deletions
|
@ -22,6 +22,8 @@ package net.tylermurphy.hideAndSeek.configuration;
|
||||||
import com.cryptomorin.xseries.XItemStack;
|
import com.cryptomorin.xseries.XItemStack;
|
||||||
import com.cryptomorin.xseries.XMaterial;
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import com.cryptomorin.xseries.XSound;
|
import com.cryptomorin.xseries.XSound;
|
||||||
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
|
import net.tylermurphy.hideAndSeek.util.CountdownDisplay;
|
||||||
import net.tylermurphy.hideAndSeek.util.Version;
|
import net.tylermurphy.hideAndSeek.util.Version;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
@ -137,6 +139,9 @@ public class Config {
|
||||||
ringingSound,
|
ringingSound,
|
||||||
heartbeatSound;
|
heartbeatSound;
|
||||||
|
|
||||||
|
public static CountdownDisplay
|
||||||
|
countdownDisplay;
|
||||||
|
|
||||||
public static void loadConfig() {
|
public static void loadConfig() {
|
||||||
|
|
||||||
config = new ConfigManager("config.yml");
|
config = new ConfigManager("config.yml");
|
||||||
|
@ -249,6 +254,12 @@ public class Config {
|
||||||
locale = config.getString("locale", "local");
|
locale = config.getString("locale", "local");
|
||||||
blockedCommands = config.getStringList("blockedCommands");
|
blockedCommands = config.getStringList("blockedCommands");
|
||||||
leaveOnEnd = config.getBoolean("leaveOnEnd");
|
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<>();
|
blockedInteracts = new ArrayList<>();
|
||||||
List<String> tempInteracts = config.getStringList("blockedInteracts");
|
List<String> tempInteracts = config.getStringList("blockedInteracts");
|
||||||
for(String id : tempInteracts){
|
for(String id : tempInteracts){
|
||||||
|
|
|
@ -52,16 +52,20 @@ public class ConfigManager {
|
||||||
|
|
||||||
this.config = YamlConfiguration.loadConfiguration(file);
|
this.config = YamlConfiguration.loadConfiguration(file);
|
||||||
|
|
||||||
InputStream input = Main.plugin.getResource(file.getName());
|
FileInputStream input = null;
|
||||||
if(input == null){
|
try{
|
||||||
|
input = new FileInputStream(file);
|
||||||
|
} catch (Exception e){
|
||||||
throw new RuntimeException("Could not create input stream for "+file.getPath());
|
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);
|
this.defaultConfig = YamlConfiguration.loadConfiguration(reader);
|
||||||
try{
|
try{
|
||||||
input.close();
|
input.close();
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (IOException ignored){}
|
} catch (IOException ignored){
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigManager(String filename, String defaultFilename){
|
public ConfigManager(String filename, String defaultFilename){
|
||||||
|
@ -221,7 +225,7 @@ public class ConfigManager {
|
||||||
while((c = reader.read()) != -1){
|
while((c = reader.read()) != -1){
|
||||||
textBuilder.append((char) c);
|
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);
|
Map<String, Object> temp = config.getValues(true);
|
||||||
for(Map.Entry<String, Object> entry: temp.entrySet()){
|
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){
|
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(entry.getValue() instanceof List){
|
||||||
if(((List<?>) entry.getValue()).isEmpty()) continue;
|
if(((List<?>) entry.getValue()).isEmpty()) continue;
|
||||||
replace = "[";
|
replace = "[";
|
||||||
for(Object o : (List<Object>)entry.getValue()){
|
for(Object o : (List<?>)entry.getValue()){
|
||||||
replace = replace + o.toString() + ", ";
|
replace = replace + new String(o.toString().getBytes(), StandardCharsets.UTF_8) + ", ";
|
||||||
}
|
}
|
||||||
replace = replace.substring(0, replace.length()-2);
|
replace = replace.substring(0, replace.length()-2);
|
||||||
replace = replace + "]";
|
replace = replace + "]";
|
||||||
} else {
|
} else {
|
||||||
replace = entry.getValue().toString();
|
replace = new String(entry.getValue().toString().getBytes(), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
if(entry.getValue() instanceof String){
|
if(entry.getValue() instanceof String){
|
||||||
replace = "\"" + replace + "\"";
|
replace = "\"" + replace + "\"";
|
||||||
}
|
}
|
||||||
StringBuilder builder = new StringBuilder(yamlString);
|
StringBuilder builder = new StringBuilder(yamlString);
|
||||||
builder.replace(start+1, end, replace);
|
builder.replace(start+1, end, replace);
|
||||||
yamlString = builder.toString();
|
yamlString = new String(builder.toString().getBytes(), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OutputStream os = new FileOutputStream(file);
|
Writer fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));
|
||||||
PrintWriter out = new PrintWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8), true);
|
fileWriter.write(yamlString);
|
||||||
out.print(yamlString);
|
fileWriter.close();
|
||||||
out.close();
|
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,7 @@ import com.google.common.io.ByteStreams;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.tylermurphy.hideAndSeek.configuration.Items;
|
import net.tylermurphy.hideAndSeek.configuration.Items;
|
||||||
import net.tylermurphy.hideAndSeek.database.Database;
|
import net.tylermurphy.hideAndSeek.database.Database;
|
||||||
import net.tylermurphy.hideAndSeek.util.Status;
|
import net.tylermurphy.hideAndSeek.util.*;
|
||||||
import net.tylermurphy.hideAndSeek.util.Version;
|
|
||||||
import net.tylermurphy.hideAndSeek.util.WinType;
|
|
||||||
import net.tylermurphy.hideAndSeek.world.WorldLoader;
|
import net.tylermurphy.hideAndSeek.world.WorldLoader;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
|
@ -41,13 +39,11 @@ import org.bukkit.entity.Firework;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.Main;
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
import net.tylermurphy.hideAndSeek.util.Packet;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.FireworkMeta;
|
import org.bukkit.inventory.meta.FireworkMeta;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -137,16 +133,18 @@ public class Game {
|
||||||
Board.reloadGameBoards();
|
Board.reloadGameBoards();
|
||||||
status = Status.STARTING;
|
status = Status.STARTING;
|
||||||
int temp = gameId;
|
int temp = gameId;
|
||||||
broadcastMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30));
|
if(countdownDisplay != CountdownDisplay.TITLE) {
|
||||||
sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(20), gameId, 20 * 10);
|
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30), gameId, 0);
|
||||||
sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(10), gameId, 20 * 20);
|
}
|
||||||
sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(5), gameId, 20 * 25);
|
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(20), gameId, 20 * 10);
|
||||||
sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(3), gameId, 20 * 27);
|
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(10), gameId, 20 * 20);
|
||||||
sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(2), gameId, 20 * 28);
|
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(5), gameId, 20 * 25);
|
||||||
sendDelayedActionbar(messagePrefix + message("START_COUNTDOWN").addAmount(1), gameId, 20 * 29);
|
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, () -> {
|
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, () -> {
|
||||||
if(temp != gameId) return;
|
if(temp != gameId) return;
|
||||||
broadcastMessage(messagePrefix + message("START"));
|
sendHideCountdownMessage(messagePrefix + message("START"), gameId, 0);
|
||||||
for(Player player : Board.getPlayers()) resetPlayer(player);
|
for(Player player : Board.getPlayers()) resetPlayer(player);
|
||||||
status = Status.PLAYING;
|
status = Status.PLAYING;
|
||||||
}, 20 * 30);
|
}, 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, () -> {
|
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, () -> {
|
||||||
if(gameId == Game.gameId){
|
if(gameId == Game.gameId){
|
||||||
for(Player player : Board.getPlayers()){
|
for(Player player : Board.getPlayers()){
|
||||||
|
if(countdownDisplay == CountdownDisplay.CHAT){
|
||||||
|
player.sendMessage(message);
|
||||||
|
} else if(countdownDisplay == CountdownDisplay.ACTIONBAR){
|
||||||
ActionBar.clearActionBar(player);
|
ActionBar.clearActionBar(player);
|
||||||
ActionBar.sendActionBar(player,message);
|
ActionBar.sendActionBar(player,message);
|
||||||
|
} else if(countdownDisplay == CountdownDisplay.TITLE){
|
||||||
|
Titles.clearTitle(player);
|
||||||
|
Titles.sendTitle(player, 10, 71, 10, null, message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, delay);
|
}, delay);
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -14,6 +14,19 @@ gameLength: 1200
|
||||||
# default: true
|
# default: true
|
||||||
announceMessagesToNonPlayers: 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.
|
# Allow Hiders to see their own teams nametags as well as seekers. Seekers can never see nametags regardless.
|
||||||
# default: false
|
# default: false
|
||||||
nametagsVisible: false
|
nametagsVisible: false
|
||||||
|
|
Loading…
Reference in a new issue