How to remove cursor from a Map (Bukkit) - java

I'm currently developing a plugin which only renders an image to a map like this:
public class MapRendererTest extends MapRenderer {
private Image image;
public MapRendererTest(File file) {
try {
this.image = ImageIO.read(file);
}
catch (IOException e) {
e.printStackTrace();
}
}
#Override
public void render(MapView mapView, MapCanvas mapCanvas, Player player) {
mapCanvas.drawImage(0, 0, image);
}
}
everything works fine, but there is this little thing in the red circle that I want to remove but I don't know how.
Things I already tried
Setting an emtpy MapCursorCollection
MapView.setWorld to a world where no-one is playing.
Creating MapCursorCollection with a invisible cursor
It would be amazing if someone could help me with that.
Thanks in advance

To get rid of the cursor, you have to remove all the other map renderers or at least the CraftMapRanderer.
In order to do this, you have to do the following:
#EventHandler
public void onMapInitialized(MapInitializeEvent e) {
e.getMap().removeRenderer(e.getMap().getRenderers().get(0));
e.getMap().addRenderer(new MapRendererTest(new File(Main.getInstance().getDataFolder() + "/image.png")));
}
This only works of course if there is no other custom map renderer assigned to this map, so the only registered is the CraftMapRenderer.
If you have multiple MapRenderers you could loop through the list and remove them.

Related

Player Head Movement Detection Bukkit

today I'm here to ask you a question, on Minecraft in particular in the PaperMc development (Bukkit Fork) I'm trying to create the "animations" effect like the famous Hypixel lootboxes (Opening phase) so I needed know how I could identify the PlayerHeadMovement Event. I tried with
#EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
System.out.println("A");
}
But it would appear not to detect head movement.
There is no event that specifically focuses on the movement of the player's head.
You can, however, on the PlayerMoveEvent get the from and to movements.
So, to see if the player's head has moved, your code could look like:
private boolean hasPlayerHeadMoved(PlayerMoveEvent e) {
Location from = e.getFrom();
Location to = e.getTo();
return from.getYaw() != to.getYaw() || from.getPitch() != to.getPitch();
}
In your event handler, you would then call the method:
#EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
boolean headHasMoved = hasPlayerHeadMoved(e);
}

Losing AWT DrawingSurface when Canvas is hidden

