Skip to content

Commit cda5648

Browse files
committed
Allow help to have pages
1 parent 7690c74 commit cda5648

File tree

4 files changed

+56
-43
lines changed

4 files changed

+56
-43
lines changed

API/src/main/java/me/ifydev/dimensify/api/DimensifyConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class DimensifyConstants {
7171
public static final String THIS_DIMENSION_DOES_NOT_EXIST_ANYMORE = DIMENSIFY_PREFIX + "&c&lThis dimension does not exist anymore!";
7272
public static final String COULD_NOT_SET_DEFAULT_WORLD = DIMENSIFY_PREFIX + "&2&lCould not set default world.";
7373
public static final String COULD_NOT_UNLOAD_DIMENSION = DIMENSIFY_PREFIX + "&2&lCould not unload dimension!";
74+
public static final String INVALID_HELP_PAGE = DIMENSIFY_PREFIX + "&2&lInvalid help page!";
7475

7576
// General success
7677
public static final String CREATING_WORLD = DIMENSIFY_PREFIX + "World '<WORLD>' is being created...";

DimensifySpigot/src/main/java/me/ifydev/dimensifyspigot/backend/SpigotFlatFileHandler.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public void reload() {
7878

7979
this.portals = this.getPortals(true);
8080
this.dimensions = this.getDimensions(true);
81-
System.out.println(dimensions);
8281
}
8382

8483
@Override
@@ -217,17 +216,14 @@ public List<Dimension> getDimensions(boolean skipCache) {
217216
if (!skipCache) return this.dimensions;
218217

219218
ConfigurationSection dimensions = storage.getConfigurationSection("dimensions");
220-
System.out.println(dimensions == null);
221219
List<Dimension> loadedDimensions = new ArrayList<>();
222220

223221
if (dimensions == null) return loadedDimensions;
224222

225223
dimensions.getKeys(false).forEach(dimension -> {
226-
System.out.println(dimension);
227224
if (!dimensions.isString(dimension + ".name") || !dimensions.isString(dimension + ".type") ||
228225
!dimensions.isString(dimension + ".meta") || !dimensions.isBoolean(dimension + ".default")) {
229226
// This isn't a valid dimension.
230-
System.out.println("TEINRSOTNRSTENRSOTEINRSETNRSTONRST");
231227
return;
232228
}
233229
String name = dimensions.getString(dimension + ".name");
@@ -237,9 +233,7 @@ public List<Dimension> getDimensions(boolean skipCache) {
237233
boolean isDefault = dimensions.getBoolean(dimension + ".default");
238234

239235
loadedDimensions.add(new Dimension(name, type, Optional.ofNullable(meta), isDefault));
240-
System.out.println(loadedDimensions);
241236
});
242-
System.out.println("============================\n" + loadedDimensions);
243237
return loadedDimensions;
244238
}
245239

DimensifySpigot/src/main/java/me/ifydev/dimensifyspigot/commands/DimensifyCommand.java

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,19 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
3333

3434
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
3535
if (args.length < 1) {
36-
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.DIMENSIFY_HELP_HEADER));
37-
DimensifyConstants.HELP_RESPONSE.forEach(messages ->
38-
messages.forEach(message -> sender.sendMessage(ColorUtil.makeReadable(message))));
39-
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.DIMENSIFY_HELP_FOOTER));
36+
sendHelp(sender);
4037
return;
4138
}
42-
if (args[0].equalsIgnoreCase("create")) {
39+
40+
if (args[0].equalsIgnoreCase("help")) {
41+
int page = 0;
42+
if (args.length >= 2) {
43+
try {
44+
page = Integer.parseInt(args[1]);
45+
} catch (NumberFormatException ignored) {}
46+
}
47+
sendHelp(sender, page);
48+
} else if (args[0].equalsIgnoreCase("create")) {
4349
if (!sender.hasPermission(DimensifyConstants.DIMENSIFY_CREATE_DIMENSION)) {
4450
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.YOU_DONT_HAVE_PERMISSION));
4551
return;
@@ -59,8 +65,6 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
5965
result = ColorUtil.makeReadable(result);
6066
sender.sendMessage(result);
6167
});
62-
63-
return;
6468
} else if (args[0].equalsIgnoreCase("go")) {
6569
if (!sender.hasPermission(DimensifyConstants.DIMENSIFY_GO)) {
6670
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.YOU_DONT_HAVE_PERMISSION));
@@ -84,7 +88,6 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
8488
if (result.equals("")) return;
8589
player.sendMessage(ColorUtil.makeReadable(result));
8690
});
87-
return;
8891
} else if (args[0].equalsIgnoreCase("delete")) {
8992
if (!sender.hasPermission(DimensifyConstants.DIMENSIFY_REMOVE_DIMENSION)) {
9093
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.YOU_DONT_HAVE_PERMISSION));
@@ -100,7 +103,6 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
100103
String result = ColorUtil.makeReadable(BasicHandler.deleteDimension(worldName));
101104
sender.sendMessage(result);
102105
});
103-
return;
104106
} else if (args[0].equalsIgnoreCase("send")) {
105107
if (!sender.hasPermission(DimensifyConstants.DIMENSIFY_SEND)) {
106108
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.YOU_DONT_HAVE_PERMISSION));
@@ -115,7 +117,6 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
115117
String result = ColorUtil.makeReadable(BasicHandler.sendPlayerToDimension(args[1], args[2]));
116118
sender.sendMessage(result);
117119
});
118-
return;
119120
} else if (args[0].equalsIgnoreCase("portal")) {
120121
if (!sender.hasPermission(DimensifyConstants.DIMENSIFY_PORTAL)) {
121122
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.YOU_DONT_HAVE_PERMISSION));
@@ -147,7 +148,6 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
147148

