Merge remote-tracking branch 'origin/master'
# Conflicts: # src/main/java/com/alttd/afkdectector/AFKCheckTimer.java # src/main/java/com/alttd/afkdectector/MessageTimer.java # src/main/java/com/alttd/afkdectector/afkplayer/AFKPlayer.java # src/main/java/com/alttd/afkdectector/command/AFKCheckCommand.java # src/main/java/com/alttd/afkdectector/command/AFKListCommand.java
This commit is contained in:
commit
32c1ae7fac
2
pom.xml
2
pom.xml
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>groupId</groupId>
|
<groupId>groupId</groupId>
|
||||||
<artifactId>AFKDetector</artifactId>
|
<artifactId>AFKDetector</artifactId>
|
||||||
<version>2.1.3</version>
|
<version>2.1.4</version>
|
||||||
<name>AFKDetector</name>
|
<name>AFKDetector</name>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import java.util.UUID;
|
||||||
import com.alttd.afkdectector.afkplayer.AFKPlayer;
|
import com.alttd.afkdectector.afkplayer.AFKPlayer;
|
||||||
import com.alttd.afkdectector.config.Config;
|
import com.alttd.afkdectector.config.Config;
|
||||||
import com.alttd.afkdectector.config.Messages;
|
import com.alttd.afkdectector.config.Messages;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -13,7 +13,6 @@ import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
|
||||||
public class AFKCheckTimer extends BukkitRunnable{
|
public class AFKCheckTimer extends BukkitRunnable{
|
||||||
|
|
||||||
private AFKDetector plugin;
|
private AFKDetector plugin;
|
||||||
|
|
@ -60,8 +59,13 @@ public class AFKCheckTimer extends BukkitRunnable{
|
||||||
player.setSleepingIgnored(true);
|
player.setSleepingIgnored(true);
|
||||||
//player.setCanPickupItems(false);
|
//player.setCanPickupItems(false);
|
||||||
plugin.AFKPlayers.addEntry(player.getName());
|
plugin.AFKPlayers.addEntry(player.getName());
|
||||||
if (Config.AFKTOGGLEMESSAGES)
|
if (Config.AFKTOGGLEMESSAGES) {
|
||||||
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(Messages.AFKTOGGLEON.getMessage(), TagResolver.resolver(Placeholder.unparsed("player", player.getName()))), "afkdetector.notify");
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
|
Placeholder.parsed("player", player.getName())
|
||||||
|
);
|
||||||
|
Component component = AFKDetector.miniMessage.deserialize(Messages.AFKTOGGLEON.getMessage(), placeholders);
|
||||||
|
Bukkit.broadcast(component, "afkdetector.notify");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(System.currentTimeMillis() - standingTime > afkplayer.getafkTime() * 60 * 1000) {
|
if(System.currentTimeMillis() - standingTime > afkplayer.getafkTime() * 60 * 1000) {
|
||||||
MessageTimer currentTimer = plugin.messageTimers.get(uuid);
|
MessageTimer currentTimer = plugin.messageTimers.get(uuid);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import com.alttd.afkdectector.command.AFKListCommand;
|
||||||
import com.alttd.afkdectector.command.ReloadCommand;
|
import com.alttd.afkdectector.command.ReloadCommand;
|
||||||
import com.alttd.afkdectector.config.Config;
|
import com.alttd.afkdectector.config.Config;
|
||||||
import com.alttd.afkdectector.config.MessagesConfig;
|
import com.alttd.afkdectector.config.MessagesConfig;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
@ -33,6 +34,8 @@ public class AFKDetector extends JavaPlugin implements Listener{
|
||||||
public HashMap<UUID, Integer> PlayerAfkTime = new HashMap<>();
|
public HashMap<UUID, Integer> PlayerAfkTime = new HashMap<>();
|
||||||
|
|
||||||
public boolean fulloverride;
|
public boolean fulloverride;
|
||||||
|
|
||||||
|
public static MiniMessage miniMessage;
|
||||||
/**
|
/**
|
||||||
* afkplayers need to be added to a team.
|
* afkplayers need to be added to a team.
|
||||||
*/
|
*/
|
||||||
|
|
@ -42,6 +45,7 @@ public class AFKDetector extends JavaPlugin implements Listener{
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
try {
|
try {
|
||||||
instance = this;
|
instance = this;
|
||||||
|
miniMessage = MiniMessage.miniMessage();
|
||||||
loadConfig(null);
|
loadConfig(null);
|
||||||
settupAfkState();
|
settupAfkState();
|
||||||
getServer().getPluginManager().registerEvents(this, this);
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
|
|
@ -113,10 +117,8 @@ public class AFKDetector extends JavaPlugin implements Listener{
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent event) {
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player != null) {
|
PlayerAfkTime.put(player.getUniqueId(), getPlayerAfktime(player));
|
||||||
PlayerAfkTime.put(player.getUniqueId(), getPlayerAfktime(player));
|
players.put(player.getUniqueId(), new AFKPlayer(player, this));
|
||||||
players.put(player.getUniqueId(), new AFKPlayer(player, this));
|
|
||||||
}
|
|
||||||
if(Bukkit.getOnlinePlayers().size() >= Config.PLAYERLIMIT && !Config.SERVERFULL) {
|
if(Bukkit.getOnlinePlayers().size() >= Config.PLAYERLIMIT && !Config.SERVERFULL) {
|
||||||
fulloverride = true;
|
fulloverride = true;
|
||||||
}
|
}
|
||||||
|
|
@ -126,9 +128,7 @@ public class AFKDetector extends JavaPlugin implements Listener{
|
||||||
public void onQuit(PlayerQuitEvent event) {
|
public void onQuit(PlayerQuitEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
// Remove the players from the timer if they logout
|
// Remove the players from the timer if they logout
|
||||||
if (player != null) {
|
players.remove(player.getUniqueId());
|
||||||
players.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
if(Bukkit.getOnlinePlayers().size() < Config.PLAYERLIMIT && fulloverride){
|
if(Bukkit.getOnlinePlayers().size() < Config.PLAYERLIMIT && fulloverride){
|
||||||
fulloverride = false;
|
fulloverride = false;
|
||||||
}
|
}
|
||||||
|
|
@ -140,9 +140,7 @@ public class AFKDetector extends JavaPlugin implements Listener{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player != null) {
|
getPlayer(player).ResetAFK();
|
||||||
getPlayer(player).ResetAFK();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
@ -151,10 +149,8 @@ public class AFKDetector extends JavaPlugin implements Listener{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player != null) {
|
getPlayer(player).ResetAFK();
|
||||||
getPlayer(player).ResetAFK();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* @EventHandler
|
/* @EventHandler
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ public class MessageTimer extends BukkitRunnable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(Config.COUNTDOWNENABLED) {
|
if(Config.COUNTDOWNENABLED) {
|
||||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
MiniMessage miniMessage = AFKDetector.miniMessage;
|
||||||
Title title = Title.title(miniMessage.deserialize(Messages.COUNTDOWNTITLE1.getMessage()),
|
Title title = Title.title(miniMessage.deserialize(Messages.COUNTDOWNTITLE1.getMessage()),
|
||||||
miniMessage.deserialize(Messages.COUNTDOWNTITLE2.getMessage()));
|
miniMessage.deserialize(Messages.COUNTDOWNTITLE2.getMessage()));
|
||||||
//Title.Times.of(Config.FADEIN, Config.STAY, Config.STAY);
|
//Title.Times.of(Config.FADEIN, Config.STAY, Config.STAY);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
import com.alttd.afkdectector.config.Config;
|
import com.alttd.afkdectector.config.Config;
|
||||||
import com.alttd.afkdectector.config.Messages;
|
import com.alttd.afkdectector.config.Messages;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -17,7 +17,6 @@ public class AFKPlayer {
|
||||||
|
|
||||||
private final String playerName;
|
private final String playerName;
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
|
|
||||||
private Location playerToSphereCenter;
|
private Location playerToSphereCenter;
|
||||||
private long standingTime;
|
private long standingTime;
|
||||||
private final int afkTime;
|
private final int afkTime;
|
||||||
|
|
@ -70,7 +69,11 @@ public class AFKPlayer {
|
||||||
|
|
||||||
public void ResetAFK() {
|
public void ResetAFK() {
|
||||||
if(isafk && Config.AFKTOGGLEMESSAGES) {
|
if(isafk && Config.AFKTOGGLEMESSAGES) {
|
||||||
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(Messages.AFKTOGGLEOFF.getMessage(), TagResolver.resolver(Placeholder.unparsed("player", playerName))), "afkdetector.notify");
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
|
Placeholder.parsed("player", playerName)
|
||||||
|
);
|
||||||
|
Component component = AFKDetector.miniMessage.deserialize(Messages.AFKTOGGLEOFF.getMessage(), placeholders);
|
||||||
|
Bukkit.broadcast(component, "afkdetector.notify");
|
||||||
}
|
}
|
||||||
standingTime = System.currentTimeMillis();
|
standingTime = System.currentTimeMillis();
|
||||||
playerToSphereCenter = Bukkit.getPlayer(getPlayerUuid()).getLocation();
|
playerToSphereCenter = Bukkit.getPlayer(getPlayerUuid()).getLocation();
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package com.alttd.afkdectector.command;
|
package com.alttd.afkdectector.command;
|
||||||
|
|
||||||
import com.alttd.afkdectector.AFKDetector;
|
import com.alttd.afkdectector.AFKDetector;
|
||||||
|
import com.alttd.afkdectector.afkplayer.AFKPlayer;
|
||||||
import com.alttd.afkdectector.config.Messages;
|
import com.alttd.afkdectector.config.Messages;
|
||||||
import net.kyori.adventure.audience.Audience;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|
@ -14,8 +14,11 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class AFKCheckCommand implements CommandExecutor, TabCompleter {
|
public class AFKCheckCommand implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
|
|
@ -36,7 +39,7 @@ public class AFKCheckCommand implements CommandExecutor, TabCompleter {
|
||||||
sender.sendMessage(Component.text(command.getUsage(), NamedTextColor.RED));
|
sender.sendMessage(Component.text(command.getUsage(), NamedTextColor.RED));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
MiniMessage miniMessage = AFKDetector.miniMessage;
|
||||||
target.showTitle(Title.title(miniMessage.deserialize(Messages.AFKCHECKTITLE.getMessage()),
|
target.showTitle(Title.title(miniMessage.deserialize(Messages.AFKCHECKTITLE.getMessage()),
|
||||||
miniMessage.deserialize(Messages.AFKCHECKSUBTITLE.getMessage())));
|
miniMessage.deserialize(Messages.AFKCHECKSUBTITLE.getMessage())));
|
||||||
if(sender instanceof Player) {
|
if(sender instanceof Player) {
|
||||||
|
|
@ -53,6 +56,10 @@ public class AFKCheckCommand implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
|
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||||
|
List<String> completions = new ArrayList<>();
|
||||||
|
if (strings.length == 1) {
|
||||||
|
StringUtil.copyPartialMatches(strings[0], plugin.players.values().stream().filter(AFKPlayer::isafk).map(AFKPlayer::getPlayerName).collect(Collectors.toList()), completions);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -28,23 +28,24 @@ public class AFKListCommand implements CommandExecutor, TabCompleter {
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
int afkplayers = 0;
|
int afkplayers = 0;
|
||||||
Component message = Component.empty();
|
Component message = Component.empty();
|
||||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
MiniMessage miniMessage = AFKDetector.miniMessage;
|
||||||
for (AFKPlayer afkplayer : plugin.players.values()) {
|
for (AFKPlayer afkplayer : plugin.players.values()) {
|
||||||
long standingTime = afkplayer.getstandingTime();
|
long standingTime = afkplayer.getstandingTime();
|
||||||
if(System.currentTimeMillis() - standingTime > Config.TOGGLETIME * 60 * 1000) {
|
if(System.currentTimeMillis() - standingTime > Config.TOGGLETIME * 60 * 1000) {
|
||||||
afkplayers += 1;
|
afkplayers += 1;
|
||||||
message = message.append(Component.newline());
|
message = message.append(Component.newline());
|
||||||
TagResolver templates = TagResolver.resolver(
|
TagResolver templates = TagResolver.resolver(
|
||||||
Placeholder.unparsed("player", afkplayer.getPlayerName()),
|
Placeholder.parsed("player", afkplayer.getPlayerName()),
|
||||||
Placeholder.unparsed("afktime", (System.currentTimeMillis() - standingTime) / 1000 + ""));
|
Placeholder.parsed("afktime", (System.currentTimeMillis() - standingTime) / 1000 + "")
|
||||||
|
);
|
||||||
Component userinfo = miniMessage.deserialize(Messages.AFK_LIST_ENTRY.getMessage(), templates);
|
Component userinfo = miniMessage.deserialize(Messages.AFK_LIST_ENTRY.getMessage(), templates);
|
||||||
message = message.append(userinfo);
|
message = message.append(userinfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TagResolver templates = TagResolver.resolver(
|
TagResolver templates = TagResolver.resolver(
|
||||||
Placeholder.unparsed("afkplayers", Integer.toString(afkplayers))
|
Placeholder.parsed("afkplayers", Integer.toString(afkplayers))
|
||||||
);
|
);
|
||||||
Component component = miniMessage.deserialize(Messages.AFK_LIST.getMessage(), templates);
|
Component component = miniMessage.deserialize(Messages.AFK_LIST.getMessage(), templates);
|
||||||
sender.sendMessage(component.append(message));
|
sender.sendMessage(component.append(message));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,151 +0,0 @@
|
||||||
package com.alttd.afkdectector.config;
|
|
||||||
|
|
||||||
import com.alttd.afkdectector.AFKDetector;
|
|
||||||
import com.alttd.afkdectector.util.Logger;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
@SuppressWarnings({"unused", "SameParameterValue"})
|
|
||||||
abstract class AbstractConfig {
|
|
||||||
File file;
|
|
||||||
YamlConfiguration yaml;
|
|
||||||
File configPath;
|
|
||||||
|
|
||||||
AbstractConfig(String filename) {
|
|
||||||
this.configPath = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + AFKDetector.getInstance().getName());
|
|
||||||
this.file = new File(configPath, filename);
|
|
||||||
this.yaml = new YamlConfiguration();
|
|
||||||
if (!this.file.getParentFile().exists()) {
|
|
||||||
if(!this.file.getParentFile().mkdirs()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
yaml.load(file);
|
|
||||||
} catch (IOException ignore) {
|
|
||||||
} catch (InvalidConfigurationException ex) {
|
|
||||||
Logger.severe(String.format("Could not load %s, please correct your syntax errors", filename));
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
yaml.options().copyDefaults(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void readConfig(Class<?> clazz, Object instance) {
|
|
||||||
for (Method method : clazz.getDeclaredMethods()) {
|
|
||||||
if (Modifier.isPrivate(method.getModifiers())) {
|
|
||||||
if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) {
|
|
||||||
try {
|
|
||||||
method.setAccessible(true);
|
|
||||||
method.invoke(instance);
|
|
||||||
} catch (InvocationTargetException ex) {
|
|
||||||
throw new RuntimeException(ex.getCause());
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Logger.severe("Error invoking " + method);
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
yaml.save(file);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
Logger.severe("Could not save " + file);
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void set(String path, Object val) {
|
|
||||||
yaml.addDefault(path, val);
|
|
||||||
yaml.set(path, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
String getString(String path, String def) {
|
|
||||||
yaml.addDefault(path, def);
|
|
||||||
return yaml.getString(path, yaml.getString(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean getBoolean(String path, boolean def) {
|
|
||||||
yaml.addDefault(path, def);
|
|
||||||
return yaml.getBoolean(path, yaml.getBoolean(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
int getInt(String path, int def) {
|
|
||||||
yaml.addDefault(path, def);
|
|
||||||
return yaml.getInt(path, yaml.getInt(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
double getDouble(String path, double def) {
|
|
||||||
yaml.addDefault(path, def);
|
|
||||||
return yaml.getDouble(path, yaml.getDouble(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
<T> List<?> getList(String path, T def) {
|
|
||||||
yaml.addDefault(path, def);
|
|
||||||
return yaml.getList(path, yaml.getList(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
<T> Map<String, T> getMap(final @NonNull String path, final @Nullable Map<String, T> def) {
|
|
||||||
final ImmutableMap.Builder<String, T> builder = ImmutableMap.builder();
|
|
||||||
if (def != null && yaml.getConfigurationSection(path) == null) {
|
|
||||||
yaml.addDefault(path, def.isEmpty() ? new HashMap<>() : def);
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
final ConfigurationSection section = yaml.getConfigurationSection(path);
|
|
||||||
if (section != null) {
|
|
||||||
for (String key : section.getKeys(false)) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
final T val = (T) section.get(key);
|
|
||||||
if (val != null) {
|
|
||||||
builder.put(key, val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack getItemStack(String path, ItemStack def) {
|
|
||||||
yaml.addDefault(path, def);
|
|
||||||
return yaml.getItemStack(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setLocations(String path, ArrayList<Location> locs) {
|
|
||||||
ArrayList<String> list = new ArrayList<>();
|
|
||||||
for(Location l : locs) {
|
|
||||||
String toSave = l.getWorld().getName() + ":" + l.getX() + ":" + l.getY() + ":" + l.getZ();
|
|
||||||
list.add(toSave);
|
|
||||||
}
|
|
||||||
yaml.set(path, list);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Location> getLocations(String path){
|
|
||||||
List<String> attempts = yaml.getStringList(path);
|
|
||||||
|
|
||||||
if (attempts == null || attempts.isEmpty()) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
List<Location> locations = new ArrayList<>();
|
|
||||||
|
|
||||||
for (String attempt : attempts) {
|
|
||||||
String[] parts = attempt.split(":");
|
|
||||||
locations.add(new Location(Bukkit.getWorld(parts[0]), Double.parseDouble(parts[1]), Double.parseDouble(parts[2]), Double.parseDouble(parts[3])));
|
|
||||||
}
|
|
||||||
return locations;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
package com.alttd.afkdectector.config;
|
package com.alttd.afkdectector.config;
|
||||||
|
|
||||||
|
import com.alttd.afkdectector.AFKDetector;
|
||||||
|
import com.alttd.galaxy.configuration.AbstractConfiguration;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class Config extends AbstractConfig {
|
public class Config extends AbstractConfiguration {
|
||||||
private Config() {
|
private Config() {
|
||||||
super("config.yml");
|
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + AFKDetector.getInstance().getName()), "config");
|
||||||
}
|
}
|
||||||
|
|
||||||
static Config config;
|
static Config config;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
package com.alttd.afkdectector.config;
|
package com.alttd.afkdectector.config;
|
||||||
|
|
||||||
|
import com.alttd.afkdectector.AFKDetector;
|
||||||
|
import com.alttd.galaxy.configuration.AbstractConfiguration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class MessagesConfig extends AbstractConfig {
|
public class MessagesConfig extends AbstractConfiguration {
|
||||||
private MessagesConfig() {
|
private MessagesConfig() {
|
||||||
super("messages.yml");
|
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + AFKDetector.getInstance().getName()), "messages");
|
||||||
}
|
}
|
||||||
|
|
||||||
static MessagesConfig config;
|
static MessagesConfig config;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user