It ALL works!
The single map mode has best performance Some latency, fix by only using Java
This commit is contained in:
parent
f9832eb554
commit
29d91a744d
4 changed files with 97 additions and 13 deletions
|
@ -2,3 +2,6 @@ name: AudioSpectrum
|
|||
main: io.github.norbipeti.audiospectrum.PluginMain
|
||||
version: 4.0
|
||||
commands:
|
||||
barcount:
|
||||
usage: Please give a number between 0 and 16.
|
||||
singlemap:
|
|
@ -1,27 +1,55 @@
|
|||
package io.github.norbipeti.audiospectrum;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.map.*;
|
||||
|
||||
public class BarsRenderer extends MapRenderer
|
||||
public class BarsRenderer extends BarsRendererBase
|
||||
{
|
||||
private int[] bars;
|
||||
private boolean single = false;
|
||||
|
||||
public BarsRenderer(int[] bars)
|
||||
{
|
||||
this.bars = bars;
|
||||
super(bars);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void render(MapView mv, MapCanvas mc, Player pl)
|
||||
{ //Width: 16, empty space: 16, count per map: 8
|
||||
{ //Width: 8, empty space: 8, count per map: 8
|
||||
//if (firstrender ? !(firstrender = !firstrender) : firstrender)
|
||||
if (firstrender < 4 ? firstrender++ < 4 : false) //Only increment if true
|
||||
for (int i = 0; i < 128; i++)
|
||||
for (int j = 0; j < 128; j++)
|
||||
mc.setPixel(i, j, MapPalette.matchColor(Color.black));
|
||||
if (single)
|
||||
{
|
||||
if (mv.getId() != 0)
|
||||
return;
|
||||
for (int i = 0; i < 16 && i < count; i++)
|
||||
for (int j = 0; j < 128; j++)
|
||||
for (int k = 0; k < 4; k++)
|
||||
mc.setPixel(i * 8 + k, 128 - j, j < bars[i] / 2 ? MapPalette.matchColor(j, 255 - j * 2, 0)
|
||||
: MapPalette.matchColor(Color.BLACK));
|
||||
return;
|
||||
}
|
||||
int offsetx = mv.getId() % 2 * 8, offsety = mv.getId() < 2 ? -128 : 0;
|
||||
//System.out.println("OX: " + offsetx + " OY: " + offsety + " ID: " + mv.getId());
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int i = 0; i < 8 && i < count - offsetx; i++)
|
||||
for (int j = 0; j < 128; j++)
|
||||
for (int k = 0; k < 16; k++)
|
||||
mc.setPixel(i * 32 + k, 128 - j, j < bars[offsetx + i] + offsety
|
||||
? MapPalette.matchColor(255 - j + offsety, j - offsety, 0) : 0); //TODO: 0 is transparent
|
||||
} //TODO: Render areas inbetween black
|
||||
for (int k = 0; k < 8; k++)
|
||||
mc.setPixel(i * 16 + k, 128 - j,
|
||||
j < bars[offsetx + i] + offsety ? MapPalette.matchColor(j - offsety, 255 - j + offsety, 0)
|
||||
: MapPalette.matchColor(Color.BLACK));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to use a single map or 4
|
||||
*/
|
||||
public boolean toggleSingle()
|
||||
{
|
||||
firstrender = 0;
|
||||
return this.single = !single;
|
||||
}
|
||||
}
|
||||
|
|
23
src/io/github/norbipeti/audiospectrum/BarsRendererBase.java
Normal file
23
src/io/github/norbipeti/audiospectrum/BarsRendererBase.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package io.github.norbipeti.audiospectrum;
|
||||
|
||||
import org.bukkit.map.MapRenderer;
|
||||
|
||||
public abstract class BarsRendererBase extends MapRenderer
|
||||
{
|
||||
protected int[] bars;
|
||||
protected byte firstrender = 0;
|
||||
protected byte count = 16;
|
||||
|
||||
public BarsRendererBase(int[] bars)
|
||||
{
|
||||
this.bars = bars;
|
||||
}
|
||||
|
||||
public byte setBarCount(byte count)
|
||||
{
|
||||
firstrender = 0;
|
||||
if (count >= 0 && count <= 16)
|
||||
this.count = count;
|
||||
return this.count;
|
||||
}
|
||||
}
|
|
@ -4,9 +4,9 @@ import java.io.IOException;
|
|||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.map.MapView;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
@ -15,13 +15,14 @@ public class PluginMain extends JavaPlugin
|
|||
private Thread thread;
|
||||
private boolean running = false;
|
||||
private volatile int[] bars = new int[16];
|
||||
private BarsRenderer br;
|
||||
|
||||
// Fired when plugin is first enabled
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
BarsRenderer br = new BarsRenderer(bars);
|
||||
br = new BarsRenderer(bars);
|
||||
for (short i = 0; i < 4; i++)
|
||||
{
|
||||
MapView map = Bukkit.getMap(i);
|
||||
|
@ -32,6 +33,7 @@ public class PluginMain extends JavaPlugin
|
|||
}
|
||||
thread = new Thread()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
PluginMain.this.run(5896);
|
||||
|
@ -48,7 +50,7 @@ public class PluginMain extends JavaPlugin
|
|||
running = false;
|
||||
}
|
||||
|
||||
private volatile byte[] packet = new byte[2];
|
||||
private volatile byte[] packet = new byte[16];
|
||||
|
||||
public void run(int port)
|
||||
{
|
||||
|
@ -76,4 +78,32 @@ public class PluginMain extends JavaPlugin
|
|||
serverSocket.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
|
||||
{
|
||||
if (command.getName().equalsIgnoreCase("barcount"))
|
||||
{
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
try
|
||||
{
|
||||
byte c = Byte.parseByte(args[0]);
|
||||
sender.sendMessage("Bar count set to " + br.setBarCount(c));
|
||||
return true;
|
||||
|
||||
} catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} else if (command.getName().equalsIgnoreCase("singlemap"))
|
||||
{
|
||||
sender.sendMessage("Single map toggled, now " + br.toggleSingle());
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
sender.sendMessage("Command not implemented!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue