mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-26 02:01:34 +01:00
Added MaterialConverter util class for type id conversions.
This commit is contained in:
parent
a7cace0fdc
commit
606a3fa3ce
14
.travis.yml
14
.travis.yml
@ -1,7 +1,7 @@
|
|||||||
language: java
|
language: java
|
||||||
jdk:
|
jdk:
|
||||||
- oraclejdk8
|
- oraclejdk8
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
||||||
before_install:
|
before_install:
|
||||||
- sed -i.bak -e 's|https://nexus.codehaus.org/snapshots/|https://oss.sonatype.org/content/repositories/codehaus-snapshots/|g' ~/.m2/settings.xml
|
- sed -i.bak -e 's|https://nexus.codehaus.org/snapshots/|https://oss.sonatype.org/content/repositories/codehaus-snapshots/|g' ~/.m2/settings.xml
|
||||||
|
@ -77,6 +77,7 @@ import com.onarandombox.MultiverseCore.utils.MVEconomist;
|
|||||||
import com.onarandombox.MultiverseCore.utils.MVMessaging;
|
import com.onarandombox.MultiverseCore.utils.MVMessaging;
|
||||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||||
import com.onarandombox.MultiverseCore.utils.MVPlayerSession;
|
import com.onarandombox.MultiverseCore.utils.MVPlayerSession;
|
||||||
|
import com.onarandombox.MultiverseCore.utils.MaterialConverter;
|
||||||
import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety;
|
import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety;
|
||||||
import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation;
|
import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation;
|
||||||
import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter;
|
import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter;
|
||||||
@ -84,15 +85,12 @@ import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper;
|
|||||||
import com.onarandombox.MultiverseCore.utils.VaultHandler;
|
import com.onarandombox.MultiverseCore.utils.VaultHandler;
|
||||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||||
import de.themoep.idconverter.IdMappings;
|
|
||||||
import me.main__.util.SerializationConfig.NoSuchPropertyException;
|
import me.main__.util.SerializationConfig.NoSuchPropertyException;
|
||||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Difficulty;
|
import org.bukkit.Difficulty;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -103,7 +101,6 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.PluginLoader;
|
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||||
@ -641,17 +638,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
|||||||
if (section.isConfigurationSection("entryfee")) {
|
if (section.isConfigurationSection("entryfee")) {
|
||||||
ConfigurationSection feeSection = section.getConfigurationSection("entryfee");
|
ConfigurationSection feeSection = section.getConfigurationSection("entryfee");
|
||||||
if (feeSection.isInt("currency")) {
|
if (feeSection.isInt("currency")) {
|
||||||
int oldCurrencyItemId = feeSection.getInt("currency", -1);
|
world.setCurrency(MaterialConverter.convertConfigType(feeSection, "currency"));
|
||||||
if (oldCurrencyItemId >= 0) {
|
|
||||||
IdMappings.Mapping mapping = IdMappings.getById(Integer.toString(oldCurrencyItemId));
|
|
||||||
if (mapping != null) {
|
|
||||||
world.setCurrency(Material.matchMaterial(mapping.getFlatteningType()));
|
|
||||||
} else {
|
|
||||||
world.setCurrency(null);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
world.setCurrency(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (feeSection.isDouble("amount"))
|
if (feeSection.isDouble("amount"))
|
||||||
|
@ -8,7 +8,6 @@ import com.onarandombox.MultiverseCore.configuration.WorldPropertyValidator;
|
|||||||
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
import com.onarandombox.MultiverseCore.enums.AllowedPortalType;
|
||||||
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
import com.onarandombox.MultiverseCore.enums.EnglishChatColor;
|
||||||
import com.onarandombox.MultiverseCore.enums.EnglishChatStyle;
|
import com.onarandombox.MultiverseCore.enums.EnglishChatStyle;
|
||||||
import de.themoep.idconverter.IdMappings;
|
|
||||||
import me.main__.util.SerializationConfig.IllegalPropertyValueException;
|
import me.main__.util.SerializationConfig.IllegalPropertyValueException;
|
||||||
import me.main__.util.SerializationConfig.Property;
|
import me.main__.util.SerializationConfig.Property;
|
||||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||||
|
@ -2,8 +2,7 @@ package com.onarandombox.MultiverseCore.configuration;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import de.themoep.idconverter.IdMappings;
|
import com.onarandombox.MultiverseCore.utils.MaterialConverter;
|
||||||
import me.main__.util.SerializationConfig.IllegalPropertyValueException;
|
|
||||||
import me.main__.util.SerializationConfig.Property;
|
import me.main__.util.SerializationConfig.Property;
|
||||||
import me.main__.util.SerializationConfig.SerializationConfig;
|
import me.main__.util.SerializationConfig.SerializationConfig;
|
||||||
|
|
||||||
@ -78,12 +77,8 @@ public class EntryFee extends SerializationConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Material deserialize(Object o, Class<Material> aClass) throws IllegalPropertyValueException {
|
public Material deserialize(Object o, Class<Material> aClass) {
|
||||||
IdMappings.Mapping mapping = IdMappings.getById(o.toString());
|
return MaterialConverter.convertTypeString(o.toString());
|
||||||
if (mapping != null) {
|
|
||||||
return Material.matchMaterial(mapping.getFlatteningType());
|
|
||||||
}
|
|
||||||
return Material.matchMaterial(o.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.onarandombox.MultiverseCore.utils;
|
||||||
|
|
||||||
|
import de.themoep.idconverter.IdMappings;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A tool for converting values which may be an old type ID to a Material.
|
||||||
|
*/
|
||||||
|
public class MaterialConverter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the value in the given config at the given path from a numeric id or flattened material name to a
|
||||||
|
* Material.
|
||||||
|
*
|
||||||
|
* @param config The config with the value to convert.
|
||||||
|
* @param path The path of the value in the config.
|
||||||
|
* @return The converted Material type or null if no matching type.
|
||||||
|
*/
|
||||||
|
public static Material convertConfigType(ConfigurationSection config, String path) {
|
||||||
|
return convertTypeString(config.getString(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a string representing a numeric id or flattened material name to a Material.
|
||||||
|
*
|
||||||
|
* @param value The value to convert.
|
||||||
|
* @return The converted Material type or null if no matching type.
|
||||||
|
*/
|
||||||
|
public static Material convertTypeString(String value) {
|
||||||
|
IdMappings.Mapping mapping = IdMappings.getById(value);
|
||||||
|
if (mapping != null) {
|
||||||
|
return Material.matchMaterial(mapping.getFlatteningType());
|
||||||
|
} else {
|
||||||
|
return Material.matchMaterial(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user