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

View File

@ -9,11 +9,8 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Color;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.Particle.DustOptions;
import io.github.thebusybiscuit.slimefun4.core.networks.NetworkManager; import io.github.thebusybiscuit.slimefun4.core.networks.NetworkManager;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
@ -103,13 +100,16 @@ public abstract class Network {
return regulatorNodes.size() + connectorNodes.size() + terminusNodes.size(); 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) { protected void addLocationToNetwork(@Nonnull Location l) {
if (connectedLocations.contains(l)) { if (connectedLocations.add(l.clone())) {
return; 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. * every {@link Location} that this {@link Network} is connected to.
*/ */
public void display() { public void display() {
SlimefunPlugin.runSync(() -> { if (manager.isVisualizerEnabled()) {
DustOptions options = new DustOptions(Color.BLUE, 3F); SlimefunPlugin.runSync(new NetworkVisualizer(this));
}
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);
}
}
});
} }
/** /**

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 { public class NetworkManager {
private final int maxNodes; private final int maxNodes;
private final boolean enableVisualizer;
private final List<Network> networks = new LinkedList<>(); private final List<Network> networks = new LinkedList<>();
/** /**
@ -37,8 +38,10 @@ public class NetworkManager {
* @param maxStepSize * @param maxStepSize
* The maximum amount of nodes a {@link Network} can have * 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!"); Validate.isTrue(maxStepSize > 0, "The maximal Network size must be above zero!");
this.enableVisualizer = enableVisualizer;
maxNodes = maxStepSize; maxNodes = maxStepSize;
} }
@ -52,6 +55,15 @@ public class NetworkManager {
return maxNodes; 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}. * 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; instance = this;
if (minecraftVersion == MinecraftVersion.UNIT_TEST) { if (minecraftVersion == MinecraftVersion.UNIT_TEST) {
local = new LocalizationService(this, "", null); onUnitTestStart();
gpsNetwork = new GPSNetwork();
networkManager = new NetworkManager(200);
command.register();
registry.load(config);
} else if (getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) { } else if (getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) {
getLogger().log(Level.INFO, "CS-CoreLib was detected!"); getLogger().log(Level.INFO, "CS-CoreLib was detected!");
long timestamp = System.nanoTime(); long timestamp = System.nanoTime();
@ -222,7 +218,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
networkSize = 1; networkSize = 1;
} }
networkManager = new NetworkManager(networkSize); networkManager = new NetworkManager(networkSize, config.getBoolean("networks.enable-visualizer"));
// Setting up bStats // Setting up bStats
new Thread(metricsService::start, "Slimefun Metrics").start(); 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 @Nonnull
private String getStartupTime(long timestamp) { private String getStartupTime(long timestamp) {
long ms = (System.nanoTime() - timestamp) / 1000000; long ms = (System.nanoTime() - timestamp) / 1000000;

View File

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

View File

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

View File

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