mirror of
https://github.com/darksaid98/EntityBingo.git
synced 2026-12-01 15:58:46 +00:00
fix issues with scoreboard saving
This commit is contained in:
1 parent
30d7cdb28b
commit
55c4c9b0e2
3 files changed
+71
-31
No files matched your search
@@ -110,7 +110,6 @@ public class DataManager {
|
||||
try {
|
||||
return Files.deleteIfExists(file.toPath());
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
@@ -147,9 +146,9 @@ public class DataManager {
|
||||
for (String path : paths) {
|
||||
File file = new File(dataFolder + File.separator + path);
|
||||
if (!file.exists()) {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("players", new ArrayList<String>());
|
||||
saveData(path, data);
|
||||
HashMap<String, Object> raw = new HashMap<>();
|
||||
raw.put("scores", new HashMap<String, Object>());
|
||||
saveData(path, raw);
|
||||
EntityBingo.getInstance().getLogger().info("Couldn't find file \"" + path + "\", generated default.");
|
||||
} else {
|
||||
EntityBingo.getInstance().getLogger().info("Found existing scoreboard file at " + dataFolder + File.separator + path);
|
||||
|
||||
@@ -6,6 +6,10 @@ import org.aubrithehuman.entitybingo.util.Helper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class EntityBingo extends JavaPlugin {
|
||||
|
||||
static EntityBingo instance;
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.aubrithehuman.entitybingo.command.EntityBingoCommand;
|
||||
import org.aubrithehuman.entitybingo.util.Helper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -29,13 +30,19 @@ public class ChatListener implements Listener {
|
||||
boolean matchFound2 = false;
|
||||
if(matchFound) {
|
||||
//start the event, only if previous one is marked as done
|
||||
if(EntityBingo.getCurrrentEvent().isDone()) {
|
||||
if(EntityBingo.getCurrrentEvent() == null) {
|
||||
EntityBingo.setCurrrentEvent(new BingoEvent());
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has begun! Type a number to enter!");
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Entity Bingo has begun! Type a number to enter!");
|
||||
} else {
|
||||
Bukkit.getLogger().info(Helper.chatLabel() + "Event Started too recently, ignoring Bingo attempt!");
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Event Started too recently, ignoring Bingo attempt!");
|
||||
if(EntityBingo.getCurrrentEvent().isDone()) {
|
||||
EntityBingo.setCurrrentEvent(new BingoEvent());
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has begun! Type a number to enter!");
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Entity Bingo has begun! Type a number to enter!");
|
||||
} else {
|
||||
Bukkit.getLogger().info(Helper.chatLabel() + "Event Started too recently, ignoring Bingo attempt!");
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Event Started too recently, ignoring Bingo attempt!");
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
@@ -84,40 +91,67 @@ public class ChatListener implements Listener {
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + "No one guessed correctly.");
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "No one guessed correctly.");
|
||||
} else {
|
||||
HashMap<String, Object> data = DataManager.getData("scoreboard.yml");
|
||||
for (String s : winners) {
|
||||
//broadcast winner
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + s + " guessed correctly!");
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + s + " guessed correctly!");
|
||||
HashMap<String, Object> raw = DataManager.getData("scoreboard.yml");
|
||||
if(raw.containsKey("scores")) {
|
||||
HashMap<String, Object> data = (HashMap<String, Object>) raw.get("scores");
|
||||
for (String s : winners) {
|
||||
//broadcast winner
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(s));
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + player.getName() + " guessed correctly!");
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + player.getName() + " guessed correctly!");
|
||||
|
||||
//get player uuid and save their wins
|
||||
UUID uuid = UUID.fromString(s);
|
||||
if(data != null) {
|
||||
if(data.containsKey(uuid.toString())) {
|
||||
data.put(uuid.toString(), (int) data.get(uuid.toString()) + 1);
|
||||
} else {
|
||||
data.put(uuid.toString(), 1);
|
||||
}
|
||||
} else {
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Data failed to load, plugins/EntityBingo/data/scoreboard.yml may be broken.");
|
||||
}
|
||||
}
|
||||
|
||||
//get player uuid and save their wins
|
||||
UUID uuid = UUID.fromString(s);
|
||||
if(data != null) {
|
||||
//save scoreboard
|
||||
HashMap<String, Object> out = new HashMap<String, Object>();
|
||||
out.put("scores", data);
|
||||
DataManager.saveData("scoreboard.yml", out);
|
||||
|
||||
//grab only entries with integer values, should be all but we need to check anyway
|
||||
Map<String, Integer> filtered = data.entrySet()
|
||||
.stream()
|
||||
.filter(v -> v.getValue() instanceof Integer)
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
v -> (int) v.getValue()));
|
||||
|
||||
//Save to static scoreboard reference
|
||||
scoreboard = Helper.sortData(filtered);
|
||||
}
|
||||
} else {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
for (String s : winners) {
|
||||
//broadcast winner
|
||||
Bukkit.broadcastMessage(Helper.chatLabel() + s + " guessed correctly!");
|
||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + s + " guessed correctly!");
|
||||
|
||||
//get player uuid and save their wins
|
||||
UUID uuid = UUID.fromString(s);
|
||||
if(data.containsKey(uuid.toString())) {
|
||||
data.put(uuid.toString(), (int) data.get(uuid.toString()) + 1);
|
||||
} else {
|
||||
data.put(uuid.toString(), 1);
|
||||
}
|
||||
} else {
|
||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Data failed to load, plugins/EntityBingo/data/scoreboard.yml may be broken.");
|
||||
}
|
||||
}
|
||||
|
||||
if(data != null) {
|
||||
//save scoreboard
|
||||
DataManager.saveData("scoreboard.yml", data);
|
||||
|
||||
//grab only entries with integer values, should be all but we need to check anyway
|
||||
Map<String, Integer> filtered = data.entrySet()
|
||||
.stream()
|
||||
.filter(v -> v.getValue() instanceof Integer)
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
v -> (int) v.getValue()));
|
||||
|
||||
//Save to static scoreboard reference
|
||||
scoreboard = Helper.sortData(filtered);
|
||||
HashMap<String, Object> out = new HashMap<String, Object>();
|
||||
out.put("scores", data);
|
||||
DataManager.saveData("scoreboard.yml", out);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
EntityBingo.getCurrrentEvent().setDone();
|
||||
@@ -141,6 +175,9 @@ public class ChatListener implements Listener {
|
||||
//Entry detection
|
||||
Bukkit.getLogger().info(Helper.chatLabel() + "comparing: " + "\"" + e.getMessage() + "\"");
|
||||
if (EntityBingo.getCurrrentEvent() != null) {
|
||||
if(EntityBingo.getCurrrentEvent().isDone()) {
|
||||
return;
|
||||
}
|
||||
String str = e.getMessage();
|
||||
//remove all color codes from this message
|
||||
str = ChatColor.stripColor(str);
|
||||
|
||||
Reference in new issue
Block a user