mirror of
https://github.com/darksaid98/EntityBingo.git
synced 2026-12-03 00:18:52 +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 {
|
try {
|
||||||
return Files.deleteIfExists(file.toPath());
|
return Files.deleteIfExists(file.toPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -147,9 +146,9 @@ public class DataManager {
|
|||||||
for (String path : paths) {
|
for (String path : paths) {
|
||||||
File file = new File(dataFolder + File.separator + path);
|
File file = new File(dataFolder + File.separator + path);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
HashMap<String, Object> data = new HashMap<>();
|
HashMap<String, Object> raw = new HashMap<>();
|
||||||
data.put("players", new ArrayList<String>());
|
raw.put("scores", new HashMap<String, Object>());
|
||||||
saveData(path, data);
|
saveData(path, raw);
|
||||||
EntityBingo.getInstance().getLogger().info("Couldn't find file \"" + path + "\", generated default.");
|
EntityBingo.getInstance().getLogger().info("Couldn't find file \"" + path + "\", generated default.");
|
||||||
} else {
|
} else {
|
||||||
EntityBingo.getInstance().getLogger().info("Found existing scoreboard file at " + dataFolder + File.separator + path);
|
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.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
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 {
|
public final class EntityBingo extends JavaPlugin {
|
||||||
|
|
||||||
static EntityBingo instance;
|
static EntityBingo instance;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.aubrithehuman.entitybingo.command.EntityBingoCommand;
|
|||||||
import org.aubrithehuman.entitybingo.util.Helper;
|
import org.aubrithehuman.entitybingo.util.Helper;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -29,13 +30,19 @@ public class ChatListener implements Listener {
|
|||||||
boolean matchFound2 = false;
|
boolean matchFound2 = false;
|
||||||
if(matchFound) {
|
if(matchFound) {
|
||||||
//start the event, only if previous one is marked as done
|
//start the event, only if previous one is marked as done
|
||||||
if(EntityBingo.getCurrrentEvent().isDone()) {
|
if(EntityBingo.getCurrrentEvent() == null) {
|
||||||
EntityBingo.setCurrrentEvent(new BingoEvent());
|
EntityBingo.setCurrrentEvent(new BingoEvent());
|
||||||
Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has begun! Type a number to enter!");
|
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!");
|
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Entity Bingo has begun! Type a number to enter!");
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getLogger().info(Helper.chatLabel() + "Event Started too recently, ignoring Bingo attempt!");
|
if(EntityBingo.getCurrrentEvent().isDone()) {
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Event Started too recently, ignoring Bingo attempt!");
|
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;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@@ -84,40 +91,67 @@ public class ChatListener implements Listener {
|
|||||||
Bukkit.broadcastMessage(Helper.chatLabel() + "No one guessed correctly.");
|
Bukkit.broadcastMessage(Helper.chatLabel() + "No one guessed correctly.");
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "No one guessed correctly.");
|
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "No one guessed correctly.");
|
||||||
} else {
|
} else {
|
||||||
HashMap<String, Object> data = DataManager.getData("scoreboard.yml");
|
HashMap<String, Object> raw = DataManager.getData("scoreboard.yml");
|
||||||
for (String s : winners) {
|
if(raw.containsKey("scores")) {
|
||||||
//broadcast winner
|
HashMap<String, Object> data = (HashMap<String, Object>) raw.get("scores");
|
||||||
Bukkit.broadcastMessage(Helper.chatLabel() + s + " guessed correctly!");
|
for (String s : winners) {
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + s + " guessed correctly!");
|
//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) {
|
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())) {
|
if(data.containsKey(uuid.toString())) {
|
||||||
data.put(uuid.toString(), (int) data.get(uuid.toString()) + 1);
|
data.put(uuid.toString(), (int) data.get(uuid.toString()) + 1);
|
||||||
} else {
|
} else {
|
||||||
data.put(uuid.toString(), 1);
|
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
|
//save scoreboard
|
||||||
DataManager.saveData("scoreboard.yml", data);
|
HashMap<String, Object> out = new HashMap<String, Object>();
|
||||||
|
out.put("scores", data);
|
||||||
//grab only entries with integer values, should be all but we need to check anyway
|
DataManager.saveData("scoreboard.yml", out);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityBingo.getCurrrentEvent().setDone();
|
EntityBingo.getCurrrentEvent().setDone();
|
||||||
@@ -141,6 +175,9 @@ public class ChatListener implements Listener {
|
|||||||
//Entry detection
|
//Entry detection
|
||||||
Bukkit.getLogger().info(Helper.chatLabel() + "comparing: " + "\"" + e.getMessage() + "\"");
|
Bukkit.getLogger().info(Helper.chatLabel() + "comparing: " + "\"" + e.getMessage() + "\"");
|
||||||
if (EntityBingo.getCurrrentEvent() != null) {
|
if (EntityBingo.getCurrrentEvent() != null) {
|
||||||
|
if(EntityBingo.getCurrrentEvent().isDone()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
String str = e.getMessage();
|
String str = e.getMessage();
|
||||||
//remove all color codes from this message
|
//remove all color codes from this message
|
||||||
str = ChatColor.stripColor(str);
|
str = ChatColor.stripColor(str);
|
||||||
|
|||||||
Reference in new issue
Block a user