PlayerRespawnEvent not running all the code SpigotMC - events

So I'm trying to make a impossibleX difficulty which is inspired by Fundy and I'm trying to make it so that when a player respawns he feels weak as shown below, but the thing is that it won't set their health to half and add the slowness/weakness/mining fatigue after he respawns, but it does send the message "You feel weak after respawning..."
May I have some help?
public static void nahwouldyounotrespawn(PlayerRespawnEvent e){
Player player = e.getPlayer();
player.sendMessage("You feel weak after respawning...");
player.setHealth(10);
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 30000, 5));
player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 30000, 5));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 30000, 255));
}

This is the fourth time you've got an answer containing information on how to schedule a task. I would strongly urge you to actually read the articles you have been given as they will help you.
public void playerRespawnEffects(PlayerRespawnEvent e){
Player player = e.getPlayer();
player.sendMessage("You feel weak after respawning...");
Bukkit.getScheduler().runTaskLater(/*Your plugin instance*/, () -> {
player.setHealth(10);
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 30000, 5));
player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 30000, 5));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 30000, 255));
}, /*Tick delay here e.g. 1L*/);
}

Related

how do i add delay to an if statement without pausing the whole program in processing

I am making a platformer type game and need help on knowing how to delay the time before going downwards on the jump function i have tried the thread function and it didn't work I do have a question related to that but if there are any alternatives please let me know that would be very much appreciate it.
Here's a way to delay something without stopping the program. It's a class I wrote a long time ago, when I was still a student, so I'm not proud of it but I think that it's a good way to introduce someone to millis().
Long story short, this class will let you enter a number of milliseconds it will wait for and you can, in your loop, test to see if the delay is expired or not. Here's the class:
class Delay {
int limit;
Delay (int l) {
limit = millis() + l;
}
boolean expired () {
return millis() > limit;
}
}
And here's an example of a program waiting 5000 millis (5 seconds) after a mouse click before letting you click again. It's pretty self-explanatory, but don't hesitate to ask questions about it:
int count;
Delay delay;
void setup() {
size(400, 400);
delay = new Delay(0);
}
void draw() {
background(255);
//
if (!delay.expired()) {
fill(color(255, 0, 0));
rect(100, 100, 100, 100);
fill(0);
text("Time before click is allowed: " + (delay.limit - millis()), 20, 20);
}
text("Time since last click: " + (millis() - count), 20, 40);
}
void mouseClicked() {
// only lets you start a new delay if the last one is expired
if (delay.expired()) {
delay = new Delay(5000);
count = millis();
}
}
class Delay {
int limit;
Delay (int l) {
limit = millis() + l;
}
boolean expired () {
return millis() > limit;
}
}
Knowing how to time stuff is important, but timing stuff like jumps in a platformer often include other considerations, like touching the ground or not. Still, I hope that this will help you.
Have fun!

Simple alternative to VolumeSampleProvider that will have a left and right volume property

when playing trying to play audio in a chat application that I'm making I got the exception {"Source sample provider must be mono"} in this line var panProvider = new PanningSampleProvider(volumeProvider);
Code:
private void ReceiveUdpMessage(IAsyncResult ar)
{
try
{
byte[] bytesRead = UDPc.EndReceive(ar, ref ep);
var waveProvider = new BufferedWaveProvider(new WaveFormat(44100, 16, 2));
waveProvider.DiscardOnBufferOverflow = true;
waveProvider.AddSamples(bytesRead, 0, bytesRead.Length);
var volumeProvider = new VolumeSampleProvider(waveProvider.ToSampleProvider());
var panProvider = new PanningSampleProvider(volumeProvider);
mixer.AddMixerInput(panProvider);
UDPc.BeginReceive(new AsyncCallback(ReceiveUdpMessage), null);
}
catch(Exception ex)
{
}
UDPc.BeginReceive(new AsyncCallback(ReceiveUdpMessage), null);
}
I saw this answer Implementing Output audio panning with Naudio
but when mark answered in the comments:"I'd make a very simple alternative to VolumeSampleProvider that had a left and right volume property in that case".
he didn't elaborate and I'm new to this so have no idea what to do from here.
Does someone know what I'm supposed to do?
Thx

Switch between Jump and Run animation Andengine

