2016-06-18 17:57:16 +02:00
/ *
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
2013-07-01 15:11:04 +02:00
package fr.neatmonster.nocheatplus.compat.blocks.init.vanilla ;
2015-01-05 16:12:05 +01:00
import java.util.Collection ;
2013-07-01 15:11:04 +02:00
import java.util.LinkedList ;
import java.util.List ;
import fr.neatmonster.nocheatplus.compat.blocks.BlockPropertiesSetup ;
2017-04-29 10:55:15 +02:00
import fr.neatmonster.nocheatplus.compat.blocks.IPatchBlockPropertiesSetup ;
2018-01-15 22:16:09 +01:00
import fr.neatmonster.nocheatplus.compat.blocks.init.vanilla.special.MultiClientProtocolBlockShapePatch ;
2013-07-01 15:11:04 +02:00
import fr.neatmonster.nocheatplus.config.WorldConfigProvider ;
2014-11-17 11:25:51 +01:00
import fr.neatmonster.nocheatplus.logging.StaticLog ;
2013-07-01 15:11:04 +02:00
2015-01-05 16:12:05 +01:00
public class VanillaBlocksFactory {
2013-07-01 15:11:04 +02:00
2015-01-05 16:12:05 +01:00
public Collection < String > setupVanillaBlocks ( final WorldConfigProvider < ? > worldConfigProvider ) {
2017-04-29 10:55:15 +02:00
// Vanilla blocks (abort with first failure, low to high MC version).
2015-01-05 14:45:17 +01:00
final List < BlockPropertiesSetup > setups = new LinkedList < BlockPropertiesSetup > ( ) ;
2015-01-05 16:12:05 +01:00
final List < String > success = new LinkedList < String > ( ) ;
2015-01-05 14:45:17 +01:00
try {
setups . add ( new BlocksMC1_5 ( ) ) ;
setups . add ( new BlocksMC1_6_1 ( ) ) ;
setups . add ( new BlocksMC1_7_2 ( ) ) ;
setups . add ( new BlocksMC1_8 ( ) ) ;
2016-03-04 21:44:51 +01:00
setups . add ( new BlocksMC1_9 ( ) ) ;
2016-06-09 13:27:43 +02:00
setups . add ( new BlocksMC1_10 ( ) ) ;
2016-11-25 11:32:26 +01:00
setups . add ( new BlocksMC1_11 ( ) ) ;
2017-05-14 12:00:02 +02:00
setups . add ( new BlocksMC1_12 ( ) ) ;
2018-08-18 22:23:21 +02:00
setups . add ( new BlocksMC1_13 ( ) ) ;
2015-01-05 14:45:17 +01:00
}
catch ( Throwable t ) { }
for ( final BlockPropertiesSetup setup : setups ) {
try {
// Assume the blocks setup to message success.
setup . setupBlockProperties ( worldConfigProvider ) ;
2015-01-05 16:12:05 +01:00
success . add ( setup . getClass ( ) . getSimpleName ( ) ) ;
// TODO: Do logging from here ?
2015-01-05 14:45:17 +01:00
}
catch ( Throwable t ) {
2015-11-15 02:15:20 +01:00
StaticLog . logSevere ( setup . getClass ( ) . getSimpleName ( ) + " .setupBlockProperties could not execute properly: " + t . getClass ( ) . getSimpleName ( ) + " - " + t . getMessage ( ) ) ;
2015-01-05 14:45:17 +01:00
StaticLog . logSevere ( t ) ;
// Abort further processing.
break ;
}
}
2017-04-29 10:55:15 +02:00
// Patches for special circumstances.
for ( IPatchBlockPropertiesSetup patch : new IPatchBlockPropertiesSetup [ ] {
2018-01-15 22:16:09 +01:00
new MultiClientProtocolBlockShapePatch ( ) ,
2017-04-29 10:55:15 +02:00
} ) {
try {
if ( patch . isAvailable ( ) ) {
patch . setupBlockProperties ( worldConfigProvider ) ;
String description = patch . getNeutralDescription ( ) ;
if ( description = = null | | description . isEmpty ( ) ) {
description = patch . getClass ( ) . getSimpleName ( ) ;
}
2017-04-29 12:19:40 +02:00
StaticLog . logInfo ( " Update block-info: " + description ) ;
2017-04-29 10:55:15 +02:00
}
}
catch ( Throwable t ) {
StaticLog . logSevere ( patch . getClass ( ) . getSimpleName ( ) + " could not be processed: " + t . getClass ( ) . getSimpleName ( ) + " - " + t . getMessage ( ) ) ;
StaticLog . logSevere ( t ) ;
}
}
2015-01-05 16:12:05 +01:00
return success ;
2015-01-05 14:45:17 +01:00
}
2013-07-01 15:11:04 +02:00
}