mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2025-01-25 09:41:32 +01:00
Added New Settings
Added settings for running hoppers in unloaded chunks And animating all chests at once.
This commit is contained in:
parent
7b57a2da00
commit
7d3685ba6d
@ -9,6 +9,8 @@ public class Settings {
|
||||
private static String CHECK_UPDATE_PERIOD = "update-checker-period";
|
||||
private static String LIMIT_CHESTS = "limit-chestlinks";
|
||||
private static String LIMIT_CHESTS_NUMBER = "limit-chestlinks-amount";
|
||||
private static String SHOULD_ANIMATE_ALL_CHESTS = "should-animate-all-chests";
|
||||
private static String RUN_HOPPERS_UNLOADED_CHUNKS = "run-hoppers-unloaded-chunks";
|
||||
|
||||
private static Settings cf;
|
||||
private FileConfiguration configuration;
|
||||
@ -18,6 +20,8 @@ public class Settings {
|
||||
private static int updateCheckerPeriod;
|
||||
private static boolean limitChests;
|
||||
private static int limitChestsAmount;
|
||||
private static boolean shouldAnimateAllChests;
|
||||
private static boolean runHoppersInUnloadedChunks;
|
||||
|
||||
public static void initConfig(Plugin plugin){
|
||||
cf = new Settings();
|
||||
@ -29,6 +33,8 @@ public class Settings {
|
||||
cf.configuration.addDefault(CHECK_UPDATE_PERIOD,60*60);
|
||||
cf.configuration.addDefault(LIMIT_CHESTS,false);
|
||||
cf.configuration.addDefault(LIMIT_CHESTS_NUMBER,0);
|
||||
cf.configuration.addDefault(SHOULD_ANIMATE_ALL_CHESTS,false);
|
||||
cf.configuration.addDefault(RUN_HOPPERS_UNLOADED_CHUNKS,false);
|
||||
|
||||
cf.configuration.options().copyDefaults(true);
|
||||
cf.plugin.saveConfig();
|
||||
@ -47,6 +53,8 @@ public class Settings {
|
||||
updateCheckerPeriod = cf.configuration.getInt(CHECK_UPDATE_PERIOD);
|
||||
limitChests = cf.configuration.getBoolean(LIMIT_CHESTS);
|
||||
limitChestsAmount = cf.configuration.getInt(LIMIT_CHESTS_NUMBER);
|
||||
shouldAnimateAllChests = cf.configuration.getBoolean(SHOULD_ANIMATE_ALL_CHESTS);
|
||||
runHoppersInUnloadedChunks = cf.configuration.getBoolean(RUN_HOPPERS_UNLOADED_CHUNKS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,4 +66,10 @@ public class Settings {
|
||||
public static int getUpdateCheckerPeriodTicks() { return 20*updateCheckerPeriod;}
|
||||
public static boolean isLimitChests() { return limitChests; }
|
||||
public static int getLimitChestsAmount() { return limitChestsAmount; }
|
||||
public static boolean isShouldAnimateAllChests() {
|
||||
return shouldAnimateAllChests;
|
||||
}
|
||||
public static boolean isRunHoppersInUnloadedChunks() {
|
||||
return runHoppersInUnloadedChunks;
|
||||
}
|
||||
}
|
||||
|
@ -18,19 +18,30 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static void openChestInventory(Player player, ChestLinkStorage storage, Location location){
|
||||
storage.getLocations().forEach(locationInfo -> {
|
||||
if(locationInfo.getLocation() != null){
|
||||
Block block = locationInfo.getLocation().getBlock();
|
||||
if(block.getState() instanceof Chest){
|
||||
Chest chest = (Chest) block.getState();
|
||||
ApiSpecific.getChestOpener().setLidOpen(chest,true);
|
||||
public static void openChestInventory(Player player, ChestLinkStorage storage, Location openedChestLocation){
|
||||
//Check if all chests should perform open animation.
|
||||
if(Settings.isShouldAnimateAllChests()) {
|
||||
storage.getLocations().forEach(locationInfo -> {
|
||||
if (locationInfo.getLocation() != null) {
|
||||
chestOpenAnimation(locationInfo.getLocation());
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
chestOpenAnimation(openedChestLocation);
|
||||
}
|
||||
player.openInventory(storage.getInventory());
|
||||
}
|
||||
|
||||
private static void chestOpenAnimation(Location location){
|
||||
if (location != null) {
|
||||
Block block = location.getBlock();
|
||||
if (block.getState() instanceof Chest) {
|
||||
Chest chest = (Chest) block.getState();
|
||||
ApiSpecific.getChestOpener().setLidOpen(chest, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void openChestInventory(Player player, Inventory inventory){
|
||||
player.getWorld().playSound(player.getLocation(), Sound.BLOCK_CHEST_OPEN,0.5f,1f);
|
||||
player.openInventory(inventory);
|
||||
|
@ -2,6 +2,7 @@ package com.jamesdpeters.minecraft.chests.runnables;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
|
||||
import com.jamesdpeters.minecraft.chests.filters.HopperFilter;
|
||||
import com.jamesdpeters.minecraft.chests.misc.Settings;
|
||||
import com.jamesdpeters.minecraft.chests.misc.Utils;
|
||||
import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorage;
|
||||
import com.jamesdpeters.minecraft.chests.serialize.LocationInfo;
|
||||
@ -13,8 +14,8 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class VirtualChestToHopper extends BukkitRunnable {
|
||||
|
||||
ChestLinkStorage storage;
|
||||
BukkitTask task;
|
||||
private ChestLinkStorage storage;
|
||||
private BukkitTask task;
|
||||
|
||||
public VirtualChestToHopper(ChestLinkStorage storage){
|
||||
this.storage = storage;
|
||||
@ -33,7 +34,7 @@ public class VirtualChestToHopper extends BukkitRunnable {
|
||||
for(LocationInfo location : storage.getLocations()) {
|
||||
if(location != null) {
|
||||
if (location.getLocation() != null) {
|
||||
if(!location.getLocation().getChunk().isLoaded()) continue;
|
||||
if(!location.getLocation().getChunk().isLoaded() && !Settings.isRunHoppersInUnloadedChunks()) continue;
|
||||
Location below = location.getLocation().clone().subtract(0, 1, 0);
|
||||
if (below.getBlock().getState() instanceof Hopper) {
|
||||
Hopper hopper = (Hopper) below.getBlock().getState();
|
||||
|
Loading…
Reference in New Issue
Block a user