use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class WorldsCommand method getAddBuilderInput.
public void getAddBuilderInput(Player player, boolean closeInventory) {
BuildWorld buildWorld = playerManager.getSelectedWorld().get(player.getUniqueId());
if (buildWorld == null) {
player.closeInventory();
player.sendMessage(plugin.getString("worlds_addbuilder_error"));
return;
}
new PlayerChatInput(plugin, player, "enter_player_name", input -> {
String builderName = input.trim();
Player builderPlayer = Bukkit.getPlayer(builderName);
Builder builder;
UUID builderId;
if (builderPlayer == null) {
builderId = UUIDFetcher.getUUID(builderName);
if (builderId == null) {
player.sendMessage(plugin.getString("worlds_addbuilder_player_not_found"));
player.closeInventory();
return;
}
builder = new Builder(builderId, builderName);
} else {
builder = new Builder(builderPlayer);
builderId = builderPlayer.getUniqueId();
}
if (buildWorld.getCreatorId() != null && buildWorld.getCreatorId().equals(builderId)) {
player.sendMessage(plugin.getString("worlds_addbuilder_already_creator"));
player.closeInventory();
return;
}
if (buildWorld.isBuilder(builderId)) {
player.sendMessage(plugin.getString("worlds_addbuilder_already_added"));
player.closeInventory();
return;
}
buildWorld.addBuilder(builder);
XSound.ENTITY_PLAYER_LEVELUP.play(player);
player.sendMessage(plugin.getString("worlds_addbuilder_added").replace("%builder%", builderName));
if (closeInventory) {
player.closeInventory();
} else {
player.openInventory(plugin.getBuilderInventory().getInventory(buildWorld, player));
}
});
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class WorldsCommand method getRemoveBuilderInput.
public void getRemoveBuilderInput(Player player, boolean closeInventory) {
BuildWorld buildWorld = playerManager.getSelectedWorld().get(player.getUniqueId());
if (buildWorld == null) {
player.closeInventory();
player.sendMessage(plugin.getString("worlds_removebuilder_error"));
return;
}
new PlayerChatInput(plugin, player, "enter_player_name", input -> {
String builderName = input.trim();
Player builderPlayer = Bukkit.getPlayer(builderName);
UUID builderId;
if (builderPlayer == null) {
builderId = UUIDFetcher.getUUID(builderName);
if (builderId == null) {
player.sendMessage(plugin.getString("worlds_removebuilder_player_not_found"));
player.closeInventory();
return;
}
} else {
builderId = builderPlayer.getUniqueId();
}
if (buildWorld.getCreatorId() != null && buildWorld.getCreatorId().equals(builderId)) {
player.sendMessage(plugin.getString("worlds_removebuilder_not_yourself"));
player.closeInventory();
return;
}
if (!buildWorld.isBuilder(builderId)) {
player.sendMessage(plugin.getString("worlds_removebuilder_not_builder"));
player.closeInventory();
return;
}
buildWorld.removeBuilder(builderId);
XSound.ENTITY_PLAYER_LEVELUP.play(player);
player.sendMessage(plugin.getString("worlds_removebuilder_removed").replace("%builder%", builderName));
if (closeInventory) {
player.closeInventory();
} else {
player.openInventory(plugin.getBuilderInventory().getInventory(buildWorld, player));
}
});
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class WorldsCommand method getPermissionInput.
public void getPermissionInput(Player player, boolean closeInventory) {
BuildWorld buildWorld = playerManager.getSelectedWorld().get(player.getUniqueId());
if (buildWorld == null) {
player.closeInventory();
player.sendMessage(plugin.getString("worlds_setpermission_error"));
return;
}
new PlayerChatInput(plugin, player, "enter_world_permission", input -> {
buildWorld.setPermission(input.trim());
playerManager.forceUpdateSidebar(buildWorld);
XSound.ENTITY_PLAYER_LEVELUP.play(player);
player.sendMessage(plugin.getString("worlds_setpermission_set").replace("%world%", buildWorld.getName()));
if (closeInventory) {
player.closeInventory();
} else {
player.openInventory(plugin.getEditInventory().getInventory(player, buildWorld));
}
});
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class WorldsCommand method onCommand.
@Override
@SuppressWarnings("deprecation")
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
if (!(sender instanceof Player)) {
plugin.getLogger().warning(plugin.getString("sender_not_player"));
return true;
}
Player player = (Player) sender;
if (args.length == 0) {
if (!player.hasPermission("buildsystem.gui")) {
plugin.sendPermissionMessage(player);
return true;
}
plugin.getNavigatorInventory().openInventory(player);
XSound.BLOCK_CHEST_OPEN.play(player);
return true;
}
switch(args[0].toLowerCase()) {
case "addbuilder":
{
if (!player.hasPermission("buildsystem.addbuilder")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length == 2) {
BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_addbuilder_unknown_world"));
return true;
}
if ((buildWorld.getCreatorId() == null || !buildWorld.getCreatorId().equals(player.getUniqueId())) && !player.hasPermission("buildsystem.admin")) {
player.sendMessage(plugin.getString("worlds_addbuilder_not_creator"));
return true;
}
playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
getAddBuilderInput(player, true);
} else {
player.sendMessage(plugin.getString("worlds_addbuilder_usage"));
}
break;
}
case "builders":
{
if (!player.hasPermission("buildsystem.builders")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length == 2) {
BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_builders_unknown_world"));
return true;
}
playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
player.openInventory(plugin.getBuilderInventory().getInventory(buildWorld, player));
} else {
player.sendMessage(plugin.getString("worlds_builders_usage"));
}
break;
}
case "delete":
{
if (!player.hasPermission("buildsystem.delete")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length == 2) {
BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_delete_unknown_world"));
return true;
}
playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
plugin.getDeleteInventory().openInventory(player, buildWorld);
} else {
player.sendMessage(plugin.getString("worlds_delete_usage"));
}
break;
}
case "edit":
{
if (!player.hasPermission("buildsystem.edit")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length == 2) {
BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_edit_unknown_world"));
return true;
}
if (buildWorld.isLoaded()) {
playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
plugin.getEditInventory().openInventory(player, buildWorld);
} else {
XSound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR.play(player);
Titles.sendTitle(player, 5, 70, 20, " ", plugin.getString("world_not_loaded"));
}
} else {
player.sendMessage(plugin.getString("worlds_edit_usage"));
}
break;
}
case "help":
{
if (args.length == 1) {
sendHelpMessage(player, 1);
} else if (args.length == 2) {
try {
int page = Integer.parseInt(args[1]);
sendHelpMessage(player, page);
} catch (NumberFormatException e) {
player.sendMessage(plugin.getString("worlds_help_invalid_page"));
}
} else {
player.sendMessage(plugin.getString("worlds_help_usage"));
}
break;
}
case "import":
{
if (!player.hasPermission("buildsystem.import")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length >= 2) {
BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
if (buildWorld != null) {
player.sendMessage(plugin.getString("worlds_import_world_is_imported"));
return true;
}
File worldFolder = new File(Bukkit.getWorldContainer(), args[1]);
File levelFile = new File(worldFolder.getAbsolutePath() + File.separator + "level.dat");
if (!worldFolder.isDirectory() || !levelFile.exists()) {
player.sendMessage(plugin.getString("worlds_import_unknown_world"));
return true;
}
if (args.length == 2) {
worldManager.importWorld(player, args[1], Generator.VOID);
} else if (args.length == 4) {
if (!args[2].equalsIgnoreCase("-g")) {
player.sendMessage(plugin.getString("worlds_import_usage"));
return true;
}
Generator generator;
boolean customGenerator = false;
switch(args[3].toLowerCase()) {
case "normal":
generator = Generator.NORMAL;
break;
case "flat":
generator = Generator.FLAT;
break;
case "void":
generator = Generator.VOID;
break;
default:
generator = Generator.CUSTOM;
customGenerator = true;
break;
}
if (!customGenerator) {
worldManager.importWorld(player, args[1], generator);
} else {
worldManager.importWorld(player, args[1], generator, args[3]);
}
} else {
player.sendMessage(plugin.getString("worlds_import_usage"));
}
} else {
player.sendMessage(plugin.getString("worlds_import_usage"));
}
break;
}
case "importall":
{
if (!player.hasPermission("buildsystem.import.all")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length == 1) {
File worldContainer = Bukkit.getWorldContainer();
String[] directories = worldContainer.list((dir, name) -> {
File worldFolder = new File(dir, name);
if (!worldFolder.isDirectory()) {
return false;
}
File levelFile = new File(dir + File.separator + name + File.separator + "level.dat");
if (!levelFile.exists()) {
return false;
}
BuildWorld buildWorld = worldManager.getBuildWorld(name);
return buildWorld == null;
});
if (directories == null || directories.length == 0) {
player.sendMessage(plugin.getString("worlds_importall_no_worlds"));
return true;
}
worldManager.importWorlds(player, directories);
} else {
player.sendMessage(plugin.getString("worlds_importall_usage"));
}
break;
}
case "info":
{
if (!player.hasPermission("buildsystem.info")) {
plugin.sendPermissionMessage(player);
return true;
}
BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
if (args.length == 2) {
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_info_unknown_world"));
return true;
}
buildWorld = worldManager.getBuildWorld(args[1]);
} else if (args.length > 2) {
player.sendMessage(plugin.getString("worlds_info_usage"));
}
sendInfoMessage(player, buildWorld);
break;
}
case "item":
{
player.getInventory().addItem(inventoryManager.getItemStack(plugin.getConfigValues().getNavigatorItem(), plugin.getString("navigator_item")));
player.sendMessage(plugin.getString("worlds_item_receive"));
break;
}
case "removebuilder":
{
if (!player.hasPermission("buildsystem.removebuilder")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length == 2) {
BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_removebuilder_unknown_world"));
return true;
}
if ((buildWorld.getCreatorId() == null || !buildWorld.getCreatorId().equals(player.getUniqueId())) && !player.hasPermission("buildsystem.admin")) {
player.sendMessage(plugin.getString("worlds_removebuilder_not_creator"));
return true;
}
playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
getRemoveBuilderInput(player, true);
} else {
player.sendMessage(plugin.getString("worlds_removebuilder_usage"));
}
break;
}
case "rename":
{
if (!player.hasPermission("buildsystem.rename")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length == 2) {
BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_rename_unknown_world"));
return true;
}
playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
getRenameInput(player);
} else {
player.sendMessage(plugin.getString("worlds_rename_usage"));
}
break;
}
case "setcreator":
{
if (!player.hasPermission("buildsystem.setcreator")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length == 2) {
BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_setcreator_unknown_world"));
return true;
}
playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
getCreatorInput(player);
} else {
player.sendMessage(plugin.getString("worlds_setcreator_usage"));
}
break;
}
case "setitem":
{
if (!player.hasPermission("buildsystem.setitem")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length == 2) {
BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_setitem_unknown_world"));
return true;
}
ItemStack itemStack = player.getItemInHand();
if (itemStack.getType().equals(Material.AIR)) {
player.sendMessage(plugin.getString("worlds_setitem_hand_empty"));
return true;
}
buildWorld.setMaterial(XMaterial.matchXMaterial(itemStack));
player.sendMessage(plugin.getString("worlds_setitem_set").replace("%world%", buildWorld.getName()));
} else {
player.sendMessage(plugin.getString("worlds_setitem_usage"));
}
break;
}
case "setpermission":
{
if (!player.hasPermission("buildsystem.setpermission")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length == 2) {
BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_setpermission_unknown_world"));
return true;
}
playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
getPermissionInput(player, true);
} else {
player.sendMessage(plugin.getString("worlds_setpermission_usage"));
}
break;
}
case "setproject":
{
if (!player.hasPermission("buildsystem.setproject")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length == 2) {
BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_setproject_unknown_world"));
return true;
}
playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
getProjectInput(player, true);
} else {
player.sendMessage(plugin.getString("worlds_setproject_usage"));
}
break;
}
case "setstatus":
{
if (!player.hasPermission("buildsystem.setstatus")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length == 2) {
BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_setstatus_unknown_world"));
return true;
}
playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
plugin.getStatusInventory().openInventory(player);
} else {
player.sendMessage(plugin.getString("worlds_setstatus_usage"));
}
break;
}
case "setspawn":
{
if (!player.hasPermission("buildsystem.setspawn")) {
plugin.sendPermissionMessage(player);
return true;
}
BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_setspawn_world_not_imported"));
return true;
}
buildWorld.setCustomSpawn(player.getLocation());
player.sendMessage(plugin.getString("worlds_setspawn_world_spawn_set").replace("%world%", buildWorld.getName()));
break;
}
case "removespawn":
{
if (!player.hasPermission("buildsystem.removespawn")) {
plugin.sendPermissionMessage(player);
return true;
}
BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_removespawn_world_not_imported"));
return true;
}
buildWorld.removeCustomSpawn();
player.sendMessage(plugin.getString("worlds_removespawn_world_spawn_removed").replace("%world%", buildWorld.getName()));
break;
}
case "tp":
{
if (!player.hasPermission("buildsystem.worldtp")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length == 2) {
BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_tp_unknown_world"));
return true;
}
World bukkitWorld = Bukkit.getServer().getWorld(args[1]);
if (buildWorld.isLoaded() && bukkitWorld == null) {
player.sendMessage(plugin.getString("worlds_tp_unknown_world"));
return true;
}
if (player.hasPermission(buildWorld.getPermission()) || buildWorld.getPermission().equalsIgnoreCase("-")) {
worldManager.teleport(player, buildWorld);
} else {
player.sendMessage(plugin.getString("worlds_tp_entry_forbidden"));
}
return true;
} else {
player.sendMessage(plugin.getString("worlds_tp_usage"));
}
break;
}
case "unimport":
{
if (!player.hasPermission("buildsystem.unimport")) {
plugin.sendPermissionMessage(player);
return true;
}
if (args.length == 2) {
BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_unimport_unknown_world"));
return true;
}
worldManager.unimportWorld(buildWorld);
player.sendMessage(plugin.getString("worlds_unimport_finished").replace("%world%", buildWorld.getName()));
} else {
player.sendMessage(plugin.getString("worlds_unimport_usage"));
}
break;
}
default:
{
player.sendMessage(plugin.getString("worlds_unknown_command"));
break;
}
}
return true;
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class PlayerInteractAtEntityListener method disableArchivedWorlds.
private void disableArchivedWorlds(Player player, PlayerInteractAtEntityEvent event) {
World bukkitWorld = player.getWorld();
BuildWorld buildWorld = worldManager.getBuildWorld(bukkitWorld.getName());
if (buildWorld == null || buildWorld.getStatus() != WorldStatus.ARCHIVE) {
return;
}
if (!playerManager.getBuildPlayers().contains(player.getUniqueId())) {
event.setCancelled(true);
}
}
Aggregations