mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Finished Cargo Filter implementation
This commit is contained in:
parent
24806ab5d0
commit
e9ad3ee357
@ -1,5 +1,9 @@
|
|||||||
package io.github.thebusybiscuit.slimefun4.implementation.items.cargo;
|
package io.github.thebusybiscuit.slimefun4.implementation.items.cargo;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
@ -9,6 +13,7 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
|||||||
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
|
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
|
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterials;
|
import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterials;
|
||||||
@ -16,7 +21,6 @@ import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
|
|||||||
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
|
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
|
||||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
|
||||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||||
@ -29,28 +33,14 @@ import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
|
|||||||
* @author TheBusyBiscuit
|
* @author TheBusyBiscuit
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
abstract class AbstractCargoNode extends SlimefunItem {
|
abstract class AbstractCargoNode extends SimpleSlimefunItem<BlockPlaceHandler> {
|
||||||
|
|
||||||
protected static final String FREQUENCY = "frequency";
|
protected static final String FREQUENCY = "frequency";
|
||||||
|
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
public AbstractCargoNode(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
|
public AbstractCargoNode(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
|
||||||
super(category, item, recipeType, recipe, recipeOutput);
|
super(category, item, recipeType, recipe, recipeOutput);
|
||||||
|
|
||||||
addItemHandler(new BlockPlaceHandler(false) {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlayerPlace(BlockPlaceEvent e) {
|
|
||||||
Block b = e.getBlock();
|
|
||||||
|
|
||||||
// The owner and frequency are required by every node
|
|
||||||
BlockStorage.addBlockInfo(b, "owner", e.getPlayer().getUniqueId().toString());
|
|
||||||
BlockStorage.addBlockInfo(b, FREQUENCY, "0");
|
|
||||||
|
|
||||||
onPlace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
new BlockMenuPreset(getId(), ChatUtils.removeColorCodes(item.getItemMeta().getDisplayName())) {
|
new BlockMenuPreset(getId(), ChatUtils.removeColorCodes(item.getItemMeta().getDisplayName())) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -60,6 +50,7 @@ abstract class AbstractCargoNode extends SlimefunItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newInstance(BlockMenu menu, Block b) {
|
public void newInstance(BlockMenu menu, Block b) {
|
||||||
|
menu.addMenuCloseHandler(p -> markDirty(b.getLocation()));
|
||||||
updateBlockMenu(menu, b);
|
updateBlockMenu(menu, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +66,25 @@ abstract class AbstractCargoNode extends SlimefunItem {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockPlaceHandler getItemHandler() {
|
||||||
|
return new BlockPlaceHandler(false) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerPlace(BlockPlaceEvent e) {
|
||||||
|
Block b = e.getBlock();
|
||||||
|
|
||||||
|
// The owner and frequency are required by every node
|
||||||
|
BlockStorage.addBlockInfo(b, "owner", e.getPlayer().getUniqueId().toString());
|
||||||
|
BlockStorage.addBlockInfo(b, FREQUENCY, "0");
|
||||||
|
|
||||||
|
onPlace(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
protected void addChannelSelector(Block b, BlockMenu menu, int slotPrev, int slotCurrent, int slotNext) {
|
protected void addChannelSelector(Block b, BlockMenu menu, int slotPrev, int slotCurrent, int slotNext) {
|
||||||
boolean isChestTerminalInstalled = SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled();
|
boolean isChestTerminalInstalled = SlimefunPlugin.getThirdPartySupportService().isChestTerminalInstalled();
|
||||||
int channel = getSelectedChannel(b);
|
int channel = getSelectedChannel(b);
|
||||||
@ -122,7 +132,7 @@ abstract class AbstractCargoNode extends SlimefunItem {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getSelectedChannel(Block b) {
|
private int getSelectedChannel(@Nonnull Block b) {
|
||||||
if (!BlockStorage.hasBlockInfo(b)) {
|
if (!BlockStorage.hasBlockInfo(b)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
@ -137,10 +147,12 @@ abstract class AbstractCargoNode extends SlimefunItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void onPlace(BlockPlaceEvent e);
|
protected abstract void onPlace(@Nonnull BlockPlaceEvent e);
|
||||||
|
|
||||||
protected abstract void createBorder(BlockMenuPreset preset);
|
protected abstract void createBorder(@Nonnull BlockMenuPreset preset);
|
||||||
|
|
||||||
protected abstract void updateBlockMenu(BlockMenu menu, Block b);
|
protected abstract void updateBlockMenu(@Nonnull BlockMenu menu, @Nonnull Block b);
|
||||||
|
|
||||||
|
protected abstract void markDirty(@Nonnull Location loc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package io.github.thebusybiscuit.slimefun4.implementation.items.cargo;
|
package io.github.thebusybiscuit.slimefun4.implementation.items.cargo;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.core.networks.cargo.CargoNet;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||||
@ -65,7 +69,8 @@ abstract class AbstractFilterNode extends AbstractCargoNode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateBlockMenu(BlockMenu menu, Block b) {
|
protected void updateBlockMenu(BlockMenu menu, Block b) {
|
||||||
String filterType = BlockStorage.getLocationInfo(b.getLocation(), FILTER_TYPE);
|
Location loc = b.getLocation();
|
||||||
|
String filterType = BlockStorage.getLocationInfo(loc, FILTER_TYPE);
|
||||||
|
|
||||||
if (!BlockStorage.hasBlockInfo(b) || filterType == null || filterType.equals("whitelist")) {
|
if (!BlockStorage.hasBlockInfo(b) || filterType == null || filterType.equals("whitelist")) {
|
||||||
menu.replaceExistingItem(15, new CustomItem(Material.WHITE_WOOL, "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist"));
|
menu.replaceExistingItem(15, new CustomItem(Material.WHITE_WOOL, "&7Type: &rWhitelist", "", "&e> Click to change it to Blacklist"));
|
||||||
@ -102,6 +107,16 @@ abstract class AbstractFilterNode extends AbstractCargoNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addChannelSelector(b, menu, 41, 42, 43);
|
addChannelSelector(b, menu, 41, 42, 43);
|
||||||
|
markDirty(loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void markDirty(@Nonnull Location loc) {
|
||||||
|
CargoNet network = CargoNet.getNetworkFromLocation(loc);
|
||||||
|
|
||||||
|
if (network != null) {
|
||||||
|
network.markCargoNodeConfigurationDirty(loc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.thebusybiscuit.slimefun4.implementation.items.cargo;
|
package io.github.thebusybiscuit.slimefun4.implementation.items.cargo;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
@ -38,4 +39,9 @@ public class CargoOutputNode extends AbstractCargoNode {
|
|||||||
addChannelSelector(b, menu, 12, 13, 14);
|
addChannelSelector(b, menu, 12, 13, 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void markDirty(Location loc) {
|
||||||
|
// No need to mark anything as dirty, there is no item filter.
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user