Skip to content

Commit f0e955a

Browse files
Fixed Inventory Issue
1 parent 42340de commit f0e955a

File tree

4 files changed

+64
-51
lines changed

4 files changed

+64
-51
lines changed

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@
6767
<scope>provided</scope>
6868
</dependency>
6969

70+
<dependency>
71+
<groupId>net.guizhanss</groupId>
72+
<artifactId>GuizhanLib-slimefun</artifactId>
73+
<version>1.2.2</version>
74+
</dependency>
75+
76+
<dependency>
77+
<groupId>com.google.guava</groupId>
78+
<artifactId>guava</artifactId>
79+
<version>28.0-jre</version>
80+
</dependency>
81+
7082

7183
<dependency>
7284
<groupId>com.github.Slimefun</groupId>

src/main/java/me/pranavverma/advancedtech/general/items/commanders/command_hub/command_hub.java

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
import io.github.thebusybiscuit.slimefun4.implementation.handlers.SimpleBlockBreakHandler;
1313
import io.github.thebusybiscuit.slimefun4.libraries.dough.skins.PlayerHead;
1414
import io.github.thebusybiscuit.slimefun4.libraries.dough.skins.PlayerSkin;
15+
import lombok.Getter;
1516
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
1617
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
1718
import me.mrCookieSlime.Slimefun.api.BlockStorage;
1819
import me.pranavverma.advancedtech.general.BaseItems;
1920
import me.pranavverma.advancedtech.general.items.solargen.AdvancedSolarGen.AdvancedSolarGen;
21+
import net.guizhanss.guizhanlib.slimefun.machines.TickingMenuBlock;
2022
import me.pranavverma.advancedtech.AdvancedTech;
2123
import org.bukkit.ChatColor;
2224
import org.bukkit.Material;
@@ -37,53 +39,39 @@
3739
import org.bukkit.event.Listener;
3840
import org.bukkit.event.Event.Result;
3941
import org.bukkit.plugin.java.JavaPlugin;
40-
42+
import java.util.HashMap;
43+
import java.util.Map;
4144
import org.bukkit.Location;
42-
import org.bukkit.Material;
43-
import org.bukkit.block.Block;
44-
import org.bukkit.entity.Entity;
45-
import org.bukkit.entity.EntityType;
46-
import org.bukkit.entity.Player;
47-
import org.bukkit.event.block.BlockPlaceEvent;
48-
import org.bukkit.inventory.ItemStack;
45+
4946

5047
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
51-
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
5248
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
5349
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
54-
import io.github.thebusybiscuit.slimefun4.api.researches.Research;
55-
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
5650
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
57-
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
58-
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
59-
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
60-
import io.github.thebusybiscuit.slimefun4.implementation.items.food.MeatJerky;
61-
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack;
62-
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
63-
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
64-
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
6551
import me.mrCookieSlime.Slimefun.api.BlockStorage;
6652
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
6753
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
68-
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
54+
import org.bukkit.Location;
55+
import org.bukkit.block.Block;
56+
import org.bukkit.event.block.BlockBreakEvent;
57+
import org.bukkit.event.block.BlockPlaceEvent;
58+
import org.bukkit.inventory.ItemStack;
6959

70-
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack;
71-
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
72-
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
73-
import lombok.AccessLevel;
74-
import lombok.Setter;
75-
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
60+
import javax.annotation.ParametersAreNonnullByDefault;
7661

7762

