import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.configuration.file.FileConfiguration;
public class MyPlugin extends JavaPlugin implements Listener {
private int limit;
@Override
public void onEnable() {
// Load the configuration
saveDefaultConfig();
FileConfiguration config = getConfig();
limit = config.getInt("limit", 100); // Default to 100 if not set
// Register the event listener
getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
Location location = event.getBlock().getLocation();
// Check if the Y-coordinate is higher than the limit
if (location.getY() > limit) {
// Cancel the block placement
event.setCancelled(true);
// Send a message to the player
player.sendMessage(ChatColor.RED + "No");
// Change the player's gamemode to survival (2) for 5 seconds
player.setGameMode(GameMode.SURVIVAL);
Bukkit.getScheduler().runTaskLater(this, () -> {
player.setGameMode(GameMode.ADVENTURE); // Change back to adventure mode
}, 100); // 100 ticks = 5 seconds
}
}
}