2022-01-01 18:27:52 +01:00
package net.minestom.demo ;
2020-02-17 17:33:53 +01:00
2021-03-25 14:20:58 +01:00
import net.kyori.adventure.text.Component ;
import net.kyori.adventure.text.format.NamedTextColor ;
2021-06-11 22:54:52 +02:00
import net.kyori.adventure.text.format.Style ;
2021-04-05 03:58:05 +02:00
import net.kyori.adventure.text.format.TextColor ;
2021-04-19 16:47:46 +02:00
import net.kyori.adventure.text.format.TextDecoration ;
2023-07-02 21:34:54 +02:00
import net.minestom.demo.block.TestBlockHandler ;
2023-07-16 13:48:05 +02:00
import net.minestom.demo.block.placement.DripstonePlacementRule ;
2022-01-01 18:27:52 +01:00
import net.minestom.demo.commands.* ;
2020-04-24 03:25:58 +02:00
import net.minestom.server.MinecraftServer ;
import net.minestom.server.command.CommandManager ;
2024-01-30 13:35:12 +01:00
import net.minestom.server.entity.Player ;
2021-04-08 23:41:22 +02:00
import net.minestom.server.event.server.ServerListPingEvent ;
2021-04-23 14:38:50 +02:00
import net.minestom.server.extras.lan.OpenToLAN ;
import net.minestom.server.extras.lan.OpenToLANConfig ;
2020-04-24 03:25:58 +02:00
import net.minestom.server.instance.block.BlockManager ;
2024-01-30 13:35:12 +01:00
import net.minestom.server.item.ItemStack ;
import net.minestom.server.item.Material ;
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket ;
2021-04-11 06:14:36 +02:00
import net.minestom.server.ping.ResponseData ;
2024-01-30 13:35:12 +01:00
import net.minestom.server.recipe.RecipeCategory ;
import net.minestom.server.recipe.ShapedRecipe ;
2021-04-18 23:47:07 +02:00
import net.minestom.server.utils.identity.NamedAndIdentified ;
2020-04-24 03:25:58 +02:00
import net.minestom.server.utils.time.TimeUnit ;
2024-01-30 13:35:12 +01:00
import org.jetbrains.annotations.NotNull ;
2021-06-30 00:47:57 +02:00
import java.time.Duration ;
2024-01-30 13:35:12 +01:00
import java.util.List ;
2020-04-01 13:16:18 +02:00
2020-02-17 17:33:53 +01:00
public class Main {
public static void main ( String [ ] args ) {
2023-12-01 20:59:50 +01:00
System . setProperty ( " minestom.experiment.pose-updates " , " true " ) ;
2023-06-17 16:43:03 +02:00
2023-10-07 13:39:24 +02:00
MinecraftServer . setCompressionThreshold ( 0 ) ;
2020-02-17 17:33:53 +01:00
MinecraftServer minecraftServer = MinecraftServer . init ( ) ;
2024-02-12 21:25:46 +01:00
MinecraftServer . getBiomeManager ( ) . loadVanillaBiomes ( ) ;
2020-02-17 17:33:53 +01:00
BlockManager blockManager = MinecraftServer . getBlockManager ( ) ;
2023-07-16 13:48:05 +02:00
blockManager . registerBlockPlacementRule ( new DripstonePlacementRule ( ) ) ;
2023-07-02 21:34:54 +02:00
blockManager . registerHandler ( TestBlockHandler . INSTANCE . getNamespaceId ( ) , ( ) - > TestBlockHandler . INSTANCE ) ;
2020-04-01 13:16:18 +02:00
CommandManager commandManager = MinecraftServer . getCommandManager ( ) ;
2020-07-14 13:35:07 +02:00
commandManager . register ( new TestCommand ( ) ) ;
2020-11-12 03:09:36 +01:00
commandManager . register ( new EntitySelectorCommand ( ) ) ;
2020-11-02 02:53:12 +01:00
commandManager . register ( new HealthCommand ( ) ) ;
2021-03-11 03:31:25 +01:00
commandManager . register ( new LegacyCommand ( ) ) ;
2020-07-24 01:03:24 +02:00
commandManager . register ( new DimensionCommand ( ) ) ;
2020-07-29 05:03:07 +02:00
commandManager . register ( new ShutdownCommand ( ) ) ;
2020-11-12 03:09:36 +01:00
commandManager . register ( new TeleportCommand ( ) ) ;
2020-11-18 19:39:06 +01:00
commandManager . register ( new PlayersCommand ( ) ) ;
2021-09-16 06:56:08 +02:00
commandManager . register ( new FindCommand ( ) ) ;
2020-12-31 19:50:26 +01:00
commandManager . register ( new TitleCommand ( ) ) ;
2021-01-09 03:40:22 +01:00
commandManager . register ( new BookCommand ( ) ) ;
2021-02-22 12:42:46 +01:00
commandManager . register ( new ShootCommand ( ) ) ;
2021-03-11 00:11:29 +01:00
commandManager . register ( new HorseCommand ( ) ) ;
2021-03-25 14:20:58 +01:00
commandManager . register ( new EchoCommand ( ) ) ;
2021-03-26 21:32:58 +01:00
commandManager . register ( new SummonCommand ( ) ) ;
commandManager . register ( new RemoveCommand ( ) ) ;
2021-04-11 23:43:35 +02:00
commandManager . register ( new GiveCommand ( ) ) ;
2021-06-16 14:39:11 +02:00
commandManager . register ( new SetBlockCommand ( ) ) ;
2021-11-01 18:04:00 +01:00
commandManager . register ( new AutoViewCommand ( ) ) ;
2022-01-08 00:56:49 +01:00
commandManager . register ( new SaveCommand ( ) ) ;
commandManager . register ( new GamemodeCommand ( ) ) ;
2022-07-02 05:39:39 +02:00
commandManager . register ( new ExecuteCommand ( ) ) ;
commandManager . register ( new RedirectTestCommand ( ) ) ;
2023-05-13 14:41:33 +02:00
commandManager . register ( new DebugGridCommand ( ) ) ;
2023-05-21 18:21:24 +02:00
commandManager . register ( new DisplayCommand ( ) ) ;
2023-08-05 20:07:34 +02:00
commandManager . register ( new NotificationCommand ( ) ) ;
2023-08-31 01:04:11 +02:00
commandManager . register ( new TestCommand2 ( ) ) ;
2023-11-25 20:43:28 +01:00
commandManager . register ( new ConfigCommand ( ) ) ;
2024-01-02 12:15:19 +01:00
commandManager . register ( new SidebarCommand ( ) ) ;
2024-01-29 20:53:15 +01:00
commandManager . register ( new SetEntityType ( ) ) ;
2024-02-04 20:16:15 +01:00
commandManager . register ( new RelightCommand ( ) ) ;
2024-02-10 23:41:57 +01:00
commandManager . register ( new KillCommand ( ) ) ;
2024-03-19 17:44:51 +01:00
commandManager . register ( new WeatherCommand ( ) ) ;
2021-09-16 06:56:08 +02:00
2021-03-25 14:20:58 +01:00
commandManager . setUnknownCommandCallback ( ( sender , command ) - > sender . sendMessage ( Component . text ( " Unknown command " , NamedTextColor . RED ) ) ) ;
2020-11-02 04:13:43 +01:00
2021-07-05 08:22:51 +02:00
MinecraftServer . getBenchmarkManager ( ) . enable ( Duration . of ( 10 , TimeUnit . SECOND ) ) ;
2020-02-17 17:33:53 +01:00
2021-12-16 00:15:55 +01:00
MinecraftServer . getSchedulerManager ( ) . buildShutdownTask ( ( ) - > System . out . println ( " Good night " ) ) ;
2020-04-28 19:22:54 +02:00
2021-07-15 05:23:33 +02:00
MinecraftServer . getGlobalEventHandler ( ) . addListener ( ServerListPingEvent . class , event - > {
2021-04-11 06:14:36 +02:00
ResponseData responseData = event . getResponseData ( ) ;
2021-04-18 23:47:07 +02:00
responseData . addEntry ( NamedAndIdentified . named ( " The first line is separated from the others " ) ) ;
responseData . addEntry ( NamedAndIdentified . named ( " Could be a name, or a message " ) ) ;
2021-04-19 16:47:46 +02:00
// on modern versions, you can obtain the player connection directly from the event
if ( event . getConnection ( ) ! = null ) {
responseData . addEntry ( NamedAndIdentified . named ( " IP test: " + event . getConnection ( ) . getRemoteAddress ( ) . toString ( ) ) ) ;
responseData . addEntry ( NamedAndIdentified . named ( " Connection Info: " ) ) ;
String ip = event . getConnection ( ) . getServerAddress ( ) ;
responseData . addEntry ( NamedAndIdentified . named ( Component . text ( '-' , NamedTextColor . DARK_GRAY )
. append ( Component . text ( " IP: " , NamedTextColor . GRAY ) )
. append ( Component . text ( ip ! = null ? ip : " ??? " , NamedTextColor . YELLOW ) ) ) ) ;
responseData . addEntry ( NamedAndIdentified . named ( Component . text ( '-' , NamedTextColor . DARK_GRAY )
. append ( Component . text ( " PORT: " , NamedTextColor . GRAY ) )
. append ( Component . text ( event . getConnection ( ) . getServerPort ( ) ) ) ) ) ;
responseData . addEntry ( NamedAndIdentified . named ( Component . text ( '-' , NamedTextColor . DARK_GRAY )
. append ( Component . text ( " VERSION: " , NamedTextColor . GRAY ) )
. append ( Component . text ( event . getConnection ( ) . getProtocolVersion ( ) ) ) ) ) ;
}
2021-06-11 22:54:52 +02:00
responseData . addEntry ( NamedAndIdentified . named ( Component . text ( " Time " , NamedTextColor . YELLOW )
. append ( Component . text ( " : " , NamedTextColor . GRAY ) )
. append ( Component . text ( System . currentTimeMillis ( ) , Style . style ( TextDecoration . ITALIC ) ) ) ) ) ;
2021-04-08 23:41:22 +02:00
2021-04-18 23:47:07 +02:00
// components will be converted the legacy section sign format so they are displayed in the client
2021-04-19 16:47:46 +02:00
responseData . addEntry ( NamedAndIdentified . named ( Component . text ( " You can use " ) . append ( Component . text ( " styling too! " , NamedTextColor . RED , TextDecoration . BOLD ) ) ) ) ;
2021-04-18 23:47:07 +02:00
// the data will be automatically converted to the correct format on response, so you can do RGB and it'll be downsampled!
2021-04-19 16:47:46 +02:00
// on legacy versions, colors will be converted to the section format so it'll work there too
responseData . setDescription ( Component . text ( " This is a Minestom Server " , TextColor . color ( 0x66b3ff ) ) ) ;
2021-06-11 22:54:52 +02:00
//responseData.setPlayersHidden(true);
2021-04-05 00:43:19 +02:00
} ) ;
2024-01-30 13:35:12 +01:00
var ironBlockRecipe = new ShapedRecipe (
" minestom:test " , 2 , 2 , " " ,
RecipeCategory . Crafting . MISC ,
List . of (
new DeclareRecipesPacket . Ingredient ( List . of ( ItemStack . of ( Material . IRON_INGOT ) ) ) ,
new DeclareRecipesPacket . Ingredient ( List . of ( ItemStack . of ( Material . IRON_INGOT ) ) ) ,
new DeclareRecipesPacket . Ingredient ( List . of ( ItemStack . of ( Material . IRON_INGOT ) ) ) ,
new DeclareRecipesPacket . Ingredient ( List . of ( ItemStack . of ( Material . IRON_INGOT ) ) )
) , ItemStack . of ( Material . IRON_BLOCK ) , true ) {
@Override
public boolean shouldShow ( @NotNull Player player ) {
return true ;
}
} ;
MinecraftServer . getRecipeManager ( ) . addRecipe ( ironBlockRecipe ) ;
2020-03-20 19:50:22 +01:00
PlayerInit . init ( ) ;
2024-01-16 15:47:38 +01:00
// VelocityProxy.enable("abcdef");
2020-11-15 08:03:33 +01:00
//BungeeCordProxy.enable();
2020-11-09 23:48:34 +01:00
2023-11-25 20:43:28 +01:00
//MojangAuth.init();
2020-06-22 00:57:53 +02:00
2021-04-23 14:38:50 +02:00
// useful for testing - we don't need to worry about event calls so just set this to a long time
2021-06-30 00:47:57 +02:00
OpenToLAN . open ( new OpenToLANConfig ( ) . eventCallDelay ( Duration . of ( 1 , TimeUnit . DAY ) ) ) ;
2021-04-23 14:38:50 +02:00
2021-04-05 03:58:05 +02:00
minecraftServer . start ( " 0.0.0.0 " , 25565 ) ;
2022-06-05 14:53:28 +02:00
// minecraftServer.start(java.net.UnixDomainSocketAddress.of("minestom-demo.sock"));
2020-12-06 20:20:05 +01:00
//Runtime.getRuntime().addShutdownHook(new Thread(MinecraftServer::stopCleanly));
2020-02-17 17:33:53 +01:00
}
}