7863
public class command_hub extends SlimefunItem implements HologramOwner, Listener {
7964

8065
public static boolean readyToUse = false;
81-
public static boolean AdvancedSolarGenFound = false;
82-
public static boolean onCommandHubRemoval = false;
66+
//Done
67+
private boolean AdvancedSolarGenFound = false;
68+
69+
protected static final Map<Location, Object> CACHES = new HashMap<>();
8370

8471

8572
public command_hub(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
8673
super(itemGroup, item, recipeType, recipe);
74+
8775

8876
addItemHandler(onBreak());
8977
addItemHandler(onPlace());
@@ -92,7 +80,7 @@ public command_hub(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recip
9280
public boolean isSynchronized() {
9381
return true;
9482
}
95-
83+
9684
@Override
9785
public void tick(Block block, SlimefunItem slimefunItem, Config config) {
9886
if (scanForCommandEngine(block)) {
@@ -106,6 +94,8 @@ public void tick(Block block, SlimefunItem slimefunItem, Config config) {
10694

10795
if (scanForAdvancedSolarGen(block)) {
10896
AdvancedSolarGenFound = true;
97+
98+
10999
} else {
110100
AdvancedSolarGenFound = false;
111101
}
@@ -120,7 +110,6 @@ public void preRegister() {
120110
addItemHandler(blockUseHandler);
121111

122112
}
123-
124113

125114

126115

@@ -132,7 +121,6 @@ private BlockBreakHandler onBreak() {
132121
@Override
133122
public void onBlockBreak(@Nonnull Block b) {
134123
removeHologram(b);
135-
onCommandHubRemoval = true;
136124
}
137125
};
138126
}
@@ -188,7 +176,6 @@ private boolean scanForAdvancedSolarGen (@Nonnull Block block){
188176

189177
@Nonnull
190178
private BlockPlaceHandler onPlace() {
191-
onCommandHubRemoval = false;
192179

193180
return new BlockPlaceHandler(true) {
194181
@Override
@@ -265,7 +252,24 @@ public void onInventoryClick(InventoryClickEvent event) {
265252
HumanEntity human = event.getWhoClicked();
266253
Inventory inventory = event.getClickedInventory();
267254

268-
if (human instanceof Player && inventory != null && inventory.getSize() == 9 && inventory.getItem(0).hasItemMeta()) {
255+
if (human instanceof Player && inventory != null && inventory.getSize() == 9 && inventory.getItem(0).hasItemMeta() && inventory.getItem(8).getType() == Material.BLACK_STAINED_GLASS && inventory.getItem(7).getType() == Material.BLACK_STAINED_GLASS && inventory.getItem(6).getType() == Material.BLACK_STAINED_GLASS) {
256+
if (inventory.getItem(0) == null) {
257+
258+
}
259+
260+
if (inventory.getItem(6) == null) {
261+
262+
}
263+
264+
if (inventory.getItem(7) == null) {
265+
266+
}
267+
268+
if (inventory.getItem(8) == null) {
269+
270+
}
271+
272+
269273
event.setResult(Result.DENY); // Cancel the click event
270274
event.setCancelled(true);
271275

@@ -279,7 +283,7 @@ public void onInventoryDrag(InventoryDragEvent event) {
279283

280284

281285

282-
if (human instanceof Player && inventory != null && inventory.getSize() == 9 && inventory.getItem(0).hasItemMeta()) {
286+
if (human instanceof Player && inventory != null && inventory.getSize() == 9 && inventory.getItem(0).hasItemMeta() && inventory.getItem(8).getType() == Material.BLACK_STAINED_GLASS && inventory.getItem(7).getType() == Material.BLACK_STAINED_GLASS && inventory.getItem(6).getType() == Material.BLACK_STAINED_GLASS) {
283287
event.setCancelled(true); // Cancel the drag event
284288
}
285289
}

src/main/java/me/pranavverma/advancedtech/general/items/solargen/AdvancedSolarGen/lib/AdvancedSolarGenLib.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import javax.annotation.ParametersAreNonnullByDefault;
55

66
import org.bukkit.Location;
7+
import org.bukkit.Material;
78
import org.bukkit.World;
89
import org.bukkit.World.Environment;
910
import org.bukkit.block.Block;
@@ -34,7 +35,8 @@ public class AdvancedSolarGenLib extends SlimefunItem implements EnergyNetProvid
3435
private final int dayEnergy;
3536
private final int nightEnergy;
3637
private final int capacity;
37-
private boolean testing;
38+
39+
private boolean commandHubFound;
3840

3941

4042
@ParametersAreNonnullByDefault
@@ -43,6 +45,7 @@ public AdvancedSolarGenLib(ItemGroup itemGroup, int dayEnergy, int nightEnergy,
4345
this.dayEnergy = dayEnergy;
4446
this.nightEnergy = nightEnergy;
4547
this.capacity = capacity;
48+
4649
addItemSetting(useNightEnergyInOtherDimensions);
4750
addItemHandler(onPlace());
4851
addItemHandler(new BlockTicker() {
@@ -54,10 +57,10 @@ public boolean isSynchronized() {
5457
@Override
5558
public void tick(Block block, SlimefunItem slimefunItem, Config config) {
5659
if (scanForCommandHub(block)) {
57-
testing = true;
60+
commandHubFound = true;
5861

5962
} else {
60-
testing = false;
63+
commandHubFound = false;
6164
}
6265
}
6366
});
@@ -71,33 +74,27 @@ public AdvancedSolarGenLib(ItemGroup itemGroup, int dayEnergy, int nightEnergy,
7174
}
7275

7376
public int getDayEnergy() {
74-
if (command_hub.AdvancedSolarGenFound && command_hub.readyToUse && testing) {
77+
if (commandHubFound) {
7578
return dayEnergy;
76-
} else if (command_hub.onCommandHubRemoval) {
77-
return 0;
78-
} else {
79+
} else {
7980
return 0;
8081
}
8182

8283
}
8384

8485
public int getNightEnergy() {
85-
if (command_hub.AdvancedSolarGenFound && command_hub.readyToUse && testing) {
86+
if (commandHubFound) {
8687
return nightEnergy;
87-
} else if (command_hub.onCommandHubRemoval) {
88-
return 0;
89-
} else {
88+
} else {
9089
return 0;
9190
}
9291
}
9392

9493
@Override
9594
public int getCapacity() {
96-
if (command_hub.AdvancedSolarGenFound && command_hub.readyToUse && testing) {
95+
if (commandHubFound) {
9796
return capacity;
98-
} else if (command_hub.onCommandHubRemoval) {
99-
return 0;
100-
} else {
97+
} else {
10198
return 0;
10299
}
103100
}
@@ -162,9 +159,9 @@ private BlockPlaceHandler onPlace() {
162159
@Override
163160
public void onPlayerPlace(@Nonnull BlockPlaceEvent e) {
164161
if (scanForCommandHub(e.getBlock())) {
165-
testing = true;
162+
commandHubFound = true;
166163
} else {
167-
testing = false;
164+
commandHubFound = false;
168165
}
169166
}
170167

src/main/java/me/pranavverma/advancedtech/general/items/solargen/ExtremeSolarGen/EMPTY

Whitespace-only changes.

0 commit comments

Comments
 (0)