1
mirror of https://github.com/CarmJos/MoeTeleport.git synced 2024-09-19 13:25:56 +00:00

实装setHome判断最多设置数量的功能

This commit is contained in:
Carm Jos 2021-12-17 10:50:19 +08:00
parent fe243c9214
commit af99af9827
5 changed files with 33 additions and 1 deletions

View File

@ -18,6 +18,15 @@ public class SetHomeCommand implements CommandExecutor {
Player player = (Player) sender;
UserData data = Main.getUserManager().getData(player);
String homeName = args.length >= 1 ? args[0] : "home";
int maxHome = Main.getUserManager().getMaxHome(player);
if (data.getHomeLocations().size() >= maxHome && data.getHomeLocation(homeName) == null) {
PluginMessages.Home.OVER_LIMIT.sendWithPlaceholders(sender,
new String[]{"%(max)"}, new Object[]{maxHome}
);
return true;
}
data.setHomeLocation(homeName, player.getLocation());
PluginMessages.Home.SET.sendWithPlaceholders(player,
new String[]{"%(name)"}, new Object[]{homeName}

View File

@ -40,6 +40,9 @@ public class PluginMessages {
public static final ConfigMessageList HEADER = new ConfigMessageList("home-list-header");
public static final ConfigMessage LIST_OBJECT = new ConfigMessage("home-list-object");
public static final ConfigMessageList OVER_LIMIT = new ConfigMessageList("home-over-limit");
public static final ConfigMessageList NOT_FOUND = new ConfigMessageList("home-not-found");
public static final ConfigMessageList SET = new ConfigMessageList("home-set");

View File

@ -1,6 +1,7 @@
package cc.carm.plugin.moeteleport.manager;
import cc.carm.plugin.moeteleport.Main;
import cc.carm.plugin.moeteleport.configuration.PluginConfig;
import cc.carm.plugin.moeteleport.model.UserData;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@ -8,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class UserManager {
@ -38,6 +40,17 @@ public class UserManager {
return getUserDataMap().get(player.getUniqueId());
}
public int getMaxHome(Player player) {
Map<String, Integer> permissions = PluginConfig.PERMISSIONS.get();
int value = PluginConfig.DEFAULT_HOME.get();
for (Map.Entry<String, Integer> entry : permissions.entrySet()) {
if (entry.getValue() > value && player.hasPermission(entry.getKey())) {
value = entry.getValue();
}
}
return value;
}
public HashMap<UUID, UserData> getUserDataMap() {
return userDataMap;
}

View File

@ -1,6 +1,7 @@
package cc.carm.plugin.moeteleport.model;
import cc.carm.plugin.moeteleport.Main;
import cc.carm.plugin.moeteleport.configuration.PluginConfig;
import cc.carm.plugin.moeteleport.configuration.location.DataLocation;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
@ -103,6 +104,8 @@ public class UserData {
return receivedRequests;
}
public @NotNull File getDataFile() {
return dataFile;
}

View File

@ -53,4 +53,8 @@ home-set:
- "&f成功设定名为 &6%(name) &f的家传送点。"
home-removed:
- "&f成功移除名为 &6%(name) &f的家传送点。"
- "&7原先位置为 &f%(location) &7。"
- "&7原先位置为 &f%(location) &7。"
home-over-limit:
- "&f您最多只能设置 &6%(max) &f个家传送点"
- "&7可以输入 &e/delHome <家名称> &7删除之前的家传送点"
- "&7或输入 &e/setHome <家名称> &7覆盖之前的家传送点。"