use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by Trichtern.
the class BlockPlaceListener method onCustomBlockPlace.
@EventHandler
public void onCustomBlockPlace(BlockPlaceEvent event) {
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer();
String worldName = player.getWorld().getName();
BuildWorld buildWorld = worldManager.getBuildWorld(worldName);
boolean isBuildWorld = buildWorld != null;
ItemStack itemStack = player.getItemInHand();
XMaterial xMaterial = XMaterial.matchXMaterial(itemStack);
if (xMaterial != XMaterial.PLAYER_HEAD) {
return;
}
boolean hadToDisablePhysics = false;
if (isBuildWorld && !buildWorld.isPhysics()) {
hadToDisablePhysics = true;
buildWorld.setPhysics(true);
}
plugin.getCustomBlocks().setBlock(event, plugin.getString("blocks_full_oak_barch"), plugin.getString("blocks_full_spruce_barch"), plugin.getString("blocks_full_birch_barch"), plugin.getString("blocks_full_jungle_barch"), plugin.getString("blocks_full_acacia_barch"), plugin.getString("blocks_full_dark_oak_barch"), plugin.getString("blocks_red_mushroom"), plugin.getString("blocks_brown_mushroom"), plugin.getString("blocks_full_mushroom_stem"), plugin.getString("blocks_mushroom_stem"), plugin.getString("blocks_mushroom_block"), plugin.getString("blocks_smooth_stone"), plugin.getString("blocks_double_stone_slab"), plugin.getString("blocks_smooth_sandstone"), plugin.getString("blocks_smooth_red_sandstone"), plugin.getString("blocks_powered_redstone_lamp"), plugin.getString("blocks_burning_furnace"), plugin.getString("blocks_command_block"), plugin.getString("blocks_barrier"), plugin.getString("blocks_mob_spawner"), plugin.getString("blocks_nether_portal"), plugin.getString("blocks_end_portal"), plugin.getString("blocks_dragon_egg"));
if (isBuildWorld && hadToDisablePhysics) {
buildWorld.setPhysics(false);
}
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by Trichtern.
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.getPlayerExact(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 (builderId.equals(player.getUniqueId()) && buildWorld.isCreator(player)) {
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 Trichtern.
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.navigator")) {
plugin.sendPermissionMessage(player);
return true;
}
plugin.getNavigatorInventory().openInventory(player);
XSound.BLOCK_CHEST_OPEN.play(player);
return true;
}
// Most command use the structure /worlds <argument> <world> <...> which is why we assume that args[1] is the world name
// Make sure to change if this is not the case for any specific command
String worldName = args.length >= 2 ? args[1] : player.getWorld().getName();
switch(args[0].toLowerCase()) {
case "addbuilder":
{
if (!plugin.isPermitted(player, "buildsystem.addbuilder", worldName)) {
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.isCreator(player) && !player.hasPermission(BuildSystem.ADMIN_PERMISSION)) {
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 (!plugin.isPermitted(player, "buildsystem.builders", worldName)) {
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 (!plugin.isPermitted(player, "buildsystem.delete", worldName)) {
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;
}
if (!buildWorld.isCreator(player) && !player.hasPermission(BuildSystem.ADMIN_PERMISSION)) {
player.sendMessage(plugin.getString("worlds_delete_not_creator"));
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 (!plugin.isPermitted(player, "buildsystem.edit", worldName)) {
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;
try {
generator = Generator.valueOf(args[3].toUpperCase());
} catch (IllegalArgumentException e) {
generator = Generator.CUSTOM;
}
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":
{
World playerWorld = player.getWorld();
if (args.length != 2) {
// When running /worlds info, use the player's world when checking for permission
worldName = playerWorld.getName();
}
if (!plugin.isPermitted(player, "buildsystem.info", worldName)) {
plugin.sendPermissionMessage(player);
return true;
}
BuildWorld buildWorld = worldManager.getBuildWorld(playerWorld.getName());
if (args.length == 2) {
if (buildWorld == null) {
player.sendMessage(plugin.getString("worlds_info_unknown_world"));
return true;
}
buildWorld = worldManager.getBuildWorld(args[1]);
} else {
player.sendMessage(plugin.getString("worlds_info_usage"));
}
sendInfoMessage(player, buildWorld);
break;
}
case "item":
{
if (!player.hasPermission("buildsystem.navigator.item")) {
plugin.sendPermissionMessage(player);
return true;
}
player.getInventory().addItem(inventoryManager.getItemStack(plugin.getConfigValues().getNavigatorItem(), plugin.getString("navigator_item")));
player.sendMessage(plugin.getString("worlds_item_receive"));
break;
}
case "removebuilder":
{
if (!plugin.isPermitted(player, "buildsystem.removebuilder", worldName)) {
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.isCreator(player) && !player.hasPermission(BuildSystem.ADMIN_PERMISSION)) {
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 (!plugin.isPermitted(player, "buildsystem.rename", worldName)) {
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 (!plugin.isPermitted(player, "buildsystem.setcreator", worldName)) {
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 (!plugin.isPermitted(player, "buildsystem.setitem", worldName)) {
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 (!plugin.isPermitted(player, "buildsystem.setpermission", worldName)) {
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 (!plugin.isPermitted(player, "buildsystem.setproject", worldName)) {
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 (!plugin.isPermitted(player, "buildsystem.setstatus", worldName)) {
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":
{
String playerWorldName = player.getWorld().getName();
if (!plugin.isPermitted(player, "buildsystem.setspawn", playerWorldName)) {
plugin.sendPermissionMessage(player);
return true;
}
BuildWorld buildWorld = worldManager.getBuildWorld(playerWorldName);
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":
{
String playerWorldName = player.getWorld().getName();
if (!plugin.isPermitted(player, "buildsystem.removespawn", playerWorldName)) {
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, true);
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 Trichtern.
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 Trichtern.
the class BuildSystem method reloadConfigData.
public void reloadConfigData(boolean init) {
for (Player pl : Bukkit.getOnlinePlayers()) {
getSettingsManager().stopScoreboard(pl);
}
configValues.setConfigValues();
if (init) {
initVersionedClasses();
worldManager.getBuildWorlds().forEach(BuildWorld::manageUnload);
if (configValues.isScoreboard()) {
getSettingsManager().startScoreboard();
} else {
getSettingsManager().stopScoreboard();
}
}
}
Aggregations