Skip to content

Commit

Permalink
update to v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
iXanadu13 committed Aug 10, 2023
1 parent c4a06ad commit 446d5f6
Show file tree
Hide file tree
Showing 24 changed files with 1,972 additions and 1,537 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xanadu.slimefunrecipe;
package pers.xanadu.slimefunrecipe;

import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
Expand All @@ -8,21 +8,19 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import xanadu.slimefunrecipe.commands.MainCommand;
import xanadu.slimefunrecipe.commands.TabCompleter;
import xanadu.slimefunrecipe.config.Config;
import xanadu.slimefunrecipe.config.Lang;
import xanadu.slimefunrecipe.metrics.Metrics;
import pers.xanadu.slimefunrecipe.commands.MainCommand;
import pers.xanadu.slimefunrecipe.commands.TabCompleter;
import pers.xanadu.slimefunrecipe.config.Config;
import pers.xanadu.slimefunrecipe.config.Lang;
import pers.xanadu.slimefunrecipe.metrics.Metrics;

import java.io.File;
import java.util.*;

import static xanadu.slimefunrecipe.config.Config.enable;
import static xanadu.slimefunrecipe.config.Lang.error;
import static xanadu.slimefunrecipe.config.Lang.info;
import static xanadu.slimefunrecipe.manager.ItemManager.*;
import static xanadu.slimefunrecipe.utils.VersionUpdater.checkUpdate;
import static pers.xanadu.slimefunrecipe.config.Config.enable;
import static pers.xanadu.slimefunrecipe.config.Lang.*;
import static pers.xanadu.slimefunrecipe.manager.ItemManager.*;
import static pers.xanadu.slimefunrecipe.utils.VersionUpdater.checkUpdate;

