+ added player uuid caching

+ added extreme paper speedup on sync mode, by disabling the chunk loading
This commit is contained in:
Peda 2020-12-28 01:30:59 +01:00
parent 27b90b7343
commit 0e180a0d50
11 changed files with 134 additions and 108 deletions

View File

@ -2,15 +2,8 @@ package de.butzlabben.world;
import de.butzlabben.world.autoupdater.AutoUpdater; import de.butzlabben.world.autoupdater.AutoUpdater;
import de.butzlabben.world.command.CommandRegistry; import de.butzlabben.world.command.CommandRegistry;
import de.butzlabben.world.config.DependenceConfig; import de.butzlabben.world.config.*;
import de.butzlabben.world.config.GuiConfig; import de.butzlabben.world.listener.*;
import de.butzlabben.world.config.MessageConfig;
import de.butzlabben.world.config.PluginConfig;
import de.butzlabben.world.config.SettingsConfig;
import de.butzlabben.world.listener.BlockListener;
import de.butzlabben.world.listener.CommandListener;
import de.butzlabben.world.listener.PlayerListener;
import de.butzlabben.world.listener.WorldEditListener;
import de.butzlabben.world.util.PapiExtension; import de.butzlabben.world.util.PapiExtension;
import de.butzlabben.world.util.PlayerPositions; import de.butzlabben.world.util.PlayerPositions;
import de.butzlabben.world.util.VersionUtil; import de.butzlabben.world.util.VersionUtil;
@ -18,16 +11,16 @@ import de.butzlabben.world.util.database.DatabaseProvider;
import de.butzlabben.world.wrapper.AsyncCreatorAdapter; import de.butzlabben.world.wrapper.AsyncCreatorAdapter;
import de.butzlabben.world.wrapper.CreatorAdapter; import de.butzlabben.world.wrapper.CreatorAdapter;
import de.butzlabben.world.wrapper.SystemWorld; import de.butzlabben.world.wrapper.SystemWorld;
import java.io.File;
import java.io.IOException;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
/** /**
* @author Butzlabben * @author Butzlabben
* @author Jubeki * @author Jubeki
@ -38,6 +31,7 @@ public class WorldSystem extends JavaPlugin {
private static boolean is1_13Plus = false; private static boolean is1_13Plus = false;
final private String version = this.getDescription().getVersion(); final private String version = this.getDescription().getVersion();
private CreatorAdapter creator; private CreatorAdapter creator;
public static void createConfigs() { public static void createConfigs() {
File folder = getInstance().getDataFolder(); File folder = getInstance().getDataFolder();
File dir = new File(folder + "/worldsources"); File dir = new File(folder + "/worldsources");
@ -120,6 +114,7 @@ public class WorldSystem extends JavaPlugin {
pm.registerEvents(new PlayerListener(), this); pm.registerEvents(new PlayerListener(), this);
pm.registerEvents(new BlockListener(), this); pm.registerEvents(new BlockListener(), this);
pm.registerEvents(new CommandListener(), this); pm.registerEvents(new CommandListener(), this);
pm.registerEvents(new WorldInitSkipSpawn(), this);
if (pm.getPlugin("WorldEdit") != null) if (pm.getPlugin("WorldEdit") != null)
pm.registerEvents(new WorldEditListener(), this); pm.registerEvents(new WorldEditListener(), this);
@ -159,11 +154,6 @@ public class WorldSystem extends JavaPlugin {
//this.getCommand("ws fire").setExecutor(new WorldFire()); //this.getCommand("ws fire").setExecutor(new WorldFire());
System.setProperty("bstats.relocatecheck", "false"); System.setProperty("bstats.relocatecheck", "false");
Metrics m = new Metrics(this); Metrics m = new Metrics(this);
m.addCustomChart(new Metrics.SingleLineChart("worlds", DependenceConfig::getHighestID)); m.addCustomChart(new Metrics.SingleLineChart("worlds", DependenceConfig::getHighestID));
@ -171,15 +161,15 @@ public class WorldSystem extends JavaPlugin {
AutoUpdater.startAsync(); AutoUpdater.startAsync();
// Choose right creatoradapter for #16 // Choose right creatoradapter for #16
/*if (Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null if (Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null
&& Bukkit.getPluginManager().getPlugin("WorldEdit") != null && Bukkit.getPluginManager().getPlugin("WorldEdit") != null
&& PluginConfig.loadWorldsASync() && PluginConfig.loadWorldsASync()
&& !is1_13Plus) {*/ && !is1_13Plus) {
try{
creator = new AsyncCreatorAdapter(); creator = new AsyncCreatorAdapter();
Bukkit.getConsoleSender() Bukkit.getConsoleSender()
.sendMessage(PluginConfig.getPrefix() + "Found FAWE! Worlds now will be created asynchronously"); .sendMessage(PluginConfig.getPrefix() + "Found FAWE! Worlds now will be created asynchronously");
}catch(Exception e) { } else {
creator = (c, sw, r) -> { creator = (c, sw, r) -> {
Bukkit.getWorlds().add(c.createWorld()); Bukkit.getWorlds().add(c.createWorld());
if (sw != null) if (sw != null)

View File

@ -79,7 +79,8 @@ public class CommandRegistry implements CommandExecutor {
case "fire": case "fire":
return settings.fireCommand(sender, command, label, args); return settings.fireCommand(sender, command, label, args);
default: default:
return false; //default command is better than the other one
return ws.mainCommand(sender, command, label, args);
} }
} }
} }

