· 6 years ago · May 02, 2019, 05:54 PM
1package oblv.mcspg.paxo.oblivioncore.authenticator;
2
3import com.warrenstrange.googleauth.GoogleAuthenticator;
4import com.warrenstrange.googleauth.GoogleAuthenticatorKey;
5import oblv.mcspg.paxo.oblivioncore.OblivionNetworks;
6import org.bukkit.entity.Player;
7import org.bukkit.event.EventHandler;
8import org.bukkit.event.Listener;
9import org.bukkit.event.block.BlockBreakEvent;
10import org.bukkit.event.block.BlockPlaceEvent;
11import org.bukkit.event.player.AsyncPlayerChatEvent;
12import org.bukkit.event.player.PlayerJoinEvent;
13import org.bukkit.event.player.PlayerMoveEvent;
14
15public class AuthMain implements Listener {
16
17 OblivionNetworks plugin = OblivionNetworks.getPlugin(OblivionNetworks.class);
18
19 @EventHandler
20 public void onJoin(PlayerJoinEvent event){
21 Player player = event.getPlayer();
22
23 if(!plugin.getConfig().contains("authcodes." + player.getUniqueId())){
24 GoogleAuthenticator gAuth = new GoogleAuthenticator();
25 GoogleAuthenticatorKey key = gAuth.createCredentials();
26
27 player.sendMessage("Auth code: " + key.getKey());
28 player.sendMessage("You must enter the code in a authenticator app");
29
30 plugin.getConfig().set("authcodes." + player.getUniqueId(), key.getKey());
31 plugin.saveConfig();
32 }else{
33 plugin.authlocked.add(player.getUniqueId());
34 player.sendMessage("Open auth app");
35 }
36 }
37
38 private boolean playerInputCode(Player player, int code) {
39 String secretKey = plugin.getConfig().getString("authcodes." + player.getUniqueId());
40
41 GoogleAuthenticator gAuth = new GoogleAuthenticator();
42 boolean authcodevallid = gAuth.authorize(secretKey, code);
43
44 if(authcodevallid){
45 plugin.authlocked.remove(player.getUniqueId());
46 return authcodevallid;
47 }
48 return authcodevallid;
49
50 }
51
52 @EventHandler
53 public void chat(AsyncPlayerChatEvent event){
54 Player player = event.getPlayer();
55 String message = event.getMessage();
56
57 if(plugin.authlocked.contains(player.getUniqueId())){
58 try{
59 Integer code = Integer.parseInt(message);
60 if(playerInputCode(player, code)){
61 plugin.authlocked.remove(player.getUniqueId());
62 player.sendMessage("Auth accepted");
63 }else {
64 player.sendMessage("Incorrect or expired code!");
65 }
66 }catch (Exception e){
67 player.sendMessage("Incorrect or expired code!");
68 }
69 event.setCancelled(true);
70 }
71 }
72
73 @EventHandler
74 public void move(PlayerMoveEvent event){
75 Player player = event.getPlayer();
76 if(plugin.authlocked.contains(player.getUniqueId())){
77 event.setCancelled(true);
78 }
79 }
80
81 @EventHandler
82 public void blockbreak(BlockBreakEvent event){
83 Player player = event.getPlayer();
84 if(plugin.authlocked.contains(player.getUniqueId())){
85 event.setCancelled(true);
86 }
87 }
88
89 @EventHandler
90 public void blockplace(BlockPlaceEvent event){
91 Player player = event.getPlayer();
92 if(plugin.authlocked.contains(player.getUniqueId())){
93 event.setCancelled(true);
94 }
95 }
96}
97
98
99[18:49:06 ERROR]: Could not pass event PlayerJoinEvent to OblivionCore v1.0
100org.bukkit.event.EventException: null
101 at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[server.jar:git-Spigot-dcd1643-e60fc34]
102 at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[server.jar:git-Spigot-dcd1643-e60fc34]
103 at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [server.jar:git-Spigot-dcd1643-e60fc34]
104 at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [server.jar:git-Spigot-dcd1643-e60fc34]
105 at net.minecraft.server.v1_12_R1.PlayerList.onPlayerJoin(PlayerList.java:346) [server.jar:git-Spigot-dcd1643-e60fc34]
106 at net.minecraft.server.v1_12_R1.PlayerList.a(PlayerList.java:166) [server.jar:git-Spigot-dcd1643-e60fc34]
107 at net.minecraft.server.v1_12_R1.LoginListener.b(LoginListener.java:159) [server.jar:git-Spigot-dcd1643-e60fc34]
108 at net.minecraft.server.v1_12_R1.LoginListener.e(LoginListener.java:57) [server.jar:git-Spigot-dcd1643-e60fc34]
109 at net.minecraft.server.v1_12_R1.NetworkManager.a(NetworkManager.java:233) [server.jar:git-Spigot-dcd1643-e60fc34]
110 at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:140) [server.jar:git-Spigot-dcd1643-e60fc34]
111 at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:845) [server.jar:git-Spigot-dcd1643-e60fc34]
112 at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [server.jar:git-Spigot-dcd1643-e60fc34]
113 at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [server.jar:git-Spigot-dcd1643-e60fc34]
114 at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [server.jar:git-Spigot-dcd1643-e60fc34]
115 at java.lang.Thread.run(Thread.java:748) [?:1.8.0_211]
116Caused by: java.lang.NoClassDefFoundError: com/warrenstrange/googleauth/GoogleAuthenticator
117 at oblv.mcspg.paxo.oblivioncore.authenticator.AuthMain.onJoin(AuthMain.java:24) ~[?:?]
118 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_211]
119 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_211]
120 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_211]
121 at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_211]
122 at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[server.jar:git-Spigot-dcd1643-e60fc34]
123 ... 14 more
124Caused by: java.lang.ClassNotFoundException: com.warrenstrange.googleauth.GoogleAuthenticator
125 at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[?:1.8.0_211]
126 at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:152) ~[server.jar:git-Spigot-dcd1643-e60fc34]
127 at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:100) ~[server.jar:git-Spigot-dcd1643-e60fc34]
128 at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_211]
129 at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_211]
130 at oblv.mcspg.paxo.oblivioncore.authenticator.AuthMain.onJoin(AuthMain.java:24) ~[?:?]
131 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_211]
132 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_211]
133 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_211]
134 at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_211]
135 at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[server.jar:git-Spigot-dcd1643-e60fc34]
136 ... 14 more
137[18:49:06 INFO]: Paxonsol[/127.0.0.1:57486] logged in with entity id 0 at ([world]-92.44304926568311, 120.0, 159.59808997142164)