mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Try add potion effect preview
Former-commit-id: fd412e0fc3237f8d0e3c586fc83cfd871011fada
This commit is contained in:
1 parent
56c3b1c812
commit
450e09257a
2 files changed
+93
No files matched your search
@@ -15,6 +15,7 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@@ -22,6 +23,8 @@ import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
|
||||
@@ -30,6 +33,7 @@ public class MsgUtil {
|
||||
private static YamlConfiguration messages;
|
||||
private static YamlConfiguration itemi18n;
|
||||
private static YamlConfiguration enchi18n;
|
||||
private static YamlConfiguration potioni18n;
|
||||
private static HashMap<UUID, LinkedList<String>> player_messages = new HashMap<UUID, LinkedList<String>>();
|
||||
/**
|
||||
* Loads all the messages from messages.yml
|
||||
@@ -176,6 +180,58 @@ public class MsgUtil {
|
||||
return Ench_i18n;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void loadPotioni18n() {
|
||||
plugin.getLogger().info("Starting loading Potion i18n...");
|
||||
File potioni18nFile = new File(plugin.getDataFolder(), "potioni18n.yml");
|
||||
if (!potioni18nFile.exists()) {
|
||||
plugin.getLogger().info("Creating potioni18n.yml");
|
||||
plugin.saveResource("potioni18n.yml", true);
|
||||
}
|
||||
// Store it
|
||||
potioni18n = YamlConfiguration.loadConfiguration(potioni18nFile);
|
||||
potioni18n.options().copyDefaults(true);
|
||||
YamlConfiguration potioni18nYAML = YamlConfiguration.loadConfiguration(new InputStreamReader(plugin.getResource("potioni18n.yml")));
|
||||
potioni18n.setDefaults(potioni18nYAML);
|
||||
Util.parseColours(potioni18n);
|
||||
PotionEffectType[] potionsi18n = PotionEffectType.values();
|
||||
for (PotionEffectType potion : potionsi18n) {
|
||||
String potionname =potioni18n.getString("potioni18n."+potion.getName().trim());
|
||||
if(potionname==null || potionname.equals("")) {
|
||||
plugin.getLogger().info("Found new ench ["+potion.getName()+"] ,add it in config...");
|
||||
enchi18n.set("enchi18n."+potion.getName().trim(),potion.getName().trim());
|
||||
}
|
||||
}
|
||||
try {
|
||||
enchi18n.save(potioni18nFile);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
plugin.getLogger().log(Level.WARNING, "Could not load/save transaction enchname from enchi18n.yml. Skipping.");
|
||||
}
|
||||
plugin.getLogger().info("Complete to load enchname i18n.");
|
||||
}
|
||||
public static String getPotioni18n(PotionEffectType potion) {
|
||||
if(potion==null) {
|
||||
return "ERROR";
|
||||
}
|
||||
String PotionString = potion.getName().trim();
|
||||
String Potion_i18n = null;
|
||||
try {
|
||||
Potion_i18n = enchi18n.getString("potioni18n."+PotionString);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Potion_i18n = null;
|
||||
}
|
||||
if(Potion_i18n==null) {
|
||||
return PotionString;
|
||||
}else {
|
||||
return Potion_i18n;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* The name of the player to message
|
||||
|
||||
@@ -12,9 +12,11 @@ import java.util.Map.Entry;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.io.output.ThresholdingOutputStream;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -29,11 +31,16 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.Sign;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
|
||||
import com.mysql.fabric.xmlrpc.base.Array;
|
||||
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
@@ -665,6 +672,11 @@ public class Util {
|
||||
for (int i = 0; i < a.size(); i++) {
|
||||
finalItemdata += ChatColor.GRAY + a.get(i) + " " + Util.formatEnchLevel(b.get(i)) + "\n";
|
||||
}
|
||||
|
||||
String potionResult = getPotiondata(itemStack);
|
||||
if(potionResult!=null) {
|
||||
finalItemdata += potionResult;
|
||||
}
|
||||
|
||||
if (Itemlore != null) {
|
||||
for (String string : Itemlore) {
|
||||
@@ -697,5 +709,30 @@ public class Util {
|
||||
|
||||
}
|
||||
}
|
||||
public static String getPotiondata(ItemStack iStack) {
|
||||
if((iStack.getType() != Material.POTION)==true && (iStack.getType() !=Material.LINGERING_POTION)==true && (iStack.getType() !=Material.SPLASH_POTION)==true){
|
||||
return null;
|
||||
}
|
||||
List<String> pEffects = new ArrayList<String>();
|
||||
PotionMeta pMeta = (PotionMeta)iStack.getItemMeta();
|
||||
if(pMeta.getBasePotionData().getType()!=null) {
|
||||
pEffects.add(MsgUtil.getPotioni18n(pMeta.getBasePotionData().getType().getEffectType()));
|
||||
}
|
||||
if(pMeta.hasCustomEffects()) {
|
||||
List<PotionEffect> cEffects = pMeta.getCustomEffects();
|
||||
for (PotionEffect potionEffect : cEffects) {
|
||||
pEffects.add(MsgUtil.getPotioni18n(potionEffect.getType()));
|
||||
}
|
||||
}
|
||||
if(pEffects != null && pEffects.isEmpty() == false) {
|
||||
String result = new String();
|
||||
for (String effectString : pEffects) {
|
||||
result+=ChatColor.BLUE + effectString+"\n";
|
||||
}
|
||||
return result;
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user