mirror of
https://github.com/SimplexDevelopment/ToolAssist.git
synced 2025-07-04 11:26:41 +00:00
Initial commit
This commit is contained in:
26
src/main/java/io/github/simplex/toolassist/ToolAssist.java
Normal file
26
src/main/java/io/github/simplex/toolassist/ToolAssist.java
Normal file
@ -0,0 +1,26 @@
|
||||
package io.github.simplex.toolassist;
|
||||
|
||||
import io.github.simplex.toolassist.data.Config;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class ToolAssist extends JavaPlugin {
|
||||
|
||||
private Config config;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
this.config = new Config(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Config getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package io.github.simplex.toolassist.data;
|
||||
|
||||
import io.github.simplex.toolassist.ToolAssist;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class BlockIdentifier {
|
||||
private final List<Block> blockList = new ArrayList<>();
|
||||
private final List<Location> blockLocations = new ArrayList<>();
|
||||
private final ToolAssist plugin;
|
||||
|
||||
public BlockIdentifier(ToolAssist plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public List<Block> populateAndRetrieve(Block block) {
|
||||
Location start = block.getLocation().clone();
|
||||
|
||||
|
||||
return blockList;
|
||||
}
|
||||
|
||||
public boolean checkBlock(Block block, ItemStack targetItem) {
|
||||
AtomicBoolean isValid = new AtomicBoolean(false);
|
||||
|
||||
if (plugin.getConfig().getSettings().useTags()) {
|
||||
TagBox.oreTagList().forEach(tag -> {
|
||||
if (tag.isTagged(block.getType())) isValid.set(true);
|
||||
});
|
||||
return isValid.get();
|
||||
}
|
||||
|
||||
Material m = block.getType();
|
||||
Material item = targetItem.getType();
|
||||
|
||||
// TODO: Tag or Material checks for the item, then the respective block type.
|
||||
|
||||
return isValid.get();
|
||||
}
|
||||
}
|
155
src/main/java/io/github/simplex/toolassist/data/Config.java
Normal file
155
src/main/java/io/github/simplex/toolassist/data/Config.java
Normal file
@ -0,0 +1,155 @@
|
||||
package io.github.simplex.toolassist.data;
|
||||
|
||||
import io.github.simplex.toolassist.ToolAssist;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
public class Config extends YamlConfiguration {
|
||||
|
||||
private final Settings settings;
|
||||
|
||||
public Config(ToolAssist plugin) {
|
||||
this.settings = new Settings(this);
|
||||
|
||||
String fileName = "config.yml";
|
||||
|
||||
File dataFolder = plugin.getDataFolder();
|
||||
|
||||
if (!dataFolder.exists()) dataFolder.mkdirs();
|
||||
|
||||
File cf = new File(dataFolder, fileName);
|
||||
|
||||
InputStream stream = plugin.getResource(fileName);
|
||||
assert stream != null;
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
|
||||
if (!cf.exists()) {
|
||||
cf.createNewFile();
|
||||
plugin.saveResource(fileName, true);
|
||||
}
|
||||
|
||||
oload(cf);
|
||||
|
||||
reader.lines().filter(s -> s.contains(":"))
|
||||
.map(s -> s.split(":")[0])
|
||||
.filter(s -> !super.getValues(true).containsKey(s))
|
||||
.forEach(s -> {
|
||||
plugin.getLogger().severe("Configuration is missing an entry, attempting to replace...");
|
||||
Optional<String> stringStream = reader.lines().filter(c -> c.contains(s)).findFirst();
|
||||
assert stringStream.isPresent();
|
||||
String key = stringStream.get().split(":")[0].trim();
|
||||
String value = stringStream.get().split(":")[1].trim();
|
||||
super.addDefault(key, value);
|
||||
osave(cf);
|
||||
});
|
||||
|
||||
|
||||
} catch (IOException ex) {
|
||||
plugin.getLogger().severe(ex.getMessage());
|
||||
}
|
||||
|
||||
oload(cf);
|
||||
}
|
||||
|
||||
public void osave(File cf) {
|
||||
try {
|
||||
super.save(cf);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void oload(File cf) {
|
||||
try {
|
||||
super.load(cf);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static class Settings {
|
||||
private final ConfigurationSection plugin_settings;
|
||||
private final ConfigurationSection tool_settings;
|
||||
|
||||
public Settings(Config config) {
|
||||
this.plugin_settings = config.getConfigurationSection("plugin_settings");
|
||||
this.tool_settings = config.getConfigurationSection("tool_settings");
|
||||
}
|
||||
|
||||
public final boolean useTags() {
|
||||
return plugin_settings.getBoolean("use_tags_no_config", false);
|
||||
}
|
||||
|
||||
public final boolean useSneak() {
|
||||
return plugin_settings.getBoolean("sneak_activation", true);
|
||||
}
|
||||
|
||||
public final int radius() {
|
||||
return plugin_settings.getInt("search_radius", 15);
|
||||
}
|
||||
|
||||
public final Set<Material> pickaxeMaterials() {
|
||||
Set<Material> materials = new HashSet<>();
|
||||
tool_settings.getStringList("pickaxe")
|
||||
.stream()
|
||||
.map(Material::matchMaterial)
|
||||
.forEach(materials::add);
|
||||
return materials;
|
||||
}
|
||||
|
||||
public final Set<Material> axeMaterials() {
|
||||
Set<Material> materials = new HashSet<>();
|
||||
tool_settings.getStringList("axe")
|
||||
.stream()
|
||||
.map(Material::matchMaterial)
|
||||
.forEach(materials::add);
|
||||
return materials;
|
||||
}
|
||||
|
||||
public final Set<Material> shovelMaterials() {
|
||||
Set<Material> materials = new HashSet<>();
|
||||
tool_settings.getStringList("shovel")
|
||||
.stream()
|
||||
.map(Material::matchMaterial)
|
||||
.forEach(materials::add);
|
||||
return materials;
|
||||
}
|
||||
|
||||
public final Set<Material> hoeMaterials() {
|
||||
Set<Material> materials = new HashSet<>();
|
||||
tool_settings.getStringList("hoe")
|
||||
.stream()
|
||||
.map(Material::matchMaterial)
|
||||
.forEach(materials::add);
|
||||
return materials;
|
||||
}
|
||||
|
||||
public final Set<Material> swordMaterials() {
|
||||
Set<Material> materials = new HashSet<>();
|
||||
tool_settings.getStringList("sword")
|
||||
.stream()
|
||||
.map(Material::matchMaterial)
|
||||
.forEach(materials::add);
|
||||
return materials;
|
||||
}
|
||||
|
||||
public final Set<Material> shearMaterials() {
|
||||
Set<Material> materials = new HashSet<>();
|
||||
tool_settings.getStringList("shears")
|
||||
.stream()
|
||||
.map(Material::matchMaterial)
|
||||
.forEach(materials::add);
|
||||
return materials;
|
||||
}
|
||||
}
|
||||
}
|
39
src/main/java/io/github/simplex/toolassist/data/TagBox.java
Normal file
39
src/main/java/io/github/simplex/toolassist/data/TagBox.java
Normal file
@ -0,0 +1,39 @@
|
||||
package io.github.simplex.toolassist.data;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TagBox {
|
||||
public static List<Tag<Material>> oreTagList() {
|
||||
return List.of(Tag.COAL_ORES,
|
||||
Tag.IRON_ORES,
|
||||
Tag.COPPER_ORES,
|
||||
Tag.GOLD_ORES,
|
||||
Tag.DIAMOND_ORES,
|
||||
Tag.REDSTONE_ORES,
|
||||
Tag.EMERALD_ORES,
|
||||
Tag.LAPIS_ORES);
|
||||
}
|
||||
|
||||
public static Tag<Material> leaves() {
|
||||
return Tag.LEAVES;
|
||||
}
|
||||
|
||||
public static Tag<Material> sandType() {
|
||||
return Tag.SAND;
|
||||
}
|
||||
|
||||
public static Tag<Material> wart() {
|
||||
return Tag.WART_BLOCKS;
|
||||
}
|
||||
|
||||
public static Tag<Material> logs() {
|
||||
return Tag.LOGS;
|
||||
}
|
||||
|
||||
public static Tag<Material> vines() {
|
||||
return Tag.CAVE_VINES;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user