Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'com.rock_mc'
version = '1.0-SNAPSHOT'
version = '1.0.2'

repositories {
mavenCentral()
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/rock_mc/syn/api/Verify.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.potion.PotionEffectType;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -105,6 +106,10 @@ public static boolean exec(Syn plugin, Logger logger, Player player, String code

PluginEventSender.sendJoinEvent(player, "歡迎 " + ChatColor.YELLOW + player.getDisplayName() + ChatColor.RESET + " 全新加入!");

player.removePotionEffect(PotionEffectType.BLINDNESS);
player.removePotionEffect(PotionEffectType.SLOW);
player.removePotionEffect(PotionEffectType.JUMP);

return true;
}
}
Expand Down
37 changes: 25 additions & 12 deletions src/main/java/com/rock_mc/syn/event/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.*;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -90,6 +92,18 @@ public void onPlayerLogin(PlayerLoginEvent event) throws IOException {
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, kickMsg);
}

private void removePlayerEffect(Player player) {
player.removePotionEffect(PotionEffectType.BLINDNESS);
player.removePotionEffect(PotionEffectType.SLOW);
player.removePotionEffect(PotionEffectType.JUMP);
}

private void addPlayerEffect(Player player) {
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Integer.MAX_VALUE, 0));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 255));
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 200));
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) throws IOException {
final Player player = event.getPlayer();
Expand All @@ -108,21 +122,32 @@ public void onPlayerJoin(PlayerJoinEvent event) throws IOException {
event.setJoinMessage(LoggerPlugin.PREFIX_GAME + "玩家 " + ChatColor.GREEN + "" + ChatColor.BOLD + name + ChatColor.RESET + " 取得女神 " + ChatColor.GOLD + Syn.APP_NAME + ChatColor.RESET + " 的允許進入伺服器。");
}

removePlayerEffect(player);

LOG_PLUGIN.sendMessage(player, "女神 " + ChatColor.GOLD + Syn.APP_NAME + ChatColor.RESET + " 輕輕地在你耳邊說:\n" + welcome.get((int) (Math.random() * welcome.size())));

} else if (player.isOp()) {
plugin.dbManager.addPlayerToAllowList(uuid);

removePlayerEffect(player);

event.setJoinMessage(LoggerPlugin.PREFIX_GAME + opWelcomeMsg);
LOG_PLUGIN.sendMessage(player, "女神 " + ChatColor.GOLD + Syn.APP_NAME + ChatColor.RESET + " 輕輕地在你耳邊說:\n" + welcome.get((int) (Math.random() * welcome.size())));
} else if (plugin.configManager.getConfig().getBoolean(Config.GUEST)) {

LOG_PLUGIN.logInfo("Guest mode is enabled");

removePlayerEffect(player);

event.setJoinMessage(LoggerPlugin.PREFIX_GAME + "訪客玩家 " + ChatColor.BOLD + name + ChatColor.RESET + " 取得女神 " + ChatColor.GOLD + Syn.APP_NAME + ChatColor.RESET + " 的暫時允許進入伺服器。");
} else {
LOG_PLUGIN.logInfo("Player " + name + " is not verified, freeze player.");

Location location = player.getLocation();
plugin.freezePlayerMap.put(player.getUniqueId(), location);

addPlayerEffect(player);

new WaitVerify(plugin, player).start();
}
}
Expand All @@ -146,18 +171,6 @@ public void onPluginKick(KickEvent event) {
player.kickPlayer(event.getMessage());
}

@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (!plugin.freezePlayerMap.containsKey(player.getUniqueId())) {
return;
}
if (!((LivingEntity) player).isOnGround()) {
return;
}
event.setCancelled(true);
}

