Repository navigation
Expand file tree
/
Copy pathNode.java
More file actions
713 lines (688 loc) · 20.1 KB
/
Copy pathNode.java
File metadata and controls
713 lines (688 loc) · 20.1 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
package net.tfminecraft.dowsing.objects;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import dev.lone.itemsadder.api.CustomFurniture;
import net.tfminecraft.dowsing.Cache;
import net.tfminecraft.dowsing.managers.NodeManager;
import net.tfminecraft.dowsing.utils.Database;
import net.tfminecraft.dowsing.utils.DropPaths;
import net.tfminecraft.dowsing.utils.ItemDropper;
import net.tfminecraft.dowsing.utils.NodeEngine;
import net.tfminecraft.simplefactions.guild.Guild;
import net.tfminecraft.simplefactions.managers.FactionManager;
import net.tfminecraft.simplefactions.utils.Formatter;
import net.tfminecraft.simplefactions.utils.Permissions;
public class Node {
UUID id;
Guild guild;
Boolean isActive;
Location loc;
Integer naturalYield;
Integer level;
NodeBlock block;
Integer timeLeft;
Integer cycleTime;
Integer modifiedTime;
Integer yield;
Double yieldPercent;
Double wealthModifier;
Double prestigeGain;
NodeType currentType;
Integer multiplier;
Double costIncrease;
Map<String, Integer> lastResult = new HashMap<>();
List<String> addedDrops = new ArrayList<String>();
List<String> errors = new ArrayList<String>();
Map<String, Double> completeDrop = new HashMap<>();
Double timeModifier;
Integer inputCounter;
Integer extraction;
Double upkeep;
//Production Efficiency
double efficiency = 0;
public Double getUpkeep() {
return upkeep;
}
public void setUpkeep(Double upkeep) {
this.upkeep = upkeep;
}
/**
* Charged by the SimpleFactions daily settlement for each day the node is active. The
* over-capacity multiplier is worked out from the guild's current nodes and capacity,
* since members joining or capacity being bought does not refresh every node.
*/
public double getDailyUpkeep() {
double base = upkeep == null ? 0.0 : upkeep;
return BigDecimal.valueOf(base)
.multiply(BigDecimal.valueOf(currentCostIncrease()))
.setScale(2, RoundingMode.HALF_UP)
.doubleValue();
}
double currentCostIncrease() {
if(resolveGuild() == null) return costIncrease == null ? 1.0 : costIncrease;
return costIncreaseFor(NodeManager.getNodeAmount(this.guild), getCapacity());
}
static double costIncreaseFor(int nodeAmount, int capacity) {
int multiplier = Math.max(1, 1+nodeAmount-capacity);
return 1.0+((multiplier-1.0)*0.5);
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public Boolean hasGuild() {
return resolveGuild() != null;
}
public Integer getExtraction() {
return extraction;
}
public void setExtraction(Integer extraction) {
this.extraction = extraction;
}
public Integer getInputCounter() {
return inputCounter;
}
public void setInputCounter(Integer inputCounter) {
this.inputCounter = inputCounter;
}
public Integer getCycleTime() {
return cycleTime;
}
public void setCycleTime(Integer cycleTime) {
this.cycleTime = cycleTime;
}
public Map<String, Double> getCompleteDrop() {
return completeDrop;
}
public Double getWealthModifier() {
return wealthModifier;
}
public void setWealthModifier(Double wealthModifier) {
this.wealthModifier = wealthModifier;
}
public Double getPrestigeGain() {
return prestigeGain;
}
public void setPrestigeGain(Double prestigeGain) {
this.prestigeGain = prestigeGain;
}
public List<String> getAddedDrops() {
return addedDrops;
}
public void setAddedDrops(List<String> addedDrops) {
this.addedDrops = addedDrops;
}
public Double getTimeModifier() {
return timeModifier;
}
public void setTimeModifier(Double timeModifier) {
this.timeModifier = timeModifier;
}
public Map<String, Integer> getLastResult() {
return lastResult;
}
public void setLastResult(Map<String, Integer> lastResult) {
this.lastResult = lastResult;
}
public NodeBlock getBlock() {
return block;
}
public void setBlock(NodeBlock block) {
this.block = block;
}
public NodeType getCurrentType() {
return currentType;
}
public void setCurrentType(NodeType currentType) {
this.currentType = currentType;
}
public Integer getYield() {
double base = yield == null ? 0 : yield;
double percent = yieldPercent == null ? 0.0 : yieldPercent;
return Math.max(0, (int) Math.round(base * (1.0 + percent / 100.0)));
}
public Integer getBaseYield() {
return yield == null ? 0 : yield;
}
public Double getYieldPercent() {
return yieldPercent == null ? 0.0 : yieldPercent;
}
public void setYield(Integer yield) {
this.yield = yield;
}
public Integer getModifiedTime() {
return modifiedTime;
}
public void setModifiedTime(Integer modifiedTime) {
this.modifiedTime = modifiedTime;
}
public Integer getTimeLeft() {
return timeLeft;
}
public void setTimeLeft(Integer timeLeft) {
this.timeLeft = timeLeft;
}
public Guild getGuild() {
return resolveGuild();
}
public void setGuild(Guild g) {
this.guild = g;
}
public Boolean getIsActive() {
return isActive;
}
public void setIsActive(Boolean isActive) {
this.isActive = isActive;
}
public Location getLoc() {
return loc;
}
public void setLoc(Location loc) {
this.loc = loc;
}
public Integer getLevel() {
return level;
}
public void setLevel(Integer level) {
this.level = level;
}
public Integer getNaturalYield() {
return naturalYield;
}
public void setNaturalYield(Integer naturalYield) {
this.naturalYield = naturalYield;
}
public List<String> getErrors() {
return errors;
}
public void setErrors(List<String> errors) {
this.errors = errors;
}
public Integer getMultiplier() {
return multiplier;
}
public void setMultiplier(Integer multiplier) {
this.multiplier = multiplier;
}
public double getNodeCapacityCost() {
Formatter format = new Formatter();
int extra = NodeManager.getExtraCapacity(resolveGuild());
return format.formatDouble(Cache.extraCapacityCost+(Cache.extraCapacityCost*extra));
}
public Double getCostIncrease() {
return costIncrease;
}
public void setCostIncrease(Double costIncrease) {
this.costIncrease = costIncrease;
}
public boolean isClaimable() {
return resolveGuild() == null;
}
//Efficiency
public double getEfficiency() {
return efficiency;
}
Guild resolveGuild() {
if(guild == null) {
return null;
}
Guild live = FactionManager.getGuildByString(guild.getId());
if(live == null) {
guild = null;
return null;
}
guild = live;
return guild;
}
public boolean canHold(Guild g){
if(g == null) return false;
Player p = Bukkit.getPlayerExact(g.getLeader());
if(p != null && p.isOnline() && Permissions.isAdmin(p)) return true;
if(g.getMembers().size() < Cache.minMembersForNode) return false;
if(NodeManager.getNodeAmount(g)-NodeManager.getNodeCapacity(g) > 0) return false;
return true;
}
public boolean canClaim(Player p, Guild g){
if(Permissions.isAdmin(p)) return true;
if(!isClaimable()) return false;
if(g.getMembers().size() < Cache.minMembersForNode){
p.sendMessage("§cYou need at least "+Cache.minMembersForNode+" members in your guild to claim this node!");
return false;
}
if(NodeManager.getNodeAmount(g)-NodeManager.getNodeCapacity(g) >= 0 && !block.isSpecial()) {
p.sendMessage("§cYour guild has already filled its node capacity!");
return false;
}
return true;
}
public Node(Location l, Guild g, NodeBlock b) {
this.id = UUID.randomUUID();
this.block = b;
this.loc = l;
this.guild = g;
if(b.isSpecial()){
this.guild = null;
}
this.efficiency = 50;
this.isActive = false;
this.level = 1;
this.yield = 0;
this.yieldPercent = 0.0;
this.timeModifier = 0.0;
this.prestigeGain = 0.0;
this.wealthModifier = 0.0;
this.cycleTime = 0;
this.currentType = b.getTypes().get(0);
this.upkeep = 0.0;
try {
this.naturalYield = getNaturalYieldFromChunk(this.currentType.getResource(), this.loc);
} catch (IOException e) {
e.printStackTrace();
}
this.timeLeft = currentType.getTimer();
this.modifiedTime = timeLeft;
this.inputCounter = 0;
this.multiplier = 1;
this.costIncrease = 1.0;
if(!isClaimable()) update();
}
public Node(UUID id, NodeBlock b, Location l, Guild g, Boolean active, int lvl, int cycleTime, NodeType currentType, int timeLeft, int inputCounter, double efficiency) {
this.id = id;
this.block = b;
this.loc = l;
this.guild = g;
this.efficiency = efficiency;
this.isActive = active;
this.level = lvl;
this.yield = 0;
this.yieldPercent = 0.0;
this.timeModifier = 0.0;
this.addedDrops = new ArrayList<String>();
this.extraction = 0;
this.naturalYield = 0;
this.upkeep = 0.0;
this.prestigeGain = 0.0;
this.wealthModifier = 0.0;
this.cycleTime = cycleTime;
this.timeLeft = timeLeft;
this.modifiedTime = timeLeft;
this.inputCounter = inputCounter;
this.multiplier = 1;
this.costIncrease = 1.0;
this.currentType = currentType;
if(!isClaimable()) update();
}
Integer getNaturalYieldFromChunk(NodeBlock b, Location l) throws NumberFormatException, IOException {
Database db = new Database();
if(db.hasResource(l.getChunk())) {
String resource = db.getResource(l.getChunk()).split("\\.")[0];
Integer yield = Integer.parseInt(db.getResource(l.getChunk()).split("\\.")[1]);
if(b.getResource().equalsIgnoreCase(resource)) {
return yield;
}
}
return 0;
}
public void check() {
if(isClaimable()) return;
Guild g = resolveGuild();
if(g == null) return;
if(canHold(g)) return;
Player p = Bukkit.getPlayer(g.getLeader());
if(p != null && p.isOnline()) {
p.sendMessage("§cYou lost control of the "+block.getResource()+" Node §c!");
p.closeInventory();
}
guild = null;
NodeManager.requestNodeBenefitSync();
}
public void tick() {
if(!isClaimable()) this.timeLeft = this.timeLeft-1;
}
public void tickCycle() {
if(!isClaimable()) this.cycleTime = this.cycleTime+1;
}
public void input() {
NodeEngine ng = new NodeEngine();
Boolean failed = false;
this.errors.clear();
if(!ng.hasBarrel(this)) {
failed = true;
this.errors.add("§7No barrel");
}
if(!ng.hasHopper(this)) {
failed = true;
this.errors.add("§7No hopper");
this.errors.add("§7Lacking resources");
}
if(ng.hasBarrel(this)) {
if(!ng.hasInputs(this)) {
failed = true;
this.errors.add("§7Lacking resources");
}
}
if(failed) {
if(this.isActive) {
this.deActivate();
}
this.update();
return;
}
ng.takeInputs(this);
}
public void refund() {
NodeEngine ng = new NodeEngine();
Boolean failed = false;
this.errors.clear();
if(!ng.hasBarrel(this)) {
failed = true;
this.errors.add("§7No barrel");
}
if(!ng.hasHopper(this)) {
failed = true;
this.errors.add("§7No hopper");
this.errors.add("§7Lacking resources");
}
if(failed) {
if(this.isActive) {
this.deActivate();
}
this.update();
return;
}
ng.refund(this);;
}
public void activate() {
if(hasPendingRefund()) {
deActivate();
return;
}
if(isClaimable()) return;
NodeEngine ng = new NodeEngine();
Boolean failed = false;
this.errors.clear();
if(!ng.hasBarrel(this)) {
failed = true;
this.errors.add("§7No barrel");
}
if(!ng.hasHopper(this)) {
failed = true;
this.errors.add("§7No hopper");
this.errors.add("§7Lacking resources");
}
if(ng.hasBarrel(this)) {
if(!ng.hasInputs(this)) {
failed = true;
this.errors.add("§7Lacking resources");
}
}
if(this.guild == null || this.guild.getBank() == null || this.guild.isBankrupt()) {
failed = true;
this.errors.add("§7No bank");
}
if(this.guild != null && this.guild.getBank() != null) {
if(this.guild.isBankrupt() || this.guild.getBank().getWealth() < getDailyUpkeep()) {
failed = true;
this.errors.add("§7Lacking upkeep");
}
}
if(this.currentType.getBiomes().size() > 0) {
String biome = this.loc.getBlock().getBiome().toString();
if(!this.currentType.getBiomes().contains(biome)) {
failed = true;
this.errors.add("§7Wrong biome, change type");
}
}
for(NodeSlot slot : this.currentType.getSlots()) {
if(!ng.checkPrerequisite(slot.getActivePm(), this)) {
failed = true;
this.errors.add("§7"+WordUtils.capitalize(slot.getActivePm().getId().replace("_", " ") +" requires at least "+ WordUtils.capitalize(slot.getActivePm().getPrerequisite().replace("_", " "))));
}
}
if(failed) {
return;
}
this.isActive = true;
this.timeLeft = this.modifiedTime;
this.cycleTime = 0;
ng.takeInputs(this);
NodeManager.requestNodeBenefitSync();
}
/** Whether an inactive node still owes refunds from an interrupted cycle. */
public boolean hasPendingRefund() {
return !this.isActive && this.inputCounter > 0
&& this.cycleTime >= 0 && this.cycleTime < Cache.cycleLength;
}
public void deActivate() {
this.isActive = false;
if(isClaimable()) return;
if(this.cycleTime >= 0 && this.cycleTime < Cache.cycleLength) {
while(this.getInputCounter() > 0) {
int pendingInputs = this.getInputCounter();
refund();
// A missing barrel or hopper prevents refunds. Keep the pending inputs for retry.
if(this.getInputCounter() >= pendingInputs) break;
}
}
NodeManager.requestNodeBenefitSync();
}
public void growEfficiency() {
if(resolveGuild() == null) return;
int members = guild.getMembers().size();
double growth = Math.min(1.0, members*Cache.efficiencyGrowthPerMember);
updateEfficiency(growth);
}
public double getMaxEfficiency() {
if(resolveGuild() == null) return 0;
return Math.min(100.0, guild.getMembers().size()*Cache.maxEfficiencyPerMember);
}
public void updateEfficiency(double eff) {
efficiency += eff;
if(efficiency < 0) efficiency = 0;
if(efficiency > getMaxEfficiency()) efficiency = getMaxEfficiency();
}
public void updateEfficiencyTime() {
int old = modifiedTime;
// Scale goes from 4x (eff=0) down to 1x (eff=100)
double scale = 4.0 - (efficiency / 100.0) * 3.0;
modifiedTime = (int) Math.round(modifiedTime * scale);
}
public void update() {
if(isClaimable()) return;
this.yield = 0;
this.yieldPercent = 0.0;
this.timeModifier = 0.0;
this.addedDrops = new ArrayList<String>();
this.extraction = 0;
this.naturalYield = 0;
this.upkeep = 0.0;
this.prestigeGain = 0.0;
try {
this.naturalYield = getNaturalYieldFromChunk(this.currentType.getResource(), this.loc);
} catch (IOException e) {
e.printStackTrace();
}
for(NodeSlot slot : this.getCurrentType().getSlots()) {
ProductionMethod pm = slot.getActivePm();
for(String s : pm.getEffects()) {
if(s.contains("extraction") && this.getNaturalYield() < 1) {
continue;
}
runEffect(s);
}
}
Level lvl = this.getCurrentType().getLevels().get(this.getLevel()-1);
for(String s : lvl.getEffects()) {
runEffect(s);
}
Double newWealthModifier = 0.0;
for(Level l : this.getCurrentType().getLevels()) {
if(l.getLevel() <= this.getLevel()) {
newWealthModifier = newWealthModifier+l.getCost();
}
}
this.wealthModifier = newWealthModifier;
if(this.extraction > this.naturalYield) {
this.extraction = this.naturalYield;
}
if(this.naturalYield > 0) {
Integer extractionY = this.currentType.getYieldNaturalYield();
Double timeY = this.currentType.getTimeNaturalYield();
Integer e = this.extraction;
if(e > 0) {
timeModifier = timeModifier+(timeY*e);
}
while(e >= extractionY) {
this.yield++;
e = e-extractionY;
}
}
if(this.timeModifier < -99) {
modifiedTime = 1;
} else {
modifiedTime = (int) Math.round(this.getCurrentType().getTimer()*(1+(this.timeModifier/100)));
}
updateEfficiencyTime();
if(timeLeft > modifiedTime) timeLeft = modifiedTime;
setCompleteDrops();
int nodeAmount = NodeManager.getNodeAmount(this.guild);
int capacity = getCapacity();
this.multiplier = Math.max(1, 1+nodeAmount-capacity);
Formatter format = new Formatter();
this.costIncrease = format.formatDouble(costIncreaseFor(nodeAmount, capacity));
this.upkeep = format.formatDouble(this.upkeep);
}
Double getAddedPrestige(String e) {
String type = e.split("\\(")[0];
if(type.equalsIgnoreCase("prestige")) {
return Double.parseDouble(e.split("\\(")[1].replace(")", ""));
}
return 0.0;
}
public int getCapacity() {
int capacity = 1;
if(Cache.extraCapacity && resolveGuild() != null) {
int members = this.guild.getMembers().size();
int added = (int) Math.floorDiv(members, Cache.membersPerCapacity);
capacity = capacity+added+NodeManager.getExtraCapacity(this.guild);
}
return capacity;
}
void setCompleteDrops() {
this.completeDrop.clear();
for(String s : this.getCurrentType().getDrops()) {
addCompleteDrop(s);
}
for(String s : this.addedDrops) {
addCompleteDrop(s);
}
}
void addCompleteDrop(String token) {
String[] drop = DropPaths.parseStored(token);
if(drop == null) {
return;
}
String key = drop[0];
Double amount = Double.parseDouble(drop[1]);
if(this.completeDrop.containsKey(key)) {
amount = amount+this.completeDrop.get(key);
}
this.completeDrop.put(key, amount);
}
void runEffect(String e) {
String type = e.split("\\(")[0];
if(type.equalsIgnoreCase("time_modifier")) {
timeModifier = timeModifier+Double.parseDouble(e.split("\\(")[1].replace(")", ""));
} else if(type.equalsIgnoreCase("yield")) {
yield = yield+Integer.parseInt(e.split("\\(")[1].replace(")", ""));
} else if(type.equalsIgnoreCase("yield_percent")) {
yieldPercent = yieldPercent+Double.parseDouble(e.split("\\(")[1].replace(")", ""));
} else if(type.equalsIgnoreCase("add_drop")) {
String[] drop = DropPaths.parseAddDropEffect(e);
if(drop != null) {
addedDrops.add(DropPaths.formatStored(drop[0], Double.parseDouble(drop[1])));
}
} else if(type.equalsIgnoreCase("extraction")) {
extraction = extraction+Integer.parseInt(e.split("\\(")[1].replace(")", ""));
} else if(type.equalsIgnoreCase("upkeep")) {
upkeep = upkeep+Double.parseDouble(e.split("\\(")[1].replace(")", ""));
} else if(type.equalsIgnoreCase("prestige")) {
prestigeGain = prestigeGain+getAddedPrestige(e);
}
}
public Integer getNaturalYieldFromChunk(String resource, Location l) throws IOException {
if(!Cache.naturalYieldEnabled) {
return 0;
}
Chunk c = l.getChunk();
Database db = new Database();
if(db.hasResource(c)) {
String s = db.getResource(c);
String dbResource = s.split("\\.")[0];
Integer yield = Integer.parseInt(s.split("\\.")[1]);
if(resource.equalsIgnoreCase(dbResource)) {
return yield;
}
}
return 0;
}
public void breakNode() {
String path = this.getBlock().getBlock();
String type = path.split("\\.")[0];
if(type.equalsIgnoreCase("v")) {
this.loc.getBlock().setType(Material.AIR);
} else if(type.equalsIgnoreCase("ia")) {
removeNearbyFurniture();
if(this.loc.getBlock().getType() != Material.AIR) {
this.loc.getBlock().setType(Material.AIR);
}
}
Location loc = new Location(this.getLoc().getWorld(), this.getLoc().getX(), this.getLoc().getY(), this.getLoc().getZ());
loc.add(0.5,0,0.5);
ItemDropper dropper = new ItemDropper();
dropper.dropItem(loc, path, false);
loc.getWorld().playSound(loc, Sound.ENTITY_GLOW_ITEM_FRAME_REMOVE_ITEM, 0.5f, 1f);
NodeManager.requestNodeBenefitSync();
}
private void removeNearbyFurniture() {
Location center = this.loc.clone().add(0.5, 0.5, 0.5);
for(Entity entity : this.loc.getWorld().getNearbyEntities(center, 1.5, 1.5, 1.5)) {
if(!isFurnitureCarrier(entity)) continue;
CustomFurniture furniture = lookupFurniture(entity);
if(furniture != null) {
furniture.remove(false);
break;
}
}
}
private static CustomFurniture lookupFurniture(Entity entity) {
try {
return CustomFurniture.byAlreadySpawned(entity);
} catch (RuntimeException ex) {
// ItemsAdder throws for entities that are not furniture instead of returning null.
return null;
}
}
private static boolean isFurnitureCarrier(Entity entity) {
return entity instanceof ArmorStand || entity instanceof ItemFrame || entity instanceof ItemDisplay;
}
}