#mc plugin hardcore grace period

1 messages · Page 1 of 1 (latest)

pearl dune
#

I am really new to java and I am trying to code a spigot 1.21.8 plugin but I need this done before friday for a minecraft server for my friends.

This is how the plugin works: The world is on hardcore. When a player first joins the world, they will have a 1 hour grace period where they can respawn. If a player leaves during their grace period the timer keeps on running. And after one hour, they player is now fully in hardcore mode and if they die, they are dead.
As you see this is per player meaning it's local. So I want it that every player gets a 1 hour grace period at their FIRST join.
(CODE IS IN THE CHAT, NEEDS HELP!)

surreal prismBOT
#

<@&987246652869971988> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
I am really new to java and I am trying to code a spigot 1.21.8 plugin but I need this done before friday for a minecraft server for my friends. This is how the plugin works: The world is on hardcore. When a player first joins the world, they will have a

I recommend starting with some basic tutorials on Java programming and Spigot plugin development to get a better understanding of the process. Since you are on a tight deadline, it would be helpful to focus on simple functionalities for your plugin. Here are 3 useful links to guide you in coding your Spigot plugin:

Useful links:

  1. Spigot Plugin Development - Official Documentation
  2. Java Programming Tutorial for Beginners
  3. Creating a Minecraft Plugin in Java - Tutorial
pearl dune
#

package me.srow12.graceperiodTestV2;

import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashMap;
import java.util.UUID;

#

public final class GraceperiodTestV2 extends JavaPlugin implements Listener {

// Houdt bij hoeveel ticks er nog over zijn in de grace period per speler
private final HashMap<UUID, Integer> graceTimers = new HashMap<>();

@Override
public void onEnable() {
    getServer().getPluginManager().registerEvents(this, this);

    // Herhaal elke tick (20 ticks = 1 seconde)
    Bukkit.getScheduler().runTaskTimer(this, () -> {
        for (UUID uuid : graceTimers.keySet().toArray(new UUID[0])) {
            int timeLeft = graceTimers.get(uuid) - 1;
            if (timeLeft <= 0) {
                Player player = Bukkit.getPlayer(uuid);
                if (player != null && player.isOnline()) {
                    player.setGameMode(GameMode.SURVIVAL); // Of Hardcore als je Hardcore wilt simuleren
                    player.setGameMode(GameMode.HARDCORE); // Zet de speler op Hardcore
                    player.sendMessage("Je grace periode is voorbij! Je bent nu in Hardcore.");
                }
                graceTimers.remove(uuid);
            } else {
                graceTimers.put(uuid, timeLeft);
            }
        }
    }, 20L, 20L); // start na 1 seconde en repeat elke seconde
}

@Override
public void onDisable() {
    // Plugin shutdown logic
}

@EventHandler
public void onJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    // Zet de speler op Survival bij joinen
    player.setGameMode(GameMode.SURVIVAL);
    player.sendMessage("Welkom! Je hebt 1 uur om te spelen voordat Hardcore start.");

    // Start een grace period van 1 uur (3600 seconden)
    graceTimers.put(player.getUniqueId(), 3600);
}

}

surreal prismBOT
# pearl dune public final class GraceperiodTestV2 extends JavaPlugin implements Listener { ...

Detected code, here are some useful tools:

Formatted code
public final class GraceperiodTestV2 extends JavaPlugin implements Listener {
  // Houdt bij hoeveel ticks er nog over zijn in de grace period per speler
  private final HashMap<UUID, Integer> graceTimers = new HashMap<>();
  @Override
  public void onEnable() {
    getServer().getPluginManager().registerEvents(this , this );
    // Herhaal elke tick (20 ticks = 1 seconde)
    Bukkit.getScheduler().runTaskTimer(this , () -> {
      for (UUID uuid : graceTimers.keySet().toArray(new UUID[0] )) {
        int timeLeft = graceTimers.get(uuid) - 1;
        if (timeLeft <= 0) {
          Player player = Bukkit.getPlayer(uuid);
          if (player != null  && player.isOnline()) {
            player.setGameMode(GameMode.SURVIVAL);
            // Of Hardcore als je Hardcore wilt simuleren
            player.setGameMode(GameMode.HARDCORE);
            // Zet de speler op Hardcore
            player.sendMessage("Je grace periode is voorbij! Je bent nu in Hardcore.");
          }
          graceTimers.remove(uuid);
        }
        else {
          graceTimers.put(uuid, timeLeft);
        }
      }
    }
    , 20L, 20L);
    // start na 1 seconde en repeat elke seconde
  }
  @Override
  public void onDisable() {
    // Plugin shutdown logic
  }
  @EventHandler
  public void onJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    // Zet de speler op Survival bij joinen
    player.setGameMode(GameMode.SURVIVAL);
    player.sendMessage("Welkom! Je hebt 1 uur om te spelen voordat Hardcore start.");
    // Start een grace period van 1 uur (3600 seconden)
    graceTimers.put(player.getUniqueId(), 3600);
  }
}
#

mc plugin hardcore grace period

#

Changed the title to mc plugin hardcore grace period.

magic karma
pearl dune
magic karma
#

use grok instead

pearl dune
#

Alright, thanks a lot.

magic karma
#

he's a bit smarter

#

just give him good response

haughty tartan
pearl dune
haughty tartan
#

the grace period starts at the beginning of the plugins lifecycle

#

and loops through all online players... ... while nobody is online

pearl dune
#

Can you take a look for me please? I truly need help

haughty tartan
#

youre welcome

pearl dune
haughty tartan
#

not very long

#

as soon as the player dies and their grace period is over... you just ban them

pearl dune
#

Or do you know if this plugin already exists? 🙏 I did at least 12 hours of research

haughty tartan
#

I've not looked

pearl dune
haughty tartan
pearl dune
#

I just really want this plugin so me and my friends can play

pearl dune
# haughty tartan look at this

Players will have lives which means that they can respawn a custom set amount of times, not a grace period. We really need a plugin that gives a grace period of 1 hour, not lives.

#

Thanks a lot tho

#

For helping me, it truly means a lot

#

But idk man, there's just nothing I can find

haughty tartan
#

bceause that is not it

pearl dune
haughty tartan
pearl dune
haughty tartan
#

its based on their no. of lifes

pearl dune
haughty tartan
#

then yeah, you will have to make your own

pearl dune
dull folio
#

hardcore isn't a game mode

#

you'd have to mess with both the respawn mechanic and the packet that the server sends to the client saying that the game is in hardcore mode

haughty tartan
#

^