Skip to content

Commit

Permalink
实装setHome判断最多设置数量的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmJos committed Dec 17, 2021
1 parent fe243c9 commit af99af9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static class Home {
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");

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/cc/carm/plugin/moeteleport/manager/UserManager.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class UserManager {
Expand Down Expand Up @@ -38,6 +40,17 @@ public UserData getData(Player player) {
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;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/cc/carm/plugin/moeteleport/model/UserData.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -103,6 +104,8 @@ public ConcurrentHashMap<UUID, TeleportRequest> getReceivedRequests() {
return receivedRequests;
}



public @NotNull File getDataFile() {
return dataFile;
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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覆盖之前的家传送点。"

0 comments on commit af99af9

Please sign in to comment.