View File

@ -28,48 +28,48 @@ public class WorldAdministrateCommand {
public boolean delMemberCommand(CommandSender sender, Command command, String label, String[] args) { public boolean delMemberCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) { if (sender instanceof Player) {
Player p = (Player) sender; Player p = (Player) sender;
if (args.length < 2) { if (args.length < 2) {
p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws delmember <Player>")); p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws delmember <Player>"));
return false; return false;
}
DependenceConfig dc = new DependenceConfig(p);
if (!dc.hasWorld()) {
p.sendMessage(MessageConfig.getNoWorldOwn());
return false;
}
@SuppressWarnings("deprecation")
OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]);
WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname());
if (a == null) {
p.sendMessage(MessageConfig.getNotRegistered().replaceAll("%player", args[1]));
return false;
} else if (!wc.isMember(a.getUniqueId())) {
p.sendMessage(MessageConfig.getNoMemberOwn());
return false;
}
WorldRemovememberEvent event = new WorldRemovememberEvent(a.getUniqueId(), dc.getWorldname(), p);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return false;
if (a.isOnline()) {
Player t = (Player) a;
if (t.getWorld().getName().equals(new DependenceConfig(p).getWorldname())) {
t.teleport(PluginConfig.getSpawn(t));
t.setGameMode(PluginConfig.getSpawnGamemode());
} }
}
wc.removeMember(a.getUniqueId()); DependenceConfig dc = new DependenceConfig(p);
try { if (!dc.hasWorld()) {
wc.save(); p.sendMessage(MessageConfig.getNoWorldOwn());
} catch (IOException e) { return false;
p.sendMessage(MessageConfig.getUnknownError()); }
e.printStackTrace();
} @SuppressWarnings("deprecation")
p.sendMessage(MessageConfig.getMemberRemoved().replaceAll("%player", a.getName())); OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]);
WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname());
if (a == null) {
p.sendMessage(MessageConfig.getNotRegistered().replaceAll("%player", args[1]));
return false;
} else if (!wc.isMember(a.getUniqueId())) {
p.sendMessage(MessageConfig.getNoMemberOwn());
return false;
}
WorldRemovememberEvent event = new WorldRemovememberEvent(a.getUniqueId(), dc.getWorldname(), p);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return false;
if (a.isOnline()) {
Player t = (Player) a;
if (t.getWorld().getName().equals(new DependenceConfig(p).getWorldname())) {
t.teleport(PluginConfig.getSpawn(t));
t.setGameMode(PluginConfig.getSpawnGamemode());
}
}
wc.removeMember(a.getUniqueId());
try {
wc.save();
} catch (IOException e) {
p.sendMessage(MessageConfig.getUnknownError());
e.printStackTrace();
}
p.sendMessage(MessageConfig.getMemberRemoved().replaceAll("%player", a.getName()));
return true; return true;
} else { } else {
sender.sendMessage("No Console"); //TODO Get Config sender.sendMessage("No Console"); //TODO Get Config
@ -140,8 +140,11 @@ public class WorldAdministrateCommand {
} }
public boolean addMemberCommand(CommandSender sender, Command command, String label, String[] args) { public boolean addMemberCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) { if (!(sender instanceof Player)) {
Player p = (Player) sender; sender.sendMessage("No Console"); //TODO Get Config
return false;
}
Player p = (Player) sender;
if (args.length < 2) { if (args.length < 2) {
p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws addmember <Player>")); p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws addmember <Player>"));
return false; return false;
@ -176,11 +179,8 @@ public class WorldAdministrateCommand {
e.printStackTrace(); e.printStackTrace();
} }
p.sendMessage(MessageConfig.getMemberAdded().replaceAll("%player", a.getName())); p.sendMessage(MessageConfig.getMemberAdded().replaceAll("%player", a.getName()));
return true; return true;
} else {
sender.sendMessage("No Console"); //TODO Get Config
return false;
}
} }
public boolean toggleTeleportCommand(CommandSender sender, Command command, String label, String[] args) { public boolean toggleTeleportCommand(CommandSender sender, Command command, String label, String[] args) {
@ -196,7 +196,6 @@ public class WorldAdministrateCommand {
p.sendMessage(MessageConfig.getNoWorldOwn()); p.sendMessage(MessageConfig.getNoWorldOwn());
return false; return false;
} }
@SuppressWarnings("deprecation")
OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]); OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]);
WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname());
if (!wc.isMember(a.getUniqueId())) { if (!wc.isMember(a.getUniqueId())) {
@ -223,33 +222,33 @@ public class WorldAdministrateCommand {
public boolean toggleGamemodeCommand(CommandSender sender, Command command, String label, String[] args) { public boolean toggleGamemodeCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) { if (sender instanceof Player) {
Player p = (Player) sender; Player p = (Player) sender;
if (args.length < 2) { if (args.length < 2) {
p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws togglegm <Player>")); p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws togglegm <Player>"));
return false; return false;
} }
DependenceConfig dc = new DependenceConfig(p); DependenceConfig dc = new DependenceConfig(p);
if (!dc.hasWorld()) { if (!dc.hasWorld()) {
p.sendMessage(MessageConfig.getNoWorldOwn()); p.sendMessage(MessageConfig.getNoWorldOwn());
return false; return false;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]); OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]);
WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname());
if (!wc.isMember(a.getUniqueId())) { if (!wc.isMember(a.getUniqueId())) {
p.sendMessage(MessageConfig.getNoMemberOwn()); p.sendMessage(MessageConfig.getNoMemberOwn());
return false; return false;
} }
WorldPlayer wp = new WorldPlayer(a, dc.getWorldname()); WorldPlayer wp = new WorldPlayer(a, dc.getWorldname());
if (wp.isOwnerofWorld()) { if (wp.isOwnerofWorld()) {
p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner"); p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner");
return false; return false;
} }
if (wp.toggleGamemode()) { if (wp.toggleGamemode()) {
p.sendMessage(MessageConfig.getToggleGameModeEnabled().replaceAll("%player", a.getName())); p.sendMessage(MessageConfig.getToggleGameModeEnabled().replaceAll("%player", a.getName()));
} else { } else {
p.sendMessage(MessageConfig.getToggleGameModeDisabled().replaceAll("%player", a.getName())); p.sendMessage(MessageConfig.getToggleGameModeDisabled().replaceAll("%player", a.getName()));
} }
return true; return true;
} else { } else {
sender.sendMessage("No Console"); //TODO Get Config sender.sendMessage("No Console"); //TODO Get Config
@ -295,8 +294,8 @@ public class WorldAdministrateCommand {
} }
public boolean toggleBuildCommand(CommandSender sender, Command command, String label, String[] args) { public boolean toggleBuildCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) { if (sender instanceof Player) {
Player p = (Player) sender; Player p = (Player) sender;
if (args.length < 2) { if (args.length < 2) {
p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws togglebuild <Player>")); p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws togglebuild <Player>"));
return false; return false;
@ -324,10 +323,10 @@ public class WorldAdministrateCommand {
} else { } else {
p.sendMessage(MessageConfig.getToggleBuildDisabled().replaceAll("%player", a.getName())); p.sendMessage(MessageConfig.getToggleBuildDisabled().replaceAll("%player", a.getName()));
} }
return true; return true;
} else { } else {
sender.sendMessage("No Console"); //TODO Get Config sender.sendMessage("No Console"); //TODO Get Config
return false; return false;
}
} }
}
} }

