mirror of
https://github.com/trainerlord/WorldSystem.git
synced 2024-11-29 12:55:11 +01:00
possible fix for getOfflinePlayer running in timeouts due to mojang
This commit is contained in:
parent
5b69c58bbb
commit
27b90b7343
@ -9,6 +9,7 @@ import de.butzlabben.world.event.WorldAddmemberEvent;
|
||||
import de.butzlabben.world.event.WorldDeleteEvent;
|
||||
import de.butzlabben.world.event.WorldRemovememberEvent;
|
||||
import de.butzlabben.world.util.PlayerPositions;
|
||||
import de.butzlabben.world.util.PlayerWrapper;
|
||||
import de.butzlabben.world.wrapper.SystemWorld;
|
||||
import de.butzlabben.world.wrapper.WorldPlayer;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
@ -39,7 +40,7 @@ public class WorldAdministrateCommand {
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]);
|
||||
OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]);
|
||||
WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname());
|
||||
if (a == null) {
|
||||
p.sendMessage(MessageConfig.getNotRegistered().replaceAll("%player", args[1]));
|
||||
@ -152,7 +153,7 @@ public class WorldAdministrateCommand {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]);
|
||||
OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]);
|
||||
WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname());
|
||||
if (a == null) {
|
||||
p.sendMessage(MessageConfig.getNotRegistered().replaceAll("%player", args[1]));
|
||||
@ -196,7 +197,7 @@ public class WorldAdministrateCommand {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]);
|
||||
OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]);
|
||||
WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname());
|
||||
if (!wc.isMember(a.getUniqueId())) {
|
||||
p.sendMessage(MessageConfig.getNoMemberOwn());
|
||||
@ -233,7 +234,7 @@ public class WorldAdministrateCommand {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]);
|
||||
OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]);
|
||||
WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname());
|
||||
if (!wc.isMember(a.getUniqueId())) {
|
||||
p.sendMessage(MessageConfig.getNoMemberOwn());
|
||||
@ -270,7 +271,7 @@ public class WorldAdministrateCommand {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]);
|
||||
OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]);
|
||||
WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname());
|
||||
if (!wc.isMember(a.getUniqueId())) {
|
||||
p.sendMessage(MessageConfig.getNoMemberOwn());
|
||||
@ -307,7 +308,7 @@ public class WorldAdministrateCommand {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]);
|
||||
OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]);
|
||||
WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname());
|
||||
if (!wc.isMember(a.getUniqueId())) {
|
||||
p.sendMessage(MessageConfig.getNoMemberOwn());
|
||||
|
@ -21,11 +21,11 @@ public class DependenceConfig {
|
||||
public DependenceConfig(String s) {
|
||||
OfflinePlayer op = null;
|
||||
try {
|
||||
op = Bukkit.getOfflinePlayer(UUID.fromString(s));
|
||||
op = PlayerWrapper.getOfflinePlayer(UUID.fromString(s));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
if (op == null) {
|
||||
op = Bukkit.getOfflinePlayer(s);
|
||||
op = PlayerWrapper.getOfflinePlayer(s);
|
||||
}
|
||||
uuid = op.getUniqueId();
|
||||
}
|
||||
@ -85,7 +85,7 @@ public class DependenceConfig {
|
||||
File dconfig = new File("plugins//WorldSystem//dependence.yml");
|
||||
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig);
|
||||
String uuid = this.uuid.toString();
|
||||
cfg.set("Dependences." + uuid + ".ActualName", Bukkit.getOfflinePlayer(this.uuid).getName());
|
||||
cfg.set("Dependences." + uuid + ".ActualName", PlayerWrapper.getOfflinePlayer(this.uuid).getName());
|
||||
try {
|
||||
cfg.save(dconfig);
|
||||
} catch (IOException e) {
|
||||
@ -102,7 +102,7 @@ public class DependenceConfig {
|
||||
id++;
|
||||
cfg.set("HighestID", id);
|
||||
cfg.set("Dependences." + uuid + ".ID", id);
|
||||
cfg.set("Dependences." + uuid + ".ActualName", Bukkit.getOfflinePlayer(this.uuid).getName());
|
||||
cfg.set("Dependences." + uuid + ".ActualName", PlayerWrapper.getOfflinePlayer(this.uuid).getName());
|
||||
try {
|
||||
cfg.save(dconfig);
|
||||
} catch (IOException e) {
|
||||
@ -158,6 +158,6 @@ public class DependenceConfig {
|
||||
}
|
||||
|
||||
public OfflinePlayer getOwner() {
|
||||
return Bukkit.getOfflinePlayer(uuid);
|
||||
return PlayerWrapper.getOfflinePlayer(uuid);
|
||||
}
|
||||
}
|
||||
|
@ -208,6 +208,12 @@ public class PluginConfig {
|
||||
return getConfig().getString("database.players_table_name");
|
||||
}
|
||||
|
||||
public static String getUUIDTableName() {
|
||||
return getConfig().getString("database.players_uuids");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getDatabaseType() {
|
||||
return getConfig().getString("database.type");
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ public class WorldConfig {
|
||||
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
|
||||
cfg.set("Informations.ID", dc.getID());
|
||||
cfg.set("Informations.Owner.PlayerUUID", uuid.toString());
|
||||
cfg.set("Informations.Owner.Actualname", Objects.requireNonNull(Bukkit.getOfflinePlayer(uuid)).getName());
|
||||
cfg.set("Informations.Owner.Actualname", Objects.requireNonNull(PlayerWrapper.getOfflinePlayer(uuid)).getName());
|
||||
cfg.set("Informations.template_key", template.getName());
|
||||
cfg.set("Settings.TNTDamage", false);
|
||||
cfg.set("Settings.Fire", false);
|
||||
@ -370,7 +370,7 @@ public class WorldConfig {
|
||||
public HashMap<UUID, String> getMembersWithNames() {
|
||||
HashMap<UUID, String> map = new HashMap<>();
|
||||
for (UUID uuid : permissions.keySet()) {
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
|
||||
OfflinePlayer op = PlayerWrapper.getOfflinePlayer(uuid);
|
||||
if (op == null || op.getName() == null) {
|
||||
if (PluginConfig.contactAuth()) {
|
||||
try {
|
||||
|
@ -22,7 +22,7 @@ public class PlayerOptionsGUI extends OrcInventory {
|
||||
|
||||
public PlayerOptionsGUI(Player loader, String otherPlayer, UUID other) {
|
||||
super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.player").replace("%player", otherPlayer), GuiConfig.getRows("options.player"), GuiConfig.isFill("options.player"));
|
||||
WorldPlayer wp = new WorldPlayer(Bukkit.getOfflinePlayer(other), loader.getWorld().getName());
|
||||
WorldPlayer wp = new WorldPlayer(PlayerWrapper.getOfflinePlayer(other), loader.getWorld().getName());
|
||||
loadItem("build", "/ws togglebuild " + otherPlayer, new BuildStatus(wp));
|
||||
loadItem("gamemode", "/ws togglegm " + otherPlayer, new GamemodeStatus(wp));
|
||||
loadItem("teleport", "/ws toggletp " + otherPlayer, new TeleportStatus(wp));
|
||||
|
@ -39,7 +39,7 @@ public class MoneyUtil {
|
||||
Preconditions.checkNotNull(uuid);
|
||||
Preconditions.checkNotNull(economy);
|
||||
Preconditions.checkArgument(money > 0, "Money must not be negative");
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
|
||||
OfflinePlayer op = PlayerWrapper.getOfflinePlayer(uuid);
|
||||
Economy economy = (Economy) MoneyUtil.economy;
|
||||
EconomyResponse response = economy.withdrawPlayer(op, money);
|
||||
if (!response.transactionSuccess()) {
|
||||
@ -52,7 +52,7 @@ public class MoneyUtil {
|
||||
Preconditions.checkNotNull(uuid);
|
||||
Preconditions.checkNotNull(economy);
|
||||
Preconditions.checkArgument(money > 0, "Money must not be negative");
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
|
||||
OfflinePlayer op = PlayerWrapper.getOfflinePlayer(uuid);
|
||||
Economy economy = (Economy) MoneyUtil.economy;
|
||||
return economy.getBalance(op) >= money;
|
||||
}
|
||||
|
97
src/main/java/de/butzlabben/world/util/PlayerWrapper.java
Normal file
97
src/main/java/de/butzlabben/world/util/PlayerWrapper.java
Normal file
@ -0,0 +1,97 @@
|
||||
package de.butzlabben.world.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import de.butzlabben.world.config.PluginConfig;
|
||||
import de.butzlabben.world.util.database.DatabaseProvider;
|
||||
import de.butzlabben.world.util.database.DatabaseUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerWrapper {
|
||||
|
||||
|
||||
private static final DatabaseUtil util = DatabaseProvider.instance.util;
|
||||
|
||||
static {
|
||||
checkTables();
|
||||
}
|
||||
|
||||
public static void checkTables() {
|
||||
if (!util.isConnectionAvailable())
|
||||
return;
|
||||
|
||||
String uuidTableName = PluginConfig.getUUIDTableName();
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("CREATE TABLE IF NOT EXISTS " + uuidTableName +
|
||||
" ( `uuid` VARCHAR(36) NOT NULL , `name` VARCHAR(36) NOT NULL , " +
|
||||
" PRIMARY KEY (`uuid`))");
|
||||
|
||||
util.executeUpdate(ps);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateDatabase(Player player) {
|
||||
if (!util.isConnectionAvailable())
|
||||
return;
|
||||
|
||||
Preconditions.checkNotNull(player);
|
||||
String playersTableName = PluginConfig.getPlayersTableName();
|
||||
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("REPLACE INTO " + playersTableName +
|
||||
" (uuid, name) VALUES (?, ?)");
|
||||
ps.setString(1, player.getUniqueId().toString());
|
||||
ps.setString(2, player.getName());
|
||||
|
||||
util.executeUpdate(ps);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static UUID getUUID(String name) {
|
||||
String uuidTableName = PluginConfig.getUUIDTableName();
|
||||
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("SELECT * FROM " + uuidTableName + " WHERE player=?");
|
||||
|
||||
ps.setString(1, name);
|
||||
ResultSet rs = util.executeQuery(ps);
|
||||
if (!rs.next())
|
||||
return null;
|
||||
|
||||
return UUID.fromString(rs.getString("uuid"));
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static OfflinePlayer getOfflinePlayer(String name) {
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
if(player != null)
|
||||
return PlayerWrapper.getOfflinePlayer(player.getUniqueId());
|
||||
|
||||
UUID uuid = PlayerWrapper.getUUID(name);
|
||||
if(uuid != null)
|
||||
return PlayerWrapper.getOfflinePlayer(uuid);
|
||||
|
||||
return PlayerWrapper.getOfflinePlayer(name);
|
||||
}
|
||||
|
||||
public static OfflinePlayer getOfflinePlayer(UUID uuid) {
|
||||
return PlayerWrapper.getOfflinePlayer(uuid);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -8,6 +8,7 @@
|
||||
import de.butzlabben.world.event.WorldLoadEvent;
|
||||
import de.butzlabben.world.event.WorldUnloadEvent;
|
||||
import de.butzlabben.world.util.PlayerPositions;
|
||||
import de.butzlabben.world.util.PlayerWrapper;
|
||||
import de.butzlabben.world.util.VersionUtil;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.*;
|
||||
@ -361,7 +362,7 @@ public class SystemWorld {
|
||||
}
|
||||
}, 10L);
|
||||
|
||||
OfflinePlayer owner = Bukkit.getOfflinePlayer(WorldConfig.getWorldConfig(worldname).getOwner());
|
||||
OfflinePlayer owner = PlayerWrapper.getOfflinePlayer(WorldConfig.getWorldConfig(worldname).getOwner());
|
||||
DependenceConfig dc = new DependenceConfig(owner);
|
||||
dc.setLastLoaded();
|
||||
}
|
||||
@ -422,7 +423,7 @@ public class SystemWorld {
|
||||
p.setGameMode(GameMode.CREATIVE);
|
||||
}
|
||||
|
||||
OfflinePlayer owner = Bukkit.getOfflinePlayer(WorldConfig.getWorldConfig(worldname).getOwner());
|
||||
OfflinePlayer owner = PlayerWrapper.getOfflinePlayer(WorldConfig.getWorldConfig(worldname).getOwner());
|
||||
DependenceConfig dc = new DependenceConfig(owner);
|
||||
dc.setLastLoaded();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user