use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class WorldsTabComplete method onTabComplete.
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
ArrayList<String> arrayList = new ArrayList<>();
if (!(sender instanceof Player)) {
return arrayList;
}
Player player = (Player) sender;
switch(args.length) {
case 1:
{
for (Argument argument : Argument.values()) {
String command = argument.getCommand();
String permission = argument.getPermission();
if (permission == null || player.hasPermission(permission)) {
addArgument(args[0], command, arrayList);
}
}
return arrayList;
}
case 2:
{
switch(args[0].toLowerCase()) {
case "builders":
case "delete":
case "edit":
case "info":
case "rename":
case "setcreator":
case "setitem":
case "setpermission":
case "setproject":
case "setstatus":
case "tp":
case "unimport":
worldManager.getBuildWorlds().forEach(world -> {
if (player.hasPermission(world.getPermission()) || world.getPermission().equalsIgnoreCase("-")) {
String worldName = world.getName();
addArgument(args[1], worldName, arrayList);
}
});
break;
case "addbuilder":
case "removebuilder":
worldManager.getBuildWorlds().forEach(world -> {
if (player.hasPermission("buildsystem.admin") || (world.getCreatorId() != null && world.getCreatorId().equals(player.getUniqueId()))) {
String worldName = world.getName();
addArgument(args[1], worldName, arrayList);
}
});
break;
case "import":
String[] directories = Bukkit.getWorldContainer().list((dir, name) -> {
for (String charString : name.split("")) {
if (charString.matches("[^A-Za-z0-9/_-]")) {
return false;
}
}
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) {
return arrayList;
}
for (String projectName : directories) {
addArgument(args[1], projectName, arrayList);
}
break;
}
return arrayList;
}
case 3:
{
if (args[0].equalsIgnoreCase("import")) {
if (args[1].equalsIgnoreCase(" ")) {
return arrayList;
}
arrayList.add("-g");
return arrayList;
}
}
case 4:
{
if (!args[2].equalsIgnoreCase("-g")) {
return arrayList;
}
for (Generator value : new Generator[] { Generator.NORMAL, Generator.FLAT, Generator.VOID }) {
String valueName = value.name();
addArgument(args[3], valueName, arrayList);
}
return arrayList;
}
}
return arrayList;
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class PlayerManager method forceUpdateSidebar.
public void forceUpdateSidebar(BuildWorld buildWorld) {
if (!configValues.isScoreboard()) {
return;
}
World bukkitWorld = Bukkit.getWorld(buildWorld.getName());
if (bukkitWorld == null) {
return;
}
bukkitWorld.getPlayers().forEach(this::forceUpdateSidebar);
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class StatusInventory method onInventoryClick.
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
String selectedWorldName = playerManager.getSelectedWorldName(player);
if (selectedWorldName == null) {
return;
}
String title = plugin.getString("status_title").replace("%world%", selectedWorldName);
if (!event.getView().getTitle().equals(title)) {
return;
}
event.setCancelled(true);
ItemStack itemStack = event.getCurrentItem();
if (itemStack == null) {
return;
}
Material itemType = itemStack.getType();
if (itemType == Material.AIR || !itemStack.hasItemMeta()) {
return;
}
BuildWorld buildWorld = playerManager.getSelectedWorld().get(player.getUniqueId());
if (buildWorld == null) {
player.closeInventory();
player.sendMessage(plugin.getString("worlds_setstatus_error"));
return;
}
switch(event.getSlot()) {
case 10:
buildWorld.setStatus(WorldStatus.NOT_STARTED);
break;
case 11:
buildWorld.setStatus(WorldStatus.IN_PROGRESS);
break;
case 12:
buildWorld.setStatus(WorldStatus.ALMOST_FINISHED);
break;
case 13:
buildWorld.setStatus(WorldStatus.FINISHED);
break;
case 14:
buildWorld.setStatus(WorldStatus.ARCHIVE);
break;
case 16:
buildWorld.setStatus(WorldStatus.HIDDEN);
break;
default:
XSound.BLOCK_CHEST_OPEN.play(player);
plugin.getEditInventory().openInventory(player, buildWorld);
return;
}
playerManager.forceUpdateSidebar(buildWorld);
player.closeInventory();
XSound.ENTITY_CHICKEN_EGG.play(player);
player.sendMessage(plugin.getString("worlds_setstatus_set").replace("%world%", buildWorld.getName()).replace("%status%", buildWorld.getStatusName()));
playerManager.getSelectedWorld().remove(player.getUniqueId());
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class PlayerChangedWorldListener method checkWorldStatus.
@SuppressWarnings("deprecation")
private void checkWorldStatus(Player player) {
String worldName = player.getWorld().getName();
BuildWorld buildWorld = worldManager.getBuildWorld(worldName);
if (buildWorld == null) {
return;
}
UUID playerUUID = player.getUniqueId();
PlayerInventory playerInventory = player.getInventory();
if (this.playerGamemode.containsKey(playerUUID)) {
player.setGameMode(this.playerGamemode.get(playerUUID));
this.playerGamemode.remove(playerUUID);
}
if (this.playerInventory.containsKey(playerUUID)) {
playerInventory.clear();
playerInventory.setContents(this.playerInventory.get(playerUUID));
this.playerInventory.remove(playerUUID);
}
if (this.playerArmor.containsKey(playerUUID)) {
removeArmorContent(player);
playerInventory.setArmorContents(this.playerArmor.get(playerUUID));
this.playerArmor.remove(playerUUID);
}
if (buildWorld.getStatus() == WorldStatus.ARCHIVE) {
this.playerGamemode.put(playerUUID, player.getGameMode());
this.playerInventory.put(playerUUID, playerInventory.getContents());
this.playerArmor.put(playerUUID, playerInventory.getArmorContents());
removeArmorContent(player);
playerInventory.clear();
playerInventory.setItem(8, inventoryManager.getItemStack(configValues.getNavigatorItem(), plugin.getString("navigator_item")));
setSpectatorMode(player);
if (configValues.isArchiveVanish()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0, false, false), false);
Bukkit.getOnlinePlayers().forEach(pl -> pl.hidePlayer(player));
}
} else {
playerInventory.setItem(8, inventoryManager.getItemStack(configValues.getNavigatorItem(), plugin.getString("navigator_item")));
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
player.removePotionEffect(PotionEffectType.INVISIBILITY);
}
Bukkit.getOnlinePlayers().forEach(pl -> pl.showPlayer(player));
}
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class PlayerChangedWorldListener method onPlayerChangedWorld.
@EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();
String worldName = player.getWorld().getName();
BuildWorld oldWorld = worldManager.getBuildWorld(event.getFrom().getName());
if (oldWorld != null && configValues.isUnloadWorlds()) {
oldWorld.resetUnloadTask();
}
BuildWorld newWorld = worldManager.getBuildWorld(worldName);
if (newWorld != null) {
if (!newWorld.isPhysics()) {
if (player.hasPermission("buildsystem.physics.message")) {
player.sendMessage(plugin.getString("physics_deactivated_in_world").replace("%world%", newWorld.getName()));
}
}
}
removeOldNavigator(player);
removeBuildMode(player);
setGoldBlock(newWorld);
checkWorldStatus(player);
if (settingsManager.getSettings(player).isScoreboard()) {
playerManager.forceUpdateSidebar(player);
}
}
Aggregations