Re-did formatting, removed some unused code and rewrote some excessive if statements
This commit is contained in:
parent
e9b13e085e
commit
b235928089
|
|
@ -3,9 +3,11 @@ package com.liteflags.auth;
|
|||
import com.liteflags.LiteFlags;
|
||||
import com.liteflags.data.maps.MapCache;
|
||||
import com.liteflags.util.Utilities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
@ -26,8 +28,8 @@ public class AuthTimer<taskID> {
|
|||
if (player.hasPermission("liteflags.authentication.success")) {
|
||||
AuthTimer.endTask(player);
|
||||
} else {
|
||||
player.sendMessage(Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.Authenticate").replace("%code%", (CharSequence)MapCache.reauthedPlayers.get(player.getUniqueId().toString()))));
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), LiteFlags.getInstance().getConfig().getString("Authenticate_Timer_Command").replace("%player%", player.getName()).replace("%code%", (CharSequence)MapCache.reauthedPlayers.get(player.getUniqueId().toString())));
|
||||
player.sendMessage(Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.Authenticate").replace("%code%", (CharSequence) MapCache.reauthedPlayers.get(player.getUniqueId().toString()))));
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), LiteFlags.getInstance().getConfig().getString("Authenticate_Timer_Command").replace("%player%", player.getName()).replace("%code%", (CharSequence) MapCache.reauthedPlayers.get(player.getUniqueId().toString())));
|
||||
this.timeRemaining = LiteFlags.getInstance().getConfig().getInt("Authenticate_Timer");
|
||||
}
|
||||
} else if (player.hasPermission("liteflags.authentication.success")) {
|
||||
|
|
@ -38,7 +40,7 @@ public class AuthTimer<taskID> {
|
|||
|
||||
}
|
||||
}, 0L, 20L);
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), LiteFlags.getInstance().getConfig().getString("Authenticate_Timer_Command").replace("%player%", player.getName()).replace("%code%", (CharSequence)MapCache.reauthedPlayers.get(player.getUniqueId().toString())));
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), LiteFlags.getInstance().getConfig().getString("Authenticate_Timer_Command").replace("%player%", player.getName()).replace("%code%", (CharSequence) MapCache.reauthedPlayers.get(player.getUniqueId().toString())));
|
||||
taskID.put(player.getUniqueId(), tid);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ package com.liteflags.auth;
|
|||
import com.liteflags.LiteFlags;
|
||||
import com.liteflags.data.maps.MapCache;
|
||||
import com.liteflags.util.Utilities;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
@ -14,8 +16,8 @@ public class Authentication {
|
|||
StringBuilder salt = new StringBuilder();
|
||||
Random rnd = new Random();
|
||||
|
||||
while(salt.length() < 6) {
|
||||
int index = (int)(rnd.nextFloat() * (float)randChars.length());
|
||||
while (salt.length() < 6) {
|
||||
int index = (int) (rnd.nextFloat() * (float) randChars.length());
|
||||
salt.append(randChars.charAt(index));
|
||||
}
|
||||
|
||||
|
|
@ -27,7 +29,7 @@ public class Authentication {
|
|||
if (!player.hasPermission("liteflags.authentication.success")) {
|
||||
MapCache.reauthedPlayers.put(player.getUniqueId().toString(), getAuthKey());
|
||||
AuthTimer.startTimer(player);
|
||||
player.sendMessage(Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.Authenticate").replace("%code%", (CharSequence)MapCache.reauthedPlayers.get(player.getUniqueId().toString()))));
|
||||
player.sendMessage(Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.Authenticate").replace("%code%", (CharSequence) MapCache.reauthedPlayers.get(player.getUniqueId().toString()))));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
package com.liteflags.commands;
|
||||
|
||||
public class AuthCMD {
|
||||
}
|
||||
|
|
@ -5,12 +5,14 @@ import com.liteflags.data.database.Database;
|
|||
import com.liteflags.data.database.Methods;
|
||||
import com.liteflags.data.maps.MapCache;
|
||||
import com.liteflags.util.Utilities;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
|
|
@ -77,10 +79,10 @@ public class FlagCMD implements CommandExecutor {
|
|||
int number = Integer.parseInt(removeTimeLetter);
|
||||
int timeInMin = this.convertTimeToMinutes(number, getLetter);
|
||||
long currentTime = TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis());
|
||||
int conTime = (int)currentTime + timeInMin;
|
||||
int conTime = (int) currentTime + timeInMin;
|
||||
StringBuilder reason = new StringBuilder();
|
||||
|
||||
for(int i = 2; i < args.length; ++i) {
|
||||
for (int i = 2; i < args.length; ++i) {
|
||||
if (i > 2) {
|
||||
reason.append(" ");
|
||||
}
|
||||
|
|
@ -88,15 +90,15 @@ public class FlagCMD implements CommandExecutor {
|
|||
reason.append(args[i]);
|
||||
}
|
||||
|
||||
Database.addFlag(target.getUniqueId(), (long)((int)TimeUnit.MINUTES.toSeconds((long)conTime)), reason.toString(), sender.getName(), Utilities.convertTime(timeInMin));
|
||||
Database.addFlag(target.getUniqueId(), (long) ((int) TimeUnit.MINUTES.toSeconds((long) conTime)), reason.toString(), sender.getName(), Utilities.convertTime(timeInMin));
|
||||
if (target.isOnline() && !MapCache.activeFlags.contains(target.getName())) {
|
||||
MapCache.activeFlags.add(target.getName());
|
||||
}
|
||||
|
||||
Iterator var25 = Bukkit.getOnlinePlayers().iterator();
|
||||
|
||||
while(var25.hasNext()) {
|
||||
Player staff = (Player)var25.next();
|
||||
while (var25.hasNext()) {
|
||||
Player staff = (Player) var25.next();
|
||||
if (staff.hasPermission("liteflags.alertflags")) {
|
||||
staff.sendMessage(Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.FlaggedPlayer").replace("%staff%", sender.getName()).replace("%player%", target.getName()).replace("%flaglength%", Utilities.convertTime(timeInMin)).replace("%reason%", reason.toString())));
|
||||
}
|
||||
|
|
@ -113,7 +115,7 @@ public class FlagCMD implements CommandExecutor {
|
|||
} else if (sender.hasPermission("liteflags.flagperm")) {
|
||||
StringBuilder reason = new StringBuilder();
|
||||
|
||||
for(int i = 2; i < args.length; ++i) {
|
||||
for (int i = 2; i < args.length; ++i) {
|
||||
if (i > 2) {
|
||||
reason.append(" ");
|
||||
}
|
||||
|
|
@ -128,8 +130,8 @@ public class FlagCMD implements CommandExecutor {
|
|||
|
||||
Iterator var21 = Bukkit.getOnlinePlayers().iterator();
|
||||
|
||||
while(var21.hasNext()) {
|
||||
Player staff = (Player)var21.next();
|
||||
while (var21.hasNext()) {
|
||||
Player staff = (Player) var21.next();
|
||||
if (staff.hasPermission("liteflags.alertflags")) {
|
||||
staff.sendMessage(Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.FlaggedPlayer").replace("%staff%", sender.getName()).replace("%player%", target.getName()).replace("%flaglength%", "Permanent").replace("%reason%", reason.toString())));
|
||||
}
|
||||
|
|
@ -148,19 +150,17 @@ public class FlagCMD implements CommandExecutor {
|
|||
} else {
|
||||
sender.sendMessage(Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.NoPermission")));
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd.getName().equalsIgnoreCase("flaglist")) {
|
||||
} else if (cmd.getName().equalsIgnoreCase("flaglist")) {
|
||||
if (sender.hasPermission("liteflags.staff")) {
|
||||
if (args.length == 0) {
|
||||
if (MapCache.activeFlags.size() > 0) {
|
||||
Iterator var17 = MapCache.activeFlags.iterator();
|
||||
|
||||
while(var17.hasNext()) {
|
||||
removeTimeLetter = (String)var17.next();
|
||||
while (var17.hasNext()) {
|
||||
removeTimeLetter = (String) var17.next();
|
||||
OfflinePlayer afPlayer = Bukkit.getServer().getOfflinePlayer(removeTimeLetter);
|
||||
int totalFlags = Methods.getTotalActiveFlags(afPlayer);
|
||||
Utilities.sendStaffHoverMessage(afPlayer, (Player)sender, Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.AlertActiveFlags").replace("%player%", afPlayer.getName()).replace("%totalactflags%", "" + totalFlags).replace("%consoleFlags%", "" + Methods.consoleFlags).replace("%staffFlags%", "" + Methods.staffFlags)));
|
||||
Utilities.sendStaffHoverMessage(afPlayer, (Player) sender, Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.AlertActiveFlags").replace("%player%", afPlayer.getName()).replace("%totalactflags%", "" + totalFlags).replace("%consoleFlags%", "" + Methods.consoleFlags).replace("%staffFlags%", "" + Methods.staffFlags)));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.GRAY + "No players have active flags.");
|
||||
|
|
@ -214,12 +214,12 @@ public class FlagCMD implements CommandExecutor {
|
|||
ResultSet flag = Database.getPlayerFlags(targetPlayer.getUniqueId());
|
||||
|
||||
label52:
|
||||
while(flag.next()) {
|
||||
long expireTime = TimeUnit.SECONDS.toMinutes((long)flag.getInt("expire_time"));
|
||||
long timeFlagged = TimeUnit.SECONDS.toMinutes((long)flag.getInt("time_flagged"));
|
||||
while (flag.next()) {
|
||||
long expireTime = TimeUnit.SECONDS.toMinutes((long) flag.getInt("expire_time"));
|
||||
long timeFlagged = TimeUnit.SECONDS.toMinutes((long) flag.getInt("time_flagged"));
|
||||
long currentTime = TimeUnit.SECONDS.toMinutes(System.currentTimeMillis() / 1000L);
|
||||
int convertedExpireTime = (int)expireTime - (int)currentTime;
|
||||
int convertedFlaggedTime = (int)currentTime - (int)timeFlagged;
|
||||
int convertedExpireTime = (int) expireTime - (int) currentTime;
|
||||
int convertedFlaggedTime = (int) currentTime - (int) timeFlagged;
|
||||
String flaggedBy = flag.getString("flagged_by");
|
||||
String flagLength = flag.getString("flag_length");
|
||||
String reason = flag.getString("reason");
|
||||
|
|
@ -227,13 +227,13 @@ public class FlagCMD implements CommandExecutor {
|
|||
TextComponent mainComponent = null;
|
||||
Iterator var20 = body.iterator();
|
||||
|
||||
while(true) {
|
||||
while(true) {
|
||||
while (true) {
|
||||
while (true) {
|
||||
if (!var20.hasNext()) {
|
||||
continue label52;
|
||||
}
|
||||
|
||||
String s = (String)var20.next();
|
||||
String s = (String) var20.next();
|
||||
s = s.replaceFirst("%player%", targetPlayer.getName());
|
||||
s = s.replaceFirst("%staff%", flaggedBy);
|
||||
s = s.replaceFirst("%flaglength%", flagLength);
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
package com.liteflags.data;
|
||||
|
||||
public class Data {
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.liteflags.data.database;
|
||||
|
||||
import com.liteflags.LiteFlags;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
|
@ -23,7 +24,7 @@ public class Database {
|
|||
}
|
||||
|
||||
public static void addFlag(UUID uuid, long expireTime, String reason, String flaggedBy, String flagLength) {
|
||||
int timeFlagged = (int)(System.currentTimeMillis() / 1000L);
|
||||
int timeFlagged = (int) (System.currentTimeMillis() / 1000L);
|
||||
String sql = "INSERT INTO player_flags (uuid, expire_time, reason, flagged_by, time_flagged, flag_length) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
|
||||
try {
|
||||
|
|
@ -99,7 +100,7 @@ public class Database {
|
|||
int i = 0;
|
||||
|
||||
try {
|
||||
for(ResultSet resultSet = getPlayerFlags(uuid); resultSet.next(); ++i) {
|
||||
for (ResultSet resultSet = getPlayerFlags(uuid); resultSet.next(); ++i) {
|
||||
}
|
||||
} catch (SQLException var3) {
|
||||
var3.printStackTrace();
|
||||
|
|
@ -224,7 +225,7 @@ public class Database {
|
|||
private static ResultSet getStringResult(String query, String... parameters) throws SQLException {
|
||||
PreparedStatement statement = DatabaseConnection.getConnection().prepareStatement(query);
|
||||
|
||||
for(int i = 1; i < parameters.length + 1; ++i) {
|
||||
for (int i = 1; i < parameters.length + 1; ++i) {
|
||||
statement.setString(i, parameters[i - 1]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.liteflags.data.database;
|
||||
|
||||
import com.liteflags.LiteFlags;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
|
@ -23,7 +24,7 @@ public class DatabaseConnection {
|
|||
|
||||
public void openConnection() throws SQLException {
|
||||
if (this.connection == null || this.connection.isClosed()) {
|
||||
synchronized(this) {
|
||||
synchronized (this) {
|
||||
if (this.connection == null || this.connection.isClosed()) {
|
||||
this.connection = DriverManager.getConnection("jdbc:" + this.drivers + "://" + this.ip + ":" + this.port + "/" + this.database, this.username, this.password);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@ package com.liteflags.data.database;
|
|||
|
||||
import com.liteflags.LiteFlags;
|
||||
import com.liteflags.util.Utilities;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class Methods {
|
||||
|
|
@ -17,15 +19,12 @@ public class Methods {
|
|||
try {
|
||||
ResultSet flag = Database.getActiveTime(player.getUniqueId());
|
||||
|
||||
while(flag.next()) {
|
||||
long expireTime = TimeUnit.SECONDS.toMinutes((long)flag.getInt("expire_time"));
|
||||
while (flag.next()) {
|
||||
long expireTime = TimeUnit.SECONDS.toMinutes((long) flag.getInt("expire_time"));
|
||||
long currentTime = TimeUnit.SECONDS.toMinutes(System.currentTimeMillis() / 1000L);
|
||||
int convertedExpireTime = (int)expireTime - (int)currentTime;
|
||||
if (convertedExpireTime >= 0) {
|
||||
return true;
|
||||
}
|
||||
int convertedExpireTime = (int) expireTime - (int) currentTime;
|
||||
|
||||
if (expireTime == 0L) {
|
||||
if (convertedExpireTime >= 0 || expireTime == 0L) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -44,23 +43,14 @@ public class Methods {
|
|||
try {
|
||||
ResultSet flag = Database.getActiveTime(player.getUniqueId());
|
||||
|
||||
while(flag.next()) {
|
||||
long expireTime = TimeUnit.SECONDS.toMinutes((long)flag.getInt("expire_time"));
|
||||
while (flag.next()) {
|
||||
long expireTime = TimeUnit.SECONDS.toMinutes((long) flag.getInt("expire_time"));
|
||||
long currentTime = TimeUnit.SECONDS.toMinutes(System.currentTimeMillis() / 1000L);
|
||||
int convertedExpireTime = (int)expireTime - (int)currentTime;
|
||||
String s;
|
||||
if (convertedExpireTime >= 0) {
|
||||
int convertedExpireTime = (int) expireTime - (int) currentTime;
|
||||
|
||||
if (convertedExpireTime >= 0 || expireTime == 0L) {
|
||||
++i;
|
||||
s = flag.getString("flagged_by");
|
||||
if (s.equalsIgnoreCase("console")) {
|
||||
++consoleFlags;
|
||||
} else {
|
||||
++staffFlags;
|
||||
}
|
||||
} else if (expireTime == 0L) {
|
||||
++i;
|
||||
s = flag.getString("flagged_by");
|
||||
if (s.equalsIgnoreCase("console")) {
|
||||
if (flag.getString("flagged_by").equalsIgnoreCase("console")) {
|
||||
++consoleFlags;
|
||||
} else {
|
||||
++staffFlags;
|
||||
|
|
@ -80,10 +70,11 @@ public class Methods {
|
|||
try {
|
||||
ResultSet flag = Database.getActiveTime(player.getUniqueId());
|
||||
|
||||
while(flag.next()) {
|
||||
long expireTime = TimeUnit.SECONDS.toMinutes((long)flag.getInt("expire_time"));
|
||||
while (flag.next()) {
|
||||
long expireTime = TimeUnit.SECONDS.toMinutes((long) flag.getInt("expire_time"));
|
||||
long currentTime = TimeUnit.SECONDS.toMinutes(System.currentTimeMillis() / 1000L);
|
||||
int convertedExpireTime = (int)expireTime - (int)currentTime;
|
||||
int convertedExpireTime = (int) expireTime - (int) currentTime;
|
||||
|
||||
if (convertedExpireTime >= 0) {
|
||||
String s = flag.getString("flagged_by");
|
||||
if (s.equalsIgnoreCase("console")) {
|
||||
|
|
@ -91,22 +82,20 @@ public class Methods {
|
|||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException var9) {
|
||||
var9.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public static void getPlayerFlags(OfflinePlayer targetPlayer) {
|
||||
}
|
||||
|
||||
public static int getRandomIntegerBetweenRange(int min, int max) {
|
||||
int x = (int)(Math.random() * (double)(max - min + 1)) + min;
|
||||
int x = (int) (Math.random() * (double) (max - min + 1)) + min;
|
||||
return x;
|
||||
}
|
||||
|
||||
static {
|
||||
playerFlagsHeader = Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.PlayerFlagsHeader").replace("%limit%", flagListLimit));
|
||||
playerFlagsHeader = Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.PlayerFlagsHeader")
|
||||
.replace("%limit%", flagListLimit));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,10 @@ import com.liteflags.data.database.Database;
|
|||
import com.liteflags.data.database.Methods;
|
||||
import com.liteflags.data.maps.MapCache;
|
||||
import com.liteflags.util.Utilities;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
|
@ -15,44 +17,54 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class ChatEvent implements Listener {
|
||||
private LiteFlags flags;
|
||||
|
||||
public ChatEvent(LiteFlags flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent e) {
|
||||
final Player player = e.getPlayer();
|
||||
if (MapCache.reauthedPlayers.containsKey(player.getUniqueId().toString())) {
|
||||
|
||||
if (!MapCache.reauthedPlayers.containsKey(player.getUniqueId().toString())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String value = MapCache.reauthedPlayers.get(player.getUniqueId().toString());
|
||||
|
||||
if (e.getMessage().equals(value)) {
|
||||
e.setCancelled(true);
|
||||
|
||||
player.sendMessage(Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.Authenticate_Success")));
|
||||
long time = TimeUnit.SECONDS.toMinutes(System.currentTimeMillis() / 1000L) + 5L;
|
||||
|
||||
final int min = LiteFlags.getInstance().getConfig().getInt("RandomReauth.MinNumber");
|
||||
final int max = LiteFlags.getInstance().getConfig().getInt("RandomReauth.MaxNumber");
|
||||
new Random();
|
||||
|
||||
final String timeAmount = LiteFlags.getInstance().getConfig().getString("RandomReauth.TimeFormat");
|
||||
(new BukkitRunnable() {
|
||||
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), LiteFlags.getInstance().getConfig().getString("Commands.TempAuthSuccess").replace("%player%", player.getName()).replace("%permission%", "liteflags.authentication.success").replace("%expiretime%", Methods.getRandomIntegerBetweenRange(min, max) + timeAmount.substring(0, 1).toLowerCase()));
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),
|
||||
LiteFlags.getInstance().getConfig().getString("Commands.TempAuthSuccess")
|
||||
.replace("%player%", player.getName())
|
||||
.replace("%permission%", "liteflags.authentication.success")
|
||||
.replace("%expiretime%",
|
||||
Methods.getRandomIntegerBetweenRange(min, max)
|
||||
+ timeAmount.substring(0, 1).toLowerCase()));
|
||||
}
|
||||
}).runTask(LiteFlags.getInstance());
|
||||
}.runTask(LiteFlags.getInstance());
|
||||
|
||||
MapCache.reauthedPlayers.remove(player.getUniqueId().toString());
|
||||
|
||||
if (Database.inPlayerCache(player.getUniqueId())) {
|
||||
long currentTime = TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis());
|
||||
int expireTime = 10080;
|
||||
int conTime = (int)currentTime + expireTime;
|
||||
Database.addFlag(player.getUniqueId(), (long)((int)TimeUnit.MINUTES.toSeconds((long)conTime)), "Possible Hacked Client - Logged out before authenticating.", "Console", "7 Days");
|
||||
int conTime = (int) currentTime + expireTime;
|
||||
|
||||
Database.addFlag(player.getUniqueId(), (long) ((int) TimeUnit.MINUTES.toSeconds((long) conTime)), "Possible Hacked Client - Logged out before authenticating.", "Console", "7 Days");
|
||||
Database.removePlayerCache(player.getUniqueId());
|
||||
}
|
||||
|
||||
} else {
|
||||
e.setCancelled(true);
|
||||
player.sendMessage(Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.Authenticate_Failed").replace("%code%", (CharSequence)MapCache.reauthedPlayers.get(player.getUniqueId().toString()))));
|
||||
player.sendMessage(Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.Authenticate_Failed").replace("%code%", (CharSequence) MapCache.reauthedPlayers.get(player.getUniqueId().toString()))));
|
||||
LiteFlags.getInstance().getLogger().info(player.getName() + " tried talking while authenticating: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import com.liteflags.auth.Authentication;
|
|||
import com.liteflags.data.database.Methods;
|
||||
import com.liteflags.data.maps.MapCache;
|
||||
import com.liteflags.util.Utilities;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
|
@ -13,11 +13,6 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class LoginEvent implements Listener {
|
||||
private LiteFlags flags;
|
||||
|
||||
public LoginEvent(LiteFlags flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLogin(PlayerJoinEvent e) {
|
||||
|
|
@ -26,18 +21,17 @@ public class LoginEvent implements Listener {
|
|||
Authentication.checkAuthStatus(player.getUniqueId());
|
||||
}
|
||||
|
||||
if (Methods.hasActiveFlags(player)) {
|
||||
if (!Methods.hasActiveFlags(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MapCache.activeFlags.add(player.getName());
|
||||
Iterator var3 = Bukkit.getOnlinePlayers().iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
Player staff = (Player)var3.next();
|
||||
if (staff.hasPermission("liteflags.alertflags") && !LiteFlags.getInstance().getConfig().getString("Messages.AlertActiveFlags").equalsIgnoreCase("disablethis")) {
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.hasPermission("liteflags.alertflags") && !LiteFlags.getInstance().getConfig().getString("Messages.AlertActiveFlags").equalsIgnoreCase("disablethis")) {
|
||||
int activeTotalFlags = Methods.getTotalActiveFlags(player);
|
||||
Utilities.sendStaffHoverMessage(player, staff, Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.AlertActiveFlags").replace("%player%", player.getName()).replace("%totalactflags%", "" + activeTotalFlags).replace("%consoleFlags%", "" + Methods.consoleFlags).replace("%staffFlags%", "" + Methods.staffFlags)));
|
||||
Utilities.sendStaffHoverMessage(player, onlinePlayer, Utilities.format(LiteFlags.getInstance().getConfig().getString("Messages.AlertActiveFlags").replace("%player%", player.getName()).replace("%totalactflags%", "" + activeTotalFlags).replace("%consoleFlags%", "" + Methods.consoleFlags).replace("%staffFlags%", "" + Methods.staffFlags)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public class LogoutEvent implements Listener {
|
|||
@EventHandler
|
||||
public void onPlayerLogout(PlayerQuitEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
|
||||
if (AuthTimer.taskID.containsKey(player.getUniqueId())) {
|
||||
AuthTimer.endTask(player);
|
||||
}
|
||||
|
|
@ -28,9 +29,7 @@ public class LogoutEvent implements Listener {
|
|||
MapCache.reauthedPlayers.remove(player.getUniqueId().toString());
|
||||
}
|
||||
|
||||
if (MapCache.activeFlags.contains(player.getName())) {
|
||||
MapCache.activeFlags.remove(player.getName());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.liteflags.events;
|
||||
|
||||
import com.liteflags.LiteFlags;
|
||||
import com.liteflags.data.maps.MapCache;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
|
@ -8,20 +7,9 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class MoveEvent implements Listener {
|
||||
private LiteFlags flags;
|
||||
|
||||
public MoveEvent(LiteFlags flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
if (MapCache.reauthedPlayers.containsKey(player.getUniqueId().toString())) {
|
||||
e.setCancelled(true);
|
||||
} else {
|
||||
e.setCancelled(false);
|
||||
}
|
||||
|
||||
e.setCancelled(MapCache.reauthedPlayers.containsKey(player.getUniqueId().toString()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.liteflags.util;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
|
@ -14,52 +15,26 @@ import org.bukkit.entity.Player;
|
|||
public class Utilities {
|
||||
public static String convertTime(int time) {
|
||||
int days = (int) TimeUnit.MINUTES.toDays(time);
|
||||
int hours = (int)(TimeUnit.MINUTES.toHours(time) - TimeUnit.DAYS.toHours(days));
|
||||
int minutes = (int)(TimeUnit.MINUTES.toMinutes(time) - TimeUnit.HOURS.toMinutes(hours) - TimeUnit.DAYS.toMinutes(days));
|
||||
String d = days + " day";
|
||||
String h = hours + " hour";
|
||||
String m = minutes + " minute";
|
||||
String c = ", ";
|
||||
if (days == 0) {
|
||||
if (hours == 0) {
|
||||
return minutes == 1 ? m : m + "s";
|
||||
} else if (hours == 1) {
|
||||
if (minutes == 1) {
|
||||
return h + c + m;
|
||||
} else {
|
||||
return minutes == 0 ? h : h + c + m + "s";
|
||||
int hours = (int) (TimeUnit.MINUTES.toHours(time) - TimeUnit.DAYS.toHours(days));
|
||||
int minutes = (int) (TimeUnit.MINUTES.toMinutes(time) - TimeUnit.HOURS.toMinutes(hours) - TimeUnit.DAYS.toMinutes(days));
|
||||
|
||||
String timeString = formatTime(days, " day");
|
||||
timeString += (timeString.length() == 0 ? "" : ", ") + formatTime(hours, " hour");
|
||||
timeString += (timeString.length() == 0 ? "" : ", ") + formatTime(minutes, " minute");
|
||||
|
||||
if (timeString.length() == 0) timeString = "0 minutes";
|
||||
|
||||
return timeString;
|
||||
}
|
||||
} else if (minutes == 1) {
|
||||
return h + "s" + c + m;
|
||||
} else {
|
||||
return minutes == 0 ? h + "s" : h + "s" + c + m + "s";
|
||||
}
|
||||
} else if (days == 1) {
|
||||
if (hours == 1) {
|
||||
if (minutes == 1) {
|
||||
return d + c + h + c + m;
|
||||
} else {
|
||||
return minutes == 0 ? d + c + h : d + c + h + c + m + "s";
|
||||
}
|
||||
} else if (minutes == 1) {
|
||||
return hours == 0 ? d + c + m : d + c + h + "s" + c + m;
|
||||
} else if (minutes == 0) {
|
||||
return hours == 0 ? d : d + c + h + "s";
|
||||
} else {
|
||||
return hours == 0 ? d + c + m + "s" : d + c + h + "s" + c + m + "s";
|
||||
}
|
||||
} else if (hours == 1) {
|
||||
if (minutes == 1) {
|
||||
return d + "s" + c + h + c + m;
|
||||
} else {
|
||||
return minutes == 0 ? d + "s" + c + h : d + "s" + c + h + c + m + "s";
|
||||
}
|
||||
} else if (minutes == 1) {
|
||||
return hours == 0 ? d + "s" + c + m : d + "s" + c + h + "s" + c + m;
|
||||
} else if (minutes == 0) {
|
||||
return hours == 0 ? d + "s" : d + "s" + c + h + "s";
|
||||
} else {
|
||||
return hours == 0 ? d + "s" + c + m + "s" : d + "s" + c + h + "s" + c + m + "s";
|
||||
|
||||
private static String formatTime(int value, String s) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
return "";
|
||||
case 1:
|
||||
return value + s;
|
||||
default:
|
||||
return value + s + "s";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user