-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLandEdit.php
93 lines (77 loc) · 2.59 KB
/
LandEdit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
#Loads Land.yml into PHP Array
$file = __DIR__ . '/Land.yml';
$array = yaml_parse_file($file);
echo "Loaded into PHP: \n";
print_r($array);
echo "Would you like to
\n1: Delete all land claims by owner?
\n2: Delete all land claims except owner?
\n3: Delete all land claims in an area?\n";
$answer = readline("\nType 1, 2, or 3: ");
#Answer 1
if ($answer == 1){
$ownerName = readline("What is the owner's name?: ");
#Searches land array for owner
if(array_search($ownerName, array_column($array, 'owner')) !== false ){
echo "...Found $ownerName \n";
#Removes owner from array
$array = removeElementWithValue($array, 'owner', $ownerName);
#Sends data back to Land.yml
$landAfterDump = yaml_emit(array_values($array));
file_put_contents($file, $landAfterDump);
echo "YAML Data dumped back: \n";
echo $landAfterDump;
echo "...Successfully removed claims owned by $ownerName \n";
}else{
echo 'Did not find ' . $ownerName . "\n";
}
#Answer 2
}elseif ($answer == 2){
$ownerName = readline("What is the owner's name?: ");
#Searches land array for owner
if(array_search($ownerName, array_column($array, 'owner')) !== false ){
echo "...Found claims by $ownerName \n";
#Removes from array except owner
$array = removeElementWithValueExcept($array, 'owner', $ownerName);
#Sends data back to Land.yml
$landAfterDump = yaml_emit(array_values($array));
file_put_contents($file, $landAfterDump);
echo "YAML Data dumped back: \n";
echo $landAfterDump;
echo "...Successfully removed claims not owned by $ownerName \n";
}
else {
echo 'Did not find ' . $ownerName . "\n";
}
#Answer 3
}elseif ($answer == 3){
echo "Feature coming soonish \n";
/*
$xStart = readline("What is the starting X coordinate: ");
$zStart = readline("What is the starting Z coordinate: ");
$xEnd = readline("what is the ending X coordinate: ");
$zEnd = readline("What is the ending Z coordinate: ");
#Determine if claims exist between coordinates
*/
}else {
echo "Input not recognized. Please run program again.\n";
}
#Remove from array
function removeElementWithValue($array, $key, $value){
foreach($array as $subKey => $subArray){
if($subArray[$key] == $value){
unset($array[$subKey]);
}
}
return $array;
}
#Remove from array except
function removeElementWithValueExcept($array, $key, $value){
foreach($array as $subKey => $subArray){
if($subArray[$key] !== $value){
unset($array[$subKey]);
}
}
return $array;
}