Skip to content

Commit 89126d7

Browse files
committed
Initial mod of README for v2.0.0
1 parent 2c68685 commit 89126d7

8 files changed

Lines changed: 277 additions & 211 deletions

File tree

README.md

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,65 @@ provides a straightforward interface for home management commands.
55

66
## Commands
77

8-
| Command | Permission | Description |
9-
|----------------|--------------------------|---------------------|
10-
| `/sethome` | `homes.commands.sethome` | Sets a home |
11-
| `/delhome` | `homes.commands.delhome` | Deletes a home |
12-
| `/home` | `homes.commands.home` | Teleports to a home |
13-
| `/homesreload` | `homes.reload` | Reloads the config |
14-
| `/homelist` | `homes.commands.list` | Lists your homes |
8+
| Command | Permission | Description |
9+
|-----------------------|--------------------|------------------------------------|
10+
| `/sethome` | `homes.sethome` | Sets a home |
11+
| `/delhome` | `homes.delhome` | Deletes a home |
12+
| `/home` | `homes.home` | Teleports to a home |
13+
| `/homes` | `homes.list` | Lists your homes |
14+
| `/homes admin reload` | `homes.reload` | Reloads the config |
15+
| `/homes admin tp` | `homes.admin.tp` | Teleports to another player's home |
16+
| `/homes admin list` | `homes.admin.list` | Lists another player's homes |
1517

1618
## Permissions
1719

18-
| Permission | Default | Description |
19-
|--------------------------|---------|----------------------------------------------------------------------------------|
20-
| `homes` | op | Allows base plugin functionality |
21-
| `homes.commands` | op | Allows player to use commands |
22-
| `homes.commands.sethome` | op | Allows player to set home |
23-
| `homes.commands.delhome` | op | Allows player to delete home |
24-
| `homes.commands.home` | op | Allows player to teleport to home |
25-
| `homes.commands.list` | op | Allows you to list your own homes |
26-
| `homes.bed` | op | Allows you to teleport to your bed |
27-
| `homes.count` | op | Base for permission on number of homes you can have |
28-
| `homes.count.<num>` | op | Base for permission on number of homes you can have |
29-
| `homes.count.bypass` | op | Allows for setting infinite homes regardless of how many you have set as the max |
30-
| `homes.reload` | op | Allows reloading the config |
31-
| `homes.safety.bypass` | false | Allows bypassing the safety checks |
20+
| Permission | Default | Description |
21+
|-----------------------|---------|----------------------------------------------------------------------------------|
22+
| `homes.sethome` | true | Allows player to set home |
23+
| `homes.delhome` | true | Allows player to delete home |
24+
| `homes.home` | true | Allows player to teleport to home |
25+
| `homes.list` | true | Allows you to list your own homes |
26+
| `homes.bed` | true | Allows you to teleport to your bed, requires configuration setting |
27+
| `homes.reload` | op | Allows reloading the config |
28+
| `homes.bypass.safety` | false | Allows bypassing the safety checks |
29+
| `homes.bypass.delay` | op | Allows bypassing the teleport delay |
30+
| `homes.bypass.count` | op | Allows for setting infinite homes regardless of how many you have set as the max |
31+
32+
## Configuring Number of Homes
33+
34+
The number of homes is determined by permission nodes you create within the `config.yml`.
35+
36+
```yml
37+
# Configuration for number of homes based on permission
38+
counts:
39+
player:
40+
permission: "homes.count.player"
41+
home-count: 3
42+
moderator:
43+
permission: "homes.count.mod"
44+
home-count: 5
45+
```
46+
47+
In the above example, we can break down the counts part of the configuration into a few parts:
48+
49+
```yml
50+
counts:
51+
name:
52+
permission: "string"
53+
home-count: int
54+
```
55+
56+
`name` can be anything, just has to be unique.
57+
58+
`permission` can be any string, just has to be unique across all plugins.
59+
60+
- We recommend using `homes.count.<something>`.
61+
- This is the permission you will give to a player or group/rank.
62+
63+
`home-count` should be an integer, the number of homes you want it to be for the player.
64+
65+
- The highest home-count value given to a player will be applied. This means in the above example,
66+
if a player has both then it will apply a maximum of 5 homes.
3267

3368
## Importing from other plugins
3469

Lines changed: 2 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -1,192 +1,4 @@
11
package simplexity.simplehomes.commands;
22

