Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into gradle
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/maven.yml
#	pom.xml
#	src/main/resources/plugin.yml
  • Loading branch information
HaHaWTH committed Dec 13, 2024
2 parents 280e441 + b630df8 commit 4bd22c1
Show file tree
Hide file tree
Showing 34 changed files with 214 additions and 107 deletions.
Empty file added .github/workflows/maven.yml
Empty file.
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,19 @@
10. Player login logic improvement to reduce lag
11. Automatically purge bot data
12. **Folia support (in active testing)**
13. Offhand Menu compatibility(Thats amazing)
14. **Velocity support (See [Velocity Support](./vc-support.md))**
15. Support Virtual Threads caching
16. Automatically fix portal stuck issue
17. Automatically login for Bedrock players(configurable)
18. Fix shulker box crash bug on legacy versions(MC 1.13-)
19. **H2 database support**
20. **100% compatibility with original authme and extensions**
21. More......
13. **Velocity support (See [Velocity Support](./vc-support.md))**
14. Support Virtual Threads caching
15. Automatically fix portal stuck issue
16. Automatically login for Bedrock players(configurable)
17. Fix shulker box crash bug on legacy versions(MC 1.13-)
18. **H2 database support**
19. **100% compatibility with original authme and extensions**
20. More......

**Download links:**
[Releases](https://github.com/HaHaWTH/AuthMeReReloaded/releases/latest)
[Actions(Dev builds, use at your own risk!)](https://github.com/HaHaWTH/AuthMeReReloaded/actions/workflows/maven.yml)

If you are using FRP(内网穿透) for your server, this plugin may help [HAProxy-Detector](https://github.com/HaHaWTH/HAProxy-Detector)

**Pull Requests and suggestions are welcome!**

## Building
Expand Down
Empty file added pom.xml
Empty file.
4 changes: 2 additions & 2 deletions src/main/java/fr/xephi/authme/AuthMe.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public class AuthMe extends JavaPlugin {
private static final int CLEANUP_INTERVAL = 5 * TICKS_PER_MINUTE;

// Version and build number values
private static String pluginVersion = "5.6.0-Fork";
private static String pluginVersion = "5.7.0-Fork";
private static final String pluginBuild = "b";
private static String pluginBuildNumber = "50";
private static String pluginBuildNumber = "53";
// Private instances
private EmailService emailService;
private CommandHandler commandHandler;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/fr/xephi/authme/api/v3/AuthMeApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* AuthMeApi authmeApi = AuthMeApi.getInstance();
* </code>
*/
@SuppressWarnings("unused")
public class AuthMeApi {

private static AuthMeApi singleton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.service.ValidationService.ValidationResult;
import fr.xephi.authme.settings.properties.SecuritySettings;
import org.bukkit.entity.Player;

import javax.inject.Inject;
Expand Down Expand Up @@ -42,11 +43,14 @@ public void runCommand(Player player, List<String> arguments) {
commonService.send(player, MessageKey.NOT_LOGGED_IN);
return;
}
// Check if the user has been verified or not
if (codeManager.isVerificationRequired(player)) {
codeManager.codeExistOrGenerateNew(name);
commonService.send(player, MessageKey.VERIFICATION_CODE_REQUIRED);
return;

if (commonService.getProperty(SecuritySettings.CHANGE_PASSWORD_EMAIL_VERIFICATION_REQUIRED)) {
// Check if the user has been verified or not
if (codeManager.isVerificationRequired(player)) {
codeManager.codeExistOrGenerateNew(name);
commonService.send(player, MessageKey.VERIFICATION_CODE_REQUIRED);
return;
}
}

String oldPassword = arguments.get(0);
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/fr/xephi/authme/data/VerificationCodeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;

import static fr.xephi.authme.AuthMe.getScheduler;

public class VerificationCodeManager implements SettingsDependent, HasCleanup {

private final EmailService emailService;
Expand Down Expand Up @@ -133,17 +135,19 @@ public void codeExistOrGenerateNew(String name) {
* @param name the name of the player to generate a code for
*/
private void generateCode(String name) {
DataSourceValue<String> emailResult = dataSource.getEmail(name);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy'年'MM'月'dd'日' HH:mm:ss");
Date date = new Date(System.currentTimeMillis());
if (emailResult.rowExists()) {
final String email = emailResult.getValue();
if (!Utils.isEmailEmpty(email)) {
String code = RandomStringUtils.generateNum(6); // 6 digits code
verificationCodes.put(name.toLowerCase(Locale.ROOT), code);
emailService.sendVerificationMail(name, email, code, dateFormat.format(date));
getScheduler().runTaskAsynchronously(() -> {
DataSourceValue<String> emailResult = dataSource.getEmail(name);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy'-'MM'-'dd'-' HH:mm:ss");
Date date = new Date(System.currentTimeMillis());
if (emailResult.rowExists()) {
final String email = emailResult.getValue();
if (!Utils.isEmailEmpty(email)) {
String code = RandomStringUtils.generateNum(6); // 6 digits code
verificationCodes.put(name.toLowerCase(Locale.ROOT), code);
emailService.sendVerificationMail(name, email, code, dateFormat.format(date));
}
}
}
});
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/fr/xephi/authme/listener/ListenerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ public boolean shouldCancelEvent(PlayerEvent event) {
* @param player the player to verify
* @return true if the associated event should be canceled, false otherwise
*/

public boolean shouldCancelEvent(Player player) {

return player != null && !checkAuth(player.getName()) && !PlayerUtils.isNpc(player);
}
@Override
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/fr/xephi/authme/listener/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.TeleportUtils;
import fr.xephi.authme.util.message.I18NUtils;
import fr.xephi.authme.util.message.MiniMessageUtils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
Expand Down Expand Up @@ -93,7 +95,6 @@ public class PlayerListener implements Listener {
@Inject
private QuickCommandsProtectionManager quickCommandsProtectionManager;


// Lowest priority to apply fast protection checks
@EventHandler(priority = EventPriority.LOWEST)
public void onAsyncPlayerPreLoginEventLowest(AsyncPlayerPreLoginEvent event) {
Expand Down Expand Up @@ -248,6 +249,11 @@ public void onPlayerQuit(PlayerQuitEvent event) {
}
}

// Remove data from locale map when player quit
if (settings.getProperty(PluginSettings.I18N_MESSAGES)) {
I18NUtils.removeLocale(player.getUniqueId());
}

if (antiBotService.wasPlayerKicked(player.getName())) {
return;
}
Expand Down Expand Up @@ -533,12 +539,4 @@ public void onPlayerInventoryClick(InventoryClickEvent event) {
event.setCancelled(true);
}
}
// @EventHandler(priority = EventPriority.LOWEST)
// public void onSwitchHand(PlayerSwapHandItemsEvent event) {
// Player player = event.getPlayer();
// if (!player.isSneaking() || !player.hasPermission("keybindings.use"))
// return;
// event.setCancelled(true);
// Bukkit.dispatchCommand(event.getPlayer(), "help");
// }
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package fr.xephi.authme.listener;

import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.PluginSettings;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;

import javax.inject.Inject;

Expand All @@ -26,12 +22,4 @@ public void onPlayerPickupItem(EntityPickupItemEvent event) {
}
}

@EventHandler(priority = EventPriority.LOWEST)
public void onSwitchHand(PlayerSwapHandItemsEvent event) {
Player player = event.getPlayer();
if (player.isSneaking() && player.hasPermission("keybindings.use") && settings.getProperty(PluginSettings.MENU_UNREGISTER_COMPATIBILITY)) {
event.setCancelled(true);
Bukkit.dispatchCommand(event.getPlayer(), "help");
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/fr/xephi/authme/listener/ServerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public void onPluginDisable(PluginDisableEvent event) {
} else if ("ProtocolLib".equalsIgnoreCase(pluginName)) {
protocolLibService.disable();
logger.warning("ProtocolLib has been disabled, unhooking packet adapters!");
} else if ("PlaceholderAPI".equalsIgnoreCase(pluginName)) {
pluginHookService.unhookPlaceholderApi();
logger.info("PlaceholderAPI has been disabled: unhooking placeholders");
}
}

Expand All @@ -74,6 +77,8 @@ public void onPluginEnable(PluginEnableEvent event) {
spawnLoader.loadCmiSpawn();
} else if ("ProtocolLib".equalsIgnoreCase(pluginName)) {
protocolLibService.setup();
} else if ("PlaceholderAPI".equalsIgnoreCase(pluginName)) {
pluginHookService.tryHookToPlaceholderApi();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import org.bukkit.GameMode;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import javax.inject.Inject;
import java.util.Locale;
Expand Down Expand Up @@ -208,7 +206,7 @@ private void processJoinSync(Player player, boolean isAuthAvailable) {
int blindTimeOut = (registrationTimeout <= 0) ? 99999 : registrationTimeout;

// AuthMeReReloaded - Fix potion apply on Folia
bukkitService.runTaskIfFolia(player,() -> player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindTimeOut, 2)));
bukkitService.runTaskIfFolia(player, () -> player.addPotionEffect(bukkitService.createBlindnessEffect(blindTimeOut)));
}
commandManager.runCommandsOnJoin(player);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import javax.inject.Inject;

Expand Down Expand Up @@ -75,7 +73,7 @@ private void applyLogoutEffect(Player player) {
// Apply Blindness effect
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2));
player.addPotionEffect(bukkitService.createBlindnessEffect(timeout));
}

// Set player's data to unauthenticated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void processSyncQuit(Player player, boolean wasLoggedIn) {
} else {
limboService.restoreData(player);
if (!UniversalScheduler.isFolia) { // AuthMeReReloaded - Fix #146 (Very stupid solution, but works)
player.saveData(); // #1238: Speed is sometimes not restored properly
// player.saveData(); // #1238: Speed is sometimes not restored properly
}
}
player.leaveVehicle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import fr.xephi.authme.settings.properties.RestrictionSettings;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import javax.inject.Inject;

Expand Down Expand Up @@ -150,7 +148,7 @@ private void performPostUnregisterActions(String name, Player player) {
private void applyBlindEffect(Player player) {
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2));
bukkitService.runTaskIfFolia(player, () -> player.addPotionEffect(bukkitService.createBlindnessEffect(timeout)));
}
}

Expand Down
18 changes: 17 additions & 1 deletion src/main/java/fr/xephi/authme/service/BukkitService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import javax.inject.Inject;
import java.util.Collection;
Expand Down Expand Up @@ -327,6 +329,16 @@ public <E extends Event> E createAndCallEvent(Function<Boolean, E> eventSupplier
return event;
}

/**
* Creates a PotionEffect with blindness for the given duration in ticks.
*
* @param timeoutInTicks duration of the effect in ticks
* @return blindness potion effect
*/
public PotionEffect createBlindnessEffect(int timeoutInTicks) {
return new PotionEffect(PotionEffectType.BLINDNESS, timeoutInTicks, 2);
}

/**
* Gets the world with the given name.
*
Expand Down Expand Up @@ -380,7 +392,11 @@ public void sendBungeeMessage(Player player, byte[] bytes) {
* @param bytes the message
*/
public void sendVelocityMessage(Player player, byte[] bytes) {
player.sendPluginMessage(authMe, "authmevelocity:main", bytes);
if (player != null) {
player.sendPluginMessage(authMe, "authmevelocity:main", bytes);
} else {
Bukkit.getServer().sendPluginMessage(authMe, "authmevelocity:main", bytes);
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/xephi/authme/service/GeoIpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class GeoIpService {
private volatile boolean downloading;

@Inject
GeoIpService(@DataFolder File dataFolder){
GeoIpService(@DataFolder File dataFolder) {
this.dataFile = dataFolder.toPath().resolve(DATABASE_FILE);

// Fires download of recent data or the initialization of the look up service
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/fr/xephi/authme/service/PluginHookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.output.ConsoleLoggerFactory;
import fr.xephi.authme.service.hook.papi.AuthMeExpansion;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
Expand All @@ -26,6 +28,8 @@ public class PluginHookService {
private Essentials essentials;
private Plugin cmi;
private MultiverseCore multiverse;
private PlaceholderAPIPlugin placeholderApi;
private AuthMeExpansion authMeExpansion;

/**
* Constructor.
Expand All @@ -38,6 +42,7 @@ public PluginHookService(PluginManager pluginManager) {
tryHookToEssentials();
tryHookToCmi();
tryHookToMultiverse();
tryHookToPlaceholderApi();
}

/**
Expand Down Expand Up @@ -133,6 +138,20 @@ public void tryHookToEssentials() {
}
}

/**
* Attempts to create a hook into PlaceholderAPI.
*/
public void tryHookToPlaceholderApi() {
try {
placeholderApi = getPlugin(pluginManager, "PlaceholderAPI", PlaceholderAPIPlugin.class);
authMeExpansion = new AuthMeExpansion();
authMeExpansion.register();
} catch (Exception | NoClassDefFoundError ignored) {
placeholderApi = null;
authMeExpansion = null;
}
}

/**
* Attempts to create a hook into CMI.
*/
Expand Down Expand Up @@ -180,6 +199,16 @@ public void unhookMultiverse() {
multiverse = null;
}

/**
* Unhooks from PlaceholderAPI.
*/
public void unhookPlaceholderApi() {
if (placeholderApi != null) {
authMeExpansion.unregister();
placeholderApi = null;
}
}

// ------
// Helpers
// ------
Expand Down
Loading

0 comments on commit 4bd22c1

Please sign in to comment.