1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 15:03:36 +01:00

Option to translate potion/tipped arrow effect names

This commit is contained in:
Zrips 2022-08-08 12:25:54 +03:00
parent 389b6dc724
commit 2056525a16
3 changed files with 1904 additions and 1866 deletions

View File

@ -12,6 +12,7 @@ import java.util.stream.Collectors;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.potion.PotionType;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
@ -21,15 +22,19 @@ import com.gamingmesh.jobs.container.NameList;
import com.gamingmesh.jobs.hooks.HookManager;
import com.gamingmesh.jobs.stuff.Util;
import net.Zrips.CMILib.Container.CMIText;
import net.Zrips.CMILib.Entities.CMIEntityType;
import net.Zrips.CMILib.FileHandler.ConfigReader;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Logs.CMIDebug;
public class NameTranslatorManager {
private final Map<CMIMaterial, NameList> listOfNames = new HashMap<>();
private final List<NameList> listOfEntities = new ArrayList<>(), listOfColors = new ArrayList<>();
private final Map<String, NameList> listOfEnchants = new HashMap<>(), listOfMMEntities = new HashMap<>();
private final Map<String, NameList> listOfEnchants = new HashMap<>();
private final Map<String, NameList> listOfMMEntities = new HashMap<>();
private final Map<String, NameList> listOfPotionEffects = new HashMap<>();
public String translate(String materialName, JobInfo info) {
return translate(materialName, info.getActionType(), info.getId(), info.getMeta(), info.getName());
@ -37,6 +42,8 @@ public class NameTranslatorManager {
public String translate(String materialName, ActionType action, int id, String meta, String name) {
// Translating name to user friendly
if (materialName.toLowerCase().contains("arrow"))
CMIDebug.d(materialName, meta, Util.getPotionByName(meta));
if (Jobs.getGCManager().UseCustomNames)
switch (action) {
case BREAK:
@ -64,6 +71,11 @@ public class NameTranslatorManager {
if (nameLs != null && !mat.isNone()) {
if (meta != null && !meta.isEmpty() && mat.isCanHavePotionType() && Util.getPotionByName(meta) != null) {
NameList record = listOfPotionEffects.get(meta.toLowerCase().replace("_", ""));
if (record != null)
meta = record.getMinecraftName();
return nameLs.getName() + ":" + meta;
}
@ -252,6 +264,18 @@ public class NameTranslatorManager {
} else
Jobs.consoleMsg("&cThe EnchantList section not found in &6" + itemFile.fileName + " &cfile.");
if ((section = itemFile.getConfig().getConfigurationSection("PotionEffects")) != null) {
listOfPotionEffects.clear();
for (String one : section.getKeys(false)) {
listOfPotionEffects.put(one.replace("_", "").toLowerCase(), new NameList(one, one, one, section.getString(one)));
}
if (listOfPotionEffects.size() > 0)
Jobs.consoleMsg("&eLoaded &6" + listOfPotionEffects.size() + " &ecustom enchant names");
} else
Jobs.consoleMsg("&cThe PotionEffects section not found in &6" + itemFile.fileName + " &cfile.");
if ((section = itemFile.getConfig().getConfigurationSection("ColorList")) != null) {
listOfColors.clear();
@ -413,6 +437,13 @@ public class NameTranslatorManager {
c.get("EnchantList." + enchName, name);
}
for (PotionType one : PotionType.values()) {
String potionName = CMIText.firstToUpperCase(one.name());
if (potionName.equals("Unknown"))
continue;
c.get("PotionEffects." + potionName, potionName);
}
// Color list
c.get("ColorList.0-white", "&fWhite");
c.get("ColorList.1-orange", "&6Orange");

View File

@ -891,11 +891,18 @@ public final class JobsPaymentListener implements Listener {
case PLACE_ONE:
case PLACE_ALL:
case PLACE_SOME:
case DROP_ONE_SLOT:
case DROP_ALL_SLOT:
return;
default:
break;
}
if (!event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) &&
!event.getAction().equals(InventoryAction.PICKUP_ALL) &&
!event.getAction().equals(InventoryAction.PICKUP_HALF))
return;
if (!(event.getWhoClicked() instanceof Player))
return;