3-
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
4-
import org.bukkit.Bukkit;
5-
import org.bukkit.Location;
6-
import org.bukkit.command.Command;
7-
import org.bukkit.command.CommandSender;
8-
import org.bukkit.command.TabExecutor;
9-
import org.bukkit.entity.Player;
10-
import org.bukkit.scheduler.BukkitTask;
11-
import org.jetbrains.annotations.NotNull;
12-
import org.jetbrains.annotations.Nullable;
13-
import simplexity.simplehomes.Home;
14-
import simplexity.simplehomes.SafetyCheck;
15-
import simplexity.simplehomes.SafetyFlags;
16-
import simplexity.simplehomes.SimpleHomes;
17-
import simplexity.simplehomes.configs.ConfigHandler;
18-
import simplexity.simplehomes.configs.LocaleHandler;
19-
import simplexity.simplehomes.saving.Cache;
20-
import simplexity.simplehomes.saving.SQLHandler;
21-
22-
import java.util.ArrayList;
23-
import java.util.HashMap;
24-
import java.util.List;
25-
26-
public class HomeCommand implements TabExecutor {
27-
28-
private static final String SAFETY_BYPASS = "homes.safety.bypass";
29-
private static final String DELAY_BYPASS = "homes.delay.bypass";
30-
public static HashMap<Player, Location> teleportRequests = new HashMap<>();
31-
public static HashMap<Player, BukkitTask> teleportTasks = new HashMap<>();
32-
33-
34-
@Override
35-
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
36-
if (!(sender instanceof Player player)) {
37-
sender.sendRichMessage(LocaleHandler.getInstance().getMustBePlayer());
38-
return false;
39-
}
40-
List<Home> playerHomesList = Cache.getInstance().getPlayerHomes(player.getUniqueId());
41-
//Check for lockout
42-
if (CommandUtils.isLockedOut(player)) {
43-
player.sendRichMessage(LocaleHandler.getInstance().getCannotUseCommand(),
44-
Placeholder.parsed("value", String.valueOf(CommandUtils.maxHomesPermission(player))),
45-
Placeholder.parsed("command", "/home"));
46-
return false;
47-
}
48-
// Get the home to teleport the player to
49-
Home playerHome;
50-
if (args.length == 0) {
51-
playerHome = handleNoArgs(player, playerHomesList);
52-
if (playerHome == null) {
53-
player.sendRichMessage(LocaleHandler.getInstance().getListNoHomes());
54-
return false;
55-
}
56-
} else {
57-
playerHome = handleHomeSelection(player, playerHomesList, args[0]);
58-
if (playerHome == null) {
59-
player.sendRichMessage(LocaleHandler.getInstance().getHomeNotFound(),
60-
Placeholder.parsed("name", args[0]));
61-
return false;
62-
}
63-
}
64-
// Check that it's safe
65-
if (!shouldTeleport(player, args, playerHome)) return false;
66-
handleTeleport(player, playerHome);
67-
return true;
68-
}
69-
70-
// If player has a bed home and supplied no args, return a new home from that location and the configured bed home name.
71-
// Otherwise, if they only have one home, return that one.
72-
// Otherwise, return null
73-
74-
private Home handleNoArgs(Player player, List<Home> homesList) {
75-
Location bedHome = getBedLocation(player);
76-
if (bedHome != null) return new Home(ConfigHandler.getInstance().getBedHomesName(), bedHome);
77-
if (homesList.size() == 1) {
78-
return homesList.get(0);
79-
}
80-
return null;
81-
}
82-
83-
private Home handleHomeSelection(Player player, List<Home> homesList, String suppliedName) {
84-
Location bedLocation = getBedLocation(player);
85-
if (suppliedName.equalsIgnoreCase(ConfigHandler.getInstance().getBedHomesName()) && bedLocation != null) {
86-
return new Home(ConfigHandler.getInstance().getBedHomesName(), bedLocation);
87-
}
88-
return CommandUtils.getHomeFromList(homesList, suppliedName);
89-
}
90-
91-
// Do config, permission, and API checks for bed location
92-
private Location getBedLocation(Player player) {
93-
if (player.getPotentialBedLocation() == null) return null;
94-
if (!ConfigHandler.getInstance().areBedHomesEnabled()) return null;
95-
if (!player.hasPermission(CommandUtils.BED_PERMISSION)) return null;
96-
return player.getPotentialBedLocation();
97-
}
98-
99-
// Safety Check
100-
private boolean shouldTeleport(Player player, String[] args, Home home) {
101-
if (player.hasPermission(SAFETY_BYPASS)) return true;
102-
if (CommandUtils.shouldOverride(args)) return true;
103-
int safetyFlags = SafetyCheck.checkSafetyFlags(home.location(), ConfigHandler.getInstance().getBlacklistedBlocks());
104-
if (safetyFlags == 0) return true;
105-
String safetyWarning = getSafetyWarning(safetyFlags);
106-
if (safetyWarning == null) {
107-
player.sendRichMessage(LocaleHandler.getInstance().getErrorHasOccurred());
108-
return false;
109-
}
110-
player.sendRichMessage(safetyWarning);
111-
return false;
112-
}
113-
114-
// Gets the configured messages for the safety warnings
115-
private String getSafetyWarning(int safetyFlags) {
116-
String warning = "";
117-
if (safetyFlags == 0) return null;
118-
if (SafetyFlags.DAMAGE_RISK.matches(safetyFlags)) {
119-
warning = LocaleHandler.getInstance().getBlacklistedWarning();
120-
}
121-
if (SafetyFlags.FALLING.matches(safetyFlags)) {
122-
warning = LocaleHandler.getInstance().getVoidWarning();
123-
}
124-
if (SafetyFlags.FIRE.matches(safetyFlags)) {
125-
warning = LocaleHandler.getInstance().getFireWarning();
126-
}
127-
if (SafetyFlags.LAVA.matches(safetyFlags)) {
128-
warning = LocaleHandler.getInstance().getLavaWarning();
129-
}
130-
if (SafetyFlags.NOT_SOLID.matches(safetyFlags)) {
131-
warning = LocaleHandler.getInstance().getVoidWarning();
132-
}
133-
if (SafetyFlags.SUFFOCATION.matches(safetyFlags)) {
134-
warning = LocaleHandler.getInstance().getBlocksWarning();
135-
}
136-
if (SafetyFlags.UNDERWATER.matches(safetyFlags)) {
137-
warning = LocaleHandler.getInstance().getWaterWarning();
138-
}
139-
if (SafetyFlags.UNSTABLE.matches(safetyFlags)) {
140-
warning = LocaleHandler.getInstance().getVoidWarning();
141-
}
142-
warning = warning + LocaleHandler.getInstance().getInsertOverride();
143-
return warning;
144-
}
145-
146-
private void handleTeleport(Player player, Home home) {
147-
if (!ConfigHandler.getInstance().isDelayEnabled()) {
148-
normalTeleport(player, home);
149-
return;
150-
}
151-
if (player.hasPermission(DELAY_BYPASS)) {
152-
normalTeleport(player, home);
153-
return;
154-
}
155-
delayTeleport(player, home);
156-
}
157-
158-
private void normalTeleport(Player player, Home home) {
159-
player.teleportAsync(home.location());
160-
player.sendRichMessage(LocaleHandler.getInstance().getHomeTeleported(),
161-
Placeholder.parsed("name", home.name()));
162-
}
163-
164-
// Runnable that allows delaying the teleport, tied into the player move listener
165-
private void delayTeleport(Player player, Home home) {
166-
player.sendRichMessage(LocaleHandler.getInstance().getPleaseWait(),
167-
Placeholder.parsed("value", String.valueOf(ConfigHandler.getInstance().getTimeInSeconds())));
168-
teleportRequests.put(player, player.getLocation());
169-
BukkitTask teleportTask = Bukkit.getScheduler().runTaskLater(SimpleHomes.getInstance(), () -> {
170-
if (!teleportRequests.containsKey(player)) return;
171-
player.teleportAsync(home.location());
172-
teleportRequests.remove(player);
173-
player.sendRichMessage(LocaleHandler.getInstance().getHomeTeleported(),
174-
Placeholder.parsed("name", home.name()));
175-
}, ConfigHandler.getInstance().getTimeInSeconds() * 20L);
176-
teleportTasks.put(player, teleportTask);
177-
}
178-
179-
@Override
180-
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
181-
if (!(commandSender instanceof Player player)) return List.of();
182-
List<Home> homesList = SQLHandler.getInstance().getHomes(player.getUniqueId());
183-
List<String> stringList = new ArrayList<>();
184-
for (Home home : homesList) {
185-
stringList.add(home.name());
186-
}
187-
if (player.hasPermission(CommandUtils.BED_PERMISSION) && getBedLocation(player) != null) {
188-
stringList.add(ConfigHandler.getInstance().getBedHomesName());
189-
}
190-
return stringList;
191-
}
192-
}
3+
public class HomeCommand {
4+
}

0 commit comments

Comments
 (0)