View File

@ -1,5 +1,6 @@
package de.butzlabben.world.config; package de.butzlabben.world.config;
import de.butzlabben.world.util.PlayerWrapper;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -17,7 +18,6 @@ public class DependenceConfig {
setConfig(); setConfig();
} }
@SuppressWarnings("deprecation")
public DependenceConfig(String s) { public DependenceConfig(String s) {
OfflinePlayer op = null; OfflinePlayer op = null;
try { try {

View File

@ -3,6 +3,7 @@ package de.butzlabben.world.config;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import de.butzlabben.world.GameProfileBuilder; import de.butzlabben.world.GameProfileBuilder;
import de.butzlabben.world.util.PlayerWrapper;
import de.butzlabben.world.wrapper.WorldTemplate; import de.butzlabben.world.wrapper.WorldTemplate;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

View File

@ -10,6 +10,7 @@ import de.butzlabben.world.gui.playeroption.BuildStatus;
import de.butzlabben.world.gui.playeroption.GamemodeStatus; import de.butzlabben.world.gui.playeroption.GamemodeStatus;
import de.butzlabben.world.gui.playeroption.TeleportStatus; import de.butzlabben.world.gui.playeroption.TeleportStatus;
import de.butzlabben.world.gui.playeroption.WorldEditStatus; import de.butzlabben.world.gui.playeroption.WorldEditStatus;
import de.butzlabben.world.util.PlayerWrapper;
import de.butzlabben.world.wrapper.WorldPlayer; import de.butzlabben.world.wrapper.WorldPlayer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -4,6 +4,7 @@ import de.butzlabben.world.config.DependenceConfig;
import de.butzlabben.world.config.PluginConfig; import de.butzlabben.world.config.PluginConfig;
import de.butzlabben.world.config.WorldConfig; import de.butzlabben.world.config.WorldConfig;
import de.butzlabben.world.util.PlayerPositions; import de.butzlabben.world.util.PlayerPositions;
import de.butzlabben.world.util.PlayerWrapper;
import de.butzlabben.world.wrapper.SystemWorld; import de.butzlabben.world.wrapper.SystemWorld;
import de.butzlabben.world.wrapper.WorldPlayer; import de.butzlabben.world.wrapper.WorldPlayer;
import java.util.HashMap; import java.util.HashMap;
@ -25,6 +26,7 @@ public class PlayerListener implements Listener {
//#17 //#17
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onJoin(PlayerJoinEvent e) { public void onJoin(PlayerJoinEvent e) {
PlayerWrapper.updateDatabase(e.getPlayer());
if (PluginConfig.spawnTeleportation()) { if (PluginConfig.spawnTeleportation()) {
Player p = e.getPlayer(); Player p = e.getPlayer();
DependenceConfig dc = new DependenceConfig(p); DependenceConfig dc = new DependenceConfig(p);

View File

@ -0,0 +1,26 @@
package de.butzlabben.world.listener;
import de.butzlabben.world.config.WorldConfig;
import de.butzlabben.world.wrapper.WorldPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.world.WorldInitEvent;
import java.io.File;
import java.util.Objects;
public class WorldInitSkipSpawn implements Listener {
@EventHandler
public void worldInit(WorldInitEvent e) {
e.getWorld().setKeepSpawnInMemory(false);
}
}

View File

@ -1,6 +1,7 @@
package de.butzlabben.world.util; package de.butzlabben.world.util;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.sk89q.worldedit.bukkit.BukkitPlayer;
import de.butzlabben.world.config.PluginConfig; import de.butzlabben.world.config.PluginConfig;
import de.butzlabben.world.util.database.DatabaseProvider; import de.butzlabben.world.util.database.DatabaseProvider;
import de.butzlabben.world.util.database.DatabaseUtil; import de.butzlabben.world.util.database.DatabaseUtil;
@ -80,17 +81,17 @@ public class PlayerWrapper {
public static OfflinePlayer getOfflinePlayer(String name) { public static OfflinePlayer getOfflinePlayer(String name) {
Player player = Bukkit.getPlayer(name); Player player = Bukkit.getPlayer(name);
if(player != null) if(player != null)
return PlayerWrapper.getOfflinePlayer(player.getUniqueId()); return Bukkit.getOfflinePlayer(player.getUniqueId());
UUID uuid = PlayerWrapper.getUUID(name); UUID uuid = PlayerWrapper.getUUID(name);
if(uuid != null) if(uuid != null)
return PlayerWrapper.getOfflinePlayer(uuid); return Bukkit.getOfflinePlayer(uuid);
return PlayerWrapper.getOfflinePlayer(name); return Bukkit.getOfflinePlayer(name);
} }
public static OfflinePlayer getOfflinePlayer(UUID uuid) { public static OfflinePlayer getOfflinePlayer(UUID uuid) {
return PlayerWrapper.getOfflinePlayer(uuid); return Bukkit.getOfflinePlayer(uuid);
} }

View File

@ -18,6 +18,8 @@ public class AsyncCreatorAdapter implements CreatorAdapter {
// Create worlds async to close #16 // Create worlds async to close #16
@Override @Override
public void create(WorldCreator creator, SystemWorld sw, Runnable r) { public void create(WorldCreator creator, SystemWorld sw, Runnable r) {
TaskManager.IMP.async(() -> { TaskManager.IMP.async(() -> {
AsyncWorld world; AsyncWorld world;
if (Bukkit.getWorld(creator.name()) == null) if (Bukkit.getWorld(creator.name()) == null)

View File

@ -63,6 +63,9 @@ database:
worlds_table_name: worlds_positions worlds_table_name: worlds_positions
# How the table with the saved player positions on the normal worlds should be named # How the table with the saved player positions on the normal worlds should be named
players_table_name: player_positions players_table_name: player_positions
# how should the uuid cache be stored
players_uuids: players_uuids
# Configure here your mysql connection # Configure here your mysql connection
mysql_settings: mysql_settings:
host: 127.0.0.1 host: 127.0.0.1