2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2011-11-18 17:42:26 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2013-06-08 21:31:19 +00:00
|
|
|
import com.earth2me.essentials.utils.LocationUtil;
|
2017-06-11 00:17:43 +00:00
|
|
|
import com.google.common.collect.Lists;
|
2011-03-19 22:39:51 +00:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.TreeType;
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
|
2017-06-11 00:17:43 +00:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
|
|
|
public class Commandtree extends EssentialsCommand {
|
|
|
|
public Commandtree() {
|
|
|
|
super("tree");
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
@Override
|
|
|
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
2015-06-03 14:05:38 +00:00
|
|
|
TreeType tree = null;
|
|
|
|
if (args.length < 1) {
|
|
|
|
throw new NotEnoughArgumentsException();
|
2015-09-30 01:56:04 +00:00
|
|
|
} else {
|
2020-10-03 17:46:05 +00:00
|
|
|
for (final TreeType type : TreeType.values()) {
|
2015-06-03 14:05:38 +00:00
|
|
|
if (type.name().replace("_", "").equalsIgnoreCase(args[0])) {
|
|
|
|
tree = type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-06-03 14:08:28 +00:00
|
|
|
if (args[0].equalsIgnoreCase("jungle")) {
|
|
|
|
tree = TreeType.SMALL_JUNGLE;
|
|
|
|
}
|
2015-06-03 14:05:38 +00:00
|
|
|
if (tree == null) {
|
2015-04-15 04:06:16 +00:00
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
}
|
2011-11-21 01:55:26 +00:00
|
|
|
|
2020-05-13 22:55:17 +00:00
|
|
|
final Location loc = LocationUtil.getTarget(user.getBase()).add(0, 1, 0);
|
2020-08-22 16:01:50 +00:00
|
|
|
if (loc.getBlock().getType().isSolid()) {
|
2020-05-13 22:55:17 +00:00
|
|
|
throw new Exception(tl("treeFailure"));
|
|
|
|
}
|
2020-08-11 18:09:22 +00:00
|
|
|
|
|
|
|
if (user.getWorld().generateTree(loc, tree)) {
|
2015-04-15 04:06:16 +00:00
|
|
|
user.sendMessage(tl("treeSpawned"));
|
2020-08-11 18:09:22 +00:00
|
|
|
return;
|
2015-04-15 04:06:16 +00:00
|
|
|
}
|
2020-08-11 18:09:22 +00:00
|
|
|
user.sendMessage(tl("treeFailure"));
|
2015-04-15 04:06:16 +00:00
|
|
|
}
|
2017-06-11 00:17:43 +00:00
|
|
|
|
|
|
|
@Override
|
2020-10-03 17:46:05 +00:00
|
|
|
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
|
2017-06-11 00:17:43 +00:00
|
|
|
if (args.length == 1) {
|
2020-10-03 17:46:05 +00:00
|
|
|
final List<String> options = Lists.newArrayList();
|
|
|
|
for (final TreeType type : TreeType.values()) {
|
2017-06-11 00:17:43 +00:00
|
|
|
options.add(type.name().toLowerCase(Locale.ENGLISH).replace("_", ""));
|
|
|
|
}
|
|
|
|
return options;
|
|
|
|
} else {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|