Skip to content

Commit

Permalink
update to v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
iXanadu13 committed Aug 11, 2023
1 parent 446d5f6 commit 74d67bc
Show file tree
Hide file tree
Showing 20 changed files with 614 additions and 205 deletions.
47 changes: 4 additions & 43 deletions src/main/java/pers/xanadu/slimefunrecipe/Main.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package pers.xanadu.slimefunrecipe;

import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.Plugin;
import pers.xanadu.slimefunrecipe.commands.MainCommand;
Expand All @@ -19,7 +15,7 @@

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.manager.RecipeManager.loadRecipes;
import static pers.xanadu.slimefunrecipe.utils.VersionUpdater.checkUpdate;

public final class Main extends JavaPlugin {
Expand All @@ -39,57 +35,22 @@ public void onEnable() {
new Metrics(this,18362);
reloadAll();
checkUpdate();
if(!"1.1.0".equals(Lang.version)){
if(!"1.2.0".equals(Lang.version)){
warn(Lang.plugin_wrong_file_version.replace("{file_name}",Config.lang + ".yml"));
}
if(!"1.0.0".equals(Config.version)){
if(!"1.2.0".equals(Config.version)){
warn(Lang.plugin_wrong_file_version.replace("{file_name}","config.yml"));
}
}
public static void reloadAll(){
getInstance().loadFiles();
if(enable) getInstance().loadRecipes();
if(enable) loadRecipes();
}
private void registerCommands(){
Objects.requireNonNull(getCommand("slimefunrecipe")).setExecutor(new MainCommand());
Objects.requireNonNull(getCommand("slimefunrecipe")).setTabCompleter(new TabCompleter());
}
private void loadRecipes(){
initRecipeType();

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;
}
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();
reloadConfig();
Expand Down
83 changes: 72 additions & 11 deletions src/main/java/pers/xanadu/slimefunrecipe/commands/MainCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import org.bukkit.inventory.ItemStack;
import pers.xanadu.slimefunrecipe.config.Lang;
import pers.xanadu.slimefunrecipe.gui.GUISize;
import pers.xanadu.slimefunrecipe.manager.GuiManager;
import pers.xanadu.slimefunrecipe.manager.RecipeManager;

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.*;
Expand All @@ -24,12 +25,12 @@ public boolean onCommand(CommandSender sender, Command cmd, String name, String[
sendCommandTips(sender);
return false;
}
if(!sender.hasPermission("slimefunrecipe.admin")){
sendFeedback(sender, command_no_permission);
return false;
}
switch (args[0].toLowerCase()){
case "reload" : {
if(!sender.hasPermission("slimefunrecipe.admin")){
sendFeedback(sender, command_no_permission);
return false;
}
if(args.length != 1){
sendCommandTips(sender);
return false;
Expand All @@ -38,7 +39,48 @@ public boolean onCommand(CommandSender sender, Command cmd, String name, String[
sendFeedback(sender,Lang.command_reload_config);
return true;
}
//sfr add [size] [id] (file.yml)
case "add" : {
if(!sender.hasPermission("slimefunrecipe.admin")){
sendFeedback(sender, command_no_permission);
return false;
}
if (!(sender instanceof Player)) {
sendFeedback(sender, Lang.command_only_player);
return false;
}
Player p = (Player) sender;
if(args.length == 3){
GUISize size = GUISize.of(args[1]);
String id = args[2];
String file_name = id+".yml";
String key = file_name+"$"+id;
if(RecipeManager.isKeyConflict(key)){
sendFeedback(p, command_key_conflict);
return false;
}
else GuiManager.openRecipeAddInv(p,size,key);
return true;
}
else if(args.length == 4){
GUISize size = GUISize.of(args[1]);
String id = args[2];
String file_name = args[3];
String key = file_name+"$"+id;
if(RecipeManager.isKeyConflict(key)){
sendFeedback(p, command_key_conflict);
return false;
}
else GuiManager.openRecipeAddInv(p,size,key);
return true;
}
break;
}
case "edit" : {
if(!sender.hasPermission("slimefunrecipe.admin")){
sendFeedback(sender, command_no_permission);
return false;
}
if(!enable){
sendFeedback(sender,plugin_fun_not_enable);
return false;
Expand Down Expand Up @@ -66,16 +108,35 @@ else if(args.length == 2){
openSizedSlimeInv(p,si, GUISize.of(args[1]));
return true;
}
else{
sendCommandTips(sender);
break;
}
case "view" : {
if(!sender.hasPermission("slimefunrecipe.view")){
sendFeedback(sender, command_no_permission);
return false;
}
}
default : {
sendCommandTips(sender);
return false;
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;
if(args.length == 2){
GuiManager.viewRecipe(p,args[1]);
return true;
}
else if(args.length == 3){
GuiManager.viewRecipe(p,args[1]+"$"+args[2]);
return true;
}
break;
}
}
sendCommandTips(sender);
return false;
}
private static void sendCommandTips(CommandSender sender){
for(String str : CommandTips){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import pers.xanadu.slimefunrecipe.config.Config;

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

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_1 = Arrays.asList("reload","add","edit","view");
private static final List<String> arguments_2 = Arrays.asList("1x4","3x3","6x6");
public static final List<String> recipe_add_files = new ArrayList<>();
public static final Map<String,List<String>> recipe_mp = new HashMap<>();
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
List<String> result = new ArrayList<>();
Expand All @@ -22,13 +23,48 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
return result;
}
else if(args.length==2){
if (args[0].equalsIgnoreCase("edit")) {
if (args[0].equals("add") || args[0].equals("edit")) {
for(String s : arguments_2){
if(s.toLowerCase().startsWith(args[1].toLowerCase())){
result.add(s);
}
}
}
else if(Config.recipe_view_tab && args[0].equals("view")){
for(String s : recipe_add_files){
if(s.toLowerCase().startsWith(args[1].toLowerCase())){
result.add(s);
}
}
}
return result;
}
else if(args.length==3){
if(args[0].equals("add")){
if("id".startsWith(args[2].toLowerCase())){
result.add("id");
}
}
else if(Config.recipe_view_tab && args[0].equals("view")){
List<String> list = recipe_mp.get(args[1]);
if(list!=null){
for(String s : list){
if(s.toLowerCase().startsWith(args[2].toLowerCase())){
result.add(s);
}
}
}
}
return result;
}
else if(args.length==4){
if(args[0].equals("add")){
for(String s : recipe_add_files){
if(s.toLowerCase().startsWith(args[3].toLowerCase())){
result.add(s);
}
}
}
return result;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Config {
public static String version;
public static String lang;
public static boolean enable;
public static boolean recipe_view_tab;

public static void reload(FileConfiguration file){
Field[] fields = Config.class.getFields();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/pers/xanadu/slimefunrecipe/config/Lang.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ public class Lang {
public static String plugin_out_of_date;
public static String plugin_up_to_date;
public static String plugin_wrong_file_version;
public static String plugin_read_file;
public static String command_no_permission;
public static String command_reload_config;
public static String command_only_player;
public static String command_item_error;
public static String command_unknown_item_size;
public static String command_recipe_type_absence;
public static String command_key_conflict;
public static String command_recipe_not_found;
public static String gui_title;
public static String gui_title_view;
public static String gui_button_verify;
public static String gui_button_cancel;
public static String gui_recipe_cancel;
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/pers/xanadu/slimefunrecipe/gui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ public abstract class GUI extends ChestMenu {
protected int index;
protected int chosen;
protected int capacity;
protected GUI(String title) {
protected GUIType type;
protected String input;
protected GUI(String title,GUIType type){
super(title);
index=1;
chosen=-1;
capacity=0;
this.type = type;
input = title;
initVector();
}
protected GUI(String title) {
this(title,GUIType.edit);
}
public void initVector(){
items.clear();
for(RecipeType recipeType : ItemManager.recipeTypes){
Expand All @@ -39,6 +46,12 @@ public int getPage(){
public int getCapacity(){
return capacity;
}
public GUIType getType(){
return type;
}
public String getTitle(){
return input;
}
public void setPage(final Player p, int to){
if(to<1||to>getSize()) return;
index=to;
Expand Down Expand Up @@ -80,4 +93,7 @@ protected void updateButton(final Player p, int page){
public abstract int getItemShowIndex();
public abstract int getPrevPageButtonIndex();
public abstract int getNextPageButtonIndex();
public abstract int[] getBlack_border();
public abstract int[] getGray_border();
public abstract int[] getItemSlots();
}
13 changes: 13 additions & 0 deletions src/main/java/pers/xanadu/slimefunrecipe/gui/GUI1x4.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import pers.xanadu.slimefunrecipe.utils.GuiUtils;

public class GUI1x4 extends GUI{
public GUI1x4(String title,GUIType type) {
super(title,type);
capacity = 4;
}
public GUI1x4(String title) {
super(title);
capacity = 4;
Expand Down Expand Up @@ -55,4 +59,13 @@ public int getPrevPageButtonIndex(){
public int getNextPageButtonIndex(){
return 34;
}
public int[] getBlack_border(){
return GuiUtils.black_border_1x4;
}
public int[] getGray_border(){
return GuiUtils.gray_border_3x3;
}
public int[] getItemSlots(){
return GuiUtils.item_slot_1x4;
}
}
13 changes: 13 additions & 0 deletions src/main/java/pers/xanadu/slimefunrecipe/gui/GUI3x3.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import pers.xanadu.slimefunrecipe.utils.GuiUtils;

public class GUI3x3 extends GUI{
public GUI3x3(String title,GUIType type) {
super(title,type);
capacity = 9;
}
public GUI3x3(String title) {
super(title);
capacity = 9;
Expand Down Expand Up @@ -55,4 +59,13 @@ public int getPrevPageButtonIndex(){
public int getNextPageButtonIndex(){
return 34;
}
public int[] getBlack_border(){
return GuiUtils.black_border_3x3;
}
public int[] getGray_border(){
return GuiUtils.gray_border_3x3;
}
public int[] getItemSlots(){
return GuiUtils.item_slot_3x3;
}
}
Loading

0 comments on commit 74d67bc

Please sign in to comment.