<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.traincarts.net/index.php?action=history&amp;feed=atom&amp;title=BKCommonLib%2FConversion</id>
	<title>BKCommonLib/Conversion - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.traincarts.net/index.php?action=history&amp;feed=atom&amp;title=BKCommonLib%2FConversion"/>
	<link rel="alternate" type="text/html" href="https://wiki.traincarts.net/index.php?title=BKCommonLib/Conversion&amp;action=history"/>
	<updated>2026-05-01T17:01:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.13</generator>
	<entry>
		<id>https://wiki.traincarts.net/index.php?title=BKCommonLib/Conversion&amp;diff=7844&amp;oldid=prev</id>
		<title>RyanDo at 09:45, 12 October 2025</title>
		<link rel="alternate" type="text/html" href="https://wiki.traincarts.net/index.php?title=BKCommonLib/Conversion&amp;diff=7844&amp;oldid=prev"/>
		<updated>2025-10-12T09:45:52Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 09:45, 12 October 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[BKCommonLib|« Go back]]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Introduction==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Introduction==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;BKCommonLib features a broad and versatile data type conversion system to convert (or cast, in some cases) one data type to another. For example, conversion between:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;BKCommonLib features a broad and versatile data type conversion system to convert (or cast, in some cases) one data type to another. For example, conversion between:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key pulseco1_mediawiki:diff::1.12:old-1537:rev-7844 --&gt;
&lt;/table&gt;</summary>
		<author><name>RyanDo</name></author>
	</entry>
	<entry>
		<id>https://wiki.traincarts.net/index.php?title=BKCommonLib/Conversion&amp;diff=1537&amp;oldid=prev</id>
		<title>RyanDo: Created page with &quot;« Go back  ==Introduction== BKCommonLib features a broad and versatile data type conversion system to convert (or cast, in some cases) one data type to anothe...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.traincarts.net/index.php?title=BKCommonLib/Conversion&amp;diff=1537&amp;oldid=prev"/>
		<updated>2021-06-09T18:38:07Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&lt;a href=&quot;/p/BKCommonLib&quot; title=&quot;BKCommonLib&quot;&gt;« Go back&lt;/a&gt;  ==Introduction== BKCommonLib features a broad and versatile data type conversion system to convert (or cast, in some cases) one data type to anothe...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[BKCommonLib|« Go back]]&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
BKCommonLib features a broad and versatile data type conversion system to convert (or cast, in some cases) one data type to another. For example, conversion between:&lt;br /&gt;
&lt;br /&gt;
* numeric values (byte, short, int, long, float, double)&lt;br /&gt;
* String (or String producing object) data and numeric values&lt;br /&gt;
* Collections and arrays (list, set, map, object array, primitive array (int[]))&lt;br /&gt;
* Wrappers and their handles (CommonTag, Entity, World, Chunk, DataWatcher, etc.)&lt;br /&gt;
* Enumerations and Strings (Material, GameMode, PermissionDefault, etc.)&lt;br /&gt;
* Properties (item container and item, difficulty and difficulty ID, etc.)&lt;br /&gt;
* Custom (plugins can register their own)&lt;br /&gt;
Whenever you set something in a generic way, or try to obtain one in a generic way, the Conversion service takes care of it. It is used in most of the data storage classes BKCommonLib provides, including configuration and NBT API. The conversion service adds functionality where serialization and de-serialization of data fails.&lt;br /&gt;
&lt;br /&gt;
==Converter==&lt;br /&gt;
The [https://github.com/bergerkiller/BKCommonLib/blob/master/src/main/java/com/bergerkiller/bukkit/common/conversion/Converter.java Converter] takes care of the conversion from an unknown Object to a certain output type. It also provides several helper methods to make working with converters easier. These, if not provided in a base class, can be copied over without an issue. The default base class, which provides the basic needs, is called [https://github.com/bergerkiller/BKCommonLib/blob/master/src/main/java/com/bergerkiller/bukkit/common/conversion/BasicConverter.java BasicConverter].&lt;br /&gt;
&lt;br /&gt;
Every converter defines several methods:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;convert&amp;#039;&amp;#039;&amp;#039; (and overloads) converts to the output type of the converter. The convert without default should be final.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;getOutputType&amp;#039;&amp;#039;&amp;#039; tells the Conversion service what type of Object this converter can produce&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;isCastingSupported&amp;#039;&amp;#039;&amp;#039; tells the Conversion service whether the produced type allows casting (e.g. Entity to Creeper)&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;isRegisterSupported&amp;#039;&amp;#039;&amp;#039; tells the Conversion service whether the converter can be registered at all&lt;br /&gt;
Make sure that for converters that produce common types, such as Object and Integer, the isRegisterSupported returns false. Not doing so may result in your (limited) converter replacing other converters that can actually do the job. This mainly applies to conversion from property owner to property. You do not want your &amp;#039;Item to Item Material&amp;#039; converter to replace the &amp;#039;Anything to Material&amp;#039; converter.&lt;br /&gt;
&lt;br /&gt;
==Conversion types==&lt;br /&gt;
You can access and use default converters in the [https://github.com/bergerkiller/BKCommonLib/blob/master/src/main/java/com/bergerkiller/bukkit/common/conversion/type/ConversionTypes.java ConversionTypes] class, or it&amp;#039;s extension, the [https://github.com/bergerkiller/BKCommonLib/blob/master/src/main/java/com/bergerkiller/bukkit/common/conversion/Conversion.java Conversion] class.&lt;br /&gt;
&lt;br /&gt;
==Converter pair==&lt;br /&gt;
A [https://github.com/bergerkiller/BKCommonLib/blob/master/src/main/java/com/bergerkiller/bukkit/common/conversion/ConverterPair.java ConverterPair] is a combination of two Converters that can convert from one to the other, and back. The class is self-explanatory. These pairs can be used to provide self-converting collections, accessors and other two-way &amp;#039;setting and getting&amp;#039; types. All default pairs can be found in the [https://github.com/bergerkiller/BKCommonLib/blob/master/src/main/java/com/bergerkiller/bukkit/common/conversion/ConversionPairs.java ConversionPairs] class.&lt;br /&gt;
&lt;br /&gt;
==Translator==&lt;br /&gt;
The main use case for Converter Pairs is reflection. To access a field of type &amp;#039;net.minecraft.server.Entity&amp;#039; without losing type information, you can provide a &amp;#039;&amp;#039;&amp;#039;translation&amp;#039;&amp;#039;&amp;#039;. For example, the definition of the field &amp;#039;passenger&amp;#039; in the nms.Entity class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public static final TranslatorFieldAccessor&amp;lt;Entity&amp;gt; = entityTemplate.getField(&amp;quot;passenger&amp;quot;).translate(ConversionPairs.entity);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now you can get and set the passenger using Bukkit entities. The TranslatorFieldAccessor allows you to still get and set the base type (nms.Entity), but no type is exposed (it&amp;#039;s an Object).&lt;br /&gt;
&lt;br /&gt;
==Converting to a generic type==&lt;br /&gt;
To convert a value to a type that is not known at compile time (generics), use the following method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Object input = ...;&lt;br /&gt;
Class&amp;lt;T&amp;gt; typeToGet = ...;&lt;br /&gt;
T default = ...;&lt;br /&gt;
T value = Conversion.convert(input, typeToGet, default);&amp;lt;/pre&amp;gt;&lt;br /&gt;
The default is returned when conversion, for some reason, fails. There are also overloads of this method to return null on failure, or to use the default class type instead of typeToGet.&lt;/div&gt;</summary>
		<author><name>RyanDo</name></author>
	</entry>
</feed>