I want switch between Run and Jump animations, but i have some problems :
If the Player run and i tap on the screen, the Player start Jumping (one time), and the Jumpanimation starts but donĀ“t end , so the player is running with the Jumpanimation.
Do you know where my fault is?
My code :
// Runanimation + Player Run
public void setRunning()
{
canRun = true;
final long[] PLAYER_ANIMATE = new long[] { 100, 100, 100,};
animate(PLAYER_ANIMATE, 0, 2, true);
}
// Jumpanimation + Player Jump
public void jump()
{
if (footContacts < 1)
{
return;
}
body.setLinearVelocity(new Vector2(body.getLinearVelocity().x, 10));
final long[] PLAYER_JUMP_ANIMATE = new long[] { 100, 100, 100, 100, 100, 100};
animate(PLAYER_JUMP_ANIMATE, 0, 5,true);
}
Thx Seref
You are animating with loop boolean set to true, which means its keep looping animation. You should have some kinds of flags (booleans) like jumping and running, so inside set running method you should check if jumping equals true, and if so, stopAnimation() and animate using different frames (in this case running)

Irrlicht Engine: Window pops up and disappears instantly

I wanted to create a simple IrrlichtDevice with IrrlichtEngine, but when I start the application, the window just appears on the screen and then instantly disappears.
My code looks like following:
int main()
{
IrrlichtDevice *device =
createDevice( video::EDT_DIRECT3D9, dimension2d<u32>(640, 480), 16,
false, false, false, 0);
}
(code copied from the HelloWorld tutorial of the documentation)
Try
int main()
{
IrrlichtDevice *device =
createDevice( video::EDT_DIRECT3D9, dimension2d<u32>(640, 480), 16,
false, false, false, 0);
while( device->run() )
{ device->getVideoDriver()->beginScene( true, true, video::SColor( 50, 50, 50, 50) );
device->getVideoDriver()->endScene();
}
}
You have no looping system in place. After you create the device the function immediately ends and everything is cleaned up.
bob2 has the correct answer, I would suggest that you practice making simple c++ applications before diving in the deep end.

gtkD: Minimal Drawing Example?

I'm a fairly experienced programmer, but new to GUI programming. I'm trying to port a plotting library I wrote for DFL to gtkD, and I can't get drawings to show up. The following code produces a blank window for me. Can someone please tell me what's wrong with it, and/or post minimal example code for getting a few lines onto a DrawingArea and displaying the results in a MainWindow?
import gtk.DrawingArea, gtk.Main, gtk.MainWindow, gdk.GC, gdk.Drawable,
gdk.Color;
void main(string[] args) {
Main.init(args);
auto win = new MainWindow("Hello, world");
win.setDefaultSize(800, 600);
auto drawingArea = new DrawingArea(800, 600);
win.add(drawingArea);
drawingArea.realize();
auto drawable = drawingArea.getWindow();
auto gc = new GC(drawable);
gc.setForeground(new Color(255, 0, 0));
gc.setBackground(new Color(255, 255, 255));
drawable.drawLine(gc, 0, 0, 100, 100);
drawingArea.showAll();
drawingArea.queueDraw();
win.showAll();
Main.run();
}
I have no experience whatsoever in D, but lots in GTK, so with the help of the gtkD tutorial I managed to hack up a minimal example:
import gtk.DrawingArea, gtk.Main, gtk.MainWindow, gdk.GC, gdk.Drawable,
gdk.Color, gtk.Widget;
class DrawingTest : MainWindow
{
this()
{
super("Hello, world");
setDefaultSize(800, 600);
auto drawingArea = new DrawingArea(800, 600);
add(drawingArea);
drawingArea.addOnExpose(&drawStuff);
showAll();
}
bool drawStuff(GdkEventExpose *event, Widget self)
{
auto drawable = self.getWindow();
auto gc = new GC(drawable);
gc.setForeground(new Color(cast(ubyte)255, cast(ubyte)0, cast(ubyte)0));
gc.setBackground(new Color(cast(ubyte)255, cast(ubyte)255, cast(ubyte)255));
drawable.drawLine(gc, 0, 0, 100, 100);
return true;
}
}
void main(string[] args) {
Main.init(args);
new DrawingTest();
Main.run();
}
In GTK, a DrawingArea is actually just a blank widget for you to paint on, and painting on widgets must always be done in the expose-event handler. (Although I understand this will change in GTK 3!)
I understand you can't connect functions as signal callbacks, only delegates, so that's the reason for the DrawingTest class.

Resources