148149
String response = ColorUtil.makeReadable(PortalHandler.createPortal(player, block, portalName));
149150
player.sendMessage(response);
150-
return;
151151
} else if (args[1].equalsIgnoreCase("delete")) {
152152
if (!sender.hasPermission(DimensifyConstants.DIMENSIFY_REMOVE_PORTAL)) {
153153
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.YOU_DONT_HAVE_PERMISSION));
@@ -161,7 +161,6 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
161161

162162
String response = ColorUtil.makeReadable(PortalHandler.deletePortal(args[2]));
163163
sender.sendMessage(response);
164-
return;
165164
} else if (args[1].equalsIgnoreCase("link")) {
166165
if (!sender.hasPermission(DimensifyConstants.DIMENSIFY_LINK)) {
167166
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.YOU_DONT_HAVE_PERMISSION));
@@ -180,7 +179,6 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
180179
sender.sendMessage(response);
181180
});
182181

183-
return;
184182
} else if (args[1].equalsIgnoreCase("list")) {
185183
if (!sender.hasPermission(DimensifyConstants.DIMENSIFY_LIST_PORTALS)) {
186184
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.YOU_DONT_HAVE_PERMISSION));
@@ -194,7 +192,6 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
194192
return;
195193
}
196194
response.stream().map(ColorUtil::makeReadable).forEach(sender::sendMessage);
197-
return;
198195
}
199196
} else if (args[0].equalsIgnoreCase("list")) {
200197
if (!sender.hasPermission(DimensifyConstants.DIMENSIFY_LIST_DIMENSIONS)) {
@@ -209,7 +206,6 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
209206
return;
210207
}
211208
response.stream().map(ColorUtil::makeReadable).forEach(sender::sendMessage);
212-
return;
213209
} else if (args[0].equalsIgnoreCase("default")) {
214210
if (!sender.hasPermission(DimensifyConstants.DIMENSIFY_DEFAULT)) {
215211
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.YOU_DONT_HAVE_PERMISSION));
@@ -219,7 +215,6 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
219215
String response = BasicHandler.setOrGetDefaultWorld(args.length >= 2 ? Optional.of(args[1]) :Optional.empty());
220216
response = ColorUtil.makeReadable(response);
221217
sender.sendMessage(response);
222-
return;
223218
} else if (args[0].equalsIgnoreCase("cache")) {
224219
if (!sender.hasPermission(DimensifyConstants.DIMENSIFY_CACHE)) {
225220
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.YOU_DONT_HAVE_PERMISSION));
@@ -232,7 +227,6 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
232227
result = ColorUtil.makeReadable(result);
233228