@EventHandler
public void onPlayerDamage(EntityDamageEvent e) {
if (e.getEntity() instanceof Player player) {
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/rock_mc/syn/event/WaitVerify.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.rock_mc.syn.log.LoggerPlugin;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.potion.PotionEffectType;

public class WaitVerify extends Thread {

Expand All @@ -28,11 +28,16 @@ public WaitVerify(Syn plugin, Player newPlayer) {

@Override
public void run() {
LOG_PLUGIN.sendMessage(player, "女神 " + ChatColor.GOLD + Syn.APP_NAME + ChatColor.RESET + " 正守護著通往磐石的入口。她雙目炯炯有神,手持大斧,氣宇軒昂。世人若想進入磐石,就必須通過她的考驗與允許。");
LOG_PLUGIN.sendMessage(player, "女神 " + ChatColor.GOLD + Syn.APP_NAME + ChatColor.RESET + " 問道:「你是誰?你有創世神給你的 " + ChatColor.BOLD + "" + ChatColor.GOLD + "驗證碼" + ChatColor.RESET + " 嗎?」");
// LOG_PLUGIN.sendMessage(player, "女神 " + ChatColor.GOLD + Syn.APP_NAME + ChatColor.RESET + " 正守護著通往磐石的入口。她雙目炯炯有神,手持大斧,氣宇軒昂。世人若想進入磐石,就必須通過她的考驗與允許。");
// LOG_PLUGIN.sendMessage(player, "女神 " + ChatColor.GOLD + Syn.APP_NAME + ChatColor.RESET + " 問道:「你是誰?你有創世神給你的 " + ChatColor.BOLD + "" + ChatColor.GOLD + "驗證碼" + ChatColor.RESET + " 嗎?」");

int failTime = plugin.dbManager.getFailedAttempts(player.getUniqueId().toString());
LOG_PLUGIN.sendMessage(player, "女神 " + ChatColor.GOLD + Syn.APP_NAME + ChatColor.RESET + ":「最好趕快回答,你有 " + (MAX_INPUT_CODE_TIMES - (failTime - 1)) + " 次機會。」");
// LOG_PLUGIN.sendMessage(player, "女神 " + ChatColor.GOLD + Syn.APP_NAME + ChatColor.RESET + ":「最好趕快回答,你有 " + (MAX_INPUT_CODE_TIMES - (failTime - 1)) + " 次機會。」");

player.sendTitle("", "女神 " + ChatColor.GOLD + Syn.APP_NAME + ChatColor.RESET + " 正守護著通往磐石的入口。她雙目炯炯有神,手持大斧,氣宇軒昂。\n世人若想進入磐石,就必須通過她的考驗與允許。",
10, 100, 20);
player.sendTitle("", "女神 " + ChatColor.GOLD + Syn.APP_NAME + ChatColor.RESET + " 問道:「你是誰?你有創世神給你的 " + ChatColor.BOLD + "" + ChatColor.GOLD + "驗證碼" + ChatColor.RESET + " 嗎?」",
10, 100, 20);

long sleepTime = (long) (1000 * CHECK_TIME);
for (int i = 0; i * CHECK_TIME < MAX_WAIT_INPUT_CODE_SECONDS; i++) {
Expand All @@ -43,6 +48,7 @@ public void run() {
}

if (!plugin.freezePlayerMap.containsKey(player.getUniqueId())) {

break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,38 @@
import org.bukkit.entity.Player;
import org.bukkit.event.Event;

import java.util.Objects;

public class PluginEventSender {

public static void sendJoinEvent(Player player, String message) {
try {
Event joinEvent = new JoinEvent(false, player, message);
Bukkit.getPluginManager().callEvent(joinEvent);
} catch (java.lang.IllegalStateException e) {
Event joinEvent = new JoinEvent(true, player, message);
Bukkit.getPluginManager().callEvent(joinEvent);

try {
Event joinEvent = new JoinEvent(true, player, message);
Bukkit.getPluginManager().callEvent(joinEvent);
} catch (java.lang.IllegalStateException e2) {

Bukkit.getScheduler().runTask(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("Syn")), () -> {
player.sendMessage(message);
});
}
}
}

public static void sendKickEvent(Player player, String message) {
try {
Event kickEvent = new KickEvent(false, player, message);
Bukkit.getPluginManager().callEvent(kickEvent);
} catch (java.lang.IllegalStateException e) {
Event kickEvent = new KickEvent(true, player, message);
Bukkit.getPluginManager().callEvent(kickEvent);
}
// 確保在主線程執行踢出操作
Bukkit.getScheduler().runTask(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("Syn")), () -> {
try {
Event kickEvent = new KickEvent(false, player, message);
Bukkit.getPluginManager().callEvent(kickEvent);
} catch (Exception e) {
// 如果事件觸發失敗,直接踢出玩家
player.kickPlayer(message);
}
});
}
}