8
8
9
9
10
10
import org .bukkit .Bukkit ;
11
+ import org .bukkit .Location ;
12
+ import org .bukkit .Material ;
11
13
import org .bukkit .Particle ;
12
14
import org .bukkit .Sound ;
13
15
import org .bukkit .SoundCategory ;
14
16
import org .bukkit .block .Block ;
15
17
import org .bukkit .entity .Player ;
16
18
import org .bukkit .event .Listener ;
19
+ import org .jetbrains .annotations .Nullable ;
20
+ import java .util .Objects ;
17
21
import java .util .Random ;
18
22
23
+ import world .bentobox .bentobox .api .user .User ;
24
+ import world .bentobox .bentobox .database .objects .Island ;
19
25
import world .bentobox .magiccobblestonegenerator .StoneGeneratorAddon ;
20
26
import world .bentobox .magiccobblestonegenerator .database .objects .GeneratorDataObject ;
27
+ import world .bentobox .magiccobblestonegenerator .database .objects .GeneratorTierObject ;
21
28
22
29
23
30
/**
@@ -42,48 +49,60 @@ public GeneratorListener(StoneGeneratorAddon addon)
42
49
// ---------------------------------------------------------------------
43
50
44
51
52
+ /**
53
+ * This method returns if someone from the island is online. The method do nothing, if offline
54
+ * offline generation is enabled.
55
+ * @param island Island that must be checked.
56
+ * @return {@code true} if someone is online or offline generation is enabled, {@code false} otherwise.
57
+ */
58
+ protected boolean isSomeoneOnline (Island island )
59
+ {
60
+ return addon .getSettings ().isOfflineGeneration () ||
61
+ island .getMemberSet ().stream ().
62
+ map (User ::getInstance ).
63
+ filter (Objects ::nonNull ).
64
+ anyMatch (User ::isOnline );
65
+ }
66
+
67
+
45
68
/**
46
69
* This method returns there is an island member in range to active of "custom" block generation
47
70
*
48
71
* @param block Block that must be checked.
49
72
* @return true if there is a player in the set range
50
73
*/
51
- protected boolean isInRangeToGenerate (Block block )
74
+ protected boolean isInRangeToGenerate (Island island , Block block )
52
75
{
53
76
// If settings value is 0, then assume that it is not set at all.
54
77
int workingRange = this .addon .getSettings ().getDefaultWorkingRange ();
55
78
79
+ // Check if any island member is near block.
56
80
if (workingRange > 0 )
57
81
{
58
- // Check if any island member is near block.
59
- return this .addon .getIslands ().getIslandAt (block .getLocation ()).
60
- map (island ->
61
- {
62
- GeneratorDataObject data = this .addon .getAddonManager ().getGeneratorData (island );
63
-
64
- if (data == null )
65
- {
66
- // If data object is not found, return false.
67
- return false ;
68
- }
69
-
70
- // Use range from island object.
71
- int range = data .getRange ();
72
-
73
- // If range is -1 or 0, the ignore it.
74
- if (range == -1 || range == 0 )
75
- {
76
- return true ;
77
- }
78
-
79
- return block .getWorld ().getNearbyEntities (block .getLocation (),
80
- range ,
81
- range ,
82
- range ).
83
- stream ().
84
- filter (Player .class ::isInstance ).
85
- anyMatch (e -> island .getMemberSet ().contains (e .getUniqueId ()));
86
- }).orElse (false );
82
+ GeneratorDataObject data = this .addon .getAddonManager ().getGeneratorData (island );
83
+
84
+ if (data == null )
85
+ {
86
+ // If data object is not found, return false.
87
+ return false ;
88
+ }
89
+
90
+ // Use range from island object.
91
+ int range = data .getRange ();
92
+
93
+ // If range is -1 or 0, the ignore it.
94
+ if (range == -1 || range == 0 )
95
+ {
96
+ return true ;
97
+ }
98
+
99
+ return block .getWorld ().getNearbyEntities (block .getLocation (),
100
+ range ,
101
+ range ,
102
+ range ).
103
+ stream ().
104
+ filter (Player .class ::isInstance ).
105
+ anyMatch (e -> island .getMemberSet ().contains (e .getUniqueId ()));
87
106
}
88
107
else
89
108
{
@@ -130,38 +149,56 @@ protected void playEffects(Block block)
130
149
131
150
132
151
/**
133
- * This method returns if generator manages to replace cobblestone to a new magic block.
152
+ * This method returns material of new block if generator manages to replace cobblestone to a new magic block.
134
153
*
135
- * @param replacedBlock Block that need to be replaced.
136
- * @return {@code true} if block is replaced, {@code false} otherwise.
154
+ * @param island Island on which block is processed.
155
+ * @param location Block location that need to be replaced.
156
+ * @return Material of replaced block or null, if block was not replaced.
137
157
*/
138
- protected boolean isCobblestoneReplacementGenerated ( Block replacedBlock )
158
+ protected @ Nullable Material generateCobblestoneReplacement ( @ Nullable Island island , Location location )
139
159
{
140
- return this .addon .getGenerator ().isCobblestoneReplacementGenerated (replacedBlock );
160
+ GeneratorTierObject generatorTier = this .addon .getAddonManager ().getGeneratorTier (
161
+ island ,
162
+ location ,
163
+ GeneratorTierObject .GeneratorType .COBBLESTONE );
164
+
165
+ return this .addon .getGenerator ().processBlockReplacement (generatorTier , location );
141
166
}
142
167
143
168
144
169
/**
145
- * This method returns if generator manages to replace stone to a new magic block.
170
+ * This method returns material of new block if generator manages to replace stone to a new magic block.
146
171
*
147
- * @param replacedBlock Block that need to be replaced.
148
- * @return {@code true} if block is replaced, {@code false} otherwise.
172
+ * @param island Island on which block is processed.
173
+ * @param location Block that need to be replaced.
174
+ * @return Material of replaced block or null, if block was not replaced.
149
175
*/
150
- protected boolean isStoneReplacementGenerated ( Block replacedBlock )
176
+ protected @ Nullable Material generateStoneReplacement ( @ Nullable Island island , Location location )
151
177
{
152
- return this .addon .getGenerator ().isStoneReplacementGenerated (replacedBlock );
178
+ GeneratorTierObject generatorTier = this .addon .getAddonManager ().getGeneratorTier (
179
+ island ,
180
+ location ,
181
+ GeneratorTierObject .GeneratorType .STONE );
182
+
183
+ return this .addon .getGenerator ().processBlockReplacement (generatorTier , location );
153
184
}
154
185
155
186
156
187
/**
157
- * This method returns if generator manages to replace basalt to a new magic block.
188
+ * This method returns material of new block if generator manages to replace basalt to a new magic block.
158
189
*
159
- * @param replacedBlock Block that need to be replaced.
160
- * @return {@code true} if block is replaced, {@code false} otherwise.
190
+ * @param island Island on which block is processed.
191
+ * @param location Block that need to be replaced.
192
+ * @return Material of replaced block or null, if block was not replaced.
161
193
*/
162
- protected boolean isBasaltReplacementGenerated ( Block replacedBlock )
194
+ protected @ Nullable Material generateBasaltReplacement ( @ Nullable Island island , Location location )
163
195
{
164
- return this .addon .getGenerator ().isBasaltReplacementGenerated (replacedBlock );
196
+ GeneratorTierObject generatorTier = this .addon .getAddonManager ().getGeneratorTier (
197
+ island ,
198
+ location ,
199
+ GeneratorTierObject .GeneratorType .BASALT );
200
+
201
+ return this .addon .getGenerator ().processBlockReplacement (generatorTier , location );
165
202
}
166
203
167
204
0 commit comments