mirror of
https://github.com/darksaid98/EntityBingo.git
synced 2026-12-01 15:58:46 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56efdb4892 | ||
|
|
3b0573b712 | ||
|
|
6fcbf28d88 |
No files matched your search
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>org.aubrithehuman</groupId>
|
<groupId>org.aubrithehuman</groupId>
|
||||||
<artifactId>EntityBingo</artifactId>
|
<artifactId>EntityBingo</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.0.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EntityBingo</name>
|
<name>EntityBingo</name>
|
||||||
|
|||||||
@@ -8,8 +8,11 @@ public class BingoEvent {
|
|||||||
|
|
||||||
private boolean done = false;
|
private boolean done = false;
|
||||||
|
|
||||||
|
private final long age;
|
||||||
|
|
||||||
public BingoEvent() {
|
public BingoEvent() {
|
||||||
this.entries = new HashMap<>();
|
this.entries = new HashMap<>();
|
||||||
|
age = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, Integer> getEntries() {
|
public HashMap<String, Integer> getEntries() {
|
||||||
@@ -43,4 +46,8 @@ public class BingoEvent {
|
|||||||
public void setDone() {
|
public void setDone() {
|
||||||
this.done = true;
|
this.done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getAge() {
|
||||||
|
return this.age;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ import java.nio.file.Files;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages file IO & Deletion for other data classes.
|
* Manages file IO & Deletion for other data classes.
|
||||||
@@ -39,7 +40,7 @@ public class DataManager {
|
|||||||
try {
|
try {
|
||||||
writer = new PrintWriter(file);
|
writer = new PrintWriter(file);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Bukkit.getLogger().info("Encountered error when creating PrintWriter for " + filePath);
|
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Encountered error when creating PrintWriter for " + filePath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +75,7 @@ public class DataManager {
|
|||||||
*/
|
*/
|
||||||
public static HashMap<String, Object> getData(File file) {
|
public static HashMap<String, Object> getData(File file) {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
Bukkit.getLogger().info("Attempted to retrieve non-existant file: " + file.getPath());
|
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Attempted to retrieve non-existant file: " + file.getPath());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +83,7 @@ public class DataManager {
|
|||||||
try {
|
try {
|
||||||
inputStream = new FileInputStream(file);
|
inputStream = new FileInputStream(file);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Bukkit.getLogger().info("Encountered error when creating FileInputStream for " + file.getPath());
|
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Encountered error when creating FileInputStream for " + file.getPath());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Yaml yaml = new Yaml();
|
Yaml yaml = new Yaml();
|
||||||
@@ -90,7 +91,7 @@ public class DataManager {
|
|||||||
try {
|
try {
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Bukkit.getLogger().info(e.getMessage());
|
EntityBingo.getInstance().getLogger().log(Level.SEVERE, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@@ -106,7 +107,7 @@ public class DataManager {
|
|||||||
File file = getFile(filePath);
|
File file = getFile(filePath);
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
Bukkit.getLogger().info("Attempted to retrieve non-existant file: " + filePath + ".yml");
|
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Attempted to retrieve non-existant file: " + filePath + ".yml");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +133,7 @@ public class DataManager {
|
|||||||
try {
|
try {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Bukkit.getLogger().info("Encountered error when creating file - " + path);
|
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Encountered error when creating file - " + path);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,9 +93,9 @@ public class EntityBingoCommand implements CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("guesses")) {
|
} else if (args[0].equalsIgnoreCase("guesses")) {
|
||||||
|
|
||||||
if (EntityBingo.getCurrentEvent() == null) {
|
if (EntityBingo.getCurrentEvent() == null) {
|
||||||
p.sendMessage(Helper.chatLabel() + Helper.color("No games have occurred recently."));
|
p.sendMessage(Helper.chatLabel() + Helper.color("No games have occurred recently."));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//print off all guesses
|
//print off all guesses
|
||||||
@@ -117,6 +117,7 @@ public class EntityBingoCommand implements CommandExecutor, TabCompleter {
|
|||||||
p.sendMessage(Helper.chatLabel() + Helper.color("&cCleared all entries in the " + (EntityBingo.getCurrentEvent().isDone() ? "previous" : "current") + " event. This won't effect the scoreboard."));
|
p.sendMessage(Helper.chatLabel() + Helper.color("&cCleared all entries in the " + (EntityBingo.getCurrentEvent().isDone() ? "previous" : "current") + " event. This won't effect the scoreboard."));
|
||||||
Bukkit.broadcastMessage(Helper.chatLabel() + Helper.color("&cEntries cleared by an admin!"));
|
Bukkit.broadcastMessage(Helper.chatLabel() + Helper.color("&cEntries cleared by an admin!"));
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.color("&cEntries cleared by an admin!"));
|
EntityBingo.getInstance().getLogger().info(Helper.color("&cEntries cleared by an admin!"));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
//clear entry pool
|
//clear entry pool
|
||||||
EntityBingo.getCurrentEvent().getEntries().clear();
|
EntityBingo.getCurrentEvent().getEntries().clear();
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class ChatListener implements Listener {
|
|||||||
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!");
|
Bukkit.broadcastMessage(Helper.chatLabel() + "Event Started too recently, ignoring Bingo attempt!");
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Event Started too recently, ignoring Bingo attempt!");
|
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "Event Started too recently, ignoring Bingo attempt!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,112 +51,112 @@ public class ChatListener implements Listener {
|
|||||||
if(matchFound2) {
|
if(matchFound2) {
|
||||||
//check if we have a bingo event happening
|
//check if we have a bingo event happening
|
||||||
if(EntityBingo.getCurrentEvent() != null) {
|
if(EntityBingo.getCurrentEvent() != null) {
|
||||||
Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has ended!");
|
if(!EntityBingo.getCurrentEvent().isDone()) {
|
||||||
|
Bukkit.broadcastMessage(Helper.chatLabel() + "Entity Bingo has ended!");
|
||||||
|
|
||||||
//extract the result number
|
//extract the result number
|
||||||
String str = e.getMessage();
|
String str = e.getMessage();
|
||||||
str = ChatColor.stripColor(str);
|
str = ChatColor.stripColor(str);
|
||||||
String numberOnly = str.replaceAll("[^0-9]", "");
|
String numberOnly = str.replaceAll("[^0-9]", "");
|
||||||
int i = -1;
|
int i = -1;
|
||||||
if(!str.isEmpty()) {
|
if(!str.isEmpty()) {
|
||||||
//we need to check if the guess exists as an int
|
//we need to check if the guess exists as an int
|
||||||
try {
|
try {
|
||||||
i = Integer.parseInt(numberOnly);
|
i = Integer.parseInt(numberOnly);
|
||||||
} catch (NumberFormatException exception) {
|
} catch (NumberFormatException exception) {
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + Helper.color("&cFailed to find the result number, cancelling bingo."));
|
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + Helper.color("&cFailed to find the result number, cancelling bingo."));
|
||||||
EntityBingo.getCurrentEvent().setDone();
|
EntityBingo.getCurrentEvent().setDone();
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//look for winners
|
|
||||||
List<String> winners = new ArrayList<>();
|
|
||||||
if(i >= 0) {
|
|
||||||
for(String s : EntityBingo.getCurrentEvent().getEntries().keySet()) {
|
|
||||||
if(EntityBingo.getCurrentEvent().getEntries().get(s) == i) {
|
|
||||||
winners.add(s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//broadcast winners
|
//look for winners
|
||||||
if(winners.isEmpty()) {
|
List<String> winners = new ArrayList<>();
|
||||||
//no winners??????
|
if(i >= 0) {
|
||||||
Bukkit.broadcastMessage(Helper.chatLabel() + "No one guessed correctly.");
|
for(String s : EntityBingo.getCurrentEvent().getEntries().keySet()) {
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "No one guessed correctly.");
|
if(EntityBingo.getCurrentEvent().getEntries().get(s) == i) {
|
||||||
} else {
|
winners.add(s);
|
||||||
HashMap<String, Object> raw = DataManager.getData("scoreboard.yml");
|
}
|
||||||
if(raw.containsKey("scores")) {
|
}
|
||||||
try {
|
}
|
||||||
HashMap<String, Object> data = (HashMap<String, Object>) raw.get("scores");
|
|
||||||
|
//broadcast winners
|
||||||
|
if(winners.isEmpty()) {
|
||||||
|
//no winners??????
|
||||||
|
Bukkit.broadcastMessage(Helper.chatLabel() + "No one guessed correctly.");
|
||||||
|
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + "No one guessed correctly.");
|
||||||
|
} else {
|
||||||
|
HashMap<String, Object> raw = DataManager.getData("scoreboard.yml");
|
||||||
|
if(raw.containsKey("scores")) {
|
||||||
|
try {
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data != null) {
|
||||||
|
//save scoreboard
|
||||||
|
HashMap<String, Object> out = new HashMap<>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
} catch (ClassCastException ex) {
|
||||||
|
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Failed to load scores, is scoreboard.yml broken?");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
for (String s : winners) {
|
for (String s : winners) {
|
||||||
//broadcast winner
|
//broadcast winner
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(s));
|
Bukkit.broadcastMessage(Helper.chatLabel() + s + " guessed correctly!");
|
||||||
Bukkit.broadcastMessage(Helper.chatLabel() + player.getName() + " guessed correctly!");
|
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + s + " guessed correctly!");
|
||||||
EntityBingo.getInstance().getLogger().info(Helper.chatLabel() + player.getName() + " guessed correctly!");
|
|
||||||
|
|
||||||
//get player uuid and save their wins
|
//get player uuid and save their wins
|
||||||
UUID uuid = UUID.fromString(s);
|
UUID uuid = UUID.fromString(s);
|
||||||
if (data != null) {
|
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 {
|
|
||||||
data.put(uuid.toString(), 1);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Data failed to load, plugins/EntityBingo/data/scoreboard.yml may be broken.");
|
data.put(uuid.toString(), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//save scoreboard
|
||||||
if (data != null) {
|
HashMap<String, Object> out = new HashMap<>();
|
||||||
//save scoreboard
|
out.put("scores", data);
|
||||||
HashMap<String, Object> out = new HashMap<>();
|
DataManager.saveData("scoreboard.yml", out);
|
||||||
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);
|
|
||||||
}
|
|
||||||
} catch (ClassCastException ex) {
|
|
||||||
EntityBingo.getInstance().getLogger().log(Level.WARNING, "Failed to load scores, is scoreboard.yml broken?");
|
|
||||||
}
|
}
|
||||||
} 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//save scoreboard
|
|
||||||
HashMap<String, Object> out = new HashMap<>();
|
|
||||||
out.put("scores", data);
|
|
||||||
DataManager.saveData("scoreboard.yml", out);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EntityBingo.getCurrentEvent().setDone();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityBingo.getCurrentEvent().setDone();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Bukkit.getLogger().info("Match not found for any part");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,29 +167,35 @@ public class ChatListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onChat(AsyncPlayerChatEvent e) {
|
public void onChat(AsyncPlayerChatEvent e) {
|
||||||
//Entry detection
|
//Entry detection
|
||||||
Bukkit.getLogger().info(Helper.chatLabel() + "comparing: " + "\"" + e.getMessage() + "\"");
|
|
||||||
if (EntityBingo.getCurrentEvent() != null) {
|
if (EntityBingo.getCurrentEvent() != null) {
|
||||||
if(EntityBingo.getCurrentEvent().isDone()) {
|
if(EntityBingo.getCurrentEvent().isDone()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Force end event if it's too old.
|
||||||
|
int maxEventAge = EntityBingo.getInstance().getConfig().getInt("maxEventAge");
|
||||||
|
if(System.currentTimeMillis() - EntityBingo.getCurrentEvent().getAge() > (maxEventAge * 1000L)) {
|
||||||
|
EntityBingo.getCurrentEvent().setDone();
|
||||||
|
Bukkit.broadcastMessage(Helper.chatLabel() + Helper.color("&cForcefully ended bingo event as it has been more than " + maxEventAge + " seconds."));
|
||||||
|
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);
|
||||||
Bukkit.getLogger().info(Helper.chatLabel() + "purges codes for: " + "\"" + str + "\"");
|
|
||||||
//remove all text other than numbers
|
//remove all text other than numbers
|
||||||
str = str.replaceAll("[^0-9.]", "");
|
str = str.replaceAll("[^0-9.]", "");
|
||||||
Bukkit.getLogger().info(Helper.chatLabel() + "numbers only: " + "\"" + str + "\"");
|
|
||||||
if(!str.isEmpty()) {
|
if(!str.isEmpty()) {
|
||||||
int guess;
|
int guess = - 1;
|
||||||
//we need to check if the guess exists as an int
|
//we need to check if the guess exists as an int
|
||||||
try {
|
try {
|
||||||
guess = Integer.parseInt(str);
|
guess = Integer.parseInt(str);
|
||||||
} catch (NumberFormatException exception) {
|
} catch (NumberFormatException exception) {
|
||||||
e.getPlayer().sendMessage(Helper.chatLabel() + Helper.color("&cDetected a number that could not be formatted, make sure not to use decimals."));
|
e.getPlayer().sendMessage(Helper.chatLabel() + Helper.color("&cDetected a number that could not be formatted, make sure not to use decimals or seperators."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (guess > 0) {
|
if (guess >= 0) {
|
||||||
//do the entry
|
//do the entry
|
||||||
int result = EntityBingo.getCurrentEvent().addEntry(e.getPlayer().getUniqueId().toString(), guess);
|
int result = EntityBingo.getCurrentEvent().addEntry(e.getPlayer().getUniqueId().toString(), guess);
|
||||||
//feedback to entrant
|
//feedback to entrant
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#check against this to start
|
#check against this to start
|
||||||
startMessage: '§4[ClearLag] §cWarning Ground items will be removed in §760 §cseconds!'
|
startMessage: '§4[ClearLag] §cWarning Ground items will be removed in §760 §cseconds!'
|
||||||
#check against this to end
|
#check against this to end
|
||||||
endMessage: '§6[ClearLag] §aRemoved '
|
endMessage: '§6[ClearLag] §aRemoved '
|
||||||
|
#max age for event (in seconds), used in case the ending fails
|
||||||
|
maxEventAge: 120
|
||||||
Reference in new issue
Block a user