234229
sender.sendMessage(result);
235-
return;
236230
} else if (args[0].equalsIgnoreCase("unload")) {
237231
if (!sender.hasPermission(DimensifyConstants.DIMENSIFY_UNLOAD)) {
238232
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.YOU_DONT_HAVE_PERMISSION));
@@ -249,14 +243,32 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
249243
String result = ColorUtil.makeReadable(BasicHandler.unloadDimension(dimension, save));
250244
sender.sendMessage(result);
251245
});
252-
return;
253246
}
254-
// Send help
255-
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.DIMENSIFY_HELP_HEADER));
256-
DimensifyConstants.HELP_RESPONSE.forEach(section -> section.stream().map(ColorUtil::makeReadable).forEach(sender::sendMessage));
257-
sender.sendMessage(ColorUtil.makeReadable(DimensifyConstants.DIMENSIFY_HELP_FOOTER));
258247
});
259248

260249
return false;
261250
}
251+
252+
private void sendResponse(List<String> responses, CommandSender source) {
253+
responses.forEach(response -> sendResponse(response, source));
254+
}
255+
256+
private void sendResponse(String response, CommandSender source) {
257+
source.sendMessage(ColorUtil.makeReadable(response)); // XXX: Probably don't need ColorUtil anymore...
258+
}
259+
260+
private void sendHelp(CommandSender player) {
261+
sendHelp(player, 0);
262+
}
263+
264+
private void sendHelp(CommandSender player, int page) {
265+
if (page < 0 || page > DimensifyConstants.HELP_RESPONSE.size()) {
266+
sendResponse(DimensifyConstants.INVALID_HELP_PAGE, player);
267+
return;
268+
}
269+
page = page == 0 ? page : page - 1; // what
270+
sendResponse(DimensifyConstants.DIMENSIFY_HELP_HEADER, player);
271+
sendResponse(DimensifyConstants.HELP_RESPONSE.get(page), player);
272+
sendResponse(DimensifyConstants.DIMENSIFY_HELP_FOOTER, player);
273+
}
262274
}

DimensifySpigot/src/main/java/me/ifydev/dimensifyspigot/events/PlayerPortal.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import me.ifydev.dimensifyspigot.DimensifyMain;
55
import me.ifydev.dimensifyspigot.util.ColorUtil;
66
import me.ifydev.dimensifyspigot.world.WorldController;
7+
import org.bukkit.Bukkit;
78
import org.bukkit.World;
89
import org.bukkit.entity.Player;
910
import org.bukkit.event.EventHandler;
@@ -23,21 +24,26 @@ public void onPlayerAboutToTeleportEvent(PlayerPortalEvent e) {
2324
// We cancel this event if they're within one of our portals, so that we can send them ourselves.
2425
DimensifyMain plugin = DimensifyMain.get();
2526

26-
Player player = e.getPlayer();
27-
plugin.getPortalRegistry().findCornersFromPosition(e.getFrom()).ifPresent(corners -> {
28-
e.setCancelled(true);
29-
30-
if (!corners.getDestination().isPresent()) return;
31-
32-
String link = corners.getDestination().get();
33-
Optional<World> dimension = DimensifyMain.get().getWorldController().getWorld(link);
34-
if (!dimension.isPresent()) {
35-
player.sendMessage(ColorUtil.makeReadable(DimensifyConstants.THIS_DIMENSION_DOES_NOT_EXIST_ANYMORE));
36-
return;
37-
}
38-
WorldController.enterDimension(player, dimension.get());
39-
// Make sure the player won't get damaged for no reason
40-
player.setFallDistance(0);
27+
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
28+
29+
Player player = e.getPlayer();
30+
plugin.getPortalRegistry().findCornersFromPosition(e.getFrom()).ifPresent(corners -> {
31+
e.setCancelled(true);
32+
33+
if (!corners.getDestination().isPresent()) return;
34+
35+
String link = corners.getDestination().get();
36+
Optional<World> dimension = DimensifyMain.get().getWorldController().getWorld(link);
37+
if (!dimension.isPresent()) {
38+
player.sendMessage(ColorUtil.makeReadable(DimensifyConstants.THIS_DIMENSION_DOES_NOT_EXIST_ANYMORE));
39+
return;
40+
}
41+
Bukkit.getScheduler().runTask(plugin, () -> {
42+
WorldController.enterDimension(player, dimension.get());
43+
// Make sure the player won't get damaged for no reason
44+
player.setFallDistance(0);
45+
});
46+
});
4147
});
4248
}
4349
}

0 commit comments

Comments
 (0)