public final class Main extends JavaPlugin {
private static Main instance;
Expand All @@ -41,6 +39,12 @@ public void onEnable() {
new Metrics(this,18362);
reloadAll();
checkUpdate();
if(!"1.1.0".equals(Lang.version)){
warn(Lang.plugin_wrong_file_version.replace("{file_name}",Config.lang + ".yml"));
}
if(!"1.0.0".equals(Config.version)){
warn(Lang.plugin_wrong_file_version.replace("{file_name}","config.yml"));
}
}
public static void reloadAll(){
getInstance().loadFiles();
Expand All @@ -52,42 +56,39 @@ private void registerCommands(){
}
private void loadRecipes(){
initRecipeType();
new BukkitRunnable(){
@Override
public void run(){
int cnt=0;
for (String key : data.getKeys(false)) {
ConfigurationSection section = (ConfigurationSection) data.get(key);
if(section == null){
error(Lang.plugin_data_parsing_error+key);
return;
}
RecipeType type = getByName(section.getString("RecipeType"));
if(type == null) {
error(Lang.item_unknown_recipe_type.replace("%item%",key));
continue;
}
SlimefunItem si = SlimefunItem.getById(key);
if(si == null){
error(Lang.item_not_slimefun.replaceAll("%item%",key));
continue;
}
ConfigurationSection section1 = section.getConfigurationSection("data");
if(section1 == null){
error(Lang.plugin_data_parsing_error+key);
return;
}
ItemStack[] recipe = new ItemStack[9];
for(int i=0;i<9;i++){
recipe[i] = readAsItem(section1, String.valueOf(i+1));
}
si.setRecipeType(type);
si.setRecipe(recipe);
cnt++;
}
info(Lang.plugin_recipes_loaded.replace("%d",String.valueOf(cnt)));

int cnt=0;
for (String key : data.getKeys(false)) {
ConfigurationSection section = (ConfigurationSection) data.get(key);
if(section == null){
error(Lang.plugin_data_parsing_error+key);
return;
}
RecipeType type = getByName(section.getString("RecipeType"));
if(type == null) {
error(Lang.item_unknown_recipe_type.replace("%item%",key));
continue;
}
}.runTaskAsynchronously(this);
SlimefunItem si = SlimefunItem.getById(key);
if(si == null){
error(Lang.item_not_slimefun.replaceAll("%item%",key));
continue;
}
ConfigurationSection section1 = section.getConfigurationSection("data");
if(section1 == null){
error(Lang.plugin_data_parsing_error+key);
return;
}
int size = section.getInt("size",9);
ItemStack[] recipe = new ItemStack[size];
for(int i=0;i<size;i++){
recipe[i] = readAsItem(section1, String.valueOf(i+1));
}
si.setRecipeType(type);
setRecipe(si,recipe);
cnt++;
}
info(Lang.plugin_recipes_loaded.replace("%d",String.valueOf(cnt)));
}
private void loadFiles(){
saveDefaultConfig();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,63 @@
package xanadu.slimefunrecipe;

import java.util.Map;
import java.util.TreeMap;

public enum SlimeRecipeType {
ancient_altar,
armor_forge,
barter_drop,
compressor,
enhanced_crafting_table,
food_composter,
food_fabricator,
freezer,
geo_miner,
gold_pan,
grind_stone,
heated_pressure_chamber,
interact,
juicer,
magic_workbench,
mob_drop,
multiblock,
nuclear_reactor,
NULL,
ore_crusher,
ore_washer,
pressure_chamber,
refinery,
smeltery,
_unknown;
public static final Map<String, SlimeRecipeType> mp = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
public static SlimeRecipeType getByName(String str){
if(str == null) return _unknown;
str=str.toLowerCase();
if("null".equals(str)) return NULL;
return mp.getOrDefault(str,_unknown);
}
static{
SlimeRecipeType[] values = values();
for (SlimeRecipeType recipeType : values) {
String name = recipeType.name();
mp.put(name, recipeType);
}
}
}
package pers.xanadu.slimefunrecipe;

import java.util.Map;
import java.util.TreeMap;

public enum SlimeRecipeType {
ancient_altar,
armor_forge,
barter_drop,
compressor,
enhanced_crafting_table,
food_composter,
food_fabricator,
freezer,
geo_miner,
gold_pan,
grind_stone,
heated_pressure_chamber,
interact,
juicer,
magic_workbench,
mob_drop,
multiblock,
nuclear_reactor,
NULL,
ore_crusher,
ore_washer,
pressure_chamber,
refinery,
smeltery,
//ExoticGarden starts
kitchen,
breaking_grass,
harvest_tree,
harvest_bush,
//InfinityExpansion starts
infinity_forge,
mob_data_infuser,
storage_forge,
//TranscEndence starts
//useless: quirp_oscillator,
quirp_annihilator,
stabilizer,
nanobot_crafter,
zot_overloader,
//FlowerPower starts
magic_basin,
_unknown;
public static final Map<String, SlimeRecipeType> mp = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
public static SlimeRecipeType getByName(String str){
if(str == null) return _unknown;
str=str.toLowerCase();
if("null".equals(str)) return NULL;
return mp.getOrDefault(str,_unknown);
}
static{
SlimeRecipeType[] values = values();
for (SlimeRecipeType recipeType : values) {
String name = recipeType.name();
mp.put(name, recipeType);
}
}
}
85 changes: 85 additions & 0 deletions src/main/java/pers/xanadu/slimefunrecipe/commands/MainCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package pers.xanadu.slimefunrecipe.commands;

import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import pers.xanadu.slimefunrecipe.config.Lang;
import pers.xanadu.slimefunrecipe.gui.GUISize;

import static pers.xanadu.slimefunrecipe.Main.langF;
import static pers.xanadu.slimefunrecipe.Main.reloadAll;
import static pers.xanadu.slimefunrecipe.config.Config.enable;
import static pers.xanadu.slimefunrecipe.config.Lang.*;
import static pers.xanadu.slimefunrecipe.manager.GuiManager.openSizedSlimeInv;
import static pers.xanadu.slimefunrecipe.manager.GuiManager.openSlimeInv;
import static pers.xanadu.slimefunrecipe.manager.ItemManager.isEmpty;

public class MainCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String name, String[] args) {
if(args.length == 0){
sendCommandTips(sender);
return false;
}
if(!sender.hasPermission("slimefunrecipe.admin")){
sendFeedback(sender, command_no_permission);
return false;
}
switch (args[0].toLowerCase()){
case "reload" : {
if(args.length != 1){
sendCommandTips(sender);
return false;
}
reloadAll();
sendFeedback(sender,Lang.command_reload_config);
return true;
}
case "edit" : {
if(!enable){
sendFeedback(sender,plugin_fun_not_enable);
return false;
}
if (!(sender instanceof Player)) {
sendFeedback(sender, Lang.command_only_player);
return false;
}
Player p = (Player) sender;
ItemStack item = p.getItemInHand();
if(isEmpty(item)){
sendFeedback(sender, command_item_error);
return false;
}
SlimefunItem si = SlimefunItem.getByItem(item);
if(si==null) {
sendFeedback(sender, command_item_error);
return false;
}
if(args.length == 1){
openSlimeInv(p, si);
return true;
}
else if(args.length == 2){
openSizedSlimeInv(p,si, GUISize.of(args[1]));
return true;
}
else{
sendCommandTips(sender);
return false;
}
}
default : {
sendCommandTips(sender);
return false;
}
}
}
private static void sendCommandTips(CommandSender sender){
for(String str : CommandTips){
sender.sendMessage(str);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
package xanadu.slimefunrecipe.commands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class TabCompleter implements org.bukkit.command.TabCompleter {
private static final List<String> arguments_1 = Arrays.asList("reload","edit");
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {

List<String> result = new ArrayList<>();
if (args.length == 1) {
for (String s : arguments_1) {
if (s.toLowerCase().startsWith(args[0].toLowerCase())) {
result.add(s);
}
}
return result;
}
return null;
}
}
package pers.xanadu.slimefunrecipe.commands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class TabCompleter implements org.bukkit.command.TabCompleter {
private static final List<String> arguments_1 = Arrays.asList("reload","edit");
private static final List<String> arguments_2 = Arrays.asList("1x4","3x3","6x6");
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
List<String> result = new ArrayList<>();
if (args.length == 1) {
for (String s : arguments_1) {
if (s.toLowerCase().startsWith(args[0].toLowerCase())) {
result.add(s);
}
}
return result;
}
else if(args.length==2){
if (args[0].equalsIgnoreCase("edit")) {
for(String s : arguments_2){
if(s.toLowerCase().startsWith(args[1].toLowerCase())){
result.add(s);
}
}
}
return result;
}
return null;
}
}
Loading

0 comments on commit 446d5f6

Please sign in to comment.