1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Added a config option to disable network visualizations

This commit is contained in:
TheBusyBiscuit 2020-11-04 11:18:06 +01:00
parent 57590b2ff3
commit 3170f143a2
8 changed files with 106 additions and 35 deletions

View File

@ -28,6 +28,7 @@
#### Additions
* The Smelters Pick now also works on Ancient Debris
* (API) Added PlayerPreResearchEvent
* Added a config option to disable network visualizations
#### Changes
* Removed 1.13 support
@ -37,6 +38,7 @@
* Cargo Motors can no longer be placed down
* Magnets can no longer be placed down
* Electromagnets can no longer be placed down
* Performance improvements to Cargo network visualizations
#### Fixes
* Fixed #2448
@ -55,6 +57,7 @@
* Fixed #2517
* Fixed Magician Talisman sometimes drawing invalid enchantments
* Fixed id conflicts for external Enchantment sources (e.g. plugins) for the Magician Talisman settings
* Fixed network visualizers spawning particles for other player heads
## Release Candidate 17 (17 Oct 2020)

View File

@ -9,11 +9,8 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang.Validate;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Particle.DustOptions;
import io.github.thebusybiscuit.slimefun4.core.networks.NetworkManager;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
@ -103,13 +100,16 @@ public abstract class Network {
return regulatorNodes.size() + connectorNodes.size() + terminusNodes.size();
}
/**
* This method adds the given {@link Location} to this {@link Network}.
*
* @param l
* The {@link Location} to add
*/
protected void addLocationToNetwork(@Nonnull Location l) {
if (connectedLocations.contains(l)) {
return;
if (connectedLocations.add(l.clone())) {
markDirty(l);
}
connectedLocations.add(l.clone());
markDirty(l);
}
/**
@ -211,17 +211,9 @@ public abstract class Network {
* every {@link Location} that this {@link Network} is connected to.
*/
public void display() {
SlimefunPlugin.runSync(() -> {
DustOptions options = new DustOptions(Color.BLUE, 3F);
for (Location l : connectedLocations) {
Material type = l.getBlock().getType();
if (type == Material.PLAYER_HEAD || type == Material.PLAYER_WALL_HEAD) {
l.getWorld().spawnParticle(Particle.REDSTONE, l.getX() + 0.5, l.getY() + 0.5, l.getZ() + 0.5, 1, 0, 0, 0, 1, options);
}
}
});
if (manager.isVisualizerEnabled()) {
SlimefunPlugin.runSync(new NetworkVisualizer(this));
}
}
/**

View File

@ -0,0 +1,59 @@
package io.github.thebusybiscuit.slimefun4.api.network;
import javax.annotation.Nonnull;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.Particle.DustOptions;
/**
* This class represents the visualizer task of a given {@link Network}.
*
* @author TheBusyBiscuit
*
*/
class NetworkVisualizer implements Runnable {
/**
* The {@link DustOptions} define the {@link Color} and size of our particles.
*/
private final DustOptions options = new DustOptions(Color.BLUE, 3.5F);
/**
* This is our {@link Network} instance.
*/
private final Network network;
/**
* This creates a new {@link NetworkVisualizer} for the given {@link Network}.
*
* @param network
* The {@link Network} to visualize
*/
NetworkVisualizer(@Nonnull Network network) {
this.network = network;
}
@Override
public void run() {
for (Location l : network.connectorNodes) {
spawnParticles(l);
}
for (Location l : network.terminusNodes) {
spawnParticles(l);
}
}
/**
* This method will spawn the actual particles.
*
* @param l
* The {@link Location} of our node
*/
private void spawnParticles(@Nonnull Location l) {
l.getWorld().spawnParticle(Particle.REDSTONE, l.getX() + 0.5, l.getY() + 0.5, l.getZ() + 0.5, 1, 0, 0, 0, 1, options);
}
}

View File

@ -29,6 +29,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.listeners.NetworkListen
public class NetworkManager {
private final int maxNodes;
private final boolean enableVisualizer;
private final List<Network> networks = new LinkedList<>();
/**
@ -37,8 +38,10 @@ public class NetworkManager {
* @param maxStepSize
* The maximum amount of nodes a {@link Network} can have
*/
public NetworkManager(int maxStepSize) {
public NetworkManager(int maxStepSize, boolean enableVisualizer) {
Validate.isTrue(maxStepSize > 0, "The maximal Network size must be above zero!");
this.enableVisualizer = enableVisualizer;
maxNodes = maxStepSize;
}
@ -52,6 +55,15 @@ public class NetworkManager {
return maxNodes;
}
/**
* This returns whether the {@link Network} visualizer is enabled.
*
* @return Whether the {@link Network} visualizer is enabled
*/
public boolean isVisualizerEnabled() {
return enableVisualizer;
}
/**
* This returns a {@link List} of every {@link Network} on the {@link Server}.
*

View File

@ -175,11 +175,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
instance = this;
if (minecraftVersion == MinecraftVersion.UNIT_TEST) {
local = new LocalizationService(this, "", null);
gpsNetwork = new GPSNetwork();
networkManager = new NetworkManager(200);
command.register();
registry.load(config);
onUnitTestStart();
} else if (getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) {
getLogger().log(Level.INFO, "CS-CoreLib was detected!");
long timestamp = System.nanoTime();
@ -222,7 +218,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
networkSize = 1;
}
networkManager = new NetworkManager(networkSize);
networkManager = new NetworkManager(networkSize, config.getBoolean("networks.enable-visualizer"));
// Setting up bStats
new Thread(metricsService::start, "Slimefun Metrics").start();
@ -306,6 +302,14 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
}
}
private void onUnitTestStart() {
local = new LocalizationService(this, "", null);
gpsNetwork = new GPSNetwork();
networkManager = new NetworkManager(200, true);
command.register();
registry.load(config);
}
@Nonnull
private String getStartupTime(long timestamp) {
long ms = (System.nanoTime() - timestamp) / 1000000;

View File

@ -37,6 +37,7 @@ URID:
networks:
max-size: 200
cargo-ticker-delay: 0
enable-visualizer: true
items:
talismans: true

View File

@ -25,7 +25,7 @@ class TestNetworkListener {
private static SlimefunPlugin plugin;
private static NetworkListener listener;
private static NetworkManager manager = new NetworkManager(80);
private static NetworkManager manager = new NetworkManager(80, false);
private static ServerMock server;
@BeforeAll

View File

@ -37,15 +37,15 @@ class TestNetworkManager {
@Test
@DisplayName("Test illegal network size arguments")
void testIllegalNetworkSize() {
Assertions.assertThrows(IllegalArgumentException.class, () -> new NetworkManager(-100));
Assertions.assertThrows(IllegalArgumentException.class, () -> new NetworkManager(0));
Assertions.assertThrows(IllegalArgumentException.class, () -> new NetworkManager(-100, false));
Assertions.assertThrows(IllegalArgumentException.class, () -> new NetworkManager(0, false));
}
@Test
@DisplayName("Test maximum network size")
void testGetMaxNetworkSize() {
int size = 50;
NetworkManager manager = new NetworkManager(size);
NetworkManager manager = new NetworkManager(size, false);
Assertions.assertEquals(size, manager.getMaxSize());
}
@ -53,7 +53,7 @@ class TestNetworkManager {
@Test
@DisplayName("Test network list")
void testGetNetworkList() {
NetworkManager manager = new NetworkManager(10);
NetworkManager manager = new NetworkManager(10, false);
World world = server.addSimpleWorld("Simple Network World");
Location loc = new Location(world, 0, 100, 0);
@ -82,7 +82,7 @@ class TestNetworkManager {
@Test
@DisplayName("Test getting a network at a location")
void testGetNetworkAtLocation() {
NetworkManager manager = new NetworkManager(10);
NetworkManager manager = new NetworkManager(10, false);
World world = server.addSimpleWorld("Simple Network World");
Location loc = new Location(world, 0, 100, 0);
Location loc2 = new Location(world, 0, 200, 0);
@ -104,7 +104,7 @@ class TestNetworkManager {
@Test
@DisplayName("Test getting all networks at a location")
void testGetNetworksAtLocation() {
NetworkManager manager = new NetworkManager(10);
NetworkManager manager = new NetworkManager(10, false);
World world = server.addSimpleWorld("Simple Network World");
Location loc = new Location(world, 0, 100, 0);
Location loc2 = new Location(world, 0, 200, 0);
@ -120,7 +120,7 @@ class TestNetworkManager {
@Test
@DisplayName("Test a single node network")
void testSingleNodeNetwork() {
NetworkManager manager = new NetworkManager(1);
NetworkManager manager = new NetworkManager(1, false);
World world = server.addSimpleWorld("Simple Network World");
Location loc = new Location(world, 0, 100, 0);
@ -134,7 +134,7 @@ class TestNetworkManager {
@Test
@DisplayName("Test networks connecting via corners")
void testCornerConnection() {
NetworkManager manager = new NetworkManager(100);
NetworkManager manager = new NetworkManager(100, false);
World world = server.addSimpleWorld("Simple Network World");
Map<Location, NetworkComponent> map = new HashMap<>();