Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
  • Loading branch information
ColdeZhang committed May 13, 2024
2 parents b5776aa + 4f752d1 commit 17af6a4
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 22 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.lunadeer</groupId>
<artifactId>Dominion</artifactId>
<version>1.23.9-beta</version>
<version>1.23.11-beta</version>
<packaging>jar</packaging>

<name>Dominion</name>
Expand Down Expand Up @@ -78,12 +78,12 @@
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.34.0</version>
<version>3.41.2.2</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.6.0</version>
<version>42.7.2</version>
</dependency>
<dependency>
<groupId>com.github.BlueMap-Minecraft</groupId>
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/cn/lunadeer/dominion/Dominion.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import cn.lunadeer.dominion.events.EnvironmentEvents;
import cn.lunadeer.dominion.events.PlayerEvents;
import cn.lunadeer.dominion.events.SelectPointEvents;
import cn.lunadeer.dominion.utils.*;
import cn.lunadeer.dominion.managers.ConfigManager;
import cn.lunadeer.dominion.managers.DatabaseManager;
import cn.lunadeer.dominion.utils.GiteaReleaseCheck;
import cn.lunadeer.dominion.utils.Scheduler;
import cn.lunadeer.dominion.utils.XLogger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -22,8 +26,8 @@ public void onEnable() {
// Plugin startup logic
instance = this;
config = new ConfigManager(this);
dbConnection = Database.createConnection();
Database.migrate();
dbConnection = DatabaseManager.createConnection();
DatabaseManager.migrate();
scheduler = new Scheduler(this);
AutoClean.run();
Cache.instance = new Cache();
Expand Down
56 changes: 49 additions & 7 deletions src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO;
import cn.lunadeer.dominion.utils.Notification;
import cn.lunadeer.dominion.utils.XLogger;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf;
import org.bukkit.event.player.PlayerTeleportEvent;

import java.time.LocalDateTime;
import java.util.Map;
Expand Down Expand Up @@ -376,12 +383,6 @@ public static void teleportToDominion(CommandSender sender, String[] args) {
}
}

Location location = dominionDTO.getTpLocation();
if (location == null) {
Notification.error(sender, "此领地没有设置传送点");
return;
}

LocalDateTime now = LocalDateTime.now();
LocalDateTime next_time = Cache.instance.NextTimeAllowTeleport.get(player.getUniqueId());
if (next_time != null) {
Expand All @@ -396,10 +397,51 @@ public static void teleportToDominion(CommandSender sender, String[] args) {
}
Cache.instance.NextTimeAllowTeleport.put(player.getUniqueId(), now.plusSeconds(Dominion.config.getTpCoolDown()));
Dominion.scheduler.region.runDelayed(Dominion.instance, (instance) -> {
Location location = dominionDTO.getTpLocation();
if (location == null) {
int x = (dominionDTO.getX1() + dominionDTO.getX2()) / 2;
int z = (dominionDTO.getZ1() + dominionDTO.getZ2()) / 2;
World world = Dominion.instance.getServer().getWorld(dominionDTO.getWorld());
location = new Location(world, x, player.getY(), z);
XLogger.warn("领地 " + dominionDTO.getName() + " 没有设置传送点,将传送到中心点");
}
if (player.isOnline()) {
player.teleportAsync(location);
doTeleportSafely(player, location);
Notification.info(player, "已将你传送到 " + dominionDTO.getName());
}
}, Dominion.config.getTpDelay() == 0 ? 1 : 20L * Dominion.config.getTpDelay());
}

private static void doTeleportSafely(Player player, Location location) {
location.getWorld().getChunkAtAsyncUrgently(location).thenAccept((chunk) -> {
int max_attempts = 512;
while (location.getBlock().isPassable()) {
location.setY(location.getY() - 1);
max_attempts--;
if (max_attempts <= 0) {
Notification.error(player, "传送目的地不安全,已取消传送");
return;
}
}
Block up1 = location.getBlock().getRelative(BlockFace.UP);
Block up2 = up1.getRelative(BlockFace.UP);
max_attempts = 512;
while (!(up1.isPassable() && !up1.isLiquid()) || !(up2.isPassable() && !up2.isLiquid())) {
location.setY(location.getY() + 1);
up1 = location.getBlock().getRelative(BlockFace.UP);
up2 = up1.getRelative(BlockFace.UP);
max_attempts--;
if (max_attempts <= 0) {
Notification.error(player, "传送目的地不安全,已取消传送");
return;
}
}
location.setY(location.getY() + 1);
if (location.getBlock().getRelative(BlockFace.DOWN).getType() == Material.LAVA) {
Notification.error(player, "传送目的地不安全,已取消传送");
return;
}
player.teleportAsync(location, PlayerTeleportEvent.TeleportCause.PLUGIN);
});
}
}
4 changes: 2 additions & 2 deletions src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.utils.Database;
import cn.lunadeer.dominion.managers.DatabaseManager;
import cn.lunadeer.dominion.utils.XLogger;
import org.bukkit.Location;
import org.bukkit.World;
Expand All @@ -18,7 +18,7 @@ public class DominionDTO {

private static List<DominionDTO> query(String sql) {
List<DominionDTO> dominions = new ArrayList<>();
try (ResultSet rs = Database.query(sql)) {
try (ResultSet rs = DatabaseManager.query(sql)) {
if (sql.contains("UPDATE") || sql.contains("DELETE") || sql.contains("INSERT")) {
// 如果是更新操作,重新加载缓存
Cache.instance.loadDominions();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cn.lunadeer.dominion.dtos;

import cn.lunadeer.dominion.utils.Database;
import cn.lunadeer.dominion.managers.DatabaseManager;
import cn.lunadeer.dominion.utils.XLogger;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -31,7 +31,7 @@ public PlayerDTO onJoin() {

private static List<PlayerDTO> query(String sql) {
List<PlayerDTO> players = new ArrayList<>();
try (ResultSet rs = Database.query(sql)) {
try (ResultSet rs = DatabaseManager.query(sql)) {
if (rs == null) return players;
while (rs.next()) {
Integer id = rs.getInt("id");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cn.lunadeer.dominion.dtos;

import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.utils.Database;
import cn.lunadeer.dominion.managers.DatabaseManager;
import cn.lunadeer.dominion.utils.XLogger;

import java.sql.ResultSet;
Expand Down Expand Up @@ -582,7 +582,7 @@ public PlayerPrivilegeDTO(UUID playerUUID, Integer domID,

private static List<PlayerPrivilegeDTO> query(String sql) {
List<PlayerPrivilegeDTO> players = new ArrayList<>();
try (ResultSet rs = Database.query(sql)) {
try (ResultSet rs = DatabaseManager.query(sql)) {
if (sql.contains("UPDATE") || sql.contains("DELETE") || sql.contains("INSERT")) {
// 如果是更新操作,重新加载缓存
Cache.instance.loadPlayerPrivileges();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.lunadeer.dominion.utils;
package cn.lunadeer.dominion.managers;

import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.utils.XLogger;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package cn.lunadeer.dominion.utils;
package cn.lunadeer.dominion.managers;

import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.utils.XLogger;

import java.sql.*;

public class Database {
public class DatabaseManager {

public static Connection createConnection() {
try {
Expand Down

0 comments on commit 17af6a4

Please sign in to comment.