I am writing 3d rendering module for an AWT/Swing application.
To provide good FPS, I can't draw using Swing/AWT methods and graphics. Instead, I obtain the Drawing Surface from the Canvas element, and then render directly to it. Something like this:
public class Window {
private Component canvas;
private JAWTDrawingSurface ds;
public static final JAWT awt;
static {
awt = JAWT.calloc();
awt.version(JAWT_VERSION_1_4);
if (!JAWT_GetAWT(awt))
throw new AssertionError("GetAWT failed");
}
public void lock() throws AWTException {
int lock = JAWT_DrawingSurface_Lock(ds, ds.Lock());
if ((lock & JAWT_LOCK_ERROR) != 0)
throw new AWTException("JAWT_DrawingSurface_Lock() failed");
}
public void unlock() throws AWTException {
JAWT_DrawingSurface_Unlock(ds, ds.Unlock());
}
public void Init2()
{
this.ds = JAWT_GetDrawingSurface(canvas, awt.GetDrawingSurface());
try
{
lock();
// Create GL Capabilities
unlock();
}
}
It works fine when I call it the first time.
But when I hide the canvas for any reason (for example minimizing window or displaying another panel instead of Canvas), the ds variable remains the same, but it doesn't work after that.
Basically, even if I make sure I call the variable only when it is visible and on top - any call using ds will throw an exception. For example lock() function stops working.
I'm wondering why's that?
Also I tried to basically obtain a new DS if I minimize and then maximize the window again, but this also doesn't work - the new DS address is returned as it should, but I can't use that new object just as I couldn't use the original one.
There's probably something stupid I'm missing here, but I can't figure out what.
Please help me sort this out. Thank you!
The solution:
When the Canvas is hidden, call eglMakeCurrent(eglDisplay,EGL_NO_SURFACE,EGL_NO_SURFACE,EGL_NO_CONTEXT) to unbind the current context.
When you need to start drawing again, you need to do something like this:
public void Reinit()
{
System.err.println("Context Reinit()");
this.ds = JAWT_GetDrawingSurface(canvas, awt.GetDrawingSurface());
try
{
lock();
try
{
JAWTDrawingSurfaceInfo dsi = JAWT_DrawingSurface_GetDrawingSurfaceInfo(ds, ds.GetDrawingSurfaceInfo());
JAWTX11DrawingSurfaceInfo dsiWin = JAWTX11DrawingSurfaceInfo.create(dsi.platformInfo());
this.display = dsiWin.display();
this.drawable = dsiWin.drawable();
eglDisplay = eglGetDisplay(display);
surface = eglCreateWindowSurface(eglDisplay,fbConfigs.get(0),drawable,(int[])null);
eglMakeCurrent(eglDisplay,surface,surface,context);
GLES.setCapabilities(glesCaps);
JAWT_DrawingSurface_FreeDrawingSurfaceInfo(dsi, ds.FreeDrawingSurfaceInfo());
}
finally
{
unlock();
System.err.printf("Unlock \n");
}
}
catch (Exception e)
{
System.err.println("JAWT Failed" + e.getMessage());
}
}
As You can see, I re-create the display and surface, but I use the previously created context for rendering, without needing to re-create it.

Wicket - Set Model from another panel

I am quite new to Wicket. I am adding a model to a sub-panel(ChartPanel) from a main panel (MainPanel) on a button click.
MainPanel.java
On button click, I am re-adding the chartPanel after I change its model. Following is the code I am using in the buttonClick of the MainPanel. Here the onRenderAnnotations event is generated on some click in the UI.
#OnEvent
public void onRenderAnnotations(RenderAnnotationsEvent aEvent)
{
LOG.trace("clicked on the annotation");
renderChart( aEvent.getRequestHandler());
}
private void renderChart(IPartialPageRequestHandler aRequestHandler)
{
MultiValuedMap<String, Double> recommenderScoreMap = getLatestScores(aRequestHandler);
Map<String,String> curveData = new HashMap<String,String>();
LearningCurve learningCurve = new LearningCurve();
for (String recommenderName : recommenderScoreMap.keySet()) {
String data = recommenderScoreMap.get(recommenderName).stream().map(Object::toString)
.collect(Collectors.joining(", "));
curveData.put(recommenderName,data);
learningCurve.setCurveData(curveData);
learningCurve.setMaximumPointsToPlot(MAX_POINTS_TO_PLOT);
}
chartPanel.setDefaultModel(Model.of(learningCurve));
// to avoid the error, A partial update of the page is being rendered
try {
aRequestHandler.add(chartPanel);
}
catch (IllegalStateException e) {
LOG.warn("Not updating the chart. " + e.toString());
setResponsePage(getPage());
}
}
ChartPanel.java
After this in the chartPanel, I want to use the updated model to add component inside the chartpanel. What would be the best way to do that?
I want to do something like this in the class ChartPanel:
#Override
protected void onRender()
{
super.onModelChanged();
LearningCurve newLearningCurve = getModel().getObject();
requestTarget = ???
String js = createJavascript(newLearningCurve);
requestTarget.prependJavascript(js);
}
My question is, in the above code how to get the request target since it is not an ajax request neither do I get it in the arguments. Should I use some other function where I also get a requestTarget. But I want it to be called every time the model of ChartPanel is updated from anywhere.
Pardon my ignorance. I have been trying for a few days but I am still stuck. I tried to explain it enough but if any information is missing, please comment and I will add it right away.
Thanks.
You should override renderHead() instead:
#Override
public void renderHead(IHeaderResponse response)
{
super.renderHead(response);
response.render(OnLoadHeaderItem.forScript(
createJavascript(newLearningCurve)));
}
This way your chart will be shown correctly regardless whether it was added due to an AjaxRequest or simply when the page is rerendered.

repainting the image using bufferedimage

i am learning to write code in java and recently started to write a game as per my assignment.
i have completed almost entire game but stuck with the animation part of the game.
here is what i have done so far,
this is the class that load the image ti display,
public class dpmImage {
private BufferedImage dpm1;
private BufferedImage setDpm1;
public dpmImage() { //this is a constructor
try {
dpm1= ImageIO.read(new File("dpm1Load.png"));
} catch (IOException e) {
e.printStackTrace();
}
setDpm1 = dpm1;
}
private BufferedImage dpm1ImageGet() {
return setDpm1;
}
}
the following code is from main class (Main.java)
private Graphics cGraphcs;
cGraphcs.drawImage(dpmImageInstance.dpm1ImageGet(), 0, 0, null);
The code is working fine and displays the image.
Now, I am allowed to modify anything in dpmImage class but not allowed to modify anything in Main.java and still make this image animate. So I create an array of BufferedImage in dpmImage class and add a second image in the array as follows,
public class dpmImage {
private BufferedImage [] dpm1 = new BufferedImage[2];
private BufferedImage setDpm1;
public dpmImage() { //this is a constructor
try {
dpm1[0]= ImageIO.read(new File("dpm1Load.png"));
dpm1[1]= ImageIO.read(new File("dpm1Load1.png"));
} catch (IOException e) {
e.printStackTrace();
}
setDpm1 = dpm1[0];
setDpm1 = dpm1[1];
}
private BufferedImage dpm1ImageGet() {
return setDpm1;
}
}
But i couldn't get to animate it from first image to 2nd. Can someone please give me any hints on that ? i am not allowed to change the Main.java class
You always return the same BufferedImage from the dpm1ImageGet method. You need to get the instance from the array. Based on the frequency of the update, you can simply use an index like
private int indexImage = 0;
private BufferedImage dpm1ImageGet() {
indexImage = ( indexImage + 1 ) % dpm1.length; //increment and use % to prevent any ArrayOutOfBoundsException
return dpm1[indexImage];
}
Each call will return the next image. Of course, this depends on when you want to get the other image. It could be anything.

Can't display GWT DataGrid

So I'm having a heck of a time creating a Datagrid with GWT. I've created my table according the the docs for GWT, and I've added my data, but I can't get it or the datagrid itself to show up at all. What am I missing? I feel I've been tearing my hair out over this. I feel like making an aysnc call might be an issue, but I get no errors. When i compile and execute this portion of my code nothing shows up on the screen and the area where the datagrid is supposed to be on the dock is empty. Am I forgetting something trivial?
static int orderID = 1001;
private static List<OrderLine> orderLineList = new ArrayList<OrderLine>();
final DataGrid<OrderLine> dgOrder = new DataGrid<OrderLine>();
dgOrder.setWidth("100%");
//set columns
TextColumn<OrderLine> orderLineIdColumn = new TextColumn<OrderLine>(){
#Override
public String getValue(OrderLine object) {
return Integer.toString(object.getOrderLineID());
}
};
dgOrder.addColumn(orderLineIdColumn, "OrderLine ID");
TextColumn<OrderLine> productColumn = new TextColumn<OrderLine>(){
#Override
public String getValue(OrderLine object) {
return getProductName(object.getProductNumber());
}
};
dgOrder.addColumn(productColumn, "Product");
TextColumn<OrderLine> quantityColumn = new TextColumn<OrderLine>(){
#Override
public String getValue(OrderLine object) {
return Integer.toString(object.getQuantity());
}
};
dgOrder.addColumn(quantityColumn, "Quantity");
// add data to datagrid
Ioma.dataservice.getOrderLines(orderID, new AsyncCallback<ArrayList<OrderLine>>(){
#Override
public void onFailure(Throwable caught) {// TODO Auto-generated method stub
System.out.println("error in retrieving GP.getOrderLines" + caught.toString());
}
#Override
public void onSuccess(ArrayList<OrderLine> result) {
// TODO Auto-generated method stub
//yes i realize I could also set it to "result" but I use the result in other places as well, I have also tried setting it to result with no success
orderLineList = result;
dgOrder.setRowData(0, orderLineList);
}
});
//add datagrid to the dock
dock.add(dgOrder, DockPanel.EAST);
//add dock to mainPanel
return dock;
When you use the DataGrid you need to give it an explicit size. For CellTable you don't need to so that's why it worked.
When you were using the DataGrid is was there but had both height and width of 0. So you either need to explicitly set the size:
DataGrid<OrderLine> grid = new DataGrid<OrderLine>;
grid.setWidth("500px");
grid.setHeight("600px");
dock.add(dgOrder, DockPanel.EAST);
or you can put the gird in a ProvidesResize widget. So in your case I believe you can make it work with a DockLayoutPanel as opposed to a DockPanel which is what you seem to be using.
I had a smilliar problem . Try to put the datagrid in a Panel that implements the ProvidesResize interface, like SimpleLayoutPanel. Also in my case it helped to set the size of the SimpleLayoutPanel.
Turns out my problem was my declaration.
final DataGrid<OrderLine> dgOrder = new DataGrid<OrderLine>();
should be
final CellTable<OrderLine> dgOrder = new CellTable<OrderLine>();
I can't find out why this works, but it does. I can see my table now. are you not supposed to explicitly call an instance of datagrid I wonder?

Categories

Resources