Skip to content

Commit

Permalink
[1.8.7]新增删除自定义燃料的命令
Browse files Browse the repository at this point in the history
  • Loading branch information
YufiriaMazenta committed Jan 6, 2024
1 parent 49ef619 commit 1dd6517
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 44 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.text.SimpleDateFormat
version = "1.8.6"
version = "1.8.7"

plugins {
`java-library`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.yufiriamazenta.craftorithm.cmd.sub.item;

import com.github.yufiriamazenta.craftorithm.cmd.sub.AbstractSubCommand;
import com.github.yufiriamazenta.craftorithm.cmd.sub.item.fuel.FuelCommand;
import org.bukkit.command.CommandSender;

import java.util.List;
Expand All @@ -11,7 +12,7 @@ public final class ItemCommand extends AbstractSubCommand {

private ItemCommand() {
super("item", "craftorithm.command.item");
regSub(SaveItemCommand.INSTANCE).regSub(GiveItemCommand.INSTANCE).regSub(AddFuelCommand.INSTANCE);
regSub(SaveItemCommand.INSTANCE).regSub(GiveItemCommand.INSTANCE).regSub(FuelCommand.INSTANCE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.yufiriamazenta.craftorithm.cmd.sub.item;
package com.github.yufiriamazenta.craftorithm.cmd.sub.item.fuel;

import com.github.yufiriamazenta.craftorithm.cmd.sub.AbstractSubCommand;
import com.github.yufiriamazenta.craftorithm.config.Languages;
Expand All @@ -19,7 +19,7 @@ public class AddFuelCommand extends AbstractSubCommand {
public static final AddFuelCommand INSTANCE = new AddFuelCommand();

protected AddFuelCommand() {
super("add-fuel", "craftorithm.command.item.add-fuel");
super("add", "craftorithm.command.item.fuel.add");
}

@Override
Expand All @@ -33,15 +33,15 @@ public boolean onCommand(CommandSender sender, List<String> args) {

ItemStack item = ((Player) sender).getInventory().getItemInMainHand();
if (ItemUtil.isAir(item)) {
LangUtil.sendLang(sender, Languages.COMMAND_ITEM_ADD_FUEL_FAILED_ADD_AIR);
LangUtil.sendLang(sender, Languages.COMMAND_ITEM_FUEL_ADD_FAILED_ADD_AIR);
return true;
}

boolean result = ItemManager.INSTANCE.addCustomFuel(item, Integer.parseInt(args.get(0)));
if (result) {
LangUtil.sendLang(sender, Languages.COMMAND_ITEM_ADD_FUEL_SUCCESS);
LangUtil.sendLang(sender, Languages.COMMAND_ITEM_FUEL_ADD_SUCCESS);
} else {
LangUtil.sendLang(sender, Languages.COMMAND_ITEM_ADD_FUEL_FAILED_EXIST);
LangUtil.sendLang(sender, Languages.COMMAND_ITEM_FUEL_ADD_FAILED_EXIST);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.yufiriamazenta.craftorithm.cmd.sub.item.fuel;

import com.github.yufiriamazenta.craftorithm.cmd.sub.AbstractSubCommand;
public class FuelCommand extends AbstractSubCommand {

public static final FuelCommand INSTANCE = new FuelCommand();

protected FuelCommand() {
super("fuel", "craftorithm.command.item.fuel");
regSub(AddFuelCommand.INSTANCE).regSub(RemoveFuelCommand.INSTANCE);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.github.yufiriamazenta.craftorithm.cmd.sub.item.fuel;

import com.github.yufiriamazenta.craftorithm.cmd.sub.AbstractSubCommand;
import com.github.yufiriamazenta.craftorithm.config.Languages;
import com.github.yufiriamazenta.craftorithm.item.ItemManager;
import com.github.yufiriamazenta.craftorithm.util.LangUtil;
import org.bukkit.command.CommandSender;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class RemoveFuelCommand extends AbstractSubCommand {

public static final RemoveFuelCommand INSTANCE = new RemoveFuelCommand();

protected RemoveFuelCommand() {
super("remove", "craftorithm.command.item.fuel.remove");
}

@Override
public boolean onCommand(CommandSender sender, List<String> args) {
if (args.isEmpty()) {
sendNotEnoughCmdParamMsg(sender, 1);
return true;
}
if (!checkSenderIsPlayer(sender))
return true;

boolean result = ItemManager.INSTANCE.removeCustomFuel(args.get(0));
if (result) {
LangUtil.sendLang(sender, Languages.COMMAND_ITEM_FUEL_REMOVE_SUCCESS);
} else {
LangUtil.sendLang(sender, Languages.COMMAND_ITEM_FUEL_REMOVE_FAILED_NOT_EXIST);
}
return true;
}

@Override
public List<String> onTabComplete(CommandSender sender, List<String> args) {
if (args.size() <= 1) {
List<String> tabs = new ArrayList<>(ItemManager.INSTANCE.customCookingFuelMap().keySet());
filterTabList(tabs, args.get(0));
return tabs;
}
return Collections.singletonList("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ public class Languages {
public static final StringLangConfigEntry COMMAND_ITEM_GIVE_SUCCESS = new StringLangConfigEntry("command.item.give.success");
public static final StringLangConfigEntry COMMAND_ITEM_GIVE_NOT_EXIST_ITEM = new StringLangConfigEntry("command.item.give.not_exist_item");
public static final StringLangConfigEntry COMMAND_ITEM_GIVE_PLAYER_OFFLINE = new StringLangConfigEntry("command.item.give.player_offline");
public static final StringLangConfigEntry COMMAND_ITEM_ADD_FUEL_SUCCESS = new StringLangConfigEntry("command.item.add_fuel.success");
public static final StringLangConfigEntry COMMAND_ITEM_ADD_FUEL_FAILED_ADD_AIR = new StringLangConfigEntry("command.item.add_fuel.failed_add_air");
public static final StringLangConfigEntry COMMAND_ITEM_ADD_FUEL_FAILED_EXIST = new StringLangConfigEntry("command.item.add_fuel.failed_exist");
public static final StringLangConfigEntry COMMAND_ITEM_FUEL_ADD_SUCCESS = new StringLangConfigEntry("command.item.fuel.add.success");
public static final StringLangConfigEntry COMMAND_ITEM_FUEL_ADD_FAILED_ADD_AIR = new StringLangConfigEntry("command.item.fuel.add.failed_add_air");
public static final StringLangConfigEntry COMMAND_ITEM_FUEL_ADD_FAILED_EXIST = new StringLangConfigEntry("command.item.fuel.add.failed_exist");
public static final StringLangConfigEntry COMMAND_ITEM_FUEL_REMOVE_SUCCESS = new StringLangConfigEntry("command.item.fuel.remove.success");
public static final StringLangConfigEntry COMMAND_ITEM_FUEL_REMOVE_FAILED_NOT_EXIST = new StringLangConfigEntry("command.item.fuel.remove.failed_not_exist");
public static final StringLangConfigEntry COMMAND_RELOAD_SUCCESS = new StringLangConfigEntry("command.reload.success");
public static final StringLangConfigEntry COMMAND_RELOAD_EXCEPTION = new StringLangConfigEntry("command.reload.exception");
public static final StringLangConfigEntry COMMAND_REMOVE_SUCCESS = new StringLangConfigEntry("command.remove.success");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,29 @@ public Integer matchCustomFuelBurnTime(ItemStack item) {

public boolean addCustomFuel(ItemStack item, int burnTime) {
String itemName = ItemUtils.matchItemNameOrCreate(item, true);
if (itemName == null)
throw new IllegalArgumentException("Cannot add null item as a fuel");
if (customCookingFuelMap.containsKey(itemName))
return false;
if (itemName == null)
throw new IllegalArgumentException("Cannot add this item as a fuel");
customCookingFuelMap.put(itemName, burnTime);
customFuelConfig.config().set(itemName + "." + BURN_TIME_KEY, burnTime);
customFuelConfig.saveConfig();
customFuelConfig.reloadConfig();
return true;
}

public boolean removeCustomFuel(@NotNull String fuelName) {
if (!customCookingFuelMap.containsKey(fuelName))
return false;
customCookingFuelMap.remove(fuelName);
customFuelConfig.config().set(fuelName, null);
customFuelConfig.saveConfig();
customFuelConfig.reloadConfig();
return true;
}

public Map<String, Integer> customCookingFuelMap() {
return customCookingFuelMap;
}

}
12 changes: 8 additions & 4 deletions src/main/resources/lang/de_de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ command:
success: '<prefix> &aGegenstand erfolgreich erhalten.'
not_exist_item: '<prefix> &cGegenstand <item_name> existiert nicht.'
player_offline: '<prefix> &cDer Spieler ist nicht online oder existiert nicht.'
add_fuel:
success: '<prefix> &aBenutzerdefinierten Kraftstoff erfolgreich hinzufügen'
failed_add_air: '<prefix> &cDas Hinzufügen des benutzerdefinierten Kraftstoffs ist fehlgeschlagen. Grund: Ein nicht vorhandener Artikel kann nicht als Treibstoff hinzugefügt werden.'
failed_exist: '<prefix> &cDas Hinzufügen des benutzerdefinierten Kraftstoffs ist fehlgeschlagen. Grund: Dieser Kraftstoff existiert bereits.'
fuel:
add:
success: '<prefix> &aBenutzerdefinierten Kraftstoff erfolgreich hinzufügen.'
failed_add_air: '<prefix> &cDas Hinzufügen des benutzerdefinierten Kraftstoffs ist fehlgeschlagen. Grund: Ein nicht vorhandener Artikel kann nicht als Treibstoff hinzugefügt werden.'
failed_exist: '<prefix> &cDas Hinzufügen des benutzerdefinierten Kraftstoffs ist fehlgeschlagen. Grund: Dieser Kraftstoff existiert bereits.'
remove:
success: '<prefix> &aBenutzerdefinierten Kraftstoff erfolgreich entfernen.'
failed_not_exist: '<prefix> &cDas Entfernen des benutzerdefinierten Kraftstoffs ist fehlgeschlagen. Grund: Dieser Kraftstoff existiert nicht.'
reload:
success: '<prefix> &aDas Plugin wurde erfolgreich neu geladen.'
exception: '<prefix> &cBeim Neuladen des Plugins ist ein Fehler aufgetreten. Bitte überprüfen Sie die Konsole.'
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/lang/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ command:
success: '<prefix> &aGive item successfully'
not_exist_item: '<prefix> &cItem <item_name> does not exist.'
player_offline: '<prefix> &cThe player is not online or does not have a profile.'
add_fuel:
success: '<prefix> &aAdd custom fuel successfully'
failed_add_air: '<prefix> &cAdd custom fuel failed. Reason: Cannot add a non-existent item as fuel.'
failed_exist: '<prefix> &cAdd custom fuel failed. Reason: This fuel already exists.'
fuel:
add:
success: '<prefix> &aAdd custom fuel successfully.'
failed_add_air: '<prefix> &cAdd custom fuel failed. Reason: Cannot add a non-existent item as fuel.'
failed_exist: '<prefix> &cAdd custom fuel failed. Reason: This fuel already exists.'
remove:
success: '<prefix> &aRemove custom fuel successfully.'
failed_not_exist: '<prefix> &cRemove custom fuel failed. Reason: This fuel does not exist.'
reload:
success: '<prefix> &aPlugin reload!'
exception: '<prefix> &cError occurred during plugin reload, please check the console.'
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/lang/fr_fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ command:
success: '<prefix> &aRécupération de l''objet réussie'
not_exist_item: '<prefix> &cL''objet <item_name> n''existe pas.'
player_offline: '<prefix> &cLe joueur n''est pas en ligne ou n''existe pas.'
add_fuel:
success: '<prefix> &aAjouter du carburant personnalisé avec succès'
failed_add_air: '<prefix> &cL''ajout de carburant personnalisé a échoué. Raison : Impossible d''ajouter un élément inexistant comme carburant.'
failed_exist: '<prefix> &cL''ajout de carburant personnalisé a échoué. Raison : Ce carburant existe déjà.'
fuel:
add:
success: '<prefix> &aAjouter du carburant personnalisé avec succès.'
failed_add_air: '<prefix> &cL''ajout de carburant personnalisé a échoué. Raison : Impossible d''ajouter un élément inexistant comme carburant.'
failed_exist: '<prefix> &cL''ajout de carburant personnalisé a échoué. Raison : Ce carburant existe déjà.'
remove:
success: '<prefix> &aSupprimer le carburant personnalisé avec succès.'
failed_not_exist: '<prefix> &cLa suppression du carburant personnalisé a échoué. Raison : Ce carburant n’existe pas.'
reload:
success: '<prefix> &aRelance du plugin réussie!'
exception: '<prefix> &cUne erreur s''est produite lors du rechargement du plugin, veuillez consulter la console.'
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/lang/ja_jp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ command:
success: '<prefix> &aアイテムの取得に成功しました。'
not_exist_item: '<prefix> &c存在しないアイテム <item_name>'
player_offline: '<prefix> &cそのプレイヤーはオフラインであるか、存在しません。'
add_fuel:
success: '<prefix> &aカスタム燃料を正常に追加しました'
failed_add_air: '<prefix> &cカスタム燃料の追加に失敗しました。 理由: 存在しないアイテムを燃料として追加することはできません。'
failed_exist: '<prefix> &cカスタム燃料の追加に失敗しました。 理由: この燃料はすでに存在します。'
fuel:
add:
success: '<prefix> &aカスタム燃料を正常に追加しました.'
failed_add_air: '<prefix> &cカスタム燃料の追加に失敗しました。 理由: 存在しないアイテムを燃料として追加することはできません。'
failed_exist: '<prefix> &cカスタム燃料の追加に失敗しました。 理由: この燃料はすでに存在します。'
remove:
success: '<prefix> &aカスタム燃料を正常に削除しました。'
failed_not_exist: '<prefix> &cカスタム燃料の削除に失敗しました。 理由: この燃料は存在しません。'
reload:
success: '<prefix> &aプラグインのリロードが成功しました。'
exception: '<prefix> &cプラグインのリロード中にエラーが発生しました。コンソールを確認してください。'
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/lang/ru_ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ command:
success: '<prefix> &aПредмет успешно получен.'
not_exist_item: '<prefix> &cПредмет <item_name> не существует.'
player_offline: '<prefix> &cЭтот игрок офлайн или не существует.'
add_fuel:
success: '<prefix> &aДобавить собственное топливо успешно'
failed_add_air: '<prefix> &cНе удалось добавить собственное топливо. Причина: Невозможно добавить несуществующий предмет в качестве топлива.'
failed_exist: '<prefix> &cНе удалось добавить собственное топливо. Причина: Это топливо уже существует.'
fuel:
add:
success: '<prefix> &aДобавить собственное топливо успешно.'
failed_add_air: '<prefix> &cНе удалось добавить собственное топливо. Причина: Невозможно добавить несуществующий предмет в качестве топлива.'
failed_exist: '<prefix> &cНе удалось добавить собственное топливо. Причина: Это топливо уже существует.'
remove:
success: '<prefix> &aУдаление пользовательского топлива успешно.'
failed_not_exist: '<prefix> &cНе удалось удалить пользовательское топливо. Причина: Этого топлива не существует.'
reload:
success: '<prefix> &aПерезагрузка плагина выполнена успешно.'
exception: '<prefix> &cВпроцессе перезагрузки плагина произошла ошибка. Пожалуйста, проверьте консоль.'
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/lang/zh_cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ command:
success: '<prefix> &a物品获取成功'
not_exist_item: '<prefix> &c不存在物品 <item_name>'
player_offline: '<prefix> &c该玩家不在线或不存在'
add_fuel:
success: '<prefix> &a添加自定义燃料成功'
failed_add_air: '<prefix> &c添加自定义燃料失败,原因:不能将不存在的物品作为燃料。'
failed_exist: '<prefix> &c添加自定义燃料失败。原因:此燃料已存在。'
fuel:
add:
success: '<prefix> &a添加自定义燃料成功.'
failed_add_air: '<prefix> &c添加自定义燃料失败,原因:不能将不存在的物品作为燃料。'
failed_exist: '<prefix> &c添加自定义燃料失败。原因:此燃料已存在。'
remove:
success: '<prefix> &a删除自定义燃料成功.'
failed_not_exist: '<prefix> &c删除自定义燃料失败。原因:此燃料不存在。'
reload:
success: '<prefix> &a插件重载成功'
exception: '<prefix> &c插件重载过程中发生错误,请查看控制台'
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/lang/zh_hk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ command:
success: '<prefix> &a物品獲取成功。'
not_exist_item: '<prefix> &c不存在物品 <item_name>。'
player_offline: '<prefix> &c該玩家不在線上或不存在。'
add_fuel:
success: '<prefix> &a添加自定義燃料成功'
failed_add_air: '<prefix> &c添加自定義燃料失敗,原因:不能將不存在的物品作為燃料。'
failed_exist: '<prefix> &c添加自定義燃料失敗。原因:此燃料已存在。'
fuel:
add:
success: '<prefix> &a添加自定義燃料成功.'
failed_add_air: '<prefix> &c添加自定義燃料失敗,原因:不能將不存在的物品作為燃料。'
failed_exist: '<prefix> &c添加自定義燃料失敗。原因:此燃料已存在。'
remove:
success: '<prefix> &a刪除自定義燃料成功。'
failed_not_exist: '<prefix> &c刪除自定義燃料失敗。原因:此燃料不存在。'
reload:
success: '<prefix> &a插件重載成功。'
exception: '<prefix> &c插件重載過程中發生錯誤,請查看控制台。'
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/lang/zh_tw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ command:
success: '<prefix> &a物品獲取成功。'
not_exist_item: '<prefix> &c不存在物品 <item_name>。'
player_offline: '<prefix> &c該玩家不在線上或不存在。'
add_fuel:
success: '<prefix> &a添加自定義燃料成功'
failed_add_air: '<prefix> &c添加自定義燃料失敗,原因:不能將不存在的物品作為燃料。'
failed_exist: '<prefix> &c添加自定義燃料失敗。原因:此燃料已存在。'
fuel:
add:
success: '<prefix> &a添加自定義燃料成功.'
failed_add_air: '<prefix> &c添加自定義燃料失敗,原因:不能將不存在的物品作為燃料。'
failed_exist: '<prefix> &c添加自定義燃料失敗。原因:此燃料已存在。'
remove:
success: '<prefix> &a刪除自定義燃料成功。'
failed_not_exist: '<prefix> &c刪除自定義燃料失敗。原因:此燃料不存在。'
reload:
success: '<prefix> &a插件重載成功。'
exception: '<prefix> &c插件重載過程中發生錯誤,請查看控制台。'
Expand Down

0 comments on commit 1dd6517

Please sign in to comment.