mirror of
https://github.com/darksaid98/EntityBingo.git
synced 2026-12-01 15:58:46 +00:00
pass 1
This commit is contained in:
1 parent
c54512bfb6
commit
6a17bbaa8d
6 files changed
+137
-6
No files matched your search
@@ -6,9 +6,11 @@ public class BingoEvent {
|
||||
|
||||
private final HashMap<String, Integer> entries;
|
||||
|
||||
private final long age;
|
||||
|
||||
public BingoEvent() {
|
||||
this.entries = new HashMap<>();
|
||||
age = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getEntries() {
|
||||
@@ -50,4 +52,8 @@ public class BingoEvent {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getAge() {
|
||||
return age;
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,7 @@ public class DataManager {
|
||||
* Creates Default Files
|
||||
*/
|
||||
private static void genDefaultFiles() {
|
||||
List<String> paths = Arrays.asList(
|
||||
List<String> paths = List.of(
|
||||
"scoreboard.yml"
|
||||
);
|
||||
|
||||
@@ -162,14 +162,14 @@ public class DataManager {
|
||||
*/
|
||||
private static void createFolders() {
|
||||
List<String> paths = Arrays.asList(
|
||||
"plugins" + File.separator + "EconomyTracker" + File.separator + "data"
|
||||
"plugins" + File.separator + "EntityBingo" + File.separator + "data"
|
||||
);
|
||||
|
||||
for (String path : paths) {
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
Bukkit.getLogger().info("Couldn't find folder \"" + path + "\", generated default.");
|
||||
EntityBingo.getInstance().getLogger().info("Couldn't find folder \"" + path + "\", generated default.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,32 @@
|
||||
package org.aubrithehuman.entitybingo;
|
||||
|
||||
import org.aubrithehuman.entitybingo.command.EntityBingoCommand;
|
||||
import org.aubrithehuman.entitybingo.listeners.ChatListener;
|
||||
import org.aubrithehuman.entitybingo.listeners.EntityClearEventListener;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import javax.swing.text.html.parser.Entity;
|
||||
|
||||
public final class EntityBingo extends JavaPlugin implements Listener {
|
||||
public final class EntityBingo extends JavaPlugin {
|
||||
|
||||
static EntityBingo instance;
|
||||
|
||||
static BingoEvent currrentEvent;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
|
||||
EntityBingoCommand c = new EntityBingoCommand(this);
|
||||
getCommand("eb").setTabCompleter(c);
|
||||
getCommand("entb").setTabCompleter(c);
|
||||
getCommand("entitybingo").setTabCompleter(c);
|
||||
|
||||
this.saveDefaultConfig();
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
this.getServer().getPluginManager().registerEvents(new ChatListener(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new EntityClearEventListener(), this);
|
||||
|
||||
DataManager.init();
|
||||
|
||||
@@ -30,4 +41,12 @@ public final class EntityBingo extends JavaPlugin implements Listener {
|
||||
public static EntityBingo getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static BingoEvent getCurrrentEvent() {
|
||||
return currrentEvent;
|
||||
}
|
||||
|
||||
public static void setCurrrentEvent(BingoEvent currrentEvent) {
|
||||
EntityBingo.currrentEvent = currrentEvent;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.aubrithehuman.entitybingo.command;
|
||||
|
||||
import org.aubrithehuman.entitybingo.EntityBingo;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -13,6 +14,12 @@ public class EntityBingoCommand implements CommandExecutor, TabCompleter {
|
||||
"scoreboard"
|
||||
});
|
||||
|
||||
public EntityBingoCommand(EntityBingo entityBingo) {
|
||||
entityBingo.getCommand("eb").setExecutor((CommandExecutor) this);
|
||||
entityBingo.getCommand("entb").setExecutor((CommandExecutor) this);
|
||||
entityBingo.getCommand("entitybingo").setExecutor((CommandExecutor) this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(args.length >= 1) {
|
||||
|
||||
@@ -1,15 +1,112 @@
|
||||
package org.aubrithehuman.entitybingo.listeners;
|
||||
|
||||
import org.aubrithehuman.entitybingo.BingoEvent;
|
||||
import org.aubrithehuman.entitybingo.EntityBingo;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.server.BroadcastMessageEvent;
|
||||
import org.bukkit.event.server.ServerEvent;
|
||||
|
||||
import javax.sound.midi.SysexMessage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ChatListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onChat(PlayerCommandPreprocessEvent e) {
|
||||
public void onChat(BroadcastMessageEvent e) {
|
||||
Bukkit.getLogger().info(e.getMessage());
|
||||
Pattern pattern = Pattern.compile("[ClearLag] Warning Ground items will be removed in 60 seconds", Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(e.getMessage());
|
||||
boolean matchFound = matcher.find();
|
||||
if(matchFound) {
|
||||
Bukkit.getLogger().info("Match found");
|
||||
} else {
|
||||
Bukkit.getLogger().info("Match not found");
|
||||
}
|
||||
|
||||
Pattern pattern2 = Pattern.compile("[ClearLag] Removed Entities!", Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher2 = pattern2.matcher(e.getMessage());
|
||||
boolean matchFound2 = matcher2.find();
|
||||
if(matchFound2) {
|
||||
Bukkit.getLogger().info("Match found");
|
||||
} else {
|
||||
Bukkit.getLogger().info("Match not found");
|
||||
}
|
||||
|
||||
//TODO start event
|
||||
if(matchFound) {
|
||||
if(EntityBingo.getCurrrentEvent() == null) {
|
||||
EntityBingo.setCurrrentEvent(new BingoEvent());
|
||||
Bukkit.broadcastMessage(chatLabel() + "Entity Bingo has begun! Enter a number in chat to enter!");
|
||||
return;
|
||||
} else {
|
||||
Bukkit.getLogger().info("Event Started too recently, ignoring Bingo attempt!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(matchFound2) {
|
||||
if(EntityBingo.getCurrrentEvent() != null) {
|
||||
Bukkit.broadcastMessage(chatLabel() + "Entity Bingo has ended!");
|
||||
|
||||
String str = e.getMessage();
|
||||
String numberOnly = str.replaceAll("[^0-9]", "");
|
||||
int i = Integer.parseInt(numberOnly);
|
||||
|
||||
List<String> winners = new ArrayList<>();
|
||||
for(String s : EntityBingo.getCurrrentEvent().getEntries().keySet()) {
|
||||
if(EntityBingo.getCurrrentEvent().getEntries().get(s) == i) {
|
||||
winners.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
if(winners.isEmpty()) {
|
||||
Bukkit.broadcastMessage(chatLabel() + "No one guessed correctly.");
|
||||
} else {
|
||||
for (String s : winners) {
|
||||
Bukkit.broadcastMessage(chatLabel() + s + " guessed correctly!");
|
||||
//TODO save result
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
//Entry detection
|
||||
Bukkit.getLogger().info(e.getMessage());
|
||||
if (EntityBingo.getCurrrentEvent() != null) {
|
||||
String str = e.getMessage();
|
||||
String numberOnly = str.replaceAll("[^0-9]", "");
|
||||
int guess = Integer.parseInt(numberOnly);
|
||||
|
||||
if (EntityBingo.getCurrrentEvent().getEntries().containsKey(e.getPlayer().getName())) {
|
||||
e.getPlayer().sendMessage("You have already entered entity bingo, your old guess has been overridden.");
|
||||
}
|
||||
e.getPlayer().sendMessage("You have entered with the guess " + guess + ".");
|
||||
EntityBingo.getCurrrentEvent().getEntries().put(e.getPlayer().getName(), guess);
|
||||
}
|
||||
}
|
||||
|
||||
public static String color(final String input) {
|
||||
return ChatColor.translateAlternateColorCodes('&', input);
|
||||
}
|
||||
|
||||
public static String chatLabel() {
|
||||
return color("&6[&4EntityBingo&6]&r ");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
&4[ClearLag] Warning Ground items will be removed in seconds!
|
||||
&6[ClearLag] &aRemoved +RemoveAmount Entities!'
|
||||
Reference in new issue
Block a user