Skip to content

Commit

Permalink
Implement the new r/place expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
cerus committed Apr 4, 2022
1 parent 3dd73dc commit 51679a6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 18 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ The plugin connects to a Reddit websocket that controls the canvas. After authen

**This plugin only works on 1.16.5 - 1.18.2 servers!**

1. Drop the plugin into your plugins folder
2. Download the [latest experimental maps release](https://github.com/cerus/maps/releases/download/2.0.0-SNAPSHOT-pre3/maps-plugin.jar) and drop it
1. Download the plugin [here](https://github.com/cerus/minecraft-place/releases/download/1.1.0/minecraft-place.jar)
2. Drop the plugin into your plugins folder
3. Download the [latest experimental maps release](https://github.com/cerus/maps/releases/download/2.0.0-SNAPSHOT-pre3/maps-plugin.jar) and drop it
into your plugins folder
3. Restart your server
4. Open `plugins/minecraft-place/config.yml`
5. Edit the credentials and save
4. Restart your server
5. Open `plugins/minecraft-place/config.yml`
6. Edit the credentials and save
1. See 'How to create a Reddit app' if you don't know how to get a client id and secret
6. Restart your server again
7. Build a 16 by 8 rectangle and place item frames ([like this](https://i.imgur.com/kHjODX5.png))
8. Go to the lower left corner, look into the middle of the lower left itemframe and type `/maps createscreen`
9. Done! (Optional: Restart your server one last time)
7. Restart your server again
8. Build a 16 by 16 rectangle and place item frames ([like this](https://i.imgur.com/D5UAi5a.png))
9. Go to the lower left corner, look into the middle of the lower left itemframe and type `/maps createscreen`
10. Done! (Optional: Restart your server one last time)

Please note: The plugin will wait 10 seconds before rendering r/place after startup.

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.cerus</groupId>
<artifactId>minecraft-place</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>

<properties>
<maven.compiler.source>16</maven.compiler.source>
Expand Down
46 changes: 42 additions & 4 deletions src/main/java/dev/cerus/minecraftplace/MinecraftPlacePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@
import org.bukkit.Bukkit;
import org.bukkit.Difficulty;
import org.bukkit.GameRule;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

Expand Down Expand Up @@ -74,7 +78,7 @@ public void onEnable() {

// Register listener
final PluginManager pluginManager = this.getServer().getPluginManager();
pluginManager.registerEvents(new JoinListener(), this);
pluginManager.registerEvents(new JoinListener(this), this);

// Generate world
if (this.getConfig().getBoolean("world.enable")) {
Expand Down Expand Up @@ -103,15 +107,33 @@ public void onEnable() {
placeWorld.setTime(6000);

pluginManager.registerEvents(new ChunkListener(worldContext, placeWorld, this, blockColorCache, playerChunkController), this);
Bukkit.getScheduler().runTaskTimerAsynchronously(this, new BlockUpdateTask(this, playerChunkController, blockColorCache), 0, 20);
Bukkit.getScheduler().runTaskTimerAsynchronously(this, new BlockUpdateTask(this, playerChunkController, blockColorCache), 0, 10);
}));
}

this.getServer().getPluginManager().registerEvents(new Listener() {
@EventHandler
public void onJoin(final PlayerJoinEvent event) {
MinecraftPlacePlugin.this.getServer().getScheduler().runTaskLater(MinecraftPlacePlugin.this, () -> {
event.getPlayer().setAllowFlight(true);
// /execute in minecraft:overworld run tp @s 5.97 11.00 14.02 179.17 22.35
event.getPlayer().teleport(new Location(
event.getPlayer().getWorld(),
6,
11,
14,
180,
22
));
}, 5);
}
}, this);

// Enable fast graphics and start update task
Bukkit.getScheduler().runTaskLater(this, () ->
MapScreenRegistry.getScreens().stream()
.filter(screen -> screen.getWidth() == 16)
.filter(screen -> screen.getHeight() == 16)
.filter(screen -> screen.getWidth() == this.getScreenWidth())
.filter(screen -> screen.getHeight() == this.getScreenHeight())
.forEach(screen -> screen.useFastGraphics(true)), 9 * 20);
Bukkit.getScheduler().runTaskTimerAsynchronously(this, new MapUpdateTask(this), 10 * 20, 20);
}
Expand Down Expand Up @@ -197,6 +219,22 @@ private void startClient(final RedditAuthenticator.Token token) throws Interrupt
this.client.start(token.token());
}

public int getScreenWidth() {
return this.getCanvasMap().values().stream()
.mapToInt(value -> value.getX() + value.getWidth())
.map(operand -> (int) Math.ceil(operand / 128d))
.max()
.orElse(0);
}

public int getScreenHeight() {
return this.getCanvasMap().values().stream()
.mapToInt(value -> value.getY() + value.getHeight())
.map(operand -> (int) Math.ceil(operand / 128d))
.max()
.orElse(0);
}

public Map<Integer, Canvas> getCanvasMap() {
return this.canvasMap;
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/dev/cerus/minecraftplace/map/JoinListener.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.cerus.minecraftplace.map;

import dev.cerus.maps.plugin.map.MapScreenRegistry;
import dev.cerus.minecraftplace.MinecraftPlacePlugin;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -11,12 +12,18 @@
*/
public class JoinListener implements Listener {

private final MinecraftPlacePlugin plugin;

public JoinListener(final MinecraftPlacePlugin plugin) {
this.plugin = plugin;
}

@EventHandler
public void onJoin(final PlayerJoinEvent event) {
final Player player = event.getPlayer();
MapScreenRegistry.getScreens().stream()
.filter(screen -> screen.getWidth() == 16)
.filter(screen -> screen.getHeight() == 16)
.filter(screen -> screen.getWidth() == this.plugin.getScreenWidth())
.filter(screen -> screen.getHeight() == this.plugin.getScreenHeight())
.forEach(screen -> screen.sendMaps(true, player));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/cerus/minecraftplace/map/MapUpdateTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public MapUpdateTask(final MinecraftPlacePlugin plugin) {
public void run() {
// Get screens to update
final List<MapScreen> screens = MapScreenRegistry.getScreens().stream()
.filter(screen -> screen.getWidth() == 16)
.filter(screen -> screen.getHeight() == 16)
.filter(screen -> screen.getWidth() == this.plugin.getScreenWidth())
.filter(screen -> screen.getHeight() == this.plugin.getScreenHeight())
.toList();
if (screens.isEmpty()) {
return;
Expand Down

0 comments on commit 51679a6

Please sign in to comment.