Refactor to make use of the new user bean.
This commit is contained in:
parent
41c5725ea8
commit
767d248ac8
10
api/src/main/java/com/alttd/essentia/request/Request.java
Normal file
10
api/src/main/java/com/alttd/essentia/request/Request.java
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package com.alttd.essentia.request;
|
||||
|
||||
public interface Request {
|
||||
|
||||
void accept();
|
||||
|
||||
void deny();
|
||||
|
||||
void cancel();
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.alttd.essentia.user;
|
||||
|
||||
import com.alttd.essentia.request.Request;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
|
|
@ -41,4 +42,8 @@ public interface User {
|
|||
|
||||
@ApiStatus.Internal
|
||||
void saving(boolean saving);
|
||||
|
||||
Request request();
|
||||
|
||||
void request(Request request);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package com.alttd.essentia.commands;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class AdminSubCommand extends SubCommand {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package com.alttd.essentia.commands;
|
|||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.user.User;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
@ -19,8 +19,8 @@ public abstract class PlayerSubCommand extends SubCommand {
|
|||
return true;
|
||||
}
|
||||
|
||||
return execute(player, PlayerConfig.getConfig(player), args);
|
||||
return execute(player, plugin.userManager().getUser(player), args);
|
||||
}
|
||||
|
||||
protected abstract boolean execute(Player player, PlayerConfig playerConfig, String... args);
|
||||
protected abstract boolean execute(Player player, User user, String... args);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,8 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FlyCommand extends AdminSubCommand {
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.events.EssentiaEvent;
|
||||
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import com.alttd.essentia.user.User;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
@ -17,8 +17,8 @@ public class BackCommand extends PlayerSubCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
Location back = playerConfig.getBackLocation(false);
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
Location back = user.getBackLocation(false);
|
||||
|
||||
if (back == null) {
|
||||
player.sendRichMessage(Config.NO_BACK_LOCATION);
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.events.EssentiaEvent;
|
||||
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import com.alttd.essentia.user.User;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
@ -17,8 +17,8 @@ public class DeathBackCommand extends PlayerSubCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
Location back = playerConfig.getBackLocation(true);
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
Location back = user.getBackLocation(true);
|
||||
|
||||
if (back == null) {
|
||||
player.sendRichMessage(Config.NO_DEATH_LOCATION);
|
||||
|
|
|
|||
|
|
@ -3,10 +3,9 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.events.EssentiaEvent;
|
||||
import com.alttd.essentia.events.PlayerRemoveHomeEvent;
|
||||
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
||||
import com.alttd.essentia.user.User;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
@ -17,7 +16,7 @@ public class DelHomeCommand extends PlayerSubCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
// TODO -- subcommand to remove other player homes
|
||||
// if (args.length > 1) {
|
||||
// if (!player.hasPermission("essentia.command.delhome.other")) {
|
||||
|
|
@ -26,7 +25,7 @@ public class DelHomeCommand extends PlayerSubCommand {
|
|||
// }
|
||||
|
||||
String home = (args.length > 0) ? args[0] : "home";
|
||||
if (!playerConfig.hasHome(home)) {
|
||||
if (!user.hasHome(home)) {
|
||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.unparsed("home", home));
|
||||
return true;
|
||||
}
|
||||
|
|
@ -34,7 +33,7 @@ public class DelHomeCommand extends PlayerSubCommand {
|
|||
if (!event.callEvent()) {
|
||||
return true;
|
||||
}
|
||||
playerConfig.setHome(home, null);
|
||||
user.setHome(home, null);
|
||||
player.sendRichMessage(Config.HOME_DELETED, Placeholder.unparsed("home", home));
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,10 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.events.EssentiaEvent;
|
||||
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
||||
import com.alttd.essentia.events.PlayerTeleportHomeEvent;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import com.alttd.essentia.user.User;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
|
|
@ -24,19 +23,14 @@ public class HomeCommand extends PlayerSubCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
String home = null;
|
||||
if (args.length == 0) {
|
||||
int count = playerConfig.getHomeCount();
|
||||
if (count == 0) {
|
||||
if (player.getBedSpawnLocation() != null) {
|
||||
home = "bed";
|
||||
}
|
||||
} else if (count == 1) {
|
||||
home = playerConfig.getConfigurationSection("home").getKeys(false)
|
||||
.stream().findFirst().orElse(null);
|
||||
int count = user.getHomeCount();
|
||||
if (count <= 1) {
|
||||
home = user.getHomes().stream().findFirst().orElse(null);
|
||||
} else {
|
||||
player.sendRichMessage(Config.SPECIFY_HOME, Placeholder.unparsed("homelist", String.join(", ", playerConfig.getHomeList())));
|
||||
player.sendRichMessage(Config.SPECIFY_HOME, Placeholder.unparsed("homelist", String.join(", ", user.getHomes())));
|
||||
return true;
|
||||
}
|
||||
if (home == null || home.isEmpty()) {
|
||||
|
|
@ -54,8 +48,7 @@ public class HomeCommand extends PlayerSubCommand {
|
|||
// }
|
||||
// }
|
||||
|
||||
Location homeLoc = home.equalsIgnoreCase("bed") ?
|
||||
player.getBedSpawnLocation() : playerConfig.getHome(home);
|
||||
Location homeLoc = user.getHome(home);
|
||||
if (homeLoc == null) {
|
||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
|
||||
return true;
|
||||
|
|
@ -77,7 +70,7 @@ public class HomeCommand extends PlayerSubCommand {
|
|||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (args.length == 1) {
|
||||
return PlayerConfig.getConfig((Player) sender).getMatchingHomeNames(args[0]);
|
||||
return plugin.userManager().getUser((Player) sender).getMatchingHomeNames(args[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.user.User;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ public class HomeListCommand extends PlayerSubCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
// TODO - subcommand to list other homes
|
||||
// if (args.length > 0) {
|
||||
// if (!player.hasPermission("essentia.command.homes.other")) {
|
||||
|
|
@ -23,7 +23,7 @@ public class HomeListCommand extends PlayerSubCommand {
|
|||
// }
|
||||
|
||||
// TODO - clickable homes that run /home <name>
|
||||
player.sendRichMessage(Config.HOME_LIST, Placeholder.unparsed("homelist", String.join(", ", playerConfig.getHomeList())));
|
||||
player.sendRichMessage(Config.HOME_LIST, Placeholder.unparsed("homelist", String.join(", ", user.getHomes())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,9 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.events.EssentiaEvent;
|
||||
import com.alttd.essentia.events.PlayerSetHomeEvent;
|
||||
import com.alttd.essentia.events.PlayerTeleportHomeEvent;
|
||||
import com.alttd.essentia.user.User;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -19,7 +18,7 @@ public class SetHomeCommand extends PlayerSubCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
// TODO -- subcommand to allow setting other player homes
|
||||
// if (args.length > 1) {
|
||||
// if (!player.hasPermission("essentia.command.sethome.other")) {
|
||||
|
|
@ -28,13 +27,13 @@ public class SetHomeCommand extends PlayerSubCommand {
|
|||
// }
|
||||
|
||||
String home = (args.length > 0) ? args[0] : "home";
|
||||
if (home.equalsIgnoreCase("bed") || home.contains(".")) {
|
||||
if (home.contains(".")) {
|
||||
player.sendRichMessage(Config.INVALID_HOME_NAME);
|
||||
return true;
|
||||
}
|
||||
|
||||
int limit = 5; // TODO -- player home limits hardcoded for now
|
||||
int count = playerConfig.getHomeCount();
|
||||
int count = user.getHomeCount();
|
||||
if (limit >= 0 && count >= limit) {
|
||||
player.sendRichMessage(Config.HOME_SET_MAX, Placeholder.unparsed("limit", String.valueOf(limit)));
|
||||
return true;
|
||||
|
|
@ -44,7 +43,7 @@ public class SetHomeCommand extends PlayerSubCommand {
|
|||
if (!event.callEvent()) {
|
||||
return true;
|
||||
}
|
||||
playerConfig.setHome(home, homeLoc);
|
||||
user.setHome(home, homeLoc);
|
||||
player.sendRichMessage(Config.HOME_SET, Placeholder.unparsed("home", home));
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,10 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.events.EssentiaEvent;
|
||||
import com.alttd.essentia.events.PlayerSetHomeEvent;
|
||||
import com.alttd.essentia.events.PlayerTeleportSpawnEvent;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import com.alttd.essentia.user.User;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -19,7 +18,7 @@ public class SpawnCommand extends PlayerSubCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
World world = plugin.getServer().getWorld(Config.SPAWN_WORLD);
|
||||
if (world == null) {
|
||||
player.sendRichMessage("<red>Could not get the configured spawn world! contact and administrator");
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.request.EssentiaRequest;
|
||||
import com.alttd.essentia.request.Request;
|
||||
import com.alttd.essentia.user.User;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TeleportAcceptCommand extends PlayerSubCommand {
|
||||
|
|
@ -14,8 +15,8 @@ public class TeleportAcceptCommand extends PlayerSubCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
Request request = playerConfig.request();
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
Request request = user.request();
|
||||
if (request == null) {
|
||||
player.sendRichMessage(Config.NO_PENDING_REQUESTS);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.request.EssentiaRequest;
|
||||
import com.alttd.essentia.request.Request;
|
||||
import com.alttd.essentia.user.User;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TeleportDenyCommand extends PlayerSubCommand {
|
||||
|
|
@ -14,8 +15,8 @@ public class TeleportDenyCommand extends PlayerSubCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
Request request = playerConfig.request();
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
Request request = user.request();
|
||||
if (request == null) {
|
||||
player.sendRichMessage(Config.NO_PENDING_REQUESTS);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.request.TeleportRequest;
|
||||
import com.alttd.essentia.request.TeleportEssentiaRequest;
|
||||
import com.alttd.essentia.user.User;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
@ -23,7 +23,7 @@ public class TeleportRequestCommand extends PlayerSubCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
if (args.length < 1) {
|
||||
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED);
|
||||
return true;
|
||||
|
|
@ -44,18 +44,18 @@ public class TeleportRequestCommand extends PlayerSubCommand {
|
|||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
PlayerConfig targetConfig = PlayerConfig.getConfig(target);
|
||||
if (targetConfig.request() != null) {
|
||||
User targetUser = plugin.userManager().getUser(target);
|
||||
if (targetUser.request() != null) {
|
||||
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!targetConfig.allowTeleports()) {
|
||||
if (!targetUser.allowTeleports()) {
|
||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
||||
targetConfig.request(new TeleportRequest(plugin, player, target));
|
||||
targetUser.request(new TeleportEssentiaRequest(plugin, player, target));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.request.TeleportHereRequest;
|
||||
import com.alttd.essentia.request.TeleportRequest;
|
||||
import com.alttd.essentia.request.TeleportHereEssentiaRequest;
|
||||
import com.alttd.essentia.user.User;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
@ -24,7 +23,7 @@ public class TeleportRequestHereCommand extends PlayerSubCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
if (args.length < 1) {
|
||||
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED);
|
||||
return true;
|
||||
|
|
@ -45,18 +44,18 @@ public class TeleportRequestHereCommand extends PlayerSubCommand {
|
|||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
PlayerConfig targetConfig = PlayerConfig.getConfig(target);
|
||||
if (targetConfig.request() != null) {
|
||||
User targetUser = plugin.userManager().getUser(target);
|
||||
if (targetUser.request() != null) {
|
||||
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!targetConfig.allowTeleports()) {
|
||||
if (!targetUser.allowTeleports()) {
|
||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
||||
targetConfig.request(new TeleportHereRequest(plugin, player, target));
|
||||
targetUser.request(new TeleportHereEssentiaRequest(plugin, player, target));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.user.User;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
|
|
@ -16,10 +16,10 @@ public class TeleportToggleCommand extends PlayerSubCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
playerConfig.setAllowTeleports(!playerConfig.allowTeleports());
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
user.setAllowTeleports(!user.allowTeleports());
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(playerConfig.allowTeleports()))
|
||||
Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(user.allowTeleports()))
|
||||
);
|
||||
player.sendRichMessage(Config.TELEPORT_TOGGLE_SET, placeholders);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1,186 +0,0 @@
|
|||
package com.alttd.essentia.configuration;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.request.Request;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlayerConfig extends YamlConfiguration {
|
||||
|
||||
private static final Map<Player, PlayerConfig> configs = new HashMap<>();
|
||||
|
||||
public static PlayerConfig getConfig(Player player) {
|
||||
synchronized (configs) {
|
||||
return configs.computeIfAbsent(player, k -> new PlayerConfig(player));
|
||||
}
|
||||
}
|
||||
|
||||
public static void remove(Player player) {
|
||||
synchronized (configs) {
|
||||
configs.remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeAll() {
|
||||
synchronized (configs) {
|
||||
configs.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private final File file;
|
||||
private final Object saveLock = new Object();
|
||||
private final OfflinePlayer player;
|
||||
@Getter @Setter private Request request;
|
||||
|
||||
private PlayerConfig(Player player) {
|
||||
super();
|
||||
this.player = player;
|
||||
this.file = new File(EssentiaPlugin.instance().getDataFolder(), "PlayerData" + File.separator + player.getUniqueId() + ".yml");
|
||||
reload();
|
||||
}
|
||||
|
||||
private void reload() {
|
||||
synchronized (saveLock) {
|
||||
try {
|
||||
load(file);
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void save() {
|
||||
synchronized (saveLock) {
|
||||
try {
|
||||
save(file);
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Location getStoredLocation(String path) {
|
||||
if (get(path) == null) {
|
||||
return null;
|
||||
}
|
||||
World world = Bukkit.getWorld(getString(path + ".world", ""));
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
double x = getDouble(path + ".x");
|
||||
double y = getDouble(path + ".y");
|
||||
double z = getDouble(path + ".z");
|
||||
float pitch = (float) getDouble(path + ".pitch");
|
||||
float yaw = (float) getDouble(path + ".yaw");
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
void setStoredLocation(String path, Location location) {
|
||||
if (location == null) {
|
||||
set(path, null);
|
||||
save();
|
||||
return;
|
||||
}
|
||||
set(path + ".world", location.getWorld().getName());
|
||||
set(path + ".x", location.getX());
|
||||
set(path + ".y", location.getY());
|
||||
set(path + ".z", location.getZ());
|
||||
set(path + ".pitch", location.getPitch());
|
||||
set(path + ".yaw", location.getYaw());
|
||||
save();
|
||||
}
|
||||
|
||||
public Location getBackLocation(boolean death) {
|
||||
return getStoredLocation(death ? "teleports.death" : "teleports.back");
|
||||
}
|
||||
|
||||
public void setBackLocation(boolean death, Location location) {
|
||||
setStoredLocation(death ? "teleports.death" : "teleports.back", location);
|
||||
}
|
||||
|
||||
public boolean hasHome(String name) {
|
||||
ConfigurationSection section = getConfigurationSection("home." + name);
|
||||
return section != null;
|
||||
}
|
||||
|
||||
public Location getHome(String name) {
|
||||
return getStoredLocation("home." + name);
|
||||
}
|
||||
|
||||
|
||||
public void setHome(String name, Location location) {
|
||||
setStoredLocation("home." + name, location);
|
||||
}
|
||||
|
||||
public int getHomeCount() {
|
||||
ConfigurationSection section = getConfigurationSection("home");
|
||||
if (section == null) {
|
||||
return 0;
|
||||
}
|
||||
return section.getKeys(false).size();
|
||||
}
|
||||
|
||||
public List<String> getMatchingHomeNames(String name) {
|
||||
ConfigurationSection section = getConfigurationSection("home");
|
||||
if (section == null) {
|
||||
return null;
|
||||
}
|
||||
List<String> list = section.getValues(false).keySet().stream()
|
||||
.filter(home -> home.toLowerCase().startsWith(name.toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (player.getBedSpawnLocation() != null && "bed".startsWith(name.toLowerCase()))
|
||||
list.add("bed");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public Map<String, Location> getHomeData() {
|
||||
ConfigurationSection section = getConfigurationSection("home");
|
||||
if (section == null) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Location> map = new HashMap<>();
|
||||
for (String key : section.getValues(false).keySet()) {
|
||||
map.put(key, getHome(key));
|
||||
}
|
||||
if (player.getBedSpawnLocation() != null)
|
||||
map.put("bed", player.getBedSpawnLocation());
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public List<String> getHomeList() {
|
||||
ConfigurationSection section = getConfigurationSection("home");
|
||||
if (section == null) {
|
||||
return null;
|
||||
}
|
||||
List<String> list = new ArrayList<>(section.getValues(false).keySet());
|
||||
if (player.getBedSpawnLocation() != null)
|
||||
list.add("bed");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public boolean allowTeleports() {
|
||||
return getBoolean("allow-teleports", true);
|
||||
}
|
||||
|
||||
public void setAllowTeleports(boolean allowTeleports) {
|
||||
set("allow-teleports", allowTeleports);
|
||||
save();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ package com.alttd.essentia.listeners;
|
|||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.user.User;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
|
@ -36,8 +36,8 @@ public class PlayerListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
PlayerConfig playerConfig = PlayerConfig.getConfig(player);
|
||||
playerConfig.setBackLocation(true, player.getLocation());
|
||||
User user = plugin.userManager().getUser(player);
|
||||
user.setBackLocation(true, player.getLocation());
|
||||
player.sendRichMessage(Config.BACK_DEATH_HINT);
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +57,8 @@ public class PlayerListener implements Listener {
|
|||
|
||||
// only save location if teleporting more than 5 blocks
|
||||
if (!to.getWorld().equals(from.getWorld()) || to.distanceSquared(from) > 25) {
|
||||
PlayerConfig.getConfig(player).setBackLocation(false, event.getFrom());
|
||||
User user = plugin.userManager().getUser(player);
|
||||
user.setBackLocation(false, event.getFrom());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.alttd.essentia.request;
|
|||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.tasks.RequestTimeout;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import lombok.Getter;
|
||||
|
|
@ -10,7 +9,7 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class Request {
|
||||
public abstract class EssentiaRequest implements Request {
|
||||
|
||||
private final EssentiaPlugin plugin;
|
||||
@Getter private final Player requester;
|
||||
|
|
@ -19,7 +18,7 @@ public abstract class Request {
|
|||
|
||||
TagResolver placeholders;
|
||||
|
||||
public Request(EssentiaPlugin plugin, Player requester, Player target) {
|
||||
public EssentiaRequest(EssentiaPlugin plugin, Player requester, Player target) {
|
||||
this.plugin = plugin;
|
||||
this.requester = requester;
|
||||
this.target = target;
|
||||
|
|
@ -65,7 +64,7 @@ public abstract class Request {
|
|||
public void cancel() {
|
||||
try {
|
||||
timeoutTask.cancel();
|
||||
PlayerConfig.getConfig(target).request(null);
|
||||
plugin.userManager().getUser(target).request(null);
|
||||
} catch (IllegalStateException ignore) {
|
||||
}
|
||||
}
|
||||
|
|
@ -4,9 +4,9 @@ import com.alttd.essentia.EssentiaPlugin;
|
|||
import com.alttd.essentia.configuration.Config;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TeleportRequest extends Request {
|
||||
public class TeleportEssentiaRequest extends EssentiaRequest {
|
||||
|
||||
public TeleportRequest(EssentiaPlugin plugin, Player requester, Player target) {
|
||||
public TeleportEssentiaRequest(EssentiaPlugin plugin, Player requester, Player target) {
|
||||
super(plugin, requester, target);
|
||||
|
||||
target.sendRichMessage(Config.TELEPORT_REQUESTHERE_TARGET, placeholders);
|
||||
|
|
@ -4,9 +4,9 @@ import com.alttd.essentia.EssentiaPlugin;
|
|||
import com.alttd.essentia.configuration.Config;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TeleportHereRequest extends Request {
|
||||
public class TeleportHereEssentiaRequest extends EssentiaRequest {
|
||||
|
||||
public TeleportHereRequest(EssentiaPlugin plugin, Player requester, Player target) {
|
||||
public TeleportHereEssentiaRequest(EssentiaPlugin plugin, Player requester, Player target) {
|
||||
super(plugin, requester, target);
|
||||
|
||||
target.sendRichMessage(Config.TELEPORT_REQUEST_TARGET, placeholders);
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
package com.alttd.essentia.tasks;
|
||||
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.request.Request;
|
||||
import com.alttd.essentia.request.EssentiaRequest;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class RequestTimeout extends BukkitRunnable {
|
||||
private final Request request;
|
||||
private final EssentiaRequest request;
|
||||
|
||||
public RequestTimeout(Request request) {
|
||||
public RequestTimeout(EssentiaRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.alttd.essentia.tasks;
|
||||
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,8 @@ public class EssentiaUser implements User {
|
|||
protected Location deathLocation;
|
||||
protected Map<String, Location> homes;
|
||||
protected boolean allowTeleports;
|
||||
protected Request request;
|
||||
|
||||
@Getter @Setter
|
||||
private Request request;
|
||||
private boolean saving;
|
||||
|
||||
private EssentiaUser(Builder builder) {
|
||||
|
|
@ -110,6 +109,16 @@ public class EssentiaUser implements User {
|
|||
this.saving = saving;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request request() {
|
||||
return request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void request(Request request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
protected UUID uuid;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user