11package dev .cerus .minecraftplace ;
22
3- import co .aikar .commands .BukkitCommandManager ;
43import com .google .gson .JsonArray ;
54import com .google .gson .JsonElement ;
65import com .google .gson .JsonObject ;
1413import dev .cerus .minecraftplace .reddit .canvas .Palette ;
1514import dev .cerus .minecraftplace .reddit .client .PlaceSocketClient ;
1615import dev .cerus .minecraftplace .reddit .worker .CanvasUpdateWorker ;
17- import dev .cerus .minecraftplace .world .BlockColorCache ;
18- import dev .cerus .minecraftplace .world .BlockUpdateTask ;
19- import dev .cerus .minecraftplace .world .ChunkListener ;
20- import dev .cerus .minecraftplace .world .PlayerChunkController ;
21- import dev .cerus .minecraftplace .world .RPlaceCommand ;
22- import dev .cerus .minecraftplace .world .RPlaceGenerator ;
23- import dev .cerus .minecraftplace .world .WorldContext ;
2416import java .awt .Color ;
2517import java .io .IOException ;
2618import java .util .HashMap ;
2921import java .util .Set ;
3022import java .util .function .Consumer ;
3123import org .bukkit .Bukkit ;
32- import org .bukkit .Difficulty ;
33- import org .bukkit .GameRule ;
34- import org .bukkit .World ;
35- import org .bukkit .WorldCreator ;
36- import org .bukkit .WorldType ;
3724import org .bukkit .plugin .PluginManager ;
3825import org .bukkit .plugin .java .JavaPlugin ;
3926
@@ -59,37 +46,6 @@ public void onEnable() {
5946 final PluginManager pluginManager = this .getServer ().getPluginManager ();
6047 pluginManager .registerEvents (new JoinListener (this ), this );
6148
62- // Generate world
63- if (this .getConfig ().getBoolean ("world.enable" )) {
64- final BukkitCommandManager commandManager = new BukkitCommandManager (this );
65- commandManager .registerCommand (new RPlaceCommand ());
66-
67- this .paletteConfigCallbacks .add (palette ->
68- this .getServer ().getScheduler ().runTask (this , () -> {
69- final String worldName = this .getConfig ().getString ("world.name" );
70-
71- final BlockColorCache blockColorCache = new BlockColorCache (palette );
72- final WorldContext worldContext = new WorldContext (this , 16 * 8 , 4 , 16 * 8 );
73- final PlayerChunkController playerChunkController = new PlayerChunkController ();
74-
75- final World placeWorld = this .getServer ().createWorld (new WorldCreator (worldName )
76- .environment (World .Environment .NORMAL )
77- .generateStructures (false )
78- .generator (new RPlaceGenerator (this , blockColorCache , worldContext ))
79- .type (WorldType .FLAT ));
80- placeWorld .setGameRule (GameRule .DO_MOB_SPAWNING , false );
81- placeWorld .setGameRule (GameRule .DO_TRADER_SPAWNING , false );
82- placeWorld .setGameRule (GameRule .DO_PATROL_SPAWNING , false );
83- placeWorld .setGameRule (GameRule .DO_DAYLIGHT_CYCLE , false );
84- placeWorld .setGameRule (GameRule .DO_WEATHER_CYCLE , false );
85- placeWorld .setDifficulty (Difficulty .PEACEFUL );
86- placeWorld .setTime (6000 );
87-
88- pluginManager .registerEvents (new ChunkListener (worldContext , placeWorld , this , blockColorCache , playerChunkController ), this );
89- Bukkit .getScheduler ().runTaskTimerAsynchronously (this , new BlockUpdateTask (this , playerChunkController , blockColorCache ), 0 , 10 );
90- }));
91- }
92-
9349 // Enable fast graphics and start update task
9450 Bukkit .getScheduler ().runTaskLater (this , () ->
9551 MapScreenRegistry .getScreens ().stream ()
@@ -163,7 +119,7 @@ private void startClient(final RedditAuthenticator.Token token) throws Interrupt
163119 }
164120
165121 if (message .getTypeName ().equals ("DiffFrameMessageData" )
166- || message .getTypeName ().equals ("FullFrameMessageData" )) {
122+ || message .getTypeName ().equals ("FullFrameMessageData" )) {
167123 // These messages contain canvas updates (an url pointing to an image of the canvas)
168124 // These images show either the full or only a few updates tiles.
169125 final String imageUrl = message .get ("data.subscribe.data" ).get ("name" ).getAsString ();
@@ -178,9 +134,10 @@ private void startClient(final RedditAuthenticator.Token token) throws Interrupt
178134 final JsonArray colorsArr = dataObj .getAsJsonObject ("colorPalette" ).getAsJsonArray ("colors" );
179135 for (final JsonElement element : colorsArr ) {
180136 final JsonObject colorObj = element .getAsJsonObject ();
137+ final String colorString = colorObj .get ("hex" ).getAsString ().substring (1 );
181138 palette .set (
182139 colorObj .get ("index" ).getAsInt (),
183- new Color (Integer .parseInt (colorObj . get ( "hex" ). getAsString (). substring ( 1 ) , 16 ), false )
140+ new Color (Integer .parseInt (colorString , 16 ), false )
184141 );
185142 }
186143
@@ -216,6 +173,8 @@ private void startClient(final RedditAuthenticator.Token token) throws Interrupt
216173
217174 this .paletteConfigCallbacks .forEach (callback -> callback .accept (palette ));
218175 this .paletteConfigCallbacks .clear ();
176+
177+ this .getLogger ().info ("Received config, canvas dimensions: " + this .getScreenWidth () + "x" + this .getScreenHeight ());
219178 }
220179 });
221180 this .client .start (token .token ());
0 commit comments